HOTFIX: Fix base64 cfg attribute
This commit is contained in:
parent
4c8dac91b0
commit
2f7deacdb1
|
@ -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<Self, FbError>
|
||||
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<Self, FbError> {
|
||||
let c_bytes = BASE64_STANDARD.decode(cipher)
|
||||
|
|
|
@ -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<U128>;
|
||||
|
||||
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<U128> for FBObj<U128> {
|
||||
const MODULUS: NonZero<U128> = NonZero::<U128>::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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue