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

Side by Side Diff: content/child/webcrypto/test/test_helpers.cc

Issue 661653002: [webcrypto] Implement RSA-PSS using BoringSSL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_rsassa
Patch Set: rebase onto master (corrected) Created 6 years, 2 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 | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_util.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 "content/child/webcrypto/test/test_helpers.h" 5 #include "content/child/webcrypto/test/test_helpers.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 #endif 115 #endif
116 return true; 116 return true;
117 } 117 }
118 118
119 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm( 119 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm(
120 blink::WebCryptoAlgorithmId algorithm_id, 120 blink::WebCryptoAlgorithmId algorithm_id,
121 const blink::WebCryptoAlgorithmId hash_id, 121 const blink::WebCryptoAlgorithmId hash_id,
122 unsigned int modulus_length, 122 unsigned int modulus_length,
123 const std::vector<uint8_t>& public_exponent) { 123 const std::vector<uint8_t>& public_exponent) {
124 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 ||
125 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep);
126 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); 124 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id));
127 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( 125 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
128 algorithm_id, 126 algorithm_id,
129 new blink::WebCryptoRsaHashedKeyGenParams( 127 new blink::WebCryptoRsaHashedKeyGenParams(
130 CreateAlgorithm(hash_id), 128 CreateAlgorithm(hash_id),
131 modulus_length, 129 modulus_length,
132 vector_as_array(&public_exponent), 130 vector_as_array(&public_exponent),
133 public_exponent.size())); 131 public_exponent.size()));
134 } 132 }
135 133
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 base::ListValue* list_value = NULL; 197 base::ListValue* list_value = NULL;
200 if (!json->GetAsList(&list_value) || !list_value) 198 if (!json->GetAsList(&list_value) || !list_value)
201 return ::testing::AssertionFailure() << "The JSON was not a list"; 199 return ::testing::AssertionFailure() << "The JSON was not a list";
202 200
203 list->reset(list_value); 201 list->reset(list_value);
204 ignore_result(json.release()); 202 ignore_result(json.release());
205 203
206 return ::testing::AssertionSuccess(); 204 return ::testing::AssertionSuccess();
207 } 205 }
208 206
209 std::vector<uint8_t> GetBytesFromHexString(base::DictionaryValue* dict, 207 ::testing::AssertionResult ReadJsonTestFileToDictionary(
210 const char* property_name) { 208 const char* test_file_name,
209 scoped_ptr<base::DictionaryValue>* dict) {
210 // Read the JSON.
211 scoped_ptr<base::Value> json;
212 ::testing::AssertionResult result = ReadJsonTestFile(test_file_name, &json);
213 if (!result)
214 return result;
215
216 // Cast to an DictionaryValue.
217 base::DictionaryValue* dict_value = NULL;
218 if (!json->GetAsDictionary(&dict_value) || !dict_value)
219 return ::testing::AssertionFailure() << "The JSON was not a dictionary";
220
221 dict->reset(dict_value);
222 ignore_result(json.release());
223
224 return ::testing::AssertionSuccess();
225 }
226
227 std::vector<uint8_t> GetBytesFromHexString(const base::DictionaryValue* dict,
228 const std::string& property_name) {
211 std::string hex_string; 229 std::string hex_string;
212 if (!dict->GetString(property_name, &hex_string)) { 230 if (!dict->GetString(property_name, &hex_string)) {
213 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; 231 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name;
214 return std::vector<uint8_t>(); 232 return std::vector<uint8_t>();
215 } 233 }
216 234
217 return HexStringToBytes(hex_string); 235 return HexStringToBytes(hex_string);
218 } 236 }
219 237
220 blink::WebCryptoAlgorithm GetDigestAlgorithm(base::DictionaryValue* dict, 238 blink::WebCryptoAlgorithm GetDigestAlgorithm(const base::DictionaryValue* dict,
221 const char* property_name) { 239 const char* property_name) {
222 std::string algorithm_name; 240 std::string algorithm_name;
223 if (!dict->GetString(property_name, &algorithm_name)) { 241 if (!dict->GetString(property_name, &algorithm_name)) {
224 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; 242 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name;
225 return blink::WebCryptoAlgorithm::createNull(); 243 return blink::WebCryptoAlgorithm::createNull();
226 } 244 }
227 245
228 struct { 246 struct {
229 const char* name; 247 const char* name;
230 blink::WebCryptoAlgorithmId id; 248 blink::WebCryptoAlgorithmId id;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 631
614 *public_key = result.public_key(); 632 *public_key = result.public_key();
615 *private_key = result.private_key(); 633 *private_key = result.private_key();
616 634
617 return Status::Success(); 635 return Status::Success();
618 } 636 }
619 637
620 } // namespace webcrypto 638 } // namespace webcrypto
621 639
622 } // namesapce content 640 } // namesapce content
OLDNEW
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698