use alloc::boxed::Box;
use alloc::vec::Vec;
use core::fmt::Debug;
use crate::msgs::enums::HpkeKem;
use crate::msgs::handshake::HpkeSymmetricCipherSuite;
use crate::Error;
pub trait HpkeProvider: Debug + Send + Sync + 'static {
fn start(&self, suite: &HpkeSuite) -> Result<Box<dyn Hpke>, Error>;
fn supports_suite(&self, suite: &HpkeSuite) -> bool;
}
pub struct HpkeSuite {
pub kem: HpkeKem,
pub sym: HpkeSymmetricCipherSuite,
}
pub trait Hpke: Debug + Send + Sync {
fn seal(
&mut self,
pk_r: &HpkePublicKey,
info: &[u8],
aad: &[u8],
plaintext: &[u8],
) -> Result<(EncapsulatedSecret, Vec<u8>), Error>;
fn open(
&mut self,
enc: &EncapsulatedSecret,
sk_r: &HpkePrivateKey,
info: &[u8],
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, Error>;
}
pub struct HpkePublicKey(pub Vec<u8>);
pub struct HpkePrivateKey(Vec<u8>);
impl HpkePrivateKey {
pub fn secret_bytes(&self) -> &[u8] {
self.0.as_slice()
}
}
impl From<Vec<u8>> for HpkePrivateKey {
fn from(bytes: Vec<u8>) -> Self {
Self(bytes)
}
}
pub struct HpkeKeyPair {
pub public_key: HpkePublicKey,
pub private_key: HpkePrivateKey,
}
pub struct EncapsulatedSecret(pub Vec<u8>);