1use crate::ffi_types::*;
2
3use crate::pubkey::{botan_privkey_t, botan_pubkey_t};
4use crate::rng::botan_rng_t;
5
6use crate::mp::botan_mp_t;
7
8use crate::oid::botan_asn1_oid_t;
9
10pub enum botan_x509_cert_struct {}
11pub type botan_x509_cert_t = *mut botan_x509_cert_struct;
12
13pub enum botan_x509_crl_struct {}
14pub type botan_x509_crl_t = *mut botan_x509_crl_struct;
15
16pub enum botan_x509_crl_entry_struct {}
17pub type botan_x509_crl_entry_t = *mut botan_x509_crl_entry_struct;
18
19pub enum botan_x509_general_name_struct {}
20pub type botan_x509_general_name_t = *mut botan_x509_general_name_struct;
21
22#[repr(u32)]
23#[allow(clippy::upper_case_acronyms)]
24pub enum X509KeyConstraints {
25 NO_CONSTRAINTS = 0,
26 DIGITAL_SIGNATURE = 32768,
27 NON_REPUDIATION = 16384,
28 KEY_ENCIPHERMENT = 8192,
29 DATA_ENCIPHERMENT = 4096,
30 KEY_AGREEMENT = 2048,
31 KEY_CERT_SIGN = 1024,
32 CRL_SIGN = 512,
33 ENCIPHER_ONLY = 256,
34 DECIPHER_ONLY = 128,
35}
36
37#[repr(i32)]
38pub enum X509ValueType {
39 BOTAN_X509_SERIAL_NUMBER = 0,
40 BOTAN_X509_SUBJECT_DN_BITS = 1,
41 BOTAN_X509_ISSUER_DN_BITS = 2,
42 BOTAN_X509_SUBJECT_KEY_IDENTIFIER = 3,
43 BOTAN_X509_AUTHORITY_KEY_IDENTIFIER = 4,
44 BOTAN_X509_PUBLIC_KEY_PKCS8_BITS = 200,
45 BOTAN_X509_TBS_DATA_BITS = 201,
46 BOTAN_X509_SIGNATURE_SCHEME_BITS = 202,
47 BOTAN_X509_SIGNATURE_BITS = 203,
48 BOTAN_X509_DER_ENCODING = 300,
49 BOTAN_X509_PEM_ENCODING = 301,
50 BOTAN_X509_CRL_DISTRIBUTION_URLS = 400,
51 BOTAN_X509_OCSP_RESPONDER_URLS = 401,
52 BOTAN_X509_CA_ISSUERS_URLS = 402,
53}
54
55#[repr(i32)]
56pub enum X509GeneralNameType {
57 BOTAN_X509_OTHER_NAME = 0,
58 BOTAN_X509_EMAIL_ADDRESS = 1,
59 BOTAN_X509_DNS_NAME = 2,
60 BOTAN_X509_DIRECTORY_NAME = 4,
61 BOTAN_X509_URI = 6,
62 BOTAN_X509_IP_ADDRESS = 7,
63}
64
65#[repr(i32)]
66pub enum X509CrlReasonCode {
67 BOTAN_CRL_ENTRY_UNSPECIFIED = 0,
68 BOTAN_CRL_ENTRY_KEY_COMPROMISE = 1,
69 BOTAN_CRL_ENTRY_CA_COMPROMISE = 2,
70 BOTAN_CRL_ENTRY_AFFILIATION_CHANGED = 3,
71 BOTAN_CRL_ENTRY_SUPERSEDED = 4,
72 BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION = 5,
73 BOTAN_CRL_ENTRY_CERTIFICATE_HOLD = 6,
74 BOTAN_CRL_ENTRY_REMOVE_FROM_CRL = 8,
75 BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN = 9,
76 BOTAN_CRL_ENTRY_AA_COMPROMISE = 10,
77}
78
79impl TryFrom<i32> for X509CrlReasonCode {
80 type Error = ();
81
82 fn try_from(value: i32) -> core::result::Result<Self, Self::Error> {
83 match value {
84 0 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_UNSPECIFIED),
85 1 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_KEY_COMPROMISE),
86 2 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_CA_COMPROMISE),
87 3 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_AFFILIATION_CHANGED),
88 4 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_SUPERSEDED),
89 5 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION),
90 6 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_CERTIFICATE_HOLD),
91 8 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_REMOVE_FROM_CRL),
92 9 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN),
93 10 => Ok(X509CrlReasonCode::BOTAN_CRL_ENTRY_AA_COMPROMISE),
94 _ => Err(()),
95 }
96 }
97}
98
99botan_ffi_functions! {
100 pub fn botan_x509_cert_load(
101 cert_obj: *mut botan_x509_cert_t,
102 cert: *const u8,
103 cert_len: usize,
104 ) -> c_int;
105 pub fn botan_x509_cert_dup(cert_obj: *mut botan_x509_cert_t, cert: botan_x509_cert_t) -> c_int;
106 pub fn botan_x509_cert_load_file(
107 cert_obj: *mut botan_x509_cert_t,
108 filename: *const c_char,
109 ) -> c_int;
110 pub fn botan_x509_cert_destroy(cert: botan_x509_cert_t) -> c_int;
111
112 #[cfg(botan_ffi_20260303)]
113 pub fn botan_x509_cert_view_binary_values(
114 cert: botan_x509_cert_t,
115 value_type: c_int,
116 index: usize,
117 ctx: botan_view_ctx,
118 view: botan_view_bin_fn,
119 ) -> c_int;
120
121 #[cfg(botan_ffi_20260303)]
122 pub fn botan_x509_cert_view_binary_values_count(
123 cert: botan_x509_cert_t,
124 value_type: c_int,
125 count: *mut usize,
126 ) -> c_int;
127
128 #[cfg(botan_ffi_20260303)]
129 pub fn botan_x509_cert_view_string_values(
130 cert: botan_x509_cert_t,
131 value_type: c_int,
132 index: usize,
133 ctx: botan_view_ctx,
134 view: botan_view_str_fn,
135 ) -> c_int;
136
137 #[cfg(botan_ffi_20260303)]
138 pub fn botan_x509_cert_view_string_values_count(
139 cert: botan_x509_cert_t,
140 value_type: c_int,
141 count: *mut usize,
142 ) -> c_int;
143
144 pub fn botan_x509_cert_get_time_starts(
145 cert: botan_x509_cert_t,
146 out: *mut c_char,
147 out_len: *mut usize,
148 ) -> c_int;
149 pub fn botan_x509_cert_get_time_expires(
150 cert: botan_x509_cert_t,
151 out: *mut c_char,
152 out_len: *mut usize,
153 ) -> c_int;
154 pub fn botan_x509_cert_not_before(cert: botan_x509_cert_t, timestamp: *mut u64) -> c_int;
155 pub fn botan_x509_cert_not_after(cert: botan_x509_cert_t, timestamp: *mut u64) -> c_int;
156 pub fn botan_x509_cert_get_fingerprint(
157 cert: botan_x509_cert_t,
158 hash: *const c_char,
159 out: *mut u8,
160 out_len: *mut usize,
161 ) -> c_int;
162 pub fn botan_x509_cert_get_serial_number(
163 cert: botan_x509_cert_t,
164 out: *mut u8,
165 out_len: *mut usize,
166 ) -> c_int;
167
168 #[cfg(botan_ffi_20260303)]
169 pub fn botan_x509_cert_serial_number(
170 cert: botan_x509_cert_t,
171 serial_number: *mut botan_mp_t,
172 ) -> c_int;
173
174 pub fn botan_x509_cert_get_authority_key_id(
175 cert: botan_x509_cert_t,
176 out: *mut u8,
177 out_len: *mut usize,
178 ) -> c_int;
179 pub fn botan_x509_cert_get_subject_key_id(
180 cert: botan_x509_cert_t,
181 out: *mut u8,
182 out_len: *mut usize,
183 ) -> c_int;
184 pub fn botan_x509_cert_get_public_key_bits(
185 cert: botan_x509_cert_t,
186 out: *mut u8,
187 out_len: *mut usize,
188 ) -> c_int;
189
190 #[cfg(botan_ffi_20230403)]
191 pub fn botan_x509_cert_view_public_key_bits(
192 cert: botan_x509_cert_t,
193 view_ctx: botan_view_ctx,
194 view_fn: botan_view_bin_fn,
195 ) -> c_int;
196
197 pub fn botan_x509_cert_get_public_key(
198 cert: botan_x509_cert_t,
199 key: *mut botan_pubkey_t,
200 ) -> c_int;
201
202 #[cfg(botan_ffi_20260303)]
203 pub fn botan_x509_cert_is_ca(cert: botan_x509_cert_t) -> c_int;
204
205 #[cfg(botan_ffi_20260303)]
206 pub fn botan_x509_cert_get_path_length_constraint(
207 cert: botan_x509_cert_t,
208 path_limit: *mut usize,
209 ) -> c_int;
210
211 pub fn botan_x509_cert_get_issuer_dn(
212 cert: botan_x509_cert_t,
213 key: *const c_char,
214 index: usize,
215 out: *mut u8,
216 out_len: *mut usize,
217 ) -> c_int;
218
219 #[cfg(botan_ffi_20260303)]
220 pub fn botan_x509_cert_get_issuer_dn_count(
221 cert: botan_x509_cert_t,
222 key: *const c_char,
223 count: *mut usize,
224 ) -> c_int;
225
226 pub fn botan_x509_cert_get_subject_dn(
227 cert: botan_x509_cert_t,
228 key: *const c_char,
229 index: usize,
230 out: *mut u8,
231 out_len: *mut usize,
232 ) -> c_int;
233
234 #[cfg(botan_ffi_20260303)]
235 pub fn botan_x509_cert_get_subject_dn_count(
236 cert: botan_x509_cert_t,
237 key: *const c_char,
238 count: *mut usize,
239 ) -> c_int;
240
241 pub fn botan_x509_cert_to_string(
242 cert: botan_x509_cert_t,
243 out: *mut c_char,
244 out_len: *mut usize,
245 ) -> c_int;
246
247 #[cfg(botan_ffi_20230403)]
248 pub fn botan_x509_cert_view_as_string(
249 cert: botan_x509_cert_t,
250 view_ctx: botan_view_ctx,
251 view_fn: botan_view_str_fn,
252 ) -> c_int;
253
254 pub fn botan_x509_cert_allowed_usage(cert: botan_x509_cert_t, key_usage: c_uint) -> c_int;
255
256 #[cfg(botan_ffi_20260303)]
257 pub fn botan_x509_cert_allowed_extended_usage_str(
258 cert: botan_x509_cert_t,
259 oid: *const c_char,
260 ) -> c_int;
261
262 #[cfg(botan_ffi_20260303)]
263 pub fn botan_x509_cert_allowed_extended_usage_oid(
264 cert: botan_x509_cert_t,
265 oid: botan_asn1_oid_t,
266 ) -> c_int;
267
268 #[cfg(botan_ffi_20260303)]
269 pub fn botan_x509_general_name_get_type(
270 name: botan_x509_general_name_t,
271 name_type: *mut c_uint,
272 ) -> c_int;
273
274 #[cfg(botan_ffi_20260303)]
275 pub fn botan_x509_general_name_view_string_value(
276 name: botan_x509_general_name_t,
277 ctx: botan_view_ctx,
278 view: botan_view_str_fn,
279 ) -> c_int;
280
281 #[cfg(botan_ffi_20260303)]
282 pub fn botan_x509_general_name_view_binary_value(
283 name: botan_x509_general_name_t,
284 ctx: botan_view_ctx,
285 view: botan_view_bin_fn,
286 ) -> c_int;
287
288 #[cfg(botan_ffi_20260303)]
289 pub fn botan_x509_general_name_destroy(alt_names: botan_x509_general_name_t) -> c_int;
290
291 #[cfg(botan_ffi_20260303)]
292 pub fn botan_x509_cert_permitted_name_constraints(
293 cert: botan_x509_cert_t,
294 index: usize,
295 constraint: *mut botan_x509_general_name_t,
296 ) -> c_int;
297
298 #[cfg(botan_ffi_20260303)]
299 pub fn botan_x509_cert_permitted_name_constraints_count(
300 cert: botan_x509_cert_t,
301 count: *mut usize,
302 ) -> c_int;
303
304 #[cfg(botan_ffi_20260303)]
305 pub fn botan_x509_cert_excluded_name_constraints(
306 cert: botan_x509_cert_t,
307 index: usize,
308 constraint: *mut botan_x509_general_name_t,
309 ) -> c_int;
310
311 #[cfg(botan_ffi_20260303)]
312 pub fn botan_x509_cert_excluded_name_constraints_count(
313 cert: botan_x509_cert_t,
314 count: *mut usize,
315 ) -> c_int;
316
317 #[cfg(botan_ffi_20260303)]
318 pub fn botan_x509_cert_subject_alternative_names(
319 cert: botan_x509_cert_t,
320 index: usize,
321 alt_name: *mut botan_x509_general_name_t,
322 ) -> c_int;
323
324 #[cfg(botan_ffi_20260303)]
325 pub fn botan_x509_cert_subject_alternative_names_count(
326 cert: botan_x509_cert_t,
327 count: *mut usize,
328 ) -> c_int;
329
330 #[cfg(botan_ffi_20260303)]
331 pub fn botan_x509_cert_issuer_alternative_names(
332 cert: botan_x509_cert_t,
333 index: usize,
334 alt_name: *mut botan_x509_general_name_t,
335 ) -> c_int;
336
337 #[cfg(botan_ffi_20260303)]
338 pub fn botan_x509_cert_issuer_alternative_names_count(
339 cert: botan_x509_cert_t,
340 count: *mut usize,
341 ) -> c_int;
342
343 pub fn botan_x509_cert_hostname_match(
344 cert: botan_x509_cert_t,
345 hostname: *const c_char,
346 ) -> c_int;
347
348 pub fn botan_x509_cert_verify(
349 validation_result: *mut c_int,
350 ee_cert: botan_x509_cert_t,
351 intermediates: *const botan_x509_cert_t,
352 intermediates_len: usize,
353 trusted: *const botan_x509_cert_t,
354 trusted_len: usize,
355 trusted_path: *const c_char,
356 required_key_strength: usize,
357 hostname: *const c_char,
358 reference_time: u64,
359 ) -> c_int;
360
361 pub fn botan_x509_cert_validation_status(code: c_int) -> *const c_char = core::ptr::null();
362
363 #[cfg(botan_ffi_20260811)]
364 pub fn botan_x509_ext_ip_addr_blocks_get_counts(
365 cert: botan_x509_cert_t,
366 v4_count: *mut usize,
367 v6_count: *mut usize,
368 ) -> c_int;
369
370 #[cfg(botan_ffi_20260811)]
371 pub fn botan_x509_ext_ip_addr_blocks_get_family(
372 cert: botan_x509_cert_t,
373 ipv6: c_int,
374 i: usize,
375 has_safi: *mut c_int,
376 safi: *mut u8,
377 present: *mut c_int,
378 count: *mut usize,
379 ) -> c_int;
380
381 #[cfg(botan_ffi_20260811)]
382 pub fn botan_x509_ext_ip_addr_blocks_get_address(
383 cert: botan_x509_cert_t,
384 ipv6: c_int,
385 i: usize,
386 entry: usize,
387 min_out: *mut u8,
388 max_out: *mut u8,
389 out_len: *mut usize,
390 ) -> c_int;
391
392 #[cfg(botan_ffi_20260811)]
393 pub fn botan_x509_ext_as_blocks_get_info(
394 cert: botan_x509_cert_t,
395 asnum: c_int,
396 present: *mut c_int,
397 count: *mut usize,
398 ) -> c_int;
399
400 #[cfg(botan_ffi_20260811)]
401 pub fn botan_x509_ext_as_blocks_get_entry_at(
402 cert: botan_x509_cert_t,
403 asnum: c_int,
404 i: usize,
405 min: *mut u32,
406 max: *mut u32,
407 ) -> c_int;
408
409 pub fn botan_x509_crl_load_file(crl: *mut botan_x509_crl_t, file_path: *const c_char) -> c_int;
410
411 pub fn botan_x509_crl_load(
412 crl: *mut botan_x509_crl_t,
413 data: *const u8,
414 data_len: usize,
415 ) -> c_int;
416
417 #[cfg(botan_ffi_20260303)]
418 pub fn botan_x509_crl_this_update(crl: botan_x509_crl_t, time_since_epoch: *mut u64) -> c_int;
419
420 #[cfg(botan_ffi_20260303)]
421 pub fn botan_x509_crl_next_update(crl: botan_x509_crl_t, time_since_epoch: *mut u64) -> c_int;
422
423 #[cfg(botan_ffi_20260303)]
424 pub fn botan_x509_crl_create(
425 crl_obj: *mut botan_x509_crl_t,
426 rng: botan_rng_t,
427 ca_cert: botan_x509_cert_t,
428 ca_key: botan_privkey_t,
429 issue_time: u64,
430 next_update: u32,
431 hash_fn: *const c_char,
432 padding: *const c_char,
433 ) -> c_int;
434
435 #[cfg(botan_ffi_20260303)]
436 pub fn botan_x509_crl_entry_create(
437 entry: *mut botan_x509_crl_entry_t,
438 cert: botan_x509_cert_t,
439 reason_code: c_int,
440 ) -> c_int;
441
442 #[cfg(botan_ffi_20260303)]
443 pub fn botan_x509_crl_update(
444 crl_obj: *mut botan_x509_crl_t,
445 last_crl: botan_x509_crl_t,
446 rng: botan_rng_t,
447 ca_cert: botan_x509_cert_t,
448 ca_key: botan_privkey_t,
449 issue_time: u64,
450 next_update: u32,
451 new_entries: *const botan_x509_crl_entry_t,
452 new_entries_len: usize,
453 hash_fn: *const c_char,
454 padding: *const c_char,
455 ) -> c_int;
456
457 #[cfg(botan_ffi_20260303)]
458 pub fn botan_x509_crl_verify_signature(crl: botan_x509_crl_t, key: botan_pubkey_t) -> c_int;
459
460 pub fn botan_x509_crl_destroy(crl: botan_x509_crl_t) -> c_int;
461
462 #[cfg(botan_ffi_20260303)]
463 pub fn botan_x509_crl_view_binary_values(
464 crl_obj: botan_x509_crl_t,
465 value_type: c_int,
466 index: usize,
467 ctx: botan_view_ctx,
468 view: botan_view_bin_fn,
469 ) -> c_int;
470
471 #[cfg(botan_ffi_20260303)]
472 pub fn botan_x509_crl_view_binary_values_count(
473 crl_obj: botan_x509_crl_t,
474 value_type: c_int,
475 count: *mut usize,
476 ) -> c_int;
477
478 #[cfg(botan_ffi_20260303)]
479 pub fn botan_x509_crl_view_string_values(
480 crl_obj: botan_x509_crl_t,
481 value_type: c_int,
482 index: usize,
483 ctx: botan_view_ctx,
484 view: botan_view_str_fn,
485 ) -> c_int;
486
487 #[cfg(botan_ffi_20260303)]
488 pub fn botan_x509_crl_view_string_values_count(
489 crl_obj: botan_x509_crl_t,
490 value_type: c_int,
491 count: *mut usize,
492 ) -> c_int;
493
494 pub fn botan_x509_is_revoked(crl: botan_x509_crl_t, cert: botan_x509_cert_t) -> c_int;
495
496 #[cfg(botan_ffi_20260303)]
497 pub fn botan_x509_crl_entries(
498 crl: botan_x509_crl_t,
499 index: usize,
500 entry: *mut botan_x509_crl_entry_t,
501 ) -> c_int;
502
503 #[cfg(botan_ffi_20260303)]
504 pub fn botan_x509_crl_entries_count(crl: botan_x509_crl_t, count: *mut usize) -> c_int;
505
506 #[cfg(botan_ffi_20260303)]
507 pub fn botan_x509_crl_entry_reason(
508 entry: botan_x509_crl_entry_t,
509 reason_code: *mut c_int,
510 ) -> c_int;
511
512 #[cfg(botan_ffi_20260303)]
513 pub fn botan_x509_crl_entry_revocation_date(
514 entry: botan_x509_crl_entry_t,
515 time_since_epoch: *mut u64,
516 ) -> c_int;
517
518 #[cfg(botan_ffi_20260303)]
519 pub fn botan_x509_crl_entry_serial_number(
520 entry: botan_x509_crl_entry_t,
521 serial_number: *mut botan_mp_t,
522 ) -> c_int;
523
524 #[cfg(botan_ffi_20260303)]
525 pub fn botan_x509_crl_entry_view_serial_number(
526 entry: botan_x509_crl_entry_t,
527 ctx: botan_view_ctx,
528 view: botan_view_bin_fn,
529 ) -> c_int;
530
531 #[cfg(botan_ffi_20260303)]
532 pub fn botan_x509_crl_entry_destroy(entry: botan_x509_crl_entry_t) -> c_int;
533
534 pub fn botan_x509_cert_verify_with_crl(
535 validation_result: *mut c_int,
536 ee_cert: botan_x509_cert_t,
537 intermediates: *const botan_x509_cert_t,
538 intermediates_len: usize,
539 trusted: *const botan_x509_cert_t,
540 trusted_len: usize,
541 crls: *const botan_x509_crl_t,
542 crls_len: usize,
543 trusted_path: *const c_char,
544 required_key_strength: usize,
545 hostname: *const c_char,
546 reference_time: u64,
547 ) -> c_int;
548}