1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! `osdp_CHLNG` (`0x76`) โ initiate Secure Channel session.
//!
//! # Spec: ยง6.17, Annex D.4
//!
//! Body is `RND.A` โ an 8-byte random challenge generated by the ACU.
//! The packet must carry an SCB of type `SCS_11`.
use crate::error::Error;
use alloc::vec::Vec;
/// `osdp_CHLNG` body.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Chlng {
/// `RND.A` โ 8 random bytes from the ACU.
pub rnd_a: [u8; 8],
}
impl Chlng {
/// New with the given `RND.A`.
pub const fn new(rnd_a: [u8; 8]) -> Self {
Self { rnd_a }
}
/// Encode.
pub fn encode(&self) -> Result<Vec<u8>, Error> {
Ok(self.rnd_a.to_vec())
}
/// Decode.
pub fn decode(data: &[u8]) -> Result<Self, Error> {
if data.len() != 8 {
return Err(Error::MalformedPayload {
code: 0x76,
reason: "CHLNG requires 8-byte RND.A",
});
}
let mut rnd_a = [0u8; 8];
rnd_a.copy_from_slice(data);
Ok(Self { rnd_a })
}
}