From 025362ad5af96e9ca54851d3554af6ca1d0c2cf6 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Mon, 17 Oct 2022 10:18:09 +0200 Subject: [PATCH] Address code review --- src/serde_impl.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/serde_impl.rs b/src/serde_impl.rs index 8374989..e0cfb03 100644 --- a/src/serde_impl.rs +++ b/src/serde_impl.rs @@ -9,8 +9,6 @@ use crate::{ fields::{Fp, Fq}, }; -const ERR_CODE: &str = "deserialized bytes don't encode a field element"; - /// Serializes bytes to human readable or compact representation. /// /// 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)?; match Fp::from_repr(bytes).into() { 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)?; match Fq::from_repr(bytes).into() { 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 { fn deserialize>(d: D) -> Result { let bytes = deserialize_bytes(d)?; - match EpAffine::from_bytes_unchecked(&bytes).into() { + match EpAffine::from_bytes(&bytes).into() { 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 { fn deserialize>(d: D) -> Result { let bytes = deserialize_bytes(d)?; - match EqAffine::from_bytes_unchecked(&bytes).into() { + match EqAffine::from_bytes(&bytes).into() { 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", + )), } } }