From 4559af529fa31948d6dbc693f11c156af8fa31b9 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 8 Jan 2024 15:32:12 -0500 Subject: [PATCH 1/3] Fix clippy lint --- ohttp/src/rh/aead.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ohttp/src/rh/aead.rs b/ohttp/src/rh/aead.rs index 76a7e44..f209086 100644 --- a/ohttp/src/rh/aead.rs +++ b/ohttp/src/rh/aead.rs @@ -54,7 +54,7 @@ impl AeadEngine { /// A switch-hitting AEAD that uses a selected primitive. pub struct Aead { mode: Mode, - aead: AeadEngine, + engine: AeadEngine, nonce_base: [u8; NONCE_LEN], seq: SequenceNumber, } @@ -80,7 +80,7 @@ impl Aead { }; Ok(Self { mode, - aead, + engine: aead, nonce_base, seq: 0, }) @@ -105,14 +105,14 @@ impl Aead { // A copy for the nonce generator to write into. But we don't use the value. let nonce = self.nonce(self.seq); self.seq += 1; - let ct = self.aead.encrypt(&nonce, Payload { msg: pt, aad })?; + let ct = self.engine.encrypt(&nonce, Payload { msg: pt, aad })?; Ok(ct) } pub fn open(&mut self, aad: &[u8], seq: SequenceNumber, ct: &[u8]) -> Res> { assert_eq!(self.mode, Mode::Decrypt); let nonce = self.nonce(seq); - let pt = self.aead.decrypt(&nonce, Payload { msg: ct, aad })?; + let pt = self.engine.decrypt(&nonce, Payload { msg: ct, aad })?; Ok(pt) } } From 407f4faf23e203810236c81715cfe70aadd8f40d Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 8 Jan 2024 15:34:57 -0500 Subject: [PATCH 2/3] Remove unused `SymKey` --- ohttp/src/nss/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohttp/src/nss/mod.rs b/ohttp/src/nss/mod.rs index 9a8a3ed..1b60c9e 100644 --- a/ohttp/src/nss/mod.rs +++ b/ohttp/src/nss/mod.rs @@ -11,7 +11,7 @@ pub mod aead; pub mod hkdf; pub mod hpke; -pub use self::p11::{random, PrivateKey, PublicKey, SymKey}; +pub use self::p11::{random, PrivateKey, PublicKey}; use err::secstatus_to_res; pub use err::Error; use lazy_static::lazy_static; From 7bc2aa2fc122091c70345f67f99939bc6d840b17 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 8 Jan 2024 15:14:27 -0500 Subject: [PATCH 3/3] Construct `ClientRequest` from `&mut KeyConfig` ClientRequests are single use so one making multiple requests needs to use they KeyConfig multiple times. Making each one from a reference rather than an owned `KeyConfig` allows this. --- ohttp/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ohttp/src/lib.rs b/ohttp/src/lib.rs index 7a26b50..ba1b57d 100644 --- a/ohttp/src/lib.rs +++ b/ohttp/src/lib.rs @@ -92,7 +92,7 @@ pub struct ClientRequest { #[cfg(feature = "client")] impl ClientRequest { /// Construct a `ClientRequest` from a specific `KeyConfig` instance. - pub fn from_config(mut config: KeyConfig) -> Res { + pub fn from_config(config: &mut KeyConfig) -> Res { // TODO(mt) choose the best config, not just the first. let selected = config.select(config.symmetric[0])?; @@ -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 config = KeyConfig::decode(encoded_config)?; - Self::from_config(config) + let mut config = KeyConfig::decode(encoded_config)?; + Self::from_config(&mut config) } /// Reads an encoded list of configurations and constructs a single use client sender @@ -117,11 +117,11 @@ 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)?; - let config = match configs.pop() { + let mut config = match configs.pop() { Some(c) => c, None => return Err(Error::Unsupported), }; - Self::from_config(config) + Self::from_config(&mut config) } /// Encapsulate a request. This consumes this object.