From 5e5d24ee25f58675a6770585fc82978b39165cd3 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Fri, 1 Jan 2016 19:36:29 +0000 Subject: Implement the possibility to create BigNums from their ffi counterpart --- openssl/src/bn/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'openssl/src/bn') diff --git a/openssl/src/bn/mod.rs b/openssl/src/bn/mod.rs index 51a49241..cd1229af 100644 --- a/openssl/src/bn/mod.rs +++ b/openssl/src/bn/mod.rs @@ -102,6 +102,20 @@ impl BigNum { }) } + pub fn new_from_ffi(orig: *mut ffi::BIGNUM) -> Result { + if orig.is_null() { + panic!("Null Pointer was supplied to BigNum::new_from_ffi"); + } + unsafe { + let r = ffi::BN_dup(orig); + if r.is_null() { + panic!("Unexpected null pointer from BN_dup(..)") + } else { + Ok(BigNum(r)) + } + } + } + pub fn new_from_slice(n: &[u8]) -> Result { BigNum::new().and_then(|v| unsafe { try_ssl_null!(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, v.raw())); -- cgit v1.2.3 From 123840563703cd1c129a9702761b2028ab6c7210 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 9 Jan 2016 22:09:38 +0000 Subject: Make the BigNum generation from a native pointer unsafe --- openssl/src/bn/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'openssl/src/bn') diff --git a/openssl/src/bn/mod.rs b/openssl/src/bn/mod.rs index cd1229af..ba1121dd 100644 --- a/openssl/src/bn/mod.rs +++ b/openssl/src/bn/mod.rs @@ -102,17 +102,15 @@ impl BigNum { }) } - pub fn new_from_ffi(orig: *mut ffi::BIGNUM) -> Result { + pub unsafe fn new_from_ffi(orig: *mut ffi::BIGNUM) -> Result { if orig.is_null() { panic!("Null Pointer was supplied to BigNum::new_from_ffi"); } - unsafe { - let r = ffi::BN_dup(orig); - if r.is_null() { - panic!("Unexpected null pointer from BN_dup(..)") - } else { - Ok(BigNum(r)) - } + let r = ffi::BN_dup(orig); + if r.is_null() { + panic!("Unexpected null pointer from BN_dup(..)") + } else { + Ok(BigNum(r)) } } -- cgit v1.2.3 From 3ee2bf9310c75228f16ec228d3cd5aaeee66b61f Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Wed, 20 Jan 2016 20:29:06 +0000 Subject: Fix up RSA integration --- openssl/src/bn/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openssl/src/bn') diff --git a/openssl/src/bn/mod.rs b/openssl/src/bn/mod.rs index ba1121dd..00a0a0ca 100644 --- a/openssl/src/bn/mod.rs +++ b/openssl/src/bn/mod.rs @@ -108,7 +108,7 @@ impl BigNum { } let r = ffi::BN_dup(orig); if r.is_null() { - panic!("Unexpected null pointer from BN_dup(..)") + Err(SslError::get()) } else { Ok(BigNum(r)) } -- cgit v1.2.3