Botan 3.14.1
Crypto and TLS for C&
pkix_enums.h
Go to the documentation of this file.
1/*
2* (C) 2013,2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_X509_PKIX_ENUMS_H_
8#define BOTAN_X509_PKIX_ENUMS_H_
9
10#include <botan/exceptn.h>
11#include <botan/types.h>
12#include <string>
13
14namespace Botan {
15
16class Public_Key;
17
18/**
19* Certificate validation status code
20*/
21enum class Certificate_Status_Code : uint16_t {
22 // TODO(Botan4) renumber this, e.g. Validation Errors -> IP_ADDR_BLOCKS_ERROR
23 // TODO(Botan4) rename variants to CamelCase
24 OK = 0,
26
27 // Revocation status
31
32 // Warnings
41
42 // Errors
44
50
51 // Time problems
59
60 // Revocation checks are skipped for chains which have an error more
61 // serious than this because they are anyway invalid
63
64 // Chain generation problems
70
71 // Validation errors
77
78 // Revocation errors
82
83 // Other problems
85
86 // Errors in extensions
88 // TODO(Botan4) remove this code, this is now rejected at parse time
96
97 // OCSP errors
106
107 // Hard failures
115};
116
117/**
118* Convert a status code to a human readable diagnostic message
119* @param code the certificate status
120* @return string literal constant, or nullptr if code unknown
121*/
123
124/**
125* X.509v3 Key Constraints.
126* If updating update copy in ffi.h
127*/
129 public:
130 enum Bits : uint16_t /* NOLINT(*-use-enum-class) */ {
131 None = 0,
133 NonRepudiation = 1 << 14,
136 KeyAgreement = 1 << 11,
137 KeyCertSign = 1 << 10,
138 CrlSign = 1 << 9,
139 EncipherOnly = 1 << 8,
140 DecipherOnly = 1 << 7,
141
142 // Deprecated SHOUTING_CASE names for Key_Constraints
143 // will be removed in a future major release
154 };
155
156 Key_Constraints(const Key_Constraints& other) = default;
158 Key_Constraints& operator=(const Key_Constraints& other) = default;
160 ~Key_Constraints() = default;
161
162 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor)
163 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
164
165 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
166
167 Key_Constraints() : m_value(0) {}
168
169 /**
170 * Return typical constraints for a CA certificate.
171 *
172 * The reasons for KeyCertSign and CrlSign should be obvious
173 *
174 * CAB baseline requirements are that DigitalSignature should be set
175 * if the certificate is used to sign OCSP responses.
176 */
181
182 bool operator==(const Key_Constraints&) const = default;
183
184 void operator|=(Key_Constraints::Bits other) { m_value |= other; }
185
186 // Return true if all bits in mask are set
187 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
188
189 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
190
191 // Return true if any of the bits provided are set
192 bool includes_any(auto&&... bits) const { return (m_value & (bits | ...)) > 0; }
193
194 bool empty() const { return m_value == 0; }
195
196 uint32_t value() const { return m_value; }
197
198 std::string to_string() const;
199
200 /**
201 * Check that key constraints are permitted for a specific public key.
202 * @param key the public key on which the constraints shall be enforced on
203 * @return false if the constraints are not permitted for this key
204 */
205 bool compatible_with(const Public_Key& key) const;
206
207 private:
208 uint32_t m_value;
209};
210
211/**
212* X.509 ReasonFlags BIT STRING used by CRLDistributionPoints and
213* IssuingDistributionPoint (RFC 5280 4.2.1.13 / 5.2.5).
214*/
215class BOTAN_PUBLIC_API(3, 13) ReasonFlags final {
216 public:
217 /* RFC 5280 4.2.1.13:
218 * ReasonFlags ::= BIT STRING {
219 * unused (0),
220 * keyCompromise (1),
221 * cACompromise (2),
222 * affiliationChanged (3),
223 * superseded (4),
224 * cessationOfOperation (5),
225 * certificateHold (6),
226 * privilegeWithdrawn (7),
227 * aACompromise (8) }
228 */
229 enum Bits : uint16_t /* NOLINT(*-use-enum-class,performance-enum-size) */ {
230 None = 0,
232 CaCompromise = 1 << 6,
234 Superseded = 1 << 4,
238 AaCompromise = 1 << 0,
239 };
240
244
245 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor)
246 ReasonFlags(ReasonFlags::Bits bits) : ReasonFlags(static_cast<uint16_t>(bits)) {}
247
248 explicit ReasonFlags(uint16_t bits) : m_value(bits) {
249 if((m_value & static_cast<uint16_t>(~DefinedReasonBits)) != 0) {
250 throw Decoding_Error("ReasonFlags contains undefined reason bits");
251 }
252 if(m_value == 0) {
253 throw Decoding_Error("ReasonFlags must have at least one defined reason");
254 }
255 }
256
257 bool operator==(const ReasonFlags&) const = default;
258
259 bool includes(ReasonFlags::Bits other) const { return (m_value & other) == other; }
260
261 bool includes(ReasonFlags other) const { return (m_value & other.m_value) == other.m_value; }
262
263 uint16_t value() const { return m_value; }
264
265 private:
266 uint16_t m_value;
267};
268
270 return ReasonFlags(static_cast<uint16_t>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b)));
271}
272
273/**
274* X.509v2 CRL Reason Code.
275*/
288
297
298} // namespace Botan
299
300#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
static Key_Constraints ca_constraints()
Definition pkix_enums.h:177
bool includes(Key_Constraints other) const
Definition pkix_enums.h:189
void operator|=(Key_Constraints::Bits other)
Definition pkix_enums.h:184
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition pkix_enums.h:165
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition pkix_enums.h:187
uint32_t value() const
Definition pkix_enums.h:196
Key_Constraints(const Key_Constraints &other)=default
bool includes_any(auto &&... bits) const
Definition pkix_enums.h:192
Key_Constraints & operator=(Key_Constraints &&other)=default
Key_Constraints & operator=(const Key_Constraints &other)=default
Key_Constraints(Key_Constraints::Bits bits)
Definition pkix_enums.h:163
static constexpr uint16_t DefinedReasonBits
Definition pkix_enums.h:241
bool includes(ReasonFlags::Bits other) const
Definition pkix_enums.h:259
ReasonFlags(uint16_t bits)
Definition pkix_enums.h:248
ReasonFlags(ReasonFlags::Bits bits)
Definition pkix_enums.h:246
bool operator==(const ReasonFlags &) const =default
bool includes(ReasonFlags other) const
Definition pkix_enums.h:261
uint16_t value() const
Definition pkix_enums.h:263
ASN1_Type operator|(ASN1_Type x, ASN1_Type y)
Definition asn1_obj.h:84
Certificate_Status_Code
Definition pkix_enums.h:21
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13