haskell / base64-bytestring

Fast base64 encoding and decoding for Haskell.
http://hackage.haskell.org/package/base64-bytestring
Other
45 stars 28 forks source link

Add support for base64url with no padding #18

Closed dcoutts closed 4 years ago

dcoutts commented 9 years ago

RFC4648 Section 3.2:

Padding of Encoded Data

In some circumstances, the use of padding ("=") in base-encoded data is not required or used. In the general case, when assumptions about the size of transported data cannot be made, padding is required to yield correct decoded data.

Implementations MUST include appropriate pad characters at the end of encoded data unless the specification referring to this document explicitly states otherwise.

As an example of such a specification is RFC7049 (section 2.4.4.2) which has this little snippet:

These three tag types suggest conversions to three of the base data encodings defined in [RFC4648]. For base64url encoding, padding is not used (see Section 3.2 of RFC 4648); that is, all trailing equals signs ("=") are removed from the base64url-encoded string.

So to support such specifications it would be convenient for the Base64.URL modules to provide variants of encode and decode that produce and expect no padding. It's actually especially useful to have the decoder variant since working around the lack of direct support on the encode side is easy, but adding back the correct amount of padding is more involved and expensive.

andrewthad commented 8 years ago

This would also be a useful feature for my purposes as well.

cartazio commented 8 years ago

https://github.com/EButlerIV/u2f/blob/master/src/U2F.hs#L180-L183 might be related?

23Skidoo commented 5 years ago

PRs welcome.

23Skidoo commented 4 years ago

Fixed by #26.