Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BSSL_PKI_CERT_STATUS_FLAGS_H_ |
| 6 | #define BSSL_PKI_CERT_STATUS_FLAGS_H_ |
| 7 | |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 8 | #include <stdint.h> |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 9 | #include "fillins/openssl_util.h" |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 10 | |
| 11 | |
| 12 | |
| 13 | namespace bssl { |
| 14 | |
| 15 | // Bitmask of status flags of a certificate, representing any errors, as well as |
| 16 | // other non-error status information such as whether the certificate is EV. |
| 17 | typedef uint32_t CertStatus; |
| 18 | |
| 19 | // NOTE: Because these names have appeared in bug reports, we preserve them as |
| 20 | // MACRO_STYLE for continuity, instead of renaming them to kConstantStyle as |
| 21 | // befits most static consts. |
| 22 | #define CERT_STATUS_FLAG(label, value) \ |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 23 | CertStatus static const CERT_STATUS_##label = value; |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 24 | #include "cert_status_flags_list.h" |
| 25 | #undef CERT_STATUS_FLAG |
| 26 | |
| 27 | static const CertStatus CERT_STATUS_ALL_ERRORS = 0xFF00FFFF; |
| 28 | |
| 29 | // Returns true if the specified cert status has an error set. |
| 30 | inline bool IsCertStatusError(CertStatus status) { |
| 31 | return (CERT_STATUS_ALL_ERRORS & status) != 0; |
| 32 | } |
| 33 | |
| 34 | // Maps a network error code to the equivalent certificate status flag. If |
| 35 | // the error code is not a certificate error, it is mapped to 0. |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 36 | // Note: It is not safe to go bssl::CertStatus -> bssl::Error -> |
| 37 | // bssl::CertStatus, as the CertStatus contains more information. Conversely, |
| 38 | // going from bssl::Error -> bssl::CertStatus -> bssl::Error is not a lossy |
| 39 | // function, for the same reason. To avoid incorrect use, this is only exported |
| 40 | // for unittest helpers. |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 41 | OPENSSL_EXPORT CertStatus MapNetErrorToCertStatus(int error); |
| 42 | |
| 43 | // Maps the most serious certificate error in the certificate status flags |
| 44 | // to the equivalent network error code. |
| 45 | OPENSSL_EXPORT int MapCertStatusToNetError(CertStatus cert_status); |
| 46 | |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 47 | } // namespace bssl |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 48 | |
| 49 | #endif // BSSL_PKI_CERT_STATUS_FLAGS_H_ |