| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/base64url.h" | 8 #include "base/base64url.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/webcrypto/algorithm_dispatch.h" | 11 #include "components/webcrypto/algorithm_dispatch.h" |
| 12 #include "components/webcrypto/algorithms/test_helpers.h" | 12 #include "components/webcrypto/algorithms/test_helpers.h" |
| 13 #include "components/webcrypto/crypto_data.h" | 13 #include "components/webcrypto/crypto_data.h" |
| 14 #include "components/webcrypto/jwk.h" | 14 #include "components/webcrypto/jwk.h" |
| 15 #include "components/webcrypto/status.h" | 15 #include "components/webcrypto/status.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 18 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 18 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 19 | 19 |
| 20 namespace webcrypto { | 20 namespace webcrypto { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Creates an RSA-OAEP algorithm | 24 // Creates an RSA-OAEP algorithm |
| 25 blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm( | 25 blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm( |
| 26 const std::vector<uint8_t>& label) { | 26 const std::vector<uint8_t>& label) { |
| 27 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 27 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 28 blink::WebCryptoAlgorithmIdRsaOaep, | 28 blink::WebCryptoAlgorithmIdRsaOaep, |
| 29 new blink::WebCryptoRsaOaepParams( | 29 new blink::WebCryptoRsaOaepParams(!label.empty(), label)); |
| 30 !label.empty(), label.data(), | |
| 31 static_cast<unsigned int>(label.size()))); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { | 32 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { |
| 35 // The JSON web signature spec says that padding is omitted. | 33 // The JSON web signature spec says that padding is omitted. |
| 36 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2 | 34 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2 |
| 37 std::string base64url_encoded; | 35 std::string base64url_encoded; |
| 38 base::Base64UrlEncode( | 36 base::Base64UrlEncode( |
| 39 base::StringPiece(reinterpret_cast<const char*>(input.data()), | 37 base::StringPiece(reinterpret_cast<const char*>(input.data()), |
| 40 input.size()), | 38 input.size()), |
| 41 base::Base64UrlEncodePolicy::OMIT_PADDING, &base64url_encoded); | 39 base::Base64UrlEncodePolicy::OMIT_PADDING, &base64url_encoded); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 EXPECT_TRUE(public_key2.extractable()); | 508 EXPECT_TRUE(public_key2.extractable()); |
| 511 EXPECT_EQ(import_algorithm.id(), public_key2.algorithm().id()); | 509 EXPECT_EQ(import_algorithm.id(), public_key2.algorithm().id()); |
| 512 | 510 |
| 513 // TODO(eroman): Export the SPKI and verify matches. | 511 // TODO(eroman): Export the SPKI and verify matches. |
| 514 } | 512 } |
| 515 } | 513 } |
| 516 | 514 |
| 517 } // namespace | 515 } // namespace |
| 518 | 516 |
| 519 } // namespace webcrypto | 517 } // namespace webcrypto |
| OLD | NEW |