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

Side by Side Diff: components/webcrypto/test/hmac_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
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/logging.h" 5 #include "base/logging.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "content/child/webcrypto/algorithm_dispatch.h" 7 #include "components/webcrypto/algorithm_dispatch.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "components/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/status.h" 9 #include "components/webcrypto/status.h"
10 #include "content/child/webcrypto/test/test_helpers.h" 10 #include "components/webcrypto/test/test_helpers.h"
11 #include "content/child/webcrypto/webcrypto_util.h" 11 #include "components/webcrypto/webcrypto_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
15 15
16 namespace content {
17
18 namespace webcrypto { 16 namespace webcrypto {
19 17
20 namespace { 18 namespace {
21 19
22 // Creates an HMAC algorithm whose parameters struct is compatible with key 20 // Creates an HMAC algorithm whose parameters struct is compatible with key
23 // generation. It is an error to call this with a hash_id that is not a SHA*. 21 // generation. It is an error to call this with a hash_id that is not a SHA*.
24 // The key_length_bits parameter is optional, with zero meaning unspecified. 22 // The key_length_bits parameter is optional, with zero meaning unspecified.
25 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( 23 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
26 blink::WebCryptoAlgorithmId hash_id, 24 blink::WebCryptoAlgorithmId hash_id,
27 unsigned int key_length_bits) { 25 unsigned int key_length_bits) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ASSERT_EQ(Status::Success(), 202 ASSERT_EQ(Status::Success(),
205 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); 203 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
206 ASSERT_EQ(1U, raw_key.size()); 204 ASSERT_EQ(1U, raw_key.size());
207 205
208 EXPECT_FALSE(raw_key[0] & 0x7F); 206 EXPECT_FALSE(raw_key[0] & 0x7F);
209 } 207 }
210 208
211 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) { 209 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) {
212 blink::WebCryptoKey key; 210 blink::WebCryptoKey key;
213 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; 211 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939";
214 EXPECT_EQ( 212 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(),
215 Status::ErrorCreateKeyEmptyUsages(), 213 ImportKey(blink::WebCryptoKeyFormatRaw,
216 ImportKey(blink::WebCryptoKeyFormatRaw, 214 CryptoData(HexStringToBytes(key_raw_hex_in)),
217 CryptoData(HexStringToBytes(key_raw_hex_in)), 215 CreateHmacImportAlgorithmNoLength(
218 CreateHmacImportAlgorithmNoLength( 216 blink::WebCryptoAlgorithmIdSha1),
219 blink::WebCryptoAlgorithmIdSha1), 217 true, 0, &key));
220 true, 0, &key));
221 } 218 }
222 219
223 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { 220 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
224 blink::WebCryptoKey key; 221 blink::WebCryptoKey key;
225 base::DictionaryValue dict; 222 base::DictionaryValue dict;
226 dict.SetString("kty", "oct"); 223 dict.SetString("kty", "oct");
227 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 224 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
228 base::ListValue* key_ops = new base::ListValue; 225 base::ListValue* key_ops = new base::ListValue;
229 dict.Set("key_ops", key_ops); // Takes ownership. 226 dict.Set("key_ops", key_ops); // Takes ownership.
230 227
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // On export the last 4 bits has been set to zero. 590 // On export the last 4 bits has been set to zero.
594 std::vector<uint8_t> raw_key; 591 std::vector<uint8_t> raw_key;
595 EXPECT_EQ(Status::Success(), 592 EXPECT_EQ(Status::Success(),
596 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); 593 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
597 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key); 594 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key);
598 } 595 }
599 596
600 } // namespace 597 } // namespace
601 598
602 } // namespace webcrypto 599 } // namespace webcrypto
603
604 } // namespace content
OLDNEW
« no previous file with comments | « components/webcrypto/test/ecdsa_unittest.cc ('k') | components/webcrypto/test/rsa_oaep_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698