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
use crate::attributes::*;
use crate::errors::*;
use util::Error;
use subtle::ConstantTimeEq;
pub fn check_size(_at: AttrType, got: usize, expected: usize) -> Result<(), Error> {
if got == expected {
Ok(())
} else {
Err(ERR_ATTRIBUTE_SIZE_INVALID.clone())
}
}
pub fn is_attr_size_invalid(err: &Error) -> bool {
*err == *ERR_ATTRIBUTE_SIZE_INVALID
}
pub(crate) fn check_hmac(got: &[u8], expected: &[u8]) -> Result<(), Error> {
if got.ct_eq(expected).unwrap_u8() != 1 {
Err(ERR_INTEGRITY_MISMATCH.clone())
} else {
Ok(())
}
}
pub(crate) fn check_fingerprint(got: u32, expected: u32) -> Result<(), Error> {
if got == expected {
Ok(())
} else {
Err(ERR_FINGERPRINT_MISMATCH.clone())
}
}
pub fn check_overflow(_at: AttrType, got: usize, max: usize) -> Result<(), Error> {
if got <= max {
Ok(())
} else {
Err(ERR_ATTRIBUTE_SIZE_OVERFLOW.clone())
}
}
pub fn is_attr_size_overflow(err: &Error) -> bool {
*err == *ERR_ATTRIBUTE_SIZE_OVERFLOW
}