| OLD | NEW |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 #endif | 114 #endif |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm( | 118 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm( |
| 119 blink::WebCryptoAlgorithmId algorithm_id, | 119 blink::WebCryptoAlgorithmId algorithm_id, |
| 120 const blink::WebCryptoAlgorithmId hash_id, | 120 const blink::WebCryptoAlgorithmId hash_id, |
| 121 unsigned int modulus_length, | 121 unsigned int modulus_length, |
| 122 const std::vector<uint8_t>& public_exponent) { | 122 const std::vector<uint8_t>& public_exponent) { |
| 123 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | |
| 124 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); | |
| 125 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 123 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
| 126 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 124 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 127 algorithm_id, | 125 algorithm_id, |
| 128 new blink::WebCryptoRsaHashedKeyGenParams( | 126 new blink::WebCryptoRsaHashedKeyGenParams( |
| 129 CreateAlgorithm(hash_id), | 127 CreateAlgorithm(hash_id), |
| 130 modulus_length, | 128 modulus_length, |
| 131 vector_as_array(&public_exponent), | 129 vector_as_array(&public_exponent), |
| 132 public_exponent.size())); | 130 public_exponent.size())); |
| 133 } | 131 } |
| 134 | 132 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 base::ListValue* list_value = NULL; | 196 base::ListValue* list_value = NULL; |
| 199 if (!json->GetAsList(&list_value) || !list_value) | 197 if (!json->GetAsList(&list_value) || !list_value) |
| 200 return ::testing::AssertionFailure() << "The JSON was not a list"; | 198 return ::testing::AssertionFailure() << "The JSON was not a list"; |
| 201 | 199 |
| 202 list->reset(list_value); | 200 list->reset(list_value); |
| 203 ignore_result(json.release()); | 201 ignore_result(json.release()); |
| 204 | 202 |
| 205 return ::testing::AssertionSuccess(); | 203 return ::testing::AssertionSuccess(); |
| 206 } | 204 } |
| 207 | 205 |
| 208 std::vector<uint8_t> GetBytesFromHexString(base::DictionaryValue* dict, | 206 ::testing::AssertionResult ReadJsonTestFileToDictionary( |
| 209 const char* property_name) { | 207 const char* test_file_name, |
| 208 scoped_ptr<base::DictionaryValue>* dict) { |
| 209 // Read the JSON. |
| 210 scoped_ptr<base::Value> json; |
| 211 ::testing::AssertionResult result = ReadJsonTestFile(test_file_name, &json); |
| 212 if (!result) |
| 213 return result; |
| 214 |
| 215 // Cast to an DictionaryValue. |
| 216 base::DictionaryValue* dict_value = NULL; |
| 217 if (!json->GetAsDictionary(&dict_value) || !dict_value) |
| 218 return ::testing::AssertionFailure() << "The JSON was not a dictionary"; |
| 219 |
| 220 dict->reset(dict_value); |
| 221 ignore_result(json.release()); |
| 222 |
| 223 return ::testing::AssertionSuccess(); |
| 224 } |
| 225 |
| 226 std::vector<uint8_t> GetBytesFromHexString(const base::DictionaryValue* dict, |
| 227 const std::string& property_name) { |
| 210 std::string hex_string; | 228 std::string hex_string; |
| 211 if (!dict->GetString(property_name, &hex_string)) { | 229 if (!dict->GetString(property_name, &hex_string)) { |
| 212 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; | 230 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; |
| 213 return std::vector<uint8_t>(); | 231 return std::vector<uint8_t>(); |
| 214 } | 232 } |
| 215 | 233 |
| 216 return HexStringToBytes(hex_string); | 234 return HexStringToBytes(hex_string); |
| 217 } | 235 } |
| 218 | 236 |
| 219 blink::WebCryptoAlgorithm GetDigestAlgorithm(base::DictionaryValue* dict, | 237 blink::WebCryptoAlgorithm GetDigestAlgorithm(const base::DictionaryValue* dict, |
| 220 const char* property_name) { | 238 const char* property_name) { |
| 221 std::string algorithm_name; | 239 std::string algorithm_name; |
| 222 if (!dict->GetString(property_name, &algorithm_name)) { | 240 if (!dict->GetString(property_name, &algorithm_name)) { |
| 223 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; | 241 EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; |
| 224 return blink::WebCryptoAlgorithm::createNull(); | 242 return blink::WebCryptoAlgorithm::createNull(); |
| 225 } | 243 } |
| 226 | 244 |
| 227 struct { | 245 struct { |
| 228 const char* name; | 246 const char* name; |
| 229 blink::WebCryptoAlgorithmId id; | 247 blink::WebCryptoAlgorithmId id; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // Export the key in raw format and compare to the original. | 594 // Export the key in raw format and compare to the original. |
| 577 std::vector<uint8_t> key_raw_out; | 595 std::vector<uint8_t> key_raw_out; |
| 578 ASSERT_EQ(Status::Success(), | 596 ASSERT_EQ(Status::Success(), |
| 579 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); | 597 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); |
| 580 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out); | 598 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out); |
| 581 } | 599 } |
| 582 | 600 |
| 583 } // namespace webcrypto | 601 } // namespace webcrypto |
| 584 | 602 |
| 585 } // namesapce content | 603 } // namesapce content |
| OLD | NEW |