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

Side by Side Diff: content/child/webcrypto/test/aes_cbc_unittest.cc

Issue 654403002: Convert ARRAYSIZE_UNSAFE -> arraysize in content/. (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/stl_util.h" 5 #include "base/stl_util.h"
6 #include "content/child/webcrypto/algorithm_dispatch.h" 6 #include "content/child/webcrypto/algorithm_dispatch.h"
7 #include "content/child/webcrypto/crypto_data.h" 7 #include "content/child/webcrypto/crypto_data.h"
8 #include "content/child/webcrypto/status.h" 8 #include "content/child/webcrypto/status.h"
9 #include "content/child/webcrypto/test/test_helpers.h" 9 #include "content/child/webcrypto/test/test_helpers.h"
10 #include "content/child/webcrypto/webcrypto_util.h" 10 #include "content/child/webcrypto/webcrypto_util.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 &output)); 245 &output));
246 } 246 }
247 } 247 }
248 } 248 }
249 249
250 // TODO(eroman): Do this same test for AES-GCM, AES-KW, AES-CTR ? 250 // TODO(eroman): Do this same test for AES-GCM, AES-KW, AES-CTR ?
251 TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) { 251 TEST(WebCryptoAesCbcTest, GenerateKeyIsRandom) {
252 // Check key generation for each allowed key length. 252 // Check key generation for each allowed key length.
253 std::vector<blink::WebCryptoAlgorithm> algorithm; 253 std::vector<blink::WebCryptoAlgorithm> algorithm;
254 const unsigned short kKeyLength[] = {128, 256}; 254 const unsigned short kKeyLength[] = {128, 256};
255 for (size_t key_length_i = 0; key_length_i < ARRAYSIZE_UNSAFE(kKeyLength); 255 for (size_t key_length_i = 0; key_length_i < arraysize(kKeyLength);
256 ++key_length_i) { 256 ++key_length_i) {
257 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 257 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
258 258
259 std::vector<std::vector<uint8_t> > keys; 259 std::vector<std::vector<uint8_t> > keys;
260 std::vector<uint8_t> key_bytes; 260 std::vector<uint8_t> key_bytes;
261 261
262 // Generate a small sample of keys. 262 // Generate a small sample of keys.
263 for (int j = 0; j < 16; ++j) { 263 for (int j = 0; j < 16; ++j) {
264 ASSERT_EQ(Status::Success(), 264 ASSERT_EQ(Status::Success(),
265 GenerateSecretKey( 265 GenerateSecretKey(
(...skipping 11 matching lines...) Expand all
277 } 277 }
278 // Ensure all entries in the key sample set are unique. This is a simplistic 278 // Ensure all entries in the key sample set are unique. This is a simplistic
279 // estimate of whether the generated keys appear random. 279 // estimate of whether the generated keys appear random.
280 EXPECT_FALSE(CopiesExist(keys)); 280 EXPECT_FALSE(CopiesExist(keys));
281 } 281 }
282 } 282 }
283 283
284 TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) { 284 TEST(WebCryptoAesCbcTest, GenerateKeyBadLength) {
285 const unsigned short kKeyLen[] = {0, 127, 257}; 285 const unsigned short kKeyLen[] = {0, 127, 257};
286 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 286 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
287 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kKeyLen); ++i) { 287 for (size_t i = 0; i < arraysize(kKeyLen); ++i) {
288 SCOPED_TRACE(i); 288 SCOPED_TRACE(i);
289 EXPECT_EQ(Status::ErrorGenerateKeyLength(), 289 EXPECT_EQ(Status::ErrorGenerateKeyLength(),
290 GenerateSecretKey( 290 GenerateSecretKey(
291 CreateAesCbcKeyGenAlgorithm(kKeyLen[i]), true, 0, &key)); 291 CreateAesCbcKeyGenAlgorithm(kKeyLen[i]), true, 0, &key));
292 } 292 }
293 } 293 }
294 294
295 // If key_ops is specified but empty, no key usages are allowed for the key. 295 // If key_ops is specified but empty, no key usages are allowed for the key.
296 TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { 296 TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) {
297 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 297 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 1032
1033 EXPECT_NE(public_key_spki, wrapped_public_key); 1033 EXPECT_NE(public_key_spki, wrapped_public_key);
1034 EXPECT_NE(private_key_pkcs8, wrapped_private_key); 1034 EXPECT_NE(private_key_pkcs8, wrapped_private_key);
1035 } 1035 }
1036 1036
1037 } // namespace 1037 } // namespace
1038 1038
1039 } // namespace webcrypto 1039 } // namespace webcrypto
1040 1040
1041 } // namespace content 1041 } // namespace content
OLDNEW
« no previous file with comments | « content/child/multipart_response_delegate_unittest.cc ('k') | content/child/webcrypto/test/aes_gcm_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698