mirror of
https://github.com/arnaucube/testudo.git
synced 2026-02-06 11:16:45 +01:00
Refactor to idiomatic Result/Option patterns (#25)
This: - introduces a small [thiserror](https://github.com/dtolnay/thiserror)-powered enum to improve ProofVerifyError's messages, - refactors point decompression errors into a variant of that enum, thereby suppressing the panics which occur when decompresison fails. - folds other panics into the Error cases of their enclosing `Result` return
This commit is contained in:
committed by
GitHub
parent
7b102a241f
commit
9e4c166edb
16
src/group.rs
16
src/group.rs
@@ -1,9 +1,25 @@
|
||||
use super::errors::ProofVerifyError;
|
||||
use super::scalar::{Scalar, ScalarBytes, ScalarBytesFromScalar};
|
||||
use core::borrow::Borrow;
|
||||
use core::ops::{Mul, MulAssign};
|
||||
|
||||
pub type GroupElement = curve25519_dalek::ristretto::RistrettoPoint;
|
||||
pub type CompressedGroup = curve25519_dalek::ristretto::CompressedRistretto;
|
||||
|
||||
pub trait CompressedGroupExt {
|
||||
type Group;
|
||||
fn unpack(&self) -> Result<Self::Group, ProofVerifyError>;
|
||||
}
|
||||
|
||||
impl CompressedGroupExt for CompressedGroup {
|
||||
type Group = curve25519_dalek::ristretto::RistrettoPoint;
|
||||
fn unpack(&self) -> Result<Self::Group, ProofVerifyError> {
|
||||
self
|
||||
.decompress()
|
||||
.ok_or_else(|| ProofVerifyError::DecompressionError(self.to_bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
pub const GROUP_BASEPOINT_COMPRESSED: CompressedGroup =
|
||||
curve25519_dalek::constants::RISTRETTO_BASEPOINT_COMPRESSED;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user