pub struct GeneralPurposeConfig { /* private fields */ }
Expand description

Contains configuration parameters for base64 encoding and decoding.

let config = GeneralPurposeConfig::new()
    .with_encode_padding(false);
    // further customize using `.with_*` methods as needed

The constants PAD and NO_PAD cover most use cases.

To specify the characters used, see Alphabet.

Implementations§

source§

impl GeneralPurposeConfig

source

pub const fn new() -> Self

Create a new config with padding = true, decode_allow_trailing_bits = false, and decode_padding_mode = DecodePaddingMode::RequireCanonicalPadding.

This probably matches most people’s expectations, but consider disabling padding to save a few bytes unless you specifically need it for compatibility with some legacy system.

source

pub const fn with_encode_padding(self, padding: bool) -> Self

Create a new config based on self with an updated padding setting.

If padding is true, encoding will append either 1 or 2 = padding characters as needed to produce an output whose length is a multiple of 4.

Padding is not needed for correct decoding and only serves to waste bytes, but it’s in the spec.

For new applications, consider not using padding if the decoders you’re using don’t require padding to be present.

source

pub const fn with_decode_allow_trailing_bits(self, allow: bool) -> Self

Create a new config based on self with an updated decode_allow_trailing_bits setting.

Most users will not need to configure this. It’s useful if you need to decode base64 produced by a buggy encoder that has bits set in the unused space on the last base64 character as per forgiving-base64 decode. If invalid trailing bits are present and this is true, those bits will be silently ignored, else DecodeError::InvalidLastSymbol will be emitted.

source

pub const fn with_decode_padding_mode(self, mode: DecodePaddingMode) -> Self

Create a new config based on self with an updated decode_padding_mode setting.

Padding is not useful in terms of representing encoded data – it makes no difference to the decoder if padding is present or not, so if you have some un-padded input to decode, it is perfectly fine to use DecodePaddingMode::Indifferent to prevent errors from being emitted.

However, since in practice people who learned nothing from BER vs DER seem to expect base64 to have one canonical encoding, the default setting is the stricter DecodePaddingMode::RequireCanonicalPadding.

Or, if “canonical” in your circumstance means no padding rather than padding to the next multiple of four, there’s DecodePaddingMode::RequireNoPadding.

Trait Implementations§

source§

impl Clone for GeneralPurposeConfig

source§

fn clone(&self) -> GeneralPurposeConfig

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Config for GeneralPurposeConfig

source§

fn encode_padding(&self) -> bool

Returns true if padding should be added after the encoded output. Read more
source§

impl Debug for GeneralPurposeConfig

source§

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

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

impl Default for GeneralPurposeConfig

source§

fn default() -> Self

source§

impl Copy for GeneralPurposeConfig

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.