use crate::Error;
pub const MIN_SECRET_BYTES: usize = 16;
pub struct Secret<'a> {
bytes: &'a [u8],
}
impl<'a> Secret<'a> {
pub fn new(bytes: &'a [u8]) -> Result<Self, Error> {
if bytes.len() < MIN_SECRET_BYTES {
return Err(Error::SecretTooShort {
actual: bytes.len(),
minimum: MIN_SECRET_BYTES,
});
}
Ok(Self { bytes })
}
pub(crate) const fn as_bytes(&self) -> &[u8] {
self.bytes
}
#[must_use]
pub const fn len(&self) -> usize {
self.bytes.len()
}
#[must_use]
pub const fn is_empty(&self) -> bool {
false
}
}
impl<'a> TryFrom<&'a [u8]> for Secret<'a> {
type Error = Error;
fn try_from(value: &'a [u8]) -> Result<Self, Self::Error> {
Self::new(value)
}
}