Botan 3.6.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/types.h>
11#include <string>
12
13namespace Botan {
14
15class Public_Key;
16
17/**
18* Certificate validation status code
19*/
21 OK = 0,
22 VERIFIED = 0,
23
24 // Revocation status
28 OCSP_NO_HTTP = 4,
29
30 // Warnings
33 DN_TOO_LONG = 501,
38
39 // Errors
40 FIRST_ERROR_STATUS = 1000,
41
43 UNTRUSTED_HASH = 1001,
44 NO_REVOCATION_DATA = 1002,
45 NO_MATCHING_CRLDP = 1003,
47
48 // Time problems
49 CERT_NOT_YET_VALID = 2000,
50 CERT_HAS_EXPIRED = 2001,
51 OCSP_NOT_YET_VALID = 2002,
52 OCSP_HAS_EXPIRED = 2003,
53 CRL_NOT_YET_VALID = 2004,
54 CRL_HAS_EXPIRED = 2005,
55 OCSP_IS_TOO_OLD = 2006,
56
57 // Chain generation problems
60 CERT_CHAIN_LOOP = 3002,
63
64 // Validation errors
65 POLICY_ERROR = 4000,
66 INVALID_USAGE = 4001,
70
71 // Revocation errors
74 OCSP_BAD_STATUS = 4007,
75
76 // Other problems
77 CERT_NAME_NOMATCH = 4008,
84 EXT_IN_V1_V2_CERT = 4505,
87
88 // Hard failures
89 CERT_IS_REVOKED = 5000,
90 CRL_BAD_SIGNATURE = 5001,
91 SIGNATURE_ERROR = 5002,
95};
96
97/**
98* Convert a status code to a human readable diagnostic message
99* @param code the certifcate status
100* @return string literal constant, or nullptr if code unknown
101*/
103
104/**
105* X.509v3 Key Constraints.
106* If updating update copy in ffi.h
107*/
109 public:
110 enum Bits : uint32_t {
111 None = 0,
112 DigitalSignature = 1 << 15,
113 NonRepudiation = 1 << 14,
114 KeyEncipherment = 1 << 13,
115 DataEncipherment = 1 << 12,
116 KeyAgreement = 1 << 11,
117 KeyCertSign = 1 << 10,
118 CrlSign = 1 << 9,
119 EncipherOnly = 1 << 8,
120 DecipherOnly = 1 << 7,
121
122 // Deprecated SHOUTING_CASE names for Key_Constraints
123 // will be removed in a future major release
125 DIGITAL_SIGNATURE BOTAN_DEPRECATED("Use DigitalSignature") = DigitalSignature,
126 NON_REPUDIATION BOTAN_DEPRECATED("Use NonRepudiation") = NonRepudiation,
127 KEY_ENCIPHERMENT BOTAN_DEPRECATED("Use KeyEncipherment") = KeyEncipherment,
128 DATA_ENCIPHERMENT BOTAN_DEPRECATED("Use DataEncipherment") = DataEncipherment,
130 KEY_CERT_SIGN BOTAN_DEPRECATED("Use KeyCertSign") = KeyCertSign,
131 CRL_SIGN BOTAN_DEPRECATED("Use CrlSign") = CrlSign,
132 ENCIPHER_ONLY BOTAN_DEPRECATED("Use EncipherOnly") = EncipherOnly,
133 DECIPHER_ONLY BOTAN_DEPRECATED("Use DecipherOnly") = DecipherOnly,
134 };
135
136 Key_Constraints(const Key_Constraints& other) = default;
138 Key_Constraints& operator=(const Key_Constraints& other) = default;
140
141 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
142
143 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
144
145 Key_Constraints() : m_value(0) {}
146
147 /**
148 * Return typical constraints for a CA certificate, namely
149 * KeyCertSign and CrlSign
150 */
154
155 bool operator==(const Key_Constraints&) const = default;
156
157 void operator|=(Key_Constraints::Bits other) { m_value |= other; }
158
159 // Return true if all bits in mask are set
160 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
161
162 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
163
164 // Return true if any of the bits provided are set
165 bool includes_any(auto&&... bits) const { return (m_value & (bits | ...)) > 0; }
166
167 bool empty() const { return m_value == 0; }
168
169 uint32_t value() const { return m_value; }
170
171 std::string to_string() const;
172
173 /**
174 * Check that key constraints are permitted for a specific public key.
175 * @param key the public key on which the constraints shall be enforced on
176 * @return false if the constraints are not permitted for this key
177 */
178 bool compatible_with(const Public_Key& key) const;
179
180 private:
181 uint32_t m_value;
182};
183
184/**
185* X.509v2 CRL Reason Code.
186*/
187enum class CRL_Code : uint32_t {
188 Unspecified = 0,
189 KeyCompromise = 1,
190 CaCompromise = 2,
192 Superseded = 4,
194 CertificateHold = 6,
195 RemoveFromCrl = 8,
197 AaCompromise = 10,
198};
199
200} // namespace Botan
201
202#endif
static Key_Constraints ca_constraints()
Definition pkix_enums.h:151
bool includes(Key_Constraints other) const
Definition pkix_enums.h:162
void operator|=(Key_Constraints::Bits other)
Definition pkix_enums.h:157
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition pkix_enums.h:143
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition pkix_enums.h:160
uint32_t value() const
Definition pkix_enums.h:169
Key_Constraints(const Key_Constraints &other)=default
bool includes_any(auto &&... bits) const
Definition pkix_enums.h:165
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:141
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_DEPRECATED(msg)
Definition compiler.h:125
@ KEY_ENCIPHERMENT
Definition ffi.h:1884
@ NO_CONSTRAINTS
Definition ffi.h:1881
@ CRL_SIGN
Definition ffi.h:1888
@ DIGITAL_SIGNATURE
Definition ffi.h:1882
@ KEY_AGREEMENT
Definition ffi.h:1886
@ DATA_ENCIPHERMENT
Definition ffi.h:1885
@ KEY_CERT_SIGN
Definition ffi.h:1887
@ ENCIPHER_ONLY
Definition ffi.h:1889
@ NON_REPUDIATION
Definition ffi.h:1883
@ DECIPHER_ONLY
Definition ffi.h:1890
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13
Certificate_Status_Code
Definition pkix_enums.h:20