Skip to content
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
12 changes: 6 additions & 6 deletions ohttp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
pub fn from_config(config: &KeyConfig) -> Res<Self> {
// 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);
Expand All @@ -108,17 +108,17 @@ 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 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
/// 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)?;
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)
}
Expand Down
10 changes: 5 additions & 5 deletions ohttp/src/rh/hpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
pub fn new(config: Config, pk_r: &PublicKey, info: &[u8]) -> Res<Self> {
let mut csprng = thread_rng();

macro_rules! dispatch_hpkes_new {
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();

Expand Down
Loading