botan-sys-0.10.5/.cargo_vcs_info.json0000644000000001470000000000100130400ustar { "git": { "sha1": "132583ab4f783b1de125efd46d0ad1357cff76c7" }, "path_in_vcs": "botan-sys" }botan-sys-0.10.5/Cargo.toml0000644000000021540000000000100110360ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.58" name = "botan-sys" version = "0.10.5" authors = ["Jack Lloyd "] build = "build.rs" links = "botan-2" description = "FFI wrapper for Botan cryptography library" homepage = "https://botan.randombit.net/" documentation = "https://docs.rs/botan-sys" readme = "README.md" categories = [ "cryptography", "external-ffi-bindings", "no-std", ] license = "MIT" repository = "https://github.com/randombit/botan-rs" resolver = "1" [build-dependencies.botan-src] version = "0.30101.2" optional = true [features] botan3 = [] default = [] no-std = [] vendored = [ "botan-src", "botan3", ] botan-sys-0.10.5/Cargo.toml.orig000064400000000000000000000012201046102023000145100ustar 00000000000000[package] name = "botan-sys" version = "0.10.5" authors = ["Jack Lloyd "] links = "botan-2" build = "build.rs" description = "FFI wrapper for Botan cryptography library" license = "MIT" homepage = "https://botan.randombit.net/" repository = "https://github.com/randombit/botan-rs" documentation = "https://docs.rs/botan-sys" readme = "README.md" categories = [ "cryptography", "external-ffi-bindings", "no-std" ] edition = "2021" rust-version = "1.58" [features] default = [] no-std = [] vendored = ["botan-src", "botan3"] botan3 = [] [build-dependencies] botan-src = { version = "0.30101.2", optional = true, path = "../botan-src" } botan-sys-0.10.5/README.md000064400000000000000000000004231046102023000131040ustar 00000000000000# botan-sys This crate contains the FFI declarations for calling the C API included in the [Botan](https://botan.randombit.net/) cryptography library. A high level Rust interface built on these declarations is included in the [botan](https://crates.io/crates/botan) crate. botan-sys-0.10.5/build.rs000064400000000000000000000027261046102023000133020ustar 00000000000000#[cfg(feature = "vendored")] fn emit_dylibs() -> Vec<&'static str> { // Windows doesn't need to dynamically link the C++ runtime // but we do need to link to DLLs with needed functionality: if cfg!(target_os = "windows") { return vec!["user32", "crypt32"]; } // On Linux we use libstdc++ if cfg!(any(target_os = "linux")) { return vec!["stdc++"]; } // For all other platforms, link to libc++ from LLVM/Clang vec!["c++"] } fn botan_lib_major_version() -> i32 { if cfg!(any(feature = "vendored", feature = "botan3")) { 3 } else { 2 } } fn botan_library_name() -> String { let major_version = botan_lib_major_version(); if cfg!(target_os = "windows") && major_version == 2 { // For some unknown reason, Botan 2.x does not include // the major version in the name of the Windows library "botan".to_string() } else { format!("botan-{major_version}") } } fn main() { #[cfg(feature = "vendored")] { let (lib_dir, _) = botan_src::build(); println!("cargo:vendored=1"); println!("cargo:rustc-link-search=native={}", &lib_dir); println!("cargo:rustc-link-lib=static={}", botan_library_name(),); for dylib in emit_dylibs() { println!("cargo:rustc-flags=-l dylib={}", dylib); } } #[cfg(not(feature = "vendored"))] { println!("cargo:rustc-link-lib={}", botan_library_name()); } } botan-sys-0.10.5/src/block.rs000064400000000000000000000024531046102023000140610ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_block_cipher_struct {} pub type botan_block_cipher_t = *mut botan_block_cipher_struct; extern "C" { pub fn botan_block_cipher_init( bc: *mut botan_block_cipher_t, cipher_name: *const c_char, ) -> c_int; pub fn botan_block_cipher_destroy(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_name( bc: botan_block_cipher_t, name: *mut c_char, name_len: *mut usize, ) -> c_int; pub fn botan_block_cipher_get_keyspec( bc: botan_block_cipher_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_block_cipher_clear(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_set_key( bc: botan_block_cipher_t, key: *const u8, len: usize, ) -> c_int; pub fn botan_block_cipher_block_size(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_encrypt_blocks( bc: botan_block_cipher_t, input: *const u8, output: *mut u8, blocks: usize, ) -> c_int; pub fn botan_block_cipher_decrypt_blocks( bc: botan_block_cipher_t, input: *const u8, output: *mut u8, blocks: usize, ) -> c_int; } botan-sys-0.10.5/src/cipher.rs000064400000000000000000000041711046102023000142400ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_cipher_struct {} pub type botan_cipher_t = *mut botan_cipher_struct; extern "C" { pub fn botan_cipher_init(cipher: *mut botan_cipher_t, name: *const c_char, flags: u32) -> c_int; pub fn botan_cipher_valid_nonce_length(cipher: botan_cipher_t, nl: usize) -> c_int; pub fn botan_cipher_get_tag_length(cipher: botan_cipher_t, tag_size: *mut usize) -> c_int; pub fn botan_cipher_get_default_nonce_length(cipher: botan_cipher_t, nl: *mut usize) -> c_int; pub fn botan_cipher_get_update_granularity(cipher: botan_cipher_t, ug: *mut usize) -> c_int; #[cfg(feature = "botan3")] pub fn botan_cipher_get_ideal_update_granularity( cipher: botan_cipher_t, ug: *mut usize, ) -> c_int; pub fn botan_cipher_query_keylen( cipher: botan_cipher_t, out_minimum_keylength: *mut usize, out_maximum_keylength: *mut usize, ) -> c_int; pub fn botan_cipher_get_keyspec( cipher: botan_cipher_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_cipher_set_key(cipher: botan_cipher_t, key: *const u8, key_len: usize) -> c_int; pub fn botan_cipher_set_associated_data( cipher: botan_cipher_t, ad: *const u8, ad_len: usize, ) -> c_int; pub fn botan_cipher_start(cipher: botan_cipher_t, nonce: *const u8, nonce_len: usize) -> c_int; pub fn botan_cipher_update( cipher: botan_cipher_t, flags: u32, output: *mut u8, output_size: usize, output_written: *mut usize, input_bytes: *const u8, input_size: usize, input_consumed: *mut usize, ) -> c_int; pub fn botan_cipher_name( cipher: botan_cipher_t, name: *mut c_char, name_len: *mut usize, ) -> c_int; pub fn botan_cipher_output_length( cipher: botan_cipher_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_cipher_clear(cipher: botan_cipher_t) -> c_int; pub fn botan_cipher_destroy(cipher: botan_cipher_t) -> c_int; } botan-sys-0.10.5/src/errors.rs000064400000000000000000000031601046102023000142770ustar 00000000000000use crate::ffi_types::{c_char, c_int}; #[allow(clippy::upper_case_acronyms)] pub type BOTAN_FFI_ERROR = c_int; pub const BOTAN_FFI_SUCCESS: BOTAN_FFI_ERROR = 0; pub const BOTAN_FFI_INVALID_VERIFIER: BOTAN_FFI_ERROR = 1; pub const BOTAN_FFI_ERROR_INVALID_INPUT: BOTAN_FFI_ERROR = -1; pub const BOTAN_FFI_ERROR_BAD_MAC: BOTAN_FFI_ERROR = -2; pub const BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE: BOTAN_FFI_ERROR = -10; pub const BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR: BOTAN_FFI_ERROR = -11; pub const BOTAN_FFI_ERROR_EXCEPTION_THROWN: BOTAN_FFI_ERROR = -20; pub const BOTAN_FFI_ERROR_OUT_OF_MEMORY: BOTAN_FFI_ERROR = -21; pub const BOTAN_FFI_ERROR_SYSTEM_ERROR: BOTAN_FFI_ERROR = -22; pub const BOTAN_FFI_ERROR_INTERNAL_ERROR: BOTAN_FFI_ERROR = -23; pub const BOTAN_FFI_ERROR_BAD_FLAG: BOTAN_FFI_ERROR = -30; pub const BOTAN_FFI_ERROR_NULL_POINTER: BOTAN_FFI_ERROR = -31; pub const BOTAN_FFI_ERROR_BAD_PARAMETER: BOTAN_FFI_ERROR = -32; pub const BOTAN_FFI_ERROR_KEY_NOT_SET: BOTAN_FFI_ERROR = -33; pub const BOTAN_FFI_ERROR_INVALID_KEY_LENGTH: BOTAN_FFI_ERROR = -34; pub const BOTAN_FFI_ERROR_INVALID_OBJECT_STATE: BOTAN_FFI_ERROR = -35; pub const BOTAN_FFI_ERROR_NOT_IMPLEMENTED: BOTAN_FFI_ERROR = -40; pub const BOTAN_FFI_ERROR_INVALID_OBJECT: BOTAN_FFI_ERROR = -50; pub const BOTAN_FFI_ERROR_TLS_ERROR: BOTAN_FFI_ERROR = -75; pub const BOTAN_FFI_ERROR_HTTP_ERROR: BOTAN_FFI_ERROR = -76; pub const BOTAN_FFI_ERROR_UNKNOWN_ERROR: BOTAN_FFI_ERROR = -100; extern "C" { pub fn botan_error_description(err: BOTAN_FFI_ERROR) -> *const c_char; #[cfg(feature = "botan3")] pub fn botan_error_last_exception_message() -> *const c_char; } botan-sys-0.10.5/src/fpe.rs000064400000000000000000000012711046102023000135360ustar 00000000000000use crate::ffi_types::c_int; use crate::mp::botan_mp_t; pub enum botan_fpe_struct {} pub type botan_fpe_t = *mut botan_fpe_struct; extern "C" { pub fn botan_fpe_fe1_init( fpe: *mut botan_fpe_t, n: botan_mp_t, key: *const u8, key_len: usize, rounds: usize, flags: u32, ) -> c_int; pub fn botan_fpe_destroy(fpe: botan_fpe_t) -> c_int; pub fn botan_fpe_encrypt( fpe: botan_fpe_t, x: botan_mp_t, tweak: *const u8, tweak_len: usize, ) -> c_int; pub fn botan_fpe_decrypt( fpe: botan_fpe_t, x: botan_mp_t, tweak: *const u8, tweak_len: usize, ) -> c_int; } botan-sys-0.10.5/src/hash.rs000064400000000000000000000015721046102023000137130ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_hash_struct {} pub type botan_hash_t = *mut botan_hash_struct; extern "C" { pub fn botan_hash_init(hash: *mut botan_hash_t, hash_name: *const c_char, flags: u32) -> c_int; pub fn botan_hash_copy_state(dest: *mut botan_hash_t, source: botan_hash_t) -> c_int; pub fn botan_hash_name(hash: botan_hash_t, name: *mut c_char, name_len: *mut usize) -> c_int; pub fn botan_hash_output_length(hash: botan_hash_t, output_length: *mut usize) -> c_int; pub fn botan_hash_block_size(hash: botan_hash_t, block_size: *mut usize) -> c_int; pub fn botan_hash_update(hash: botan_hash_t, data: *const u8, len: usize) -> c_int; pub fn botan_hash_final(hash: botan_hash_t, digest: *mut u8) -> c_int; pub fn botan_hash_clear(hash: botan_hash_t) -> c_int; pub fn botan_hash_destroy(hash: botan_hash_t) -> c_int; } botan-sys-0.10.5/src/kdf.rs000064400000000000000000000032771046102023000135400ustar 00000000000000use crate::ffi_types::{c_char, c_int}; extern "C" { pub fn botan_pbkdf( pbkdf_algo: *const c_char, out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, iterations: usize, ) -> c_int; pub fn botan_pbkdf_timed( pbkdf_algo: *const c_char, out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, milliseconds_to_run: usize, out_iterations_used: *mut usize, ) -> c_int; pub fn botan_pwdhash( algo: *const c_char, param1: usize, param2: usize, param3: usize, out: *mut u8, out_len: usize, passphrase: *const c_char, passphrase_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_pwdhash_timed( algo: *const c_char, msec: u32, param1: *mut usize, param2: *mut usize, param3: *mut usize, out: *mut u8, out_len: usize, passphrase: *const c_char, passphrase_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_scrypt( out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, N: usize, r: usize, p: usize, ) -> c_int; pub fn botan_kdf( kdf_algo: *const c_char, out: *mut u8, out_len: usize, secret: *const u8, secret_len: usize, salt: *const u8, salt_len: usize, label: *const u8, label_len: usize, ) -> c_int; } botan-sys-0.10.5/src/keywrap.rs000064400000000000000000000022311046102023000144430ustar 00000000000000use crate::ffi_types::c_int; #[cfg(feature = "botan3")] use crate::ffi_types::c_char; extern "C" { pub fn botan_key_wrap3394( input: *const u8, input_len: usize, kek: *const u8, kek_len: usize, wrapped_key: *mut u8, wrapped_key_len: *mut usize, ) -> c_int; pub fn botan_key_unwrap3394( wrapped_key: *const u8, wrapped_key_len: usize, kek: *const u8, kek_len: usize, unwrapped_key: *mut u8, unwrapped_key_len: *mut usize, ) -> c_int; #[cfg(feature = "botan3")] pub fn botan_nist_kw_enc( cipher_algo: *const c_char, padding: c_int, input: *const u8, input_len: usize, kek: *const u8, kek_len: usize, wrapped_key: *mut u8, wrapped_key_len: *mut usize, ) -> c_int; #[cfg(feature = "botan3")] pub fn botan_nist_kw_dec( cipher_algo: *const c_char, padding: c_int, wrapped_key: *const u8, wrapped_key_len: usize, kek: *const u8, kek_len: usize, unwrapped_key: *mut u8, unwrapped_key_len: *mut usize, ) -> c_int; } botan-sys-0.10.5/src/lib.rs000064400000000000000000000022301046102023000135260ustar 00000000000000#![allow(non_camel_case_types)] #![cfg_attr(feature = "no-std", no_std)] mod block; mod cipher; mod errors; mod fpe; mod hash; mod kdf; mod keywrap; mod mac; mod mp; mod otp; mod passhash; mod pk_ops; mod pubkey; mod rng; mod utils; mod version; mod x509; mod zfec; pub mod ffi_types { #[cfg(feature = "no-std")] pub use core::ffi::{c_char, c_int, c_uint, c_void}; #[cfg(not(feature = "no-std"))] pub use std::os::raw::{c_char, c_int, c_uint, c_void}; #[cfg(feature = "botan3")] pub type botan_view_ctx = *mut c_void; #[cfg(feature = "botan3")] pub type botan_view_bin_fn = extern "C" fn(view_ctx: botan_view_ctx, data: *const u8, len: usize) -> c_int; #[cfg(feature = "botan3")] pub type botan_view_str_fn = extern "C" fn(view_ctx: botan_view_ctx, data: *const c_char, len: usize) -> c_int; } pub use block::*; pub use cipher::*; pub use errors::*; pub use fpe::*; pub use hash::*; pub use kdf::*; pub use keywrap::*; pub use mac::*; pub use mp::*; pub use otp::*; pub use passhash::*; pub use pk_ops::*; pub use pubkey::*; pub use rng::*; pub use utils::*; pub use version::*; pub use x509::*; pub use zfec::*; botan-sys-0.10.5/src/mac.rs000064400000000000000000000020601046102023000135210ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_mac_struct {} pub type botan_mac_t = *mut botan_mac_struct; extern "C" { pub fn botan_mac_init(mac: *mut botan_mac_t, mac_name: *const c_char, flags: u32) -> c_int; pub fn botan_mac_output_length(mac: botan_mac_t, output_length: *mut usize) -> c_int; pub fn botan_mac_set_key(mac: botan_mac_t, key: *const u8, key_len: usize) -> c_int; #[cfg(feature = "botan3")] pub fn botan_mac_set_nonce(mac: botan_mac_t, nonce: *const u8, nonce_len: usize) -> c_int; pub fn botan_mac_name(mac: botan_mac_t, name: *mut c_char, name_len: *mut usize) -> c_int; pub fn botan_mac_get_keyspec( mac: botan_mac_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_mac_update(mac: botan_mac_t, buf: *const u8, len: usize) -> c_int; pub fn botan_mac_final(mac: botan_mac_t, out: *mut u8) -> c_int; pub fn botan_mac_clear(mac: botan_mac_t) -> c_int; pub fn botan_mac_destroy(mac: botan_mac_t) -> c_int; } botan-sys-0.10.5/src/mp.rs000064400000000000000000000067541046102023000134130ustar 00000000000000use crate::ffi_types::{c_char, c_int}; use crate::rng::botan_rng_t; pub enum botan_mp_struct {} pub type botan_mp_t = *mut botan_mp_struct; extern "C" { pub fn botan_mp_init(mp: *mut botan_mp_t) -> c_int; pub fn botan_mp_destroy(mp: botan_mp_t) -> c_int; pub fn botan_mp_to_hex(mp: botan_mp_t, out: *mut c_char) -> c_int; pub fn botan_mp_to_str( mp: botan_mp_t, base: u8, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_mp_clear(mp: botan_mp_t) -> c_int; pub fn botan_mp_set_from_int(mp: botan_mp_t, initial_value: c_int) -> c_int; pub fn botan_mp_set_from_mp(dest: botan_mp_t, source: botan_mp_t) -> c_int; pub fn botan_mp_set_from_str(dest: botan_mp_t, str: *const c_char) -> c_int; pub fn botan_mp_set_from_radix_str(dest: botan_mp_t, str: *const c_char, radix: usize) -> c_int; pub fn botan_mp_num_bits(n: botan_mp_t, bits: *mut usize) -> c_int; pub fn botan_mp_num_bytes(n: botan_mp_t, bytes: *mut usize) -> c_int; pub fn botan_mp_to_bin(mp: botan_mp_t, vec: *mut u8) -> c_int; pub fn botan_mp_from_bin(mp: botan_mp_t, vec: *const u8, vec_len: usize) -> c_int; pub fn botan_mp_to_uint32(mp: botan_mp_t, val: *mut u32) -> c_int; pub fn botan_mp_is_positive(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_negative(mp: botan_mp_t) -> c_int; pub fn botan_mp_flip_sign(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_zero(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_odd(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_even(mp: botan_mp_t) -> c_int; pub fn botan_mp_add(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_sub(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_add_u32(result: botan_mp_t, x: botan_mp_t, y: u32) -> c_int; pub fn botan_mp_sub_u32(result: botan_mp_t, x: botan_mp_t, y: u32) -> c_int; pub fn botan_mp_mul(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_div( quotient: botan_mp_t, remainder: botan_mp_t, x: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_mp_mod_mul( result: botan_mp_t, x: botan_mp_t, y: botan_mp_t, mod_: botan_mp_t, ) -> c_int; pub fn botan_mp_equal(x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_cmp(result: *mut c_int, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_swap(x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_powmod( out: botan_mp_t, base: botan_mp_t, exponent: botan_mp_t, modulus: botan_mp_t, ) -> c_int; pub fn botan_mp_lshift(out: botan_mp_t, in_: botan_mp_t, shift: usize) -> c_int; pub fn botan_mp_rshift(out: botan_mp_t, in_: botan_mp_t, shift: usize) -> c_int; pub fn botan_mp_mod_inverse(out: botan_mp_t, in_: botan_mp_t, modulus: botan_mp_t) -> c_int; pub fn botan_mp_rand_bits(rand_out: botan_mp_t, rng: botan_rng_t, bits: usize) -> c_int; pub fn botan_mp_rand_range( rand_out: botan_mp_t, rng: botan_rng_t, lower_bound: botan_mp_t, upper_bound: botan_mp_t, ) -> c_int; pub fn botan_mp_gcd(out: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_is_prime(n: botan_mp_t, rng: botan_rng_t, test_prob: usize) -> c_int; pub fn botan_mp_get_bit(n: botan_mp_t, bit: usize) -> c_int; pub fn botan_mp_set_bit(n: botan_mp_t, bit: usize) -> c_int; pub fn botan_mp_clear_bit(n: botan_mp_t, bit: usize) -> c_int; } botan-sys-0.10.5/src/otp.rs000064400000000000000000000023761046102023000135750ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_hotp_struct {} pub type botan_hotp_t = *mut botan_hotp_struct; pub enum botan_totp_struct {} pub type botan_totp_t = *mut botan_totp_struct; extern "C" { pub fn botan_hotp_init( hotp: *mut botan_hotp_t, key: *const u8, key_len: usize, hash_algo: *const c_char, digits: usize, ) -> c_int; pub fn botan_hotp_destroy(hotp: botan_hotp_t) -> c_int; pub fn botan_hotp_generate(hotp: botan_hotp_t, hotp_code: *mut u32, hotp_counter: u64) -> c_int; pub fn botan_hotp_check( hotp: botan_hotp_t, next_counter: *mut u64, hotp_code: u32, hotp_counter: u64, resync_range: usize, ) -> c_int; pub fn botan_totp_init( totp: *mut botan_totp_t, key: *const u8, key_len: usize, hash_algo: *const c_char, digits: usize, time_step: usize, ) -> c_int; pub fn botan_totp_destroy(totp: botan_totp_t) -> c_int; pub fn botan_totp_generate(totp: botan_totp_t, totp_code: *mut u32, timestamp: u64) -> c_int; pub fn botan_totp_check( totp: botan_totp_t, totp_code: u32, timestamp: u64, acceptable_drift: usize, ) -> c_int; } botan-sys-0.10.5/src/passhash.rs000064400000000000000000000005751046102023000146040ustar 00000000000000use crate::ffi_types::{c_char, c_int}; use crate::rng::botan_rng_t; extern "C" { pub fn botan_bcrypt_generate( out: *mut u8, out_len: *mut usize, password: *const c_char, rng: botan_rng_t, work_factor: usize, flags: u32, ) -> c_int; pub fn botan_bcrypt_is_valid(pass: *const c_char, hash: *const c_char) -> c_int; } botan-sys-0.10.5/src/pk_ops.rs000064400000000000000000000136641046102023000142700ustar 00000000000000use crate::ffi_types::*; use crate::pubkey::{botan_privkey_t, botan_pubkey_t}; use crate::rng::botan_rng_t; pub enum botan_pk_op_encrypt_struct {} pub type botan_pk_op_encrypt_t = *mut botan_pk_op_encrypt_struct; pub enum botan_pk_op_decrypt_struct {} pub type botan_pk_op_decrypt_t = *mut botan_pk_op_decrypt_struct; pub enum botan_pk_op_sign_struct {} pub type botan_pk_op_sign_t = *mut botan_pk_op_sign_struct; pub enum botan_pk_op_verify_struct {} pub type botan_pk_op_verify_t = *mut botan_pk_op_verify_struct; pub enum botan_pk_op_ka_struct {} pub type botan_pk_op_ka_t = *mut botan_pk_op_ka_struct; pub enum botan_pk_op_kem_encrypt_struct {} pub type botan_pk_op_kem_encrypt_t = *mut botan_pk_op_kem_encrypt_struct; pub enum botan_pk_op_kem_decrypt_struct {} pub type botan_pk_op_kem_decrypt_t = *mut botan_pk_op_kem_decrypt_struct; extern "C" { pub fn botan_pk_op_encrypt_create( op: *mut botan_pk_op_encrypt_t, key: botan_pubkey_t, padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_encrypt_destroy(op: botan_pk_op_encrypt_t) -> c_int; pub fn botan_pk_op_encrypt_output_length( op: botan_pk_op_encrypt_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_pk_op_encrypt( op: botan_pk_op_encrypt_t, rng: botan_rng_t, out: *mut u8, out_len: *mut usize, plaintext: *const u8, plaintext_len: usize, ) -> c_int; pub fn botan_pk_op_decrypt_create( op: *mut botan_pk_op_decrypt_t, key: botan_privkey_t, padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_decrypt_output_length( op: botan_pk_op_decrypt_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_pk_op_decrypt_destroy(op: botan_pk_op_decrypt_t) -> c_int; pub fn botan_pk_op_decrypt( op: botan_pk_op_decrypt_t, out: *mut u8, out_len: *mut usize, ciphertext: *const u8, ciphertext_len: usize, ) -> c_int; pub fn botan_pk_op_sign_create( op: *mut botan_pk_op_sign_t, key: botan_privkey_t, hash_and_padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_sign_output_length(op: botan_pk_op_sign_t, siglen: *mut usize) -> c_int; pub fn botan_pk_op_sign_destroy(op: botan_pk_op_sign_t) -> c_int; pub fn botan_pk_op_sign_update(op: botan_pk_op_sign_t, in_: *const u8, in_len: usize) -> c_int; pub fn botan_pk_op_sign_finish( op: botan_pk_op_sign_t, rng: botan_rng_t, sig: *mut u8, sig_len: *mut usize, ) -> c_int; pub fn botan_pk_op_verify_create( op: *mut botan_pk_op_verify_t, key: botan_pubkey_t, hash_and_padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_verify_destroy(op: botan_pk_op_verify_t) -> c_int; pub fn botan_pk_op_verify_update( op: botan_pk_op_verify_t, in_: *const u8, in_len: usize, ) -> c_int; pub fn botan_pk_op_verify_finish( op: botan_pk_op_verify_t, sig: *const u8, sig_len: usize, ) -> c_int; pub fn botan_pk_op_key_agreement_create( op: *mut botan_pk_op_ka_t, key: botan_privkey_t, kdf: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_key_agreement_destroy(op: botan_pk_op_ka_t) -> c_int; pub fn botan_pk_op_key_agreement_size(op: botan_pk_op_ka_t, agreed_len: *mut usize) -> c_int; pub fn botan_pk_op_key_agreement_export_public( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_pk_op_key_agreement( op: botan_pk_op_ka_t, out: *mut u8, out_len: *mut usize, other_key: *const u8, other_key_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_pkcs_hash_id( hash_name: *const c_char, pkcs_id: *mut u8, pkcs_id_len: *mut usize, ) -> c_int; } #[cfg(feature = "botan3")] extern "C" { pub fn botan_pk_op_key_agreement_view_public( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; pub fn botan_pk_op_kem_encrypt_create( op: *mut botan_pk_op_kem_encrypt_t, key: botan_pubkey_t, kdf: *const c_char, ) -> c_int; pub fn botan_pk_op_kem_encrypt_destroy(op: botan_pk_op_kem_encrypt_t) -> c_int; pub fn botan_pk_op_kem_encrypt_shared_key_length( op: botan_pk_op_kem_encrypt_t, desired_shared_key_length: usize, output_shared_key_length: *mut usize, ) -> c_int; pub fn botan_pk_op_kem_encrypt_encapsulated_key_length( op: botan_pk_op_kem_encrypt_t, output_encapsulated_key_length: *mut usize, ) -> c_int; pub fn botan_pk_op_kem_encrypt_create_shared_key( op: botan_pk_op_kem_encrypt_t, rng: botan_rng_t, salt: *const u8, salt_len: usize, desired_shared_key_len: usize, shared_key: *mut u8, shared_key_len: *mut usize, encapsulated_key: *mut u8, encapsulated_key_len: *mut usize, ) -> c_int; pub fn botan_pk_op_kem_decrypt_destroy(op: botan_pk_op_kem_decrypt_t) -> c_int; pub fn botan_pk_op_kem_decrypt_create( op: *mut botan_pk_op_kem_decrypt_t, key: botan_privkey_t, kdf: *const c_char, ) -> c_int; pub fn botan_pk_op_kem_decrypt_shared_key_length( op: botan_pk_op_kem_decrypt_t, desired_shared_key_length: usize, output_shared_key_length: *mut usize, ) -> c_int; pub fn botan_pk_op_kem_decrypt_shared_key( op: botan_pk_op_kem_decrypt_t, salt: *const u8, salt_len: usize, encapsulated_key: *const u8, encapsulated_key_len: usize, desired_shared_key_len: usize, shared_key: *mut u8, shared_key_len: *mut usize, ) -> c_int; } botan-sys-0.10.5/src/pubkey.rs000064400000000000000000000242211046102023000142630ustar 00000000000000use crate::ffi_types::*; use crate::mp::botan_mp_t; use crate::rng::botan_rng_t; pub enum botan_pubkey_struct {} pub type botan_pubkey_t = *mut botan_pubkey_struct; pub enum botan_privkey_struct {} pub type botan_privkey_t = *mut botan_privkey_struct; extern "C" { pub fn botan_privkey_create( key: *mut botan_privkey_t, algo_name: *const c_char, algo_params: *const c_char, rng: botan_rng_t, ) -> c_int; pub fn botan_privkey_check_key(key: botan_privkey_t, rng: botan_rng_t, flags: u32) -> c_int; pub fn botan_privkey_create_rsa( key: *mut botan_privkey_t, rng: botan_rng_t, n_bits: usize, ) -> c_int; pub fn botan_privkey_create_ecdsa( key: *mut botan_privkey_t, rng: botan_rng_t, params: *const c_char, ) -> c_int; pub fn botan_privkey_create_ecdh( key: *mut botan_privkey_t, rng: botan_rng_t, params: *const c_char, ) -> c_int; pub fn botan_privkey_create_mceliece( key: *mut botan_privkey_t, rng: botan_rng_t, n: usize, t: usize, ) -> c_int; pub fn botan_privkey_create_dh( key: *mut botan_privkey_t, rng: botan_rng_t, param: *const c_char, ) -> c_int; pub fn botan_privkey_create_dsa( key: *mut botan_privkey_t, rng: botan_rng_t, pbits: usize, qbits: usize, ) -> c_int; pub fn botan_privkey_create_elgamal( key: *mut botan_privkey_t, rng: botan_rng_t, pbits: usize, qbits: usize, ) -> c_int; pub fn botan_privkey_load( key: *mut botan_privkey_t, rng: botan_rng_t, bits: *const u8, len: usize, password: *const c_char, ) -> c_int; pub fn botan_privkey_destroy(key: botan_privkey_t) -> c_int; pub fn botan_privkey_export( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, encryption_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted_pbkdf_msec( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, pbkdf_msec_runtime: u32, pbkdf_iterations_out: *mut usize, cipher_algo: *const c_char, pbkdf_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted_pbkdf_iter( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, pbkdf_iterations: usize, cipher_algo: *const c_char, pbkdf_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_pubkey_load(key: *mut botan_pubkey_t, bits: *const u8, len: usize) -> c_int; pub fn botan_privkey_export_pubkey(out: *mut botan_pubkey_t, in_: botan_privkey_t) -> c_int; pub fn botan_pubkey_export( key: botan_pubkey_t, out: *mut u8, out_len: *mut usize, flags: u32, ) -> c_int; pub fn botan_privkey_algo_name( key: botan_privkey_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_algo_name( key: botan_pubkey_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_check_key(key: botan_pubkey_t, rng: botan_rng_t, flags: u32) -> c_int; pub fn botan_pubkey_estimated_strength(key: botan_pubkey_t, estimate: *mut usize) -> c_int; pub fn botan_pubkey_fingerprint( key: botan_pubkey_t, hash: *const c_char, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_destroy(key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_get_field( output: botan_mp_t, key: botan_pubkey_t, field_name: *const c_char, ) -> c_int; pub fn botan_privkey_get_field( output: botan_mp_t, key: botan_privkey_t, field_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_rsa( key: *mut botan_privkey_t, p: botan_mp_t, q: botan_mp_t, e: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_rsa_pkcs1( key: *mut botan_privkey_t, bits: *const u8, len: usize, ) -> c_int; pub fn botan_privkey_rsa_get_p(p: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_q(q: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_d(d: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_pubkey_load_rsa(key: *mut botan_pubkey_t, n: botan_mp_t, e: botan_mp_t) -> c_int; pub fn botan_pubkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int; pub fn botan_privkey_load_dsa( key: *mut botan_privkey_t, p: botan_mp_t, q: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_dsa( key: *mut botan_pubkey_t, p: botan_mp_t, q: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_privkey_dsa_get_x(n: botan_mp_t, key: botan_privkey_t) -> c_int; pub fn botan_pubkey_dsa_get_p(p: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_q(q: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_g(d: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_y(y: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_privkey_load_dh( key: *mut botan_privkey_t, p: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_dh( key: *mut botan_pubkey_t, p: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_elgamal( key: *mut botan_pubkey_t, p: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_elgamal( key: *mut botan_privkey_t, p: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_ed25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; pub fn botan_pubkey_load_ed25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; pub fn botan_privkey_ed25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int; pub fn botan_pubkey_ed25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int; pub fn botan_privkey_load_x25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; pub fn botan_pubkey_load_x25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; pub fn botan_privkey_x25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int; pub fn botan_pubkey_x25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int; pub fn botan_privkey_load_ecdsa( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_ecdsa( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_ecdh( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_ecdh( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_sm2( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_sm2( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_sm2_enc( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_sm2_enc( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_sm2_compute_za( out: *mut u8, out_len: *mut usize, ident: *const c_char, hash_algo: *const c_char, key: botan_pubkey_t, ) -> c_int; } #[cfg(feature = "botan3")] extern "C" { pub fn botan_pubkey_view_der( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; pub fn botan_pubkey_view_pem( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_privkey_view_der( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; pub fn botan_privkey_view_pem( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_pubkey_view_ec_public_point( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; pub fn botan_privkey_view_encrypted_der( key: botan_privkey_t, rng: botan_rng_t, passphrase: *const c_char, cipher_algo: *const c_char, pbkdf_algo: *const c_char, pbkdf_iterations: usize, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; pub fn botan_privkey_view_encrypted_pem( key: botan_privkey_t, rng: botan_rng_t, passphrase: *const c_char, cipher_algo: *const c_char, pbkdf_algo: *const c_char, pbkdf_iterations: usize, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; } botan-sys-0.10.5/src/rng.rs000064400000000000000000000011511046102023000135470ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_rng_struct {} pub type botan_rng_t = *mut botan_rng_struct; extern "C" { pub fn botan_rng_init(rng: *mut botan_rng_t, rng_type: *const c_char) -> c_int; pub fn botan_rng_get(rng: botan_rng_t, out: *mut u8, out_len: usize) -> c_int; pub fn botan_rng_reseed(rng: botan_rng_t, bits: usize) -> c_int; pub fn botan_rng_reseed_from_rng(rng: botan_rng_t, src: botan_rng_t, bits: usize) -> c_int; pub fn botan_rng_add_entropy(rng: botan_rng_t, data: *const u8, len: usize) -> c_int; pub fn botan_rng_destroy(rng: botan_rng_t) -> c_int; } botan-sys-0.10.5/src/utils.rs000064400000000000000000000014071046102023000141250ustar 00000000000000use crate::ffi_types::{c_char, c_int, c_void}; extern "C" { pub fn botan_constant_time_compare(x: *const u8, y: *const u8, len: usize) -> c_int; pub fn botan_scrub_mem(mem: *mut c_void, bytes: usize) -> c_int; pub fn botan_hex_encode(x: *const u8, len: usize, out: *mut c_char, flags: u32) -> c_int; pub fn botan_hex_decode( hex_str: *const c_char, in_len: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_base64_encode( x: *const u8, len: usize, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_base64_decode( base64_str: *const c_char, in_len: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; } botan-sys-0.10.5/src/version.rs000064400000000000000000000006001046102023000144440ustar 00000000000000use crate::ffi_types::{c_char, c_int}; extern "C" { pub fn botan_ffi_api_version() -> u32; pub fn botan_ffi_supports_api(api_version: u32) -> c_int; pub fn botan_version_string() -> *const c_char; pub fn botan_version_major() -> u32; pub fn botan_version_minor() -> u32; pub fn botan_version_patch() -> u32; pub fn botan_version_datestamp() -> u32; } botan-sys-0.10.5/src/x509.rs000064400000000000000000000107531046102023000134760ustar 00000000000000use crate::ffi_types::*; use crate::pubkey::{botan_privkey_t, botan_pubkey_t}; use crate::rng::botan_rng_t; pub enum botan_x509_cert_struct {} pub type botan_x509_cert_t = *mut botan_x509_cert_struct; pub enum botan_x509_crl_struct {} pub type botan_x509_crl_t = *mut botan_x509_crl_struct; #[repr(u32)] #[allow(clippy::upper_case_acronyms)] pub enum X509KeyConstraints { NO_CONSTRAINTS = 0, DIGITAL_SIGNATURE = 32768, NON_REPUDIATION = 16384, KEY_ENCIPHERMENT = 8192, DATA_ENCIPHERMENT = 4096, KEY_AGREEMENT = 2048, KEY_CERT_SIGN = 1024, CRL_SIGN = 512, ENCIPHER_ONLY = 256, DECIPHER_ONLY = 128, } extern "C" { pub fn botan_x509_cert_load( cert_obj: *mut botan_x509_cert_t, cert: *const u8, cert_len: usize, ) -> c_int; pub fn botan_x509_cert_dup(cert_obj: *mut botan_x509_cert_t, cert: botan_x509_cert_t) -> c_int; pub fn botan_x509_cert_load_file( cert_obj: *mut botan_x509_cert_t, filename: *const c_char, ) -> c_int; pub fn botan_x509_cert_destroy(cert: botan_x509_cert_t) -> c_int; pub fn botan_x509_cert_gen_selfsigned( cert: *mut botan_x509_cert_t, key: botan_privkey_t, rng: botan_rng_t, common_name: *const c_char, org_name: *const c_char, ) -> c_int; pub fn botan_x509_cert_get_time_starts( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_time_expires( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_fingerprint( cert: botan_x509_cert_t, hash: *const c_char, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_serial_number( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_authority_key_id( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_subject_key_id( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_public_key_bits( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_public_key( cert: botan_x509_cert_t, key: *mut botan_pubkey_t, ) -> c_int; pub fn botan_x509_cert_get_issuer_dn( cert: botan_x509_cert_t, key: *const c_char, index: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_subject_dn( cert: botan_x509_cert_t, key: *const c_char, index: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_to_string( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_allowed_usage(cert: botan_x509_cert_t, key_usage: c_uint) -> c_int; pub fn botan_x509_cert_hostname_match( cert: botan_x509_cert_t, hostname: *const c_char, ) -> c_int; pub fn botan_x509_cert_verify( validation_result: *mut c_int, ee_cert: botan_x509_cert_t, intermediates: *const botan_x509_cert_t, intermediates_len: usize, trusted: *const botan_x509_cert_t, trusted_len: usize, trusted_path: *const c_char, required_key_strength: usize, hostname: *const c_char, reference_time: u64, ) -> c_int; pub fn botan_x509_cert_validation_status(code: c_int) -> *const c_char; #[cfg(feature = "botan3")] pub fn botan_x509_cert_view_public_key_bits( cert: botan_x509_cert_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(feature = "botan3")] pub fn botan_x509_cert_view_as_string( cert: botan_x509_cert_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_x509_crl_load_file(crl: *mut botan_x509_crl_t, file_path: *const c_char) -> c_int; pub fn botan_x509_crl_load( crl: *mut botan_x509_crl_t, data: *const u8, data_len: usize, ) -> c_int; pub fn botan_x509_crl_destroy(crl: botan_x509_crl_t) -> c_int; pub fn botan_x509_is_revoked(crl: botan_x509_crl_t, cert: botan_x509_cert_t) -> c_int; // TODO: botan_x509_cert_verify_with_crl } botan-sys-0.10.5/src/zfec.rs000064400000000000000000000007451046102023000137200ustar 00000000000000extern "C" { #[cfg(feature = "botan3")] pub fn botan_zfec_encode( k: usize, n: usize, input: *const u8, input_len: usize, outputs: *mut *mut u8, ) -> crate::ffi_types::c_int; #[cfg(feature = "botan3")] pub fn botan_zfec_decode( k: usize, n: usize, indexes: *const usize, shares: *const *const u8, share_size: usize, outputs: *mut *mut u8, ) -> crate::ffi_types::c_int; } botan-sys-0.10.5/tests/tests.rs000064400000000000000000000053711046102023000145060ustar 00000000000000extern crate botan_sys; use std::ffi::CString; use botan_sys::*; #[test] fn test_hex() { let bin = vec![0x42, 0x23, 0x45, 0x8F]; let mut out = Vec::new(); out.resize(bin.len() * 2, 0); unsafe { assert_eq!( botan_hex_encode(bin.as_ptr(), bin.len(), out.as_mut_ptr(), 0), 0 ); } assert_eq!(out[0], '4' as _); assert_eq!(out[1], '2' as _); assert_eq!(out[2], '2' as _); assert_eq!(out[3], '3' as _); assert_eq!(out[4], '4' as _); assert_eq!(out[5], '5' as _); assert_eq!(out[6], '8' as _); assert_eq!(out[7], 'F' as _); let mut decoded = vec![0; 1024]; let mut out_len = decoded.len(); unsafe { assert_eq!( botan_hex_decode(out.as_ptr(), out.len(), decoded.as_mut_ptr(), &mut out_len), 0 ); } assert_eq!(out_len, bin.len()); decoded.resize(out_len, 0); assert_eq!(bin, decoded); } #[test] fn test_hash() { unsafe { let mut hash = std::ptr::null_mut(); let hash_name = CString::new("SHA-384").unwrap(); assert_eq!(botan_hash_init(&mut hash, hash_name.as_ptr(), 0u32), 0); let input = vec![97, 98, 99]; assert_eq!(botan_hash_update(hash, input.as_ptr(), input.len()), 0); assert_eq!(botan_hash_update(hash, input.as_ptr(), input.len()), 0); let mut output_len = 0; assert_eq!(botan_hash_output_length(hash, &mut output_len), 0); assert!(output_len == 48); let mut digest = vec![0u8; output_len]; assert_eq!(botan_hash_final(hash, digest.as_mut_ptr()), 0); assert_eq!(digest[0], 0xCA); assert_eq!(digest[1], 0xF3); assert_eq!(digest[47], 0x8D); assert_eq!(botan_hash_destroy(hash), 0); } } #[test] fn test_version() { unsafe { let api_version = botan_ffi_api_version(); assert!(botan_ffi_supports_api(api_version) == 0); assert!(botan_ffi_supports_api(api_version + 1) != 0); #[cfg(feature = "botan3")] { assert_eq!(botan_version_major(), 3); } #[cfg(not(feature = "botan3"))] { if botan_version_major() == 2 { assert!(botan_version_minor() > 8); } else { assert_eq!(botan_version_major(), 3); } } } } #[test] fn test_rng() { unsafe { let mut rng = std::ptr::null_mut(); botan_rng_init(&mut rng, std::ptr::null()); let mut rng1 = vec![0u8; 16]; let mut rng2 = vec![0u8; 16]; assert_eq!(botan_rng_get(rng, rng1.as_mut_ptr(), rng1.len()), 0); assert_eq!(botan_rng_get(rng, rng2.as_mut_ptr(), rng2.len()), 0); assert!(rng1 != rng2); assert_eq!(botan_rng_destroy(rng), 0); } }