Skip to content

Commit

Permalink
Merge pull request #1889 from AntelopeIO/GH-1461-base64-3.2
Browse files Browse the repository at this point in the history
[3.2] Do not require trailing `=` for base64 encoded strings
  • Loading branch information
heifner authored Nov 13, 2023
2 parents 27f6bdf + bce1b0b commit 8a9d841
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 8a9d841

Please sign in to comment.