From be900653a80e3570300f5a126af98660ab59a7d2 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Mon, 10 Jul 2023 12:06:18 +0200 Subject: [PATCH 1/9] fix: python typings don't match runtime --- .github/workflows/workspace.yml | 8 ++- Pipfile | 11 ++++ ferveo-python/Cargo.toml | 1 - ferveo-python/Pipfile | 11 ++++ ferveo-python/examples/exception.py | 2 +- .../examples/server_api_precomputed.py | 2 +- ferveo-python/examples/server_api_simple.py | 2 +- ferveo-python/ferveo/__init__.py | 2 +- ferveo-python/ferveo/__init__.pyi | 65 ++++++++++--------- ferveo-python/pyproject.toml | 26 ++++---- ferveo-python/src/lib.rs | 2 +- ferveo-python/test/test_ferveo.py | 2 +- ferveo-python/test/test_serialization.py | 2 +- ferveo/src/bindings_python.rs | 1 + 14 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 Pipfile create mode 100644 ferveo-python/Pipfile diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 04be31b8..e14f8e2a 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -175,13 +175,17 @@ jobs: run: python examples/server_api_simple.py working-directory: ferveo-python - - name: Install pytest - run: pip install pytest + - name: Install pip dependencies + run: pip install pytest mypy - name: Run pytest run: pytest working-directory: ferveo-python + - name: Run mypy.stubtest + run: python -m mypy.stubtest ferveo + working-directory: ferveo-python + codecov: runs-on: ubuntu-latest needs: [ test ] diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..c398b0d5 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.10" diff --git a/ferveo-python/Cargo.toml b/ferveo-python/Cargo.toml index 7fc78583..eafc050c 100644 --- a/ferveo-python/Cargo.toml +++ b/ferveo-python/Cargo.toml @@ -8,7 +8,6 @@ publish = false [lib] crate-type = ["cdylib"] -name = "ferveo_py" [features] extension-module = ["pyo3/extension-module"] diff --git a/ferveo-python/Pipfile b/ferveo-python/Pipfile new file mode 100644 index 00000000..c398b0d5 --- /dev/null +++ b/ferveo-python/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.10" diff --git a/ferveo-python/examples/exception.py b/ferveo-python/examples/exception.py index a653b43a..4e16aea9 100644 --- a/ferveo-python/examples/exception.py +++ b/ferveo-python/examples/exception.py @@ -1,4 +1,4 @@ -from ferveo_py import ( +from ferveo import ( Keypair, Validator, Dkg, diff --git a/ferveo-python/examples/server_api_precomputed.py b/ferveo-python/examples/server_api_precomputed.py index c0973b66..0916738d 100644 --- a/ferveo-python/examples/server_api_precomputed.py +++ b/ferveo-python/examples/server_api_precomputed.py @@ -1,4 +1,4 @@ -from ferveo_py import ( +from ferveo import ( encrypt, combine_decryption_shares_precomputed, decrypt_with_shared_secret, diff --git a/ferveo-python/examples/server_api_simple.py b/ferveo-python/examples/server_api_simple.py index de26ba38..e41c9f24 100644 --- a/ferveo-python/examples/server_api_simple.py +++ b/ferveo-python/examples/server_api_simple.py @@ -1,4 +1,4 @@ -from ferveo_py import ( +from ferveo import ( encrypt, combine_decryption_shares_simple, decrypt_with_shared_secret, diff --git a/ferveo-python/ferveo/__init__.py b/ferveo-python/ferveo/__init__.py index 43b4bbd6..f89aa778 100644 --- a/ferveo-python/ferveo/__init__.py +++ b/ferveo-python/ferveo/__init__.py @@ -1,4 +1,4 @@ -from .ferveo_py import ( +from ._ferveo import ( encrypt, combine_decryption_shares_simple, combine_decryption_shares_precomputed, diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index e16189d1..4d540655 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -1,21 +1,21 @@ -from typing import Sequence - +from typing import Sequence, final +@final class Keypair: @staticmethod def random() -> Keypair: ... @staticmethod - def from_secure_randomness(data: bytes) -> Keypair: + def from_secure_randomness(bytes: bytes) -> Keypair: ... @staticmethod - def secure_randomness_size(data: bytes) -> int: + def secure_randomness_size() -> int: ... @staticmethod - def from_bytes(data: bytes) -> Keypair: + def from_bytes(bytes: bytes) -> Keypair: ... def __bytes__(self) -> bytes: @@ -24,10 +24,10 @@ class Keypair: def public_key(self) -> FerveoPublicKey: ... - +@final class FerveoPublicKey: @staticmethod - def from_bytes(data: bytes) -> FerveoPublicKey: + def from_bytes(bytes: bytes) -> FerveoPublicKey: ... def __bytes__(self) -> bytes: @@ -36,10 +36,11 @@ class FerveoPublicKey: def __hash__(self) -> int: ... - def __richcmp__(self, other: FerveoPublicKey, op: int) -> bool: + @staticmethod + def serialized_size() -> int: ... - +@final class Validator: def __init__(self, address: str, public_key: FerveoPublicKey): @@ -49,25 +50,29 @@ class Validator: public_key: FerveoPublicKey - +@final class Transcript: @staticmethod - def from_bytes(data: bytes) -> Transcript: + def from_bytes(bytes: bytes) -> Transcript: ... def __bytes__(self) -> bytes: ... - +@final class DkgPublicKey: @staticmethod - def from_bytes(data: bytes) -> DkgPublicKey: + def from_bytes(bytes: bytes) -> DkgPublicKey: ... def __bytes__(self) -> bytes: ... + @staticmethod + def serialized_size() -> int: + ... +@final class ValidatorMessage: def __init__( @@ -80,7 +85,7 @@ class ValidatorMessage: validator: Validator transcript: Transcript - +@final class Dkg: def __init__( @@ -101,34 +106,33 @@ class Dkg: def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript: ... - +@final class Ciphertext: @staticmethod - def from_bytes(data: bytes) -> Ciphertext: + def from_bytes(bytes: bytes) -> Ciphertext: ... def __bytes__(self) -> bytes: ... - +@final class DecryptionShareSimple: @staticmethod - def from_bytes(data: bytes) -> DecryptionShareSimple: + def from_bytes(bytes: bytes) -> DecryptionShareSimple: ... def __bytes__(self) -> bytes: ... - - +@final class DecryptionSharePrecomputed: @staticmethod - def from_bytes(data: bytes) -> DecryptionSharePrecomputed: + def from_bytes(bytes: bytes) -> DecryptionSharePrecomputed: ... def __bytes__(self) -> bytes: ... - +@final class AggregatedTranscript: def __init__(self, messages: Sequence[ValidatorMessage]): @@ -156,23 +160,24 @@ class AggregatedTranscript: ... @staticmethod - def from_bytes(data: bytes) -> AggregatedTranscript: + def from_bytes(bytes: bytes) -> AggregatedTranscript: ... def __bytes__(self) -> bytes: ... - +@final class SharedSecret: @staticmethod - def from_bytes(data: bytes) -> SharedSecret: + def from_bytes(bytes: bytes) -> SharedSecret: ... def __bytes__(self) -> bytes: ... +@final class FerveoVariant: @staticmethod def simple() -> str: ... @@ -181,18 +186,18 @@ class FerveoVariant: def precomputed() -> str: ... -def encrypt(message: bytes, add: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: +def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: ... def combine_decryption_shares_simple( - decryption_shares: Sequence[DecryptionShareSimple], + shares: Sequence[DecryptionShareSimple], ) -> bytes: ... def combine_decryption_shares_precomputed( - decryption_shares: Sequence[DecryptionSharePrecomputed], + shares: Sequence[DecryptionSharePrecomputed], ) -> SharedSecret: ... @@ -267,7 +272,3 @@ class ValidatorPublicKeyMismatch(Exception): class SerializationError(Exception): pass - - -class InvalidVariant(Exception): - pass diff --git a/ferveo-python/pyproject.toml b/ferveo-python/pyproject.toml index a0010648..f90a4e13 100644 --- a/ferveo-python/pyproject.toml +++ b/ferveo-python/pyproject.toml @@ -1,14 +1,18 @@ -[build-system] -requires = ["maturin>=0.14,<0.15"] -build-backend = "maturin" +#[build-system] +#requires = ["maturin>=0.14,<0.15"] +#build-backend = "maturin" +# +#[project] +#name = "ferveo" +#requires-python = ">=3.7" +#classifiers = [ +# "Programming Language :: Rust", +# "Programming Language :: Python :: Implementation :: CPython", +# "Programming Language :: Python :: Implementation :: PyPy", +#] +# -[project] -name = "ferveo" -requires-python = ">=3.7" -classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", -] +[build-system] +requires = ["setuptools", "wheel", "setuptools-rust"] diff --git a/ferveo-python/src/lib.rs b/ferveo-python/src/lib.rs index fff55e96..71e29c9f 100644 --- a/ferveo-python/src/lib.rs +++ b/ferveo-python/src/lib.rs @@ -2,6 +2,6 @@ use ferveo::bindings_python::*; use pyo3::prelude::*; #[pymodule] -fn ferveo_py(py: Python, m: &PyModule) -> PyResult<()> { +fn _ferveo(py: Python, m: &PyModule) -> PyResult<()> { make_ferveo_py_module(py, m) } diff --git a/ferveo-python/test/test_ferveo.py b/ferveo-python/test/test_ferveo.py index b92f1c01..b045fec3 100644 --- a/ferveo-python/test/test_ferveo.py +++ b/ferveo-python/test/test_ferveo.py @@ -1,6 +1,6 @@ import pytest -from ferveo_py import ( +from ferveo import ( encrypt, combine_decryption_shares_simple, combine_decryption_shares_precomputed, diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py index 6b564be2..ee48cd8a 100644 --- a/ferveo-python/test/test_serialization.py +++ b/ferveo-python/test/test_serialization.py @@ -1,4 +1,4 @@ -from ferveo_py import ( +from ferveo import ( Keypair, Validator, Dkg, diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index cf19ebc9..99538e60 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -193,6 +193,7 @@ macro_rules! generate_boxed_bytes_serialization { #[pymethods] impl $struct_name { #[staticmethod] + #[pyo3(signature = (bytes))] pub fn from_bytes(bytes: &[u8]) -> PyResult { Ok($struct_name( $inner_struct_name::from_bytes(bytes).map_err(|err| { From 4fcc7c0ad33c05b0d956378efed3858c2a389885 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Mon, 10 Jul 2023 12:19:53 +0200 Subject: [PATCH 2/9] chore(ci): remove maturin --- .github/workflows/maturin.yml | 104 ---------------------------------- ferveo-python/Cargo.toml | 7 --- ferveo-python/README.md | 7 --- ferveo-python/pyproject.toml | 14 ----- 4 files changed, 132 deletions(-) delete mode 100644 .github/workflows/maturin.yml diff --git a/.github/workflows/maturin.yml b/.github/workflows/maturin.yml deleted file mode 100644 index cc6338a9..00000000 --- a/.github/workflows/maturin.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Maturin - -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - -env: - python-versions: [ "3.7", "3.8", "3.9", "3.10" ] - -jobs: - linux: - runs-on: ubuntu-latest - strategy: - matrix: - target: [ x86_64 ] - # TODO: Enable these upon stable release - # x86, - # aarch64, - # armv7, - # s390x, - # ppc64le - python-version: ${{ env.python-versions }} - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter --manifest-path ferveo-python/Cargo.toml - manylinux: auto - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - windows: - runs-on: windows-latest - strategy: - matrix: - target: [ x64, x86 ] - python-version: ${{ env.python-versions }} - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - architecture: ${{ matrix.target }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter --manifest-path ferveo-python/Cargo.toml - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - macos: - runs-on: macos-latest - strategy: - matrix: - target: [ x86_64, aarch64 ] - python-version: ${{ env.python-versions }} - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter --manifest-path ferveo-python/Cargo.toml - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - release: - name: Release - runs-on: ubuntu-latest - # Only runs on tagged versions - if: "startsWith(github.ref, 'refs/tags/')" - needs: [ linux, windows, macos ] - steps: - - uses: actions/download-artifact@v3 - with: - name: wheels - - name: Publish to PyPI - uses: PyO3/maturin-action@v1 - env: - MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} - with: - command: upload - args: --skip-existing * diff --git a/ferveo-python/Cargo.toml b/ferveo-python/Cargo.toml index eafc050c..44a81853 100644 --- a/ferveo-python/Cargo.toml +++ b/ferveo-python/Cargo.toml @@ -17,12 +17,5 @@ default = ["extension-module"] ferveo = { package = "ferveo-pre-release", path = "../ferveo", features = ["bindings-python"] } pyo3 = "0.18.2" -# We avoid declaring "pyo3/extension-module" in `dependencies` since it causes compile-time issues: -# https://github.com/PyO3/pyo3/issues/340 -# Instead, we expose it in certain cases: -# https://github.com/PyO3/maturin/issues/325 -[tool.maturin] -features = ["pyo3/extension-module"] - [build-dependencies] pyo3-build-config = "*" diff --git a/ferveo-python/README.md b/ferveo-python/README.md index 0e61c107..3d067b6b 100644 --- a/ferveo-python/README.md +++ b/ferveo-python/README.md @@ -3,10 +3,3 @@ ## Build You will need to have `setuptools-rust` installed. Then, for development, you can just do `pip install -e .` as usual. - -## Publish - -```bash -maturin build --release -maturin publish -``` diff --git a/ferveo-python/pyproject.toml b/ferveo-python/pyproject.toml index f90a4e13..f92911b2 100644 --- a/ferveo-python/pyproject.toml +++ b/ferveo-python/pyproject.toml @@ -1,17 +1,3 @@ -#[build-system] -#requires = ["maturin>=0.14,<0.15"] -#build-backend = "maturin" -# -#[project] -#name = "ferveo" -#requires-python = ">=3.7" -#classifiers = [ -# "Programming Language :: Rust", -# "Programming Language :: Python :: Implementation :: CPython", -# "Programming Language :: Python :: Implementation :: PyPy", -#] -# - [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] From 50511fff3c9829d6f2004360be93b67730f66f1f Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Tue, 11 Jul 2023 11:54:10 +0200 Subject: [PATCH 3/9] feat: replace FerveoVariant static methods with class atributed --- ferveo-python/ferveo/__init__.pyi | 7 +--- ferveo-python/test/test_ferveo.py | 47 ++++++++++++------------ ferveo-python/test/test_serialization.py | 4 +- ferveo/src/bindings_python.rs | 4 +- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 4d540655..503bc77e 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -179,11 +179,8 @@ class SharedSecret: @final class FerveoVariant: - @staticmethod - def simple() -> str: ... - - @staticmethod - def precomputed() -> str: ... + simple: str + precomputed: str def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: diff --git a/ferveo-python/test/test_ferveo.py b/ferveo-python/test/test_ferveo.py index b045fec3..38fa1f06 100644 --- a/ferveo-python/test/test_ferveo.py +++ b/ferveo-python/test/test_ferveo.py @@ -11,7 +11,8 @@ Dkg, AggregatedTranscript, DkgPublicKey, - ThresholdEncryptionError + ThresholdEncryptionError, + FerveoVariant ) @@ -19,26 +20,26 @@ def gen_eth_addr(i: int) -> str: return f"0x{i:040x}" -def decryption_share_for_variant(variant, agg_transcript): - if variant == "simple": +def decryption_share_for_variant(v: FerveoVariant, agg_transcript): + if v == FerveoVariant.simple: return agg_transcript.create_decryption_share_simple - elif variant == "precomputed": + elif v == FerveoVariant.precomputed: return agg_transcript.create_decryption_share_precomputed else: raise ValueError("Unknown variant") -def combine_shares_for_variant(variant, decryption_shares): - if variant == "simple": +def combine_shares_for_variant(v: FerveoVariant, decryption_shares): + if v == FerveoVariant.simple: return combine_decryption_shares_simple(decryption_shares) - elif variant == "precomputed": + elif v == FerveoVariant.precomputed: return combine_decryption_shares_precomputed(decryption_shares) else: raise ValueError("Unknown variant") -def scenario_for_variant(variant, shares_num, threshold, shares_to_use): - if variant not in ["simple", "precomputed"]: +def scenario_for_variant(variant: FerveoVariant, shares_num, threshold, shares_to_use): + if variant not in [FerveoVariant.simple, FerveoVariant.precomputed]: raise ValueError("Unknown variant: " + variant) tau = 1 @@ -98,12 +99,12 @@ def scenario_for_variant(variant, shares_num, threshold, shares_to_use): shared_secret = combine_shares_for_variant(variant, decryption_shares) - if variant == "simple" and len(decryption_shares) < threshold: + if variant == FerveoVariant.simple and len(decryption_shares) < threshold: with pytest.raises(ThresholdEncryptionError): decrypt_with_shared_secret(ciphertext, aad, shared_secret) return - if variant == "precomputed" and len(decryption_shares) < shares_num: + if variant == FerveoVariant.precomputed and len(decryption_shares) < shares_num: with pytest.raises(ThresholdEncryptionError): decrypt_with_shared_secret(ciphertext, aad, shared_secret) return @@ -113,30 +114,30 @@ def scenario_for_variant(variant, shares_num, threshold, shares_to_use): def test_simple_tdec_has_enough_messages(): - scenario_for_variant("simple", shares_num=4, threshold=3, shares_to_use=3) + scenario_for_variant(FerveoVariant.simple, shares_num=4, threshold=3, shares_to_use=3) def test_simple_tdec_doesnt_have_enough_messages(): - scenario_for_variant("simple", shares_num=4, threshold=3, shares_to_use=2) + scenario_for_variant(FerveoVariant.simple, shares_num=4, threshold=3, shares_to_use=2) def test_precomputed_tdec_has_enough_messages(): - scenario_for_variant("precomputed", shares_num=4, threshold=4, shares_to_use=4) + scenario_for_variant(FerveoVariant.precomputed, shares_num=4, threshold=4, shares_to_use=4) def test_precomputed_tdec_doesnt_have_enough_messages(): - scenario_for_variant("precomputed", shares_num=4, threshold=4, shares_to_use=3) + scenario_for_variant(FerveoVariant.precomputed, shares_num=4, threshold=4, shares_to_use=3) PARAMS = [ - (1, 'simple'), - (4, 'simple'), - (8, 'simple'), - (32, 'simple'), - (1, 'precomputed'), - (4, 'precomputed'), - (8, 'precomputed'), - (32, 'precomputed'), + (1, FerveoVariant.simple), + (4, FerveoVariant.simple), + (8, FerveoVariant.simple), + (32, FerveoVariant.simple), + (1, FerveoVariant.precomputed), + (4, FerveoVariant.precomputed), + (8, FerveoVariant.precomputed), + (32, FerveoVariant.precomputed), ] diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py index ee48cd8a..f608f5b9 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 FerveoVariant.precomputed == "FerveoVariant::Precomputed" + assert FerveoVariant.simple == "FerveoVariant::Simple" diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index 99538e60..eab2a3db 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -273,12 +273,12 @@ struct FerveoVariant {} #[pymethods] impl FerveoVariant { - #[staticmethod] + #[classattr] fn precomputed() -> &'static str { api::FerveoVariant::Precomputed.as_str() } - #[staticmethod] + #[classattr] fn simple() -> &'static str { api::FerveoVariant::Simple.as_str() } From 7cbe65def65a76043d21763723ce98787cbf8eed Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Tue, 11 Jul 2023 12:22:23 +0200 Subject: [PATCH 4/9] apply pr suggestions --- ferveo-python/ferveo/__init__.pyi | 20 ++++++++++---------- ferveo-python/test/test_ferveo.py | 7 ++++--- ferveo/src/bindings_python.rs | 24 ++++++++++++------------ 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 503bc77e..9fc82342 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -7,7 +7,7 @@ class Keypair: ... @staticmethod - def from_secure_randomness(bytes: bytes) -> Keypair: + def from_secure_randomness(secure_randomness: bytes) -> Keypair: ... @staticmethod @@ -15,7 +15,7 @@ class Keypair: ... @staticmethod - def from_bytes(bytes: bytes) -> Keypair: + def from_bytes(data: bytes) -> Keypair: ... def __bytes__(self) -> bytes: @@ -27,7 +27,7 @@ class Keypair: @final class FerveoPublicKey: @staticmethod - def from_bytes(bytes: bytes) -> FerveoPublicKey: + def from_bytes(data: bytes) -> FerveoPublicKey: ... def __bytes__(self) -> bytes: @@ -53,7 +53,7 @@ class Validator: @final class Transcript: @staticmethod - def from_bytes(bytes: bytes) -> Transcript: + def from_bytes(data: bytes) -> Transcript: ... def __bytes__(self) -> bytes: @@ -62,7 +62,7 @@ class Transcript: @final class DkgPublicKey: @staticmethod - def from_bytes(bytes: bytes) -> DkgPublicKey: + def from_bytes(data: bytes) -> DkgPublicKey: ... def __bytes__(self) -> bytes: @@ -109,7 +109,7 @@ class Dkg: @final class Ciphertext: @staticmethod - def from_bytes(bytes: bytes) -> Ciphertext: + def from_bytes(data: bytes) -> Ciphertext: ... def __bytes__(self) -> bytes: @@ -118,7 +118,7 @@ class Ciphertext: @final class DecryptionShareSimple: @staticmethod - def from_bytes(bytes: bytes) -> DecryptionShareSimple: + def from_bytes(data: bytes) -> DecryptionShareSimple: ... def __bytes__(self) -> bytes: @@ -126,7 +126,7 @@ class DecryptionShareSimple: @final class DecryptionSharePrecomputed: @staticmethod - def from_bytes(bytes: bytes) -> DecryptionSharePrecomputed: + def from_bytes(data: bytes) -> DecryptionSharePrecomputed: ... def __bytes__(self) -> bytes: @@ -160,7 +160,7 @@ class AggregatedTranscript: ... @staticmethod - def from_bytes(bytes: bytes) -> AggregatedTranscript: + def from_bytes(data: bytes) -> AggregatedTranscript: ... def __bytes__(self) -> bytes: @@ -170,7 +170,7 @@ class AggregatedTranscript: class SharedSecret: @staticmethod - def from_bytes(bytes: bytes) -> SharedSecret: + def from_bytes(data: bytes) -> SharedSecret: ... def __bytes__(self) -> bytes: diff --git a/ferveo-python/test/test_ferveo.py b/ferveo-python/test/test_ferveo.py index 38fa1f06..9406a5ae 100644 --- a/ferveo-python/test/test_ferveo.py +++ b/ferveo-python/test/test_ferveo.py @@ -131,14 +131,15 @@ def test_precomputed_tdec_doesnt_have_enough_messages(): PARAMS = [ (1, FerveoVariant.simple), + (3, FerveoVariant.simple), (4, FerveoVariant.simple), + (7, FerveoVariant.simple), (8, FerveoVariant.simple), - (32, FerveoVariant.simple), (1, FerveoVariant.precomputed), + (3, FerveoVariant.precomputed), (4, FerveoVariant.precomputed), + (7, FerveoVariant.precomputed), (8, FerveoVariant.precomputed), - (32, FerveoVariant.precomputed), - ] TEST_CASES_WITH_THRESHOLD_RANGE = [] diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index eab2a3db..d746fd1c 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -177,8 +177,9 @@ macro_rules! generate_bytes_serialization { #[pymethods] impl $struct_name { #[staticmethod] - pub fn from_bytes(bytes: &[u8]) -> PyResult { - from_py_bytes(bytes).map(Self) + #[pyo3(signature = (data))] + pub fn from_bytes(data: &[u8]) -> PyResult { + from_py_bytes(data).map(Self) } fn __bytes__(&self) -> PyResult { @@ -193,13 +194,11 @@ macro_rules! generate_boxed_bytes_serialization { #[pymethods] impl $struct_name { #[staticmethod] - #[pyo3(signature = (bytes))] - pub fn from_bytes(bytes: &[u8]) -> PyResult { - Ok($struct_name( - $inner_struct_name::from_bytes(bytes).map_err(|err| { - FerveoPythonError::Other(err.to_string()) - })?, - )) + #[pyo3(signature = (data))] + pub fn from_bytes(data: &[u8]) -> PyResult { + Ok($struct_name($inner_struct_name::from_bytes(data).map_err( + |err| FerveoPythonError::Other(err.to_string()), + )?)) } fn __bytes__(&self) -> PyResult { @@ -304,9 +303,10 @@ impl Keypair { } #[staticmethod] - pub fn from_secure_randomness(bytes: &[u8]) -> PyResult { - let keypair = api::Keypair::from_secure_randomness(bytes) - .map_err(|err| FerveoPythonError::Other(err.to_string()))?; + pub fn from_secure_randomness(secure_randomness: &[u8]) -> PyResult { + let keypair = + api::Keypair::from_secure_randomness(secure_randomness) + .map_err(|err| FerveoPythonError::Other(err.to_string()))?; Ok(Self(keypair)) } From fbb97be59d991a263233a0b876da982143b2cbf2 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Tue, 11 Jul 2023 14:46:57 +0200 Subject: [PATCH 5/9] add api conversion method to FerveoVariant --- ferveo/src/bindings_python.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index d746fd1c..0c5db521 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -268,7 +268,7 @@ pub fn decrypt_with_shared_secret( } #[pyclass(module = "ferveo")] -struct FerveoVariant {} +pub struct FerveoVariant {} #[pymethods] impl FerveoVariant { @@ -283,6 +283,13 @@ impl FerveoVariant { } } +impl FerveoVariant { + pub fn inner_form_string(variant: &str) -> PyResult { + api::FerveoVariant::from_string(variant) + .map_err(|err| FerveoPythonError::FerveoError(err).into()) + } +} + #[pyclass(module = "ferveo")] #[derive(derive_more::AsRef)] pub struct SharedSecret(api::SharedSecret); From 6c1d4becd89005d6698734caa9d681dde727bff6 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Wed, 12 Jul 2023 12:01:14 +0200 Subject: [PATCH 6/9] apply pr suggestions --- ferveo-python/ferveo/__init__.pyi | 8 ++--- ferveo-python/test/test_serialization.py | 4 +-- ferveo/src/api.rs | 9 ++++++ ferveo/src/bindings_python.rs | 41 ++++++++++++++++-------- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 9fc82342..6c32cdc4 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -179,8 +179,8 @@ class SharedSecret: @final class FerveoVariant: - simple: str - precomputed: str + simple: FerveoVariant + precomputed: FerveoVariant def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: @@ -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..c909cfed 100644 --- a/ferveo/src/api.rs +++ b/ferveo/src/api.rs @@ -21,6 +21,8 @@ pub type Validator = crate::Validator; pub type Transcript = PubliclyVerifiableSS; pub type ValidatorMessage = (Validator, Transcript); +#[cfg(feature = "bindings-python")] +use crate::bindings_python; pub use crate::EthereumAddress; use crate::{ do_verify_aggregation, Error, PVSSMap, PubliclyVerifiableParams, @@ -101,6 +103,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) } } From cea467e0bd48a096f70dd1c7ca24a7e4bd88b3d4 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Thu, 13 Jul 2023 10:16:09 +0200 Subject: [PATCH 7/9] add equality to FerveoVariant python bindings --- ferveo-python/ferveo/__init__.pyi | 19 ++++++++++++++++++ ferveo-python/test/test_serialization.py | 3 +++ ferveo/src/api.rs | 13 +++++++++++- ferveo/src/bindings_python.rs | 10 +++++----- ferveo/src/bindings_wasm.rs | 25 +++++++++++++++++++----- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 6c32cdc4..51f982a6 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -1,5 +1,6 @@ from typing import Sequence, final + @final class Keypair: @staticmethod @@ -24,6 +25,7 @@ class Keypair: def public_key(self) -> FerveoPublicKey: ... + @final class FerveoPublicKey: @staticmethod @@ -40,6 +42,10 @@ class FerveoPublicKey: def serialized_size() -> int: ... + def __eq__(self, other: object) -> bool: + ... + + @final class Validator: @@ -50,6 +56,7 @@ class Validator: public_key: FerveoPublicKey + @final class Transcript: @staticmethod @@ -59,6 +66,7 @@ class Transcript: def __bytes__(self) -> bytes: ... + @final class DkgPublicKey: @staticmethod @@ -72,6 +80,7 @@ class DkgPublicKey: def serialized_size() -> int: ... + @final class ValidatorMessage: @@ -85,6 +94,7 @@ class ValidatorMessage: validator: Validator transcript: Transcript + @final class Dkg: @@ -106,6 +116,7 @@ class Dkg: def aggregate_transcripts(self, messages: Sequence[ValidatorMessage]) -> AggregatedTranscript: ... + @final class Ciphertext: @staticmethod @@ -115,6 +126,7 @@ class Ciphertext: def __bytes__(self) -> bytes: ... + @final class DecryptionShareSimple: @staticmethod @@ -123,6 +135,8 @@ class DecryptionShareSimple: def __bytes__(self) -> bytes: ... + + @final class DecryptionSharePrecomputed: @staticmethod @@ -132,6 +146,7 @@ class DecryptionSharePrecomputed: def __bytes__(self) -> bytes: ... + @final class AggregatedTranscript: @@ -166,6 +181,7 @@ class AggregatedTranscript: def __bytes__(self) -> bytes: ... + @final class SharedSecret: @@ -182,6 +198,9 @@ class FerveoVariant: simple: FerveoVariant precomputed: FerveoVariant + def __eq__(self, other: object) -> bool: + ... + def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: ... diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py index 9eaccdbd..78e07868 100644 --- a/ferveo-python/test/test_serialization.py +++ b/ferveo-python/test/test_serialization.py @@ -83,3 +83,6 @@ def test_public_key_serialization(): def test_ferveo_variant_serialization(): assert str(FerveoVariant.precomputed) == "FerveoVariant::Precomputed" assert str(FerveoVariant.simple) == "FerveoVariant::Simple" + assert FerveoVariant.precomputed == FerveoVariant.precomputed + assert FerveoVariant.simple == FerveoVariant.simple + assert FerveoVariant.precomputed != FerveoVariant.simple diff --git a/ferveo/src/api.rs b/ferveo/src/api.rs index c909cfed..ccf9ff5f 100644 --- a/ferveo/src/api.rs +++ b/ferveo/src/api.rs @@ -23,6 +23,8 @@ pub type ValidatorMessage = (Validator, Transcript); #[cfg(feature = "bindings-python")] use crate::bindings_python; +#[cfg(feature = "bindings-wasm")] +use crate::bindings_wasm; pub use crate::EthereumAddress; use crate::{ do_verify_aggregation, Error, PVSSMap, PubliclyVerifiableParams, @@ -72,7 +74,9 @@ pub fn decrypt_with_shared_secret( } /// The ferveo variant to use for the decryption share derivation. -#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Copy, Clone)] +#[derive( + PartialEq, Eq, Debug, Serialize, Deserialize, Copy, Clone, PartialOrd, +)] pub enum FerveoVariant { /// The simple variant requires m of n shares to decrypt Simple, @@ -110,6 +114,13 @@ impl From for FerveoVariant { } } +#[cfg(feature = "bindings-wasm")] +impl From for FerveoVariant { + fn from(variant: bindings_wasm::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 51088e23..c01dffc4 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -271,7 +271,9 @@ pub fn decrypt_with_shared_secret( } #[pyclass(module = "ferveo")] -#[derive(Clone)] +#[derive( + Clone, PartialEq, PartialOrd, Eq, derive_more::From, derive_more::AsRef, +)] pub struct FerveoVariant(pub(crate) api::FerveoVariant); #[pymethods] @@ -289,11 +291,9 @@ impl FerveoVariant { fn __str__(&self) -> String { self.0.to_string() } -} -impl From for FerveoVariant { - fn from(variant: api::FerveoVariant) -> Self { - Self(variant) + fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult { + richcmp(self, other, op) } } diff --git a/ferveo/src/bindings_wasm.rs b/ferveo/src/bindings_wasm.rs index ab610160..7b9ae484 100644 --- a/ferveo/src/bindings_wasm.rs +++ b/ferveo/src/bindings_wasm.rs @@ -162,18 +162,33 @@ macro_rules! generate_common_methods { } #[wasm_bindgen] -pub struct FerveoVariant {} +#[derive(Clone, Debug, derive_more::AsRef, derive_more::From)] +pub struct FerveoVariant(pub(crate) api::FerveoVariant); + +impl fmt::Display for FerveoVariant { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self.0) + } +} + +generate_common_methods!(FerveoVariant); #[wasm_bindgen] impl FerveoVariant { #[wasm_bindgen(js_name = "precomputed", getter)] - pub fn precomputed() -> String { - api::FerveoVariant::Precomputed.as_str().to_string() + pub fn precomputed() -> FerveoVariant { + FerveoVariant(api::FerveoVariant::Precomputed) } #[wasm_bindgen(js_name = "simple", getter)] - pub fn simple() -> String { - api::FerveoVariant::Simple.as_str().to_string() + pub fn simple() -> FerveoVariant { + FerveoVariant(api::FerveoVariant::Simple) + } + + #[allow(clippy::inherent_to_string_shadow_display)] + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.0.to_string() } } From 06321d798fc30768173eec447aed753c34890194 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Fri, 14 Jul 2023 08:45:26 +0200 Subject: [PATCH 8/9] add __hash__ to FerveoVariant --- ferveo-python/ferveo/__init__.pyi | 3 +++ ferveo/src/bindings_python.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 51f982a6..4b5aaa4c 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -201,6 +201,9 @@ class FerveoVariant: def __eq__(self, other: object) -> bool: ... + def __hash__(self) -> int: + ... + def encrypt(message: bytes, aad: bytes, dkg_public_key: DkgPublicKey) -> Ciphertext: ... diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index c01dffc4..8ee06dbd 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -295,6 +295,14 @@ impl FerveoVariant { fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult { richcmp(self, other, op) } + + fn __hash__(&self) -> PyResult { + let bytes = self + .0 + .to_bytes() + .map_err(|err| FerveoPythonError::Other(err.to_string()))?; + hash("FerveoVariant", &bytes) + } } impl fmt::Display for FerveoVariant { From 0e7c5615a0660a69077e7b431dd24c5bb3d0f10d Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Fri, 14 Jul 2023 09:51:40 +0200 Subject: [PATCH 9/9] rename FerveoVariant attributes --- ferveo-python/ferveo/__init__.pyi | 4 +-- ferveo-python/test/test_ferveo.py | 42 ++++++++++++------------ ferveo-python/test/test_serialization.py | 10 +++--- ferveo/src/bindings_python.rs | 2 ++ 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ferveo-python/ferveo/__init__.pyi b/ferveo-python/ferveo/__init__.pyi index 4b5aaa4c..1dfab2f0 100644 --- a/ferveo-python/ferveo/__init__.pyi +++ b/ferveo-python/ferveo/__init__.pyi @@ -195,8 +195,8 @@ class SharedSecret: @final class FerveoVariant: - simple: FerveoVariant - precomputed: FerveoVariant + Simple: FerveoVariant + Precomputed: FerveoVariant def __eq__(self, other: object) -> bool: ... diff --git a/ferveo-python/test/test_ferveo.py b/ferveo-python/test/test_ferveo.py index 9406a5ae..7d93c637 100644 --- a/ferveo-python/test/test_ferveo.py +++ b/ferveo-python/test/test_ferveo.py @@ -21,25 +21,25 @@ def gen_eth_addr(i: int) -> str: def decryption_share_for_variant(v: FerveoVariant, agg_transcript): - if v == FerveoVariant.simple: + if v == FerveoVariant.Simple: return agg_transcript.create_decryption_share_simple - elif v == FerveoVariant.precomputed: + elif v == FerveoVariant.Precomputed: return agg_transcript.create_decryption_share_precomputed else: raise ValueError("Unknown variant") def combine_shares_for_variant(v: FerveoVariant, decryption_shares): - if v == FerveoVariant.simple: + if v == FerveoVariant.Simple: return combine_decryption_shares_simple(decryption_shares) - elif v == FerveoVariant.precomputed: + elif v == FerveoVariant.Precomputed: return combine_decryption_shares_precomputed(decryption_shares) else: raise ValueError("Unknown variant") def scenario_for_variant(variant: FerveoVariant, shares_num, threshold, shares_to_use): - if variant not in [FerveoVariant.simple, FerveoVariant.precomputed]: + if variant not in [FerveoVariant.Simple, FerveoVariant.Precomputed]: raise ValueError("Unknown variant: " + variant) tau = 1 @@ -99,12 +99,12 @@ def scenario_for_variant(variant: FerveoVariant, shares_num, threshold, shares_t shared_secret = combine_shares_for_variant(variant, decryption_shares) - if variant == FerveoVariant.simple and len(decryption_shares) < threshold: + if variant == FerveoVariant.Simple and len(decryption_shares) < threshold: with pytest.raises(ThresholdEncryptionError): decrypt_with_shared_secret(ciphertext, aad, shared_secret) return - if variant == FerveoVariant.precomputed and len(decryption_shares) < shares_num: + if variant == FerveoVariant.Precomputed and len(decryption_shares) < shares_num: with pytest.raises(ThresholdEncryptionError): decrypt_with_shared_secret(ciphertext, aad, shared_secret) return @@ -114,32 +114,32 @@ def scenario_for_variant(variant: FerveoVariant, shares_num, threshold, shares_t def test_simple_tdec_has_enough_messages(): - scenario_for_variant(FerveoVariant.simple, shares_num=4, threshold=3, shares_to_use=3) + scenario_for_variant(FerveoVariant.Simple, shares_num=4, threshold=3, shares_to_use=3) def test_simple_tdec_doesnt_have_enough_messages(): - scenario_for_variant(FerveoVariant.simple, shares_num=4, threshold=3, shares_to_use=2) + scenario_for_variant(FerveoVariant.Simple, shares_num=4, threshold=3, shares_to_use=2) def test_precomputed_tdec_has_enough_messages(): - scenario_for_variant(FerveoVariant.precomputed, shares_num=4, threshold=4, shares_to_use=4) + scenario_for_variant(FerveoVariant.Precomputed, shares_num=4, threshold=4, shares_to_use=4) def test_precomputed_tdec_doesnt_have_enough_messages(): - scenario_for_variant(FerveoVariant.precomputed, shares_num=4, threshold=4, shares_to_use=3) + scenario_for_variant(FerveoVariant.Precomputed, shares_num=4, threshold=4, shares_to_use=3) PARAMS = [ - (1, FerveoVariant.simple), - (3, FerveoVariant.simple), - (4, FerveoVariant.simple), - (7, FerveoVariant.simple), - (8, FerveoVariant.simple), - (1, FerveoVariant.precomputed), - (3, FerveoVariant.precomputed), - (4, FerveoVariant.precomputed), - (7, FerveoVariant.precomputed), - (8, FerveoVariant.precomputed), + (1, FerveoVariant.Simple), + (3, FerveoVariant.Simple), + (4, FerveoVariant.Simple), + (7, FerveoVariant.Simple), + (8, FerveoVariant.Simple), + (1, FerveoVariant.Precomputed), + (3, FerveoVariant.Precomputed), + (4, FerveoVariant.Precomputed), + (7, FerveoVariant.Precomputed), + (8, FerveoVariant.Precomputed), ] TEST_CASES_WITH_THRESHOLD_RANGE = [] diff --git a/ferveo-python/test/test_serialization.py b/ferveo-python/test/test_serialization.py index 78e07868..8533d437 100644 --- a/ferveo-python/test/test_serialization.py +++ b/ferveo-python/test/test_serialization.py @@ -81,8 +81,8 @@ def test_public_key_serialization(): def test_ferveo_variant_serialization(): - assert str(FerveoVariant.precomputed) == "FerveoVariant::Precomputed" - assert str(FerveoVariant.simple) == "FerveoVariant::Simple" - assert FerveoVariant.precomputed == FerveoVariant.precomputed - assert FerveoVariant.simple == FerveoVariant.simple - assert FerveoVariant.precomputed != FerveoVariant.simple + assert str(FerveoVariant.Precomputed) == "FerveoVariant::Precomputed" + assert str(FerveoVariant.Simple) == "FerveoVariant::Simple" + assert FerveoVariant.Precomputed == FerveoVariant.Precomputed + assert FerveoVariant.Simple == FerveoVariant.Simple + assert FerveoVariant.Precomputed != FerveoVariant.Simple diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index 8ee06dbd..7d1cb93b 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -279,11 +279,13 @@ pub struct FerveoVariant(pub(crate) api::FerveoVariant); #[pymethods] impl FerveoVariant { #[classattr] + #[pyo3(name = "Precomputed")] fn precomputed() -> FerveoVariant { api::FerveoVariant::Precomputed.into() } #[classattr] + #[pyo3(name = "Simple")] fn simple() -> FerveoVariant { api::FerveoVariant::Simple.into() }