//! Multi Precision Integers.
use std::fmt;
use std::cmp::Ordering;
use quickcheck::{Arbitrary, Gen};
use rand::Rng;
use crate::types::{
Curve,
HashAlgorithm,
PublicKeyAlgorithm,
SymmetricAlgorithm,
};
use crate::crypto::hash::{self, Hash};
use crate::crypto::mem::{secure_cmp, Protected};
use crate::serialize::Serialize;
use crate::Error;
use crate::Result;
/// Holds a single MPI.
#[derive(Clone)]
pub struct MPI {
/// Integer value as big-endian.
value: Box<[u8]>,
}
impl From<Vec<u8>> for MPI {
fn from(v: Vec<u8>) -> Self {
Self::new(&v)
}
}
impl MPI {
/// Creates a new MPI.
///
/// This function takes care of leading zeros.
pub fn new(value: &[u8]) -> Self {
let mut leading_zeros = 0;
for b in value {
leading_zeros += b.leading_zeros() as usize;
if *b != 0 {
break;
}
}
let offset = leading_zeros / 8;
let value = Vec::from(&value[offset..]).into_boxed_slice();
MPI {
value: value,
}
}
/// Creates new MPI for EC point.
pub fn new_weierstrass(x: &