1use crate::error::Error;
6use alloc::vec::Vec;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct GenAuthR {
11 pub response: Vec<u8>,
13}
14
15impl GenAuthR {
16 pub fn encode(&self) -> Result<Vec<u8>, Error> {
18 Ok(self.response.clone())
19 }
20
21 pub fn decode(data: &[u8]) -> Result<Self, Error> {
23 Ok(Self {
24 response: data.to_vec(),
25 })
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn roundtrip() {
35 let body = GenAuthR {
36 response: alloc::vec![0x7C, 0x02, 0x82, 0x00],
37 };
38 let bytes = body.encode().unwrap();
39 assert_eq!(bytes, [0x7C, 0x02, 0x82, 0x00]);
40 assert_eq!(GenAuthR::decode(&bytes).unwrap(), body);
41 }
42
43 #[test]
44 fn empty_response_is_valid() {
45 assert_eq!(
46 GenAuthR::decode(&[]).unwrap(),
47 GenAuthR {
48 response: Vec::new()
49 }
50 );
51 }
52}