use super::errors::ParseBigIntError;
pub use num_integer::{Integer, Roots};
pub use num_traits::{One, Zero};
#[deprecated(
since = "0.6.0",
note = "BigInt now implements zeroize::Zeroize trait, you should use it instead"
)]
pub trait ZeroizeBN {
fn zeroize_bn(&mut self);
}
pub trait Converter: Sized {
fn to_bytes(&self) -> Vec<u8>;
fn from_bytes(bytes: &[u8]) -> Self;
fn to_bytes_array<const N: usize>(&self) -> Option<[u8; N]> {
let bytes = self.to_bytes();
if bytes.len() > N {
return None;
}
let mut array = [0u8; N];
array[N - bytes.len()..].copy_from_slice(&bytes);
Some(array)
}
fn to_hex(&self) -> String {
self.to_str_radix(16)
}
fn from_hex(n: &str) -> Result<Self, ParseBigIntError> {
Self::from_str_radix(n, 16)
}
fn to_str_radix(&self, radix: u8) -> String;
fn from_str_radix(s: &str, radix: u8) -> Result<Self, ParseBigIntError>;
}
pub trait BasicOps {
fn pow(&self, exponent: u32) -> Self;
fn mul(&self, other: &Self) -> Self;
fn sub(&self, other: &Self) -> Self;
fn add(&self, other: &Self) -> Self;
fn abs(&self) -> Self;
}
pub trait Modulo: Sized {
fn mod_pow(base: &Self, exponent: &Self, m: &Self) -> Self;
fn mod_mul(a: &Self, b: &Self, modulus: &Self) -> Self;
fn mod_sub(a: &Self, b: &Self, modulus: &Self) -> Self;
fn mod_add(a: &Self, b: &Self, modulus: &Self) -> Self;
fn mod_inv(a: &Self, m: &Self) -> Option<Self>;
fn modulus(&self, modulus: &Self) -> Self;
}
pub trait Samplable {
fn sample_below(upper: &Self) -> Self;
fn sample_range(lower: &Self, upper: &Self) -> Self;
fn strict_sample_range(lower: &Self, upper: &Self) -> Self;
fn sample(bit_size: usize) -> Self;
fn strict_sample(bit_size: usize) -> Self;
}
pub trait NumberTests {
fn is_zero(n: &Self) -> bool;
fn is_negative(n: &Self) -> bool;
}
pub trait EGCD
where
Self: Sized,
{
fn egcd(a: &Self, b: &Self) -> (Self, Self, Self);
}
pub trait BitManipulation {
fn set_bit(&mut self, bit: usize, bit_val: bool);
fn test_bit(&self, bit: usize) -> bool;
fn bit_length(&self) -> usize;
}
#[deprecated(
since = "0.6.0",
note = "Use corresponding From<T> and TryFrom<T> traits implemented on BigInt"
)]
pub trait ConvertFrom<T> {
fn _from(_: &T) -> Self;
}
pub trait Primes {
fn next_prime(&self) -> Self;
fn is_probable_prime(&self, n: u32) -> bool;
}