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:
Yuxiang Cao 2023-11-06 11:25:15 -08:00 committed by Joe Birr-Pixton
parent e7a380f536
commit 3355e06f97
3 changed files with 3 additions and 3 deletions

View File

@ -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(),

View File

@ -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;

View File

@ -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)?;