1#[cfg(feature = "alloc")]
4use crate::buffer::SecretBytes;
5use crate::{buffer::WriteBuffer, error::Error};
6
7#[cfg(feature = "argon2")]
8#[cfg_attr(docsrs, doc(cfg(feature = "argon2")))]
9pub mod argon2;
10
11pub mod concat;
12
13pub mod ecdh_1pu;
14
15pub mod ecdh_es;
16
17pub trait KeyExchange<Rhs: ?Sized = Self> {
19 fn write_key_exchange(&self, other: &Rhs, out: &mut dyn WriteBuffer) -> Result<(), Error>;
21
22 #[cfg(feature = "alloc")]
23 #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
24 fn key_exchange_bytes(&self, other: &Rhs) -> Result<SecretBytes, Error> {
26 let mut buf = SecretBytes::with_capacity(128);
27 self.write_key_exchange(other, &mut buf)?;
28 Ok(buf)
29 }
30}
31
32pub trait FromKeyExchange<Lhs: ?Sized, Rhs: ?Sized>: Sized {
34 fn from_key_exchange(lhs: &Lhs, rhs: &Rhs) -> Result<Self, Error>;
36}
37
38pub trait KeyDerivation {
40 fn derive_key_bytes(&mut self, key_output: &mut [u8]) -> Result<(), Error>;
42}
43
44pub trait FromKeyDerivation {
46 fn from_key_derivation<D: KeyDerivation>(derive: D) -> Result<Self, Error>
48 where
49 Self: Sized;
50}