#![forbid(unsafe_code)]
#![warn(missing_docs, clippy::pedantic)]
#![cfg_attr(
not(test),
deny(
clippy::unwrap_used,
clippy::expect_used,
clippy::indexing_slicing,
clippy::panic,
clippy::unreachable,
clippy::todo,
clippy::unimplemented
)
)]
pub mod aead;
pub mod error;
pub mod format;
pub mod hash;
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub mod hazmat;
pub mod kdf;
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub mod kem;
#[cfg(feature = "password")]
pub mod password;
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub mod seal;
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub mod sign;
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub mod suite;
pub use error::{Error, Result};
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub use seal::{open, open_with_policy, seal};
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub use suite::{Suite, SuitePolicy};
pub trait Rng: rand_core::CryptoRng {}
impl<R: rand_core::CryptoRng + ?Sized> Rng for R {}
pub(crate) fn random<const N: usize, R: Rng + ?Sized>(rng: &mut R) -> [u8; N] {
let mut out = [0u8; N];
rng.fill_bytes(&mut out);
out
}
#[must_use]
pub fn ct_eq(a: &[u8], b: &[u8]) -> bool {
use subtle::ConstantTimeEq;
a.len() == b.len() && bool::from(a.ct_eq(b))
}
#[cfg(test)]
pub(crate) mod test_util {
use rand_core::UnwrapErr;
pub fn rng() -> UnwrapErr<getrandom::SysRng> {
UnwrapErr(getrandom::SysRng)
}
pub fn hex(s: &str) -> Vec<u8> {
assert!(s.len().is_multiple_of(2), "odd-length hex");
(0..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("hex digit"))
.collect()
}
#[cfg(any(feature = "suite-max", feature = "suite-xwing"))]
pub fn to_hex(b: &[u8]) -> String {
use core::fmt::Write;
b.iter().fold(String::new(), |mut s, x| {
let _ = write!(s, "{x:02x}");
s
})
}
}