Skip to content

Commit d77f8af

Browse files
authored
Merge pull request #512 from dcangulo/base64
chore: bump base64 from 2.rc.08 to 2.rc.09
2 parents 0ecfa91 + 1bceffd commit d77f8af

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cpp/base64.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
More information at
66
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
77
8-
Version: 2.rc.08 (release candidate)
8+
Version: 2.rc.09 (release candidate)
99
10-
Copyright (C) 2004-2017, 2020, 2021 René Nyffenegger
10+
Copyright (C) 2004-2017, 2020-2022 René Nyffenegger
1111
1212
This source code is provided 'as-is', without any express or implied
1313
warranty. In no event will the author be held liable for any damages
@@ -160,7 +160,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, size_t in_len, b
160160
}
161161

162162
template <typename String>
163-
static std::string decode(String encoded_string, bool remove_linebreaks) {
163+
static std::string decode(String const& encoded_string, bool remove_linebreaks) {
164164
//
165165
// decode(…) is templated so that it can be used with String = const std::string&
166166
// or std::string_view (requires at least C++17)
@@ -204,33 +204,33 @@ static std::string decode(String encoded_string, bool remove_linebreaks) {
204204
// The last chunk produces at least one and up to three bytes.
205205
//
206206

207-
size_t pos_of_char_1 = pos_of_char(encoded_string[pos+1] );
207+
size_t pos_of_char_1 = pos_of_char(encoded_string.at(pos+1) );
208208

209209
//
210210
// Emit the first output byte that is produced in each chunk:
211211
//
212-
ret.push_back(static_cast<std::string::value_type>( ( (pos_of_char(encoded_string[pos+0]) ) << 2 ) + ( (pos_of_char_1 & 0x30 ) >> 4)));
212+
ret.push_back(static_cast<std::string::value_type>( ( (pos_of_char(encoded_string.at(pos+0)) ) << 2 ) + ( (pos_of_char_1 & 0x30 ) >> 4)));
213213

214214
if ( ( pos + 2 < length_of_string ) && // Check for data that is not padded with equal signs (which is allowed by RFC 2045)
215-
encoded_string[pos+2] != '=' &&
216-
encoded_string[pos+2] != '.' // accept URL-safe base 64 strings, too, so check for '.' also.
215+
encoded_string.at(pos+2) != '=' &&
216+
encoded_string.at(pos+2) != '.' // accept URL-safe base 64 strings, too, so check for '.' also.
217217
)
218218
{
219219
//
220220
// Emit a chunk's second byte (which might not be produced in the last chunk).
221221
//
222-
unsigned int pos_of_char_2 = pos_of_char(encoded_string[pos+2] );
222+
unsigned int pos_of_char_2 = pos_of_char(encoded_string.at(pos+2) );
223223
ret.push_back(static_cast<std::string::value_type>( (( pos_of_char_1 & 0x0f) << 4) + (( pos_of_char_2 & 0x3c) >> 2)));
224224

225225
if ( ( pos + 3 < length_of_string ) &&
226-
encoded_string[pos+3] != '=' &&
227-
encoded_string[pos+3] != '.'
226+
encoded_string.at(pos+3) != '=' &&
227+
encoded_string.at(pos+3) != '.'
228228
)
229229
{
230230
//
231231
// Emit a chunk's third byte (which might not be produced in the last chunk).
232232
//
233-
ret.push_back(static_cast<std::string::value_type>( ( (pos_of_char_2 & 0x03 ) << 6 ) + pos_of_char(encoded_string[pos+3]) ));
233+
ret.push_back(static_cast<std::string::value_type>( ( (pos_of_char_2 & 0x03 ) << 6 ) + pos_of_char(encoded_string.at(pos+3)) ));
234234
}
235235
}
236236

cpp/base64.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// base64 encoding and decoding with C++.
3-
// Version: 2.rc.08 (release candidate)
3+
// Version: 2.rc.09 (release candidate)
44
//
55

66
#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A

0 commit comments

Comments
 (0)