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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::Bytes;
use serde_indexed::{DeserializeIndexed, SerializeIndexed};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::cose::EcdhEsHkdf256PublicKey;
#[derive(Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum PinV1Subcommand {
GetRetries = 0x01,
GetKeyAgreement = 0x02,
SetPin = 0x03,
ChangePin = 0x04,
GetPinToken = 0x05,
GetPinUvAuthTokenUsingUvWithPermissions = 0x06,
GetUVRetries = 0x07,
GetPinUvAuthTokenUsingPinWithPermissions = 0x09,
}
#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct Request {
pub pin_protocol: u8,
pub sub_command: PinV1Subcommand,
#[serde(skip_serializing_if = "Option::is_none")]
pub key_agreement: Option<EcdhEsHkdf256PublicKey>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_auth: Option<Bytes<16>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub new_pin_enc: Option<Bytes<64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_hash_enc: Option<Bytes<64>>,
}
#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct Response {
#[serde(skip_serializing_if = "Option::is_none")]
pub key_agreement: Option<EcdhEsHkdf256PublicKey>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_token: Option<Bytes<32>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retries: Option<u8>,
}
#[cfg(test)]
mod tests {
#[test]
fn pin_v1_subcommand() {
let mut buf = [0u8; 64];
let example = super::PinV1Subcommand::GetKeyAgreement;
let ser = crate::serde::cbor_serialize(&example, &mut buf).unwrap();
assert_eq!(ser, &[0x02]);
}
}