diff --git a/acme_common/src/error.rs b/acme_common/src/error.rs index 3ab32eb..c0699f4 100644 --- a/acme_common/src/error.rs +++ b/acme_common/src/error.rs @@ -69,6 +69,12 @@ impl From for Error { } } +impl From for Error { + fn from(error: base64::DecodeError) -> Self { + format!("base 64 decode error: {}", error).into() + } +} + impl From for Error { fn from(error: syslog::Error) -> Self { format!("syslog error: {}", error).into() diff --git a/acme_common/src/lib.rs b/acme_common/src/lib.rs index d81b884..657f621 100644 --- a/acme_common/src/lib.rs +++ b/acme_common/src/lib.rs @@ -42,6 +42,11 @@ pub fn b64_encode>(input: &T) -> String { base64::encode_config(input, base64::URL_SAFE_NO_PAD) } +pub fn b64_decode>(input: &T) -> Result, error::Error> { + let res = base64::decode_config(input, base64::URL_SAFE_NO_PAD)?; + Ok(res) +} + pub fn init_server(foreground: bool, pid_file: Option<&str>, default_pid_file: &str) { if !foreground { let daemonize = Daemonize::new().pid_file(pid_file.unwrap_or(default_pid_file));