google / guava

Google core libraries for Java
Apache License 2.0
50.25k stars 10.91k forks source link

[BaseEncoding] add option for strict decoding Base64 of "invalid" Base64 string #3705

Open sdoeringNew opened 5 years ago

sdoeringNew commented 5 years ago

The string "Base64" is strictly no valid Base64 string but decoding it with Guavas BaseEncoding utility does not fail because only the padding at the end is missing. This is the valid version of that string "Base64==" with correct padding.

And that is okay. Even Javas default Base64 decoder does not fail for that string. But e.g. Jacksons ObjectMapper fails:

Unexpected end of base64-encoded String: base64 variant 'MIME-NO-LINEFEEDS' expects padding (one or more '=' characters) at the end

Is it possible to add a config forcePaddingOnDecoding() to force a strictly valid Base64 string while decoding? That config would be in contrary to the encoding config omitPadding() that cuts the padding at the end of a Base64 string.

(Same for Base16, Base32, Base32Hex, Base64Url - of course.)

rajalohiy8 commented 4 years ago

Hi, I am new to open source. can I work on this?