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 { | 14 namespace components { |
15 | 15 |
16 namespace webcrypto { | 16 namespace webcrypto { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Creates an AES-CBC algorithm. | 20 // Creates an AES-CBC algorithm. |
21 blink::WebCryptoAlgorithm CreateAesCbcAlgorithm( | 21 blink::WebCryptoAlgorithm CreateAesCbcAlgorithm( |
22 const std::vector<uint8_t>& iv) { | 22 const std::vector<uint8_t>& iv) { |
23 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 23 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
24 blink::WebCryptoAlgorithmIdAesCbc, | 24 blink::WebCryptoAlgorithmIdAesCbc, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(kKeyLen[i]), true, | 197 GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(kKeyLen[i]), true, |
198 blink::WebCryptoKeyUsageEncrypt, &key)); | 198 blink::WebCryptoKeyUsageEncrypt, &key)); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 TEST(WebCryptoAesCbcTest, ImportKeyEmptyUsage) { | 202 TEST(WebCryptoAesCbcTest, ImportKeyEmptyUsage) { |
203 blink::WebCryptoKey key; | 203 blink::WebCryptoKey key; |
204 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), | 204 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
205 ImportKey(blink::WebCryptoKeyFormatRaw, | 205 ImportKey(blink::WebCryptoKeyFormatRaw, |
206 CryptoData(std::vector<uint8_t>(16)), | 206 CryptoData(std::vector<uint8_t>(16)), |
207 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 207 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), true, |
208 true, 0, &key)); | 208 0, &key)); |
209 } | 209 } |
210 | 210 |
211 // If key_ops is specified but empty, no key usages are allowed for the key. | 211 // If key_ops is specified but empty, no key usages are allowed for the key. |
212 TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { | 212 TEST(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { |
213 blink::WebCryptoKey key; | 213 blink::WebCryptoKey key; |
214 base::DictionaryValue dict; | 214 base::DictionaryValue dict; |
215 dict.SetString("kty", "oct"); | 215 dict.SetString("kty", "oct"); |
216 dict.SetBoolean("ext", false); | 216 dict.SetBoolean("ext", false); |
217 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); | 217 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); |
218 dict.Set("key_ops", new base::ListValue); // Takes ownership. | 218 dict.Set("key_ops", new base::ListValue); // Takes ownership. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); | 561 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); |
562 | 562 |
563 EXPECT_NE(public_key_spki, wrapped_public_key); | 563 EXPECT_NE(public_key_spki, wrapped_public_key); |
564 EXPECT_NE(private_key_pkcs8, wrapped_private_key); | 564 EXPECT_NE(private_key_pkcs8, wrapped_private_key); |
565 } | 565 } |
566 | 566 |
567 } // namespace | 567 } // namespace |
568 | 568 |
569 } // namespace webcrypto | 569 } // namespace webcrypto |
570 | 570 |
571 } // namespace content | 571 } // namespace components |
OLD | NEW |