diff options
| author | Daniel Albert <[email protected]> | 2016-01-01 19:36:29 +0000 |
|---|---|---|
| committer | Daniel Albert <[email protected]> | 2016-01-01 19:36:29 +0000 |
| commit | 5e5d24ee25f58675a6770585fc82978b39165cd3 (patch) | |
| tree | 8328078f877b798dc729a33788b716da3266ef2b | |
| parent | Add RSA structs (diff) | |
| download | rust-openssl-5e5d24ee25f58675a6770585fc82978b39165cd3.tar.xz rust-openssl-5e5d24ee25f58675a6770585fc82978b39165cd3.zip | |
Implement the possibility to create BigNums from their ffi counterpart
| -rw-r--r-- | openssl/src/bn/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<BigNum, SslError> { + 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, SslError> { BigNum::new().and_then(|v| unsafe { try_ssl_null!(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, v.raw())); |