Skip to content

Commit

Permalink
Merge pull request AntelopeIO#1892 from AntelopeIO/AntelopeIOGH-1461-…
Browse files Browse the repository at this point in the history
…base64-4.0

[3.2 -> 4.0] Do not require trailing `=` for base64 encoded strings
  • Loading branch information
heifner authored Nov 13, 2023
2 parents dd4217f + 78181c4 commit e41fbb7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libraries/libfc/src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,14 @@ blob variant::as_blob()const
{
const string& str = get_string();
if( str.size() == 0 ) return blob();
if( str.back() == '=' )
{
std::string b64 = base64_decode( get_string() );
try {
// variant adds `=` to end of base64 encoded string (see as_string() above) which produces invalid base64
// variant in 5.0 no longer appends the '=' character to conform to valid base64 encoding
// fc version of base64_decode allows for extra `=` at the end of the string
std::string b64 = base64_decode( str );
return blob( { std::vector<char>( b64.begin(), b64.end() ) } );
} catch(const std::exception&) {
// unable to decode, return raw chars
}
return blob( { std::vector<char>( str.begin(), str.end() ) } );
}
Expand Down

0 comments on commit e41fbb7

Please sign in to comment.