From 06321d798fc30768173eec447aed753c34890194 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Fri, 14 Jul 2023 08:45:26 +0200 Subject: [PATCH] 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 {