Bug 1065264: Use MOZILLA_PKIX_MAP_LIST to define mozilla::pkix::Result, r=keeler
authorBrian Smith <brian@briansmith.org>
Wed, 10 Sep 2014 00:17:24 -0700
changeset 206340 7c4ab322d5dd758345156b3ab93663f48eb9522f
parent 206339 0830392b3bfac180e2dba13b4d8c1669089203f7
child 206341 ecb41e4383b3a8b7e22e3b14ef02903f05b54e88
push id27524
push usercbook@mozilla.com
push dateMon, 22 Sep 2014 10:59:09 +0000
treeherdermozilla-central@53f7f5b6d7bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1065264
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1065264: Use MOZILLA_PKIX_MAP_LIST to define mozilla::pkix::Result, r=keeler
security/pkix/include/pkix/Result.h
security/pkix/lib/pkixnss.cpp
security/pkix/lib/pkixresult.cpp
security/pkix/test/gtest/pkixgtest.cpp
--- a/security/pkix/include/pkix/Result.h
+++ b/security/pkix/include/pkix/Result.h
@@ -28,171 +28,124 @@
 #include <cassert>
 
 #include "pkix/enumclass.h"
 
 namespace mozilla { namespace pkix {
 
 static const unsigned int FATAL_ERROR_FLAG = 0x800;
 
-MOZILLA_PKIX_ENUM_CLASS Result
-{
-  Success = 0,
-
-  ERROR_BAD_DER = 1,
-  ERROR_CA_CERT_INVALID = 2,
-  ERROR_BAD_SIGNATURE = 3,
-  ERROR_CERT_BAD_ACCESS_LOCATION = 4,
-  ERROR_CERT_NOT_IN_NAME_SPACE = 5,
-  ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED = 6,
-  ERROR_CONNECT_REFUSED = 7,
-  ERROR_EXPIRED_CERTIFICATE = 8,
-  ERROR_EXTENSION_VALUE_INVALID = 9,
-  ERROR_INADEQUATE_CERT_TYPE = 10,
-  ERROR_INADEQUATE_KEY_USAGE = 11,
-  ERROR_INVALID_ALGORITHM = 12,
-  ERROR_INVALID_TIME = 13,
-  ERROR_KEY_PINNING_FAILURE = 14,
-  ERROR_PATH_LEN_CONSTRAINT_INVALID = 15,
-  ERROR_POLICY_VALIDATION_FAILED = 16,
-  ERROR_REVOKED_CERTIFICATE = 17,
-  ERROR_UNKNOWN_CRITICAL_EXTENSION = 18,
-  ERROR_UNKNOWN_ISSUER = 19,
-  ERROR_UNTRUSTED_CERT = 20,
-  ERROR_UNTRUSTED_ISSUER = 21,
-
-  ERROR_OCSP_BAD_SIGNATURE = 22,
-  ERROR_OCSP_INVALID_SIGNING_CERT = 23,
-  ERROR_OCSP_MALFORMED_REQUEST = 24,
-  ERROR_OCSP_MALFORMED_RESPONSE = 25,
-  ERROR_OCSP_OLD_RESPONSE = 26,
-  ERROR_OCSP_REQUEST_NEEDS_SIG = 27,
-  ERROR_OCSP_RESPONDER_CERT_INVALID = 28,
-  ERROR_OCSP_SERVER_ERROR = 29,
-  ERROR_OCSP_TRY_SERVER_LATER = 30,
-  ERROR_OCSP_UNAUTHORIZED_REQUEST = 31,
-  ERROR_OCSP_UNKNOWN_RESPONSE_STATUS = 32,
-  ERROR_OCSP_UNKNOWN_CERT = 33,
-  ERROR_OCSP_FUTURE_RESPONSE = 34,
-
-  ERROR_UNKNOWN_ERROR = 35,
-  ERROR_INVALID_KEY = 36,
-  ERROR_UNSUPPORTED_KEYALG = 37,
-  ERROR_EXPIRED_ISSUER_CERTIFICATE = 38,
-  ERROR_CA_CERT_USED_AS_END_ENTITY = 39,
-  ERROR_INADEQUATE_KEY_SIZE = 40,
-
-  // Keep this in sync with MAP_LIST below
-
-  FATAL_ERROR_INVALID_ARGS = FATAL_ERROR_FLAG | 1,
-  FATAL_ERROR_INVALID_STATE = FATAL_ERROR_FLAG | 2,
-  FATAL_ERROR_LIBRARY_FAILURE = FATAL_ERROR_FLAG | 3,
-  FATAL_ERROR_NO_MEMORY = FATAL_ERROR_FLAG | 4,
-
-  // Keep this in sync with MAP_LIST below
-};
-
 // The first argument to MOZILLA_PKIX_MAP() is used for building the mapping
 // from error code to error name in MapResultToName.
 //
-// The second argument to MOZILLA_PKIX_MAP() is used, along with the first
+// The second argument is for defining the value for the enum literal in the
+// Result enum class.
+//
+// The third argument to MOZILLA_PKIX_MAP() is used, along with the first
 // argument, for maintaining the mapping of mozilla::pkix error codes to
 // NSS/NSPR error codes in pkixnss.cpp.
 #define MOZILLA_PKIX_MAP_LIST \
-    MOZILLA_PKIX_MAP(Result::Success, 0) \
-    MOZILLA_PKIX_MAP(Result::ERROR_BAD_DER, \
-                         SEC_ERROR_BAD_DER) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CA_CERT_INVALID, \
-                         SEC_ERROR_CA_CERT_INVALID) \
-    MOZILLA_PKIX_MAP(Result::ERROR_BAD_SIGNATURE, \
-                         SEC_ERROR_BAD_SIGNATURE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CERT_BAD_ACCESS_LOCATION, \
-                         SEC_ERROR_CERT_BAD_ACCESS_LOCATION) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CERT_NOT_IN_NAME_SPACE, \
-                         SEC_ERROR_CERT_NOT_IN_NAME_SPACE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED, \
-                         SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CONNECT_REFUSED, \
-                                PR_CONNECT_REFUSED_ERROR) \
-    MOZILLA_PKIX_MAP(Result::ERROR_EXPIRED_CERTIFICATE, \
-                         SEC_ERROR_EXPIRED_CERTIFICATE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_EXTENSION_VALUE_INVALID, \
-                         SEC_ERROR_EXTENSION_VALUE_INVALID) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INADEQUATE_CERT_TYPE, \
-                         SEC_ERROR_INADEQUATE_CERT_TYPE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INADEQUATE_KEY_USAGE, \
-                         SEC_ERROR_INADEQUATE_KEY_USAGE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INVALID_ALGORITHM, \
-                         SEC_ERROR_INVALID_ALGORITHM) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INVALID_TIME, \
-                         SEC_ERROR_INVALID_TIME) \
-    MOZILLA_PKIX_MAP(Result::ERROR_KEY_PINNING_FAILURE, \
-                MOZILLA_PKIX_ERROR_KEY_PINNING_FAILURE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_PATH_LEN_CONSTRAINT_INVALID, \
-                         SEC_ERROR_PATH_LEN_CONSTRAINT_INVALID) \
-    MOZILLA_PKIX_MAP(Result::ERROR_POLICY_VALIDATION_FAILED, \
-                         SEC_ERROR_POLICY_VALIDATION_FAILED) \
-    MOZILLA_PKIX_MAP(Result::ERROR_REVOKED_CERTIFICATE, \
-                         SEC_ERROR_REVOKED_CERTIFICATE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNKNOWN_CRITICAL_EXTENSION, \
-                         SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNKNOWN_ERROR, \
-                                PR_UNKNOWN_ERROR) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNKNOWN_ISSUER, \
-                         SEC_ERROR_UNKNOWN_ISSUER) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNTRUSTED_CERT, \
-                         SEC_ERROR_UNTRUSTED_CERT) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNTRUSTED_ISSUER, \
-                         SEC_ERROR_UNTRUSTED_ISSUER) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_BAD_SIGNATURE, \
-                         SEC_ERROR_OCSP_BAD_SIGNATURE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_INVALID_SIGNING_CERT, \
-                         SEC_ERROR_OCSP_INVALID_SIGNING_CERT) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_MALFORMED_REQUEST, \
-                         SEC_ERROR_OCSP_MALFORMED_REQUEST) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_MALFORMED_RESPONSE, \
-                         SEC_ERROR_OCSP_MALFORMED_RESPONSE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_OLD_RESPONSE, \
-                         SEC_ERROR_OCSP_OLD_RESPONSE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_REQUEST_NEEDS_SIG, \
-                         SEC_ERROR_OCSP_REQUEST_NEEDS_SIG) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_RESPONDER_CERT_INVALID, \
-                         SEC_ERROR_OCSP_RESPONDER_CERT_INVALID) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_SERVER_ERROR, \
-                         SEC_ERROR_OCSP_SERVER_ERROR) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_TRY_SERVER_LATER, \
-                         SEC_ERROR_OCSP_TRY_SERVER_LATER) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_UNAUTHORIZED_REQUEST, \
-                         SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_UNKNOWN_RESPONSE_STATUS, \
-                         SEC_ERROR_OCSP_UNKNOWN_RESPONSE_STATUS) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_UNKNOWN_CERT, \
-                         SEC_ERROR_OCSP_UNKNOWN_CERT) \
-    MOZILLA_PKIX_MAP(Result::ERROR_OCSP_FUTURE_RESPONSE, \
-                         SEC_ERROR_OCSP_FUTURE_RESPONSE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INVALID_KEY, \
-                         SEC_ERROR_INVALID_KEY) \
-    MOZILLA_PKIX_MAP(Result::ERROR_UNSUPPORTED_KEYALG, \
-                         SEC_ERROR_UNSUPPORTED_KEYALG) \
-    MOZILLA_PKIX_MAP(Result::ERROR_EXPIRED_ISSUER_CERTIFICATE, \
-                         SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE) \
-    MOZILLA_PKIX_MAP(Result::ERROR_CA_CERT_USED_AS_END_ENTITY, \
-                MOZILLA_PKIX_ERROR_CA_CERT_USED_AS_END_ENTITY) \
-    MOZILLA_PKIX_MAP(Result::ERROR_INADEQUATE_KEY_SIZE, \
-                MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE) \
-    MOZILLA_PKIX_MAP(Result::FATAL_ERROR_INVALID_ARGS, \
-                               SEC_ERROR_INVALID_ARGS) \
-    MOZILLA_PKIX_MAP(Result::FATAL_ERROR_INVALID_STATE, \
-                                      PR_INVALID_STATE_ERROR) \
-    MOZILLA_PKIX_MAP(Result::FATAL_ERROR_LIBRARY_FAILURE, \
-                               SEC_ERROR_LIBRARY_FAILURE) \
-    MOZILLA_PKIX_MAP(Result::FATAL_ERROR_NO_MEMORY, \
-                               SEC_ERROR_NO_MEMORY) \
+    MOZILLA_PKIX_MAP(Success, 0, 0) \
+    MOZILLA_PKIX_MAP(ERROR_BAD_DER, 1, \
+                     SEC_ERROR_BAD_DER) \
+    MOZILLA_PKIX_MAP(ERROR_CA_CERT_INVALID, 2, \
+                     SEC_ERROR_CA_CERT_INVALID) \
+    MOZILLA_PKIX_MAP(ERROR_BAD_SIGNATURE, 3, \
+                     SEC_ERROR_BAD_SIGNATURE) \
+    MOZILLA_PKIX_MAP(ERROR_CERT_BAD_ACCESS_LOCATION, 4, \
+                     SEC_ERROR_CERT_BAD_ACCESS_LOCATION) \
+    MOZILLA_PKIX_MAP(ERROR_CERT_NOT_IN_NAME_SPACE, 5, \
+                     SEC_ERROR_CERT_NOT_IN_NAME_SPACE) \
+    MOZILLA_PKIX_MAP(ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED, 6, \
+                     SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED) \
+    MOZILLA_PKIX_MAP(ERROR_CONNECT_REFUSED, 7, \
+                     PR_CONNECT_REFUSED_ERROR) \
+    MOZILLA_PKIX_MAP(ERROR_EXPIRED_CERTIFICATE, 8, \
+                     SEC_ERROR_EXPIRED_CERTIFICATE) \
+    MOZILLA_PKIX_MAP(ERROR_EXTENSION_VALUE_INVALID, 9, \
+                     SEC_ERROR_EXTENSION_VALUE_INVALID) \
+    MOZILLA_PKIX_MAP(ERROR_INADEQUATE_CERT_TYPE, 10, \
+                     SEC_ERROR_INADEQUATE_CERT_TYPE) \
+    MOZILLA_PKIX_MAP(ERROR_INADEQUATE_KEY_USAGE, 11, \
+                     SEC_ERROR_INADEQUATE_KEY_USAGE) \
+    MOZILLA_PKIX_MAP(ERROR_INVALID_ALGORITHM, 12, \
+                     SEC_ERROR_INVALID_ALGORITHM) \
+    MOZILLA_PKIX_MAP(ERROR_INVALID_TIME, 13, \
+                     SEC_ERROR_INVALID_TIME) \
+    MOZILLA_PKIX_MAP(ERROR_KEY_PINNING_FAILURE, 14, \
+                     MOZILLA_PKIX_ERROR_KEY_PINNING_FAILURE) \
+    MOZILLA_PKIX_MAP(ERROR_PATH_LEN_CONSTRAINT_INVALID, 15, \
+                     SEC_ERROR_PATH_LEN_CONSTRAINT_INVALID) \
+    MOZILLA_PKIX_MAP(ERROR_POLICY_VALIDATION_FAILED, 16, \
+                     SEC_ERROR_POLICY_VALIDATION_FAILED) \
+    MOZILLA_PKIX_MAP(ERROR_REVOKED_CERTIFICATE, 17, \
+                     SEC_ERROR_REVOKED_CERTIFICATE) \
+    MOZILLA_PKIX_MAP(ERROR_UNKNOWN_CRITICAL_EXTENSION, 18, \
+                     SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION) \
+    MOZILLA_PKIX_MAP(ERROR_UNKNOWN_ERROR, 19, \
+                     PR_UNKNOWN_ERROR) \
+    MOZILLA_PKIX_MAP(ERROR_UNKNOWN_ISSUER, 20, \
+                     SEC_ERROR_UNKNOWN_ISSUER) \
+    MOZILLA_PKIX_MAP(ERROR_UNTRUSTED_CERT, 21, \
+                     SEC_ERROR_UNTRUSTED_CERT) \
+    MOZILLA_PKIX_MAP(ERROR_UNTRUSTED_ISSUER, 22, \
+                     SEC_ERROR_UNTRUSTED_ISSUER) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_BAD_SIGNATURE, 23, \
+                     SEC_ERROR_OCSP_BAD_SIGNATURE) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_INVALID_SIGNING_CERT, 24, \
+                     SEC_ERROR_OCSP_INVALID_SIGNING_CERT) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_MALFORMED_REQUEST, 25, \
+                     SEC_ERROR_OCSP_MALFORMED_REQUEST) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_MALFORMED_RESPONSE, 26, \
+                     SEC_ERROR_OCSP_MALFORMED_RESPONSE) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_OLD_RESPONSE, 27, \
+                     SEC_ERROR_OCSP_OLD_RESPONSE) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_REQUEST_NEEDS_SIG, 28, \
+                     SEC_ERROR_OCSP_REQUEST_NEEDS_SIG) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_RESPONDER_CERT_INVALID, 29, \
+                     SEC_ERROR_OCSP_RESPONDER_CERT_INVALID) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_SERVER_ERROR, 30, \
+                     SEC_ERROR_OCSP_SERVER_ERROR) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_TRY_SERVER_LATER, 31, \
+                     SEC_ERROR_OCSP_TRY_SERVER_LATER) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_UNAUTHORIZED_REQUEST, 32, \
+                     SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_UNKNOWN_RESPONSE_STATUS, 33, \
+                     SEC_ERROR_OCSP_UNKNOWN_RESPONSE_STATUS) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_UNKNOWN_CERT, 34, \
+                     SEC_ERROR_OCSP_UNKNOWN_CERT) \
+    MOZILLA_PKIX_MAP(ERROR_OCSP_FUTURE_RESPONSE, 35, \
+                     SEC_ERROR_OCSP_FUTURE_RESPONSE) \
+    MOZILLA_PKIX_MAP(ERROR_INVALID_KEY, 36, \
+                     SEC_ERROR_INVALID_KEY) \
+    MOZILLA_PKIX_MAP(ERROR_UNSUPPORTED_KEYALG, 37, \
+                     SEC_ERROR_UNSUPPORTED_KEYALG) \
+    MOZILLA_PKIX_MAP(ERROR_EXPIRED_ISSUER_CERTIFICATE, 38, \
+                     SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE) \
+    MOZILLA_PKIX_MAP(ERROR_CA_CERT_USED_AS_END_ENTITY, 39, \
+                     MOZILLA_PKIX_ERROR_CA_CERT_USED_AS_END_ENTITY) \
+    MOZILLA_PKIX_MAP(ERROR_INADEQUATE_KEY_SIZE, 40, \
+                     MOZILLA_PKIX_ERROR_INADEQUATE_KEY_SIZE) \
+    MOZILLA_PKIX_MAP(FATAL_ERROR_INVALID_ARGS, FATAL_ERROR_FLAG | 1, \
+                     SEC_ERROR_INVALID_ARGS) \
+    MOZILLA_PKIX_MAP(FATAL_ERROR_INVALID_STATE, FATAL_ERROR_FLAG | 2, \
+                     PR_INVALID_STATE_ERROR) \
+    MOZILLA_PKIX_MAP(FATAL_ERROR_LIBRARY_FAILURE, FATAL_ERROR_FLAG | 3, \
+                     SEC_ERROR_LIBRARY_FAILURE) \
+    MOZILLA_PKIX_MAP(FATAL_ERROR_NO_MEMORY, FATAL_ERROR_FLAG | 4, \
+                     SEC_ERROR_NO_MEMORY) \
     /* nothing here */
 
