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

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

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated issues in ecdh tests and other review comments. Created 6 years 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/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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ASSERT_EQ(blink::WebCryptoAlgorithmIdAesGcm, derived_key.algorithm().id()); 309 ASSERT_EQ(blink::WebCryptoAlgorithmIdAesGcm, derived_key.algorithm().id());
310 ASSERT_EQ(128, derived_key.algorithm().aesParams()->lengthBits()); 310 ASSERT_EQ(128, derived_key.algorithm().aesParams()->lengthBits());
311 311
312 // Export the key and verify its contents. 312 // Export the key and verify its contents.
313 std::vector<uint8_t> raw_key; 313 std::vector<uint8_t> raw_key;
314 EXPECT_EQ(Status::Success(), 314 EXPECT_EQ(Status::Success(),
315 ExportKey(blink::WebCryptoKeyFormatRaw, derived_key, &raw_key)); 315 ExportKey(blink::WebCryptoKeyFormatRaw, derived_key, &raw_key));
316 EXPECT_EQ(16u, raw_key.size()); 316 EXPECT_EQ(16u, raw_key.size());
317 } 317 }
318 318
319 TEST(WebCryptoEcdhTest, ImportKeyEmptyUsage) {
320 if (!SupportsEcdh())
321 return;
322
323 blink::WebCryptoKey key;
324
325 scoped_ptr<base::ListValue> tests;
326 ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests));
327
328 const base::DictionaryValue* test;
329 ASSERT_TRUE(tests->GetDictionary(0, &test));
330
331 // Import the public key.
332 const base::DictionaryValue* public_key_json = NULL;
333 EXPECT_TRUE(test->GetDictionary("public_key", &public_key_json));
334 blink::WebCryptoNamedCurve curve =
335 GetCurveNameFromDictionary(public_key_json, "crv");
336 ASSERT_EQ(Status::Success(),
337 ImportKey(blink::WebCryptoKeyFormatJwk,
338 CryptoData(MakeJsonVector(*public_key_json)),
339 CreateEcdhImportAlgorithm(curve), true, 0, &key));
340 EXPECT_EQ(0, key.usages());
341
342 // Import the private key.
343 const base::DictionaryValue* private_key_json = NULL;
344 EXPECT_TRUE(test->GetDictionary("private_key", &private_key_json));
345 curve = GetCurveNameFromDictionary(private_key_json, "crv");
346 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
347 ImportKey(blink::WebCryptoKeyFormatJwk,
348 CryptoData(MakeJsonVector(*private_key_json)),
349 CreateEcdhImportAlgorithm(curve), true,
350 0, &key));
351 }
352
319 } // namespace 353 } // namespace
320 354
321 } // namespace webcrypto 355 } // namespace webcrypto
322 356
323 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698