diff options
| author | Steven Fackler <[email protected]> | 2016-10-31 19:37:21 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-31 20:02:24 -0700 |
| commit | 927c3e924cd894cb4b32efff666f949a294ab7c7 (patch) | |
| tree | 2a5667608e85469e4115a9d358c8a4119af7fada /openssl/src/lib.rs | |
| parent | Mention 0.7 README (diff) | |
| download | rust-openssl-927c3e924cd894cb4b32efff666f949a294ab7c7.tar.xz rust-openssl-927c3e924cd894cb4b32efff666f949a294ab7c7.zip | |
Add a generic Ref type
Diffstat (limited to 'openssl/src/lib.rs')
| -rw-r--r-- | openssl/src/lib.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index f335c097..8fa53f3b 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -20,6 +20,44 @@ use libc::c_int; use error::ErrorStack; +macro_rules! type_ { + ($n:ident, $c:path, $d:path) => { + pub struct $n(*mut $c); + + unsafe impl ::types::OpenSslType for $n { + type CType = $c; + + unsafe fn from_ptr(ptr: *mut $c) -> $n { + $n(ptr) + } + + fn as_ptr(&self) -> *mut $c { + self.0 + } + } + + impl Drop for $n { + fn drop(&mut self) { + unsafe { $d(self.0) } + } + } + + impl ::std::ops::Deref for $n { + type Target = ::types::Ref<$n>; + + fn deref(&self) -> &::types::Ref<$n> { + unsafe { ::types::Ref::from_ptr(self.0) } + } + } + + impl ::std::ops::DerefMut for $n { + fn deref_mut(&mut self) -> &mut ::types::Ref<$n> { + unsafe { ::types::Ref::from_ptr_mut(self.0) } + } + } + } +} + mod bio; mod opaque; mod util; @@ -37,6 +75,7 @@ pub mod pkcs12; pub mod pkcs5; pub mod pkey; pub mod rand; +pub mod types; pub mod rsa; pub mod sign; pub mod ssl; |