Skip to content

Commit

Permalink
Bug 1296180 - Replace more uses of PR_ARRAY_SIZE with mozilla::ArrayL…
Browse files Browse the repository at this point in the history
…engh. r=mt
  • Loading branch information
ipalmieri committed Sep 9, 2016
1 parent 090fad3 commit 3ae4c91
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
16 changes: 9 additions & 7 deletions dom/crypto/CryptoKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* 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 "pk11pub.h"
#include "cryptohi.h"
#include "nsNSSComponent.h"
#include "CryptoKey.h"

#include "ScopedNSSTypes.h"
#include "mozilla/dom/CryptoKey.h"
#include "cryptohi.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsNSSComponent.h"
#include "pk11pub.h"

// Templates taken from security/nss/lib/cryptohi/seckey.c
// These would ideally be exported by NSS and until that
Expand Down Expand Up @@ -361,7 +363,7 @@ CryptoKey::AddPublicKeyData(SECKEYPublicKey* aPublicKey)
};

mPrivateKey = PrivateKeyFromPrivateKeyTemplate(keyTemplate,
PR_ARRAY_SIZE(keyTemplate));
ArrayLength(keyTemplate));
NS_ENSURE_TRUE(mPrivateKey, NS_ERROR_DOM_OPERATION_ERR);

return NS_OK;
Expand Down Expand Up @@ -797,7 +799,7 @@ CryptoKey::PrivateKeyFromJwk(const JsonWebKey& aJwk,
};

return PrivateKeyFromPrivateKeyTemplate(keyTemplate,
PR_ARRAY_SIZE(keyTemplate));
ArrayLength(keyTemplate));
}

if (aJwk.mKty.EqualsLiteral(JWK_TYPE_RSA)) {
Expand Down Expand Up @@ -840,7 +842,7 @@ CryptoKey::PrivateKeyFromJwk(const JsonWebKey& aJwk,
};

return PrivateKeyFromPrivateKeyTemplate(keyTemplate,
PR_ARRAY_SIZE(keyTemplate));
ArrayLength(keyTemplate));
}

return nullptr;
Expand Down
13 changes: 7 additions & 6 deletions dom/crypto/WebCryptoCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
#ifndef mozilla_dom_WebCryptoCommon_h
#define mozilla_dom_WebCryptoCommon_h

#include "pk11pub.h"
#include "nsString.h"
#include "nsContentUtils.h"
#include "mozilla/dom/CryptoBuffer.h"
#include "js/StructuredClone.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/dom/CryptoBuffer.h"
#include "nsContentUtils.h"
#include "nsString.h"
#include "pk11pub.h"

// WebCrypto algorithm names
#define WEBCRYPTO_ALG_AES_CBC "AES-CBC"
Expand Down Expand Up @@ -106,15 +107,15 @@
// python security/pkix/tools/DottedOIDToCode.py id-ecDH 1.3.132.112
static const uint8_t id_ecDH[] = { 0x2b, 0x81, 0x04, 0x70 };
const SECItem SEC_OID_DATA_EC_DH = { siBuffer, (unsigned char*)id_ecDH,
PR_ARRAY_SIZE(id_ecDH) };
mozilla::ArrayLength(id_ecDH) };

// python security/pkix/tools/DottedOIDToCode.py dhKeyAgreement 1.2.840.113549.1.3.1
static const uint8_t dhKeyAgreement[] = {
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x03, 0x01
};
const SECItem SEC_OID_DATA_DH_KEY_AGREEMENT = { siBuffer,
(unsigned char*)dhKeyAgreement,
PR_ARRAY_SIZE(dhKeyAgreement) };
mozilla::ArrayLength(dhKeyAgreement) };

