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
// Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use std::convert::TryFrom;
use tss_esapi::structures::Auth;
use tss_esapi::tss2_esys::TPM2B_AUTH;
// The TPM2B_AUTH is currently
// just a typedef in the C code which results
// in it being just a type alias for TPM2B_DIGEST
// in the rust code. So the same size restrictions that
// TPM2B_DIGEST have will apply here as well.
mod test_auth {
use super::*;
#[test]
fn test_max_sized_data() {
let _ = Auth::try_from([0xff; 64].to_vec()).unwrap();
}
#[test]
fn test_to_large_data() {
// Removed:
// - test_handle_auth::test_set_large_handle
// - test_create::test_long_auth_create
// - test_create_primary::test_long_auth_create_primary
// from the context tests and put here instead.
let _ = Auth::try_from([0xff; 100].to_vec()).unwrap_err();
}
#[test]
fn test_default() {
{
let auth: Auth = Default::default();
let expected: TPM2B_AUTH = Default::default();
let actual = TPM2B_AUTH::try_from(auth).unwrap();
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.buffer.len(),
actual.buffer.len(),
"Buffers don't have the same length"
);
assert!(
expected
.buffer
.iter()
.zip(actual.buffer.iter())
.all(|(a, b)| a == b),
"Buffers are not equal"
);
}
{
let tss_auth: TPM2B_AUTH = Default::default();
let expected: Auth = Default::default();
let actual = Auth::try_from(tss_auth).unwrap();
assert_eq!(expected, actual);
}
}
}