mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-03 19:53:40 +00:00
Address code review
This commit is contained in:
parent
52902e6fdf
commit
025362ad5a
1 changed files with 14 additions and 8 deletions
|
|
@ -9,8 +9,6 @@ use crate::{
|
||||||
fields::{Fp, Fq},
|
fields::{Fp, Fq},
|
||||||
};
|
};
|
||||||
|
|
||||||
const ERR_CODE: &str = "deserialized bytes don't encode a field element";
|
|
||||||
|
|
||||||
/// Serializes bytes to human readable or compact representation.
|
/// Serializes bytes to human readable or compact representation.
|
||||||
///
|
///
|
||||||
/// Depending on whether the serializer is a human readable one or not, the bytes are either
|
/// Depending on whether the serializer is a human readable one or not, the bytes are either
|
||||||
|
|
@ -46,7 +44,9 @@ impl<'de> Deserialize<'de> for Fp {
|
||||||
let bytes = deserialize_bytes(d)?;
|
let bytes = deserialize_bytes(d)?;
|
||||||
match Fp::from_repr(bytes).into() {
|
match Fp::from_repr(bytes).into() {
|
||||||
Some(fq) => Ok(fq),
|
Some(fq) => Ok(fq),
|
||||||
None => Err(D::Error::custom(ERR_CODE)),
|
None => Err(D::Error::custom(
|
||||||
|
"deserialized bytes don't encode a Pallas field element",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +62,9 @@ impl<'de> Deserialize<'de> for Fq {
|
||||||
let bytes = deserialize_bytes(d)?;
|
let bytes = deserialize_bytes(d)?;
|
||||||
match Fq::from_repr(bytes).into() {
|
match Fq::from_repr(bytes).into() {
|
||||||
Some(fq) => Ok(fq),
|
Some(fq) => Ok(fq),
|
||||||
None => Err(D::Error::custom(ERR_CODE)),
|
None => Err(D::Error::custom(
|
||||||
|
"deserialized bytes don't encode a Vesta field element",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,9 +78,11 @@ impl Serialize for EpAffine {
|
||||||
impl<'de> Deserialize<'de> for EpAffine {
|
impl<'de> Deserialize<'de> for EpAffine {
|
||||||
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||||
let bytes = deserialize_bytes(d)?;
|
let bytes = deserialize_bytes(d)?;
|
||||||
match EpAffine::from_bytes_unchecked(&bytes).into() {
|
match EpAffine::from_bytes(&bytes).into() {
|
||||||
Some(ep_affine) => Ok(ep_affine),
|
Some(ep_affine) => Ok(ep_affine),
|
||||||
None => Err(D::Error::custom(ERR_CODE)),
|
None => Err(D::Error::custom(
|
||||||
|
"deserialized bytes don't encode a Pallas curve point",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,9 +96,11 @@ impl Serialize for EqAffine {
|
||||||
impl<'de> Deserialize<'de> for EqAffine {
|
impl<'de> Deserialize<'de> for EqAffine {
|
||||||
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||||
let bytes = deserialize_bytes(d)?;
|
let bytes = deserialize_bytes(d)?;
|
||||||
match EqAffine::from_bytes_unchecked(&bytes).into() {
|
match EqAffine::from_bytes(&bytes).into() {
|
||||||
Some(eq_affine) => Ok(eq_affine),
|
Some(eq_affine) => Ok(eq_affine),
|
||||||
None => Err(D::Error::custom(ERR_CODE)),
|
None => Err(D::Error::custom(
|
||||||
|
"deserialized bytes don't encode a Vesta curve point",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue