Skip to main content

osdp/reply/
rmac_i.rs

1//! `osdp_RMAC_I` (`0x78`) — initial R-MAC.
2//!
3//! # Spec: §7.17, Annex D.4
4
5use crate::error::Error;
6use alloc::vec::Vec;
7
8/// `osdp_RMAC_I` body.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct RMacI {
11    /// Initial R-MAC seed (16 bytes).
12    pub r_mac_i: [u8; 16],
13}
14
15impl RMacI {
16    /// Encode.
17    pub fn encode(&self) -> Result<Vec<u8>, Error> {
18        Ok(self.r_mac_i.to_vec())
19    }
20
21    /// Decode.
22    pub fn decode(data: &[u8]) -> Result<Self, Error> {
23        if data.len() != 16 {
24            return Err(Error::MalformedPayload {
25                code: 0x78,
26                reason: "RMAC_I requires 16 bytes",
27            });
28        }
29        let mut r_mac_i = [0u8; 16];
30        r_mac_i.copy_from_slice(data);
31        Ok(Self { r_mac_i })
32    }
33}