use crate::{
attributes::AlgorithmAttributes, constants::AlgorithmIdentifier, tss2_esys::TPMS_ALG_PROPERTY,
Error, Result,
};
use std::convert::{TryFrom, TryInto};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AlgorithmProperty {
algorithm_identifier: AlgorithmIdentifier,
algorithm_properties: AlgorithmAttributes,
}
impl AlgorithmProperty {
pub const fn new(
algorithm_identifier: AlgorithmIdentifier,
algorithm_properties: AlgorithmAttributes,
) -> Self {
AlgorithmProperty {
algorithm_identifier,
algorithm_properties,
}
}
pub const fn algorithm_identifier(&self) -> AlgorithmIdentifier {
self.algorithm_identifier
}
pub const fn algorithm_properties(&self) -> AlgorithmAttributes {
self.algorithm_properties
}
}
impl TryFrom<TPMS_ALG_PROPERTY> for AlgorithmProperty {
type Error = Error;
fn try_from(tpms_algorithm_description: TPMS_ALG_PROPERTY) -> Result<Self> {
Ok(AlgorithmProperty {
algorithm_identifier: tpms_algorithm_description.alg.try_into()?,
algorithm_properties: tpms_algorithm_description.algProperties.into(),
})
}
}
impl From<AlgorithmProperty> for TPMS_ALG_PROPERTY {
fn from(algorithm_description: AlgorithmProperty) -> Self {
TPMS_ALG_PROPERTY {
alg: algorithm_description.algorithm_identifier.into(),
algProperties: algorithm_description.algorithm_properties.into(),
}
}
}