tss_esapi/interface_types/
structure_tags.rs1use crate::{constants::StructureTag, tss2_esys::TPMI_ST_ATTEST, Error, Result, WrapperErrorKind};
5use std::convert::TryFrom;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum AttestationType {
13 Certify,
14 Quote,
15 SessionAudit,
16 CommandAudit,
17 Time,
18 Creation,
19 Nv,
20 NvDigest,
21}
22
23impl From<AttestationType> for StructureTag {
24 fn from(native: AttestationType) -> Self {
25 match native {
26 AttestationType::Certify => StructureTag::AttestCertify,
27 AttestationType::Quote => StructureTag::AttestQuote,
28 AttestationType::SessionAudit => StructureTag::AttestSessionAudit,
29 AttestationType::CommandAudit => StructureTag::AttestCommandAudit,
30 AttestationType::Time => StructureTag::AttestTime,
31 AttestationType::Creation => StructureTag::AttestCreation,
32 AttestationType::Nv => StructureTag::AttestNv,
33 AttestationType::NvDigest => StructureTag::AttestNvDigest,
34 }
35 }
36}
37
38impl TryFrom<StructureTag> for AttestationType {
39 type Error = Error;
40
41 fn try_from(structure_tag: StructureTag) -> Result<AttestationType> {
42 match structure_tag {
43 StructureTag::AttestCertify => Ok(AttestationType::Certify),
44 StructureTag::AttestQuote => Ok(AttestationType::Quote),
45 StructureTag::AttestSessionAudit => Ok(AttestationType::SessionAudit),
46 StructureTag::AttestCommandAudit => Ok(AttestationType::CommandAudit),
47 StructureTag::AttestTime => Ok(AttestationType::Time),
48 StructureTag::AttestCreation => Ok(AttestationType::Creation),
49 StructureTag::AttestNv => Ok(AttestationType::Nv),
50 StructureTag::AttestNvDigest => Ok(AttestationType::NvDigest),
51 _ => Err(Error::local_error(WrapperErrorKind::InvalidParam)),
52 }
53 }
54}
55
56impl From<AttestationType> for TPMI_ST_ATTEST {
57 fn from(attestation_type: AttestationType) -> Self {
58 StructureTag::from(attestation_type).into()
59 }
60}
61
62impl TryFrom<TPMI_ST_ATTEST> for AttestationType {
63 type Error = Error;
64
65 fn try_from(tpmi_st_attest: TPMI_ST_ATTEST) -> Result<Self> {
66 AttestationType::try_from(StructureTag::try_from(tpmi_st_attest)?)
67 }
68}