tss_esapi/structures/attestation/
quote_info.rs

1// Copyright 2021 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{
5    structures::{Digest, PcrSelectionList},
6    tss2_esys::TPMS_QUOTE_INFO,
7    Error, Result,
8};
9use std::convert::{TryFrom, TryInto};
10/// Structure holding the attested data for TPM2_Quote()
11///
12/// # Details
13/// This corresponds to the TPMS_QUOTE_INFO
14#[derive(Debug, Clone)]
15pub struct QuoteInfo {
16    pcr_selection: PcrSelectionList,
17    pcr_digest: Digest,
18}
19
20impl QuoteInfo {
21    /// Returns the pcr selections list representing the selected PCRs.
22    pub const fn pcr_selection(&self) -> &PcrSelectionList {
23        &self.pcr_selection
24    }
25
26    /// Returns the digest selected PCRs hash of the signing key.
27    pub const fn pcr_digest(&self) -> &Digest {
28        &self.pcr_digest
29    }
30}
31
32impl From<QuoteInfo> for TPMS_QUOTE_INFO {
33    fn from(quote_info: QuoteInfo) -> Self {
34        TPMS_QUOTE_INFO {
35            pcrSelect: quote_info.pcr_selection.into(),
36            pcrDigest: quote_info.pcr_digest.into(),
37        }
38    }
39}
40
41impl TryFrom<TPMS_QUOTE_INFO> for QuoteInfo {
42    type Error = Error;
43
44    fn try_from(tpms_quote_info: TPMS_QUOTE_INFO) -> Result<Self> {
45        Ok(QuoteInfo {
46            pcr_selection: tpms_quote_info.pcrSelect.try_into()?,
47            pcr_digest: tpms_quote_info.pcrDigest.try_into()?,
48        })
49    }
50}