pub struct Base64Codec { /* private fields */ }Expand description
Encodes and decodes Base64 byte strings.
This facade intentionally remains a whole-value codec backed by the
base64 crate. Final partial quantum handling and optional = padding are
facade/transcoder responsibilities, not part of the low-level quantum codec.
Decoding is strict: each constructor accepts only its configured alphabet
and padding policy, rejects whitespace and non-canonical trailing bits, and
does not permit padded and unpadded partial groups to be interchanged.
Complete three-byte groups such as TWFu need no = and are accepted by
both padding policies.
§Examples
use qubit_codec_misc::Base64Codec;
let codec = Base64Codec::standard();
assert_eq!(codec.encode(b"hello"), "aGVsbG8=");Implementations§
Source§impl Base64Codec
impl Base64Codec
Sourcepub fn standard() -> Self
pub fn standard() -> Self
Creates a standard Base64 codec that requires canonical padding for a
partial final group. Complete groups need no =.
§Returns
Standard Base64 codec.
Sourcepub fn standard_no_pad() -> Self
pub fn standard_no_pad() -> Self
Creates a standard Base64 codec that rejects padding and accepts unpadded partial final groups.
§Returns
Standard no-padding Base64 codec.
Sourcepub fn url_safe() -> Self
pub fn url_safe() -> Self
Creates a URL-safe Base64 codec that requires canonical padding for a
partial final group. Complete groups need no =.
§Returns
URL-safe Base64 codec.
Sourcepub fn url_safe_no_pad() -> Self
pub fn url_safe_no_pad() -> Self
Creates a URL-safe Base64 codec that rejects padding and accepts unpadded partial final groups.
§Returns
URL-safe no-padding Base64 codec.
Sourcepub fn decode(&self, text: &str) -> MiscCodecResult<Vec<u8>>
pub fn decode(&self, text: &str) -> MiscCodecResult<Vec<u8>>
Decodes Base64 text into bytes.
§Parameters
text: Base64 text.
§Returns
Decoded bytes.
§Errors
Returns MiscCodecError::InvalidBase64 when text uses another
alphabet, violates this codec’s padding policy, contains whitespace, or
has non-canonical trailing bits.