OLD | NEW |
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 "components/webcrypto/algorithm_dispatch.h" |
7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "components/webcrypto/crypto_data.h" |
8 #include "content/child/webcrypto/status.h" | 8 #include "components/webcrypto/status.h" |
9 #include "content/child/webcrypto/test/test_helpers.h" | 9 #include "components/webcrypto/test/test_helpers.h" |
10 #include "content/child/webcrypto/webcrypto_util.h" | 10 #include "components/webcrypto/webcrypto_util.h" |
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
13 | 13 |
14 namespace content { | |
15 | |
16 namespace webcrypto { | 14 namespace webcrypto { |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( | 18 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( |
21 unsigned short key_length_bits) { | 19 unsigned short key_length_bits) { |
22 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, | 20 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, |
23 key_length_bits); | 21 key_length_bits); |
24 } | 22 } |
25 | 23 |
26 TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { | 24 TEST(WebCryptoAesKwTest, GenerateKeyBadLength) { |
27 const unsigned short kKeyLen[] = {0, 127, 257}; | 25 const unsigned short kKeyLen[] = {0, 127, 257}; |
28 blink::WebCryptoKey key; | 26 blink::WebCryptoKey key; |
29 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { | 27 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { |
30 SCOPED_TRACE(i); | 28 SCOPED_TRACE(i); |
31 EXPECT_EQ(Status::ErrorGenerateAesKeyLength(), | 29 EXPECT_EQ(Status::ErrorGenerateAesKeyLength(), |
32 GenerateSecretKey(CreateAesKwKeyGenAlgorithm(kKeyLen[i]), true, | 30 GenerateSecretKey(CreateAesKwKeyGenAlgorithm(kKeyLen[i]), true, |
33 blink::WebCryptoKeyUsageWrapKey, &key)); | 31 blink::WebCryptoKeyUsageWrapKey, &key)); |
34 } | 32 } |
35 } | 33 } |
36 | 34 |
37 TEST(WebCryptoAesKwTest, GenerateKeyEmptyUsage) { | 35 TEST(WebCryptoAesKwTest, GenerateKeyEmptyUsage) { |
38 blink::WebCryptoKey key; | 36 blink::WebCryptoKey key; |
39 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(), | 37 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
40 GenerateSecretKey(CreateAesKwKeyGenAlgorithm(256), true, 0, &key)); | 38 GenerateSecretKey(CreateAesKwKeyGenAlgorithm(256), true, 0, &key)); |
41 } | 39 } |
42 | 40 |
43 TEST(WebCryptoAesKwTest, ImportKeyEmptyUsage) { | 41 TEST(WebCryptoAesKwTest, ImportKeyEmptyUsage) { |
44 blink::WebCryptoKey key; | 42 blink::WebCryptoKey key; |
45 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(), | 43 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
46 ImportKey(blink::WebCryptoKeyFormatRaw, | 44 ImportKey(blink::WebCryptoKeyFormatRaw, |
47 CryptoData(std::vector<uint8_t>(16)), | 45 CryptoData(std::vector<uint8_t>(16)), |
48 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw), | 46 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw), true, |
49 true, 0, &key)); | 47 0, &key)); |
50 } | 48 } |
51 | 49 |
52 TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { | 50 TEST(WebCryptoAesKwTest, ImportKeyJwkKeyOpsWrapUnwrap) { |
53 blink::WebCryptoKey key; | 51 blink::WebCryptoKey key; |
54 base::DictionaryValue dict; | 52 base::DictionaryValue dict; |
55 dict.SetString("kty", "oct"); | 53 dict.SetString("kty", "oct"); |
56 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); | 54 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); |
57 base::ListValue* key_ops = new base::ListValue; | 55 base::ListValue* key_ops = new base::ListValue; |
58 dict.Set("key_ops", key_ops); // Takes ownership. | 56 dict.Set("key_ops", key_ops); // Takes ownership. |
59 | 57 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 CreateRsaHashedImportAlgorithm( | 527 CreateRsaHashedImportAlgorithm( |
530 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 528 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
531 blink::WebCryptoAlgorithmIdSha256), | 529 blink::WebCryptoAlgorithmIdSha256), |
532 true, bad_usages[i], &key)); | 530 true, bad_usages[i], &key)); |
533 } | 531 } |
534 } | 532 } |
535 | 533 |
536 } // namespace | 534 } // namespace |
537 | 535 |
538 } // namespace webcrypto | 536 } // namespace webcrypto |
539 | |
540 } // namespace content | |
OLD | NEW |