23 lines
590 B
Rust
23 lines
590 B
Rust
|
use base64::engine::{DecodePaddingMode, GeneralPurpose as Base64Engine, GeneralPurposeConfig};
|
||
|
use base64::{alphabet, DecodeError, Engine};
|
||
|
|
||
|
/// 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<T>(data: T) -> String
|
||
|
where
|
||
|
T: AsRef<[u8]>,
|
||
|
{
|
||
|
ENGINE.encode(data)
|
||
|
}
|
||
|
|
||
|
pub fn decode<T>(data: T) -> Result<Vec<u8>, DecodeError>
|
||
|
where
|
||
|
T: AsRef<[u8]>,
|
||
|
{
|
||
|
ENGINE.decode(data)
|
||
|
}
|