1use crate::error::Error;
9use alloc::vec::Vec;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct Chlng {
14 pub rnd_a: [u8; 8],
16}
17
18impl Chlng {
19 pub const fn new(rnd_a: [u8; 8]) -> Self {
21 Self { rnd_a }
22 }
23
24 pub fn encode(&self) -> Result<Vec<u8>, Error> {
26 Ok(self.rnd_a.to_vec())
27 }
28
29 pub fn decode(data: &[u8]) -> Result<Self, Error> {
31 if data.len() != 8 {
32 return Err(Error::MalformedPayload {
33 code: 0x76,
34 reason: "CHLNG requires 8-byte RND.A",
35 });
36 }
37 let mut rnd_a = [0u8; 8];
38 rnd_a.copy_from_slice(data);
39 Ok(Self { rnd_a })
40 }
41}