mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
docs(std.base64): Add references to RFC 4648
There are multiple implementations of Base64, but `std.base64` appears to be based on RFC 4648, so we clarify that it is based on RFC 4648.
This commit is contained in:
parent
a7cfc23e5a
commit
f062ec2a1a
@ -1,4 +1,5 @@
|
|||||||
//! Base64 encoding/decoding.
|
//! Base64 encoding/decoding as specified by
|
||||||
|
//! [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648).
|
||||||
|
|
||||||
const std = @import("std.zig");
|
const std = @import("std.zig");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
@ -24,12 +25,15 @@ pub const Codecs = struct {
|
|||||||
Decoder: Base64Decoder,
|
Decoder: Base64Decoder,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The Base64 alphabet defined in
|
||||||
|
/// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
|
||||||
pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".*;
|
pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".*;
|
||||||
fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
|
fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
|
||||||
return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore);
|
return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Standard Base64 codecs, with padding
|
/// Standard Base64 codecs, with padding, as defined in
|
||||||
|
/// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
|
||||||
pub const standard = Codecs{
|
pub const standard = Codecs{
|
||||||
.alphabet_chars = standard_alphabet_chars,
|
.alphabet_chars = standard_alphabet_chars,
|
||||||
.pad_char = '=',
|
.pad_char = '=',
|
||||||
@ -38,7 +42,8 @@ pub const standard = Codecs{
|
|||||||
.Decoder = Base64Decoder.init(standard_alphabet_chars, '='),
|
.Decoder = Base64Decoder.init(standard_alphabet_chars, '='),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Standard Base64 codecs, without padding
|
/// Standard Base64 codecs, without padding, as defined in
|
||||||
|
/// [RFC 4648 section 3.2](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2).
|
||||||
pub const standard_no_pad = Codecs{
|
pub const standard_no_pad = Codecs{
|
||||||
.alphabet_chars = standard_alphabet_chars,
|
.alphabet_chars = standard_alphabet_chars,
|
||||||
.pad_char = null,
|
.pad_char = null,
|
||||||
@ -47,12 +52,15 @@ pub const standard_no_pad = Codecs{
|
|||||||
.Decoder = Base64Decoder.init(standard_alphabet_chars, null),
|
.Decoder = Base64Decoder.init(standard_alphabet_chars, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The URL-safe Base64 alphabet defined in
|
||||||
|
/// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
|
||||||
pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;
|
pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;
|
||||||
fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
|
fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
|
||||||
return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore);
|
return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// URL-safe Base64 codecs, with padding
|
/// URL-safe Base64 codecs, with padding, as defined in
|
||||||
|
/// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
|
||||||
pub const url_safe = Codecs{
|
pub const url_safe = Codecs{
|
||||||
.alphabet_chars = url_safe_alphabet_chars,
|
.alphabet_chars = url_safe_alphabet_chars,
|
||||||
.pad_char = '=',
|
.pad_char = '=',
|
||||||
@ -61,7 +69,8 @@ pub const url_safe = Codecs{
|
|||||||
.Decoder = Base64Decoder.init(url_safe_alphabet_chars, '='),
|
.Decoder = Base64Decoder.init(url_safe_alphabet_chars, '='),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// URL-safe Base64 codecs, without padding
|
/// URL-safe Base64 codecs, without padding, as defined in
|
||||||
|
/// [RFC 4648 section 3.2](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2).
|
||||||
pub const url_safe_no_pad = Codecs{
|
pub const url_safe_no_pad = Codecs{
|
||||||
.alphabet_chars = url_safe_alphabet_chars,
|
.alphabet_chars = url_safe_alphabet_chars,
|
||||||
.pad_char = null,
|
.pad_char = null,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user