Merge pull request #198 from isislovecruft/feature/add-compressed-from_slice

Add constructors for compressed points from slices.
This commit is contained in:
Henry de Valence 2018-09-26 15:53:31 -07:00 committed by GitHub
commit dc2a895a83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -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 { impl Identity for EdwardsPoint {
fn identity() -> EdwardsPoint { fn identity() -> EdwardsPoint {
EdwardsPoint{ X: FieldElement::zero(), EdwardsPoint{ X: FieldElement::zero(),

View file

@ -213,6 +213,19 @@ impl CompressedRistretto {
&self.0 &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`. /// Attempt to decompress to an `RistrettoPoint`.
/// ///
/// # Return /// # Return