diff --git a/src/util/helpers.rs b/src/util/helpers.rs index fad0b671..2aa37013 100644 --- a/src/util/helpers.rs +++ b/src/util/helpers.rs @@ -39,7 +39,7 @@ impl TrimmedPlainText { } } -/// Codec wrapping base64 encode/decode +/// Codec wrapping base64 encode/decode. pub struct Base64; impl Base64 { @@ -51,3 +51,17 @@ impl Base64 { Some(base64::encode(b)) } } + +/// Codec wrapping base64 encode/decode, while ignoring whitespace characters. +pub struct WhitespaceAwareBase64; + +impl WhitespaceAwareBase64 { + pub fn decode(s: &str) -> Result, Error> { + let s: String = s.chars().into_iter().filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t').collect(); + Ok(base64::decode(&s)?) + } + + pub fn encode(b: &Vec) -> Option { + Some(base64::encode(b)) + } +}