cert_status_flags.h 1.8 KB

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