more exposed

This commit is contained in:
NikVolf
2017-03-22 02:53:41 +03:00
parent 1645afdbec
commit 78cf02fd7b
+18
View File
@@ -27,6 +27,12 @@ impl Fr {
pub fn interpret(buf: &[u8; 64]) -> Fr {
Fr(fields::Fr::interpret(buf))
}
pub fn from_slice(slice: &[u8]) -> Result<Self, FieldError> {
arith::U256::from_slice(slice)
.map_err(|_| FieldError::InvalidSliceLength) // todo: maybe more sensful error handling
.and_then(|x| fields::Fr::new(x).ok_or(FieldError::NotMember))
.map(|x| Fr(x))
}
}
impl Add<Fr> for Fr {
@@ -53,6 +59,12 @@ impl Mul for Fr {
fn mul(self, other: Fr) -> Fr { Fr(self.0 * other.0) }
}
#[derive(Debug)]
pub enum FieldError {
InvalidSliceLength,
NotMember,
}
#[derive(Copy, Clone, PartialEq, Eq, RustcDecodable, RustcEncodable)]
#[repr(C)]
pub struct Fq(fields::Fq);
@@ -68,6 +80,12 @@ impl Fq {
pub fn interpret(buf: &[u8; 64]) -> Fq {
Fq(fields::Fq::interpret(buf))
}
pub fn from_slice(slice: &[u8]) -> Result<Self, FieldError> {
arith::U256::from_slice(slice)
.map_err(|_| FieldError::InvalidSliceLength) // todo: maybe more sensful error handling
.and_then(|x| fields::Fq::new(x).ok_or(FieldError::NotMember))
.map(|x| Fq(x))
}
}
impl Add<Fq> for Fq {