From 0d29835634ea9450919f6d1c3dcbdb57b13ec24d Mon Sep 17 00:00:00 2001 From: tessico Date: Wed, 30 Nov 2022 17:47:46 +0100 Subject: [PATCH] Revert "Remove `Deref` impl for BLS structs" This reverts commit 7149b1a63e4562d70c87c5b18109e383b20dc48a. --- primitives/src/signatures/bls.rs | 37 +++++++++++++++++++++++--------- primitives/src/vrf/blsvrf.rs | 4 ++-- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/primitives/src/signatures/bls.rs b/primitives/src/signatures/bls.rs index 6468b97fd..a644f15b9 100644 --- a/primitives/src/signatures/bls.rs +++ b/primitives/src/signatures/bls.rs @@ -27,6 +27,14 @@ use zeroize::Zeroize; #[derive(Clone, Debug, Zeroize)] pub struct BLSSignKey(SecretKey); +impl core::ops::Deref for BLSSignKey { + type Target = SecretKey; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl CanonicalSerialize for BLSSignKey { fn serialized_size(&self) -> usize { BLS_SIG_KEY_SIZE @@ -64,7 +72,15 @@ impl Eq for BLSSignKey {} /// Newtype wrapper for a BLS Signature. #[tagged(tag::BLS_SIG)] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct BLSSignature(pub(crate) Signature); +pub struct BLSSignature(Signature); + +impl core::ops::Deref for BLSSignature { + type Target = Signature; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} impl CanonicalSerialize for BLSSignature { fn serialized_size(&self) -> usize { @@ -97,6 +113,14 @@ impl CanonicalDeserialize for BLSSignature { #[derive(Clone, Debug, PartialEq, Eq)] pub struct BLSVerKey(PublicKey); +impl core::ops::Deref for BLSVerKey { + type Target = PublicKey; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl CanonicalSerialize for BLSVerKey { fn serialized_size(&self) -> usize { BLS_SIG_VERKEY_SIZE @@ -174,7 +198,7 @@ impl SignatureScheme for BLSSignatureScheme { msg: M, _prng: &mut R, ) -> Result { - Ok(BLSSignature(sk.0.sign( + Ok(BLSSignature(sk.sign( msg.as_ref(), Self::CS_ID.as_bytes(), &[], @@ -188,14 +212,7 @@ impl SignatureScheme for BLSSignatureScheme { msg: M, sig: &Self::Signature, ) -> Result<(), PrimitivesError> { - match sig.0.verify( - false, - msg.as_ref(), - Self::CS_ID.as_bytes(), - &[], - &vk.0, - true, - ) { + match sig.verify(false, msg.as_ref(), Self::CS_ID.as_bytes(), &[], vk, true) { BLST_ERROR::BLST_SUCCESS => Ok(()), e => Err(PrimitivesError::VerificationError(format!("{:?}", e))), } diff --git a/primitives/src/vrf/blsvrf.rs b/primitives/src/vrf/blsvrf.rs index 050d506ca..b22004896 100644 --- a/primitives/src/vrf/blsvrf.rs +++ b/primitives/src/vrf/blsvrf.rs @@ -101,7 +101,7 @@ impl Vrf for BLSVRFScheme { _pp: &Self::PublicParameter, proof: &Self::Proof, ) -> Result { - let proof_serialized = proof.0.serialize(); + let proof_serialized = proof.serialize(); let mut hasher = (*self.hasher).box_clone(); hasher.update(&proof_serialized); let output = hasher.finalize(); @@ -151,7 +151,7 @@ mod test { // check the VRF output vs. hashing the proof directly let mut hasher = H::new(); - hasher.update(vrf_proof.0.serialize()); + hasher.update(vrf_proof.serialize()); let direct_hash_output = hasher.finalize().to_vec(); assert_eq!(direct_hash_output, vrf_output);