Skip to main content

osdp/reply/
piv.rs

1//! `osdp_PIVDATAR` (`0x80`) — PIV data response. Opaque body.
2//!
3//! # Spec: §7.20
4
5use crate::error::Error;
6use alloc::vec::Vec;
7
8/// `osdp_PIVDATAR` body.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct PivDataR {
11    /// Raw PIV data (often multi-part).
12    pub data: Vec<u8>,
13}
14
15impl PivDataR {
16    /// Encode.
17    pub fn encode(&self) -> Result<Vec<u8>, Error> {
18        Ok(self.data.clone())
19    }
20
21    /// Decode.
22    pub fn decode(data: &[u8]) -> Result<Self, Error> {
23        Ok(Self {
24            data: data.to_vec(),
25        })
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn roundtrip() {
35        let body = PivDataR {
36            data: alloc::vec![0xDE, 0xAD, 0xBE, 0xEF],
37        };
38        let bytes = body.encode().unwrap();
39        assert_eq!(bytes, [0xDE, 0xAD, 0xBE, 0xEF]);
40        assert_eq!(PivDataR::decode(&bytes).unwrap(), body);
41    }
42
43    #[test]
44    fn empty_payload_is_valid() {
45        assert_eq!(
46            PivDataR::decode(&[]).unwrap(),
47            PivDataR { data: Vec::new() }
48        );
49    }
50}