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 "jwk.h" | 5 #include "jwk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 | 10 |
| 11 #include "base/base64.h" |
11 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/stl_util.h" |
13 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
14 #include "content/child/webcrypto/crypto_data.h" | 16 #include "content/child/webcrypto/crypto_data.h" |
15 #include "content/child/webcrypto/status.h" | 17 #include "content/child/webcrypto/status.h" |
16 #include "content/child/webcrypto/webcrypto_util.h" | 18 #include "content/child/webcrypto/webcrypto_util.h" |
17 | 19 |
18 // TODO(eroman): The algorithm-specific logic in this file for AES and RSA | 20 // TODO(eroman): The algorithm-specific logic in this file for AES and RSA |
19 // should be moved into the corresponding AlgorithmImplementation file. It | 21 // should be moved into the corresponding AlgorithmImplementation file. It |
20 // exists in this file to avoid duplication between OpenSSL and NSS | 22 // exists in this file to avoid duplication between OpenSSL and NSS |
21 // implementations. | 23 // implementations. |
22 | 24 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 return "HS256"; | 697 return "HS256"; |
696 case blink::WebCryptoAlgorithmIdSha384: | 698 case blink::WebCryptoAlgorithmIdSha384: |
697 return "HS384"; | 699 return "HS384"; |
698 case blink::WebCryptoAlgorithmIdSha512: | 700 case blink::WebCryptoAlgorithmIdSha512: |
699 return "HS512"; | 701 return "HS512"; |
700 default: | 702 default: |
701 return NULL; | 703 return NULL; |
702 } | 704 } |
703 } | 705 } |
704 | 706 |
| 707 // TODO(eroman): This accepts invalid inputs. http://crbug.com/378034 |
| 708 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { |
| 709 std::string base64_encoded_text(input); |
| 710 std::replace( |
| 711 base64_encoded_text.begin(), base64_encoded_text.end(), '-', '+'); |
| 712 std::replace( |
| 713 base64_encoded_text.begin(), base64_encoded_text.end(), '_', '/'); |
| 714 base64_encoded_text.append((4 - base64_encoded_text.size() % 4) % 4, '='); |
| 715 return base::Base64Decode(base64_encoded_text, output); |
| 716 } |
| 717 |
| 718 std::string Base64EncodeUrlSafe(const base::StringPiece& input) { |
| 719 std::string output; |
| 720 base::Base64Encode(input, &output); |
| 721 std::replace(output.begin(), output.end(), '+', '-'); |
| 722 std::replace(output.begin(), output.end(), '/', '_'); |
| 723 output.erase(std::remove(output.begin(), output.end(), '='), output.end()); |
| 724 return output; |
| 725 } |
| 726 |
| 727 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { |
| 728 const base::StringPiece string_piece( |
| 729 reinterpret_cast<const char*>(vector_as_array(&input)), input.size()); |
| 730 return Base64EncodeUrlSafe(string_piece); |
| 731 } |
| 732 |
705 } // namespace webcrypto | 733 } // namespace webcrypto |
706 | 734 |
707 } // namespace content | 735 } // namespace content |
OLD | NEW |