From 5e5d24ee25f58675a6770585fc82978b39165cd3 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Fri, 1 Jan 2016 19:36:29 +0000 Subject: [PATCH] Implement the possibility to create BigNums from their ffi counterpart --- openssl/src/bn/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()));