Skip to main content

botan_sys/
lib.rs

1#![no_std]
2#![allow(non_camel_case_types)]
3#![allow(unused_imports)]
4
5//! FFI declarations for the Botan cryptography library
6//!
7//! By default (and with the `static` or `vendored` features) this crate links
8//! against the Botan library and detects at build time which functions the
9//! installed headers declare. Functions the headers predate are replaced by
10//! stubs returning [`BOTAN_FFI_ERROR_FUNCTION_NOT_AVAILABLE`].
11//!
12//! With the `dynamic-loading` feature the crate does not link against Botan;
13//! the shared library is loaded at runtime (see `load_library`) and every
14//! function is resolved on first use, so the set of available functions is
15//! determined entirely by the library found at runtime.
16
17#[cfg(feature = "dynamic-loading")]
18extern crate std;
19
20#[cfg(all(
21    feature = "dynamic-loading",
22    any(feature = "vendored", feature = "static")
23))]
24compile_error!("The dynamic-loading feature cannot be combined with vendored or static linking");
25
26#[macro_use]
27mod macros;
28
29#[cfg(feature = "dynamic-loading")]
30mod loader;
31
32#[cfg(feature = "dynamic-loading")]
33pub use loader::{LoadError, last_load_error, load_library, loaded_library_name};
34
35mod block;
36mod cipher;
37mod ec_group;
38mod errors;
39mod fpe;
40mod hash;
41mod kdf;
42mod keywrap;
43mod mac;
44mod mp;
45mod oid;
46mod otp;
47mod passhash;
48mod pk_ops;
49mod pubkey;
50mod rng;
51mod spake2p;
52mod srp6;
53mod tpm2;
54mod utils;
55mod version;
56mod x509;
57mod xof;
58mod zfec;
59
60pub mod ffi_types {
61    pub use core::ffi::{c_char, c_int, c_uint, c_void};
62
63    pub type botan_view_ctx = *mut c_void;
64
65    pub type botan_view_bin_fn =
66        extern "C" fn(view_ctx: botan_view_ctx, data: *const u8, len: usize) -> c_int;
67
68    pub type botan_view_str_fn =
69        extern "C" fn(view_ctx: botan_view_ctx, data: *const c_char, len: usize) -> c_int;
70}
71
72pub use block::*;
73pub use cipher::*;
74pub use ec_group::*;
75pub use errors::*;
76pub use fpe::*;
77pub use hash::*;
78pub use kdf::*;
79pub use keywrap::*;
80pub use mac::*;
81pub use mp::*;
82pub use oid::*;
83pub use otp::*;
84pub use passhash::*;
85pub use pk_ops::*;
86pub use pubkey::*;
87pub use rng::*;
88pub use spake2p::*;
89pub use srp6::*;
90pub use tpm2::*;
91pub use utils::*;
92pub use version::*;
93pub use x509::*;
94pub use xof::*;
95pub use zfec::*;
96
97/// Returns a description of why the Botan library could not be loaded
98///
99/// This is only ever `Some` when the `dynamic-loading` feature is enabled and
100/// loading the Botan shared library failed; in the linked build modes it
101/// always returns `None`.
102#[cfg(not(feature = "dynamic-loading"))]
103pub fn last_load_error() -> Option<&'static str> {
104    None
105}