Browse Source

Add the b64_decode function

pull/39/head
Rodolphe Breard 4 years ago
parent
commit
875a403485
  1. 6
      acme_common/src/error.rs
  2. 5
      acme_common/src/lib.rs

6
acme_common/src/error.rs

@ -69,6 +69,12 @@ impl From<std::time::SystemTimeError> for Error {
}
}
impl From<base64::DecodeError> for Error {
fn from(error: base64::DecodeError) -> Self {
format!("base 64 decode error: {}", error).into()
}
}
impl From<syslog::Error> for Error {
fn from(error: syslog::Error) -> Self {
format!("syslog error: {}", error).into()

5
acme_common/src/lib.rs

@ -42,6 +42,11 @@ pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
}
pub fn b64_decode<T: ?Sized + AsRef<[u8]>>(input: &T) -> Result<Vec<u8>, 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));

Loading…
Cancel
Save