From f2831345f82fed235aef585abf9b65439ded909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Mon, 21 Dec 2020 21:13:54 +0100 Subject: [PATCH] Remove the redundant encode_jwk_no_nonce function --- acmed/src/acme_proto/account.rs | 16 ++++++++++++---- acmed/src/jws.rs | 25 ++++--------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/acmed/src/acme_proto/account.rs b/acmed/src/acme_proto/account.rs index 6c09cd8..8a01a92 100644 --- a/acmed/src/acme_proto/account.rs +++ b/acmed/src/acme_proto/account.rs @@ -3,7 +3,7 @@ use crate::acme_proto::http; use crate::acme_proto::structs::{Account, AccountKeyRollover, AccountUpdate, AcmeError}; use crate::endpoint::Endpoint; use crate::http::HttpError; -use crate::jws::{encode_jwk, encode_jwk_no_nonce, encode_kid}; +use crate::jws::{encode_jwk, encode_kid}; use crate::logs::HasLogger; use crate::set_data_builder; use acme_common::error::Error; @@ -40,8 +40,15 @@ pub fn register_account(endpoint: &mut Endpoint, account: &mut BaseAccount) -> R let acc_ref = &account_struct; let kp_ref = &account.current_key.key; let signature_algorithm = &account.current_key.signature_algorithm; - let data_builder = - |n: &str, url: &str| encode_jwk(kp_ref, signature_algorithm, acc_ref.as_bytes(), url, n); + let data_builder = |n: &str, url: &str| { + encode_jwk( + kp_ref, + signature_algorithm, + acc_ref.as_bytes(), + url, + Some(n.to_string()), + ) + }; let (acc_rep, account_url) = http::new_account(endpoint, &data_builder).map_err(HttpError::in_err)?; account.set_account_url(&endpoint.name, &account_url)?; @@ -110,11 +117,12 @@ pub fn update_account_key(endpoint: &mut Endpoint, account: &mut BaseAccount) -> let account_url = account.get_endpoint(&endpoint_name)?.account_url.clone(); let rollover_struct = AccountKeyRollover::new(&account_url, &old_key)?; let rollover_struct = serde_json::to_string(&rollover_struct)?; - let rollover_payload = encode_jwk_no_nonce( + let rollover_payload = encode_jwk( &account.current_key.key, &account.current_key.signature_algorithm, rollover_struct.as_bytes(), &url, + None, )?; let data_builder = |n: &str, url: &str| { encode_kid( diff --git a/acmed/src/jws.rs b/acmed/src/jws.rs index 71cda7b..0bd2ab6 100644 --- a/acmed/src/jws.rs +++ b/acmed/src/jws.rs @@ -48,30 +48,13 @@ pub fn encode_jwk( sign_alg: &JwsSignatureAlgorithm, payload: &[u8], url: &str, - nonce: &str, -) -> Result { - let protected = JwsProtectedHeader { - alg: sign_alg.to_string(), - jwk: Some(key_pair.jwk_public_key()?), - kid: None, - nonce: Some(nonce.into()), - url: url.into(), - }; - let protected = serde_json::to_string(&protected)?; - get_data(key_pair, sign_alg, &protected, payload) -} - -pub fn encode_jwk_no_nonce( - key_pair: &KeyPair, - sign_alg: &JwsSignatureAlgorithm, - payload: &[u8], - url: &str, + nonce: Option, ) -> Result { let protected = JwsProtectedHeader { alg: sign_alg.to_string(), jwk: Some(key_pair.jwk_public_key()?), kid: None, - nonce: None, + nonce, url: url.into(), }; let protected = serde_json::to_string(&protected)?; @@ -150,7 +133,7 @@ mod tests { &key_type.get_default_signature_alg(), payload.as_bytes(), "", - "", + Some(String::new()), ); assert!(s.is_ok()); let s = s.unwrap(); @@ -172,7 +155,7 @@ mod tests { &key_type.get_default_signature_alg(), payload.as_bytes(), "", - "", + Some(String::new()), ); assert!(s.is_ok()); let s = s.unwrap();