From dc8eefb4bd866197a713a4bd47223b02b1b17096 Mon Sep 17 00:00:00 2001 From: olegnn Date: Thu, 24 Aug 2023 18:43:01 +0200 Subject: [PATCH] Validation tweaks --- utils/src/owned_pairs.rs | 17 ++++++++++++++++- utils/src/pairs.rs | 2 -- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/utils/src/owned_pairs.rs b/utils/src/owned_pairs.rs index f1a8710d..d08976c5 100644 --- a/utils/src/owned_pairs.rs +++ b/utils/src/owned_pairs.rs @@ -7,7 +7,7 @@ use ark_ec::{AffineRepr, VariableBaseMSM}; use ark_ff::PrimeField; use ark_serialize::*; -use serde::{de::Error, Deserializer, Serializer}; +use serde::{de::Error, Deserialize, Deserializer, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; use zeroize::Zeroize; @@ -265,6 +265,21 @@ where } } +impl<'de, Left, Right> Deserialize<'de> for OwnedPairs +where + Left: Deserialize<'de>, + Right: Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let (left, right) = <(Vec, Vec)>::deserialize(deserializer)?; + + Self::new(left, right).ok_or(serde::de::Error::custom("Invalid length")) + } +} + impl<'de, LeftAs, RightAs, Left, Right> DeserializeAs<'de, OwnedPairs> for OwnedPairs where diff --git a/utils/src/pairs.rs b/utils/src/pairs.rs index 1b6bba5e..bedc4d98 100644 --- a/utils/src/pairs.rs +++ b/utils/src/pairs.rs @@ -20,7 +20,6 @@ impl<'left, 'right, Left, Right> Clone for Pairs<'left, 'right, Left, Right> { } } -#[allow(dead_code)] impl<'left, 'right, Left, Right> Pairs<'left, 'right, Left, Right> { /// Combines two slices together if they have equal length. pub fn new(left: &'left [Left], right: &'right [Right]) -> Option { @@ -150,7 +149,6 @@ impl<'left, 'right, G: AffineRepr> Pairs<'left, 'right, G, G::ScalarField> { } /// Extension for `OwnedPairs` for cases when left is an `AffineRepr` implementer, and right is a `ScalarField::BigInt` implementer. -#[allow(dead_code)] impl Pairs<'_, '_, G, ::BigInt> { /// `G::Group::msm_bigint(left, right)` pub fn msm_bigint(&self) -> G::Group {