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
use super::hmac::HMACTag;
use super::{Command, Response};
use {Adapter, CommandType, ObjectId, Session, SessionError};
pub fn verify_hmac<A, D, T>(
session: &mut Session<A>,
key_id: ObjectId,
data: D,
tag: T,
) -> Result<(), SessionError>
where
A: Adapter,
D: Into<Vec<u8>>,
T: Into<HMACTag>,
{
let result = session.send_command(VerifyHMACCommand {
key_id,
tag: tag.into(),
data: data.into(),
})?;
if result.0 == 1 {
Ok(())
} else {
Err(command_err!(ResponseError, "HMAC verification failure"))
}
}
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct VerifyHMACCommand {
pub key_id: ObjectId,
pub tag: HMACTag,
pub data: Vec<u8>,
}
impl Command for VerifyHMACCommand {
type ResponseType = VerifyHMACResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct VerifyHMACResponse(pub(crate) u8);
impl Response for VerifyHMACResponse {
const COMMAND_TYPE: CommandType = CommandType::VerifyHMAC;
}