Bug 802378: Make PSM coding patterns more consistent, and more consistent with Mozilla Coding Style, r=keeler
authorBrian Smith <bsmith@mozilla.com>
Wed, 17 Oct 2012 13:48:36 -0700
changeset 20377 ef3eb7c1a7e0d16d12845c755e4f490714bd592d
parent 20376 efa60ab5882351c123d7ef6699aadd4f2e842615
child 20378 db1e136b314ef5240294d93a03b29377fbaf7ff8
push id1209
push usermbanner@mozilla.com
push dateTue, 02 Sep 2014 16:59:36 +0000
treeherdercomm-beta@842e0fd167ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs802378
Bug 802378: Make PSM coding patterns more consistent, and more consistent with Mozilla Coding Style, r=keeler
mailnews/mime/src/nsCMS.cpp
mailnews/mime/src/nsCMSSecureMessage.cpp
--- a/mailnews/mime/src/nsCMS.cpp
+++ b/mailnews/mime/src/nsCMS.cpp
@@ -11,22 +11,26 @@
 #include "cms.h"
 #include "nsICMSMessageErrors.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "nsCertVerificationThread.h"
 #include "nsCERTValInParamWrapper.h"
 
 #include "prlog.h"
+
+#include "nsNSSCleaner.h"
+#include "nsNSSComponent.h"
+
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gPIPNSSLog;
 #endif
 
-#include "nsNSSCleaner.h"
-#include "nsNSSComponent.h"
+using namespace mozilla;
+
 static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
 
 NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
 
 NS_IMPL_THREADSAFE_ISUPPORTS2(nsCMSMessage, nsICMSMessage, 
                                             nsICMSMessage2)
 
 nsCMSMessage::nsCMSMessage()
@@ -175,17 +179,17 @@ NS_IMETHODIMP nsCMSMessage::GetSignerCer
 
     *scert = nsNSSCertificate::Create(si->cert);
     if (*scert) {
       (*scert)->AddRef();
     }
   }
   else {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::GetSignerCert no signer cert, do we have a cert list? %s\n",
-      (si->certList != nullptr ? "yes" : "no") ));
+      (si->certList ? "yes" : "no") ));
 
     *scert = nullptr;
   }
   
   return NS_OK;
 }
 
 NS_IMETHODIMP nsCMSMessage::GetEncryptionCert(nsIX509Cert **ecert)
@@ -212,17 +216,17 @@ nsresult nsCMSMessage::CommonVerifySigna
     return NS_ERROR_NOT_AVAILABLE;
 
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature, content level count %d\n", NSS_CMSMessage_ContentLevelCount(m_cmsMsg)));
   NSSCMSContentInfo *cinfo = nullptr;
   NSSCMSSignedData *sigd = nullptr;
   NSSCMSSignerInfo *si;
   int32_t nsigners;
   nsresult rv = NS_ERROR_FAILURE;
-  nsRefPtr<nsCERTValInParamWrapper> survivingParams;
+  RefPtr<nsCERTValInParamWrapper> survivingParams;
   nsCOMPtr<nsINSSComponent> inss;
 
   if (!NSS_CMSMessage_IsSigned(m_cmsMsg)) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - not signed\n"));
     return NS_ERROR_CMS_VERIFY_NOT_SIGNED;
   } 
 
   cinfo = NSS_CMSMessage_ContentLevel(m_cmsMsg, 0);
@@ -260,17 +264,17 @@ nsresult nsCMSMessage::CommonVerifySigna
   si = NSS_CMSSignedData_GetSignerInfo(sigd, 0);
 
   // See bug 324474. We want to make sure the signing cert is 
   // still valid at the current time.
 
   if (!nsNSSComponent::globalConstFlagUsePKIXVerification) {
     if (CERT_VerifyCertificateNow(CERT_GetDefaultCertDB(), si->cert, true, 
                                   certificateUsageEmailSigner,
-                                  si->cmsg->pwfn_arg, NULL) != SECSuccess) {
+                                  si->cmsg->pwfn_arg, nullptr) != SECSuccess) {
       PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CommonVerifySignature - signing cert not trusted now\n"));
       rv = NS_ERROR_CMS_VERIFY_UNTRUSTED;
       goto loser;
     }
   }
   else {
     CERTValOutParam cvout[1];
     cvout[0].type = cert_po_end;
@@ -362,28 +366,20 @@ NS_IMETHODIMP nsCMSMessage::AsyncVerifyD
 
   return CommonAsyncVerifySignature(aListener, aDigestData, aDigestDataLen);
 }
 
 nsresult nsCMSMessage::CommonAsyncVerifySignature(nsISMimeVerificationListener *aListener,
                                                   unsigned char* aDigestData, uint32_t aDigestDataLen)
 {
   nsSMimeVerificationJob *job = new nsSMimeVerificationJob;
-  if (!job)
-    return NS_ERROR_OUT_OF_MEMORY;
   
   if (aDigestData)
   {
     job->digest_data = new unsigned char[aDigestDataLen];
-    if (!job->digest_data)
-    {
-      delete job;
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-    
     memcpy(job->digest_data, aDigestData, aDigestDataLen);
   }
   else
   {
     job->digest_data = nullptr;
   }
   
   job->digest_len = aDigestDataLen;
@@ -552,18 +548,18 @@ NS_IMETHODIMP nsCMSMessage::CreateEncryp
   // Find a bulk key algorithm //
   if (NSS_SMIMEUtil_FindBulkAlgForRecipients(recipientCerts.getRawArray(), &bulkAlgTag,
                                             &keySize) != SECSuccess) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateEncrypted - can't find bulk alg for recipients\n"));
     rv = NS_ERROR_CMS_ENCRYPT_NO_BULK_ALG;
     goto loser;
   }
 
-  m_cmsMsg = NSS_CMSMessage_Create(NULL);
-  if (m_cmsMsg == nullptr) {
+  m_cmsMsg = NSS_CMSMessage_Create(nullptr);
+  if (!m_cmsMsg) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateEncrypted - can't create new cms message\n"));
     rv = NS_ERROR_OUT_OF_MEMORY;
     goto loser;
   }
 
   if ((envd = NSS_CMSEnvelopedData_Create(m_cmsMsg, bulkAlgTag, keySize)) == nullptr) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateEncrypted - can't create enveloped data\n"));
     goto loser;
@@ -635,27 +631,27 @@ NS_IMETHODIMP nsCMSMessage::CreateSigned
   }
 
   CERTCertificateCleaner ecertCleaner(ecert);
   CERTCertificateCleaner scertCleaner(scert);
 
   /*
    * create the message object
    */
