Botan 3.13.0
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
95
96 // OCSP errors
105
106 // Hard failures
114};
115
116/**
117* Convert a status code to a human readable diagnostic message
118* @param code the certificate status
119* @return string literal constant, or nullptr if code unknown
120*/
122
123/**
124* X.509v3 Key Constraints.
125* If updating update copy in ffi.h
126*/
128 public:
129 enum Bits : uint16_t /* NOLINT(*-use-enum-class) */ {
130 None = 0,
132 NonRepudiation = 1 << 14,
135 KeyAgreement = 1 << 11,
136 KeyCertSign = 1 << 10,
137 CrlSign = 1 << 9,
138 EncipherOnly = 1 << 8,
139 DecipherOnly = 1 << 7,
140
141 // Deprecated SHOUTING_CASE names for Key_Constraints
142 // will be removed in a future major release
153 };
154
155 Key_Constraints(const Key_Constraints& other) = default;
157 Key_Constraints& operator=(const Key_Constraints& other) = default;
159 ~Key_Constraints() = default;
160
161 // NOLINTNEXTLINE(*-explicit-conversions)
162 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
163
164 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
165
166 Key_Constraints() : m_value(0) {}
167
168 /**
169 * Return typical constraints for a CA certificate.
170 *
171 * The reasons for KeyCertSign and CrlSign should be obvious
172 *
173 * CAB baseline requirements are that DigitalSignature should be set
174 * if the certificate is used to sign OCSP responses.
175 */
180
181 bool operator==(const Key_Constraints&) const = default;
182
183 void operator|=(Key_Constraints::Bits other) { m_value |= other; }
184
185 // Return true if all bits in mask are set
186 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
187
188 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
189
190 // Return true if any of the bits provided are set
191 bool includes_any(auto&&... bits) const { return (m_value & (bits | ...)) > 0; }
192
193 bool empty() const { return m_value == 0; }
194
195 uint32_t value() const { return m_value; }
196
197 std::string to_string() const;
198
199 /**
200 * Check that key constraints are permitted for a specific public key.
201 * @param key the public key on which the constraints shall be enforced on
202 * @return false if the constraints are not permitted for this key
203 */
204 bool compatible_with(const Public_Key& key) const;
205
206 private:
207 uint32_t m_value;
208};
209
210/**
211* X.509 ReasonFlags BIT STRING used by CRLDistributionPoints and
212* IssuingDistributionPoint (RFC 5280 4.2.1.13 / 5.2.5).
213*/
214class BOTAN_PUBLIC_API(3, 13) ReasonFlags final {
215 public:
216 /* RFC 5280 4.2.1.13:
217 * ReasonFlags ::= BIT STRING {
218 * unused (0),
219 * keyCompromise (1),
220 * cACompromise (2),
221 * affiliationChanged (3),
222 * superseded (4),
223 * cessationOfOperation (5),
224 * certificateHold (6),
225 * privilegeWithdrawn (7),
226 * aACompromise (8) }
227 */
228 enum Bits : uint16_t /* NOLINT(*-use-enum-class,performance-enum-size) */ {
229 None = 0,
231 CaCompromise = 1 << 6,
233 Superseded = 1 << 4,
237 AaCompromise = 1 << 0,
238 };
239
243
244 // NOLINTNEXTLINE(*-explicit-conversions)
245 ReasonFlags(ReasonFlags::Bits bits) : ReasonFlags(static_cast<uint16_t>(bits)) {}
246
247 explicit ReasonFlags(uint16_t bits) : m_value(bits) {
248 if((m_value & static_cast<uint16_t>(~DefinedReasonBits)) != 0) {
249 throw Decoding_Error("ReasonFlags contains undefined reason bits");
250 }
251 if(m_value == 0) {
252 throw Decoding_Error("ReasonFlags must have at least one defined reason");
253 }
254 }
255
256 bool operator==(const ReasonFlags&) const = default;
257
258 bool includes(ReasonFlags::Bits other) const { return (m_value & other) == other; }
259
260 bool includes(ReasonFlags other) const { return (m_value & other.m_value) == other.m_value; }
261
262 uint16_t value() const { return m_value; }
263
264 private:
265 uint16_t m_value;
266};
267
269 return ReasonFlags(static_cast<uint16_t>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b)));
270}
271
272/**
273* X.509v2 CRL Reason Code.
274*/
287
296
297} // namespace Botan
298
299#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:176
bool includes(Key_Constraints other) const
Definition pkix_enums.h:188
void operator|=(Key_Constraints::Bits other)
Definition pkix_enums.h:183
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition pkix_enums.h:164
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition pkix_enums.h:186
uint32_t value() const
Definition pkix_enums.h:195
Key_Constraints(const Key_Constraints &other)=default
bool includes_any(auto &&... bits) const
Definition pkix_enums.h:191
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:162
static constexpr uint16_t DefinedReasonBits
Definition pkix_enums.h:240
bool includes(ReasonFlags::Bits other) const
Definition pkix_enums.h:258
ReasonFlags(uint16_t bits)
Definition pkix_enums.h:247
ReasonFlags(ReasonFlags::Bits bits)
Definition pkix_enums.h:245
bool operator==(const ReasonFlags &) const =default
bool includes(ReasonFlags other) const
Definition pkix_enums.h:260
uint16_t value() const
Definition pkix_enums.h:262
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