Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: base/base32.cc

Issue 2547863002: Move base32 into base so that it can be used within base.
Patch Set: sync to position 437832 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/base32.h ('k') | base/base32_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/base32/base32.h" 5 #include "base/base32.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace base32 { 13 namespace base {
14 14
15 namespace { 15 namespace {
16 constexpr char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; 16 constexpr char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
17 } // namespace 17 } // namespace
18 18
19 std::string Base32Encode(base::StringPiece input, Base32EncodePolicy policy) { 19 std::string Base32Encode(StringPiece input, Base32EncodePolicy policy) {
20 if (input.empty()) 20 if (input.empty())
21 return std::string(); 21 return std::string();
22 22
23 if (input.size() > std::numeric_limits<size_t>::max() / 8) { 23 if (input.size() > std::numeric_limits<size_t>::max() / 8) {
24 NOTREACHED() 24 NOTREACHED()
25 << "Input is too large and would overflow encoded size computation."; 25 << "Input is too large and would overflow encoded size computation.";
26 return std::string(); 26 return std::string();
27 } 27 }
28 28
29 // Per RFC4648, the output is formed of 8 characters per 40 bits of input and 29 // Per RFC4648, the output is formed of 8 characters per 40 bits of input and
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 if (policy == Base32EncodePolicy::INCLUDE_PADDING) { 67 if (policy == Base32EncodePolicy::INCLUDE_PADDING) {
68 output.append(padded_length - unpadded_length, '='); 68 output.append(padded_length - unpadded_length, '=');
69 } 69 }
70 70
71 DCHECK_EQ(encoded_length, output.size()); 71 DCHECK_EQ(encoded_length, output.size());
72 return output; 72 return output;
73 } 73 }
74 74
75 } // namespace base32 75 } // namespace base
OLDNEW
« no previous file with comments | « base/base32.h ('k') | base/base32_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698