Loading src/bn/mod.rs +11 −25 Original line number Diff line number Diff line Loading @@ -79,41 +79,27 @@ macro_rules! with_bn_in_ctx( ) impl BigNum { // FIXME: squash 3 constructors into one pub fn new() -> Result<BigNum, SslError> { unsafe { ffi::init(); let v = ffi::BN_new(); if v.is_null() { Err(SslError::get()) } else { let v = try_ssl_null!(ffi::BN_new()); Ok(BigNum(v)) } } } pub fn new_from(n: u64) -> Result<BigNum, SslError> { unsafe { ffi::init(); let bn = ffi::BN_new(); if bn.is_null() || ffi::BN_set_word(bn, n as c_ulong) == 0 { Err(SslError::get()) } else { Ok(BigNum(bn)) } } BigNum::new().and_then(|v| unsafe { try_ssl!(ffi::BN_set_word(v.raw(), n as c_ulong)); Ok(v) }) } pub fn new_from_slice(n: &[u8]) -> Result<BigNum, SslError> { unsafe { ffi::init(); let bn = ffi::BN_new(); if bn.is_null() || ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, bn).is_null() { Err(SslError::get()) } else { Ok(BigNum(bn)) } } BigNum::new().and_then(|v| unsafe { try_ssl_null!(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, v.raw())); Ok(v) }) } pub fn checked_sqr(&self) -> Result<BigNum, SslError> { Loading Loading
src/bn/mod.rs +11 −25 Original line number Diff line number Diff line Loading @@ -79,41 +79,27 @@ macro_rules! with_bn_in_ctx( ) impl BigNum { // FIXME: squash 3 constructors into one pub fn new() -> Result<BigNum, SslError> { unsafe { ffi::init(); let v = ffi::BN_new(); if v.is_null() { Err(SslError::get()) } else { let v = try_ssl_null!(ffi::BN_new()); Ok(BigNum(v)) } } } pub fn new_from(n: u64) -> Result<BigNum, SslError> { unsafe { ffi::init(); let bn = ffi::BN_new(); if bn.is_null() || ffi::BN_set_word(bn, n as c_ulong) == 0 { Err(SslError::get()) } else { Ok(BigNum(bn)) } } BigNum::new().and_then(|v| unsafe { try_ssl!(ffi::BN_set_word(v.raw(), n as c_ulong)); Ok(v) }) } pub fn new_from_slice(n: &[u8]) -> Result<BigNum, SslError> { unsafe { ffi::init(); let bn = ffi::BN_new(); if bn.is_null() || ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, bn).is_null() { Err(SslError::get()) } else { Ok(BigNum(bn)) } } BigNum::new().and_then(|v| unsafe { try_ssl_null!(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, v.raw())); Ok(v) }) } pub fn checked_sqr(&self) -> Result<BigNum, SslError> { Loading