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