blob: cd66547c56d26e310b69c5e944a45f02902fffb5 [file] [log] [blame]
Bob Beckbc97b7a2023-04-18 08:35:15 -06001// 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 Beckbc97b7a2023-04-18 08:35:15 -06008#include <stdint.h>
Bob Beck5c7a2a02023-11-20 17:28:21 -07009#include "fillins/openssl_util.h"
Bob Beckbc97b7a2023-04-18 08:35:15 -060010
11
12
13namespace 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.
17typedef 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 Beck5c7a2a02023-11-20 17:28:21 -070023 CertStatus static const CERT_STATUS_##label = value;
Bob Beckbc97b7a2023-04-18 08:35:15 -060024#include "cert_status_flags_list.h"
25#undef CERT_STATUS_FLAG
26
27static const CertStatus CERT_STATUS_ALL_ERRORS = 0xFF00FFFF;
28
29// Returns true if the specified cert status has an error set.
30inline 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 Beck5c7a2a02023-11-20 17:28:21 -070036// 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 Beckbc97b7a2023-04-18 08:35:15 -060041OPENSSL_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.
45OPENSSL_EXPORT int MapCertStatusToNetError(CertStatus cert_status);
46
Bob Beck5c7a2a02023-11-20 17:28:21 -070047} // namespace bssl
Bob Beckbc97b7a2023-04-18 08:35:15 -060048
49#endif // BSSL_PKI_CERT_STATUS_FLAGS_H_