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 bool Base64DecodeUrlSafe(const std::string& input, std::string* output) { | |
708 std::string base64EncodedText(input); | |
Ryan Sleevi
2014/08/27 17:22:15
1) variable naming / style
2) This still seems to
eroman
2014/08/27 18:00:57
Good catch, Done.
| |
709 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+'); | |
710 std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/'); | |
711 base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '='); | |
712 return base::Base64Decode(base64EncodedText, output); | |
713 } | |
714 | |
715 std::string Base64EncodeUrlSafe(const base::StringPiece& input) { | |
716 std::string output; | |
717 base::Base64Encode(input, &output); | |
718 std::replace(output.begin(), output.end(), '+', '-'); | |
719 std::replace(output.begin(), output.end(), '/', '_'); | |
720 output.erase(std::remove(output.begin(), output.end(), '='), output.end()); | |
721 return output; | |
722 } | |
723 | |
724 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { | |
725 const base::StringPiece string_piece( | |
726 reinterpret_cast<const char*>(vector_as_array(&input)), input.size()); | |
727 return Base64EncodeUrlSafe(string_piece); | |
728 } | |
729 | |
705 } // namespace webcrypto | 730 } // namespace webcrypto |
706 | 731 |
707 } // namespace content | 732 } // namespace content |
OLD | NEW |