OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_CERT_STATUS_FLAGS_H_ | 5 #ifndef NET_BASE_CERT_STATUS_FLAGS_H_ |
6 #define NET_BASE_CERT_STATUS_FLAGS_H_ | 6 #define NET_BASE_CERT_STATUS_FLAGS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | |
10 | |
11 namespace net { | 9 namespace net { |
12 | 10 |
13 // Bitmask of status flags of a certificate, representing any errors, as well as | 11 // Status flags, such as errors and extended validation. |
14 // other non-error status information such as whether the certificate is EV. | 12 enum { |
15 typedef uint32 CertStatus; | 13 // Bits 0 to 15 are for errors. |
| 14 CERT_STATUS_ALL_ERRORS = 0xFFFF, |
| 15 CERT_STATUS_COMMON_NAME_INVALID = 1 << 0, |
| 16 CERT_STATUS_DATE_INVALID = 1 << 1, |
| 17 CERT_STATUS_AUTHORITY_INVALID = 1 << 2, |
| 18 // 1 << 3 is reserved for ERR_CERT_CONTAINS_ERRORS (not useful with WinHTTP). |
| 19 CERT_STATUS_NO_REVOCATION_MECHANISM = 1 << 4, |
| 20 CERT_STATUS_UNABLE_TO_CHECK_REVOCATION = 1 << 5, |
| 21 CERT_STATUS_REVOKED = 1 << 6, |
| 22 CERT_STATUS_INVALID = 1 << 7, |
| 23 CERT_STATUS_WEAK_SIGNATURE_ALGORITHM = 1 << 8, |
| 24 CERT_STATUS_NOT_IN_DNS = 1 << 9, |
| 25 CERT_STATUS_NON_UNIQUE_NAME = 1 << 10, |
16 | 26 |
17 // The possible status bits for CertStatus. | 27 // Bits 16 to 30 are for non-error statuses. |
18 // NOTE: Because these names have appeared in bug reports, we preserve them as | 28 CERT_STATUS_IS_EV = 1 << 16, |
19 // MACRO_STYLE for continuity, instead of renaming them to kConstantStyle as | 29 CERT_STATUS_REV_CHECKING_ENABLED = 1 << 17, |
20 // befits most static consts. | 30 CERT_STATUS_IS_DNSSEC = 1 << 18, |
21 // Bits 0 to 15 are for errors. | |
22 static const CertStatus CERT_STATUS_ALL_ERRORS = 0xFFFF; | |
23 static const CertStatus CERT_STATUS_COMMON_NAME_INVALID = 1 << 0; | |
24 static const CertStatus CERT_STATUS_DATE_INVALID = 1 << 1; | |
25 static const CertStatus CERT_STATUS_AUTHORITY_INVALID = 1 << 2; | |
26 // 1 << 3 is reserved for ERR_CERT_CONTAINS_ERRORS (not useful with WinHTTP). | |
27 static const CertStatus CERT_STATUS_NO_REVOCATION_MECHANISM = 1 << 4; | |
28 static const CertStatus CERT_STATUS_UNABLE_TO_CHECK_REVOCATION = 1 << 5; | |
29 static const CertStatus CERT_STATUS_REVOKED = 1 << 6; | |
30 static const CertStatus CERT_STATUS_INVALID = 1 << 7; | |
31 static const CertStatus CERT_STATUS_WEAK_SIGNATURE_ALGORITHM = 1 << 8; | |
32 static const CertStatus CERT_STATUS_NOT_IN_DNS = 1 << 9; | |
33 static const CertStatus CERT_STATUS_NON_UNIQUE_NAME = 1 << 10; | |
34 | 31 |
35 // Bits 16 to 31 are for non-error statuses. | 32 // 1 << 31 (the sign bit) is reserved so that the cert status will never be |
36 static const CertStatus CERT_STATUS_IS_EV = 1 << 16; | 33 // negative. |
37 static const CertStatus CERT_STATUS_REV_CHECKING_ENABLED = 1 << 17; | 34 }; |
38 static const CertStatus CERT_STATUS_IS_DNSSEC = 1 << 18; | |
39 | 35 |
40 // Returns true if the specified cert status has an error set. | 36 // Returns true if the specified cert status has an error set. |
41 static inline bool IsCertStatusError(CertStatus status) { | 37 static inline bool IsCertStatusError(int status) { |
42 return (CERT_STATUS_ALL_ERRORS & status) != 0; | 38 return (CERT_STATUS_ALL_ERRORS & status) != 0; |
43 } | 39 } |
44 | 40 |
45 // Maps a network error code to the equivalent certificate status flag. If | 41 // Maps a network error code to the equivalent certificate status flag. If |
46 // the error code is not a certificate error, it is mapped to 0. | 42 // the error code is not a certificate error, it is mapped to 0. |
47 CertStatus MapNetErrorToCertStatus(int error); | 43 int MapNetErrorToCertStatus(int error); |
48 | 44 |
49 // Maps the most serious certificate error in the certificate status flags | 45 // Maps the most serious certificate error in the certificate status flags |
50 // to the equivalent network error code. | 46 // to the equivalent network error code. |
51 int MapCertStatusToNetError(CertStatus cert_status); | 47 int MapCertStatusToNetError(int cert_status); |
52 | 48 |
53 } // namespace net | 49 } // namespace net |
54 | 50 |
55 #endif // NET_BASE_CERT_STATUS_FLAGS_H_ | 51 #endif // NET_BASE_CERT_STATUS_FLAGS_H_ |
OLD | NEW |