Skip to main content

tpm2_protocol/data/
tpma.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) 2025 Opinsys Oy
3
4use crate::tpm_bitflags;
5
6tpm_bitflags! {
7    /// `TPMA_ACT` (Table 213)
8    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9    pub struct TpmaAct(TpmUint32) {
10        const SIGNALED = 0x0000_0001, "SIGNALED";
11        const PRESERVE_SIGNALED = 0x0000_0002, "PRESERVE_SIGNALED";
12    }
13}
14
15tpm_bitflags! {
16    /// `TPMA_ALGORITHM`
17    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
18    pub struct TpmaAlgorithm(TpmUint32) {
19        const ASYMMETRIC = 0x0000_0001, "ASYMMETRIC";
20        const SYMMETRIC = 0x0000_0002, "SYMMETRIC";
21        const HASH = 0x0000_0004, "HASH";
22        const OBJECT = 0x0000_0008, "OBJECT";
23        const SIGNING = 0x0000_0100, "SIGNING";
24        const ENCRYPTING = 0x0000_0200, "ENCRYPTING";
25        const METHOD = 0x0000_0400, "METHOD";
26    }
27}
28
29tpm_bitflags! {
30    /// `TPMA_CC` (Table 37)
31    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
32    pub struct TpmaCc(TpmUint32) {
33        const NV = 0x0040_0000, "NV";
34        const EXTENSIVE = 0x0080_0000, "EXTENSIVE";
35        const FLUSHED = 0x0100_0000, "FLUSHED";
36        const R_HANDLE = 0x1000_0000, "R_HANDLE";
37        const V = 0x2000_0000, "V";
38    }
39}
40
41impl TpmaCc {
42    /// Returns the `commandIndex` field.
43    #[must_use]
44    #[allow(clippy::cast_possible_truncation)]
45    pub const fn command_index(self) -> u16 {
46        (self.bits() & 0xFFFF) as u16
47    }
48
49    /// Returns the `cHandles` field: the number of handles the command takes.
50    #[must_use]
51    #[allow(clippy::cast_possible_truncation)]
52    pub const fn c_handles(self) -> u8 {
53        ((self.bits() >> 25) & 0x7) as u8
54    }
55}
56
57tpm_bitflags! {
58    /// `TPMA_LOCALITY` (Table 41)
59    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
60    pub struct TpmaLocality(TpmUint8) {
61        const LOC_ZERO = 0x01, "LOC_ZERO";
62        const LOC_ONE = 0x02, "LOC_ONE";
63        const LOC_TWO = 0x04, "LOC_TWO";
64        const LOC_THREE = 0x08, "LOC_THREE";
65        const LOC_FOUR = 0x10, "LOC_FOUR";
66    }
67}
68
69impl TpmaLocality {
70    /// Returns the `Extended` locality field.
71    #[must_use]
72    pub const fn extended(self) -> u8 {
73        (self.bits() >> 5) & 0x7
74    }
75}
76
77tpm_bitflags! {
78    /// `TPMA_NV` (Table 233)
79    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
80    pub struct TpmaNv(TpmUint32) {
81        const PPWRITE = 0x0000_0001, "PPWRITE";
82        const OWNERWRITE = 0x0000_0002, "OWNERWRITE";
83        const AUTHWRITE = 0x0000_0004, "AUTHWRITE";
84        const POLICYWRITE = 0x0000_0008, "POLICYWRITE";
85        const COUNTER = 0x0000_0010, "COUNTER";
86        const BITS = 0x0000_0020, "BITS";
87        const EXTEND = 0x0000_0040, "EXTEND";
88        const POLICY_DELETE = 0x0000_0400, "POLICY_DELETE";
89        const WRITELOCKED = 0x0000_0800, "WRITELOCKED";
90        const WRITEALL = 0x0000_1000, "WRITEALL";
91        const WRITEDEFINE = 0x0000_2000, "WRITEDEFINE";
92        const WRITE_STCLEAR = 0x0000_4000, "WRITE_STCLEAR";
93        const GLOBALLOCK = 0x0000_8000, "GLOBALLOCK";
94        const PPREAD = 0x0001_0000, "PPREAD";
95        const OWNERREAD = 0x0002_0000, "OWNERREAD";
96        const AUTHREAD = 0x0004_0000, "AUTHREAD";
97        const POLICYREAD = 0x0008_0000, "POLICYREAD";
98        const NO_DA = 0x0200_0000, "NO_DA";
99        const ORDERLY = 0x0400_0000, "ORDERLY";
100        const CLEAR_STCLEAR = 0x0800_0000, "CLEAR_STCLEAR";
101        const READLOCKED = 0x1000_0000, "READLOCKED";
102        const WRITTEN = 0x2000_0000, "WRITTEN";
103        const PLATFORMCREATE = 0x4000_0000, "PLATFORMCREATE";
104        const READ_STCLEAR = 0x8000_0000, "READ_STCLEAR";
105    }
106}
107
108tpm_bitflags! {
109    /// `TPMA_NV_EXP` (Table 234)
110    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
111    pub struct TpmaNvExp(TpmUint64) {
112        const ENCRYPTION = 0x0000_0001_0000_0000, "ENCRYPTION";
113        const INTEGRITY = 0x0000_0002_0000_0000, "INTEGRITY";
114        const ANTIROLLBACK = 0x0000_0004_0000_0000, "ANTIROLLBACK";
115    }
116}
117
118tpm_bitflags! {
119    /// `TPMA_OBJECT`
120    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
121    pub struct TpmaObject(TpmUint32) {
122        const FIXED_TPM = 0x0000_0002, "FIXED_TPM";
123        const ST_CLEAR = 0x0000_0004, "ST_CLEAR";
124        const FIXED_PARENT = 0x0000_0010, "FIXED_PARENT";
125        const SENSITIVE_DATA_ORIGIN = 0x0000_0020, "SENSITIVE_DATA_ORIGIN";
126        const USER_WITH_AUTH = 0x0000_0040, "USER_WITH_AUTH";
127        const ADMIN_WITH_POLICY = 0x0000_0080, "ADMIN_WITH_POLICY";
128        const NO_DA = 0x0000_0400, "NO_DA";
129        const ENCRYPTED_DUPLICATION = 0x0000_0800, "ENCRYPTED_DUPLICATION";
130        const RESTRICTED = 0x0001_0000, "RESTRICTED";
131        const DECRYPT = 0x0002_0000, "DECRYPT";
132        const SIGN_ENCRYPT = 0x0004_0000, "SIGN_ENCRYPT";
133    }
134}
135
136tpm_bitflags! {
137    /// `TPMA_SESSION`
138    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
139    pub struct TpmaSession(TpmUint8) {
140        const CONTINUE_SESSION = 0x01, "CONTINUE_SESSION";
141        const AUDIT_EXCLUSIVE = 0x02, "AUDIT_EXCLUSIVE";
142        const AUDIT_RESET = 0x04, "AUDIT_RESET";
143        const DECRYPT = 0x20, "DECRYPT";
144        const ENCRYPT = 0x40, "ENCRYPT";
145        const AUDIT = 0x80, "AUDIT";
146    }
147}