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

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 code to adapt to new changes + code 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 blink::WebCryptoKey key;
314
315 scoped_ptr<base::ListValue> tests;
316 ASSERT_TRUE(ReadJsonTestFileToList("ecdh.json", &tests));
317
318 const base::DictionaryValue* test;
319 ASSERT_TRUE(tests->GetDictionary(0, &test));
320
321 // Import the public key.
322 const base::DictionaryValue* public_key_json = NULL;
323 EXPECT_TRUE(test->GetDictionary("public_key", &public_key_json));
324 blink::WebCryptoNamedCurve curve =
325 GetCurveNameFromDictionary(public_key_json, "crv");
326 ASSERT_EQ(Status::Success(),
327 ImportKey(blink::WebCryptoKeyFormatJwk,
328 CryptoData(MakeJsonVector(*public_key_json)),
329 CreateEcdhImportAlgorithm(curve), true, 0, &key));
330
331 // Import the private key.
332 const base::DictionaryValue* private_key_json = NULL;
333 EXPECT_TRUE(test->GetDictionary("private_key", &private_key_json));
334 curve = GetCurveNameFromDictionary(private_key_json, "crv");
335 ASSERT_EQ(Status::ErrorKeyEmptyUsages(),
336 ImportKey(blink::WebCryptoKeyFormatJwk,
337 CryptoData(MakeJsonVector(*private_key_json)),
338 CreateEcdhImportAlgorithm(curve), true,
339 0, &key));
340 }
341
312 } // namespace 342 } // namespace
313 343
314 } // namespace webcrypto 344 } // namespace webcrypto
315 345
316 } // namespace content 346 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698