use crate::error::Error;
use alloc::vec::Vec;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CrAuthR {
pub response: Vec<u8>,
}
impl CrAuthR {
pub fn encode(&self) -> Result<Vec<u8>, Error> {
Ok(self.response.clone())
}
pub fn decode(data: &[u8]) -> Result<Self, Error> {
Ok(Self {
response: data.to_vec(),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn roundtrip() {
let body = CrAuthR {
response: alloc::vec![0xDE, 0xAD, 0xBE, 0xEF],
};
let bytes = body.encode().unwrap();
assert_eq!(bytes, [0xDE, 0xAD, 0xBE, 0xEF]);
assert_eq!(CrAuthR::decode(&bytes).unwrap(), body);
}
#[test]
fn empty_response_is_valid() {
assert_eq!(
CrAuthR::decode(&[]).unwrap(),
CrAuthR {
response: Vec::new()
}
);
}
}