use crate::error::Error;
use alloc::vec::Vec;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SCrypt {
pub server_cryptogram: [u8; 16],
}
impl SCrypt {
pub const fn new(c: [u8; 16]) -> Self {
Self {
server_cryptogram: c,
}
}
pub fn encode(&self) -> Result<Vec<u8>, Error> {
Ok(self.server_cryptogram.to_vec())
}
pub fn decode(data: &[u8]) -> Result<Self, Error> {
if data.len() != 16 {
return Err(Error::MalformedPayload {
code: 0x77,
reason: "SCRYPT requires 16-byte cryptogram",
});
}
let mut c = [0u8; 16];
c.copy_from_slice(data);
Ok(Self {
server_cryptogram: c,
})
}
}