| ... | ... | @@ -31,6 +31,9 @@ pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq |
| 31 | 31 | fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { |
| 32 | 32 | return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore); |
| 33 | 33 | } |
| 34 | fn standardNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { |
| 35 | return Base64DecoderWithIgnore.init(standard_alphabet_chars, null, ignore); |
| 36 | } |
| 34 | 37 | |
| 35 | 38 | /// Standard Base64 codecs, with padding, as defined in |
| 36 | 39 | /// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4). |
| ... | ... | @@ -47,7 +50,7 @@ pub const standard = Codecs{ |
| 47 | 50 | pub const standard_no_pad = Codecs{ |
| 48 | 51 | .alphabet_chars = standard_alphabet_chars, |
| 49 | 52 | .pad_char = null, |
| 50 | | .decoderWithIgnore = standardBase64DecoderWithIgnore, |
| 53 | .decoderWithIgnore = standardNoPadBase64DecoderWithIgnore, |
| 51 | 54 | .Encoder = Base64Encoder.init(standard_alphabet_chars, null), |
| 52 | 55 | .Decoder = Base64Decoder.init(standard_alphabet_chars, null), |
| 53 | 56 | }; |
| ... | ... | @@ -56,6 +59,9 @@ pub const standard_no_pad = Codecs{ |
| 56 | 59 | /// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5). |
| 57 | 60 | pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; |
| 58 | 61 | fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { |
| 62 | return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, '=', ignore); |
| 63 | } |
| 64 | fn urlSafeNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { |
| 59 | 65 | return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore); |
| 60 | 66 | } |
| 61 | 67 | |
| ... | ... | @@ -74,7 +80,7 @@ pub const url_safe = Codecs{ |
| 74 | 80 | pub const url_safe_no_pad = Codecs{ |
| 75 | 81 | .alphabet_chars = url_safe_alphabet_chars, |
| 76 | 82 | .pad_char = null, |
| 77 | | .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, |
| 83 | .decoderWithIgnore = urlSafeNoPadBase64DecoderWithIgnore, |
| 78 | 84 | .Encoder = Base64Encoder.init(url_safe_alphabet_chars, null), |
| 79 | 85 | .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null), |
| 80 | 86 | }; |
| ... | ... | @@ -401,6 +407,20 @@ test "base64 url_safe_no_pad" { |
| 401 | 407 | try comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU"); |
| 402 | 408 | } |
| 403 | 409 | |
| 410 | test "base64 standard_no_pad" { |
| 411 | @setEvalBranchQuota(8000); |
| 412 | try testAllApis(standard_no_pad, "f", "Zg"); |
| 413 | try comptime testAllApis(standard_no_pad, "comptime", "Y29tcHRpbWU"); |
| 414 | try testError(standard_no_pad, "Zg==", error.InvalidCharacter); |
| 415 | } |
| 416 | |
| 417 | test "base64 url_safe" { |
| 418 | @setEvalBranchQuota(8000); |
| 419 | try testAllApis(url_safe, "f", "Zg=="); |
| 420 | try comptime testAllApis(url_safe, "comptime", "Y29tcHRpbWU="); |
| 421 | try testError(url_safe, "Zg", error.InvalidPadding); |
| 422 | } |
| 423 | |
| 404 | 424 | fn testBase64() !void { |
| 405 | 425 | const codecs = standard; |
| 406 | 426 | |