|
|
|
@ -443,6 +443,31 @@ pub mod formats
|
|
|
|
|
|
|
|
|
|
pub type Base64FormattedStr = FormattedStr<Base64Format>;
|
|
|
|
|
pub type Base64FormattedString = FormattedString<Base64Format>;
|
|
|
|
|
|
|
|
|
|
impl Base64FormattedString
|
|
|
|
|
{
|
|
|
|
|
/// Encode some data as base64
|
|
|
|
|
pub fn encode(data: impl AsRef<[u8]>) -> Self
|
|
|
|
|
{
|
|
|
|
|
unsafe { Self::new_unchecked(base64::encode(data)) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Base64FormattedStr
|
|
|
|
|
{
|
|
|
|
|
/// Decode this base64 string to a byte slice, returning the length of the written bytes.
|
|
|
|
|
///
|
|
|
|
|
/// # Panics
|
|
|
|
|
/// If the slice is not large enough
|
|
|
|
|
pub fn decode_slice(&self, mut to: impl AsMut<[u8]>) -> usize
|
|
|
|
|
{
|
|
|
|
|
base64::decode_config_slice(self.as_str(), base64::STANDARD, to.as_mut()).unwrap()
|
|
|
|
|
}
|
|
|
|
|
/// Decode this base64 string to a `Vec<u8>`
|
|
|
|
|
pub fn decode(&self) -> Vec<u8>
|
|
|
|
|
{
|
|
|
|
|
base64::decode(self.as_str()).unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type PEMFormattedStr = FormattedStr<PEMFormat>;
|
|
|
|
|
pub type PEMFormattedString = FormattedString<PEMFormat>;
|
|
|
|
|