diff --git a/umbral-pre-python/src/lib.rs b/umbral-pre-python/src/lib.rs index aaa01780..0e8ace63 100644 --- a/umbral-pre-python/src/lib.rs +++ b/umbral-pre-python/src/lib.rs @@ -16,6 +16,9 @@ use umbral_pre::{ trait HasSerializableBackend { fn as_backend(&self) -> &T; fn from_backend(backend: T) -> Self; +} + +trait HasName { fn name() -> &'static str; } @@ -26,7 +29,9 @@ fn to_bytes, U: SerializableToArray>(obj: &T) -> Py }) } -fn from_bytes, U: SerializableToArray>(bytes: &[u8]) -> PyResult { +fn from_bytes + HasName, U: SerializableToArray>( + bytes: &[u8], +) -> PyResult { U::from_bytes(bytes) .map(T::from_backend) .map_err(|err| match err { @@ -42,7 +47,9 @@ fn from_bytes, U: SerializableToArray>(bytes: &[u8] }) } -fn hash, U: SerializableToArray>(obj: &T) -> PyResult { +fn hash + HasName, U: SerializableToArray>( + obj: &T, +) -> PyResult { let serialized = obj.as_backend().to_array(); // call `hash((class_name, bytes(obj)))` @@ -58,12 +65,14 @@ fn hash, U: SerializableToArray>(obj: &T) -> PyResu // remove when CI is updated to a newer Rust version. #[allow(clippy::unknown_clippy_lints)] #[allow(clippy::unnecessary_wraps)] // Don't want to wrap it in Ok() on every call -fn hexstr, U: SerializableToArray>(obj: &T) -> PyResult { +fn hexstr + HasName, U: SerializableToArray>( + obj: &T, +) -> PyResult { let hex_str = hex::encode(obj.as_backend().to_array().as_slice()); Ok(format!("{}:{}", T::name(), &hex_str[0..16])) } -fn richcmp + PyClass + PartialEq, U>( +fn richcmp( obj: &T, other: PyRef, op: CompareOp, @@ -94,7 +103,9 @@ impl HasSerializableBackend for SecretKey { fn from_backend(backend: umbral_pre::SecretKey) -> Self { Self { backend } } +} +impl HasName for SecretKey { fn name() -> &'static str { "SecretKey" } @@ -144,7 +155,9 @@ impl HasSerializableBackend for SecretKeyFactory { fn from_backend(backend: umbral_pre::SecretKeyFactory) -> Self { Self { backend } } +} +impl HasName for SecretKeyFactory { fn name() -> &'static str { "SecretKeyFactory" } @@ -208,7 +221,9 @@ impl HasSerializableBackend for PublicKey { fn from_backend(backend: umbral_pre::PublicKey) -> Self { Self { backend } } +} +impl HasName for PublicKey { fn name() -> &'static str { "PublicKey" } @@ -262,7 +277,9 @@ impl HasSerializableBackend for Capsule { fn from_backend(backend: umbral_pre::Capsule) -> Self { Self { backend } } +} +impl HasName for Capsule { fn name() -> &'static str { "Capsule" } @@ -352,7 +369,9 @@ impl HasSerializableBackend for KeyFrag { fn from_backend(backend: umbral_pre::KeyFrag) -> Self { Self { backend } } +} +impl HasName for KeyFrag { fn name() -> &'static str { "KeyFrag" } @@ -440,7 +459,9 @@ impl HasSerializableBackend for CapsuleFrag { fn from_backend(backend: umbral_pre::CapsuleFrag) -> Self { Self { backend } } +} +impl HasName for CapsuleFrag { fn name() -> &'static str { "CapsuleFrag" }