Browse Source

Format code

pull/19/head
Rodolphe Breard 5 years ago
parent
commit
39df1601d8
  1. 2
      acme_common/src/crypto/openssl_certificate.rs
  2. 4
      acmed/build.rs
  3. 6
      acmed/src/acme_proto/http.rs
  4. 2
      acmed/src/certificate.rs
  5. 3
      acmed/src/config.rs
  6. 2
      acmed/src/main_event_loop.rs

2
acme_common/src/crypto/openssl_certificate.rs

@ -72,7 +72,7 @@ impl X509Certificate {
crt.tbs_certificate crt.tbs_certificate
.validity .validity
.time_to_expiration() .time_to_expiration()
.ok_or(Error::from("Invalid certificate validity."))
.ok_or_else(|| Error::from("Invalid certificate validity."))
} }
pub fn subject_alt_names(&self) -> HashSet<String> { pub fn subject_alt_names(&self) -> HashSet<String> {

4
acmed/build.rs

@ -69,7 +69,7 @@ fn set_lock() {
} }
fn get_openssl_version_unit(n: u64, pos: u32) -> u64 { fn get_openssl_version_unit(n: u64, pos: u32) -> u64 {
let p = 0xff_00_00_00_0 >> (8 * pos);
let p = 0x000f_f000_0000 >> (8 * pos);
let n = n & p; let n = n & p;
n >> (8 * (3 - pos) + 4) n >> (8 * (3 - pos) + 4)
} }
@ -118,7 +118,7 @@ fn set_tls() {
set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version); set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version);
set_rustc_env_var!("ACMED_TLS_LIB_NAME", "LibreSSL"); set_rustc_env_var!("ACMED_TLS_LIB_NAME", "LibreSSL");
} }
if let Ok(_) = env::var("CARGO_FEATURE_STANDALONE") {
if env::var("CARGO_FEATURE_STANDALONE").is_ok() {
let version = get_lib_version("ring").unwrap(); let version = get_lib_version("ring").unwrap();
set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version); set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version);
set_rustc_env_var!("ACMED_TLS_LIB_NAME", "ring"); set_rustc_env_var!("ACMED_TLS_LIB_NAME", "ring");

6
acmed/src/acme_proto/http.rs

@ -100,7 +100,7 @@ fn nonce_from_response(cert: &Certificate, res: &Response) -> Result<String, Err
let nonce = get_header(res, "Replay-Nonce")?; let nonce = get_header(res, "Replay-Nonce")?;
if is_nonce(&nonce) { if is_nonce(&nonce) {
cert.trace(&format!("New nonce: {}", nonce)); cert.trace(&format!("New nonce: {}", nonce));
Ok(nonce.to_string())
Ok(nonce)
} else { } else {
let msg = format!("{}: invalid nonce.", nonce); let msg = format!("{}: invalid nonce.", nonce);
Err(msg.into()) Err(msg.into())
@ -123,13 +123,13 @@ fn post_jose_type(
let rstr = String::from_utf8_lossy(data); let rstr = String::from_utf8_lossy(data);
cert.trace(&format!("request body: {}", rstr)); cert.trace(&format!("request body: {}", rstr));
let (res, res_body) = send_request(cert, &request)?; let (res, res_body) = send_request(cert, &request)?;
let lpos = res_body.find("{").unwrap_or(0);
let lpos = res_body.find('{').unwrap_or(0);
let res_body = if lpos == 0 { let res_body = if lpos == 0 {
res_body res_body
} else { } else {
res_body.chars().skip(lpos).collect::<String>() res_body.chars().skip(lpos).collect::<String>()
}; };
let rpos = res_body.rfind("}").unwrap_or(0);
let rpos = res_body.rfind('}').unwrap_or(0);
let res_body = if rpos == 0 { let res_body = if rpos == 0 {
res_body res_body
} else { } else {

2
acmed/src/certificate.rs

@ -108,7 +108,7 @@ impl Certificate {
self.debug(&format!("expires in {} days", expires_in.as_secs() / 86400)); self.debug(&format!("expires in {} days", expires_in.as_secs() / 86400));
// TODO: allow a custom duration (using time-parse ?) // TODO: allow a custom duration (using time-parse ?)
// 1814400 is 3 weeks (3 * 7 * 24 * 60 * 60) // 1814400 is 3 weeks (3 * 7 * 24 * 60 * 60)
let renewal_time = Duration::new(1814400, 0);
let renewal_time = Duration::new(1_814_400, 0);
Ok(expires_in <= renewal_time) Ok(expires_in <= renewal_time)
} }

3
acmed/src/config.rs

@ -300,7 +300,8 @@ impl Certificate {
match &self.name { match &self.name {
Some(n) => n.to_string(), Some(n) => n.to_string(),
None => self.domains.first().unwrap().dns.to_owned(), None => self.domains.first().unwrap().dns.to_owned(),
}.replace("*", "_")
}
.replace("*", "_")
} }
pub fn get_crt_name_format(&self) -> String { pub fn get_crt_name_format(&self) -> String {

2
acmed/src/main_event_loop.rs

@ -74,7 +74,7 @@ impl MainEventLoop {
Ok(MainEventLoop { Ok(MainEventLoop {
certs, certs,
root_certs: root_certs.iter().map(|v| v.to_string()).collect(),
root_certs: root_certs.iter().map(|v| (*v).to_string()).collect(),
}) })
} }

Loading…
Cancel
Save