File: algorithm_property_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 (62 lines) | stat: -rw-r--r-- 2,211 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
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

use std::convert::TryInto;
use tss_esapi::{
    attributes::AlgorithmAttributes, constants::AlgorithmIdentifier, structures::AlgorithmProperty,
    tss2_esys::TPMS_ALG_PROPERTY,
};

#[test]
fn test_new() {
    let expected_algorithm_identifier = AlgorithmIdentifier::Rsa;
    let expected_algorithm_properties = AlgorithmAttributes(0x1);
    let algorithm_proprty =
        AlgorithmProperty::new(expected_algorithm_identifier, expected_algorithm_properties);

    assert_eq!(
        expected_algorithm_identifier,
        algorithm_proprty.algorithm_identifier(),
        "AlgorithmProperty, created with new, did not contain expected algorithm identifier value"
    );

    assert_eq!(
        expected_algorithm_properties,
        algorithm_proprty.algorithm_properties(),
        "AlgorithmProperty, created with new, did not contain expected algorithm properties value"
    );
}

#[test]
fn test_conversions() {
    let expected_algorithm_identifier = AlgorithmIdentifier::Rsa;
    let expected_algorithm_properties = AlgorithmAttributes(0x1);

    let expected_tpms_algorithm_property = TPMS_ALG_PROPERTY {
        alg: expected_algorithm_identifier.into(),
        algProperties: expected_algorithm_properties.into(),
    };

    let algorithm_property: AlgorithmProperty = expected_tpms_algorithm_property
        .try_into()
        .expect("Failed to convert TPMS_ALG_PROPERTY into AlgorithmProperty");

    assert_eq!(
        expected_algorithm_identifier,
        algorithm_property.algorithm_identifier(),
        "AlgorithmProperty, converted from TPMS_ALG_PROPERTY, did not contain the expected algorithm identifier value"
    );

    assert_eq!(
        expected_algorithm_properties,
        algorithm_property.algorithm_properties(),
        "AlgorithmProperty, converted from TPMS_ALG_PROPERTY, did not contain the expected algorithm properties value"
    );

    let actual_tpms_algorithm_property: TPMS_ALG_PROPERTY = algorithm_property.into();

    crate::common::ensure_tpms_alg_property_equality(
        &expected_tpms_algorithm_property,
        &actual_tpms_algorithm_property,
    );
}