Skip to main content

Crate pw_base64

Crate pw_base64 

Source
Expand description

pw_base64 provides simple encoding of data into base64.

const INPUT: &'static [u8] = "I ๐Ÿ’– Pigweed".as_bytes();

// [`encoded_size`] can be used to calculate the size of the output buffer.
let mut output = [0u8; pw_base64::encoded_size(INPUT.len())];

// Data can be encoded to a `&mut [u8]`.
let output_size = pw_base64::encode(INPUT, &mut output).unwrap();
assert_eq!(&output[0..output_size], b"SSDwn5KWIFBpZ3dlZWQ=");

// The output buffer can also be automatically converted to a `&str`.
let output_str = pw_base64::encode_str(INPUT, &mut output).unwrap();
assert_eq!(output_str, "SSDwn5KWIFBpZ3dlZWQ=");

Functionsยง

decode
Decodes the provided Base64 data into raw binary.
decoded_size
Returns the exact size of the decoded output for a valid Base64 string.
encode
Encode input as base64 into the output_buffer.
encode_str
Encode input as base64 into output_buffer and interprets it as a string.
encoded_size
Returns the size of the output buffer needed to encode an input buffer of size input_size.
is_valid
Returns true if the provided data is valid Base64.
is_valid_char
Returns true if the provided character is a valid Base64 character.
max_decoded_size
Returns the maximum size of the decoded output for a given encoded size.