| ... | @@ -39,13 +39,33 @@ pub const standard = Codecs{ | ... | @@ -39,13 +39,33 @@ pub const standard = Codecs{ |
| 39 | .DecoderUnsafe = Base64DecoderUnsafe.init(standard_alphabet_chars, '='), | 39 | .DecoderUnsafe = Base64DecoderUnsafe.init(standard_alphabet_chars, '='), |
| 40 | }; | 40 | }; |
| 41 | | 41 | |
| | 42 | /// Standard Base64 codecs, without padding |
| | 43 | pub const standard_no_pad = Codecs{ |
| | 44 | .alphabet_chars = standard_alphabet_chars, |
| | 45 | .pad_char = null, |
| | 46 | .decoderWithIgnore = standardBase64DecoderWithIgnore, |
| | 47 | .Encoder = Base64Encoder.init(standard_alphabet_chars, null), |
| | 48 | .Decoder = Base64Decoder.init(standard_alphabet_chars, null), |
| | 49 | .DecoderUnsafe = Base64DecoderUnsafe.init(standard_alphabet_chars, null), |
| | 50 | }; |
| | 51 | |
| 42 | pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; | 52 | pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; |
| 43 | fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { | 53 | fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { |
| 44 | return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore); | 54 | return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore); |
| 45 | } | 55 | } |
| 46 | | 56 | |
| 47 | /// URL-safe Base64 codecs, without padding | 57 | /// URL-safe Base64 codecs, with padding |
| 48 | pub const url_safe = Codecs{ | 58 | pub const url_safe = Codecs{ |
| | 59 | .alphabet_chars = url_safe_alphabet_chars, |
| | 60 | .pad_char = '=', |
| | 61 | .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, |
| | 62 | .Encoder = Base64Encoder.init(url_safe_alphabet_chars, '='), |
| | 63 | .Decoder = Base64Decoder.init(url_safe_alphabet_chars, '='), |
| | 64 | .DecoderUnsafe = Base64DecoderUnsafe.init(url_safe_alphabet_chars, '='), |
| | 65 | }; |
| | 66 | |
| | 67 | /// URL-safe Base64 codecs, without padding |
| | 68 | pub const url_safe_no_pad = Codecs{ |
| 49 | .alphabet_chars = url_safe_alphabet_chars, | 69 | .alphabet_chars = url_safe_alphabet_chars, |
| 50 | .pad_char = null, | 70 | .pad_char = null, |
| 51 | .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, | 71 | .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, |
| ... | @@ -378,10 +398,10 @@ test "base64" { | ... | @@ -378,10 +398,10 @@ test "base64" { |
| 378 | comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable; | 398 | comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable; |
| 379 | } | 399 | } |
| 380 | | 400 | |
| 381 | test "base64 url_safe" { | 401 | test "base64 url_safe_no_pad" { |
| 382 | @setEvalBranchQuota(8000); | 402 | @setEvalBranchQuota(8000); |
| 383 | testBase64UrlSafe() catch unreachable; | 403 | testBase64UrlSafeNoPad() catch unreachable; |
| 384 | comptime testAllApis(url_safe, "comptime", "Y29tcHRpbWU") catch unreachable; | 404 | comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable; |
| 385 | } | 405 | } |
| 386 | | 406 | |
| 387 | fn testBase64() !void { | 407 | fn testBase64() !void { |
| ... | @@ -420,8 +440,8 @@ fn testBase64() !void { | ... | @@ -420,8 +440,8 @@ fn testBase64() !void { |
| 420 | try testNoSpaceLeftError(codecs, "AAAAAA=="); | 440 | try testNoSpaceLeftError(codecs, "AAAAAA=="); |
| 421 | } | 441 | } |
| 422 | | 442 | |
| 423 | fn testBase64UrlSafe() !void { | 443 | fn testBase64UrlSafeNoPad() !void { |
| 424 | const codecs = url_safe; | 444 | const codecs = url_safe_no_pad; |
| 425 | | 445 | |
| 426 | try testAllApis(codecs, "", ""); | 446 | try testAllApis(codecs, "", ""); |
| 427 | try testAllApis(codecs, "f", "Zg"); | 447 | try testAllApis(codecs, "f", "Zg"); |