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

Side by Side Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 211943002: [webcrypto] Minor cleanup/consolidation of JWK source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes for eroman Created 6 years, 9 months 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 "content/child/webcrypto/shared_crypto.h" 5 #include "content/child/webcrypto/shared_crypto.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 cipher_text_with_tag.reserve(cipher_text.size() + authentication_tag.size()); 509 cipher_text_with_tag.reserve(cipher_text.size() + authentication_tag.size());
510 cipher_text_with_tag.insert( 510 cipher_text_with_tag.insert(
511 cipher_text_with_tag.end(), cipher_text.begin(), cipher_text.end()); 511 cipher_text_with_tag.end(), cipher_text.begin(), cipher_text.end());
512 cipher_text_with_tag.insert(cipher_text_with_tag.end(), 512 cipher_text_with_tag.insert(cipher_text_with_tag.end(),
513 authentication_tag.begin(), 513 authentication_tag.begin(),
514 authentication_tag.end()); 514 authentication_tag.end());
515 515
516 return Decrypt(algorithm, key, CryptoData(cipher_text_with_tag), plain_text); 516 return Decrypt(algorithm, key, CryptoData(cipher_text_with_tag), plain_text);
517 } 517 }
518 518
519 Status ImportKeyJwk(const CryptoData& key_data,
520 const blink::WebCryptoAlgorithm& algorithm,
521 bool extractable,
522 blink::WebCryptoKeyUsageMask usage_mask,
523 blink::WebCryptoKey* key) {
524 return ImportKey(blink::WebCryptoKeyFormatJwk,
525 key_data,
526 algorithm,
527 extractable,
528 usage_mask,
529 key);
530 }
531
519 Status ImportKeyJwkFromDict(const base::DictionaryValue& dict, 532 Status ImportKeyJwkFromDict(const base::DictionaryValue& dict,
520 const blink::WebCryptoAlgorithm& algorithm, 533 const blink::WebCryptoAlgorithm& algorithm,
521 bool extractable, 534 bool extractable,
522 blink::WebCryptoKeyUsageMask usage_mask, 535 blink::WebCryptoKeyUsageMask usage_mask,
523 blink::WebCryptoKey* key) { 536 blink::WebCryptoKey* key) {
524 return ImportKeyJwk(CryptoData(MakeJsonVector(dict)), 537 return ImportKeyJwk(CryptoData(MakeJsonVector(dict)),
525 algorithm, 538 algorithm,
526 extractable, 539 extractable,
527 usage_mask, 540 usage_mask,
528 key); 541 key);
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 if (test.algorithm.id() == blink::WebCryptoAlgorithmIdAesGcm && 1726 if (test.algorithm.id() == blink::WebCryptoAlgorithmIdAesGcm &&
1714 !SupportsAesGcm()) { 1727 !SupportsAesGcm()) {
1715 continue; 1728 continue;
1716 } 1729 }
1717 1730
1718 // Import a raw key. 1731 // Import a raw key.
1719 key = ImportSecretKeyFromRaw( 1732 key = ImportSecretKeyFromRaw(
1720 HexStringToBytes(test.key_hex), test.algorithm, test.usage); 1733 HexStringToBytes(test.key_hex), test.algorithm, test.usage);
1721 1734
1722 // Export the key in JWK format and validate. 1735 // Export the key in JWK format and validate.
1723 ASSERT_STATUS_SUCCESS(ExportKeyJwk(key, &json)); 1736 ASSERT_STATUS_SUCCESS(ExportKey(blink::WebCryptoKeyFormatJwk, key, &json));
1724 EXPECT_TRUE(VerifySecretJwk(json, test.jwk_alg, test.key_hex, test.usage)); 1737 EXPECT_TRUE(VerifySecretJwk(json, test.jwk_alg, test.key_hex, test.usage));
1725 1738
1726 // Import the JWK-formatted key. 1739 // Import the JWK-formatted key.
1727 ASSERT_STATUS_SUCCESS( 1740 ASSERT_STATUS_SUCCESS(
1728 ImportKeyJwk(CryptoData(json), test.algorithm, true, test.usage, &key)); 1741 ImportKeyJwk(CryptoData(json), test.algorithm, true, test.usage, &key));
1729 EXPECT_TRUE(key.handle()); 1742 EXPECT_TRUE(key.handle());
1730 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); 1743 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type());
1731 EXPECT_EQ(test.algorithm.id(), key.algorithm().id()); 1744 EXPECT_EQ(test.algorithm.id(), key.algorithm().id());
1732 EXPECT_EQ(true, key.extractable()); 1745 EXPECT_EQ(true, key.extractable());
1733 EXPECT_EQ(test.usage, key.usages()); 1746 EXPECT_EQ(test.usage, key.usages());
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 algorithm, 3192 algorithm,
3180 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), 3193 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)),
3181 true, 3194 true,
3182 blink::WebCryptoKeyUsageEncrypt, 3195 blink::WebCryptoKeyUsageEncrypt,
3183 &unwrapped_key)); 3196 &unwrapped_key));
3184 } 3197 }
3185 3198
3186 } // namespace webcrypto 3199 } // namespace webcrypto
3187 3200
3188 } // namespace content 3201 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698