Skip to content

Commit

Permalink
fix: remove extra compress call during pubkey::deserialize (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Sep 6, 2021
2 parents 48b68d2 + 3862d28 commit 8864b5a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ristretto/ristretto_keys.rs
Expand Up @@ -213,12 +213,18 @@ pub struct RistrettoPublicKey {

impl RistrettoPublicKey {
// Private constructor
pub(crate) fn new_from_pk(pk: RistrettoPoint) -> RistrettoPublicKey {
pub(super) fn new_from_pk(pk: RistrettoPoint) -> RistrettoPublicKey {
RistrettoPublicKey {
point: pk,
compressed: pk.compress(),
}
}

pub(super) fn new_from_compressed(compressed: CompressedRistretto) -> Option<RistrettoPublicKey> {
compressed
.decompress()
.map(|point| RistrettoPublicKey { compressed, point })
}
}

impl PublicKey for RistrettoPublicKey {
Expand Down Expand Up @@ -332,12 +338,12 @@ impl ByteArray for RistrettoPublicKey {
if bytes.len() != 32 {
return Err(ByteArrayError::IncorrectLength);
}
let pk = CompressedRistretto::from_slice(bytes);
match pk.decompress() {
let compressed = CompressedRistretto::from_slice(bytes);
match RistrettoPublicKey::new_from_compressed(compressed) {
Some(p) => Ok(p),
None => Err(ByteArrayError::ConversionError(
"Invalid compressed Ristretto point".to_string(),
)),
Some(p) => Ok(RistrettoPublicKey::new_from_pk(p)),
}
}

Expand Down

0 comments on commit 8864b5a

Please sign in to comment.