docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

core::encoding::base64

On this page

base64 (RFC 4648 sections 4 and 5). A Codec picks the alphabet and the padding policy; STANDARD is the default argument everywhere. Whitespace is not skipped.

Structs

CodecSource

pub struct Codec

An alphabet and a padding policy.

Enums

AlphabetSource

pub enum Alphabet

The 64 characters a codec writes.

  • Standard§

    Source

    A-Z a-z 0-9 + / (RFC 4648 section 4).

  • UrlSafe§

    Source

    A-Z a-z 0-9 - _, for URLs and file names (RFC 4648 section 5).

PaddingSource

pub enum Padding

The = padding policy: what encode writes and what decode takes.

  • Present§

    Source

    Encode pads; decode requires padding.

  • Absent§

    Source

    Encode does not pad; decode rejects padding.

  • PresentOptional§

    Source

    Encode pads; decode takes padded and unpadded text.

  • AbsentOptional§

    Source

    Encode does not pad; decode takes padded and unpadded text.

Functions

encoded_lenSource

pub const fn encoded_len(n: usize, codec: Codec = STANDARD) -> usize

The length of the text encode makes of n bytes.

decoded_len_maxSource

pub const fn decoded_len_max(n: usize) -> usize

The most bytes decode makes of n characters: enough room for decode_into.

encodeSource

pub fn encode<B: AsBytes>(data: B, codec: Codec = STANDARD) -> str

data in base64.

encode_intoSource

pub fn encode_into<B: AsBytes>(data: B, out: SliceMut<u8>, codec: Codec = STANDARD) -> usize

data in base64, written to the front of out; returns how many bytes it wrote. Panics if out is shorter than encoded_len.

decodeSource

pub fn decode<B: AsBytes>(text: B, codec: Codec = STANDARD) throws (DecodeError) -> List<u8>

The bytes text spells in base64.

decode_intoSource

pub fn decode_into<B: AsBytes>(text: B, out: SliceMut<u8>, codec: Codec = STANDARD) throws (DecodeError) -> usize

The bytes text spells in base64, written to the front of out; returns how many it wrote. Panics if out is shorter than decoded_len_max(text.len()) less what the padding saves.

Constants

STANDARDSource

pub const STANDARD: Codec = Codec { alphabet: Alphabet::Standard, padding: Padding::PresentOptional }

The standard alphabet; encode pads, decode takes either.

STANDARD_NO_PADSource

pub const STANDARD_NO_PAD: Codec = Codec { alphabet: Alphabet::Standard, padding: Padding::Absent }

The standard alphabet without padding.

URL_SAFESource

pub const URL_SAFE: Codec = Codec { alphabet: Alphabet::UrlSafe, padding: Padding::PresentOptional }

The URL-safe alphabet; encode pads, decode takes either.

URL_SAFE_NO_PADSource

pub const URL_SAFE_NO_PAD: Codec = Codec { alphabet: Alphabet::UrlSafe, padding: Padding::Absent }

The URL-safe alphabet without padding.