diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 9fc82342..6a58165f 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -188,13 +188,13 @@ def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphert def combine_decryption_shares_simple( - shares: Sequence[DecryptionShareSimple], + decryption_shares: Sequence[DecryptionShareSimple], ) -> bytes: ... def combine_decryption_shares_precomputed( - shares: Sequence[DecryptionSharePrecomputed], + decryption_shares: Sequence[DecryptionSharePrecomputed], ) -> SharedSecret: ... diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py index f608f5b9..9eaccdbd 100644 --- a/ferveo-python/test/test_serialization.py +++ b/ferveo-python/test/test_serialization.py @@ -81,5 +81,5 @@ def test_public_key_serialization(): def test_ferveo_variant_serialization(): - assert FerveoVariant.precomputed == "FerveoVariant::Precomputed" - assert FerveoVariant.simple == "FerveoVariant::Simple" + assert str(FerveoVariant.precomputed) == "FerveoVariant::Precomputed" + assert str(FerveoVariant.simple) == "FerveoVariant::Simple" diff --git a/ferveo/src/api.rs b/ferveo/src/api.rs index 10b283a7..145d5659 100644 --- a/ferveo/src/api.rs +++ b/ferveo/src/api.rs @@ -23,8 +23,8 @@ pub type ValidatorMessage = (Validator, Transcript); pub use crate::EthereumAddress; use crate::{ - do_verify_aggregation, Error, PVSSMap, PubliclyVerifiableParams, - PubliclyVerifiableSS, Result, + bindings_python, do_verify_aggregation, Error, PVSSMap, + PubliclyVerifiableParams, PubliclyVerifiableSS, Result, }; pub type DecryptionSharePrecomputed = tpke::api::DecryptionSharePrecomputed; @@ -101,6 +101,13 @@ impl FerveoVariant { } } +#[cfg(feature = "bindings-python")] +impl From for FerveoVariant { + fn from(variant: bindings_python::FerveoVariant) -> Self { + variant.0 + } +} + #[serde_as] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct DkgPublicKey( diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index 0c5db521..51088e23 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -1,4 +1,7 @@ -use std::fmt::{Debug, Formatter}; +use std::{ + fmt, + fmt::{Debug, Formatter}, +}; use ferveo_common::serialization::{FromBytes, ToBytes}; use pyo3::{ @@ -235,9 +238,9 @@ pub fn encrypt( #[pyfunction] pub fn combine_decryption_shares_simple( - shares: Vec, + decryption_shares: Vec, ) -> SharedSecret { - let shares = shares + let shares = decryption_shares .iter() .map(|share| share.0.clone()) .collect::>(); @@ -247,9 +250,9 @@ pub fn combine_decryption_shares_simple( #[pyfunction] pub fn combine_decryption_shares_precomputed( - shares: Vec, + decryption_shares: Vec, ) -> SharedSecret { - let shares = shares + let shares = decryption_shares .iter() .map(|share| share.0.clone()) .collect::>(); @@ -268,25 +271,35 @@ pub fn decrypt_with_shared_secret( } #[pyclass(module = "ferveo")] -pub struct FerveoVariant {} +#[derive(Clone)] +pub struct FerveoVariant(pub(crate) api::FerveoVariant); #[pymethods] impl FerveoVariant { #[classattr] - fn precomputed() -> &'static str { - api::FerveoVariant::Precomputed.as_str() + fn precomputed() -> FerveoVariant { + api::FerveoVariant::Precomputed.into() } #[classattr] - fn simple() -> &'static str { - api::FerveoVariant::Simple.as_str() + fn simple() -> FerveoVariant { + api::FerveoVariant::Simple.into() + } + + fn __str__(&self) -> String { + self.0.to_string() } } -impl FerveoVariant { - pub fn inner_form_string(variant: &str) -> PyResult { - api::FerveoVariant::from_string(variant) - .map_err(|err| FerveoPythonError::FerveoError(err).into()) +impl From for FerveoVariant { + fn from(variant: api::FerveoVariant) -> Self { + Self(variant) + } +} + +impl fmt::Display for FerveoVariant { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) } }