+MOZILLA_PKIX_ENUM_CLASS Result
+{
+#define MOZILLA_PKIX_MAP(name, value, nss_name) name = value,
+  MOZILLA_PKIX_MAP_LIST
+#undef MOZILLA_PKIX_MAP
+};
+
 // Returns the stringified name of the given result, e.g. "Result::Success",
 // or nullptr if result is unknown (invalid).
 const char* MapResultToName(Result result);
 
 // We write many comparisons as (x != Success), and this shortened name makes
 // those comparisons clearer, especially because the shortened name often
 // results in less line wrapping.
 //
--- a/security/pkix/lib/pkixnss.cpp
+++ b/security/pkix/lib/pkixnss.cpp
@@ -190,35 +190,35 @@ DigestBuf(Input item, /*out*/ uint8_t* d
   return Success;
 }
 
 Result
 MapPRErrorCodeToResult(PRErrorCode error)
 {
   switch (error)
   {
-#define MOZILLA_PKIX_MAP(mozilla_pkix_result, nss_result) \
-    case nss_result: return mozilla_pkix_result;
+#define MOZILLA_PKIX_MAP(mozilla_pkix_result, value, nss_result) \
+    case nss_result: return Result::mozilla_pkix_result;
 
     MOZILLA_PKIX_MAP_LIST
 
 #undef MOZILLA_PKIX_MAP
 
     default:
       return Result::ERROR_UNKNOWN_ERROR;
   }
 }
 
 PRErrorCode
 MapResultToPRErrorCode(Result result)
 {
   switch (result)
   {
-#define MOZILLA_PKIX_MAP(mozilla_pkix_result, nss_result) \
-    case mozilla_pkix_result: return nss_result;
+#define MOZILLA_PKIX_MAP(mozilla_pkix_result, value, nss_result) \
+    case Result::mozilla_pkix_result: return nss_result;
 
     MOZILLA_PKIX_MAP_LIST
 
 #undef MOZILLA_PKIX_MAP
 
     default:
       PR_NOT_REACHED("Unknown error code in MapResultToPRErrorCode");
       return SEC_ERROR_LIBRARY_FAILURE;
--- a/security/pkix/lib/pkixresult.cpp
+++ b/security/pkix/lib/pkixresult.cpp
@@ -28,18 +28,18 @@
 
 namespace mozilla { namespace pkix {
 
 const char*
 MapResultToName(Result result)
 {
   switch (result)
   {
-#define MOZILLA_PKIX_MAP(mozilla_pkix_result, nss_result) \
-    case mozilla_pkix_result: return #mozilla_pkix_result;
+#define MOZILLA_PKIX_MAP(mozilla_pkix_result, value, nss_result) \
+    case Result::mozilla_pkix_result: return "Result::" #mozilla_pkix_result;
 
     MOZILLA_PKIX_MAP_LIST
 
 #undef MOZILLA_PKIX_MAP
 
     default:
       assert(false);
       return nullptr;