Browse Source

Remove the redundant encode_jwk_no_nonce function

pull/42/head
Rodolphe Bréard 4 years ago
parent
commit
f2831345f8
  1. 16
      acmed/src/acme_proto/account.rs
  2. 25
      acmed/src/jws.rs

16
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::acme_proto::structs::{Account, AccountKeyRollover, AccountUpdate, AcmeError};
use crate::endpoint::Endpoint; use crate::endpoint::Endpoint;
use crate::http::HttpError; 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::logs::HasLogger;
use crate::set_data_builder; use crate::set_data_builder;
use acme_common::error::Error; 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 acc_ref = &account_struct;
let kp_ref = &account.current_key.key; let kp_ref = &account.current_key.key;
let signature_algorithm = &account.current_key.signature_algorithm; 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) = let (acc_rep, account_url) =
http::new_account(endpoint, &data_builder).map_err(HttpError::in_err)?; http::new_account(endpoint, &data_builder).map_err(HttpError::in_err)?;
account.set_account_url(&endpoint.name, &account_url)?; 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 account_url = account.get_endpoint(&endpoint_name)?.account_url.clone();
let rollover_struct = AccountKeyRollover::new(&account_url, &old_key)?; let rollover_struct = AccountKeyRollover::new(&account_url, &old_key)?;
let rollover_struct = serde_json::to_string(&rollover_struct)?; 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.key,
&account.current_key.signature_algorithm, &account.current_key.signature_algorithm,
rollover_struct.as_bytes(), rollover_struct.as_bytes(),
&url, &url,
None,
)?; )?;
let data_builder = |n: &str, url: &str| { let data_builder = |n: &str, url: &str| {
encode_kid( encode_kid(

25
acmed/src/jws.rs

@ -48,30 +48,13 @@ pub fn encode_jwk(
sign_alg: &JwsSignatureAlgorithm, sign_alg: &JwsSignatureAlgorithm,
payload: &[u8], payload: &[u8],
url: &str, url: &str,
nonce: &str,
) -> Result<String, Error> {
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<String>,
) -> Result<String, Error> { ) -> Result<String, Error> {
let protected = JwsProtectedHeader { let protected = JwsProtectedHeader {
alg: sign_alg.to_string(), alg: sign_alg.to_string(),
jwk: Some(key_pair.jwk_public_key()?), jwk: Some(key_pair.jwk_public_key()?),
kid: None, kid: None,
nonce: None,
nonce,
url: url.into(), url: url.into(),
}; };
let protected = serde_json::to_string(&protected)?; let protected = serde_json::to_string(&protected)?;
@ -150,7 +133,7 @@ mod tests {
&key_type.get_default_signature_alg(), &key_type.get_default_signature_alg(),
payload.as_bytes(), payload.as_bytes(),
"", "",
"",
Some(String::new()),
); );
assert!(s.is_ok()); assert!(s.is_ok());
let s = s.unwrap(); let s = s.unwrap();
@ -172,7 +155,7 @@ mod tests {
&key_type.get_default_signature_alg(), &key_type.get_default_signature_alg(),
payload.as_bytes(), payload.as_bytes(),
"", "",
"",
Some(String::new()),
); );
assert!(s.is_ok()); assert!(s.is_ok());
let s = s.unwrap(); let s = s.unwrap();

Loading…
Cancel
Save