Fix SSZ for bls fake_crypto features

This commit is contained in:
Paul Hauner 2019-05-13 12:23:06 +10:00
parent eb62b5842d
commit 03fee2fb97
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 38 additions and 2 deletions

View File

@ -3,7 +3,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, PrefixedHexVisitor};
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
use ssz::{ssz_encode, Decodable, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A BLS aggregate signature.
@ -57,6 +57,24 @@ impl FakeAggregateSignature {
) -> bool {
true
}
/// Convert bytes to fake BLS aggregate signature
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
if bytes.len() != BLS_AGG_SIG_BYTE_SIZE {
Err(DecodeError::InvalidByteLength {
len: bytes.len(),
expected: BLS_AGG_SIG_BYTE_SIZE,
})
} else {
Ok(Self {
bytes: bytes.to_vec(),
})
}
}
pub fn as_bytes(&self) -> Vec<u8> {
self.bytes.clone()
}
}
impl_ssz!(

View File

@ -4,7 +4,7 @@ use hex::encode as hex_encode;
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_hex::HexVisitor;
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
use ssz::{ssz_encode, Decodable, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A single BLS signature.
@ -49,6 +49,24 @@ impl FakeSignature {
true
}
/// Convert bytes to fake BLS Signature
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
if bytes.len() != BLS_SIG_BYTE_SIZE {
Err(DecodeError::InvalidByteLength {
len: bytes.len(),
expected: BLS_SIG_BYTE_SIZE,
})
} else {
Ok(Self {
bytes: bytes.to_vec(),
})
}
}
pub fn as_bytes(&self) -> Vec<u8> {
self.bytes.clone()
}
/// Returns a new empty signature.
pub fn empty_signature() -> Self {
FakeSignature::zero()