1
- //! Base64 encoding/decoding.
1
+ //! Base64 encoding/decoding as specified by
2
+ //! [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648).
2
3
3
4
const std = @import ("std.zig" );
4
5
const assert = std .debug .assert ;
@@ -24,12 +25,15 @@ pub const Codecs = struct {
24
25
Decoder : Base64Decoder ,
25
26
};
26
27
28
+ /// The Base64 alphabet defined in
29
+ /// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
27
30
pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" .* ;
28
31
fn standardBase64DecoderWithIgnore (ignore : []const u8 ) Base64DecoderWithIgnore {
29
32
return Base64DecoderWithIgnore .init (standard_alphabet_chars , '=' , ignore );
30
33
}
31
34
32
- /// Standard Base64 codecs, with padding
35
+ /// Standard Base64 codecs, with padding, as defined in
36
+ /// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
33
37
pub const standard = Codecs {
34
38
.alphabet_chars = standard_alphabet_chars ,
35
39
.pad_char = '=' ,
@@ -38,7 +42,8 @@ pub const standard = Codecs{
38
42
.Decoder = Base64Decoder .init (standard_alphabet_chars , '=' ),
39
43
};
40
44
41
- /// Standard Base64 codecs, without padding
45
+ /// Standard Base64 codecs, without padding, as defined in
46
+ /// [RFC 4648 section 3.2](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2).
42
47
pub const standard_no_pad = Codecs {
43
48
.alphabet_chars = standard_alphabet_chars ,
44
49
.pad_char = null ,
@@ -47,12 +52,15 @@ pub const standard_no_pad = Codecs{
47
52
.Decoder = Base64Decoder .init (standard_alphabet_chars , null ),
48
53
};
49
54
55
+ /// The URL-safe Base64 alphabet defined in
56
+ /// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
50
57
pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" .* ;
51
58
fn urlSafeBase64DecoderWithIgnore (ignore : []const u8 ) Base64DecoderWithIgnore {
52
59
return Base64DecoderWithIgnore .init (url_safe_alphabet_chars , null , ignore );
53
60
}
54
61
55
- /// URL-safe Base64 codecs, with padding
62
+ /// URL-safe Base64 codecs, with padding, as defined in
63
+ /// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
56
64
pub const url_safe = Codecs {
57
65
.alphabet_chars = url_safe_alphabet_chars ,
58
66
.pad_char = '=' ,
@@ -61,7 +69,8 @@ pub const url_safe = Codecs{
61
69
.Decoder = Base64Decoder .init (url_safe_alphabet_chars , '=' ),
62
70
};
63
71
64
- /// URL-safe Base64 codecs, without padding
72
+ /// URL-safe Base64 codecs, without padding, as defined in
73
+ /// [RFC 4648 section 3.2](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2).
65
74
pub const url_safe_no_pad = Codecs {
66
75
.alphabet_chars = url_safe_alphabet_chars ,
67
76
.pad_char = null ,
0 commit comments