variant_ssl_sys/handwritten/
x509.rs

1use super::super::*;
2use libc::*;
3
4cfg_if! {
5    if #[cfg(libressl400)] {
6        pub enum X509_VAL {}
7    } else {
8        #[repr(C)]
9        pub struct X509_VAL {
10            pub notBefore: *mut ASN1_TIME,
11            pub notAfter: *mut ASN1_TIME,
12        }
13    }
14}
15
16pub enum X509_NAME_ENTRY {}
17
18stack!(stack_st_X509_NAME_ENTRY);
19
20stack!(stack_st_X509_NAME);
21
22pub enum X509_EXTENSION {}
23
24stack!(stack_st_X509_EXTENSION);
25
26pub enum X509_ATTRIBUTE {}
27
28stack!(stack_st_X509_ATTRIBUTE);
29
30cfg_if! {
31    if #[cfg(any(ossl110, libressl350))] {
32        pub enum X509_REQ_INFO {}
33    } else {
34        #[repr(C)]
35        pub struct X509_REQ_INFO {
36            pub enc: ASN1_ENCODING,
37            pub version: *mut ASN1_INTEGER,
38            pub subject: *mut X509_NAME,
39            pubkey: *mut c_void,
40            pub attributes: *mut stack_st_X509_ATTRIBUTE,
41        }
42    }
43}
44
45cfg_if! {
46    if #[cfg(any(ossl110, libressl350))] {
47        pub enum X509_CRL {}
48    } else {
49        #[repr(C)]
50        pub struct X509_CRL {
51            pub crl: *mut X509_CRL_INFO,
52            sig_alg: *mut X509_ALGOR,
53            signature: *mut c_void,
54            references: c_int,
55            flags: c_int,
56            akid: *mut c_void,
57            idp: *mut c_void,
58            idp_flags: c_int,
59            idp_reasons: c_int,
60            crl_number: *mut ASN1_INTEGER,
61            base_crl_number: *mut ASN1_INTEGER,
62            sha1_hash: [c_uchar; 20],
63            issuers: *mut c_void,
64            meth: *const c_void,
65            meth_data: *mut c_void,
66        }
67    }
68}
69
70stack!(stack_st_X509_CRL);
71
72cfg_if! {
73    if #[cfg(any(ossl110, libressl350))] {
74        pub enum X509_CRL_INFO {}
75    } else {
76        #[repr(C)]
77        pub struct X509_CRL_INFO {
78            version: *mut ASN1_INTEGER,
79            sig_alg: *mut X509_ALGOR,
80            pub issuer: *mut X509_NAME,
81            pub lastUpdate: *mut ASN1_TIME,
82            pub nextUpdate: *mut ASN1_TIME,
83            pub revoked: *mut stack_st_X509_REVOKED,
84            extensions: *mut stack_st_X509_EXTENSION,
85            enc: ASN1_ENCODING,
86        }
87    }
88}
89
90cfg_if! {
91    if #[cfg(any(ossl110, libressl350))] {
92        pub enum X509_REVOKED {}
93    } else {
94        #[repr(C)]
95        pub struct X509_REVOKED {
96            pub serialNumber: *mut ASN1_INTEGER,
97            pub revocationDate: *mut ASN1_TIME,
98            pub extensions: *mut stack_st_X509_EXTENSION,
99            issuer: *mut stack_st_GENERAL_NAME,
100            reason: c_int,
101            sequence: c_int,
102        }
103    }
104}
105
106stack!(stack_st_X509_REVOKED);
107
108cfg_if! {
109    if #[cfg(any(ossl110, libressl350))] {
110        pub enum X509_REQ {}
111    } else {
112        #[repr(C)]
113        pub struct X509_REQ {
114            pub req_info: *mut X509_REQ_INFO,
115            sig_alg: *mut c_void,
116            signature: *mut c_void,
117            references: c_int,
118        }
119    }
120}
121
122cfg_if! {
123    if #[cfg(any(ossl110, libressl350))] {
124        pub enum X509_CINF {}
125    } else {
126        #[repr(C)]
127        pub struct X509_CINF {
128            version: *mut c_void,
129            serialNumber: *mut c_void,
130            signature: *mut c_void,
131            issuer: *mut c_void,
132            pub validity: *mut X509_VAL,
133            subject: *mut c_void,
134            key: *mut c_void,
135            issuerUID: *mut c_void,
136            subjectUID: *mut c_void,
137            pub extensions: *mut stack_st_X509_EXTENSION,
138            enc: ASN1_ENCODING,
139        }
140    }
141}
142
143stack!(stack_st_X509);
144
145stack!(stack_st_X509_OBJECT);
146
147stack!(stack_st_X509_LOOKUP);
148
149extern "C" {
150    pub fn X509_verify_cert_error_string(n: c_long) -> *const c_char;
151
152    pub fn X509_sign(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
153
154    pub fn X509_digest(
155        x: *const X509,
156        digest: *const EVP_MD,
157        buf: *mut c_uchar,
158        len: *mut c_uint,
159    ) -> c_int;
160    pub fn X509_pubkey_digest(
161        x: *const X509,
162        digest: *const EVP_MD,
163        buf: *mut c_uchar,
164        len: *mut c_uint,
165    ) -> c_int;
166
167    pub fn X509_REQ_sign(x: *mut X509_REQ, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
168    pub fn X509_REQ_digest(
169        x: *const X509_REQ,
170        digest: *const EVP_MD,
171        md: *mut c_uchar,
172        len: *mut c_uint,
173    ) -> c_int;
174}
175
176const_ptr_api! {
177    extern "C" {
178        pub fn i2d_X509_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509) -> c_int;
179        pub fn i2d_X509_REQ_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509_REQ) -> c_int;
180        pub fn i2d_PrivateKey_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int;
181        pub fn i2d_PUBKEY_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int;
182
183        pub fn i2d_PUBKEY(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int;
184        pub fn i2d_PrivateKey(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int;
185    }
186}
187
188#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
189const_ptr_api! {
190    extern "C" {
191        pub fn i2d_RSA_PUBKEY(k: #[const_ptr_if(ossl300)] RSA, buf: *mut *mut u8) -> c_int;
192        pub fn i2d_DSA_PUBKEY(a: #[const_ptr_if(ossl300)] DSA, pp: *mut *mut c_uchar) -> c_int;
193        pub fn i2d_ECPrivateKey(ec_key: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int;
194        pub fn i2d_EC_PUBKEY(a: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int;
195    }
196}
197extern "C" {
198    pub fn d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY;
199}
200
201#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
202extern "C" {
203    pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
204    pub fn d2i_DSA_PUBKEY(k: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA;
205    pub fn d2i_EC_PUBKEY(
206        a: *mut *mut EC_KEY,
207        pp: *mut *const c_uchar,
208        length: c_long,
209    ) -> *mut EC_KEY;
210
211    pub fn d2i_ECPrivateKey(
212        k: *mut *mut EC_KEY,
213        pp: *mut *const c_uchar,
214        length: c_long,
215    ) -> *mut EC_KEY;
216}
217
218const_ptr_api! {
219    extern "C" {
220        #[cfg(any(ossl102, libressl350))]
221        pub fn X509_ALGOR_get0(
222            paobj: *mut #[const_ptr_if(any(ossl110, libressl350))] ASN1_OBJECT,
223            pptype: *mut c_int,
224            ppval: *mut #[const_ptr_if(any(ossl110, libressl350))] c_void,
225            alg: #[const_ptr_if(any(ossl110, libressl350))] X509_ALGOR,
226        );
227    }
228}
229
230extern "C" {
231    pub fn X509_gmtime_adj(time: *mut ASN1_TIME, adj: c_long) -> *mut ASN1_TIME;
232
233    pub fn X509_to_X509_REQ(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> *mut X509_REQ;
234
235    pub fn X509_ALGOR_free(x: *mut X509_ALGOR);
236
237    pub fn X509_REVOKED_new() -> *mut X509_REVOKED;
238    pub fn X509_REVOKED_free(x: *mut X509_REVOKED);
239}
240const_ptr_api! {
241    extern "C" {
242        #[cfg(any(ossl110, libressl270))]
243        pub fn X509_REVOKED_dup(rev: #[const_ptr_if(ossl300)] X509_REVOKED) -> *mut X509_REVOKED;
244    }
245}
246
247extern "C" {
248    pub fn d2i_X509_REVOKED(
249        a: *mut *mut X509_REVOKED,
250        pp: *mut *const c_uchar,
251        length: c_long,
252    ) -> *mut X509_REVOKED;
253}
254const_ptr_api! {
255    extern "C" {
256        pub fn i2d_X509_REVOKED(x: #[const_ptr_if(ossl300)] X509_REVOKED, buf: *mut *mut u8) -> c_int;
257    }
258}
259extern "C" {
260    pub fn X509_CRL_new() -> *mut X509_CRL;
261    pub fn X509_CRL_free(x: *mut X509_CRL);
262    pub fn d2i_X509_CRL(
263        a: *mut *mut X509_CRL,
264        pp: *mut *const c_uchar,
265        length: c_long,
266    ) -> *mut X509_CRL;
267}
268const_ptr_api! {
269    extern "C" {
270        pub fn i2d_X509_CRL(x: #[const_ptr_if(ossl300)] X509_CRL, buf: *mut *mut u8) -> c_int;
271        #[cfg(any(ossl110, libressl270))]
272        pub fn X509_CRL_dup(x: #[const_ptr_if(ossl300)] X509_CRL) -> *mut X509_CRL;
273    }
274}
275
276extern "C" {
277    pub fn X509_REQ_new() -> *mut X509_REQ;
278    pub fn X509_REQ_free(x: *mut X509_REQ);
279    pub fn d2i_X509_REQ(
280        a: *mut *mut X509_REQ,
281        pp: *mut *const c_uchar,
282        length: c_long,
283    ) -> *mut X509_REQ;
284}
285const_ptr_api! {
286    extern "C" {
287        pub fn i2d_X509_REQ(x: #[const_ptr_if(ossl300)] X509_REQ, buf: *mut *mut u8) -> c_int;
288
289        #[cfg(any(ossl102, libressl273))]
290        pub fn X509_get0_signature(
291            psig: *mut #[const_ptr_if(any(ossl110, libressl273))] ASN1_BIT_STRING,
292            palg: *mut #[const_ptr_if(any(ossl110, libressl273))] X509_ALGOR,
293            x: *const X509,
294        );
295
296        #[cfg(any(ossl110, libressl270))]
297        pub fn X509_REQ_dup(x: #[const_ptr_if(ossl300)] X509_REQ) -> *mut X509_REQ;
298    }
299}
300extern "C" {
301    #[cfg(ossl102)]
302    pub fn X509_get_signature_nid(x: *const X509) -> c_int;
303
304    pub fn X509_EXTENSION_free(ext: *mut X509_EXTENSION);
305
306    pub fn X509_NAME_ENTRY_free(x: *mut X509_NAME_ENTRY);
307
308    pub fn X509_NAME_new() -> *mut X509_NAME;
309    pub fn X509_NAME_cmp(x: *const X509_NAME, y: *const X509_NAME) -> c_int;
310    pub fn X509_NAME_free(x: *mut X509_NAME);
311
312    pub fn X509_NAME_digest(
313        data: *const X509_NAME,
314        type_: *const EVP_MD,
315        md: *mut c_uchar,
316        len: *mut c_uint,
317    ) -> c_int;
318
319    pub fn X509_new() -> *mut X509;
320    pub fn X509_free(x: *mut X509);
321}
322const_ptr_api! {
323    extern "C" {
324        pub fn i2d_X509(x: #[const_ptr_if(ossl300)] X509, buf: *mut *mut u8) -> c_int;
325        #[cfg(any(ossl110, libressl270))]
326        pub fn X509_NAME_dup(x: #[const_ptr_if(ossl300)] X509_NAME) -> *mut X509_NAME;
327        #[cfg(any(ossl110, libressl270))]
328        pub fn X509_dup(x: #[const_ptr_if(ossl300)] X509) -> *mut X509;
329        #[cfg(any(ossl101, libressl350))]
330        pub fn X509_NAME_add_entry(
331            name: *mut X509_NAME,
332            ne: #[const_ptr_if(any(ossl110, libressl))] X509_NAME_ENTRY,
333            loc: c_int,
334            set: c_int,
335            ) -> c_int;
336    }
337}
338extern "C" {
339    pub fn d2i_X509(a: *mut *mut X509, pp: *mut *const c_uchar, length: c_long) -> *mut X509;
340    pub fn d2i_X509_bio(b: *mut BIO, a: *mut *mut X509) -> *mut X509;
341
342    pub fn X509_get_pubkey(x: *mut X509) -> *mut EVP_PKEY;
343
344    pub fn X509_set_version(x: *mut X509, version: c_long) -> c_int;
345    #[cfg(any(ossl110, libressl282))]
346    pub fn X509_get_version(x: *const X509) -> c_long;
347    pub fn X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int;
348    pub fn X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER;
349    pub fn X509_alias_get0(x: *mut X509, len: *mut c_int) -> *mut c_uchar;
350}
351const_ptr_api! {
352    extern "C" {
353        pub fn X509_set_issuer_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
354    }
355}
356extern "C" {
357    pub fn X509_issuer_name_hash(x: *mut X509) -> c_ulong;
358    pub fn X509_subject_name_hash(x: *mut X509) -> c_ulong;
359}
360const_ptr_api! {
361    extern "C" {
362        pub fn X509_get_issuer_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME;
363        pub fn X509_set_subject_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
364        pub fn X509_get_subject_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME;
365    }
366}
367cfg_if! {
368    if #[cfg(any(ossl110, libressl350))] {
369        extern "C" {
370            pub fn X509_set1_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
371            pub fn X509_set1_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
372        }
373    } else {
374        extern "C" {
375            pub fn X509_set_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
376            pub fn X509_set_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
377        }
378    }
379}
380extern "C" {
381    #[cfg(any(ossl110, libressl350))]
382    pub fn X509_REQ_get_version(req: *const X509_REQ) -> c_long;
383    pub fn X509_REQ_set_version(req: *mut X509_REQ, version: c_long) -> c_int;
384    #[cfg(any(ossl110, libressl350))]
385    pub fn X509_REQ_get_subject_name(req: *const X509_REQ) -> *mut X509_NAME;
386}
387const_ptr_api! {
388    extern "C" {
389        pub fn X509_REQ_set_subject_name(req: *mut X509_REQ, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
390    }
391}
392extern "C" {
393    pub fn X509_REQ_set_pubkey(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
394    pub fn X509_REQ_get_pubkey(req: *mut X509_REQ) -> *mut EVP_PKEY;
395    #[cfg(ossl110)]
396    pub fn X509_REQ_get_X509_PUBKEY(req: *mut X509_REQ) -> *mut X509_PUBKEY;
397    pub fn X509_REQ_get_extensions(req: *mut X509_REQ) -> *mut stack_st_X509_EXTENSION;
398}
399cfg_if! {
400    if #[cfg(tongsuo)] {
401        extern "C" {
402            pub fn X509_set0_sm2_id(x: *mut X509, sm2_id: *mut ASN1_OCTET_STRING);
403            pub fn X509_get0_sm2_id(x: *mut X509) -> *mut ASN1_OCTET_STRING;
404            pub fn X509_REQ_set0_sm2_id(x: *mut X509_REQ, sm2_id: *mut ASN1_OCTET_STRING);
405            pub fn X509_REQ_get0_sm2_id(x: *mut X509_REQ) -> *mut ASN1_OCTET_STRING;
406        }
407    }
408}
409const_ptr_api! {
410    extern "C" {
411        pub fn X509_REQ_add_extensions(req: *mut X509_REQ, exts: #[const_ptr_if(ossl300)] stack_st_X509_EXTENSION)
412            -> c_int;
413    }
414}
415extern "C" {
416    pub fn X509_REQ_get_attr_count(req: *const X509_REQ) -> c_int;
417    pub fn X509_REQ_get_attr_by_NID(req: *const X509_REQ, nid: c_int, lastpos: c_int) -> c_int;
418    pub fn X509_REQ_get_attr(req: *const X509_REQ, loc: c_int) -> *mut X509_ATTRIBUTE;
419    pub fn X509_REQ_delete_attr(req: *mut X509_REQ, loc: c_int) -> *mut X509_ATTRIBUTE;
420    pub fn X509_REQ_add1_attr_by_txt(
421        req: *mut X509_REQ,
422        attrname: *const c_char,
423        chtype: c_int,
424        bytes: *const c_uchar,
425        len: c_int,
426    ) -> c_int;
427    pub fn X509_REQ_add1_attr_by_NID(
428        req: *mut X509_REQ,
429        nid: c_int,
430        chtype: c_int,
431        bytes: *const c_uchar,
432        len: c_int,
433    ) -> c_int;
434    pub fn X509_REQ_add1_attr_by_OBJ(
435        req: *mut X509_REQ,
436        obj: *const ASN1_OBJECT,
437        chtype: c_int,
438        bytes: *const c_uchar,
439        len: c_int,
440    ) -> c_int;
441}
442extern "C" {
443    pub fn X509_set_pubkey(x: *mut X509, pkey: *mut EVP_PKEY) -> c_int;
444    pub fn X509_REQ_verify(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
445    #[cfg(any(ossl110, libressl273))]
446    pub fn X509_getm_notBefore(x: *const X509) -> *mut ASN1_TIME;
447    #[cfg(any(ossl110, libressl273))]
448    pub fn X509_getm_notAfter(x: *const X509) -> *mut ASN1_TIME;
449    #[cfg(any(ossl110, libressl273))]
450    pub fn X509_up_ref(x: *mut X509) -> c_int;
451
452    #[cfg(any(ossl110, libressl270))]
453    pub fn X509_REVOKED_get0_serialNumber(req: *const X509_REVOKED) -> *const ASN1_INTEGER;
454    #[cfg(any(ossl110, libressl270))]
455    pub fn X509_REVOKED_get0_revocationDate(req: *const X509_REVOKED) -> *const ASN1_TIME;
456    #[cfg(any(ossl110, libressl270))]
457    pub fn X509_REVOKED_get0_extensions(r: *const X509_REVOKED) -> *const stack_st_X509_EXTENSION;
458
459    pub fn X509_REVOKED_set_serialNumber(r: *mut X509_REVOKED, serial: *mut ASN1_INTEGER) -> c_int;
460    pub fn X509_REVOKED_set_revocationDate(r: *mut X509_REVOKED, tm: *mut ASN1_TIME) -> c_int;
461
462    pub fn X509_CRL_sign(x: *mut X509_CRL, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
463    pub fn X509_CRL_digest(
464        x: *const X509_CRL,
465        digest: *const EVP_MD,
466        md: *mut c_uchar,
467        len: *mut c_uint,
468    ) -> c_int;
469    pub fn X509_CRL_verify(crl: *mut X509_CRL, pkey: *mut EVP_PKEY) -> c_int;
470    pub fn X509_CRL_get0_by_cert(
471        x: *mut X509_CRL,
472        ret: *mut *mut X509_REVOKED,
473        cert: *mut X509,
474    ) -> c_int;
475}
476const_ptr_api! {
477    extern "C" {
478        pub fn X509_CRL_get0_by_serial(
479            x: *mut X509_CRL,
480            ret: *mut *mut X509_REVOKED,
481            serial: #[const_ptr_if(ossl300)] ASN1_INTEGER,
482        ) -> c_int;
483    }
484}
485
486extern "C" {
487    pub fn X509_PUBKEY_new() -> *mut X509_PUBKEY;
488    pub fn X509_PUBKEY_free(a: *mut X509_PUBKEY);
489    #[cfg(ossl300)]
490    pub fn X509_PUBKEY_dup(a: *const X509_PUBKEY) -> *mut X509_PUBKEY;
491    #[cfg(ossl300)]
492    pub fn X509_PUBKEY_eq(a: *const X509_PUBKEY, b: *const X509_PUBKEY) -> c_int;
493    pub fn d2i_X509_PUBKEY(
494        a: *mut *mut X509_PUBKEY,
495        in_: *mut *const c_uchar,
496        len: c_long,
497    ) -> *mut X509_PUBKEY;
498    #[cfg(ossl300)]
499    pub fn X509_PUBKEY_new_ex(libctx: *mut OSSL_LIB_CTX, propq: *const c_char) -> *mut X509_PUBKEY;
500    pub fn X509_PUBKEY_set(x: *mut *mut X509_PUBKEY, pkey: *mut EVP_PKEY) -> c_int;
501
502    pub fn X509_PUBKEY_set0_param(
503        pub_: *mut X509_PUBKEY,
504        aobj: *mut ASN1_OBJECT,
505        ptype: c_int,
506        pval: *mut c_void,
507        penc: *mut c_uchar,
508        penclen: c_int,
509    ) -> c_int;
510}
511const_ptr_api! {
512    extern "C" {
513       pub fn i2d_X509_PUBKEY(a: #[const_ptr_if(ossl300)] X509_PUBKEY, out: *mut *mut c_uchar) -> c_int;
514       pub fn X509_PUBKEY_get0_param(
515           ppkalg: *mut *mut ASN1_OBJECT,
516           pk: *mut *const c_uchar,
517           ppklen: *mut c_int,
518           pa: *mut *mut X509_ALGOR,
519           pub_: #[const_ptr_if(ossl300)] X509_PUBKEY,
520       ) -> c_int;
521       pub fn X509_PUBKEY_get(key: #[const_ptr_if(ossl300)] X509_PUBKEY) -> *mut EVP_PKEY;
522       pub fn X509_PUBKEY_get0(key: #[const_ptr_if(ossl300)] X509_PUBKEY) -> *mut EVP_PKEY;
523    }
524}
525
526extern "C" {
527    #[cfg(any(ossl110, libressl281))]
528    pub fn X509_CRL_get_REVOKED(crl: *mut X509_CRL) -> *mut stack_st_X509_REVOKED;
529    #[cfg(any(ossl110, libressl281))]
530    pub fn X509_CRL_get0_nextUpdate(x: *const X509_CRL) -> *const ASN1_TIME;
531    #[cfg(any(ossl110, libressl281))]
532    pub fn X509_CRL_get0_lastUpdate(x: *const X509_CRL) -> *const ASN1_TIME;
533    #[cfg(any(ossl110, libressl281))]
534    pub fn X509_CRL_get_issuer(x: *const X509_CRL) -> *mut X509_NAME;
535
536    #[cfg(any(ossl110, libressl272))]
537    pub fn X509_get0_extensions(req: *const X509) -> *const stack_st_X509_EXTENSION;
538    #[cfg(any(ossl110, boringssl))]
539    pub fn X509_get_X509_PUBKEY(x: *const X509) -> *mut X509_PUBKEY;
540
541    pub fn X509_CRL_set_version(crl: *mut X509_CRL, version: c_long) -> c_int;
542}
543const_ptr_api! {
544    extern "C" {
545        pub fn X509_CRL_set_issuer_name(crl: *mut X509_CRL, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
546    }
547}
548extern "C" {
549    pub fn X509_CRL_sort(crl: *mut X509_CRL) -> c_int;
550
551    #[cfg(any(ossl110, libressl270))]
552    pub fn X509_CRL_up_ref(crl: *mut X509_CRL) -> c_int;
553    pub fn X509_CRL_add0_revoked(crl: *mut X509_CRL, rev: *mut X509_REVOKED) -> c_int;
554}
555cfg_if! {
556    if #[cfg(any(ossl110, libressl270))] {
557        extern "C" {
558            pub fn X509_CRL_set1_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
559            pub fn X509_CRL_set1_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
560        }
561    } else {
562        // libressl270 kept them, ossl110 "#define"s them to the variants above
563        extern "C" {
564            pub fn X509_CRL_set_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
565            pub fn X509_CRL_set_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
566        }
567    }
568}
569
570const_ptr_api! {
571    extern "C" {
572        pub fn X509_NAME_entry_count(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME) -> c_int;
573        pub fn X509_NAME_get_index_by_NID(n: #[const_ptr_if(any(ossl300, libressl280))] X509_NAME, nid: c_int, last_pos: c_int) -> c_int;
574        pub fn X509_NAME_get_entry(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME, loc: c_int) -> *mut X509_NAME_ENTRY;
575        pub fn X509_NAME_add_entry_by_NID(
576            x: *mut X509_NAME,
577            field: c_int,
578            ty: c_int,
579            bytes: #[const_ptr_if(any(ossl110, libressl280))] c_uchar,
580            len: c_int,
581            loc: c_int,
582            set: c_int,
583        ) -> c_int;
584        pub fn i2d_X509_NAME(n: #[const_ptr_if(ossl300)] X509_NAME, buf: *mut *mut u8) -> c_int;
585        pub fn X509_NAME_ENTRY_get_object(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_OBJECT;
586        pub fn X509_NAME_ENTRY_get_data(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_STRING;
587    }
588}
589extern "C" {
590    pub fn X509_NAME_add_entry_by_txt(
591        x: *mut X509_NAME,
592        field: *const c_char,
593        ty: c_int,
594        bytes: *const c_uchar,
595        len: c_int,
596        loc: c_int,
597        set: c_int,
598    ) -> c_int;
599    pub fn d2i_X509_NAME(
600        n: *mut *mut X509_NAME,
601        pp: *mut *const c_uchar,
602        length: c_long,
603    ) -> *mut X509_NAME;
604}
605
606// "raw" X509_EXTENSION related functions
607extern "C" {
608    // in X509
609    pub fn X509_delete_ext(x: *mut X509, loc: c_int) -> *mut X509_EXTENSION;
610    pub fn X509_add_ext(x: *mut X509, ext: *mut X509_EXTENSION, loc: c_int) -> c_int;
611    pub fn X509_add1_ext_i2d(
612        x: *mut X509,
613        nid: c_int,
614        value: *mut c_void,
615        crit: c_int,
616        flags: c_ulong,
617    ) -> c_int;
618    // in X509_CRL
619    pub fn X509_CRL_delete_ext(x: *mut X509_CRL, loc: c_int) -> *mut X509_EXTENSION;
620    pub fn X509_CRL_add_ext(x: *mut X509_CRL, ext: *mut X509_EXTENSION, loc: c_int) -> c_int;
621    pub fn X509_CRL_add1_ext_i2d(
622        x: *mut X509_CRL,
623        nid: c_int,
624        value: *mut c_void,
625        crit: c_int,
626        flags: c_ulong,
627    ) -> c_int;
628    // in X509_REVOKED
629    pub fn X509_REVOKED_delete_ext(x: *mut X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION;
630    pub fn X509_REVOKED_add_ext(
631        x: *mut X509_REVOKED,
632        ext: *mut X509_EXTENSION,
633        loc: c_int,
634    ) -> c_int;
635    pub fn X509_REVOKED_add1_ext_i2d(
636        x: *mut X509_REVOKED,
637        nid: c_int,
638        value: *mut c_void,
639        crit: c_int,
640        flags: c_ulong,
641    ) -> c_int;
642    // X509_EXTENSION stack
643    // - these getters always used *const STACK
644    pub fn X509v3_get_ext_count(x: *const stack_st_X509_EXTENSION) -> c_int;
645    pub fn X509v3_get_ext_by_NID(
646        x: *const stack_st_X509_EXTENSION,
647        nid: c_int,
648        lastpos: c_int,
649    ) -> c_int;
650    pub fn X509v3_get_ext_by_critical(
651        x: *const stack_st_X509_EXTENSION,
652        crit: c_int,
653        lastpos: c_int,
654    ) -> c_int;
655    pub fn X509v3_get_ext(x: *const stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION;
656    pub fn X509v3_delete_ext(x: *mut stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION;
657    pub fn X509v3_add_ext(
658        x: *mut *mut stack_st_X509_EXTENSION,
659        ex: *mut X509_EXTENSION,
660        loc: c_int,
661    ) -> *mut stack_st_X509_EXTENSION;
662    // - X509V3_add1_i2d in x509v3.rs
663    // X509_EXTENSION itself
664    pub fn X509_EXTENSION_create_by_NID(
665        ex: *mut *mut X509_EXTENSION,
666        nid: c_int,
667        crit: c_int,
668        data: *mut ASN1_OCTET_STRING,
669    ) -> *mut X509_EXTENSION;
670    pub fn X509_EXTENSION_set_critical(ex: *mut X509_EXTENSION, crit: c_int) -> c_int;
671    pub fn X509_EXTENSION_set_data(ex: *mut X509_EXTENSION, data: *mut ASN1_OCTET_STRING) -> c_int;
672    pub fn X509_EXTENSION_get_object(ext: *mut X509_EXTENSION) -> *mut ASN1_OBJECT;
673    pub fn X509_EXTENSION_get_data(ext: *mut X509_EXTENSION) -> *mut ASN1_OCTET_STRING;
674}
675
676const_ptr_api! {
677    extern "C" {
678        pub fn i2d_X509_EXTENSION(ext: #[const_ptr_if(ossl300)] X509_EXTENSION, pp: *mut *mut c_uchar) -> c_int;
679    }
680}
681
682const_ptr_api! {
683    extern "C" {
684        // in X509
685        pub fn X509_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> c_int;
686        pub fn X509_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509, nid: c_int, lastpos: c_int) -> c_int;
687        pub fn X509_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int;
688        pub fn X509_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509, crit: c_int, lastpos: c_int) -> c_int;
689        pub fn X509_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509, loc: c_int) -> *mut X509_EXTENSION;
690        pub fn X509_get_ext_d2i(
691            x: #[const_ptr_if(any(ossl110, libressl280))] X509,
692            nid: c_int,
693            crit: *mut c_int,
694            idx: *mut c_int,
695        ) -> *mut c_void;
696        // in X509_CRL
697        pub fn X509_CRL_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL) -> c_int;
698        pub fn X509_CRL_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, nid: c_int, lastpos: c_int) -> c_int;
699        pub fn X509_CRL_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int;
700        pub fn X509_CRL_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, crit: c_int, lastpos: c_int) -> c_int;
701        pub fn X509_CRL_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, loc: c_int) -> *mut X509_EXTENSION;
702        pub fn X509_CRL_get_ext_d2i(
703            x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL,
704            nid: c_int,
705            crit: *mut c_int,
706            idx: *mut c_int,
707        ) -> *mut c_void;
708        // in X509_REVOKED
709        pub fn X509_REVOKED_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED) -> c_int;
710        pub fn X509_REVOKED_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, nid: c_int, lastpos: c_int) -> c_int;
711        pub fn X509_REVOKED_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int;
712        pub fn X509_REVOKED_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, crit: c_int, lastpos: c_int) -> c_int;
713        pub fn X509_REVOKED_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION;
714        pub fn X509_REVOKED_get_ext_d2i(
715            x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED,
716            nid: c_int,
717            crit: *mut c_int,
718            idx: *mut c_int,
719        ) -> *mut c_void;
720        // X509_EXTENSION stack
721        pub fn X509v3_get_ext_by_OBJ(x: *const stack_st_X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int;
722        // X509_EXTENSION itself
723        pub fn X509_EXTENSION_create_by_OBJ(ex: *mut *mut X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, crit: c_int, data: *mut ASN1_OCTET_STRING) -> *mut X509_EXTENSION;
724        pub fn X509_EXTENSION_set_object(ex: *mut X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT) -> c_int;
725        pub fn X509_EXTENSION_get_critical(ex: #[const_ptr_if(any(ossl110, libressl280))] X509_EXTENSION) -> c_int;
726    }
727}
728
729extern "C" {
730    pub fn X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int;
731}
732
733const_ptr_api! {
734    extern "C" {
735        #[cfg(any(ossl110, libressl270))]
736        pub fn X509_STORE_get0_objects(ctx: #[const_ptr_if(ossl300)] X509_STORE) -> *mut stack_st_X509_OBJECT;
737        #[cfg(ossl330)]
738        pub fn X509_STORE_get1_objects(ctx: *mut X509_STORE) -> *mut stack_st_X509_OBJECT;
739        #[cfg(ossl300)]
740        pub fn X509_STORE_get1_all_certs(ctx: *mut X509_STORE) -> *mut stack_st_X509;
741    }
742}
743
744#[cfg(any(ossl110, libressl270))]
745extern "C" {
746    pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509;
747}
748
749cfg_if! {
750    if #[cfg(any(ossl110, libressl350))] {
751        extern "C" {
752            pub fn X509_OBJECT_free(a: *mut X509_OBJECT);
753        }
754    } else {
755        extern "C" {
756            pub fn X509_OBJECT_free_contents(a: *mut X509_OBJECT);
757        }
758    }
759}
760
761extern "C" {
762    pub fn X509_get_default_cert_file_env() -> *const c_char;
763    pub fn X509_get_default_cert_file() -> *const c_char;
764    pub fn X509_get_default_cert_dir_env() -> *const c_char;
765    pub fn X509_get_default_cert_dir() -> *const c_char;
766}
767
768extern "C" {
769    pub fn X509_cmp(a: *const X509, b: *const X509) -> c_int;
770    pub fn X509_issuer_and_serial_cmp(a: *const X509, b: *const X509) -> c_int;
771    pub fn X509_issuer_name_cmp(a: *const X509, b: *const X509) -> c_int;
772    pub fn X509_subject_name_cmp(a: *const X509, b: *const X509) -> c_int;
773    pub fn X509_CRL_cmp(a: *const X509_CRL, b: *const X509_CRL) -> c_int;
774    pub fn X509_CRL_match(a: *const X509_CRL, b: *const X509_CRL) -> c_int;
775}
776
777extern "C" {
778    pub fn X509_print(bio: *mut BIO, x509: *mut X509) -> c_int;
779    pub fn X509_REQ_print(bio: *mut BIO, req: *mut X509_REQ) -> c_int;
780}
781
782cfg_if! {
783    if #[cfg(libressl390)] {
784        pub enum X509_PURPOSE {}
785    } else {
786        #[repr(C)]
787        pub struct X509_PURPOSE {
788            pub purpose: c_int,
789            pub trust: c_int, // Default trust ID
790            pub flags: c_int,
791            pub check_purpose:
792                Option<unsafe extern "C" fn(*const X509_PURPOSE, *const X509, c_int) -> c_int>,
793            pub name: *mut c_char,
794            pub sname: *mut c_char,
795            pub usr_data: *mut c_void,
796        }
797    }
798}
799
800const_ptr_api! {
801    extern "C" {
802        pub fn X509_PURPOSE_get_by_sname(sname: #[const_ptr_if(any(ossl110, libressl280))] c_char) -> c_int;
803        pub fn X509_PURPOSE_get_id(purpose: #[const_ptr_if(any(ossl110, libressl280))] X509_PURPOSE) -> c_int;
804        pub fn X509_PURPOSE_get0(idx: c_int) -> #[const_ptr_if(libressl390)] X509_PURPOSE;
805    }
806}
807
808extern "C" {
809    pub fn X509_ATTRIBUTE_new() -> *mut X509_ATTRIBUTE;
810    pub fn X509_ATTRIBUTE_free(attr: *mut X509_ATTRIBUTE);
811    pub fn X509_ATTRIBUTE_create(
812        nid: c_int,
813        atrtype: c_int,
814        value: *mut c_void,
815    ) -> *mut X509_ATTRIBUTE;
816    pub fn X509_ATTRIBUTE_create_by_NID(
817        attr: *mut *mut X509_ATTRIBUTE,
818        nid: c_int,
819        atrtype: c_int,
820        data: *const c_void,
821        len: c_int,
822    ) -> *mut X509_ATTRIBUTE;
823    pub fn X509_ATTRIBUTE_create_by_OBJ(
824        attr: *mut *mut X509_ATTRIBUTE,
825        obj: *const ASN1_OBJECT,
826        atrtype: c_int,
827        data: *const c_void,
828        len: c_int,
829    ) -> *mut X509_ATTRIBUTE;
830    pub fn X509_ATTRIBUTE_create_by_txt(
831        attr: *mut *mut X509_ATTRIBUTE,
832        atrname: *const c_char,
833        atrtype: c_int,
834        bytes: *const c_uchar,
835        len: c_int,
836    ) -> *mut X509_ATTRIBUTE;
837    pub fn X509_ATTRIBUTE_set1_object(attr: *mut X509_ATTRIBUTE, obj: *const ASN1_OBJECT) -> c_int;
838    pub fn X509_ATTRIBUTE_set1_data(
839        attr: *mut X509_ATTRIBUTE,
840        attrtype: c_int,
841        data: *const c_void,
842        len: c_int,
843    ) -> c_int;
844    pub fn X509_ATTRIBUTE_get0_data(
845        attr: *mut X509_ATTRIBUTE,
846        idx: c_int,
847        atrtype: c_int,
848        data: *mut c_void,
849    ) -> *mut c_void;
850    pub fn X509_ATTRIBUTE_get0_object(attr: *mut X509_ATTRIBUTE) -> *mut ASN1_OBJECT;
851    pub fn X509_ATTRIBUTE_get0_type(attr: *mut X509_ATTRIBUTE, idx: c_int) -> *mut ASN1_TYPE;
852    pub fn d2i_X509_ATTRIBUTE(
853        a: *mut *mut X509_ATTRIBUTE,
854        pp: *mut *const c_uchar,
855        length: c_long,
856    ) -> *mut X509_ATTRIBUTE;
857}
858const_ptr_api! {
859    extern "C" {
860        pub fn X509_ATTRIBUTE_count(
861            attr: #[const_ptr_if(any(ossl110, libressl280))] X509_ATTRIBUTE // const since OpenSSL v1.1.0
862        ) -> c_int;
863        pub fn i2d_X509_ATTRIBUTE(x: #[const_ptr_if(ossl300)] X509_ATTRIBUTE, buf: *mut *mut u8) -> c_int;
864        pub fn X509_ATTRIBUTE_dup(x: #[const_ptr_if(ossl300)] X509_ATTRIBUTE) -> *mut X509_ATTRIBUTE;
865    }
866}