xref: /third_party/openssl/crypto/x509/x509_meth.c (revision e1051a39)
1/*
2 * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License").  You may not use
5 * this file except in compliance with the License.  You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include <stdio.h>
11#include <time.h>
12#include <errno.h>
13
14#include "internal/cryptlib.h"
15#include <openssl/asn1.h>
16#include <openssl/x509.h>
17#include <openssl/types.h>
18#include "x509_local.h"
19
20X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name)
21{
22    X509_LOOKUP_METHOD *method = OPENSSL_zalloc(sizeof(X509_LOOKUP_METHOD));
23
24    if (method != NULL) {
25        method->name = OPENSSL_strdup(name);
26        if (method->name == NULL) {
27            ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
28            goto err;
29        }
30    }
31
32    return method;
33
34err:
35    OPENSSL_free(method);
36    return NULL;
37}
38
39void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method)
40{
41    if (method != NULL)
42        OPENSSL_free(method->name);
43    OPENSSL_free(method);
44}
45
46int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
47                                  int (*new_item) (X509_LOOKUP *ctx))
48{
49    method->new_item = new_item;
50    return 1;
51}
52
53int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
54    (X509_LOOKUP *ctx)
55{
56    return method->new_item;
57}
58
59int X509_LOOKUP_meth_set_free(
60    X509_LOOKUP_METHOD *method,
61    void (*free_fn) (X509_LOOKUP *ctx))
62{
63    method->free = free_fn;
64    return 1;
65}
66
67void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
68    (X509_LOOKUP *ctx)
69{
70    return method->free;
71}
72
73int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
74                              int (*init) (X509_LOOKUP *ctx))
75{
76    method->init = init;
77    return 1;
78}
79
80int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
81    (X509_LOOKUP *ctx)
82{
83    return method->init;
84}
85
86int X509_LOOKUP_meth_set_shutdown(
87    X509_LOOKUP_METHOD *method,
88    int (*shutdown) (X509_LOOKUP *ctx))
89{
90    method->shutdown = shutdown;
91    return 1;
92}
93
94int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
95    (X509_LOOKUP *ctx)
96{
97    return method->shutdown;
98}
99
100int X509_LOOKUP_meth_set_ctrl(
101    X509_LOOKUP_METHOD *method,
102    X509_LOOKUP_ctrl_fn ctrl)
103{
104    method->ctrl = ctrl;
105    return 1;
106}
107
108X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method)
109{
110    return method->ctrl;
111}
112
113int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
114    X509_LOOKUP_get_by_subject_fn get_by_subject)
115{
116    method->get_by_subject = get_by_subject;
117    return 1;
118}
119
120X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
121    const X509_LOOKUP_METHOD *method)
122{
123    return method->get_by_subject;
124}
125
126
127int X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method,
128    X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial)
129{
130    method->get_by_issuer_serial = get_by_issuer_serial;
131    return 1;
132}
133
134X509_LOOKUP_get_by_issuer_serial_fn
135    X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD *method)
136{
137    return method->get_by_issuer_serial;
138}
139
140
141int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
142    X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint)
143{
144    method->get_by_fingerprint = get_by_fingerprint;
145    return 1;
146}
147
148X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
149    const X509_LOOKUP_METHOD *method)
150{
151    return method->get_by_fingerprint;
152}
153
154int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
155                                      X509_LOOKUP_get_by_alias_fn get_by_alias)
156{
157    method->get_by_alias = get_by_alias;
158    return 1;
159}
160
161X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
162    const X509_LOOKUP_METHOD *method)
163{
164    return method->get_by_alias;
165}
166
167