9#include <botan/tpm2_error.h>
11#include <botan/internal/fmt.h>
12#include <botan/internal/tpm2_util.h>
14#include <tss2/tss2_rc.h>
19#if defined(BOTAN_TSS2_SUPPORTS_ERROR_DECODING)
21 const TSS2_RC decoding_rc = Tss2_RC_DecodeInfo(rc, &info);
22 if(decoding_rc != TSS2_RC_SUCCESS) [[unlikely]] {
23 throw Error(
fmt(
"Decoding RC failed (was: {})", rc), decoding_rc);
29 const bool formatted = (rc & (1 << 7)) != 0;
31 return (rc & 0x3F) | TPM2_RC_FMT1;
40std::string raw_rc_to_string(
TSS2_RC rc)
noexcept {
43 return "TPM2_RC_SUCCESS";
45 return "TPM2_RC_BAD_TAG";
46 case TPM2_RC_INITIALIZE:
47 return "TPM2_RC_INITIALIZE";
49 return "TPM2_RC_FAILURE";
50 case TPM2_RC_SEQUENCE:
51 return "TPM2_RC_SEQUENCE";
53 return "TPM2_RC_PRIVATE";
55 return "TPM2_RC_HMAC";
56 case TPM2_RC_DISABLED:
57 return "TPM2_RC_DISABLED";
58 case TPM2_RC_EXCLUSIVE:
59 return "TPM2_RC_EXCLUSIVE";
60 case TPM2_RC_AUTH_TYPE:
61 return "TPM2_RC_AUTH_TYPE";
62 case TPM2_RC_AUTH_MISSING:
63 return "TPM2_RC_AUTH_MISSING";
65 return "TPM2_RC_POLICY";
68 case TPM2_RC_PCR_CHANGED:
69 return "TPM2_RC_PCR_CHANGED";
71 return "TPM2_RC_UPGRADE";
72 case TPM2_RC_TOO_MANY_CONTEXTS:
73 return "TPM2_RC_TOO_MANY_CONTEXTS";
74 case TPM2_RC_AUTH_UNAVAILABLE:
75 return "TPM2_RC_AUTH_UNAVAILABLE";
77 return "TPM2_RC_REBOOT";
78 case TPM2_RC_UNBALANCED:
79 return "TPM2_RC_UNBALANCED";
80 case TPM2_RC_COMMAND_SIZE:
81 return "TPM2_RC_COMMAND_SIZE";
82 case TPM2_RC_COMMAND_CODE:
83 return "TPM2_RC_COMMAND_CODE";
84 case TPM2_RC_AUTHSIZE:
85 return "TPM2_RC_AUTHSIZE";
86 case TPM2_RC_AUTH_CONTEXT:
87 return "TPM2_RC_AUTH_CONTEXT";
88 case TPM2_RC_NV_RANGE:
89 return "TPM2_RC_NV_RANGE";
91 return "TPM2_RC_NV_SIZE";
92 case TPM2_RC_NV_LOCKED:
93 return "TPM2_RC_NV_LOCKED";
94 case TPM2_RC_NV_AUTHORIZATION:
95 return "TPM2_RC_NV_AUTHORIZATION";
96 case TPM2_RC_NV_UNINITIALIZED:
97 return "TPM2_RC_NV_UNINITIALIZED";
98 case TPM2_RC_NV_SPACE:
99 return "TPM2_RC_NV_SPACE";
100 case TPM2_RC_NV_DEFINED:
101 return "TPM2_RC_NV_DEFINED";
102 case TPM2_RC_BAD_CONTEXT:
103 return "TPM2_RC_BAD_CONTEXT";
105 return "TPM2_RC_CPHASH";
107 return "TPM2_RC_PARENT";
108 case TPM2_RC_NEEDS_TEST:
109 return "TPM2_RC_NEEDS_TEST";
110 case TPM2_RC_NO_RESULT:
111 return "TPM2_RC_NO_RESULT";
112 case TPM2_RC_SENSITIVE:
113 return "TPM2_RC_SENSITIVE";
114 case TPM2_RC_MAX_FM0:
115 return "TPM2_RC_MAX_FM0";
117 return "TPM2_RC_FMT1";
118 case TPM2_RC_ASYMMETRIC:
119 return "TPM2_RC_ASYMMETRIC";
120 case TPM2_RC_ATTRIBUTES:
121 return "TPM2_RC_ATTRIBUTES";
123 return "TPM2_RC_HASH";
125 return "TPM2_RC_VALUE";
126 case TPM2_RC_HIERARCHY:
127 return "TPM2_RC_HIERARCHY";
128 case TPM2_RC_KEY_SIZE:
129 return "TPM2_RC_KEY_SIZE";
131 return "TPM2_RC_MGF";
133 return "TPM2_RC_MODE";
135 return "TPM2_RC_TYPE";
137 return "TPM2_RC_HANDLE";
139 return "TPM2_RC_KDF";
141 return "TPM2_RC_RANGE";
142 case TPM2_RC_AUTH_FAIL:
143 return "TPM2_RC_AUTH_FAIL";
145 return "TPM2_RC_NONCE";
149 return "TPM2_RC_SCHEME";
151 return "TPM2_RC_SIZE";
152 case TPM2_RC_SYMMETRIC:
153 return "TPM2_RC_SYMMETRIC";
155 return "TPM2_RC_TAG";
156 case TPM2_RC_SELECTOR:
157 return "TPM2_RC_SELECTOR";
158 case TPM2_RC_INSUFFICIENT:
159 return "TPM2_RC_INSUFFICIENT";
160 case TPM2_RC_SIGNATURE:
161 return "TPM2_RC_SIGNATURE";
163 return "TPM2_RC_KEY";
164 case TPM2_RC_POLICY_FAIL:
165 return "TPM2_RC_POLICY_FAIL";
166 case TPM2_RC_INTEGRITY:
167 return "TPM2_RC_INTEGRITY";
169 return "TPM2_RC_TICKET";
170 case TPM2_RC_RESERVED_BITS:
171 return "TPM2_RC_RESERVED_BITS";
172 case TPM2_RC_BAD_AUTH:
173 return "TPM2_RC_BAD_AUTH";
174 case TPM2_RC_EXPIRED:
175 return "TPM2_RC_EXPIRED";
176 case TPM2_RC_POLICY_CC:
177 return "TPM2_RC_POLICY_CC";
178 case TPM2_RC_BINDING:
179 return "TPM2_RC_BINDING";
181 return "TPM2_RC_CURVE";
182 case TPM2_RC_ECC_POINT:
183 return "TPM2_RC_ECC_POINT";
185 return "TPM2_RC_WARN";
186 case TPM2_RC_CONTEXT_GAP:
187 return "TPM2_RC_CONTEXT_GAP";
188 case TPM2_RC_OBJECT_MEMORY:
189 return "TPM2_RC_OBJECT_MEMORY";
190 case TPM2_RC_SESSION_MEMORY:
191 return "TPM2_RC_SESSION_MEMORY";
193 return "TPM2_RC_MEMORY";
194 case TPM2_RC_SESSION_HANDLES:
195 return "TPM2_RC_SESSION_HANDLES";
196 case TPM2_RC_OBJECT_HANDLES:
197 return "TPM2_RC_OBJECT_HANDLES";
198 case TPM2_RC_LOCALITY:
199 return "TPM2_RC_LOCALITY";
200 case TPM2_RC_YIELDED:
201 return "TPM2_RC_YIELDED";
202 case TPM2_RC_CANCELED:
203 return "TPM2_RC_CANCELED";
204 case TPM2_RC_TESTING:
205 return "TPM2_RC_TESTING";
206 case TPM2_RC_REFERENCE_H0:
207 return "TPM2_RC_REFERENCE_H0";
208 case TPM2_RC_REFERENCE_H1:
209 return "TPM2_RC_REFERENCE_H1";
210 case TPM2_RC_REFERENCE_H2:
211 return "TPM2_RC_REFERENCE_H2";
212 case TPM2_RC_REFERENCE_H3:
213 return "TPM2_RC_REFERENCE_H3";
214 case TPM2_RC_REFERENCE_H4:
215 return "TPM2_RC_REFERENCE_H4";
216 case TPM2_RC_REFERENCE_H5:
217 return "TPM2_RC_REFERENCE_H5";
218 case TPM2_RC_REFERENCE_H6:
219 return "TPM2_RC_REFERENCE_H6";
220 case TPM2_RC_REFERENCE_S0:
221 return "TPM2_RC_REFERENCE_S0";
222 case TPM2_RC_REFERENCE_S1:
223 return "TPM2_RC_REFERENCE_S1";
224 case TPM2_RC_REFERENCE_S2:
225 return "TPM2_RC_REFERENCE_S2";
226 case TPM2_RC_REFERENCE_S3:
227 return "TPM2_RC_REFERENCE_S3";
228 case TPM2_RC_REFERENCE_S4:
229 return "TPM2_RC_REFERENCE_S4";
230 case TPM2_RC_REFERENCE_S5:
231 return "TPM2_RC_REFERENCE_S5";
232 case TPM2_RC_REFERENCE_S6:
233 return "TPM2_RC_REFERENCE_S6";
234 case TPM2_RC_NV_RATE:
235 return "TPM2_RC_NV_RATE";
236 case TPM2_RC_LOCKOUT:
237 return "TPM2_RC_LOCKOUT";
239 return "TPM2_RC_RETRY";
240 case TPM2_RC_NV_UNAVAILABLE:
241 return "TPM2_RC_NV_UNAVAILABLE";
251 Exception(
fmt(
"TPM2 Exception in {}: Code {} - {} ({})",
255 Tss2_RC_Decode(rc))),
259 return Tss2_RC_Decode(m_rc);
std::string error_message() const
Error(std::string_view location, TSS2_RC rc)
TSS2_RC get_raw_rc(TSS2_RC rc)
std::string fmt(std::string_view format, const T &... args)
uint32_t TSS2_RC
Forward declaration of TSS2 type for convenience.