From 5cc2b9ac14d17f9500fec0c722a2508eba011ebc Mon Sep 17 00:00:00 2001 From: Ayush Shukla Date: Tue, 23 Jan 2024 03:11:30 +0530 Subject: [PATCH] fix: put serde behind feature --- src/ed25519/curve.rs | 10 +++++++--- src/ed25519/fq.rs | 8 +++++--- src/ed25519/fr.rs | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ed25519/curve.rs b/src/ed25519/curve.rs index 93563c6d..1c0a17fa 100644 --- a/src/ed25519/curve.rs +++ b/src/ed25519/curve.rs @@ -9,9 +9,11 @@ use ff::{BatchInverter, Field, PrimeField}; use group::{self, Curve}; use group::{prime::PrimeCurveAffine, GroupEncoding}; use rand::RngCore; -use serde::{Deserialize, Serialize}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +#[cfg(feature = "derive_serde")] +use serde::{Deserialize, Serialize}; + const ED25519_GENERATOR_X: Fq = Fq::from_raw([ 0xc956_2d60_8f25_d51a, 0x692c_c760_9525_a7b2, @@ -43,7 +45,8 @@ use crate::{ impl_binops_multiplicative, impl_binops_multiplicative_mixed, impl_sub_binop_specify_output, }; -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))] pub struct Ed25519 { pub x: Fq, pub y: Fq, @@ -51,7 +54,8 @@ pub struct Ed25519 { pub t: Fq, } -#[derive(Copy, Clone, Debug, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Hash)] +#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))] pub struct Ed25519Affine { pub x: Fq, pub y: Fq, diff --git a/src/ed25519/fq.rs b/src/ed25519/fq.rs index cfba8129..fed7e413 100644 --- a/src/ed25519/fq.rs +++ b/src/ed25519/fq.rs @@ -1,12 +1,13 @@ use core::convert::TryInto; use core::fmt; use core::ops::{Add, Mul, Neg, Sub}; - use ff::{FromUniformBytes, PrimeField, WithSmallOrderMulGroup}; use rand::RngCore; -use serde::{Deserialize, Serialize}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +#[cfg(feature = "derive_serde")] +use serde::{Deserialize, Serialize}; + use crate::arithmetic::{adc, mac, macx, sbb}; /// This represents an element of $\mathbb{F}_q$ where @@ -17,7 +18,8 @@ use crate::arithmetic::{adc, mac, macx, sbb}; // The internal representation of this type is four 64-bit unsigned // integers in little-endian order. `Fq` values are always in // Montgomery form; i.e., Fq(a) = aR mod q, with R = 2^256. -#[derive(Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))] pub struct Fq(pub(crate) [u64; 4]); /// Constant representing the modulus diff --git a/src/ed25519/fr.rs b/src/ed25519/fr.rs index dc2c0789..4ef3ab4b 100644 --- a/src/ed25519/fr.rs +++ b/src/ed25519/fr.rs @@ -1,12 +1,13 @@ use core::convert::TryInto; use core::fmt; use core::ops::{Add, Mul, Neg, Sub}; - use ff::{FromUniformBytes, PrimeField, WithSmallOrderMulGroup}; use rand::RngCore; -use serde::{Deserialize, Serialize}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +#[cfg(feature = "derive_serde")] +use serde::{Deserialize, Serialize}; + use crate::arithmetic::{adc, mac, macx, sbb}; /// This represents an element of $\mathbb{F}_q$ where @@ -17,7 +18,8 @@ use crate::arithmetic::{adc, mac, macx, sbb}; // The internal representation of this type is four 64-bit unsigned // integers in little-endian order. `Fr` values are always in // Montgomery form; i.e., Fr(a) = aR mod r, with R = 2^256. -#[derive(Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))] pub struct Fr(pub(crate) [u64; 4]); /// Constant representing the modulus