OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base64.h" | 5 #include "base/base64.h" |
6 | 6 |
| 7 #include "base/compiler_specific.h" |
| 8 |
| 9 MSVC_PUSH_DISABLE_WARNING(4267); |
7 #include "third_party/modp_b64/modp_b64.h" | 10 #include "third_party/modp_b64/modp_b64.h" |
| 11 MSVC_POP_WARNING(); |
8 | 12 |
9 namespace base { | 13 namespace base { |
10 | 14 |
11 bool Base64Encode(const StringPiece& input, std::string* output) { | 15 bool Base64Encode(const StringPiece& input, std::string* output) { |
12 std::string temp; | 16 std::string temp; |
13 temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte | 17 temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte |
14 | 18 |
15 // null terminates result since result is base64 text! | 19 // null terminates result since result is base64 text! |
16 int input_size = static_cast<int>(input.size()); | 20 int input_size = static_cast<int>(input.size()); |
17 | 21 |
(...skipping 16 matching lines...) Expand all Loading... |
34 int output_size = modp_b64_decode(&(temp[0]), input.data(), input_size); | 38 int output_size = modp_b64_decode(&(temp[0]), input.data(), input_size); |
35 if (output_size < 0) | 39 if (output_size < 0) |
36 return false; | 40 return false; |
37 | 41 |
38 temp.resize(output_size); | 42 temp.resize(output_size); |
39 output->swap(temp); | 43 output->swap(temp); |
40 return true; | 44 return true; |
41 } | 45 } |
42 | 46 |
43 } // namespace base | 47 } // namespace base |
OLD | NEW |