use crate::suites;
use crate::{Error, NamedGroup};
use core::fmt::Debug;
#[cfg(feature = "ring")]
pub mod ring;
pub mod cipher;
pub mod hash;
pub mod hmac;
pub mod signer;
pub use crate::rand::GetRandomFailed;
pub use crate::msgs::handshake::KeyExchangeAlgorithm;
pub trait CryptoProvider: Send + Sync + Debug + 'static {
fn fill_random(&self, buf: &mut [u8]) -> Result<(), GetRandomFailed>;
fn default_cipher_suites(&self) -> &'static [suites::SupportedCipherSuite];
fn default_kx_groups(&self) -> &'static [&'static dyn SupportedKxGroup];
}
pub trait SupportedKxGroup: Send + Sync + Debug {
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, GetRandomFailed>;
fn name(&self) -> NamedGroup;
}
pub trait ActiveKeyExchange: Send + Sync {
fn complete(self: Box<Self>, peer_pub_key: &[u8]) -> Result<SharedSecret, Error>;
fn pub_key(&self) -> &[u8];
fn group(&self) -> NamedGroup;
}
pub struct SharedSecret(Vec<u8>);
impl SharedSecret {
pub(crate) fn secret_bytes(&self) -> &[u8] {
&self.0
}
}
impl From<&[u8]> for SharedSecret {
fn from(source: &[u8]) -> Self {
Self(source.to_vec())
}
}