mirror of https://github.com/ctz/rustls
refactor: more general error in SupportedKxGroup
Use `Error` instead of `GetRandomFailed` in trait `SupportedKxGroup`, so that underlying crypto provider could throw errors other than RNG related errors.
This commit is contained in:
parent
e7a380f536
commit
3355e06f97
|
@ -34,7 +34,7 @@ pub const ALL_KX_GROUPS: &[&dyn SupportedKxGroup] = &[&X25519 as &dyn SupportedK
|
|||
pub struct X25519;
|
||||
|
||||
impl crypto::SupportedKxGroup for X25519 {
|
||||
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, rustls::crypto::GetRandomFailed> {
|
||||
fn start(&self) -> Result<Box<dyn crypto::ActiveKeyExchange>, rustls::Error> {
|
||||
let priv_key = x25519_dalek::EphemeralSecret::random_from_rng(rand_core::OsRng);
|
||||
Ok(Box::new(KeyExchange {
|
||||
pub_key: (&priv_key).into(),
|
||||
|
|
|
@ -59,7 +59,7 @@ pub trait SupportedKxGroup: Send + Sync + Debug {
|
|||
/// # Errors
|
||||
///
|
||||
/// This can fail if the random source fails during ephemeral key generation.
|
||||
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, GetRandomFailed>;
|
||||
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, Error>;
|
||||
|
||||
/// Named group the SupportedKxGroup operates in.
|
||||
fn name(&self) -> NamedGroup;
|
||||
|
|
|
@ -22,7 +22,7 @@ struct KxGroup {
|
|||
}
|
||||
|
||||
impl SupportedKxGroup for KxGroup {
|
||||
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, GetRandomFailed> {
|
||||
fn start(&self) -> Result<Box<dyn ActiveKeyExchange>, Error> {
|
||||
let rng = SystemRandom::new();
|
||||
let priv_key = EphemeralPrivateKey::generate(self.agreement_algorithm, &rng)
|
||||
.map_err(|_| GetRandomFailed)?;
|
||||
|
|
Loading…
Reference in New Issue