#![no_std]
#![cfg_attr(all(test, feature = "nightly"), feature(test))]
extern crate alloc;
#[cfg(any(test, feature = "std"))]
#[allow(unused_imports)]
#[macro_use]
extern crate std;
#[cfg(all(test, feature = "nightly"))]
extern crate test;
#[cfg(test)]
#[macro_use]
mod test_support;
#[macro_use]
mod misc;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod avx2;
mod lut_align64;
mod decode;
mod encode;
use alloc::{string::String, vec::Vec};
pub use self::CharacterSet::*;
#[derive(Clone, Copy, Debug)]
pub enum CharacterSet {
Standard,
UrlSafe,
}
#[derive(Clone, Copy, Debug)]
pub enum Newline {
LF,
CRLF,
}
#[derive(Clone, Copy, Debug)]
pub struct Config {
pub char_set: CharacterSet,
pub newline: Newline,
pub pad: bool,
pub line_length: Option<usize>,
}
pub static STANDARD: Config = Config {
char_set: Standard,
newline: Newline::CRLF,
pad: true,
line_length: None,
};
pub static URL_SAFE: Config = Config {
char_set: UrlSafe,
newline: Newline::CRLF,
pad: false,
line_length: None,
};
pub static MIME: Config = Config {
char_set: Standard,
newline: Newline::CRLF,
pad: true,
line_length: Some(76),
};
pub trait ToBase64 {
fn to_base64(&self, config: Config) -> String;
}
impl ToBase64 for [u8] {
fn to_base64(&self, config: Config) -> String {
encode::encode64_arch(self, config)
}
}
impl<'a, T: ?Sized + ToBase64> ToBase64 for &'a T {
fn to_base64(&self, config: Config) -> String {
(**self).to_base64(config)
}
}
#[doc(inline)]
pub use decode::Error as FromBase64Error;
pub trait FromBase64 {
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error>;
}
impl FromBase64 for str {
#[inline]
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
self.as_bytes().from_base64()
}
}
impl FromBase64 for [u8] {
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
decode::decode64_arch(self)
}
}
impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T {
fn from_base64(&self) -> Result<Vec<u8>, FromBase64Error> {
(**self).from_base64()
}
}