use snafu::prelude::*;
use crate::secrets::{
DecodingError, SecretBytes, SecretDecoder,
encodings::{InvalidHexSnafu, InvalidUtf8Snafu},
};
#[derive(Debug, Clone, Copy, Default)]
pub struct HexEncoding;
impl SecretDecoder for HexEncoding {
type Output = SecretBytes;
fn decode(&self, bytes: &[u8]) -> Result<Self::Output, DecodingError> {
let s = std::str::from_utf8(bytes).context(InvalidUtf8Snafu)?;
let decoded = hex::decode(s.trim()).context(InvalidHexSnafu)?;
Ok(SecretBytes::new(decoded))
}
}