From 55afe8f243c21f4bc276c877b4d6ccd716965e13 Mon Sep 17 00:00:00 2001 From: AlexSherbinin Date: Thu, 29 Aug 2024 17:46:48 +0300 Subject: [PATCH] fix: replaced empty tuple error types with Infallible --- dhkem/src/ecdh_kem.rs | 6 +++--- dhkem/src/x25519_kem.rs | 5 +++-- ml-kem/src/kem.rs | 18 ++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/dhkem/src/ecdh_kem.rs b/dhkem/src/ecdh_kem.rs index 8dda9e0..03bf256 100644 --- a/dhkem/src/ecdh_kem.rs +++ b/dhkem/src/ecdh_kem.rs @@ -1,7 +1,7 @@ //! Generic Elliptic Curve Diffie-Hellman KEM adapter. use crate::{DhDecapsulator, DhEncapsulator, DhKem}; -use core::marker::PhantomData; +use core::{convert::Infallible, marker::PhantomData}; use elliptic_curve::{ ecdh::{EphemeralSecret, SharedSecret}, CurveArithmetic, PublicKey, @@ -19,7 +19,7 @@ impl Encapsulate, SharedSecret> for DhEncapsulator Decapsulate, SharedSecret> for DhDecapsulator) -> Result, Self::Error> { let ss = self.0.diffie_hellman(encapsulated_key); diff --git a/dhkem/src/x25519_kem.rs b/dhkem/src/x25519_kem.rs index 2deb80c..6cd35fd 100644 --- a/dhkem/src/x25519_kem.rs +++ b/dhkem/src/x25519_kem.rs @@ -1,4 +1,5 @@ use crate::{DhDecapsulator, DhEncapsulator, DhKem}; +use core::convert::Infallible; use kem::{Decapsulate, Encapsulate}; use rand_core::CryptoRngCore; use x25519::{PublicKey, ReusableSecret, SharedSecret}; @@ -9,7 +10,7 @@ use x25519::{PublicKey, ReusableSecret, SharedSecret}; pub struct X25519Kem; impl Encapsulate for DhEncapsulator { - type Error = (); + type Error = Infallible; fn encapsulate( &self, @@ -25,7 +26,7 @@ impl Encapsulate for DhEncapsulator { } impl Decapsulate for DhDecapsulator { - type Error = (); + type Error = Infallible; fn decapsulate(&self, encapsulated_key: &PublicKey) -> Result { let ss = self.0.diffie_hellman(encapsulated_key); diff --git a/ml-kem/src/kem.rs b/ml-kem/src/kem.rs index 0047125..4abc52a 100644 --- a/ml-kem/src/kem.rs +++ b/ml-kem/src/kem.rs @@ -1,3 +1,4 @@ +use core::convert::Infallible; use core::marker::PhantomData; use hybrid_array::typenum::U32; use rand_core::CryptoRngCore; @@ -85,12 +86,12 @@ impl

::kem::Decapsulate, SharedKey> for DecapsulationKey where P: KemParams, { - // Decapsulation is infallible - // XXX(RLB): Maybe we should reflect decryption failure as an error? - // TODO(RLB) Make Infallible - type Error = (); + type Error = Infallible; - fn decapsulate(&self, encapsulated_key: &EncodedCiphertext

) -> Result { + fn decapsulate( + &self, + encapsulated_key: &EncodedCiphertext

, + ) -> Result { let mp = self.dk_pke.decrypt(encapsulated_key); let (Kp, rp) = G(&[&mp, &self.ek.h]); let Kbar = J(&[self.z.as_slice(), encapsulated_key.as_ref()]); @@ -187,9 +188,7 @@ impl

::kem::Encapsulate, SharedKey> for EncapsulationKey where P: KemParams, { - // TODO(RLB) Make Infallible - // TODO(RLB) Swap the order of the - type Error = (); + type Error = Infallible; fn encapsulate( &self, @@ -205,8 +204,7 @@ impl

crate::EncapsulateDeterministic, SharedKey> for Enc where P: KemParams, { - // TODO(RLB) Make Infallible - type Error = (); + type Error = Infallible; fn encapsulate_deterministic( &self,