#[derive(Debug, Clone, PartialEq)]
pub struct SecretError;
impl std::fmt::Display for SecretError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "must not be empty")
}
}
pub type SecretResult<T> = Result<T, SecretError>;
#[derive(Debug, Clone, PartialEq)]
pub struct Secret(pub Vec<u8>);
impl Secret {
pub fn new_from_str(secret: &str) -> SecretResult<Self> {
if secret.is_empty() {
return Err(SecretError);
}
Ok(Self(secret.as_bytes().to_vec()))
}
pub fn new_from_vec(secret: Vec<u8>) -> Secret {
Self(secret)
}
pub fn get(self) -> Vec<u8> {
self.0
}
pub fn string(self) -> String {
String::from_utf8(self.0).unwrap()
}
}