#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use crate::{from_bytes, match_algo, Config, HpkeError};
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
#[cfg(feature = "base-mode-open")]
pub fn base_mode_open(
config: &Config,
private_key: &[u8],
encapped_key: &[u8],
info: &[u8],
ciphertext: &[u8],
aad: &[u8],
) -> Result<Vec<u8>, HpkeError> {
let Config { aead, kdf, kem } = *config;
let open = match_algo!(aead, kdf, kem, open);
open(private_key, encapped_key, info, ciphertext, aad)
}
fn open<AeadT, KdfT, KemT>(
private_key: &[u8],
encapped_key: &[u8],
info: &[u8],
ciphertext: &[u8],
aad: &[u8],
) -> Result<Vec<u8>, HpkeError>
where
AeadT: hpke::aead::Aead,
KdfT: hpke::kdf::Kdf,
KemT: hpke::kem::Kem,
{
hpke::single_shot_open::<AeadT, KdfT, KemT>(
&hpke::OpModeR::Base,
&from_bytes(private_key)?,
&from_bytes(encapped_key)?,
info,
ciphertext,
aad,
)
.map_err(Into::into) }