Begin updating serde such that it can read the yaml test files

This commit is contained in:
Kirk Baird
2019-03-19 18:05:05 +11:00
parent 37b8e9f39a
commit 26f8694161
9 changed files with 708 additions and 313 deletions

View File

@@ -8,13 +8,13 @@ impl<'de> Visitor<'de> for HexVisitor {
type Value = Vec<u8>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a hex string (without 0x prefix)")
formatter.write_str("a hex string (irrelevant of prefix)")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(hex::decode(value).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?)
Ok(hex::decode(value.trim_start_matches("0x")).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?)
}
}

View File

@@ -73,7 +73,7 @@ impl Encodable for Signature {
impl Decodable for Signature {
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
let (sig_bytes, i) = decode_ssz_list(bytes, i)?;
let raw_sig = RawSignature::from_bytes(&sig_bytes).map_err(|_| DecodeError::TooShort)?;
let raw_sig = RawSignature::from_bytes(&sig_bytes).map_err(|_| DecodeError::Invalid)?;
Ok((Signature(raw_sig), i))
}
}