1use crate::error::Error;
8use alloc::vec::Vec;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct SCrypt {
13 pub server_cryptogram: [u8; 16],
15}
16
17impl SCrypt {
18 pub const fn new(c: [u8; 16]) -> Self {
20 Self {
21 server_cryptogram: c,
22 }
23 }
24
25 pub fn encode(&self) -> Result<Vec<u8>, Error> {
27 Ok(self.server_cryptogram.to_vec())
28 }
29
30 pub fn decode(data: &[u8]) -> Result<Self, Error> {
32 if data.len() != 16 {
33 return Err(Error::MalformedPayload {
34 code: 0x77,
35 reason: "SCRYPT requires 16-byte cryptogram",
36 });
37 }
38 let mut c = [0u8; 16];
39 c.copy_from_slice(data);
40 Ok(Self {
41 server_cryptogram: c,
42 })
43 }
44}