Skip to content

Commit

Permalink
rename existing Error to SignatureError
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed May 9, 2021
1 parent ace14eb commit 5d13f77
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Item {
/// borrowing the message data, the `Item` type is unlinked from the lifetime of
/// the message.
#[allow(non_snake_case)]
pub fn verify_single(self) -> Result<(), Error> {
pub fn verify_single(self) -> Result<(), SignatureError> {
match self.inner {
Inner::Binding { vk_bytes, sig, c } => VerificationKey::<Binding>::try_from(vk_bytes)
.and_then(|vk| vk.verify_prehashed(&sig, c)),
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Verifier {
///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#reddsabatchverify
#[allow(non_snake_case)]
pub fn verify<R: RngCore + CryptoRng>(self, mut rng: R) -> Result<(), Error> {
pub fn verify<R: RngCore + CryptoRng>(self, mut rng: R) -> Result<(), SignatureError> {
let n = self.signatures.len();

let mut VK_coeffs = Vec::with_capacity(n);
Expand All @@ -200,7 +200,7 @@ impl Verifier {
if maybe_scalar.is_some().into() {
maybe_scalar.unwrap()
} else {
return Err(Error::InvalidSignature);
return Err(SignatureError::Invalid);
}
};

Expand All @@ -211,7 +211,7 @@ impl Verifier {
if maybe_point.is_some().into() {
jubjub::ExtendedPoint::from(maybe_point.unwrap())
} else {
return Err(Error::InvalidSignature);
return Err(SignatureError::Invalid);
}
};

Expand Down Expand Up @@ -258,7 +258,7 @@ impl Verifier {
if check.is_small_order().into() {
Ok(())
} else {
Err(Error::InvalidSignature)
Err(SignatureError::Invalid)
}
}
}
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use thiserror::Error;

/// An error related to RedJubJub signatures.
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
pub enum Error {
pub enum SignatureError {
/// The encoding of a signing key was malformed.
#[error("Malformed signing key encoding.")]
MalformedSigningKey,
Expand All @@ -21,5 +21,5 @@ pub enum Error {
MalformedVerificationKey,
/// Signature verification failed.
#[error("Invalid signature.")]
InvalidSignature,
Invalid,
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub type Randomizer = jubjub::Scalar;

use hash::HStar;

pub use error::Error;
pub use error::SignatureError;
pub use signature::Signature;
pub use signing_key::SigningKey;
pub use verification_key::{VerificationKey, VerificationKeyBytes};
Expand Down
8 changes: 4 additions & 4 deletions src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
marker::PhantomData,
};

use crate::{Error, Randomizer, SigType, Signature, SpendAuth, VerificationKey};
use crate::{error::SignatureError, Randomizer, SigType, Signature, SpendAuth, VerificationKey};

use jubjub::Scalar;
use rand_core::{CryptoRng, RngCore};
Expand Down Expand Up @@ -42,7 +42,7 @@ impl<T: SigType> From<SigningKey<T>> for [u8; 32] {
}

impl<T: SigType> TryFrom<[u8; 32]> for SigningKey<T> {
type Error = Error;
type Error = SignatureError;

fn try_from(bytes: [u8; 32]) -> Result<Self, Self::Error> {
// XXX-jubjub: this should not use CtOption
Expand All @@ -52,7 +52,7 @@ impl<T: SigType> TryFrom<[u8; 32]> for SigningKey<T> {
let pk = VerificationKey::from(&sk);
Ok(SigningKey { sk, pk })
} else {
Err(Error::MalformedSigningKey)
Err(SignatureError::MalformedSigningKey)
}
}
}
Expand All @@ -61,7 +61,7 @@ impl<T: SigType> TryFrom<[u8; 32]> for SigningKey<T> {
struct SerdeHelper([u8; 32]);

impl<T: SigType> TryFrom<SerdeHelper> for SigningKey<T> {
type Error = Error;
type Error = SignatureError;

fn try_from(helper: SerdeHelper) -> Result<Self, Self::Error> {
helper.0.try_into()
Expand Down
20 changes: 10 additions & 10 deletions src/verification_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{

use jubjub::Scalar;

use crate::{Error, Randomizer, SigType, Signature, SpendAuth};
use crate::{error::SignatureError, Randomizer, SigType, Signature, SpendAuth};

/// A refinement type for `[u8; 32]` indicating that the bytes represent
/// an encoding of a RedJubJub verification key.
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<T: SigType> From<VerificationKey<T>> for [u8; 32] {
}

impl<T: SigType> TryFrom<VerificationKeyBytes<T>> for VerificationKey<T> {
type Error = Error;
type Error = SignatureError;

fn try_from(bytes: VerificationKeyBytes<T>) -> Result<Self, Self::Error> {
// XXX-jubjub: this should not use CtOption
Expand All @@ -103,16 +103,16 @@ impl<T: SigType> TryFrom<VerificationKeyBytes<T>> for VerificationKey<T> {
if <bool>::from(point.is_small_order()) == false {
Ok(VerificationKey { point, bytes })
} else {
Err(Error::MalformedVerificationKey)
Err(SignatureError::MalformedVerificationKey)
}
} else {
Err(Error::MalformedVerificationKey)
Err(SignatureError::MalformedVerificationKey)
}
}
}

impl<T: SigType> TryFrom<[u8; 32]> for VerificationKey<T> {
type Error = Error;
type Error = SignatureError;

fn try_from(bytes: [u8; 32]) -> Result<Self, Self::Error> {
use std::convert::TryInto;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<T: SigType> VerificationKey<T> {

/// Verify a purported `signature` over `msg` made by this verification key.
// This is similar to impl signature::Verifier but without boxed errors
pub fn verify(&self, msg: &[u8], signature: &Signature<T>) -> Result<(), Error> {
pub fn verify(&self, msg: &[u8], signature: &Signature<T>) -> Result<(), SignatureError> {
use crate::HStar;
let c = HStar::default()
.update(&signature.r_bytes[..])
Expand All @@ -163,15 +163,15 @@ impl<T: SigType> VerificationKey<T> {
&self,
signature: &Signature<T>,
c: Scalar,
) -> Result<(), Error> {
) -> Result<(), SignatureError> {
let r = {
// XXX-jubjub: should not use CtOption here
// XXX-jubjub: inconsistent ownership in from_bytes
let maybe_point = jubjub::AffinePoint::from_bytes(signature.r_bytes);
if maybe_point.is_some().into() {
jubjub::ExtendedPoint::from(maybe_point.unwrap())
} else {
return Err(Error::InvalidSignature);
return Err(SignatureError::Invalid);
}
};

Expand All @@ -181,7 +181,7 @@ impl<T: SigType> VerificationKey<T> {
if maybe_scalar.is_some().into() {
maybe_scalar.unwrap()
} else {
return Err(Error::InvalidSignature);
return Err(SignatureError::Invalid);
}
};

Expand All @@ -195,7 +195,7 @@ impl<T: SigType> VerificationKey<T> {
if check.is_small_order().into() {
Ok(())
} else {
Err(Error::InvalidSignature)
Err(SignatureError::Invalid)
}
}
}

0 comments on commit 5d13f77

Please sign in to comment.