use std::fmt::{Debug, Formatter};
use zeroize::Zeroizing;
pub struct SecretKey {
bytes: Zeroizing<Vec<u8>>,
}
impl SecretKey {
pub fn new(bytes: Vec<u8>) -> Self {
Self {
bytes: Zeroizing::new(bytes),
}
}
pub fn from_slice(bytes: &[u8]) -> Self {
Self::new(bytes.to_vec())
}
pub fn expose_secret(&self) -> &[u8] {
self.bytes.as_slice()
}
pub fn len(&self) -> usize {
self.bytes.len()
}
pub fn is_empty(&self) -> bool {
self.bytes.is_empty()
}
}
impl Debug for SecretKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("SecretKey([REDACTED])")
}
}
impl From<Vec<u8>> for SecretKey {
fn from(bytes: Vec<u8>) -> Self {
Self::new(bytes)
}
}