Marge fixes to test_harness, add serdehex crate

This commit is contained in:
Paul Hauner
2019-03-15 13:31:30 +11:00
parent 69100a0c03
commit 236b97476a
32 changed files with 355 additions and 92 deletions

View File

@@ -2,7 +2,9 @@ use super::{AggregatePublicKey, Signature};
use bls_aggregates::{
AggregatePublicKey as RawAggregatePublicKey, AggregateSignature as RawAggregateSignature,
};
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, PrefixedHexVisitor};
use ssz::{
decode_ssz_list, hash, ssz_encode, Decodable, DecodeError, Encodable, SszStream, TreeHash,
};
@@ -82,7 +84,19 @@ impl Serialize for AggregateSignature {
where
S: Serializer,
{
serializer.serialize_bytes(&ssz_encode(self))
serializer.serialize_str(&hex_encode(ssz_encode(self)))
}
}
impl<'de> Deserialize<'de> for AggregateSignature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let bytes = deserializer.deserialize_str(PrefixedHexVisitor)?;
let (obj, _) = <_>::ssz_decode(&bytes[..], 0)
.map_err(|e| serde::de::Error::custom(format!("invalid ssz ({:?})", e)))?;
Ok(obj)
}
}