diff options
| author | Moritz Wanzenböck <[email protected]> | 2018-06-18 11:39:15 +0200 |
|---|---|---|
| committer | Moritz Wanzenböck <[email protected]> | 2018-06-18 11:39:15 +0200 |
| commit | 52c942f4b3d96cff239646d86998b7b898c5e0ed (patch) | |
| tree | 4d5b9b2bf2ea7ec1442fbcf5a9cec9cbce85c96e /openssl/src | |
| parent | Merge pull request #943 from lolzballs/master (diff) | |
| download | rust-openssl-52c942f4b3d96cff239646d86998b7b898c5e0ed.tar.xz rust-openssl-52c942f4b3d96cff239646d86998b7b898c5e0ed.zip | |
Add methods to access private and public part of DSA keys
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/dsa.rs | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index e8d78dcb..684666cf 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -13,7 +13,7 @@ use std::ptr; use bn::BigNumRef; use error::ErrorStack; -use pkey::{HasParams, HasPublic, Private, Public}; +use pkey::{HasParams, HasPrivate, HasPublic, Private, Public}; use {cvt, cvt_p}; generic_foreign_type_and_impl_send_sync! { @@ -83,6 +83,28 @@ where public_key_to_der, ffi::i2d_DSA_PUBKEY } + + /// Returns a reference to the public exponent. + pub fn pub_key(&self) -> &BigNumRef { + unsafe { + let mut pub_key = ptr::null(); + DSA_get0_key(self.as_ptr(), &mut pub_key, ptr::null_mut()); + BigNumRef::from_ptr(pub_key as *mut _) + } + } +} + +impl<T> DsaRef<T> +where + T: HasPrivate, +{ + pub fn priv_key(&self) -> &BigNumRef { + unsafe { + let mut priv_key = ptr::null(); + DSA_get0_key(self.as_ptr(), ptr::null_mut(), &mut priv_key); + BigNumRef::from_ptr(priv_key as *mut _) + } + } } impl<T> DsaRef<T> @@ -211,6 +233,26 @@ cfg_if! { } } +cfg_if! { + if #[cfg(any(ossl110, libressl273))] { + use ffi::DSA_get0_key; + } else { + #[allow(bad_style)] + unsafe fn DSA_get0_pqg( + d: *mut ffi::DSA, + pub_key: *mut *const ffi::BIGNUM, + priv_key: *mut *const ffi::BIGNUM) + { + if !pub_key.is_null() { + *pub_key = (*d).pub_key; + } + if !priv_key.is_null() { + *priv_key = (*d).priv_key; + } + } + } +} + #[cfg(test)] mod test { use super::*; |