Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: net/quic/crypto/aes_128_gcm_12_decrypter_test.cc

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/crypto/aes_128_gcm_12_decrypter.h" 5 #include "net/quic/crypto/aes_128_gcm_12_decrypter.h"
6 6
7 #include "net/quic/test_tools/quic_test_utils.h" 7 #include "net/quic/test_tools/quic_test_utils.h"
8 8
9 using base::StringPiece; 9 using base::StringPiece;
10 10
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, 255 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter,
256 StringPiece nonce, 256 StringPiece nonce,
257 StringPiece associated_data, 257 StringPiece associated_data,
258 StringPiece ciphertext) { 258 StringPiece ciphertext) {
259 size_t plaintext_size = ciphertext.length(); 259 size_t plaintext_size = ciphertext.length();
260 scoped_ptr<char[]> plaintext(new char[plaintext_size]); 260 scoped_ptr<char[]> plaintext(new char[plaintext_size]);
261 261
262 if (!decrypter->Decrypt(nonce, associated_data, ciphertext, 262 if (!decrypter->Decrypt(nonce, associated_data, ciphertext,
263 reinterpret_cast<unsigned char*>(plaintext.get()), 263 reinterpret_cast<unsigned char*>(plaintext.get()),
264 &plaintext_size)) { 264 &plaintext_size)) {
265 return NULL; 265 return nullptr;
266 } 266 }
267 return new QuicData(plaintext.release(), plaintext_size, true); 267 return new QuicData(plaintext.release(), plaintext_size, true);
268 } 268 }
269 269
270 TEST(Aes128Gcm12DecrypterTest, Decrypt) { 270 TEST(Aes128Gcm12DecrypterTest, Decrypt) {
271 for (size_t i = 0; i < arraysize(test_group_array); i++) { 271 for (size_t i = 0; i < arraysize(test_group_array); i++) {
272 SCOPED_TRACE(i); 272 SCOPED_TRACE(i);
273 const TestVector* test_vectors = test_group_array[i]; 273 const TestVector* test_vectors = test_group_array[i];
274 const TestGroupInfo& test_info = test_group_info[i]; 274 const TestGroupInfo& test_info = test_group_info[i];
275 for (size_t j = 0; test_vectors[j].key != NULL; j++) { 275 for (size_t j = 0; test_vectors[j].key != nullptr; j++) {
276 // If not present then decryption is expected to fail. 276 // If not present then decryption is expected to fail.
277 bool has_pt = test_vectors[j].pt; 277 bool has_pt = test_vectors[j].pt;
278 278
279 // Decode the test vector. 279 // Decode the test vector.
280 string key; 280 string key;
281 string iv; 281 string iv;
282 string ct; 282 string ct;
283 string aad; 283 string aad;
284 string tag; 284 string tag;
285 string pt; 285 string pt;
(...skipping 23 matching lines...) Expand all
309 tag.length()); 309 tag.length());
310 tag.resize(Aes128Gcm12Decrypter::kAuthTagSize); 310 tag.resize(Aes128Gcm12Decrypter::kAuthTagSize);
311 string ciphertext = ct + tag; 311 string ciphertext = ct + tag;
312 312
313 Aes128Gcm12Decrypter decrypter; 313 Aes128Gcm12Decrypter decrypter;
314 ASSERT_TRUE(decrypter.SetKey(key)); 314 ASSERT_TRUE(decrypter.SetKey(key));
315 315
316 scoped_ptr<QuicData> decrypted(DecryptWithNonce( 316 scoped_ptr<QuicData> decrypted(DecryptWithNonce(
317 &decrypter, iv, 317 &decrypter, iv,
318 // This deliberately tests that the decrypter can handle an AAD that 318 // This deliberately tests that the decrypter can handle an AAD that
319 // is set to NULL, as opposed to a zero-length, non-NULL pointer. 319 // is set to nullptr, as opposed to a zero-length, non-nullptr
320 // pointer.
320 aad.length() ? aad : StringPiece(), ciphertext)); 321 aad.length() ? aad : StringPiece(), ciphertext));
321 if (!decrypted.get()) { 322 if (!decrypted.get()) {
322 EXPECT_FALSE(has_pt); 323 EXPECT_FALSE(has_pt);
323 continue; 324 continue;
324 } 325 }
325 EXPECT_TRUE(has_pt); 326 EXPECT_TRUE(has_pt);
326 327
327 ASSERT_EQ(pt.length(), decrypted->length()); 328 ASSERT_EQ(pt.length(), decrypted->length());
328 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), 329 test::CompareCharArraysWithHexError("plaintext", decrypted->data(),
329 pt.length(), pt.data(), pt.length()); 330 pt.length(), pt.data(), pt.length());
330 } 331 }
331 } 332 }
332 } 333 }
333 334
334 } // namespace test 335 } // namespace test
335 } // namespace net 336 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/aes_128_gcm_12_decrypter_nss.cc ('k') | net/quic/crypto/aes_128_gcm_12_encrypter_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698