Skip to content

Commit

Permalink
Use base::size rather than arraysize in crypto/.
Browse files Browse the repository at this point in the history
This is purely a mechanical change; there is no intended behavior change.

BUG=837308
TBR=davidben@chromium.org

Change-Id: I2de7af87ac267bd3bbcf809196a88c650b1e5225
Reviewed-on: https://chromium-review.googlesource.com/c/1390732
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618879}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Dec 25, 2018
1 parent 141d025 commit 34f6b42
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions crypto/ec_private_key_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>
#include <vector>

#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {
Expand Down Expand Up @@ -266,7 +266,7 @@ TEST(ECPrivateKeyUnitTest, LoadOpenSSLKeyTest) {
std::string raw_public_key;
EXPECT_TRUE(keypair_openssl->ExportRawPublicKey(&raw_public_key));
EXPECT_EQ(std::string(reinterpret_cast<const char*>(kOpenSSLRawPublicKey),
arraysize(kOpenSSLRawPublicKey)),
base::size(kOpenSSLRawPublicKey)),
raw_public_key);
}

Expand Down
44 changes: 21 additions & 23 deletions crypto/encryptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>
#include <string>

#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "crypto/symmetric_key.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -81,7 +81,7 @@ TEST(EncryptorTest, DecryptWrongKey) {
0x48, 0x1D, 0x42, 0xB0, 0xBA, 0x21, 0xB2, 0x0C
};

