Skip to main content

Base64Codec

Struct Base64Codec 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn encode(&self, bytes: &[u8]) -> String

Encodes bytes into Base64 text.

§Parameters
  • bytes: Bytes to encode.
§Returns

Encoded Base64 text.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Base64Codec

Source§

impl Debug for Base64Codec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Base64Codec

Source§

fn default() -> Self

Creates a standard Base64 codec with padding.

Source§

impl Eq for Base64Codec

Source§

impl PartialEq for Base64Codec

Source§

fn eq(&self, other: &Self) -> bool

Compares codecs by their alphabet and padding configuration.

§Parameters
  • other: Codec configuration to compare with this one.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ValueDecoder<str> for Base64Codec

Source§

type Error = MiscCodecError

Decoding failures are reported as Base64 codec errors.

Source§

type Output = Vec<u8>

Decoded bytes.

Source§

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

Source§

type Error = MiscCodecError

The encoding operation is infallible for byte slices.

Source§

type Output = String

Encoded Base64 text.

Source§

fn encode(&mut self, input: &[u8]) -> Result<Self::Output, Self::Error>

Encodes bytes into Base64 text without a fallible operation.

§Parameters
  • input: Bytes to encode.
§Returns

Encoded Base64 text.

§Errors

This implementation does not return an error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.