diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-19 06:52:06 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-19 06:52:06 +0000 |
commit | f829ee3d50971c100110066416a94134191d8a2d (patch) | |
tree | 0b1d5c13acff13a6ab04ff8176ac22b1943478ab /net | |
parent | 3b8f5fc05ff91c6c0e4845692c4e40f743e3e272 (diff) | |
download | chromium_src-f829ee3d50971c100110066416a94134191d8a2d.zip chromium_src-f829ee3d50971c100110066416a94134191d8a2d.tar.gz chromium_src-f829ee3d50971c100110066416a94134191d8a2d.tar.bz2 |
Prefer length() over size() for std:string in QUIC code.
Other miscellaneous cleanups to reduce the differences
from the internal code.
R=rch@chromium.org
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/202923002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257887 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/quic/crypto/aes_128_gcm_12_decrypter_test.cc | 24 | ||||
-rw-r--r-- | net/quic/crypto/aes_128_gcm_12_encrypter_test.cc | 26 | ||||
-rw-r--r-- | net/quic/crypto/chacha20_poly1305_decrypter_test.cc | 9 |
3 files changed, 31 insertions, 28 deletions
diff --git a/net/quic/crypto/aes_128_gcm_12_decrypter_test.cc b/net/quic/crypto/aes_128_gcm_12_decrypter_test.cc index f2eead6..5a719a0 100644 --- a/net/quic/crypto/aes_128_gcm_12_decrypter_test.cc +++ b/net/quic/crypto/aes_128_gcm_12_decrypter_test.cc @@ -294,21 +294,21 @@ TEST(Aes128Gcm12DecrypterTest, Decrypt) { // The test vector's lengths should look sane. Note that the lengths // in |test_info| are in bits. - EXPECT_EQ(test_info.key_len, key.size() * 8); - EXPECT_EQ(test_info.iv_len, iv.size() * 8); - EXPECT_EQ(test_info.pt_len, ct.size() * 8); - EXPECT_EQ(test_info.aad_len, aad.size() * 8); - EXPECT_EQ(test_info.tag_len, tag.size() * 8); + EXPECT_EQ(test_info.key_len, key.length() * 8); + EXPECT_EQ(test_info.iv_len, iv.length() * 8); + EXPECT_EQ(test_info.pt_len, ct.length() * 8); + EXPECT_EQ(test_info.aad_len, aad.length() * 8); + EXPECT_EQ(test_info.tag_len, tag.length() * 8); if (has_pt) { - EXPECT_EQ(test_info.pt_len, pt.size() * 8); + EXPECT_EQ(test_info.pt_len, pt.length() * 8); } // The test vectors have 16 byte authenticators but this code only uses // the first 12. ASSERT_LE(static_cast<size_t>(Aes128Gcm12Decrypter::kAuthTagSize), - tag.size()); - string ciphertext = - ct + tag.substr(0, Aes128Gcm12Decrypter::kAuthTagSize); + tag.length()); + tag.resize(Aes128Gcm12Decrypter::kAuthTagSize); + string ciphertext = ct + tag; Aes128Gcm12Decrypter decrypter; ASSERT_TRUE(decrypter.SetKey(key)); @@ -317,16 +317,16 @@ TEST(Aes128Gcm12DecrypterTest, Decrypt) { &decrypter, iv, // This deliberately tests that the decrypter can handle an AAD that // is set to NULL, as opposed to a zero-length, non-NULL pointer. - aad.size() ? aad : StringPiece(), ciphertext)); + aad.length() ? aad : StringPiece(), ciphertext)); if (!decrypted.get()) { EXPECT_FALSE(has_pt); continue; } EXPECT_TRUE(has_pt); - ASSERT_EQ(pt.size(), decrypted->length()); + ASSERT_EQ(pt.length(), decrypted->length()); test::CompareCharArraysWithHexError("plaintext", decrypted->data(), - pt.size(), pt.data(), pt.size()); + pt.length(), pt.data(), pt.length()); } } } diff --git a/net/quic/crypto/aes_128_gcm_12_encrypter_test.cc b/net/quic/crypto/aes_128_gcm_12_encrypter_test.cc index fcf91de..afe4310 100644 --- a/net/quic/crypto/aes_128_gcm_12_encrypter_test.cc +++ b/net/quic/crypto/aes_128_gcm_12_encrypter_test.cc @@ -245,12 +245,12 @@ TEST(Aes128Gcm12EncrypterTest, Encrypt) { // The test vector's lengths should look sane. Note that the lengths // in |test_info| are in bits. - EXPECT_EQ(test_info.key_len, key.size() * 8); - EXPECT_EQ(test_info.iv_len, iv.size() * 8); - EXPECT_EQ(test_info.pt_len, pt.size() * 8); - EXPECT_EQ(test_info.aad_len, aad.size() * 8); - EXPECT_EQ(test_info.pt_len, ct.size() * 8); - EXPECT_EQ(test_info.tag_len, tag.size() * 8); + EXPECT_EQ(test_info.key_len, key.length() * 8); + EXPECT_EQ(test_info.iv_len, iv.length() * 8); + EXPECT_EQ(test_info.pt_len, pt.length() * 8); + EXPECT_EQ(test_info.aad_len, aad.length() * 8); + EXPECT_EQ(test_info.pt_len, ct.length() * 8); + EXPECT_EQ(test_info.tag_len, tag.length() * 8); Aes128Gcm12Encrypter encrypter; ASSERT_TRUE(encrypter.SetKey(key)); @@ -258,21 +258,21 @@ TEST(Aes128Gcm12EncrypterTest, Encrypt) { &encrypter, iv, // This deliberately tests that the encrypter can handle an AAD that // is set to NULL, as opposed to a zero-length, non-NULL pointer. - aad.size() ? aad : StringPiece(), pt)); + aad.length() ? aad : StringPiece(), pt)); ASSERT_TRUE(encrypted.get()); // The test vectors have 16 byte authenticators but this code only uses // the first 12. ASSERT_LE(static_cast<size_t>(Aes128Gcm12Encrypter::kAuthTagSize), - tag.size()); - size_t tag_len = Aes128Gcm12Encrypter::kAuthTagSize; + tag.length()); + tag.resize(Aes128Gcm12Encrypter::kAuthTagSize); - ASSERT_EQ(ct.size() + tag_len, encrypted->length()); + ASSERT_EQ(ct.length() + tag.length(), encrypted->length()); test::CompareCharArraysWithHexError("ciphertext", encrypted->data(), - ct.size(), ct.data(), ct.size()); + ct.length(), ct.data(), ct.length()); test::CompareCharArraysWithHexError( - "authentication tag", encrypted->data() + ct.size(), tag_len, - tag.data(), tag_len); + "authentication tag", encrypted->data() + ct.length(), tag.length(), + tag.data(), tag.length()); } } } diff --git a/net/quic/crypto/chacha20_poly1305_decrypter_test.cc b/net/quic/crypto/chacha20_poly1305_decrypter_test.cc index 894e925..8482e01 100644 --- a/net/quic/crypto/chacha20_poly1305_decrypter_test.cc +++ b/net/quic/crypto/chacha20_poly1305_decrypter_test.cc @@ -92,6 +92,9 @@ TEST(ChaCha20Poly1305DecrypterTest, Decrypt) { } for (size_t i = 0; test_vectors[i].key != NULL; i++) { + // If not present then decryption is expected to fail. + bool has_pt = test_vectors[i].pt; + // Decode the test vector. string key; string iv; @@ -102,7 +105,7 @@ TEST(ChaCha20Poly1305DecrypterTest, Decrypt) { ASSERT_TRUE(DecodeHexString(test_vectors[i].iv, &iv)); ASSERT_TRUE(DecodeHexString(test_vectors[i].aad, &aad)); ASSERT_TRUE(DecodeHexString(test_vectors[i].ct, &ct)); - if (test_vectors[i].pt) { + if (has_pt) { ASSERT_TRUE(DecodeHexString(test_vectors[i].pt, &pt)); } @@ -114,10 +117,10 @@ TEST(ChaCha20Poly1305DecrypterTest, Decrypt) { // is set to NULL, as opposed to a zero-length, non-NULL pointer. StringPiece(aad.length() ? aad.data() : NULL, aad.length()), ct)); if (!decrypted.get()) { - EXPECT_FALSE(test_vectors[i].pt); + EXPECT_FALSE(has_pt); continue; } - EXPECT_TRUE(test_vectors[i].pt); + EXPECT_TRUE(has_pt); ASSERT_EQ(pt.length(), decrypted->length()); test::CompareCharArraysWithHexError("plaintext", decrypted->data(), |