Skip to content

Support for rejecting non-canonical encodings #24

Closed
@emilypi

Description

@emilypi

Consider the following Base64-encoded string: "ZE==". What is the correct result of decoding the string "ZE=="?

Answer: It is not valid Base64, but it still satisfies the decoder's understanding of Base64 encoded data. Unfortunately, there is no way to construct such a result from binary, which leads to confusion - the decoder in base64-bytestring is not smart enough to differentiate such data. In fact, this value never round trips:

П> decode "ZE=="
Right "d"
П> encode "d"
"ZA=="
П> fmap encode (decode "ZE==")
Right "ZA=="

A more correct implementation should fail with an "invalid input" error. Or we can leave it as is and leave a note about the support status for "impossible by construction" inputs to the decoder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bikesheddingenhancementenhance semantics of existing code, or add feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions