| 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/test/test_helpers.h" | 5 #include "components/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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (!dict.get() || dict->empty()) | 488 if (!dict.get() || dict->empty()) |
| 489 return ::testing::AssertionFailure() << "JSON parsing failed"; | 489 return ::testing::AssertionFailure() << "JSON parsing failed"; |
| 490 | 490 |
| 491 // ---- k | 491 // ---- k |
| 492 std::string value_string; | 492 std::string value_string; |
| 493 if (!dict->GetString("k", &value_string)) | 493 if (!dict->GetString("k", &value_string)) |
| 494 return ::testing::AssertionFailure() << "Missing 'k'"; | 494 return ::testing::AssertionFailure() << "Missing 'k'"; |
| 495 std::string k_value; | 495 std::string k_value; |
| 496 if (!Base64DecodeUrlSafe(value_string, &k_value)) | 496 if (!Base64DecodeUrlSafe(value_string, &k_value)) |
| 497 return ::testing::AssertionFailure() << "Base64DecodeUrlSafe(k) failed"; | 497 return ::testing::AssertionFailure() << "Base64DecodeUrlSafe(k) failed"; |
| 498 if (!LowerCaseEqualsASCII(base::HexEncode(k_value.data(), k_value.size()), | 498 if (!base::LowerCaseEqualsASCII( |
| 499 k_expected_hex.c_str())) { | 499 base::HexEncode(k_value.data(), k_value.size()), |
| 500 k_expected_hex.c_str())) { |
| 500 return ::testing::AssertionFailure() << "Expected 'k' to be " | 501 return ::testing::AssertionFailure() << "Expected 'k' to be " |
| 501 << k_expected_hex | 502 << k_expected_hex |
| 502 << " but found something different"; | 503 << " but found something different"; |
| 503 } | 504 } |
| 504 | 505 |
| 505 return VerifyJwk(dict, "oct", alg_expected, use_mask_expected); | 506 return VerifyJwk(dict, "oct", alg_expected, use_mask_expected); |
| 506 } | 507 } |
| 507 | 508 |
| 508 ::testing::AssertionResult VerifyPublicJwk( | 509 ::testing::AssertionResult VerifyPublicJwk( |
| 509 const std::vector<uint8_t>& json, | 510 const std::vector<uint8_t>& json, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 527 "value"; | 528 "value"; |
| 528 } | 529 } |
| 529 // TODO(padolph): LowerCaseEqualsASCII() does not work for above! | 530 // TODO(padolph): LowerCaseEqualsASCII() does not work for above! |
| 530 | 531 |
| 531 // ---- e | 532 // ---- e |
| 532 if (!dict->GetString("e", &value_string)) | 533 if (!dict->GetString("e", &value_string)) |
| 533 return ::testing::AssertionFailure() << "Missing 'e'"; | 534 return ::testing::AssertionFailure() << "Missing 'e'"; |
| 534 std::string e_value; | 535 std::string e_value; |
| 535 if (!Base64DecodeUrlSafe(value_string, &e_value)) | 536 if (!Base64DecodeUrlSafe(value_string, &e_value)) |
| 536 return ::testing::AssertionFailure() << "Base64DecodeUrlSafe(e) failed"; | 537 return ::testing::AssertionFailure() << "Base64DecodeUrlSafe(e) failed"; |
| 537 if (!LowerCaseEqualsASCII(base::HexEncode(e_value.data(), e_value.size()), | 538 if (!base::LowerCaseEqualsASCII( |
| 538 e_expected_hex.c_str())) { | 539 base::HexEncode(e_value.data(), e_value.size()), |
| 540 e_expected_hex.c_str())) { |
| 539 return ::testing::AssertionFailure() << "Expected 'e' to be " | 541 return ::testing::AssertionFailure() << "Expected 'e' to be " |
| 540 << e_expected_hex | 542 << e_expected_hex |
| 541 << " but found something different"; | 543 << " but found something different"; |
| 542 } | 544 } |
| 543 | 545 |
| 544 return VerifyJwk(dict, "RSA", alg_expected, use_mask_expected); | 546 return VerifyJwk(dict, "RSA", alg_expected, use_mask_expected); |
| 545 } | 547 } |
| 546 | 548 |
| 547 void ImportExportJwkSymmetricKey( | 549 void ImportExportJwkSymmetricKey( |
| 548 int key_len_bits, | 550 int key_len_bits, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 return blink::WebCryptoNamedCurveP384; | 681 return blink::WebCryptoNamedCurveP384; |
| 680 if (curve_str == "P-521") | 682 if (curve_str == "P-521") |
| 681 return blink::WebCryptoNamedCurveP521; | 683 return blink::WebCryptoNamedCurveP521; |
| 682 else | 684 else |
| 683 ADD_FAILURE() << "Unrecognized curve name: " << curve_str; | 685 ADD_FAILURE() << "Unrecognized curve name: " << curve_str; |
| 684 | 686 |
| 685 return blink::WebCryptoNamedCurveP384; | 687 return blink::WebCryptoNamedCurveP384; |
| 686 } | 688 } |
| 687 | 689 |
| 688 } // namespace webcrypto | 690 } // namespace webcrypto |
| OLD | NEW |