post body internals

new-idea
Avril 4 years ago
parent 9ba00f6722
commit 878a2435c5
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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>;

@ -173,7 +173,7 @@ mod tests
email: None,
tripcode: Some(super::Tripcode::generate("uhh hello").unwrap()),
},
body: unsafe { super::PostBodyString::new_unchecked(base64::encode("test")) },
body: super::PostBodyString::new(crate::hard_format::formats::Base64FormattedString::encode("Hello world").into()).unwrap(),
signature: None,
hash: Default::default(),

Loading…
Cancel
Save