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

Side by Side Diff: components/webcrypto/algorithms/rsa_oaep_unittest.cc

Issue 1461703009: Switch //components from vector_as_array to vector::data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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/base64url.h" 5 #include "base/base64url.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/stl_util.h"
8 #include "components/webcrypto/algorithm_dispatch.h" 7 #include "components/webcrypto/algorithm_dispatch.h"
9 #include "components/webcrypto/algorithms/test_helpers.h" 8 #include "components/webcrypto/algorithms/test_helpers.h"
10 #include "components/webcrypto/crypto_data.h" 9 #include "components/webcrypto/crypto_data.h"
11 #include "components/webcrypto/jwk.h" 10 #include "components/webcrypto/jwk.h"
12 #include "components/webcrypto/status.h" 11 #include "components/webcrypto/status.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
16 15
17 namespace webcrypto { 16 namespace webcrypto {
18 17
19 namespace { 18 namespace {
20 19
21 // Creates an RSA-OAEP algorithm 20 // Creates an RSA-OAEP algorithm
22 blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm( 21 blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm(
23 const std::vector<uint8_t>& label) { 22 const std::vector<uint8_t>& label) {
24 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( 23 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
25 blink::WebCryptoAlgorithmIdRsaOaep, 24 blink::WebCryptoAlgorithmIdRsaOaep,
26 new blink::WebCryptoRsaOaepParams( 25 new blink::WebCryptoRsaOaepParams(
27 !label.empty(), vector_as_array(&label), 26 !label.empty(), label.data(),
28 static_cast<unsigned int>(label.size()))); 27 static_cast<unsigned int>(label.size())));
29 } 28 }
30 29
31 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { 30 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) {
32 // The JSON web signature spec says that padding is omitted. 31 // The JSON web signature spec says that padding is omitted.
33 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2 32 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2
34 std::string base64url_encoded; 33 std::string base64url_encoded;
35 base::Base64UrlEncode( 34 base::Base64UrlEncode(
36 base::StringPiece(reinterpret_cast<const char*>(vector_as_array(&input)), 35 base::StringPiece(reinterpret_cast<const char*>(input.data()),
eroman 2015/11/20 00:35:14 side note: wonder if we should have an automatic t
davidben 2015/11/20 19:12:50 Yeah, we certainly need something. Doing these rei
37 input.size()), 36 input.size()),
38 base::Base64UrlEncodePolicy::OMIT_PADDING, &base64url_encoded); 37 base::Base64UrlEncodePolicy::OMIT_PADDING, &base64url_encoded);
39 return base64url_encoded; 38 return base64url_encoded;
40 } 39 }
41 40
42 scoped_ptr<base::DictionaryValue> CreatePublicKeyJwkDict() { 41 scoped_ptr<base::DictionaryValue> CreatePublicKeyJwkDict() {
43 scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue()); 42 scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue());
44 jwk->SetString("kty", "RSA"); 43 jwk->SetString("kty", "RSA");
45 jwk->SetString("n", 44 jwk->SetString("n",
46 Base64EncodeUrlSafe(HexStringToBytes(kPublicKeyModulusHex))); 45 Base64EncodeUrlSafe(HexStringToBytes(kPublicKeyModulusHex)));
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 EXPECT_TRUE(public_key2.extractable()); 506 EXPECT_TRUE(public_key2.extractable());
508 EXPECT_EQ(import_algorithm.id(), public_key2.algorithm().id()); 507 EXPECT_EQ(import_algorithm.id(), public_key2.algorithm().id());
509 508
510 // TODO(eroman): Export the SPKI and verify matches. 509 // TODO(eroman): Export the SPKI and verify matches.
511 } 510 }
512 } 511 }
513 512
514 } // namespace 513 } // namespace
515 514
516 } // namespace webcrypto 515 } // namespace webcrypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698