bls: debugging utils and fake sig fix

There was a discrepancy between the is_empty fields of fake signatures during testing, so I've added
a small hack to set the is_empty field of a fake signature based on the byte content.
Alternatively, we could just make it so that any fake signature is defined to be equal to any other.
This commit is contained in:
Michael Sproul 2019-06-12 15:44:23 +10:00
parent 64dca6fba7
commit 88790e6abe
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
4 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,4 @@
use super::{PublicKey, BLS_PUBLIC_KEY_BYTE_SIZE};
use milagro_bls::AggregatePublicKey as RawAggregatePublicKey;
/// A BLS aggregate public key.
///

View File

@ -1,6 +1,5 @@
use super::{SecretKey, BLS_PUBLIC_KEY_BYTE_SIZE};
use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
use milagro_bls::PublicKey as RawPublicKey;
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, HexVisitor};

View File

@ -59,9 +59,10 @@ impl FakeSignature {
expected: BLS_SIG_BYTE_SIZE,
})
} else {
let is_empty = bytes.iter().all(|x| *x == 0);
Ok(Self {
bytes: bytes.to_vec(),
is_empty: false,
is_empty,
})
}
}

View File

@ -101,6 +101,12 @@ impl Signature {
pub fn is_empty(&self) -> bool {
self.is_empty
}
/// Display a signature as a hex string of its bytes.
#[cfg(test)]
pub fn as_hex_string(&self) -> String {
hex_encode(self.as_bytes())
}
}
impl_ssz!(Signature, BLS_SIG_BYTE_SIZE, "Signature");