use zeroize::Zeroize; /// Provides a wrapper around a `Vec` that implements `Zeroize` on `Drop`. #[derive(Zeroize)] #[zeroize(drop)] pub struct SecretBytes(Vec); impl SecretBytes { /// Instantiates `Self` with an all-zeros byte array of length `len`. pub fn zero(len: usize) -> Self { Self(vec![0; len]) } /// Returns a reference to the underlying bytes. pub fn as_bytes(&self) -> &[u8] { &self.0 } /// Returns a mutable reference to the underlying bytes. pub fn as_mut_bytes(&mut self) -> &mut [u8] { &mut self.0 } } impl From> for SecretBytes { fn from(vec: Vec) -> Self { Self(vec) } }