#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![warn(
clippy::pedantic,
clippy::nursery,
clippy::all
)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::cast_possible_wrap)]
#![allow(clippy::cast_lossless)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::manual_assert)]
#![allow(clippy::inline_always)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::used_underscore_binding)]
#![allow(clippy::result_large_err)]
#![allow(clippy::redundant_pub_crate)]
#![allow(clippy::similar_names)]
#![warn(missing_docs)]
#[cfg(any(test, feature = "alloc"))]
extern crate alloc;
#[cfg(test)]
extern crate std;
extern crate core;
#[macro_use]
mod macros;
mod ptr;
pub mod buf;
pub mod opaque_res;
mod sealed;
pub mod aes;
pub mod hash;
mod error;
non_fips! { pub mod chacha;
}
pub mod aead;
pub mod mac;
pub(crate) mod ct;
pub mod kdf;
pub use ct::ct_eq;
pub mod hex {
pub use super::ct::HexError;
pub use super::ct::hex_encode as encode_into;
pub use super::ct::hex_encode_str as encode_str;
pub use super::ct::hex_decode as decode_into;
alloc! {
pub use super::ct::hex_encode_alloc as encode;
pub use super::ct::hex_decode_alloc as decode;
}
}
pub use error::Unspecified;
pub use error::MakeOpaque;
#[cfg(not(target_pointer_width = "32"))]
#[inline]
#[must_use]
pub(crate) const fn const_can_cast_u32<const S: usize>() -> bool {
const_lte::<S, { u32::MAX }>()
}
#[cfg(not(target_pointer_width = "32"))]
#[inline]
#[must_use]
pub(crate) const fn can_cast_u32(len: usize) -> bool {
len <= (u32::MAX as usize)
}
#[cfg(target_pointer_width = "32")]
#[inline]
#[must_use]
pub(crate) const fn const_can_cast_u32<const S: usize>() -> bool {
true
}
#[cfg(target_pointer_width = "32")]
#[inline]
#[must_use]
pub(crate) const fn can_cast_u32(_len: usize) -> bool {
true
}
#[inline]
#[must_use]
pub(crate) const fn const_can_cast_i32<const S: usize>() -> bool {
const_lte::<S, { i32::MAX as u32 }>()
}
#[inline]
#[must_use]
pub(crate) const fn can_cast_i32(len: usize) -> bool {
len <= (i32::MAX as usize)
}
#[must_use]
pub(crate) const fn const_lte<const L: usize, const MAX: u32>() -> bool {
L <= (MAX as usize)
}
#[cfg_attr(not(feature = "allow-non-fips"), allow(dead_code))]
#[must_use]
pub(crate) const fn const_gte<const L: usize, const MIN: usize>() -> bool {
L >= MIN
}
#[allow(dead_code)]
#[inline]
#[must_use]
pub(crate) const fn lte<const MAX: usize>(value: usize) -> bool {
value <= MAX
}
#[cfg_attr(not(feature = "allow-non-fips"), allow(dead_code))]
#[inline]
#[must_use]
pub(crate) const fn gte<const MIN: usize>(value: usize) -> bool {
value >= MIN
}
#[cfg(not(target_pointer_width = "32"))]
#[inline]
#[must_use]
pub(crate) const fn to_u32(num: usize) -> Option<u32> {
if can_cast_u32(num) {
Some(num as u32)
} else {
None
}
}
#[cfg(target_pointer_width = "32")]
#[inline]
#[must_use]
pub(crate) const fn to_u32(num: usize) -> Option<u32> {
Some(num as u32)
}
pub trait Fips: sealed::FipsSealed {}
pub const fn ensure_fips<F: Fips>() {}