From 5c1458ba46832911a32fb2df1e6fbcbb79298a6f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 8 Mar 2019 13:19:37 +1100 Subject: [PATCH] Add bls serde_vistors file --- eth2/utils/bls/src/serde_vistors.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 eth2/utils/bls/src/serde_vistors.rs diff --git a/eth2/utils/bls/src/serde_vistors.rs b/eth2/utils/bls/src/serde_vistors.rs new file mode 100644 index 000000000..55eadb883 --- /dev/null +++ b/eth2/utils/bls/src/serde_vistors.rs @@ -0,0 +1,20 @@ +use hex; +use serde::de::{self, Visitor}; +use std::fmt; + +pub struct HexVisitor; + +impl<'de> Visitor<'de> for HexVisitor { + type Value = Vec; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a hex string (without 0x prefix)") + } + + fn visit_str(self, value: &str) -> Result + where + E: de::Error, + { + Ok(hex::decode(value).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?) + } +}