| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "content/child/webcrypto/algorithm_dispatch.h" | 7 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/jwk.h" | 9 #include "content/child/webcrypto/jwk.h" |
| 10 #include "content/child/webcrypto/status.h" | 10 #include "content/child/webcrypto/status.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 struct TestData { | 148 struct TestData { |
| 149 blink::WebCryptoAlgorithmId hash_alg; | 149 blink::WebCryptoAlgorithmId hash_alg; |
| 150 const char* expected_jwk_alg; | 150 const char* expected_jwk_alg; |
| 151 } kTestData[] = {{blink::WebCryptoAlgorithmIdSha1, "RSA-OAEP"}, | 151 } kTestData[] = {{blink::WebCryptoAlgorithmIdSha1, "RSA-OAEP"}, |
| 152 {blink::WebCryptoAlgorithmIdSha256, "RSA-OAEP-256"}, | 152 {blink::WebCryptoAlgorithmIdSha256, "RSA-OAEP-256"}, |
| 153 {blink::WebCryptoAlgorithmIdSha384, "RSA-OAEP-384"}, | 153 {blink::WebCryptoAlgorithmIdSha384, "RSA-OAEP-384"}, |
| 154 {blink::WebCryptoAlgorithmIdSha512, "RSA-OAEP-512"}}; | 154 {blink::WebCryptoAlgorithmIdSha512, "RSA-OAEP-512"}}; |
| 155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestData); ++i) { | 155 for (size_t i = 0; i < arraysize(kTestData); ++i) { |
| 156 const TestData& test_data = kTestData[i]; | 156 const TestData& test_data = kTestData[i]; |
| 157 SCOPED_TRACE(test_data.expected_jwk_alg); | 157 SCOPED_TRACE(test_data.expected_jwk_alg); |
| 158 | 158 |
| 159 scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); | 159 scoped_ptr<base::DictionaryValue> jwk(CreatePublicKeyJwkDict()); |
| 160 jwk->SetString("alg", test_data.expected_jwk_alg); | 160 jwk->SetString("alg", test_data.expected_jwk_alg); |
| 161 | 161 |
| 162 // Import the key in a known-good format | 162 // Import the key in a known-good format |
| 163 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 163 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 164 ASSERT_EQ(Status::Success(), | 164 ASSERT_EQ(Status::Success(), |
| 165 ImportKeyJwkFromDict( | 165 ImportKeyJwkFromDict( |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 }; | 582 }; |
| 583 const TestCase kTests[] = {{blink::WebCryptoAlgorithmIdSha1, | 583 const TestCase kTests[] = {{blink::WebCryptoAlgorithmIdSha1, |
| 584 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP"}, | 584 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP"}, |
| 585 {blink::WebCryptoAlgorithmIdSha256, | 585 {blink::WebCryptoAlgorithmIdSha256, |
| 586 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-256"}, | 586 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-256"}, |
| 587 {blink::WebCryptoAlgorithmIdSha384, | 587 {blink::WebCryptoAlgorithmIdSha384, |
| 588 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-384"}, | 588 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-384"}, |
| 589 {blink::WebCryptoAlgorithmIdSha512, | 589 {blink::WebCryptoAlgorithmIdSha512, |
| 590 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-512"}}; | 590 blink::WebCryptoKeyUsageEncrypt, "RSA-OAEP-512"}}; |
| 591 | 591 |
| 592 for (size_t test_index = 0; test_index < ARRAYSIZE_UNSAFE(kTests); | 592 for (size_t test_index = 0; test_index < arraysize(kTests); ++test_index) { |
| 593 ++test_index) { | |
| 594 SCOPED_TRACE(test_index); | 593 SCOPED_TRACE(test_index); |
| 595 const TestCase& test = kTests[test_index]; | 594 const TestCase& test = kTests[test_index]; |
| 596 | 595 |
| 597 const blink::WebCryptoAlgorithm import_algorithm = | 596 const blink::WebCryptoAlgorithm import_algorithm = |
| 598 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaOaep, | 597 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaOaep, |
| 599 test.hash); | 598 test.hash); |
| 600 | 599 |
| 601 // Import the spki to create a public key | 600 // Import the spki to create a public key |
| 602 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 601 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 603 ASSERT_EQ(Status::Success(), | 602 ASSERT_EQ(Status::Success(), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 634 | 633 |
| 635 // TODO(eroman): Export the SPKI and verify matches. | 634 // TODO(eroman): Export the SPKI and verify matches. |
| 636 } | 635 } |
| 637 } | 636 } |
| 638 | 637 |
| 639 } // namespace | 638 } // namespace |
| 640 | 639 |
| 641 } // namespace webcrypto | 640 } // namespace webcrypto |
| 642 | 641 |
| 643 } // namespace content | 642 } // namespace content |
| OLD | NEW |