From b582ba749b36b84ad812314c456b0954a37ff9ba Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 18 Sep 2016 11:04:18 -0600 Subject: [PATCH] Split off U512 interpretation. --- src/arith.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/arith.rs b/src/arith.rs index eefc702..709a523 100644 --- a/src/arith.rs +++ b/src/arith.rs @@ -78,6 +78,15 @@ impl U512 { (q, r) } } + + pub fn interpret(buf: &[u8; 64]) -> U512 { + let mut n = [0; 8]; + for (l, i) in (0..8).rev().zip((0..8).map(|i| i * 8)) { + n[l] = BigEndian::read_u64(&buf[i..]); + } + + U512(n) + } } impl Encodable for U512 { @@ -104,12 +113,7 @@ impl Decodable for U512 { buf[i] = try!(s.read_u8()); } - let mut n = [0; 8]; - for (l, i) in (0..8).rev().zip((0..8).map(|i| i * 8)) { - n[l] = BigEndian::read_u64(&buf[i..]); - } - - Ok(U512(n)) + Ok(U512::interpret(&buf)) } }