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.
Sourcepub fn encoder(&self) -> Base64Encoder
pub fn encoder(&self) -> Base64Encoder
Creates an independent encoder with this codec’s configuration.
The returned encoder does not borrow this codec, uses fixed-size state, and must be reset before streaming.
§Returns
An independent streaming encoder with the same alphabet and padding policy.
Sourcepub fn decoder(&self) -> Base64Decoder
pub fn decoder(&self) -> Base64Decoder
Creates an independent decoder with this codec’s configuration.
The returned decoder does not borrow this codec, uses fixed-size state, and must be reset before streaming.
§Returns
An independent streaming decoder with the same alphabet and padding policy.
Trait Implementations§
Source§impl Clone for Base64Codec
impl Clone for Base64Codec
impl Copy for Base64Codec
Source§impl Debug for Base64Codec
impl Debug for Base64Codec
Source§impl Default for Base64Codec
impl Default for Base64Codec
impl Eq for Base64Codec
Source§impl PartialEq for Base64Codec
impl PartialEq for Base64Codec
Source§impl ValueDecoder<str> for Base64Codec
impl ValueDecoder<str> for Base64Codec
Source§type Error = MiscCodecError
type Error = MiscCodecError
Decoding failures are reported as Base64 codec errors.
Source§fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
Decodes Base64 text into bytes using this codec’s alphabet and padding policy.
§Parameters
input: Base64 text to decode.
§Returns
Decoded bytes.
§Errors
Returns MiscCodecError::InvalidBase64 when the input is malformed
or violates this codec’s alphabet or padding policy.
Source§impl ValueEncoder<[u8]> for Base64Codec
impl ValueEncoder<[u8]> for Base64Codec
Source§type Error = MiscCodecError
type Error = MiscCodecError
The encoding operation is infallible for byte slices.