From a59a909cc615abba9fa984e3cf0249deef189d6e Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Tue, 7 May 2019 16:38:11 +0200 Subject: [PATCH] Format code --- acmed/src/acme_proto.rs | 6 ++++-- acmed/src/acme_proto/http.rs | 36 +++++++++++++++++++++++++++++------- acmed/src/main.rs | 10 +++++----- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/acmed/src/acme_proto.rs b/acmed/src/acme_proto.rs index 44084a2..5ff2ac3 100644 --- a/acmed/src/acme_proto.rs +++ b/acmed/src/acme_proto.rs @@ -124,7 +124,8 @@ pub fn request_certificate(cert: &Certificate, root_certs: &[String]) -> Result< // 8. Tell the server the challenge has been completed let chall_url = challenge.get_url(); let data_builder = set_data_builder!(account, b"{}", chall_url); - let new_nonce = http::post_challenge_response(root_certs, &chall_url, &data_builder, &nonce)?; + let new_nonce = + http::post_challenge_response(root_certs, &chall_url, &data_builder, &nonce)?; nonce = new_nonce; } } @@ -147,7 +148,8 @@ pub fn request_certificate(cert: &Certificate, root_certs: &[String]) -> Result< let (priv_key, pub_key) = certificate::get_key_pair(cert)?; let csr = certificate::generate_csr(cert, &priv_key, &pub_key)?; let data_builder = set_data_builder!(account, csr.as_bytes(), order.finalize); - let (_, nonce): (Order, String) = http::get_obj(root_certs, &order.finalize, &data_builder, &nonce)?; + let (_, nonce): (Order, String) = + http::get_obj(root_certs, &order.finalize, &data_builder, &nonce)?; // 12. Pool the order in order to see whether or not it is valid let data_builder = set_empty_data_builder!(account, order_url); diff --git a/acmed/src/acme_proto/http.rs b/acmed/src/acme_proto/http.rs index aa67fba..a03bb40 100644 --- a/acmed/src/acme_proto/http.rs +++ b/acmed/src/acme_proto/http.rs @@ -4,9 +4,9 @@ use http_req::request::{Method, Request}; use http_req::response::Response; use http_req::uri::Uri; use log::{debug, trace, warn}; +use std::path::Path; use std::str::FromStr; use std::{thread, time}; -use std::path::Path; const CONTENT_TYPE_JOSE: &str = "application/jose+json"; const CONTENT_TYPE_JSON: &str = "application/json"; @@ -97,7 +97,12 @@ fn nonce_from_response(res: &Response) -> Result { } } -fn post_jose_type(root_certs: &[String], url: &str, data: &[u8], accept_type: &str) -> Result<(Response, String), Error> { +fn post_jose_type( + root_certs: &[String], + url: &str, + data: &[u8], + accept_type: &str, +) -> Result<(Response, String), Error> { let uri = url.parse::()?; let mut request = new_request(root_certs, &uri, Method::POST); request.header("Content-Type", CONTENT_TYPE_JOSE); @@ -155,7 +160,12 @@ where Err("Too much errors, will not retry".into()) } -fn fetch_obj(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result<(T, String, String), Error> +fn fetch_obj( + root_certs: &[String], + url: &str, + data_builder: &G, + nonce: &str, +) -> Result<(T, String, String), Error> where T: std::str::FromStr, G: Fn(&str) -> Result, @@ -181,7 +191,12 @@ where } } -pub fn get_obj(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result<(T, String), Error> +pub fn get_obj( + root_certs: &[String], + url: &str, + data_builder: &G, + nonce: &str, +) -> Result<(T, String), Error> where T: std::str::FromStr, G: Fn(&str) -> Result, @@ -215,11 +230,17 @@ where Err(msg.into()) } -pub fn post_challenge_response(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result +pub fn post_challenge_response( + root_certs: &[String], + url: &str, + data_builder: &G, + nonce: &str, +) -> Result where G: Fn(&str) -> Result, { - let (_, _, nonce): (DummyString, String, String) = fetch_obj(root_certs, url, data_builder, nonce)?; + let (_, _, nonce): (DummyString, String, String) = + fetch_obj(root_certs, url, data_builder, nonce)?; Ok(nonce) } @@ -232,7 +253,8 @@ pub fn get_certificate( where G: Fn(&str) -> Result, { - let (res_body, _, nonce): (DummyString, String, String) = fetch_obj(root_certs, url, data_builder, nonce)?; + let (res_body, _, nonce): (DummyString, String, String) = + fetch_obj(root_certs, url, data_builder, nonce)?; Ok((res_body.content, nonce)) } diff --git a/acmed/src/main.rs b/acmed/src/main.rs index e910f40..fbe9498 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -77,11 +77,11 @@ fn main() { ) .arg( Arg::with_name("root-cert") - .long("root-cert") - .help("Add a root certificate to the trust store") - .takes_value(true) - .multiple(true) - .value_name("FILE") + .long("root-cert") + .help("Add a root certificate to the trust store") + .takes_value(true) + .multiple(true) + .value_name("FILE"), ) .get_matches();