From b8fa5ec3e0c5c1a26f12411a9bac0be3b4ef3d20 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 26 Sep 2018 02:07:15 +0000 Subject: [PATCH] Add constructors for compressed points from slices. --- src/edwards.rs | 15 +++++++++++++++ src/ristretto.rs | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/edwards.rs b/src/edwards.rs index 68e6b9f..919bcb1 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -271,6 +271,21 @@ impl Default for CompressedEdwardsY { } } +impl CompressedEdwardsY { + /// Construct a `CompressedEdwardsY` from a slice of bytes. + /// + /// # Panics + /// + /// If the input `bytes` slice does not have a length of 32. + pub fn from_slice(bytes: &[u8]) -> CompressedEdwardsY { + let mut tmp = [0u8; 32]; + + tmp.copy_from_slice(bytes); + + CompressedEdwardsY(tmp) + } +} + impl Identity for EdwardsPoint { fn identity() -> EdwardsPoint { EdwardsPoint{ X: FieldElement::zero(), diff --git a/src/ristretto.rs b/src/ristretto.rs index 92c0b39..b606c9a 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -213,6 +213,19 @@ impl CompressedRistretto { &self.0 } + /// Construct a `CompressedRistretto` from a slice of bytes. + /// + /// # Panics + /// + /// If the input `bytes` slice does not have a length of 32. + pub fn from_slice(bytes: &[u8]) -> CompressedRistretto { + let mut tmp = [0u8; 32]; + + tmp.copy_from_slice(bytes); + + CompressedRistretto(tmp) + } + /// Attempt to decompress to an `RistrettoPoint`. /// /// # Return