Bug 784739 - Switch from NULL to nullptr in services/; r=ehsan
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Wed, 31 Jul 2013 11:44:18 -0400
changeset 153067 5172d6907d409cc1c95b4a20a3c9b875284a7482
parent 153066 88130a1e283111c8fd39dbf2008547d347c61d52
child 153068 ac758cadd0341af4ea6a8e9763cf6b668a677734
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs784739
milestone25.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 784739 - Switch from NULL to nullptr in services/; r=ehsan
services/crypto/component/nsSyncJPAKE.cpp
--- a/services/crypto/component/nsSyncJPAKE.cpp
+++ b/services/crypto/component/nsSyncJPAKE.cpp
@@ -128,27 +128,28 @@ NS_IMETHODIMP nsSyncJPAKE::Round1(const 
                                   nsACString & aGX1,
                                   nsACString & aGV1,
                                   nsACString & aR1,
                                   nsACString & aGX2,
                                   nsACString & aGV2,
                                   nsACString & aR2)
 {
   NS_ENSURE_STATE(round == JPAKENotStarted);
-  NS_ENSURE_STATE(key == NULL);
+  NS_ENSURE_STATE(key == nullptr);
 
   static CK_MECHANISM_TYPE mechanisms[] = {
     CKM_NSS_JPAKE_ROUND1_SHA256,
     CKM_NSS_JPAKE_ROUND2_SHA256,
     CKM_NSS_JPAKE_FINAL_SHA256
   };
 
   PK11SlotInfo * slot = PK11_GetBestSlotMultiple(mechanisms,
-                                                 NUM_ELEM(mechanisms), NULL);
-  NS_ENSURE_STATE(slot != NULL);
+                                                 NUM_ELEM(mechanisms),
+                                                 nullptr);
+  NS_ENSURE_STATE(slot != nullptr);
     
   CK_BYTE pBuf[(NUM_ELEM(p) - 1) / 2];
   CK_BYTE qBuf[(NUM_ELEM(q) - 1) / 2];
   CK_BYTE gBuf[(NUM_ELEM(g) - 1) / 2];
     
   CK_KEY_TYPE keyType = CKK_NSS_JPAKE_ROUND1;
   NS_ENSURE_STATE(fromHex(p, pBuf, (NUM_ELEM(p) - 1)));
   NS_ENSURE_STATE(fromHex(q, qBuf, (NUM_ELEM(q) - 1)));
