Skip to content

Commit

Permalink
Revert "Remove Deref impl for BLS structs"
Browse files Browse the repository at this point in the history
This reverts commit 7149b1a.
  • Loading branch information
tessico committed Dec 7, 2022
1 parent 7d6dcfa commit 0d29835
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
37 changes: 27 additions & 10 deletions primitives/src/signatures/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -174,7 +198,7 @@ impl SignatureScheme for BLSSignatureScheme {
msg: M,
_prng: &mut R,
) -> Result<Self::Signature, PrimitivesError> {
Ok(BLSSignature(sk.0.sign(
Ok(BLSSignature(sk.sign(
msg.as_ref(),
Self::CS_ID.as_bytes(),
&[],
Expand All @@ -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))),
}
Expand Down
4 changes: 2 additions & 2 deletions primitives/src/vrf/blsvrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Vrf for BLSVRFScheme {
_pp: &Self::PublicParameter,
proof: &Self::Proof,
) -> Result<Self::Output, PrimitivesError> {
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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0d29835

Please sign in to comment.