From 875a4034859e42c0061a0b5b0466958738956448 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 12 Sep 2020 15:55:17 +0200 Subject: [PATCH] Add the b64_decode function --- acme_common/src/error.rs | 6 ++++++ acme_common/src/lib.rs | 5 +++++ 2 files changed, 11 insertions(+) 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));