Introduce static hex and valid signature for block test.

This commit is contained in:
Gav
2018-01-18 17:35:18 +01:00
parent 7f8949bed1
commit abb8304389
8 changed files with 144 additions and 17 deletions
@@ -0,0 +1,29 @@
use rustc_hex::FromHex;
pub trait StaticHexConversion: Sized {
fn from_static_hex(hex: &'static str) -> Self;
}
macro_rules! impl_sizes {
( $( $t:expr ),* ) => { $(
impl StaticHexConversion for [u8; $t] {
fn from_static_hex(hex: &'static str) -> Self {
let mut r = [0u8; $t];
r.copy_from_slice(&FromHex::from_hex(hex).unwrap());
r
}
}
)* }
}
impl_sizes!(1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128);
pub trait StaticHexInto {
fn convert<T: StaticHexConversion>(self) -> T;
}
impl StaticHexInto for &'static str {
fn convert<T: StaticHexConversion>(self) -> T {
T::from_static_hex(self)
}
}