From eca28fd3e8b6198e3d994ca258f34068e57b8434 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 28 Feb 2017 19:08:37 -0800 Subject: [PATCH] Refactor Scalar::hash_from_bytes to allow streaming input to the hash. --- src/scalar.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scalar.rs b/src/scalar.rs index f7808e3..62e6183 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -173,6 +173,8 @@ impl Scalar { /// Takes a type parameter `D`, which is any `Digest` producing 64 /// bytes (512 bits) of output. /// + /// Convenience wrapper around `from_hash`. + /// /// # Example /// /// ``` @@ -193,6 +195,16 @@ impl Scalar { where D: Digest + Default { let mut hash = D::default(); hash.input(input); + Scalar::from_hash(hash) + } + + /// Construct a scalar from an existing `Digest` instance. + /// + /// Use this instead of `hash_from_bytes` if it is more convenient + /// to stream data into the `Digest` than to pass a single byte + /// slice. + pub fn from_hash(hash: D) -> Scalar + where D: Digest + Default { // XXX this seems clumsy let mut output = [0u8;64]; output.copy_from_slice(hash.result().as_slice());