use base64::engine::{DecodePaddingMode, GeneralPurpose as Base64Engine, GeneralPurposeConfig}; use base64::{alphabet, Engine}; pub use base64::DecodeError; /// Don't add padding when encoding, and require no padding when decoding. pub const ENGINE: Base64Engine = Base64Engine::new( &alphabet::STANDARD, GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent), ); pub fn encode(data: T) -> String where T: AsRef<[u8]>, { ENGINE.encode(data) } pub fn decode(data: T) -> Result, DecodeError> where T: AsRef<[u8]>, { ENGINE.decode(data) }