Botan 3.12.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/types.h>
11#include <string>
12
13namespace Botan {
14
15class Public_Key;
16
17/**
18* Certificate validation status code
19*/
20enum class Certificate_Status_Code : uint16_t {
21 // TODO(Botan4) renumber this, e.g. Validation Errors -> IP_ADDR_BLOCKS_ERROR
22 // TODO(Botan4) rename variants to CamelCase
23 OK = 0,
25
26 // Revocation status
31
32 // Warnings
40
41 // Errors
43
49
50 // Time problems
58
59 // Revocation checks are skipped for chains which have an error more
60 // serious than this because they are anyway invalid
62
63 // Chain generation problems
69
70 // Validation errors
78
79 // Revocation errors
83
84 // Other problems
96
97 // Hard failures
105};
106
107/**
108* Convert a status code to a human readable diagnostic message
109* @param code the certificate status
110* @return string literal constant, or nullptr if code unknown
111*/
113
114/**
115* X.509v3 Key Constraints.
116* If updating update copy in ffi.h
117*/
119 public:
120 enum Bits : uint16_t /* NOLINT(*-use-enum-class) */ {
121 None = 0,
123 NonRepudiation = 1 << 14,
126 KeyAgreement = 1 << 11,
127 KeyCertSign = 1 << 10,
128 CrlSign = 1 << 9,
129 EncipherOnly = 1 << 8,
130 DecipherOnly = 1 << 7,
131
132 // Deprecated SHOUTING_CASE names for Key_Constraints
133 // will be removed in a future major release
144 };
145
146 Key_Constraints(const Key_Constraints& other) = default;
148 Key_Constraints& operator=(const Key_Constraints& other) = default;
150 ~Key_Constraints() = default;
151
152 // NOLINTNEXTLINE(*-explicit-conversions)
153 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
154
155 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
156
157 Key_Constraints() : m_value(0) {}
158
159 /**
160 * Return typical constraints for a CA certificate.
161 *
162 * The reasons for KeyCertSign and CrlSign should be obvious
163 *
164 * CAB baseline requirements are that DigitalSignature should be set
165 * if the certificate is used to sign OCSP responses.
166 */
171
172 bool operator==(const Key_Constraints&) const = default;
173
174 void operator|=(Key_Constraints::Bits other) { m_value |= other; }
175
176 // Return true if all bits in mask are set
177 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
178
179 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
180
181 // Return true if any of the bits provided are set
182 bool includes_any(auto&&... bits) const { return (m_value & (bits | ...)) > 0; }
183
184 bool empty() const { return m_value == 0; }
185
186 uint32_t value() const { return m_value; }
187
188 std::string to_string() const;
189
190 /**
191 * Check that key constraints are permitted for a specific public key.
192 * @param key the public key on which the constraints shall be enforced on
193 * @return false if the constraints are not permitted for this key
194 */
195 bool compatible_with(const Public_Key& key) const;
196
197 private:
198 uint32_t m_value;
199};
200
201/**
202* X.509v2 CRL Reason Code.
203*/
216
225
226} // namespace Botan
227
228#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:167
bool includes(Key_Constraints other) const
Definition pkix_enums.h:179
void operator|=(Key_Constraints::Bits other)
Definition pkix_enums.h:174
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition pkix_enums.h:155
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition pkix_enums.h:177
uint32_t value() const
Definition pkix_enums.h:186
Key_Constraints(const Key_Constraints &other)=default
bool includes_any(auto &&... bits) const
Definition pkix_enums.h:182
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:153
Certificate_Status_Code
Definition pkix_enums.h:20
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13