Rename BnCtx

This commit is contained in:
Steven Fackler 2016-11-03 20:54:08 -07:00
parent 62a9f89fce
commit e87b75fa03
1 changed files with 10 additions and 10 deletions

View File

@ -23,12 +23,12 @@ pub enum RNGProperty {
TwoMsbOne = 1, TwoMsbOne = 1,
} }
type_!(BnCtx, ffi::BN_CTX, ffi::BN_CTX_free); type_!(BigNumContext, ffi::BN_CTX, ffi::BN_CTX_free);
impl BnCtx { impl BigNumContext {
/// Returns a new `BnCtx`. /// Returns a new `BigNumContext`.
pub fn new() -> Result<BnCtx, ErrorStack> { pub fn new() -> Result<BigNumContext, ErrorStack> {
unsafe { cvt_p(ffi::BN_CTX_new()).map(BnCtx) } unsafe { cvt_p(ffi::BN_CTX_new()).map(BigNumContext) }
} }
/// Places the result of `a * b` in `r`. /// Places the result of `a * b` in `r`.
@ -681,7 +681,7 @@ impl<'a, 'b> Mul<&'b Ref<BigNum>> for &'a Ref<BigNum> {
type Output = BigNum; type Output = BigNum;
fn mul(self, oth: &Ref<BigNum>) -> BigNum { fn mul(self, oth: &Ref<BigNum>) -> BigNum {
let mut ctx = BnCtx::new().unwrap(); let mut ctx = BigNumContext::new().unwrap();
let mut r = BigNum::new().unwrap(); let mut r = BigNum::new().unwrap();
ctx.mul(&mut r, self, oth).unwrap(); ctx.mul(&mut r, self, oth).unwrap();
r r
@ -694,7 +694,7 @@ impl<'a, 'b> Div<&'b Ref<BigNum>> for &'a Ref<BigNum> {
type Output = BigNum; type Output = BigNum;
fn div(self, oth: &'b Ref<BigNum>) -> BigNum { fn div(self, oth: &'b Ref<BigNum>) -> BigNum {
let mut ctx = BnCtx::new().unwrap(); let mut ctx = BigNumContext::new().unwrap();
let mut dv = BigNum::new().unwrap(); let mut dv = BigNum::new().unwrap();
ctx.div(Some(&mut dv), None, self, oth).unwrap(); ctx.div(Some(&mut dv), None, self, oth).unwrap();
dv dv
@ -707,7 +707,7 @@ impl<'a, 'b> Rem<&'b Ref<BigNum>> for &'a Ref<BigNum> {
type Output = BigNum; type Output = BigNum;
fn rem(self, oth: &'b Ref<BigNum>) -> BigNum { fn rem(self, oth: &'b Ref<BigNum>) -> BigNum {
let mut ctx = BnCtx::new().unwrap(); let mut ctx = BigNumContext::new().unwrap();
let mut rem = BigNum::new().unwrap(); let mut rem = BigNum::new().unwrap();
ctx.div(None, Some(&mut rem), self, oth).unwrap(); ctx.div(None, Some(&mut rem), self, oth).unwrap();
rem rem
@ -780,7 +780,7 @@ impl Neg for BigNum {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use bn::{BnCtx, BigNum}; use bn::{BigNumContext, BigNum};
#[test] #[test]
fn test_to_from_slice() { fn test_to_from_slice() {
@ -805,7 +805,7 @@ mod tests {
let mut p = BigNum::new().unwrap(); let mut p = BigNum::new().unwrap();
BigNum::generate_prime(&mut p, 128, true, None, Some(&a)).unwrap(); BigNum::generate_prime(&mut p, 128, true, None, Some(&a)).unwrap();
let mut ctx = BnCtx::new().unwrap(); let mut ctx = BigNumContext::new().unwrap();
assert!(ctx.is_prime(&p, 100).unwrap()); assert!(ctx.is_prime(&p, 100).unwrap());
assert!(ctx.is_prime_fasttest(&p, 100, true).unwrap()); assert!(ctx.is_prime_fasttest(&p, 100, true).unwrap());
} }