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

Side by Side Diff: components/webcrypto/test/aes_cbc_unittest.cc

Issue 1077273002: html_viewer: Move webcrypto to a place where html_viewer can use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT Created 5 years, 8 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
« no previous file with comments | « components/webcrypto/status.cc ('k') | components/webcrypto/test/aes_ctr_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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
OLDNEW
« no previous file with comments | « components/webcrypto/status.cc ('k') | components/webcrypto/test/aes_ctr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698