Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct ClientRequest from &mut KeyConfig #56

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ohttp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
pub fn from_config(config: &mut KeyConfig) -> Res<Self> {
// TODO(mt) choose the best config, not just the first.
let selected = config.select(config.symmetric[0])?;

Expand All @@ -108,20 +108,20 @@ 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<Self> {
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
/// from the first supported configuration.
/// See `KeyConfig::decode_list` for the structure details.
pub fn from_encoded_config_list(encoded_config_list: &[u8]) -> Res<Self> {
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.
Expand Down
2 changes: 1 addition & 1 deletion ohttp/src/nss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions ohttp/src/rh/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -80,7 +80,7 @@ impl Aead {
};
Ok(Self {
mode,
aead,
engine: aead,
nonce_base,
seq: 0,
})
Expand All @@ -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<Vec<u8>> {
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)
}
}
Expand Down
Loading