xref: /openssl/crypto/x509/x509_meth.c (revision e077455e)
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 
X509_LOOKUP_meth_new(const char * name)20 X509_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             goto err;
28     }
29 
30     return method;
31 
32 err:
33     OPENSSL_free(method);
34     return NULL;
35 }
36 
X509_LOOKUP_meth_free(X509_LOOKUP_METHOD * method)37 void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method)
38 {
39     if (method != NULL)
40         OPENSSL_free(method->name);
41     OPENSSL_free(method);
42 }
43 
X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD * method,int (* new_item)(X509_LOOKUP * ctx))44 int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
45                                   int (*new_item) (X509_LOOKUP *ctx))
46 {
47     method->new_item = new_item;
48     return 1;
49 }
50 
X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD * method)51 int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
52     (X509_LOOKUP *ctx)
53 {
54     return method->new_item;
55 }
56 
X509_LOOKUP_meth_set_free(X509_LOOKUP_METHOD * method,void (* free_fn)(X509_LOOKUP * ctx))57 int X509_LOOKUP_meth_set_free(
58     X509_LOOKUP_METHOD *method,
59     void (*free_fn) (X509_LOOKUP *ctx))
60 {
61     method->free = free_fn;
62     return 1;
63 }
64 
X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD * method)65 void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
66     (X509_LOOKUP *ctx)
67 {
68     return method->free;
69 }
70 
X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD * method,int (* init)(X509_LOOKUP * ctx))71 int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
72                               int (*init) (X509_LOOKUP *ctx))
73 {
74     method->init = init;
75     return 1;
76 }
77 
X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD * method)78 int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
79     (X509_LOOKUP *ctx)
80 {
81     return method->init;
82 }
83 
X509_LOOKUP_meth_set_shutdown(X509_LOOKUP_METHOD * method,int (* shutdown)(X509_LOOKUP * ctx))84 int X509_LOOKUP_meth_set_shutdown(
85     X509_LOOKUP_METHOD *method,
86     int (*shutdown) (X509_LOOKUP *ctx))
87 {
88     method->shutdown = shutdown;
89     return 1;
90 }
91 
X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD * method)92 int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
93     (X509_LOOKUP *ctx)
94 {
95     return method->shutdown;
96 }
97 
X509_LOOKUP_meth_set_ctrl(X509_LOOKUP_METHOD * method,X509_LOOKUP_ctrl_fn ctrl)98 int X509_LOOKUP_meth_set_ctrl(
99     X509_LOOKUP_METHOD *method,
100     X509_LOOKUP_ctrl_fn ctrl)
101 {
102     method->ctrl = ctrl;
103     return 1;
104 }
105 
X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD * method)106 X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method)
107 {
108     return method->ctrl;
109 }
110 
X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD * method,X509_LOOKUP_get_by_subject_fn get_by_subject)111 int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
112     X509_LOOKUP_get_by_subject_fn get_by_subject)
113 {
114     method->get_by_subject = get_by_subject;
115     return 1;
116 }
117 
X509_LOOKUP_meth_get_get_by_subject(const X509_LOOKUP_METHOD * method)118 X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
119     const X509_LOOKUP_METHOD *method)
120 {
121     return method->get_by_subject;
122 }
123 
124 
X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD * method,X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial)125 int X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method,
126     X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial)
127 {
128     method->get_by_issuer_serial = get_by_issuer_serial;
129     return 1;
130 }
131 
132 X509_LOOKUP_get_by_issuer_serial_fn
X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD * method)133     X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD *method)
134 {
135     return method->get_by_issuer_serial;
136 }
137 
138 
X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD * method,X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint)139 int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
140     X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint)
141 {
142     method->get_by_fingerprint = get_by_fingerprint;
143     return 1;
144 }
145 
X509_LOOKUP_meth_get_get_by_fingerprint(const X509_LOOKUP_METHOD * method)146 X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
147     const X509_LOOKUP_METHOD *method)
148 {
149     return method->get_by_fingerprint;
150 }
151 
X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD * method,X509_LOOKUP_get_by_alias_fn get_by_alias)152 int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
153                                       X509_LOOKUP_get_by_alias_fn get_by_alias)
154 {
155     method->get_by_alias = get_by_alias;
156     return 1;
157 }
158 
X509_LOOKUP_meth_get_get_by_alias(const X509_LOOKUP_METHOD * method)159 X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
160     const X509_LOOKUP_METHOD *method)
161 {
162     return method->get_by_alias;
163 }
164 
165