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