ASSERT_EQ(arraysize(expected_ciphertext), ciphertext.size());
ASSERT_EQ(base::size(expected_ciphertext), ciphertext.size());
for (size_t i = 0; i < ciphertext.size(); ++i) {
ASSERT_EQ(expected_ciphertext[i],
static_cast<unsigned char>(ciphertext[i]));
Expand Down Expand Up @@ -236,7 +236,7 @@ void TestAESCTRMultipleDecrypt(
int kTestDecryptSizes[] = { 32, 16, 8 };

int offset = 0;
for (size_t i = 0; i < arraysize(kTestDecryptSizes); ++i) {
for (size_t i = 0; i < base::size(kTestDecryptSizes); ++i) {
std::string decrypted;
size_t len = kTestDecryptSizes[i];
EXPECT_TRUE(
Expand All @@ -250,35 +250,33 @@ void TestAESCTRMultipleDecrypt(
} // namespace

TEST(EncryptorTest, EncryptAES128CTR) {
TestAESCTREncrypt(
kAES128CTRKey, arraysize(kAES128CTRKey),
kAESCTRInitCounter, arraysize(kAESCTRInitCounter),
kAESCTRPlaintext, arraysize(kAESCTRPlaintext),
kAES128CTRCiphertext, arraysize(kAES128CTRCiphertext));
TestAESCTREncrypt(kAES128CTRKey, base::size(kAES128CTRKey),
kAESCTRInitCounter, base::size(kAESCTRInitCounter),
kAESCTRPlaintext, base::size(kAESCTRPlaintext),
kAES128CTRCiphertext, base::size(kAES128CTRCiphertext));
}

TEST(EncryptorTest, EncryptAES256CTR) {
TestAESCTREncrypt(
kAES256CTRKey, arraysize(kAES256CTRKey),
kAESCTRInitCounter, arraysize(kAESCTRInitCounter),
kAESCTRPlaintext, arraysize(kAESCTRPlaintext),
kAES256CTRCiphertext, arraysize(kAES256CTRCiphertext));
TestAESCTREncrypt(kAES256CTRKey, base::size(kAES256CTRKey),
kAESCTRInitCounter, base::size(kAESCTRInitCounter),
kAESCTRPlaintext, base::size(kAESCTRPlaintext),
kAES256CTRCiphertext, base::size(kAES256CTRCiphertext));
}

TEST(EncryptorTest, EncryptAES128CTR_MultipleDecrypt) {
TestAESCTRMultipleDecrypt(
kAES128CTRKey, arraysize(kAES128CTRKey),
kAESCTRInitCounter, arraysize(kAESCTRInitCounter),
kAESCTRPlaintext, arraysize(kAESCTRPlaintext),
kAES128CTRCiphertext, arraysize(kAES128CTRCiphertext));
TestAESCTRMultipleDecrypt(kAES128CTRKey, base::size(kAES128CTRKey),
kAESCTRInitCounter, base::size(kAESCTRInitCounter),
kAESCTRPlaintext, base::size(kAESCTRPlaintext),
kAES128CTRCiphertext,
base::size(kAES128CTRCiphertext));
}

TEST(EncryptorTest, EncryptAES256CTR_MultipleDecrypt) {
TestAESCTRMultipleDecrypt(
kAES256CTRKey, arraysize(kAES256CTRKey),
kAESCTRInitCounter, arraysize(kAESCTRInitCounter),
kAESCTRPlaintext, arraysize(kAESCTRPlaintext),
kAES256CTRCiphertext, arraysize(kAES256CTRCiphertext));
TestAESCTRMultipleDecrypt(kAES256CTRKey, base::size(kAES256CTRKey),
kAESCTRInitCounter, base::size(kAESCTRInitCounter),
kAESCTRPlaintext, base::size(kAESCTRPlaintext),
kAES256CTRCiphertext,
base::size(kAES256CTRCiphertext));
}

TEST(EncryptorTest, EncryptDecryptCTR) {
Expand Down
8 changes: 4 additions & 4 deletions crypto/hmac_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <string>

#include "base/macros.h"
#include "base/stl_util.h"
#include "crypto/hmac.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -145,7 +145,7 @@ TEST(HMACTest, RFC2202TestCases) {
"\xBB\xFF\x1A\x91" }
};

for (size_t i = 0; i < arraysize(cases); ++i) {
for (size_t i = 0; i < base::size(cases); ++i) {
crypto::HMAC hmac(crypto::HMAC::SHA1);
ASSERT_TRUE(hmac.Init(reinterpret_cast<const unsigned char*>(cases[i].key),
cases[i].key_len));
Expand Down Expand Up @@ -242,7 +242,7 @@ TEST(HMACTest, HMACObjectReuse) {
ASSERT_TRUE(
hmac.Init(reinterpret_cast<const unsigned char*>(kSimpleKey),
kSimpleKeyLength));
for (size_t i = 0; i < arraysize(kSimpleHmacCases); ++i) {
for (size_t i = 0; i < base::size(kSimpleHmacCases); ++i) {
std::string data_string(kSimpleHmacCases[i].data,
kSimpleHmacCases[i].data_len);
unsigned char digest[kSHA1DigestSize];
Expand All @@ -257,7 +257,7 @@ TEST(HMACTest, Verify) {
hmac.Init(reinterpret_cast<const unsigned char*>(kSimpleKey),
kSimpleKeyLength));
const char empty_digest[kSHA1DigestSize] = { 0 };
for (size_t i = 0; i < arraysize(kSimpleHmacCases); ++i) {
for (size_t i = 0; i < base::size(kSimpleHmacCases); ++i) {
// Expected results
EXPECT_TRUE(hmac.Verify(
base::StringPiece(kSimpleHmacCases[i].data,
Expand Down
4 changes: 2 additions & 2 deletions crypto/mock_apple_keychain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "crypto/mock_apple_keychain.h"

#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/time/time.h"

namespace {
Expand Down Expand Up @@ -42,7 +42,7 @@ OSStatus MockAppleKeychain::FindGenericPassword(
// The function to free this data is mocked so the cast is fine.
*passwordData = const_cast<char*>(kPassword);
DCHECK(passwordLength);
*passwordLength = arraysize(kPassword);
*passwordLength = base::size(kPassword);
password_data_count_++;
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/p224_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "crypto/p224.h"

#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace crypto {
Expand Down Expand Up @@ -785,7 +785,7 @@ TEST(P224, ExternalToInternalAndBack) {
TEST(P224, ScalarBaseMult) {
Point point;

for (size_t i = 0; i < arraysize(kNISTTestVectors); i++) {
for (size_t i = 0; i < base::size(kNISTTestVectors); i++) {
p224::ScalarBaseMult(kNISTTestVectors[i].scalar, &point);
const std::string external = point.ToString();
ASSERT_EQ(external.size(), 56u);
Expand Down

0 comments on commit 34f6b42

Please sign in to comment.