util: add base64 transcoding wrappers
parent
f54a172e07
commit
f13c3a3dbe
@ -0,0 +1,20 @@
|
||||
use base64::{
|
||||
alphabet,
|
||||
engine::{GeneralPurpose, GeneralPurposeConfig},
|
||||
Engine,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
|
||||
use crate::core::*;
|
||||
|
||||
static ENGINE: GeneralPurpose =
|
||||
GeneralPurpose::new(&alphabet::STANDARD, GeneralPurposeConfig::new());
|
||||
|
||||
pub fn base64_decode(s: &str) -> Result<Bytes> {
|
||||
let bytes = ENGINE.decode(s).map_err(|_| Error::Base64)?;
|
||||
Ok(Bytes::from(bytes))
|
||||
}
|
||||
|
||||
pub fn base64_encode(b: &[u8]) -> String {
|
||||
ENGINE.encode(b)
|
||||
}
|
Loading…
Reference in New Issue