Skip to main content

Base64Codec

Struct Base64Codec 

Source
pub struct Base64Codec {
    pub encode: bool,
    pub columns: usize,
    pub carry: u8,
    pub position: usize,
    pub line_position: usize,
    pub finished: bool,
}
Expand description

Plain state of one Base64 stream, restorable between successful calls.

Each call checks the state before reading input or writing output. The fields describe a logical state, with no Rust or C layout guarantee.

Fields§

§encode: bool

True for encoding and false for decoding.

§columns: usize

Encoded line width, or zero for a single line. Ignored by the decoder.

§carry: u8

Previous input byte (encoding) or sextet (decoding).

§position: usize

Bytes carried by the encoder or characters seen in the decoder group.

§line_position: usize

Number of characters on the current encoded line. Zero for decoding.

§finished: bool

The stream has finished, or the decoder has started reading padding.

Implementations§

Source§

impl Base64Codec

Source

pub const fn new(encode: bool, columns: usize) -> Self

Start a stream with the specified direction and encoded line width.

Source

pub fn encoded_capacity(columns: usize, size: usize) -> Option<usize>

Upper bound for encoding a chunk and finalizing, including spare room for a caller’s terminator. Returns None on arithmetic overflow.

Source

pub fn decoded_capacity(size: usize) -> Option<usize>

Upper bound for decoding a chunk, including spare room to consume padding. Returns None on arithmetic overflow.

Source

pub fn update( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, Base64Error>

Consume all input and return the number of output bytes written.

After an error, discard the stream and any output from this call. A successful call can be followed by another with a different slice.

§Errors

Returns Base64Error::Invalid for invalid input or state, or Base64Error::OutputFull when the output has insufficient space.

Source

pub fn finish(&mut self, output: &mut [u8]) -> Result<usize, Base64Error>

Complete the stream, writing any final encoded characters and padding.

A nonempty output slice is required. Encoding leaves one spare byte for the caller. Decoding returns zero and rejects an incomplete group. After an error, discard the stream and any output from this call. A successful call closes the stream.

§Errors

Returns Base64Error::Invalid for invalid state, Base64Error::OutputFull when the output has insufficient space, or Base64Error::Truncated for an incomplete decoder group.

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 Eq for Base64Codec

Source§

impl PartialEq for Base64Codec

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Base64Codec

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, 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.