@@ -173,18 +174,18 @@ NS_IMETHODIMP nsSyncJPAKE::Round1(const 
       { gx2Buf, sizeof gx2Buf, gv2Buf, sizeof gv2Buf, r2Buf, sizeof r2Buf }
   };
   SECItem paramsItem;
   paramsItem.data = (unsigned char *) &rp;
   paramsItem.len = sizeof rp;
   key = PK11_KeyGenWithTemplate(slot, CKM_NSS_JPAKE_ROUND1_SHA256,
                                 CKM_NSS_JPAKE_ROUND1_SHA256,
                                 &paramsItem, keyTemplate,
-                                NUM_ELEM(keyTemplate), NULL);
-  nsresult rv = key != NULL
+                                NUM_ELEM(keyTemplate), nullptr);
+  nsresult rv = key != nullptr
               ? NS_OK
               : mapErrno();
   if (rv == NS_OK) {
     NS_ENSURE_TRUE(toHexString(rp.gx1.pGX, rp.gx1.ulGXLen, aGX1) &&
                    toHexString(rp.gx1.pGV, rp.gx1.ulGVLen, aGV1) &&
                    toHexString(rp.gx1.pR,  rp.gx1.ulRLen,  aR1)  &&
                    toHexString(rp.gx2.pGX, rp.gx2.ulGXLen, aGX2) &&
                    toHexString(rp.gx2.pGV, rp.gx2.ulGVLen, aGV2) &&
@@ -203,17 +204,17 @@ NS_IMETHODIMP nsSyncJPAKE::Round2(const 
                                   const nsACString & aGX4,
                                   const nsACString & aGV4,
                                   const nsACString & aR4,
                                   nsACString & aA,
                                   nsACString & aGVA,
                                   nsACString & aRA)
 {
   NS_ENSURE_STATE(round == JPAKEBeforeRound2);
-  NS_ENSURE_STATE(key != NULL);
+  NS_ENSURE_STATE(key != nullptr);
   NS_ENSURE_ARG(!aPeerID.IsEmpty());
 
   /* PIN cannot be equal to zero when converted to a bignum. NSS 3.12.9 J-PAKE
      assumes that the caller has already done this check. Future versions of 
      NSS J-PAKE will do this check internally. See Bug 609068 Comment 4 */
   bool foundNonZero = false;
   for (size_t i = 0; i < aPIN.Length(); ++i) {
     if (aPIN[i] != 0) {
@@ -269,17 +270,17 @@ NS_IMETHODIMP nsSyncJPAKE::Round2(const 
   PK11SymKey * newKey = PK11_DeriveWithTemplate(key,
                                                 CKM_NSS_JPAKE_ROUND2_SHA256,
                                                 &paramsItem,
                                                 CKM_NSS_JPAKE_FINAL_SHA256,
                                                 CKA_DERIVE, 0,
                                                 keyTemplate,
                                                 NUM_ELEM(keyTemplate),
                                                 false);
-  if (newKey != NULL) {
+  if (newKey != nullptr) {
     if (toHexString(rp.A.pGX, rp.A.ulGXLen, aA) &&
         toHexString(rp.A.pGV, rp.A.ulGVLen, aGVA) &&
         toHexString(rp.A.pR, rp.A.ulRLen, aRA)) {
       round = JPAKEAfterRound2;
       PK11_FreeSymKey(key);
       key = newKey;
       return NS_OK;
     } else {
@@ -293,17 +294,17 @@ NS_IMETHODIMP nsSyncJPAKE::Round2(const 
 }
 
 static nsresult
 setBase64(const unsigned char * data, unsigned len, nsACString & out)
 {
   nsresult rv = NS_OK;
   const char * base64 = BTOA_DataToAscii(data, len);
   
-  if (base64 != NULL) {
+  if (base64 != nullptr) {
     size_t len = PORT_Strlen(base64);
     if (out.SetCapacity(len, fallible_t())) {
       out.SetLength(0);
       out.Append(base64, len);
       PORT_Free((void*) base64);
     } else {
       rv = NS_ERROR_OUT_OF_MEMORY;
     }
@@ -314,17 +315,17 @@ setBase64(const unsigned char * data, un
 }
 
 static nsresult
 base64KeyValue(PK11SymKey * key, nsACString & keyString)
 {
   nsresult rv = NS_OK;
   if (PK11_ExtractKeyValue(key) == SECSuccess) {
     const SECItem * value = PK11_GetKeyData(key);
-    rv = value != NULL && value->data != NULL && value->len > 0
+    rv = value != nullptr && value->data != nullptr && value->len > 0
        ? setBase64(value->data, value->len, keyString)
        : NS_ERROR_UNEXPECTED;
   } else {
     rv = mapErrno();
   }
   return rv;
 }
 
@@ -334,17 +335,17 @@ extractBase64KeyValue(PK11SymKey * keyBl
                       nsACString & keyString)
 {
   SECItem paramsItem;
   paramsItem.data = (CK_BYTE *) &bitPosition;
   paramsItem.len = sizeof bitPosition;
   PK11SymKey * key = PK11_Derive(keyBlock, CKM_EXTRACT_KEY_FROM_KEY,
                                  &paramsItem, destMech,
                                  CKA_SIGN, keySize);
-  if (key == NULL)
+  if (key == nullptr)
     return mapErrno();
   nsresult rv = base64KeyValue(key, keyString);
   PK11_FreeSymKey(key);
   return rv;
 }
 
 
 NS_IMETHODIMP nsSyncJPAKE::Final(const nsACString & aB,
@@ -355,17 +356,17 @@ NS_IMETHODIMP nsSyncJPAKE::Final(const n
                                  nsACString & aHMAC256Key)
 {
   static const unsigned AES256_KEY_SIZE = 256 / 8;
   static const unsigned HMAC_SHA256_KEY_SIZE = 256 / 8;
   CK_EXTRACT_PARAMS aesBitPosition = 0;
   CK_EXTRACT_PARAMS hmacBitPosition = aesBitPosition + (AES256_KEY_SIZE * 8);
 
   NS_ENSURE_STATE(round == JPAKEAfterRound2);
-  NS_ENSURE_STATE(key != NULL);
+  NS_ENSURE_STATE(key != nullptr);
 
   CK_BYTE gxBBuf[NUM_ELEM(p)/2], gvBBuf[NUM_ELEM(p)/2], rBBuf [NUM_ELEM(p)/2];
   nsresult         rv = fromHexString(aB,   gxBBuf, sizeof gxBBuf);
   if (rv == NS_OK) rv = fromHexString(aGVB, gvBBuf, sizeof gvBBuf);
   if (rv == NS_OK) rv = fromHexString(aRB,  rBBuf,  sizeof rBBuf);
   if (rv != NS_OK)
     return rv;
 
@@ -374,81 +375,81 @@ NS_IMETHODIMP nsSyncJPAKE::Final(const n
   rp.B.pGV = gvBBuf; rp.B.ulGVLen = aGVB.Length() / 2;
   rp.B.pR  = rBBuf;  rp.B.ulRLen  = aRB .Length() / 2;
   SECItem paramsItem;
   paramsItem.data = (unsigned char *) &rp;
   paramsItem.len = sizeof rp;
   PK11SymKey * keyMaterial = PK11_Derive(key, CKM_NSS_JPAKE_FINAL_SHA256,
                                          &paramsItem, CKM_NSS_HKDF_SHA256,
                                          CKA_DERIVE, 0);
-  PK11SymKey * keyBlock = NULL;
+  PK11SymKey * keyBlock = nullptr;
 
-  if (keyMaterial == NULL)
+  if (keyMaterial == nullptr)
     rv = mapErrno();
 
   if (rv == NS_OK) {
     CK_NSS_HKDFParams hkdfParams;
     hkdfParams.bExtract = CK_TRUE;
-    hkdfParams.pSalt = NULL;
+    hkdfParams.pSalt = nullptr;
     hkdfParams.ulSaltLen = 0;
     hkdfParams.bExpand = CK_TRUE;
     hkdfParams.pInfo = (CK_BYTE *) aHKDFInfo.Data();
     hkdfParams.ulInfoLen = aHKDFInfo.Length();
     paramsItem.data = (unsigned char *) &hkdfParams;
     paramsItem.len = sizeof hkdfParams;
     keyBlock = PK11_Derive(keyMaterial, CKM_NSS_HKDF_SHA256,
                            &paramsItem, CKM_EXTRACT_KEY_FROM_KEY,
                            CKA_DERIVE, AES256_KEY_SIZE + HMAC_SHA256_KEY_SIZE);
-    if (keyBlock == NULL)
+    if (keyBlock == nullptr)
       rv = mapErrno();
   }
 
   if (rv == NS_OK) {
     rv = extractBase64KeyValue(keyBlock, aesBitPosition, CKM_AES_CBC,
                                AES256_KEY_SIZE, aAES256Key);
   }
   if (rv == NS_OK) {
     rv = extractBase64KeyValue(keyBlock, hmacBitPosition, CKM_SHA256_HMAC,
                                HMAC_SHA256_KEY_SIZE, aHMAC256Key);
   }
 
   if (rv == NS_OK) {
     SECStatus srv = PK11_ExtractKeyValue(keyMaterial);
     NS_ENSURE_TRUE(srv == SECSuccess, NS_ERROR_UNEXPECTED); // XXX leaks
     SECItem * keyMaterialBytes = PK11_GetKeyData(keyMaterial);
-    NS_ENSURE_TRUE(keyMaterialBytes != NULL, NS_ERROR_UNEXPECTED);
+    NS_ENSURE_TRUE(keyMaterialBytes != nullptr, NS_ERROR_UNEXPECTED);
   }
 
-  if (keyBlock != NULL)
+  if (keyBlock != nullptr)
     PK11_FreeSymKey(keyBlock);
-  if (keyMaterial != NULL)
+  if (keyMaterial != nullptr)
     PK11_FreeSymKey(keyMaterial);
 
   return rv;
 }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSyncJPAKE)
 NS_DEFINE_NAMED_CID(NS_SYNCJPAKE_CID);
 
-nsSyncJPAKE::nsSyncJPAKE() : round(JPAKENotStarted), key(NULL) { }
+nsSyncJPAKE::nsSyncJPAKE() : round(JPAKENotStarted), key(nullptr) { }
 
 nsSyncJPAKE::~nsSyncJPAKE()
 {
-  if (key != NULL)
+  if (key != nullptr)
     PK11_FreeSymKey(key);
 }
 
 static const mozilla::Module::CIDEntry kServicesCryptoCIDs[] = {
-  { &kNS_SYNCJPAKE_CID, false, NULL, nsSyncJPAKEConstructor },
-  { NULL }
+  { &kNS_SYNCJPAKE_CID, false, nullptr, nsSyncJPAKEConstructor },
+  { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kServicesCryptoContracts[] = {
   { NS_SYNCJPAKE_CONTRACTID, &kNS_SYNCJPAKE_CID },
-  { NULL }
+  { nullptr }
 };
 
 static const mozilla::Module kServicesCryptoModule = {
   mozilla::Module::kVersion,
   kServicesCryptoCIDs,
   kServicesCryptoContracts
 };