use std::fmt;
use zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
pub struct SecretBytes(Vec<u8>);
impl SecretBytes {
#[must_use]
pub fn new(bytes: impl Into<Vec<u8>>) -> Self {
Self(bytes.into())
}
#[must_use]
#[cfg(feature = "aes")]
pub(crate) fn expose(&self) -> &[u8] {
&self.0
}
}
impl fmt::Debug for SecretBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("SecretBytes([REDACTED])")
}
}
impl From<Vec<u8>> for SecretBytes {
fn from(value: Vec<u8>) -> Self {
Self::new(value)
}
}
impl From<&[u8]> for SecretBytes {
fn from(value: &[u8]) -> Self {
Self::new(value.to_vec())
}
}