File: data_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 (53 lines) | stat: -rw-r--r-- 1,628 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
// Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use std::convert::TryFrom;
use tss_esapi::structures::Data;
use tss_esapi::tss2_esys::TPM2B_DATA;
// The TPM2B_DATA has a size of 64 bytes
mod test_data {
    use super::*;

    #[test]
    fn test_max_sized_data() {
        let _ = Data::try_from([0xff; 64].to_vec()).unwrap();
    }

    #[test]
    fn test_to_large_data() {
        // Removed:
        //    - test_create::test_long_outside_info_create
        //    - test_create_primary::test_long_outside_info_create_primary
        // from the context tests and put here instead.

        let _ = Data::try_from([0xff; 100].to_vec()).unwrap_err();
    }

    #[test]
    fn test_default() {
        {
            let data: Data = Default::default();
            let expected: TPM2B_DATA = Default::default();
            let actual = TPM2B_DATA::from(data);
            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_data: TPM2B_DATA = Default::default();
            let expected: Data = Default::default();
            let actual = Data::try_from(tss_data).unwrap();
            assert_eq!(expected, actual);
        }
    }
}