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

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: Copy the msvs_disabled_warnings to the new target. 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 { 16 namespace components {
17 17
18 namespace webcrypto { 18 namespace webcrypto {
19 19
20 namespace { 20 namespace {
21 21
22 // Creates an HMAC algorithm whose parameters struct is compatible with key 22 // 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*. 23 // 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. 24 // The key_length_bits parameter is optional, with zero meaning unspecified.
25 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm( 25 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
26 blink::WebCryptoAlgorithmId hash_id, 26 blink::WebCryptoAlgorithmId hash_id,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ASSERT_EQ(Status::Success(), 204 ASSERT_EQ(Status::Success(),
205 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); 205 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
206 ASSERT_EQ(1U, raw_key.size()); 206 ASSERT_EQ(1U, raw_key.size());
207 207
208 EXPECT_FALSE(raw_key[0] & 0x7F); 208 EXPECT_FALSE(raw_key[0] & 0x7F);
209 } 209 }
210 210
211 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) { 211 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) {
212 blink::WebCryptoKey key; 212 blink::WebCryptoKey key;
213 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; 213 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939";
214 EXPECT_EQ( 214 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(),
215 Status::ErrorCreateKeyEmptyUsages(), 215 ImportKey(blink::WebCryptoKeyFormatRaw,
216 ImportKey(blink::WebCryptoKeyFormatRaw, 216 CryptoData(HexStringToBytes(key_raw_hex_in)),
217 CryptoData(HexStringToBytes(key_raw_hex_in)), 217 CreateHmacImportAlgorithmNoLength(
218 CreateHmacImportAlgorithmNoLength( 218 blink::WebCryptoAlgorithmIdSha1),
219 blink::WebCryptoAlgorithmIdSha1), 219 true, 0, &key));
220 true, 0, &key));
221 } 220 }
222 221
223 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) { 222 TEST(WebCryptoHmacTest, ImportKeyJwkKeyOpsSignVerify) {
224 blink::WebCryptoKey key; 223 blink::WebCryptoKey key;
225 base::DictionaryValue dict; 224 base::DictionaryValue dict;
226 dict.SetString("kty", "oct"); 225 dict.SetString("kty", "oct");
227 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 226 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
228 base::ListValue* key_ops = new base::ListValue; 227 base::ListValue* key_ops = new base::ListValue;
229 dict.Set("key_ops", key_ops); // Takes ownership. 228 dict.Set("key_ops", key_ops); // Takes ownership.
230 229
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 std::vector<uint8_t> raw_key; 593 std::vector<uint8_t> raw_key;
595 EXPECT_EQ(Status::Success(), 594 EXPECT_EQ(Status::Success(),
596 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key)); 595 ExportKey(blink::WebCryptoKeyFormatRaw, key, &raw_key));
597 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key); 596 EXPECT_BYTES_EQ(HexStringToBytes("b1f0"), raw_key);
598 } 597 }
599 598
600 } // namespace 599 } // namespace
601 600
602 } // namespace webcrypto 601 } // namespace webcrypto
603 602
604 } // namespace content 603 } // namespace components
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698