From 2f7deacdb13b31fd24e14bd14f81b091c0913625 Mon Sep 17 00:00:00 2001 From: K Shiva Kiran Date: Tue, 7 May 2024 14:45:07 +0530 Subject: [PATCH] HOTFIX: Fix base64 cfg attribute --- src/encode.rs | 5 +++++ src/fbobj/fb128.rs | 42 ------------------------------------------ 2 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 src/fbobj/fb128.rs diff --git a/src/encode.rs b/src/encode.rs index 56e2fb1..ca5e968 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -4,6 +4,7 @@ use crypto_bigint::{ArrayEncoding, generic_array::GenericArray, Uint}; use std::sync::RwLock; #[cfg(feature = "base64")] +#[cfg_attr(docsrs, doc(cfg(feature = "base64")))] use base64::{prelude::BASE64_STANDARD, Engine}; /// Provides methods to encode and decode data to and from several formats. @@ -21,6 +22,7 @@ pub trait Encode { /// Returns the base64 encoded representation of the ciphertext and keybase. /// Requires `base64` feature to be enabled. + #[cfg(feature = "base64")] #[cfg_attr(docsrs, doc(cfg(feature = "base64")))] fn to_base64(&self) -> (String, String); @@ -30,6 +32,7 @@ pub trait Encode { /// # Errors /// - [DecodeError](FbError::DecodeError) /// - [InvalidParams](FbError::InvalidParams) - Are the parameters in the wrong order? + #[cfg(feature = "base64")] #[cfg_attr(docsrs, doc(cfg(feature = "base64")))] fn from_base64(cipher: &str, keybase: &str) -> Result where @@ -68,6 +71,7 @@ where Ok(FbObj {c, r}) } + #[cfg(feature = "base64")] #[cfg_attr(docsrs, doc(cfg(feature = "base64")))] fn to_base64(&self) -> (String, String) { let (c, r) = self.to_bytes(); @@ -75,6 +79,7 @@ where (BASE64_STANDARD.encode(c), BASE64_STANDARD.encode(r)) } + #[cfg(feature = "base64")] #[cfg_attr(docsrs, doc(cfg(feature = "base64")))] fn from_base64(cipher: &str, keybase: &str) -> Result { let c_bytes = BASE64_STANDARD.decode(cipher) diff --git a/src/fbobj/fb128.rs b/src/fbobj/fb128.rs deleted file mode 100644 index d39b724..0000000 --- a/src/fbobj/fb128.rs +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -use crate::{FBAlgo, FBObj, FieldOps, Packing, WrappingOps}; -use crypto_bigint::{Limb, NonZero, U128}; - -/// [`FBObj`] with a block size of 128 bits. -pub type FB128 = FBObj; - -const PRIME_POS_VAL: u16 = 159; -const PRIME: U128 = U128::MAX.wrapping_sub(&U128::from_u16(PRIME_POS_VAL-1)); -const PRIME_POS: Limb = Limb::from_u16(PRIME_POS_VAL); - -impl FBAlgo for FBObj { - const MODULUS: NonZero = NonZero::::const_new(PRIME).0; -} - -impl FieldOps for U128 { - fn field_add(&self, rhs: &Self) -> Self { - self.add_mod_special(rhs, PRIME_POS) - } - fn field_sub(&self, rhs: &Self) -> Self { - self.sub_mod_special(rhs, PRIME_POS) - } - fn field_mul(&self, rhs: &Self) -> Self { - self.mul_mod_special(rhs, PRIME_POS) - } - fn field_inv(&self) -> Self { - self.inv_odd_mod(&PRIME).0 - } -} - -impl Packing for U128 { - const R_BOUND: U128 = PRIME.wrapping_sub(&U128::ONE); -} - -impl WrappingOps for U128 { - fn wrapping_add(&self, rhs: &U128) -> U128 { - self.wrapping_add(rhs) - } - fn wrapping_sub(&self, rhs: &U128) -> U128 { - self.wrapping_sub(rhs) - } -}