Skip to content

Commit 5a8a30f

Browse files
committed
Added functionality to Base64 package
The Base64 package previously had extremely basic functionality. It only suported the standard encoding character set, didn't support line breaks and always padded output. This commit makes it significantly more powerful. The FromBase64 impl now supports all of the standard variants of Base64. It ignores newlines,interprets '-' and '_' as well as '+' and '/' and doesn't require padding. It isn't incredibly pedantic and will successfully parse strings that are not strictly valid, but I don't think the extra complexity required to make it accept _only_ valid strings is worth it. The ToBase64 trait has been modified such that to_base64 now takes a base64::Config struct which contains the output format configuration. This currently includes the selection of character set (standard or url safe), whether or not to pad and an optional line break width. The package comes with three static Config structs for the RFC 4648 standard, RFC 4648 url safe and RFC 2045 MIME formats. The other option for configuring ToBase64 output would be to have one method with the configuration flags passed and other traits with default impls for the common cases, but I think that's a little messier.
1 parent 3c0a162 commit 5a8a30f

File tree

1 file changed

+210
-121
lines changed

1 file changed

+210
-121
lines changed

0 commit comments

Comments
 (0)