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
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

use crate::{
    structures::SymmetricDefinitionObject, tss2_esys::TPMS_SYMCIPHER_PARMS, Error, Result,
};

use std::convert::{TryFrom, TryInto};

/// Symmetric cipher parameters
///
/// # Details
/// Corresponds to TPMS_SYMCIPHER_PARMS
#[derive(Clone, Debug, Copy, PartialEq, Eq)]
pub struct SymmetricCipherParameters {
    symmetric_definition_object: SymmetricDefinitionObject,
}

impl SymmetricCipherParameters {
    /// Creates a new [SymmetricDefinitionObject]
    pub const fn new(
        symmetric_definition_object: SymmetricDefinitionObject,
    ) -> SymmetricCipherParameters {
        SymmetricCipherParameters {
            symmetric_definition_object,
        }
    }
}

impl TryFrom<TPMS_SYMCIPHER_PARMS> for SymmetricCipherParameters {
    type Error = Error;
    fn try_from(tpms_symcipher_params: TPMS_SYMCIPHER_PARMS) -> Result<SymmetricCipherParameters> {
        Ok(SymmetricCipherParameters {
            symmetric_definition_object: tpms_symcipher_params.sym.try_into()?,
        })
    }
}

impl From<SymmetricCipherParameters> for TPMS_SYMCIPHER_PARMS {
    fn from(symmetric_cipher_parameters: SymmetricCipherParameters) -> TPMS_SYMCIPHER_PARMS {
        TPMS_SYMCIPHER_PARMS {
            sym: symmetric_cipher_parameters
                .symmetric_definition_object
                .into(),
        }
    }
}