tss_esapi/structures/attestation/
nv_certify_info.rs

1// Copyright 2021 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{
5    structures::{MaxNvBuffer, Name},
6    tss2_esys::TPMS_NV_CERTIFY_INFO,
7    Error, Result,
8};
9use std::convert::{TryFrom, TryInto};
10/// This  structure  contains  the  Name  and  contents  of  the
11/// selected  NV  Index  that  is  certified  by TPM2_NV_Certify()
12///
13/// # Details
14/// This corresponds to the TPMS_NV_CERTIFY_INFO.
15#[derive(Debug, Clone)]
16pub struct NvCertifyInfo {
17    index_name: Name,
18    offset: u16,
19    nv_contents: MaxNvBuffer,
20}
21
22impl NvCertifyInfo {
23    /// Returns index name
24    pub const fn index_name(&self) -> &Name {
25        &self.index_name
26    }
27
28    /// Returns offset
29    pub const fn offset(&self) -> u16 {
30        self.offset
31    }
32
33    /// Returns nv contents
34    pub const fn nv_contents(&self) -> &MaxNvBuffer {
35        &self.nv_contents
36    }
37}
38
39impl From<NvCertifyInfo> for TPMS_NV_CERTIFY_INFO {
40    fn from(nv_certify_info: NvCertifyInfo) -> Self {
41        TPMS_NV_CERTIFY_INFO {
42            indexName: nv_certify_info.index_name.into(),
43            offset: nv_certify_info.offset,
44            nvContents: nv_certify_info.nv_contents.into(),
45        }
46    }
47}
48
49impl TryFrom<TPMS_NV_CERTIFY_INFO> for NvCertifyInfo {
50    type Error = Error;
51
52    fn try_from(tpms_nv_certify_info: TPMS_NV_CERTIFY_INFO) -> Result<Self> {
53        Ok(NvCertifyInfo {
54            index_name: tpms_nv_certify_info.indexName.try_into()?,
55            offset: tpms_nv_certify_info.offset,
56            nv_contents: tpms_nv_certify_info.nvContents.try_into()?,
57        })
58    }
59}