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