Bug 1153737: Avoid unnecessary uses of mozilla::pkix::ScopedPtr, r=keeler

This commit is contained in:
Brian Smith 2015-04-12 19:57:48 -10:00
parent 9f72dfd5dc
commit 27c206b435
9 changed files with 51 additions and 53 deletions

View File

@ -6,12 +6,12 @@
#include "nsNSSCertificateDB.h"
#include "pkix/pkix.h"
#include "pkix/pkixnss.h"
#include "pkix/ScopedPtr.h"
#include "mozilla/RefPtr.h"
#include "CryptoTask.h"
#include "AppTrustDomain.h"
#include "base64.h"
#include "certdb.h"
#include "CryptoTask.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h"
#include "nsDataSignatureVerifier.h"
@ -24,16 +24,16 @@
#include "nsNetUtil.h"
#include "nsNSSCertificate.h"
#include "nsProxyRelease.h"
#include "nssb64.h"
#include "NSSCertDBTrustDomain.h"
#include "nsString.h"
#include "nsTHashtable.h"
#include "base64.h"
#include "certdb.h"
#include "nssb64.h"
#include "secmime.h"
#include "plstr.h"
#include "prlog.h"
#include "pkix/pkix.h"
#include "pkix/pkixnss.h"
#include "secmime.h"
using namespace mozilla::pkix;
using namespace mozilla;
@ -807,8 +807,10 @@ VerifySignedManifest(AppTrustedRoot aTrustedRoot,
}
// Get base64 encoded string from manifest buffer digest
ScopedPtr<char, PORT_Free_string> base64EncDigest(NSSBase64_EncodeItem(nullptr,
nullptr, 0, const_cast<SECItem*>(&manifestCalculatedDigest.get())));
UniquePtr<char, void(&)(void*)>
base64EncDigest(NSSBase64_EncodeItem(nullptr, nullptr, 0,
const_cast<SECItem*>(&manifestCalculatedDigest.get())),
PORT_Free);
if (NS_WARN_IF(!base64EncDigest)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -18,13 +18,11 @@
#include "pk11pub.h"
#include "pkix/pkix.h"
#include "pkix/pkixnss.h"
#include "pkix/ScopedPtr.h"
#include "prerror.h"
#include "prmem.h"
#include "prprf.h"
#include "ScopedNSSTypes.h"
#include "secerr.h"
#include "secmod.h"
using namespace mozilla;
using namespace mozilla::pkix;
@ -39,14 +37,6 @@ namespace mozilla { namespace psm {
const char BUILTIN_ROOTS_MODULE_DEFAULT_NAME[] = "Builtin Roots Module";
void PORT_Free_string(char* str) { PORT_Free(str); }
namespace {
typedef ScopedPtr<SECMODModule, SECMOD_DestroyModule> ScopedSECMODModule;
} // unnamed namespace
NSSCertDBTrustDomain::NSSCertDBTrustDomain(SECTrustType certDBTrustType,
OCSPFetching ocspFetching,
OCSPCache& ocspCache,
@ -831,14 +821,15 @@ LoadLoadableRoots(/*optional*/ const char* dir, const char* modNameUTF8)
return SECFailure;
}
ScopedPtr<char, PR_FreeLibraryName> fullLibraryPath(
PR_GetLibraryName(dir, "nssckbi"));
UniquePtr<char, void(&)(char*)>
fullLibraryPath(PR_GetLibraryName(dir, "nssckbi"), PR_FreeLibraryName);
if (!fullLibraryPath) {
return SECFailure;
}
ScopedPtr<char, PORT_Free_string> escaped_fullLibraryPath(
nss_addEscape(fullLibraryPath.get(), '\"'));
UniquePtr<char, void(&)(void*)>
escaped_fullLibraryPath(nss_addEscape(fullLibraryPath.get(), '\"'),
PORT_Free);
if (!escaped_fullLibraryPath) {
return SECFailure;
}
@ -847,9 +838,10 @@ LoadLoadableRoots(/*optional*/ const char* dir, const char* modNameUTF8)
int modType;
SECMOD_DeleteModule(modNameUTF8, &modType);
ScopedPtr<char, PR_smprintf_free> pkcs11ModuleSpec(
PR_smprintf("name=\"%s\" library=\"%s\"", modNameUTF8,
escaped_fullLibraryPath.get()));
UniquePtr<char, void(&)(char*)>
pkcs11ModuleSpec(PR_smprintf("name=\"%s\" library=\"%s\"", modNameUTF8,
escaped_fullLibraryPath.get()),
PR_smprintf_free);
if (!pkcs11ModuleSpec) {
return SECFailure;
}
@ -965,7 +957,7 @@ SaveIntermediateCerts(const ScopedCERTCertList& certList)
// We have found a signer cert that we want to remember.
char* nickname = DefaultServerNicknameForCert(node->cert);
if (nickname && *nickname) {
ScopedPtr<PK11SlotInfo, PK11_FreeSlot> slot(PK11_GetInternalKeySlot());
ScopedPK11SlotInfo slot(PK11_GetInternalKeySlot());
if (slot) {
PK11_ImportCert(slot.get(), node->cert, CK_INVALID_HANDLE,
nickname, false);

View File

@ -20,8 +20,6 @@ void DisableMD5();
extern const char BUILTIN_ROOTS_MODULE_DEFAULT_NAME[];
void PORT_Free_string(char* str);
// The dir parameter is the path to the directory containing the NSS builtin
// roots module. Usually this is the same as the path to the other NSS shared
// libraries. If it is null then the (library) path will be searched.

View File

@ -9,36 +9,42 @@
#include <limits>
#include "mozilla/Base64.h"
#include "mozilla/Scoped.h"
#include "nsIURLParser.h"
#include "nsNSSCallbacks.h"
#include "nsNetCID.h"
#include "nsServiceManagerUtils.h"
#include "pkix/ScopedPtr.h"
#include "secerr.h"
#ifdef PR_LOGGING
extern PRLogModuleInfo* gCertVerifierLog;
#endif
namespace mozilla { namespace psm {
using mozilla::pkix::ScopedPtr;
namespace mozilla {
void
ReleaseHttpServerSession(nsNSSHttpServerSession* httpServerSession)
{
delete httpServerSession;
}
typedef ScopedPtr<nsNSSHttpServerSession, ReleaseHttpServerSession>
ScopedHTTPServerSession;
void
ReleaseHttpRequestSession(nsNSSHttpRequestSession* httpRequestSession)
{
httpRequestSession->Release();
}
typedef ScopedPtr<nsNSSHttpRequestSession, ReleaseHttpRequestSession>
ScopedHTTPRequestSession;
MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedHTTPServerSession,
nsNSSHttpServerSession,
ReleaseHttpServerSession)
MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedHTTPRequestSession,
nsNSSHttpRequestSession,
ReleaseHttpRequestSession)
} // namespace mozilla
namespace mozilla { namespace psm {
static nsresult
AppendEscapedBase64Item(const SECItem* encodedRequest, nsACString& path)

View File

@ -98,7 +98,6 @@
#include "pkix/pkix.h"
#include "pkix/pkixnss.h"
#include "pkix/ScopedPtr.h"
#include "CertVerifier.h"
#include "CryptoTask.h"
#include "ExtendedValidation.h"
@ -114,6 +113,7 @@
#include "mozilla/Mutex.h"
#include "mozilla/Telemetry.h"
#include "mozilla/net/DNS.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/unused.h"
#include "nsIThreadPool.h"
#include "nsNetUtil.h"
@ -876,8 +876,8 @@ GatherBaselineRequirementsTelemetry(const ScopedCERTCertList& certList)
return;
}
CERTCertificate* cert = endEntityNode->cert;
mozilla::pkix::ScopedPtr<char, PORT_Free_string> commonName(
CERT_GetCommonName(&cert->subject));
UniquePtr<char, void(&)(void*)>
commonName(CERT_GetCommonName(&cert->subject), PORT_Free);
// This only applies to certificates issued by authorities in our root
// program.
bool isBuiltIn = false;

View File

@ -28,6 +28,7 @@
#include "secpkcs7.h"
#include "secport.h"
#include "prerror.h"
#include "secmod.h"
namespace mozilla {
@ -334,6 +335,8 @@ MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedSECKEYPublicKey,
MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedSECAlgorithmID,
SECAlgorithmID,
internal::SECOID_DestroyAlgorithmID_true)
MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedSECMODModule, SECMODModule,
SECMOD_DestroyModule)
} // namespace mozilla

View File

@ -9,10 +9,7 @@
#include "nsNSSComponent.h"
#include "nsNativeCharsetUtils.h"
#include "nsServiceManagerUtils.h"
#include "pkix/ScopedPtr.h"
#include "secmod.h"
typedef mozilla::pkix::ScopedPtr<SECMODModule, SECMOD_DestroyModule> ScopedSECMODModule;
#include "ScopedNSSTypes.h"
// QueryInterface implementation for nsPkcs11
NS_INTERFACE_MAP_BEGIN(nsPkcs11)

View File

@ -10,9 +10,9 @@
#include "prprf.h"
#include "CertVerifier.h"
#include "ExtendedValidation.h"
#include "mozilla/UniquePtr.h"
#include "pkix/pkixnss.h"
#include "pkix/pkixtypes.h"
#include "pkix/ScopedPtr.h"
#include "nsNSSComponent.h" // for PIPNSS string bundle calls.
#include "nsCOMPtr.h"
#include "nsIMutableArray.h"
@ -534,8 +534,8 @@ nsNSSCertificate::GetWindowTitle(nsAString& aWindowTitle)
return NS_ERROR_FAILURE;
}
mozilla::pkix::ScopedPtr<char, mozilla::psm::PORT_Free_string>
commonName(CERT_GetCommonName(&mCert->subject));
UniquePtr<char, void(&)(void*)>
commonName(CERT_GetCommonName(&mCert->subject), PORT_Free);
const char* titleOptions[] = {
mCert->nickname,

View File

@ -6,12 +6,12 @@
#include "nsNSSIOLayer.h"
#include "pkix/ScopedPtr.h"
#include "pkix/pkixtypes.h"
#include "nsNSSComponent.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/Casting.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Telemetry.h"
#include "prlog.h"
@ -2313,8 +2313,8 @@ ClientAuthDataRunnable::RunOnTargetThread()
NS_ASSERTION(nicknames->numnicknames == NumberOfCerts, "nicknames->numnicknames != NumberOfCerts");
// Get CN and O of the subject and O of the issuer
mozilla::pkix::ScopedPtr<char, PORT_Free_string> ccn(
CERT_GetCommonName(&mServerCert->subject));
UniquePtr<char, void(&)(void*)>
ccn(CERT_GetCommonName(&mServerCert->subject), PORT_Free);
NS_ConvertUTF8toUTF16 cn(ccn.get());
int32_t port;