Carry the interpreted value of the encoding through the error.

This commit is contained in:
Sean Bowe 2017-07-17 10:31:22 -06:00
parent 09531d0810
commit 1027dda432
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
3 changed files with 9 additions and 5 deletions

View File

@ -408,7 +408,7 @@ impl PrimeField for Fq {
Ok(r) Ok(r)
} else { } else {
Err(PrimeFieldDecodingError::NotInField) Err(PrimeFieldDecodingError::NotInField(format!("{:?}", r.0)))
} }
} }

View File

@ -229,7 +229,7 @@ impl PrimeField for Fr {
Ok(r) Ok(r)
} else { } else {
Err(PrimeFieldDecodingError::NotInField) Err(PrimeFieldDecodingError::NotInField(format!("{:?}", r.0)))
} }
} }

View File

@ -365,20 +365,24 @@ pub trait PrimeFieldRepr: Sized +
#[derive(Debug)] #[derive(Debug)]
pub enum PrimeFieldDecodingError { pub enum PrimeFieldDecodingError {
// The encoded value is not in the field // The encoded value is not in the field
NotInField NotInField(String)
} }
impl Error for PrimeFieldDecodingError { impl Error for PrimeFieldDecodingError {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { match self {
&PrimeFieldDecodingError::NotInField => "not an element in the field" &PrimeFieldDecodingError::NotInField(..) => "not an element of the field"
} }
} }
} }
impl fmt::Display for PrimeFieldDecodingError { impl fmt::Display for PrimeFieldDecodingError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.description()) match self {
&PrimeFieldDecodingError::NotInField(ref repr) => {
write!(f, "{} is not an element of the field", repr)
}
}
} }
} }