File: algorithm_attributes_tests.rs

package info (click to toggle)
rust-tss-esapi 7.5.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,432 kB
  • sloc: sh: 130; makefile: 2
file content (150 lines) | stat: -rw-r--r-- 6,326 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

use std::ops::Shl;

use tss_esapi::{attributes::AlgorithmAttributes, tss2_esys::TPMA_ALGORITHM};

#[test]
fn test_conversions() {
    let expected_tpma_algorithm: TPMA_ALGORITHM = 0x16;
    let expected_algorithm_attributes = AlgorithmAttributes(expected_tpma_algorithm);
    let actual_algorithm_attributes: AlgorithmAttributes = expected_tpma_algorithm.into();
    let actual_tpma_algorithm: TPMA_ALGORITHM = expected_algorithm_attributes.into();

    assert_eq!(
        expected_algorithm_attributes, actual_algorithm_attributes,
        "AlgorithmAttributes converted from TPMA_ALGORITHM did not contain expected value"
    );

    assert_eq!(
        expected_tpma_algorithm, actual_tpma_algorithm,
        "TPMA_ALGORITHM converted from AlgorithmAttributes did not contain expected value"
    );
}

#[test]
fn test_all_set() {
    let attributes = AlgorithmAttributes::from(0xFFFFFFFF);
    assert!(
        attributes.asymmetric(),
        "'asymmetric' is unexpectedly not set"
    );
    assert!(
        attributes.symmetric(),
        "'symmetric' is unexpectedly not set"
    );
    assert!(attributes.hash(), "'hash' is unexpectedly not set");
    assert!(attributes.object(), "'object' is unexpectedly not set");
    assert!(attributes.signing(), "'signing' is unexpectedly not set");
    assert!(
        attributes.encrypting(),
        "'encrypting' is unexpectedly not set"
    );
    assert!(attributes.method(), "'method' is unexpectedly not set");
}

#[test]
fn test_none_set() {
    let attributes = AlgorithmAttributes::from(0x0);
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_asymmetric_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(0));
    assert!(
        attributes.asymmetric(),
        "'asymmetric' is unexpectedly not set"
    );
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_symmetric_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(1));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(
        attributes.symmetric(),
        "'symmetric' is unexpectedly not set"
    );
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_hash_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(2));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(attributes.hash(), "'hash' is unexpectedly not set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_object_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(3));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(attributes.object(), "'object' is unexpectedly not set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_signing_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(8));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(attributes.signing(), "'signing' is unexpectedly not set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_encrypting_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(9));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(
        attributes.encrypting(),
        "'encrypting' is unexpectedly not set"
    );
    assert!(!attributes.method(), "'method' is unexpectedly set");
}

#[test]
fn test_method_set() {
    let attributes = AlgorithmAttributes::from(1u32.shl(10));
    assert!(!attributes.asymmetric(), "'asymmetric' is unexpectedly set");
    assert!(!attributes.symmetric(), "'symmetric' is unexpectedly set");
    assert!(!attributes.hash(), "'hash' is unexpectedly set");
    assert!(!attributes.object(), "'object' is unexpectedly set");
    assert!(!attributes.signing(), "'signing' is unexpectedly set");
    assert!(!attributes.encrypting(), "'encrypting' is unexpectedly set");
    assert!(attributes.method(), "'method' is unexpectedly not set");
}