NSData Base64 Encoding Features Need URL Support

Originator:justatheory
Number:rdar://30588232 Date Originated:2017-02-17
Status:Open Resolved:
Product:Foundation Product Version:
Classification:Feature Reproducible:Always
 
Area:
Foundation

Summary:
A variant of Base64 encoding is Base64-URL encoding, wherein the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '_'. Many variants also omit the padding '=' characters to avoid them being confused with field separators. It'd be lovely to have NSDataBase64DecodingOptions and NSDataBase64EncodingOptions options to support these features.

Perhaps add NSDataBase64DecodingAddPadding and NSDataBase64DecodingURLVariant to NSDataBase64DecodingOptions, and add NSDataBase64EncodingOmitPadding and NSDataBase64EncodingURLFormat to NSDataBase64EncodingOptions

Steps to Reproduce:
1. Encode 0xF8 in Base64 URL format. Should be "-A" but comes out as "+A=="
1. Encode 0xFC in Base64 URL format. Should be "_A" but comes out as "/A=="
1. Try to decode "-A" or "_A". Will fail.

Expected Results:
Should be able to encode and decode base64 URL format.

Actual Results:
NSData includes support only for Base64 encoding, not the Base64 URL variant.

Version:
iOS 7.0+, macOS 10.9+

Notes:


Configuration:
iOS & macOS

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!