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 "components/webcrypto/algorithms/test_helpers.h" | 5 #include "components/webcrypto/algorithms/test_helpers.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/stl_util.h" | |
16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
18 #include "base/values.h" | 17 #include "base/values.h" |
19 #include "components/test_runner/test_common.h" | 18 #include "components/test_runner/test_common.h" |
20 #include "components/webcrypto/algorithm_dispatch.h" | 19 #include "components/webcrypto/algorithm_dispatch.h" |
21 #include "components/webcrypto/crypto_data.h" | 20 #include "components/webcrypto/crypto_data.h" |
22 #include "components/webcrypto/generate_key_result.h" | 21 #include "components/webcrypto/generate_key_result.h" |
23 #include "components/webcrypto/jwk.h" | 22 #include "components/webcrypto/jwk.h" |
24 #include "components/webcrypto/status.h" | 23 #include "components/webcrypto/status.h" |
25 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 24 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return result; | 102 return result; |
104 } | 103 } |
105 | 104 |
106 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm( | 105 blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm( |
107 blink::WebCryptoAlgorithmId algorithm_id, | 106 blink::WebCryptoAlgorithmId algorithm_id, |
108 const blink::WebCryptoAlgorithmId hash_id, | 107 const blink::WebCryptoAlgorithmId hash_id, |
109 unsigned int modulus_length, | 108 unsigned int modulus_length, |
110 const std::vector<uint8_t>& public_exponent) { | 109 const std::vector<uint8_t>& public_exponent) { |
111 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); | 110 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); |
112 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 111 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
113 algorithm_id, new blink::WebCryptoRsaHashedKeyGenParams( | 112 algorithm_id, |
114 CreateAlgorithm(hash_id), modulus_length, | 113 new blink::WebCryptoRsaHashedKeyGenParams( |
115 vector_as_array(&public_exponent), | 114 CreateAlgorithm(hash_id), modulus_length, public_exponent.data(), |
116 static_cast<unsigned int>(public_exponent.size()))); | 115 static_cast<unsigned int>(public_exponent.size()))); |
117 } | 116 } |
118 | 117 |
119 std::vector<uint8_t> Corrupted(const std::vector<uint8_t>& input) { | 118 std::vector<uint8_t> Corrupted(const std::vector<uint8_t>& input) { |
120 std::vector<uint8_t> corrupted_data(input); | 119 std::vector<uint8_t> corrupted_data(input); |
121 if (corrupted_data.empty()) | 120 if (corrupted_data.empty()) |
122 corrupted_data.push_back(0); | 121 corrupted_data.push_back(0); |
123 corrupted_data[corrupted_data.size() / 2] ^= 0x01; | 122 corrupted_data[corrupted_data.size() / 2] ^= 0x01; |
124 return corrupted_data; | 123 return corrupted_data; |
125 } | 124 } |
126 | 125 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 bool extractable, | 380 bool extractable, |
382 blink::WebCryptoKeyUsageMask usages, | 381 blink::WebCryptoKeyUsageMask usages, |
383 blink::WebCryptoKey* key) { | 382 blink::WebCryptoKey* key) { |
384 return ImportKey(blink::WebCryptoKeyFormatJwk, | 383 return ImportKey(blink::WebCryptoKeyFormatJwk, |
385 CryptoData(MakeJsonVector(dict)), algorithm, extractable, | 384 CryptoData(MakeJsonVector(dict)), algorithm, extractable, |
386 usages, key); | 385 usages, key); |
387 } | 386 } |
388 | 387 |
389 scoped_ptr<base::DictionaryValue> GetJwkDictionary( | 388 scoped_ptr<base::DictionaryValue> GetJwkDictionary( |
390 const std::vector<uint8_t>& json) { | 389 const std::vector<uint8_t>& json) { |
391 base::StringPiece json_string( | 390 base::StringPiece json_string(reinterpret_cast<const char*>(json.data()), |
392 reinterpret_cast<const char*>(vector_as_array(&json)), json.size()); | 391 json.size()); |
393 scoped_ptr<base::Value> value = base::JSONReader::Read(json_string); | 392 scoped_ptr<base::Value> value = base::JSONReader::Read(json_string); |
394 EXPECT_TRUE(value.get()); | 393 EXPECT_TRUE(value.get()); |
395 EXPECT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 394 EXPECT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
396 | 395 |
397 return scoped_ptr<base::DictionaryValue>( | 396 return scoped_ptr<base::DictionaryValue>( |
398 static_cast<base::DictionaryValue*>(value.release())); | 397 static_cast<base::DictionaryValue*>(value.release())); |
399 } | 398 } |
400 | 399 |
401 // Verifies the input dictionary contains the expected values. Exact matches are | 400 // Verifies the input dictionary contains the expected values. Exact matches are |
402 // required on the fields examined. | 401 // required on the fields examined. |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 } | 686 } |
688 | 687 |
689 blink::WebCryptoAlgorithm CreateEcImportAlgorithm( | 688 blink::WebCryptoAlgorithm CreateEcImportAlgorithm( |
690 blink::WebCryptoAlgorithmId id, | 689 blink::WebCryptoAlgorithmId id, |
691 blink::WebCryptoNamedCurve named_curve) { | 690 blink::WebCryptoNamedCurve named_curve) { |
692 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 691 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
693 id, new blink::WebCryptoEcKeyImportParams(named_curve)); | 692 id, new blink::WebCryptoEcKeyImportParams(named_curve)); |
694 } | 693 } |
695 | 694 |
696 } // namespace webcrypto | 695 } // namespace webcrypto |
OLD | NEW |