tss_esapi/structures/attestation/
creation_info.rs

1// Copyright 2021 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{
5    structures::{Digest, Name},
6    tss2_esys::TPMS_CREATION_INFO,
7    Error, Result,
8};
9use std::convert::{TryFrom, TryInto};
10/// Structure holding the attested data for TPM2_CertifyCreation()
11///
12/// # Details
13/// This corresponds to the TPMS_CREATION_INFO
14#[derive(Debug, Clone)]
15pub struct CreationInfo {
16    object_name: Name,
17    creation_hash: Digest,
18}
19
20impl CreationInfo {
21    /// Returns the name of the object
22    pub const fn object_name(&self) -> &Name {
23        &self.object_name
24    }
25
26    /// Returns the creation hash
27    pub const fn creation_hash(&self) -> &Digest {
28        &self.creation_hash
29    }
30}
31
32impl From<CreationInfo> for TPMS_CREATION_INFO {
33    fn from(creation_info: CreationInfo) -> Self {
34        TPMS_CREATION_INFO {
35            objectName: creation_info.object_name.into(),
36            creationHash: creation_info.creation_hash.into(),
37        }
38    }
39}
40
41impl TryFrom<TPMS_CREATION_INFO> for CreationInfo {
42    type Error = Error;
43
44    fn try_from(tpms_creation_info: TPMS_CREATION_INFO) -> Result<Self> {
45        Ok(CreationInfo {
46            object_name: tpms_creation_info.objectName.try_into()?,
47            creation_hash: tpms_creation_info.creationHash.try_into()?,
48        })
49    }
50}