openssl_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
161    pub fn X509_REQ_sign(x: *mut X509_REQ, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
162}
163
164const_ptr_api! {
165    extern "C" {
166        pub fn i2d_X509_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509) -> c_int;
167        pub fn i2d_X509_REQ_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509_REQ) -> c_int;
168        pub fn i2d_PrivateKey_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int;
169        pub fn i2d_PUBKEY_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int;
170
171        pub fn i2d_PUBKEY(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int;
172        pub fn i2d_RSA_PUBKEY(k: #[const_ptr_if(ossl300)] RSA, buf: *mut *mut u8) -> c_int;
173        pub fn i2d_DSA_PUBKEY(a: #[const_ptr_if(ossl300)] DSA, pp: *mut *mut c_uchar) -> c_int;
174        pub fn i2d_PrivateKey(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int;
175        pub fn i2d_ECPrivateKey(ec_key: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int;
176        pub fn i2d_EC_PUBKEY(a: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int;
177    }
178}
179extern "C" {
180    pub fn d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY;
181    pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
182    pub fn d2i_DSA_PUBKEY(k: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA;
183    pub fn d2i_EC_PUBKEY(
184        a: *mut *mut EC_KEY,
185        pp: *mut *const c_uchar,
186        length: c_long,
187    ) -> *mut EC_KEY;
188
189    pub fn d2i_ECPrivateKey(
190        k: *mut *mut EC_KEY,
191        pp: *mut *const c_uchar,
192        length: c_long,
193    ) -> *mut EC_KEY;
194}
195
196const_ptr_api! {
197    extern "C" {
198        #[cfg(any(ossl102, libressl350))]
199        pub fn X509_ALGOR_get0(
200            paobj: *mut #[const_ptr_if(any(ossl110, libressl350))] ASN1_OBJECT,
201            pptype: *mut c_int,
202            ppval: *mut #[const_ptr_if(any(ossl110, libressl350))] c_void,
203            alg: #[const_ptr_if(any(ossl110, libressl350))] X509_ALGOR,
204        );
205    }
206}
207
208extern "C" {
209    pub fn X509_gmtime_adj(time: *mut ASN1_TIME, adj: c_long) -> *mut ASN1_TIME;
210
211    pub fn X509_to_X509_REQ(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> *mut X509_REQ;
212
213    pub fn X509_ALGOR_free(x: *mut X509_ALGOR);
214
215    pub fn X509_REVOKED_new() -> *mut X509_REVOKED;
216    pub fn X509_REVOKED_free(x: *mut X509_REVOKED);
217}
218const_ptr_api! {
219    extern "C" {
220        #[cfg(any(ossl110, libressl270))]
221        pub fn X509_REVOKED_dup(rev: #[const_ptr_if(ossl300)] X509_REVOKED) -> *mut X509_REVOKED;
222    }
223}
224
225extern "C" {
226    pub fn d2i_X509_REVOKED(
227        a: *mut *mut X509_REVOKED,
228        pp: *mut *const c_uchar,
229        length: c_long,
230    ) -> *mut X509_REVOKED;
231}
232const_ptr_api! {
233    extern "C" {
234        pub fn i2d_X509_REVOKED(x: #[const_ptr_if(ossl300)] X509_REVOKED, buf: *mut *mut u8) -> c_int;
235    }
236}
237extern "C" {
238    pub fn X509_CRL_new() -> *mut X509_CRL;
239    pub fn X509_CRL_free(x: *mut X509_CRL);
240    pub fn d2i_X509_CRL(
241        a: *mut *mut X509_CRL,
242        pp: *mut *const c_uchar,
243        length: c_long,
244    ) -> *mut X509_CRL;
245}
246const_ptr_api! {
247    extern "C" {
248        pub fn i2d_X509_CRL(x: #[const_ptr_if(ossl300)] X509_CRL, buf: *mut *mut u8) -> c_int;
249        #[cfg(any(ossl110, libressl270))]
250        pub fn X509_CRL_dup(x: #[const_ptr_if(ossl300)] X509_CRL) -> *mut X509_CRL;
251    }
252}
253
254extern "C" {
255    pub fn X509_REQ_new() -> *mut X509_REQ;
256    pub fn X509_REQ_free(x: *mut X509_REQ);
257    pub fn d2i_X509_REQ(
258        a: *mut *mut X509_REQ,
259        pp: *mut *const c_uchar,
260        length: c_long,
261    ) -> *mut X509_REQ;
262}
263const_ptr_api! {
264    extern "C" {
265        pub fn i2d_X509_REQ(x: #[const_ptr_if(ossl300)] X509_REQ, buf: *mut *mut u8) -> c_int;
266
267        #[cfg(any(ossl102, libressl273))]
268        pub fn X509_get0_signature(
269            psig: *mut #[const_ptr_if(any(ossl110, libressl273))] ASN1_BIT_STRING,
270            palg: *mut #[const_ptr_if(any(ossl110, libressl273))] X509_ALGOR,
271            x: *const X509,
272        );
273
274        #[cfg(any(ossl110, libressl270))]
275        pub fn X509_REQ_dup(x: #[const_ptr_if(ossl300)] X509_REQ) -> *mut X509_REQ;
276    }
277}
278extern "C" {
279    #[cfg(ossl102)]
280    pub fn X509_get_signature_nid(x: *const X509) -> c_int;
281
282    pub fn X509_EXTENSION_free(ext: *mut X509_EXTENSION);
283
284    pub fn X509_NAME_ENTRY_free(x: *mut X509_NAME_ENTRY);
285
286    pub fn X509_NAME_new() -> *mut X509_NAME;
287    pub fn X509_NAME_cmp(x: *const X509_NAME, y: *const X509_NAME) -> c_int;
288    pub fn X509_NAME_free(x: *mut X509_NAME);
289
290    pub fn X509_new() -> *mut X509;
291    pub fn X509_free(x: *mut X509);
292}
293const_ptr_api! {
294    extern "C" {
295        pub fn i2d_X509(x: #[const_ptr_if(ossl300)] X509, buf: *mut *mut u8) -> c_int;
296        #[cfg(any(ossl110, libressl270))]
297        pub fn X509_NAME_dup(x: #[const_ptr_if(ossl300)] X509_NAME) -> *mut X509_NAME;
298        #[cfg(any(ossl110, libressl270))]
299        pub fn X509_dup(x: #[const_ptr_if(ossl300)] X509) -> *mut X509;
300        #[cfg(any(ossl101, libressl350))]
301        pub fn X509_NAME_add_entry(
302            name: *mut X509_NAME,
303            ne: #[const_ptr_if(any(ossl110, libressl))] X509_NAME_ENTRY,
304            loc: c_int,
305            set: c_int,
306            ) -> c_int;
307    }
308}
309extern "C" {
310    pub fn d2i_X509(a: *mut *mut X509, pp: *mut *const c_uchar, length: c_long) -> *mut X509;
311    pub fn d2i_X509_bio(b: *mut BIO, a: *mut *mut X509) -> *mut X509;
312
313    pub fn X509_get_pubkey(x: *mut X509) -> *mut EVP_PKEY;
314
315    pub fn X509_set_version(x: *mut X509, version: c_long) -> c_int;
316    #[cfg(ossl110)]
317    pub fn X509_get_version(x: *const X509) -> c_long;
318    pub fn X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int;
319    pub fn X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER;
320    pub fn X509_alias_get0(x: *mut X509, len: *mut c_int) -> *mut c_uchar;
321}
322const_ptr_api! {
323    extern "C" {
324        pub fn X509_set_issuer_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
325    }
326}
327extern "C" {
328    pub fn X509_issuer_name_hash(x: *mut X509) -> c_ulong;
329    pub fn X509_subject_name_hash(x: *mut X509) -> c_ulong;
330}
331const_ptr_api! {
332    extern "C" {
333        pub fn X509_get_issuer_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME;
334        pub fn X509_set_subject_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
335        pub fn X509_get_subject_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME;
336    }
337}
338cfg_if! {
339    if #[cfg(any(ossl110, libressl350))] {
340        extern "C" {
341            pub fn X509_set1_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
342            pub fn X509_set1_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
343        }
344    } else {
345        extern "C" {
346            pub fn X509_set_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
347            pub fn X509_set_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int;
348        }
349    }
350}
351extern "C" {
352    #[cfg(any(ossl110, libressl350))]
353    pub fn X509_REQ_get_version(req: *const X509_REQ) -> c_long;
354    pub fn X509_REQ_set_version(req: *mut X509_REQ, version: c_long) -> c_int;
355    #[cfg(any(ossl110, libressl350))]
356    pub fn X509_REQ_get_subject_name(req: *const X509_REQ) -> *mut X509_NAME;
357}
358const_ptr_api! {
359    extern "C" {
360        pub fn X509_REQ_set_subject_name(req: *mut X509_REQ, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
361    }
362}
363extern "C" {
364    pub fn X509_REQ_set_pubkey(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
365    pub fn X509_REQ_get_pubkey(req: *mut X509_REQ) -> *mut EVP_PKEY;
366    pub fn X509_REQ_get_extensions(req: *mut X509_REQ) -> *mut stack_st_X509_EXTENSION;
367}
368const_ptr_api! {
369    extern "C" {
370        pub fn X509_REQ_add_extensions(req: *mut X509_REQ, exts: #[const_ptr_if(ossl300)] stack_st_X509_EXTENSION)
371            -> c_int;
372    }
373}
374extern "C" {
375    pub fn X509_REQ_get_attr_count(req: *const X509_REQ) -> c_int;
376    pub fn X509_REQ_get_attr_by_NID(req: *const X509_REQ, nid: c_int, lastpos: c_int) -> c_int;
377    pub fn X509_REQ_get_attr(req: *const X509_REQ, loc: c_int) -> *mut X509_ATTRIBUTE;
378    pub fn X509_REQ_delete_attr(req: *mut X509_REQ, loc: c_int) -> *mut X509_ATTRIBUTE;
379    pub fn X509_REQ_add1_attr_by_txt(
380        req: *mut X509_REQ,
381        attrname: *const c_char,
382        chtype: c_int,
383        bytes: *const c_uchar,
384        len: c_int,
385    ) -> c_int;
386    pub fn X509_REQ_add1_attr_by_NID(
387        req: *mut X509_REQ,
388        nid: c_int,
389        chtype: c_int,
390        bytes: *const c_uchar,
391        len: c_int,
392    ) -> c_int;
393    pub fn X509_REQ_add1_attr_by_OBJ(
394        req: *mut X509_REQ,
395        obj: *const ASN1_OBJECT,
396        chtype: c_int,
397        bytes: *const c_uchar,
398        len: c_int,
399    ) -> c_int;
400}
401extern "C" {
402    pub fn X509_set_pubkey(x: *mut X509, pkey: *mut EVP_PKEY) -> c_int;
403    pub fn X509_REQ_verify(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
404    #[cfg(any(ossl110, libressl273))]
405    pub fn X509_getm_notBefore(x: *const X509) -> *mut ASN1_TIME;
406    #[cfg(any(ossl110, libressl273))]
407    pub fn X509_getm_notAfter(x: *const X509) -> *mut ASN1_TIME;
408    #[cfg(any(ossl110, libressl273))]
409    pub fn X509_up_ref(x: *mut X509) -> c_int;
410
411    #[cfg(any(ossl110, libressl270))]
412    pub fn X509_REVOKED_get0_serialNumber(req: *const X509_REVOKED) -> *const ASN1_INTEGER;
413    #[cfg(any(ossl110, libressl270))]
414    pub fn X509_REVOKED_get0_revocationDate(req: *const X509_REVOKED) -> *const ASN1_TIME;
415    #[cfg(any(ossl110, libressl270))]
416    pub fn X509_REVOKED_get0_extensions(r: *const X509_REVOKED) -> *const stack_st_X509_EXTENSION;
417
418    pub fn X509_REVOKED_set_serialNumber(r: *mut X509_REVOKED, serial: *mut ASN1_INTEGER) -> c_int;
419    pub fn X509_REVOKED_set_revocationDate(r: *mut X509_REVOKED, tm: *mut ASN1_TIME) -> c_int;
420
421    pub fn X509_CRL_sign(x: *mut X509_CRL, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
422    pub fn X509_CRL_digest(
423        x: *const X509_CRL,
424        digest: *const EVP_MD,
425        md: *mut c_uchar,
426        len: *mut c_uint,
427    ) -> c_int;
428    pub fn X509_CRL_verify(crl: *mut X509_CRL, pkey: *mut EVP_PKEY) -> c_int;
429    pub fn X509_CRL_get0_by_cert(
430        x: *mut X509_CRL,
431        ret: *mut *mut X509_REVOKED,
432        cert: *mut X509,
433    ) -> c_int;
434}
435const_ptr_api! {
436    extern "C" {
437        pub fn X509_CRL_get0_by_serial(
438            x: *mut X509_CRL,
439            ret: *mut *mut X509_REVOKED,
440            serial: #[const_ptr_if(ossl300)] ASN1_INTEGER,
441        ) -> c_int;
442    }
443}
444
445extern "C" {
446    #[cfg(any(ossl110, libressl281))]
447    pub fn X509_CRL_get_REVOKED(crl: *mut X509_CRL) -> *mut stack_st_X509_REVOKED;
448    #[cfg(any(ossl110, libressl281))]
449    pub fn X509_CRL_get0_nextUpdate(x: *const X509_CRL) -> *const ASN1_TIME;
450    #[cfg(any(ossl110, libressl281))]
451    pub fn X509_CRL_get0_lastUpdate(x: *const X509_CRL) -> *const ASN1_TIME;
452    #[cfg(any(ossl110, libressl281))]
453    pub fn X509_CRL_get_issuer(x: *const X509_CRL) -> *mut X509_NAME;
454
455    #[cfg(ossl110)]
456    pub fn X509_get0_extensions(req: *const X509) -> *const stack_st_X509_EXTENSION;
457
458    pub fn X509_CRL_set_version(crl: *mut X509_CRL, version: c_long) -> c_int;
459}
460const_ptr_api! {
461    extern "C" {
462        pub fn X509_CRL_set_issuer_name(crl: *mut X509_CRL, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int;
463    }
464}
465extern "C" {
466    pub fn X509_CRL_sort(crl: *mut X509_CRL) -> c_int;
467
468    #[cfg(any(ossl110, libressl270))]
469    pub fn X509_CRL_up_ref(crl: *mut X509_CRL) -> c_int;
470    pub fn X509_CRL_add0_revoked(crl: *mut X509_CRL, rev: *mut X509_REVOKED) -> c_int;
471}
472cfg_if! {
473    if #[cfg(any(ossl110, libressl270))] {
474        extern "C" {
475            pub fn X509_CRL_set1_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
476            pub fn X509_CRL_set1_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
477        }
478    } else {
479        // libressl270 kept them, ossl110 "#define"s them to the variants above
480        extern "C" {
481            pub fn X509_CRL_set_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
482            pub fn X509_CRL_set_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int;
483        }
484    }
485}
486
487const_ptr_api! {
488    extern "C" {
489        pub fn X509_NAME_entry_count(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME) -> c_int;
490        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;
491        pub fn X509_NAME_get_entry(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME, loc: c_int) -> *mut X509_NAME_ENTRY;
492        pub fn X509_NAME_add_entry_by_NID(
493            x: *mut X509_NAME,
494            field: c_int,
495            ty: c_int,
496            bytes: #[const_ptr_if(any(ossl110, libressl280))] c_uchar,
497            len: c_int,
498            loc: c_int,
499            set: c_int,
500        ) -> c_int;
501        pub fn i2d_X509_NAME(n: #[const_ptr_if(ossl300)] X509_NAME, buf: *mut *mut u8) -> c_int;
502        pub fn X509_NAME_ENTRY_get_object(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_OBJECT;
503        pub fn X509_NAME_ENTRY_get_data(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_STRING;
504    }
505}
506extern "C" {
507    pub fn X509_NAME_add_entry_by_txt(
508        x: *mut X509_NAME,
509        field: *const c_char,
510        ty: c_int,
511        bytes: *const c_uchar,
512        len: c_int,
513        loc: c_int,
514        set: c_int,
515    ) -> c_int;
516    pub fn d2i_X509_NAME(
517        n: *mut *mut X509_NAME,
518        pp: *mut *const c_uchar,
519        length: c_long,
520    ) -> *mut X509_NAME;
521}
522
523// "raw" X509_EXTENSION related functions
524extern "C" {
525    // in X509
526    pub fn X509_delete_ext(x: *mut X509, loc: c_int) -> *mut X509_EXTENSION;
527    pub fn X509_add_ext(x: *mut X509, ext: *mut X509_EXTENSION, loc: c_int) -> c_int;
528    pub fn X509_add1_ext_i2d(
529        x: *mut X509,
530        nid: c_int,
531        value: *mut c_void,
532        crit: c_int,
533        flags: c_ulong,
534    ) -> c_int;
535    // in X509_CRL
536    pub fn X509_CRL_delete_ext(x: *mut X509_CRL, loc: c_int) -> *mut X509_EXTENSION;
537    pub fn X509_CRL_add_ext(x: *mut X509_CRL, ext: *mut X509_EXTENSION, loc: c_int) -> c_int;
538    pub fn X509_CRL_add1_ext_i2d(
539        x: *mut X509_CRL,
540        nid: c_int,
541        value: *mut c_void,
542        crit: c_int,
543        flags: c_ulong,
544    ) -> c_int;
545    // in X509_REVOKED
546    pub fn X509_REVOKED_delete_ext(x: *mut X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION;
547    pub fn X509_REVOKED_add_ext(
548        x: *mut X509_REVOKED,
549        ext: *mut X509_EXTENSION,
550        loc: c_int,
551    ) -> c_int;
552    pub fn X509_REVOKED_add1_ext_i2d(
553        x: *mut X509_REVOKED,
554        nid: c_int,
555        value: *mut c_void,
556        crit: c_int,
557        flags: c_ulong,
558    ) -> c_int;
559    // X509_EXTENSION stack
560    // - these getters always used *const STACK
561    pub fn X509v3_get_ext_count(x: *const stack_st_X509_EXTENSION) -> c_int;
562    pub fn X509v3_get_ext_by_NID(
563        x: *const stack_st_X509_EXTENSION,
564        nid: c_int,
565        lastpos: c_int,
566    ) -> c_int;
567    pub fn X509v3_get_ext_by_critical(
568        x: *const stack_st_X509_EXTENSION,
569        crit: c_int,
570        lastpos: c_int,
571    ) -> c_int;
572    pub fn X509v3_get_ext(x: *const stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION;
573    pub fn X509v3_delete_ext(x: *mut stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION;
574    pub fn X509v3_add_ext(
575        x: *mut *mut stack_st_X509_EXTENSION,
576        ex: *mut X509_EXTENSION,
577        loc: c_int,
578    ) -> *mut stack_st_X509_EXTENSION;
579    // - X509V3_add1_i2d in x509v3.rs
580    // X509_EXTENSION itself
581    pub fn X509_EXTENSION_create_by_NID(
582        ex: *mut *mut X509_EXTENSION,
583        nid: c_int,
584        crit: c_int,
585        data: *mut ASN1_OCTET_STRING,
586    ) -> *mut X509_EXTENSION;
587    pub fn X509_EXTENSION_set_critical(ex: *mut X509_EXTENSION, crit: c_int) -> c_int;
588    pub fn X509_EXTENSION_set_data(ex: *mut X509_EXTENSION, data: *mut ASN1_OCTET_STRING) -> c_int;
589    pub fn X509_EXTENSION_get_object(ext: *mut X509_EXTENSION) -> *mut ASN1_OBJECT;
590    pub fn X509_EXTENSION_get_data(ext: *mut X509_EXTENSION) -> *mut ASN1_OCTET_STRING;
591}
592
593const_ptr_api! {
594    extern "C" {
595        pub fn i2d_X509_EXTENSION(ext: #[const_ptr_if(ossl300)] X509_EXTENSION, pp: *mut *mut c_uchar) -> c_int;
596    }
597}
598
599const_ptr_api! {
600    extern "C" {
601        // in X509
602        pub fn X509_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> c_int;
603        pub fn X509_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509, nid: c_int, lastpos: c_int) -> c_int;
604        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;
605        pub fn X509_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509, crit: c_int, lastpos: c_int) -> c_int;
606        pub fn X509_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509, loc: c_int) -> *mut X509_EXTENSION;
607        pub fn X509_get_ext_d2i(
608            x: #[const_ptr_if(any(ossl110, libressl280))] X509,
609            nid: c_int,
610            crit: *mut c_int,
611            idx: *mut c_int,
612        ) -> *mut c_void;
613        // in X509_CRL
614        pub fn X509_CRL_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL) -> c_int;
615        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;
616        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;
617        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;
618        pub fn X509_CRL_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, loc: c_int) -> *mut X509_EXTENSION;
619        pub fn X509_CRL_get_ext_d2i(
620            x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL,
621            nid: c_int,
622            crit: *mut c_int,
623            idx: *mut c_int,
624        ) -> *mut c_void;
625        // in X509_REVOKED
626        pub fn X509_REVOKED_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED) -> c_int;
627        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;
628        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;
629        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;
630        pub fn X509_REVOKED_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION;
631        pub fn X509_REVOKED_get_ext_d2i(
632            x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED,
633            nid: c_int,
634            crit: *mut c_int,
635            idx: *mut c_int,
636        ) -> *mut c_void;
637        // X509_EXTENSION stack
638        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;
639        // X509_EXTENSION itself
640        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;
641        pub fn X509_EXTENSION_set_object(ex: *mut X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT) -> c_int;
642        pub fn X509_EXTENSION_get_critical(ex: #[const_ptr_if(any(ossl110, libressl280))] X509_EXTENSION) -> c_int;
643    }
644}
645
646extern "C" {
647    pub fn X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int;
648}
649
650const_ptr_api! {
651    extern "C" {
652        #[cfg(any(ossl110, libressl270))]
653        pub fn X509_STORE_get0_objects(ctx: #[const_ptr_if(ossl300)] X509_STORE) -> *mut stack_st_X509_OBJECT;
654        #[cfg(ossl300)]
655        pub fn X509_STORE_get1_all_certs(ctx: *mut X509_STORE) -> *mut stack_st_X509;
656    }
657}
658
659#[cfg(any(ossl110, libressl270))]
660extern "C" {
661    pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509;
662}
663
664cfg_if! {
665    if #[cfg(any(ossl110, libressl350))] {
666        extern "C" {
667            pub fn X509_OBJECT_free(a: *mut X509_OBJECT);
668        }
669    } else {
670        extern "C" {
671            pub fn X509_OBJECT_free_contents(a: *mut X509_OBJECT);
672        }
673    }
674}
675
676extern "C" {
677    pub fn X509_get_default_cert_file_env() -> *const c_char;
678    pub fn X509_get_default_cert_file() -> *const c_char;
679    pub fn X509_get_default_cert_dir_env() -> *const c_char;
680    pub fn X509_get_default_cert_dir() -> *const c_char;
681}
682
683extern "C" {
684    pub fn X509_cmp(a: *const X509, b: *const X509) -> c_int;
685    pub fn X509_issuer_and_serial_cmp(a: *const X509, b: *const X509) -> c_int;
686    pub fn X509_issuer_name_cmp(a: *const X509, b: *const X509) -> c_int;
687    pub fn X509_subject_name_cmp(a: *const X509, b: *const X509) -> c_int;
688    pub fn X509_CRL_cmp(a: *const X509_CRL, b: *const X509_CRL) -> c_int;
689    pub fn X509_CRL_match(a: *const X509_CRL, b: *const X509_CRL) -> c_int;
690}
691
692extern "C" {
693    pub fn X509_print(bio: *mut BIO, x509: *mut X509) -> c_int;
694    pub fn X509_REQ_print(bio: *mut BIO, req: *mut X509_REQ) -> c_int;
695}
696
697cfg_if! {
698    if #[cfg(libressl390)] {
699        pub enum X509_PURPOSE {}
700    } else {
701        #[repr(C)]
702        pub struct X509_PURPOSE {
703            pub purpose: c_int,
704            pub trust: c_int, // Default trust ID
705            pub flags: c_int,
706            pub check_purpose:
707                Option<unsafe extern "C" fn(*const X509_PURPOSE, *const X509, c_int) -> c_int>,
708            pub name: *mut c_char,
709            pub sname: *mut c_char,
710            pub usr_data: *mut c_void,
711        }
712    }
713}
714
715const_ptr_api! {
716    extern "C" {
717        pub fn X509_PURPOSE_get_by_sname(sname: #[const_ptr_if(any(ossl110, libressl280))] c_char) -> c_int;
718        pub fn X509_PURPOSE_get_id(purpose: #[const_ptr_if(any(ossl110, libressl280))] X509_PURPOSE) -> c_int;
719        pub fn X509_PURPOSE_get0(idx: c_int) -> #[const_ptr_if(libressl390)] X509_PURPOSE;
720    }
721}
722
723extern "C" {
724    pub fn X509_ATTRIBUTE_new() -> *mut X509_ATTRIBUTE;
725    pub fn X509_ATTRIBUTE_free(attr: *mut X509_ATTRIBUTE);
726    pub fn X509_ATTRIBUTE_create(
727        nid: c_int,
728        atrtype: c_int,
729        value: *mut c_void,
730    ) -> *mut X509_ATTRIBUTE;
731    pub fn X509_ATTRIBUTE_create_by_NID(
732        attr: *mut *mut X509_ATTRIBUTE,
733        nid: c_int,
734        atrtype: c_int,
735        data: *const c_void,
736        len: c_int,
737    ) -> *mut X509_ATTRIBUTE;
738    pub fn X509_ATTRIBUTE_create_by_OBJ(
739        attr: *mut *mut X509_ATTRIBUTE,
740        obj: *const ASN1_OBJECT,
741        atrtype: c_int,
742        data: *const c_void,
743        len: c_int,
744    ) -> *mut X509_ATTRIBUTE;
745    pub fn X509_ATTRIBUTE_create_by_txt(
746        attr: *mut *mut X509_ATTRIBUTE,
747        atrname: *const c_char,
748        atrtype: c_int,
749        bytes: *const c_uchar,
750        len: c_int,
751    ) -> *mut X509_ATTRIBUTE;
752    pub fn X509_ATTRIBUTE_set1_object(attr: *mut X509_ATTRIBUTE, obj: *const ASN1_OBJECT) -> c_int;
753    pub fn X509_ATTRIBUTE_set1_data(
754        attr: *mut X509_ATTRIBUTE,
755        attrtype: c_int,
756        data: *const c_void,
757        len: c_int,
758    ) -> c_int;
759    pub fn X509_ATTRIBUTE_get0_data(
760        attr: *mut X509_ATTRIBUTE,
761        idx: c_int,
762        atrtype: c_int,
763        data: *mut c_void,
764    ) -> *mut c_void;
765    pub fn X509_ATTRIBUTE_get0_object(attr: *mut X509_ATTRIBUTE) -> *mut ASN1_OBJECT;
766    pub fn X509_ATTRIBUTE_get0_type(attr: *mut X509_ATTRIBUTE, idx: c_int) -> *mut ASN1_TYPE;
767    pub fn d2i_X509_ATTRIBUTE(
768        a: *mut *mut X509_ATTRIBUTE,
769        pp: *mut *const c_uchar,
770        length: c_long,
771    ) -> *mut X509_ATTRIBUTE;
772}
773const_ptr_api! {
774    extern "C" {
775        pub fn X509_ATTRIBUTE_count(
776            attr: #[const_ptr_if(any(ossl110, libressl280))] X509_ATTRIBUTE // const since OpenSSL v1.1.0
777        ) -> c_int;
778        pub fn i2d_X509_ATTRIBUTE(x: #[const_ptr_if(ossl300)] X509_ATTRIBUTE, buf: *mut *mut u8) -> c_int;
779        pub fn X509_ATTRIBUTE_dup(x: #[const_ptr_if(ossl300)] X509_ATTRIBUTE) -> *mut X509_ATTRIBUTE;
780    }
781}