From 7e69767db5f9257ae96e855672a67e2101a6fba7 Mon Sep 17 00:00:00 2001 From: Yuval Kogman Date: Tue, 16 Sep 2025 22:33:58 +0200 Subject: [PATCH] don't mutably borrow the public key unnecessarily --- ohttp/src/lib.rs | 12 ++++++------ ohttp/src/rh/hpke.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ohttp/src/lib.rs b/ohttp/src/lib.rs index b0e4bc1..1e8b0e8 100644 --- a/ohttp/src/lib.rs +++ b/ohttp/src/lib.rs @@ -92,13 +92,13 @@ pub struct ClientRequest { #[cfg(feature = "client")] impl ClientRequest { /// Construct a `ClientRequest` from a specific `KeyConfig` instance. - pub fn from_config(config: &mut KeyConfig) -> Res { + pub fn from_config(config: &KeyConfig) -> Res { // TODO(mt) choose the best config, not just the first. let selected = config.select(config.symmetric[0])?; // Build the info, which contains the message header. let info = build_info(config.key_id, selected)?; - let hpke = HpkeS::new(selected, &mut config.pk, &info)?; + let hpke = HpkeS::new(selected, &config.pk, &info)?; let header = Vec::from(&info[INFO_REQUEST.len() + 1..]); debug_assert_eq!(header.len(), REQUEST_HEADER_LEN); @@ -108,8 +108,8 @@ impl ClientRequest { /// Reads an encoded configuration and constructs a single use client sender. /// See `KeyConfig::decode` for the structure details. pub fn from_encoded_config(encoded_config: &[u8]) -> Res { - let mut config = KeyConfig::decode(encoded_config)?; - Self::from_config(&mut config) + let config = KeyConfig::decode(encoded_config)?; + Self::from_config(&config) } /// Reads an encoded list of configurations and constructs a single use client sender @@ -117,8 +117,8 @@ impl ClientRequest { /// See `KeyConfig::decode_list` for the structure details. pub fn from_encoded_config_list(encoded_config_list: &[u8]) -> Res { let mut configs = KeyConfig::decode_list(encoded_config_list)?; - if let Some(mut config) = configs.pop() { - Self::from_config(&mut config) + if let Some(config) = configs.pop() { + Self::from_config(&config) } else { Err(Error::Unsupported) } diff --git a/ohttp/src/rh/hpke.rs b/ohttp/src/rh/hpke.rs index 156cbb6..eb2a49a 100644 --- a/ohttp/src/rh/hpke.rs +++ b/ohttp/src/rh/hpke.rs @@ -158,7 +158,7 @@ pub struct HpkeS { impl HpkeS { /// Create a new context that uses the KEM mode for sending. - pub fn new(config: Config, pk_r: &mut PublicKey, info: &[u8]) -> Res { + pub fn new(config: Config, pk_r: &PublicKey, info: &[u8]) -> Res { let mut csprng = thread_rng(); macro_rules! dispatch_hpkes_new { @@ -435,8 +435,8 @@ mod test { fn make() { init(); let cfg = Config::default(); - let (sk_r, mut pk_r) = generate_key_pair(cfg.kem()).unwrap(); - let hpke_s = HpkeS::new(cfg, &mut pk_r, INFO).unwrap(); + let (sk_r, pk_r) = generate_key_pair(cfg.kem()).unwrap(); + let hpke_s = HpkeS::new(cfg, &pk_r, INFO).unwrap(); let _hpke_r = HpkeR::new(cfg, &pk_r, &sk_r, &hpke_s.enc().unwrap(), INFO).unwrap(); } @@ -450,10 +450,10 @@ mod test { ..Config::default() }; assert!(cfg.supported()); - let (sk_r, mut pk_r) = generate_key_pair(cfg.kem()).unwrap(); + let (sk_r, pk_r) = generate_key_pair(cfg.kem()).unwrap(); // Send - let mut hpke_s = HpkeS::new(cfg, &mut pk_r, INFO).unwrap(); + let mut hpke_s = HpkeS::new(cfg, &pk_r, INFO).unwrap(); let enc = hpke_s.enc().unwrap(); let ct = hpke_s.seal(AAD, PT).unwrap();