-  m_cmsMsg = NSS_CMSMessage_Create(NULL); /* create a message on its own pool */
-  if (m_cmsMsg == NULL) {
+  m_cmsMsg = NSS_CMSMessage_Create(nullptr); /* create a message on its own pool */
+  if (!m_cmsMsg) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned - can't create new message\n"));
     rv = NS_ERROR_OUT_OF_MEMORY;
     goto loser;
   }
 
   /*
    * build chain of objects: message->signedData->data
    */
-  if ((sigd = NSS_CMSSignedData_Create(m_cmsMsg)) == NULL) {
+  if ((sigd = NSS_CMSSignedData_Create(m_cmsMsg)) == nullptr) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned - can't create signed data\n"));
     goto loser;
   }
   cinfo = NSS_CMSMessage_GetContentInfo(m_cmsMsg);
   if (NSS_CMSContentInfo_SetContent_SignedData(m_cmsMsg, cinfo, sigd) 
           != SECSuccess) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned - can't set content signed data\n"));
     goto loser;
@@ -669,17 +665,17 @@ NS_IMETHODIMP nsCMSMessage::CreateSigned
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned - can't set content data\n"));
     goto loser;
   }
 
   /* 
    * create & attach signer information
    */
   if ((signerinfo = NSS_CMSSignerInfo_Create(m_cmsMsg, scert, SEC_OID_SHA1)) 
-          == NULL) {
+          == nullptr) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSMessage::CreateSigned - can't create signer info\n"));
     goto loser;
   }
 
   /* we want the cert chain included for this one */
   if (NSS_CMSSignerInfo_IncludeCerts(signerinfo, NSSCMSCM_CertChain, 
                                        certUsageEmailSigner) 
           != SECSuccess) {
@@ -876,17 +872,17 @@ NS_IMETHODIMP nsCMSEncoder::Start(nsICMS
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Start\n"));
   nsCMSMessage *cmsMsg = static_cast<nsCMSMessage*>(aMsg);
   m_ctx = new PipUIContext();
 
   m_ecx = NSS_CMSEncoder_Start(cmsMsg->getCMS(), cb, arg, 0, 0, 0, m_ctx, 0, 0, 0, 0);
-  if (m_ecx == nullptr) {
+  if (!m_ecx) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSEncoder::Start - can't start encoder\n"));
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 /* void update (in string aBuf, in long aLen); */
 NS_IMETHODIMP nsCMSEncoder::Update(const char *aBuf, int32_t aLen)
--- a/mailnews/mime/src/nsCMSSecureMessage.cpp
+++ b/mailnews/mime/src/nsCMSSecureMessage.cpp
@@ -1,14 +1,13 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsMemory.h"
 #include "nsXPIDLString.h"
 #include "nsCOMPtr.h"
 #include "nsISupports.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsCRT.h"
 
 #include "nsICMSSecureMessage.h"
 
@@ -142,17 +141,17 @@ SendMessage(const char *msg, const char 
   NSSCMSContentInfo *cinfo;
   NSSCMSRecipientInfo *rcpt;
   SECItem output;
   PLArenaPool *arena = PORT_NewArena(1024);
   SECStatus s;
   nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext();
 
   /* Step 0. Create a CMS Message */
-  cmsMsg = NSS_CMSMessage_Create(NULL);
+  cmsMsg = NSS_CMSMessage_Create(nullptr);
   if (!cmsMsg) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::SendMessage - can't create NSSCMSMessage\n"));
     rv = NS_ERROR_FAILURE;
     goto done;
   }
 
   /* Step 1.  Import the certificate into NSS */
   rv = decode(base64Cert, &certDER, &derLen);
@@ -311,17 +310,17 @@ done:
   return rv;
 }
 
 nsresult nsCMSSecureMessage::
 encode(const unsigned char *data, int32_t dataLen, char **_retval)
 {
   nsresult rv = NS_OK;
 
-  *_retval = PL_Base64Encode((const char *)data, dataLen, NULL);
+  *_retval = PL_Base64Encode((const char *)data, dataLen, nullptr);
   if (!*_retval) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
 
 loser:
   return rv;
 }
 
 nsresult nsCMSSecureMessage::
 decode(const char *data, unsigned char **result, int32_t * _retval)
@@ -332,17 +331,17 @@ decode(const char *data, unsigned char *
   int adjust = 0;
 
   /* Compute length adjustment */
   if (data[len-1] == '=') {
     adjust++;
     if (data[len-2] == '=') adjust++;
   }
 
-  *result = (unsigned char *)PL_Base64Decode(data, len, NULL);
+  *result = (unsigned char *)PL_Base64Decode(data, len, nullptr);
   if (!*result) {
     PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsCMSSecureMessage::decode - error decoding base64\n"));
     rv = NS_ERROR_ILLEGAL_VALUE;
     goto loser;
   }
 
   *_retval = (len*3)/4 - adjust;