Bug 1048642, Part 1: Change TamperOnce return type from SECStatus to Result, r=cviecco
authorBrian Smith <brian@briansmith.org>
Sun, 03 Aug 2014 22:49:10 -0700
changeset 14648 75b0a9c807fabee0ad81c3c6675babc8d1d8f771
parent 14647 5d522165ffbbcdb1744ac78026d0f722add3f125
child 14649 91860e48f97b7554945495e611c293cb87f41375
push id3202
push userfranziskuskiefer@gmail.com
push dateMon, 01 Oct 2018 08:30:12 +0000
reviewerscviecco
bugs1048642
Bug 1048642, Part 1: Change TamperOnce return type from SECStatus to Result, r=cviecco
lib/mozpkix/test/gtest/pkixocsp_VerifyEncodedOCSPResponse.cpp
lib/mozpkix/test/lib/pkixtestutil.cpp
lib/mozpkix/test/lib/pkixtestutil.h
--- a/lib/mozpkix/test/gtest/pkixocsp_VerifyEncodedOCSPResponse.cpp
+++ b/lib/mozpkix/test/gtest/pkixocsp_VerifyEncodedOCSPResponse.cpp
@@ -627,19 +627,20 @@ TEST_F(pkixocsp_VerifyEncodedResponse_De
 #define EKU_PREFIX \
   0x06, 8, /* OBJECT IDENTIFIER, 8 bytes */ \
   0x2B, 6, 1, 5, 5, 7, /* id-pkix */ \
   0x03 /* id-kp */
   static const uint8_t EKU_SERVER_AUTH[] = { EKU_PREFIX, 0x01 }; // serverAuth
   static const uint8_t EKU_OCSP_SIGNER[] = { EKU_PREFIX, 0x09 }; // OCSPSigning
 #undef EKU_PREFIX
   SECItem responseSECItem = UnsafeMapInputToSECItem(response);
-  ASSERT_SECSuccess(TamperOnce(responseSECItem,
-                               EKU_SERVER_AUTH, PR_ARRAY_SIZE(EKU_SERVER_AUTH),
-                               EKU_OCSP_SIGNER, PR_ARRAY_SIZE(EKU_OCSP_SIGNER)));
+  ASSERT_EQ(Success,
+            TamperOnce(responseSECItem,
+                       EKU_SERVER_AUTH, PR_ARRAY_SIZE(EKU_SERVER_AUTH),
+                       EKU_OCSP_SIGNER, PR_ARRAY_SIZE(EKU_OCSP_SIGNER)));
 
   bool expired;
   ASSERT_EQ(Result::ERROR_OCSP_INVALID_SIGNING_CERT,
             VerifyEncodedOCSPResponse(trustDomain, *endEntityCertID, now,
                                       END_ENTITY_MAX_LIFETIME_IN_DAYS,
                                       response, expired));
   ASSERT_FALSE(expired);
 }
--- a/lib/mozpkix/test/lib/pkixtestutil.cpp
+++ b/lib/mozpkix/test/lib/pkixtestutil.cpp
@@ -91,58 +91,51 @@ OpenFile(const char* dir, const char* fi
   if (!file) {
     // TODO: map errno to NSPR error code
     PR_SetError(PR_FILE_NOT_FOUND_ERROR, errno);
   }
 #endif
   return file.release();
 }
 
-SECStatus
+Result
 TamperOnce(SECItem& item,
            const uint8_t* from, size_t fromLen,
            const uint8_t* to, size_t toLen)
 {
   if (!item.data || !from || !to || fromLen != toLen) {
-    PR_NOT_REACHED("invalid args to TamperOnce");
-    PR_SetError(SEC_ERROR_INVALID_ARGS, 0);
-    return SECFailure;
+    return Result::FATAL_ERROR_INVALID_ARGS;
   }
 
   if (fromLen < 8) {
-    PR_NOT_REACHED("invalid parameter to TamperOnce; fromLen must be at least 8");
-    PR_SetError(SEC_ERROR_INVALID_ARGS, 0);
-    return SECFailure;
+    return Result::FATAL_ERROR_INVALID_ARGS;
   }
 
   uint8_t* p = item.data;
   size_t remaining = item.len;
   bool alreadyFoundMatch = false;
   for (;;) {
     uint8_t* foundFirstByte = static_cast<uint8_t*>(memchr(p, from[0],
                                                            remaining));
     if (!foundFirstByte) {
       if (alreadyFoundMatch) {
-        return SECSuccess;
+        return Success;
       }
-      PR_SetError(SEC_ERROR_BAD_DATA, 0);
-      return SECFailure;
+      return Result::FATAL_ERROR_INVALID_ARGS;
     }
     remaining -= (foundFirstByte - p);
     if (remaining < fromLen) {
       if (alreadyFoundMatch) {
-        return SECSuccess;
+        return Success;
       }
-      PR_SetError(SEC_ERROR_BAD_DATA, 0);
-      return SECFailure;
+      return Result::FATAL_ERROR_INVALID_ARGS;
     }
     if (!memcmp(foundFirstByte, from, fromLen)) {
       if (alreadyFoundMatch) {
-        PR_SetError(SEC_ERROR_BAD_DATA, 0);
-        return SECFailure;
+        return Result::FATAL_ERROR_INVALID_ARGS;
       }
       alreadyFoundMatch = true;
       memmove(foundFirstByte, to, toLen);
       p = foundFirstByte + toLen;
     } else {
       p = foundFirstByte + 1;
       --remaining;
     }
--- a/lib/mozpkix/test/lib/pkixtestutil.h
+++ b/lib/mozpkix/test/lib/pkixtestutil.h
@@ -87,18 +87,20 @@ const SECItem* ASCIIToDERName(PLArenaPoo
 
 // Replace one substring in item with another of the same length, but only if
 // the substring was found exactly once. The "only once" restriction is helpful
 // for avoiding making multiple changes at once.
 //
 // The string to search for must be 8 or more bytes long so that it is
 // extremely unlikely that there will ever be any false positive matches
 // in digital signatures, keys, hashes, etc.
-SECStatus TamperOnce(SECItem& item, const uint8_t* from, size_t fromLen,
-                     const uint8_t* to, size_t toLen);
+//
+// Returns true on success, false on failure.
+Result TamperOnce(SECItem& item, const uint8_t* from, size_t fromLen,
+                  const uint8_t* to, size_t toLen);
 
 Result InitInputFromSECItem(const SECItem* secItem, /*out*/ Input& input);
 
 ///////////////////////////////////////////////////////////////////////////////
 // Encode Certificates
 
 enum Version { v1 = 0, v2 = 1, v3 = 2 };