#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "bolero", derive(bolero::generator::TypeGenerator))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Nonce([u8; 16]);
impl Nonce {
#[allow(clippy::expect_used)]
#[must_use]
pub fn random() -> Self {
let mut bytes = [0u8; 16];
getrandom::getrandom(&mut bytes).expect("getrandom failed");
Self(bytes)
}
#[must_use]
pub const fn from_u128(value: u128) -> Self {
Self(value.to_le_bytes())
}
#[must_use]
pub const fn as_u128(&self) -> u128 {
u128::from_le_bytes(self.0)
}
#[must_use]
pub const fn from_bytes(bytes: [u8; 16]) -> Self {
Self(bytes)
}
#[must_use]
pub const fn as_bytes(&self) -> &[u8; 16] {
&self.0
}
}