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 "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/jwk.h" | 8 #include "content/child/webcrypto/jwk.h" |
9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
10 #include "content/child/webcrypto/test/test_helpers.h" | 10 #include "content/child/webcrypto/test/test_helpers.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 ASSERT_EQ(blink::WebCryptoAlgorithmIdAesGcm, derived_key.algorithm().id()); | 302 ASSERT_EQ(blink::WebCryptoAlgorithmIdAesGcm, derived_key.algorithm().id()); |
303 ASSERT_EQ(128, derived_key.algorithm().aesParams()->lengthBits()); | 303 ASSERT_EQ(128, derived_key.algorithm().aesParams()->lengthBits()); |
304 | 304 |
305 // Export the key and verify its contents. | 305 // Export the key and verify its contents. |
306 std::vector<uint8_t> raw_key; | 306 std::vector<uint8_t> raw_key; |
307 EXPECT_EQ(Status::Success(), | 307 EXPECT_EQ(Status::Success(), |
308 ExportKey(blink::WebCryptoKeyFormatRaw, derived_key, &raw_key)); | 308 ExportKey(blink::WebCryptoKeyFormatRaw, derived_key, &raw_key)); |
309 EXPECT_EQ(16u, raw_key.size()); | 309 EXPECT_EQ(16u, raw_key.size()); |
310 } | 310 } |
311 | 311 |
| 312 TEST(WebCryptoEcdhTest, ImportKeyEmptyUsage) { |
| 313 if (!SupportsEcdh()) |
| 314 return; |
| 315 |
| 316 blink::WebCryptoKey key; |
| 317 |
| 318 scoped_ptr<base::ListValue> tests; |
| 319 ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests)); |
| 320 |
| 321 const base::DictionaryValue* test; |
| 322 ASSERT_TRUE(tests->GetDictionary(0, &test)); |
| 323 |
| 324 // Import the public key. |
| 325 const base::DictionaryValue* public_key_json = NULL; |
| 326 EXPECT_TRUE(test->GetDictionary("public_key", &public_key_json)); |
| 327 blink::WebCryptoNamedCurve curve = |
| 328 GetCurveNameFromDictionary(public_key_json, "crv"); |
| 329 ASSERT_EQ(Status::Success(), |
| 330 ImportKey(blink::WebCryptoKeyFormatJwk, |
| 331 CryptoData(MakeJsonVector(*public_key_json)), |
| 332 CreateEcdhImportAlgorithm(curve), true, 0, &key)); |
| 333 |
| 334 // Import the private key. |
| 335 const base::DictionaryValue* private_key_json = NULL; |
| 336 EXPECT_TRUE(test->GetDictionary("private_key", &private_key_json)); |
| 337 curve = GetCurveNameFromDictionary(private_key_json, "crv"); |
| 338 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(), |
| 339 ImportKey(blink::WebCryptoKeyFormatJwk, |
| 340 CryptoData(MakeJsonVector(*private_key_json)), |
| 341 CreateEcdhImportAlgorithm(curve), true, |
| 342 0, &key)); |
| 343 } |
| 344 |
312 } // namespace | 345 } // namespace |
313 | 346 |
314 } // namespace webcrypto | 347 } // namespace webcrypto |
315 | 348 |
316 } // namespace content | 349 } // namespace content |
OLD | NEW |