namespace mozilla {
namespace dom {
Expand Down
43 changes: 21 additions & 22 deletions media/mtransport/transportlayerdtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@

// Original author: [email protected]

#include <queue>
#include "transportlayerdtls.h"

#include <algorithm>
#include <queue>
#include <sstream>

#include "mozilla/UniquePtr.h"

#include "logging.h"
#include "ssl.h"
#include "sslerr.h"
#include "sslproto.h"
#include "dtlsidentity.h"
#include "keyhi.h"

#include "logging.h"
#include "mozilla/UniquePtr.h"
#include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsIEventTarget.h"
#include "nsNetCID.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"

#include "dtlsidentity.h"
#include "ssl.h"
#include "sslerr.h"
#include "sslproto.h"
#include "transportflow.h"
#include "transportlayerdtls.h"


namespace mozilla {

Expand Down Expand Up @@ -739,31 +738,31 @@ bool TransportLayerDtls::SetupCipherSuites(PRFileDesc* ssl_fd) const {
}
}

for (size_t i = 0; i < PR_ARRAY_SIZE(EnabledCiphers); ++i) {
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Enabling: " << EnabledCiphers[i]);
rv = SSL_CipherPrefSet(ssl_fd, EnabledCiphers[i], PR_TRUE);
for (const auto& cipher : EnabledCiphers) {
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Enabling: " << cipher);
rv = SSL_CipherPrefSet(ssl_fd, cipher, PR_TRUE);
if (rv != SECSuccess) {
MOZ_MTLOG(ML_ERROR, LAYER_INFO <<
"Unable to enable suite: " << EnabledCiphers[i]);
"Unable to enable suite: " << cipher);
return false;
}
}

for (size_t i = 0; i < PR_ARRAY_SIZE(DisabledCiphers); ++i) {
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Disabling: " << DisabledCiphers[i]);
for (const auto& cipher : DisabledCiphers) {
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Disabling: " << cipher);

PRBool enabled = false;
rv = SSL_CipherPrefGet(ssl_fd, DisabledCiphers[i], &enabled);
rv = SSL_CipherPrefGet(ssl_fd, cipher, &enabled);
if (rv != SECSuccess) {
MOZ_MTLOG(ML_NOTICE, LAYER_INFO <<
"Unable to check if suite is enabled: " << DisabledCiphers[i]);
"Unable to check if suite is enabled: " << cipher);
return false;
}
if (enabled) {
rv = SSL_CipherPrefSet(ssl_fd, DisabledCiphers[i], PR_FALSE);
rv = SSL_CipherPrefSet(ssl_fd, cipher, PR_FALSE);
if (rv != SECSuccess) {
MOZ_MTLOG(ML_NOTICE, LAYER_INFO <<
"Unable to disable suite: " << DisabledCiphers[i]);
"Unable to disable suite: " << cipher);
return false;
}
}
Expand Down
18 changes: 8 additions & 10 deletions security/certverifier/ExtendedValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

#include "ExtendedValidation.h"

#include "base64.h"
#include "cert.h"
#include "certdb.h"
#include "base64.h"
#include "hasht.h"
#include "pkix/pkixtypes.h"
#include "mozilla/ArrayUtils.h"
#include "pk11pub.h"
#include "secerr.h"
#include "pkix/pkixtypes.h"
#include "prerror.h"
#include "prinit.h"
#include "secerr.h"

extern mozilla::LazyLogModule gPIPNSSLog;

Expand Down Expand Up @@ -1273,8 +1274,7 @@ RegisterOID(const SECItem& oidItem, const char* oidName)
static bool
isEVPolicy(SECOidTag policyOIDTag)
{
for (size_t iEV = 0; iEV < PR_ARRAY_SIZE(myTrustedEVInfos); ++iEV) {
nsMyTrustedEVInfo& entry = myTrustedEVInfos[iEV];
for (const nsMyTrustedEVInfo& entry : myTrustedEVInfos) {
if (policyOIDTag == entry.oid_tag) {
return true;
}
Expand All @@ -1294,8 +1294,7 @@ CertIsAuthoritativeForEVPolicy(const UniqueCERTCertificate& cert,
return false;
}

for (size_t iEV = 0; iEV < PR_ARRAY_SIZE(myTrustedEVInfos); ++iEV) {
nsMyTrustedEVInfo& entry = myTrustedEVInfos[iEV];
for (const nsMyTrustedEVInfo& entry : myTrustedEVInfos) {
if (entry.cert && CERT_CompareCerts(cert.get(), entry.cert.get())) {
const SECOidData* oidData = SECOID_FindOIDByTag(entry.oid_tag);
if (oidData && oidData->oid.len == policy.numBytes &&
Expand All @@ -1311,7 +1310,7 @@ CertIsAuthoritativeForEVPolicy(const UniqueCERTCertificate& cert,
static PRStatus
IdentityInfoInit()
{
for (size_t iEV = 0; iEV < PR_ARRAY_SIZE(myTrustedEVInfos); ++iEV) {
for (size_t iEV = 0; iEV < mozilla::ArrayLength(myTrustedEVInfos); ++iEV) {
nsMyTrustedEVInfo& entry = myTrustedEVInfos[iEV];

mozilla::ScopedAutoSECItem derIssuer;
Expand Down Expand Up @@ -1400,8 +1399,7 @@ EnsureIdentityInfoLoaded()
void
CleanupIdentityInfo()
{
for (size_t iEV = 0; iEV < PR_ARRAY_SIZE(myTrustedEVInfos); ++iEV) {
nsMyTrustedEVInfo &entry = myTrustedEVInfos[iEV];
for (nsMyTrustedEVInfo& entry : myTrustedEVInfos) {
entry.cert = nullptr;
}

Expand Down

0 comments on commit 3ae4c91

Please sign in to comment.