Skip to content

Commit 3d7c1dd

Browse files
committed
auto merge of #7513 : sfackler/rust/master, r=msullivan
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. FromBase64 still kills the task if you pass it invalid input, which isn't particularly appropriate for a function into which you'll be passing unvalidated input. Would it be worth changing its signature to return a Result?
2 parents e07e9bb + e9988c1 commit 3d7c1dd

File tree

1 file changed

+233
-121
lines changed

1 file changed

+233
-121
lines changed

0 commit comments

Comments
 (0)