diff options
| author | Steven Fackler <[email protected]> | 2016-11-13 16:52:19 +0000 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-11-13 16:52:19 +0000 |
| commit | b0415f466c4b62f949b1e47e6b1e703d1b24122b (patch) | |
| tree | 4cbe8cb2d812d10f22c7ed6ae2617f8fe50ecf62 /openssl/src/macros.rs | |
| parent | Make password callback return a Result (diff) | |
| download | rust-openssl-b0415f466c4b62f949b1e47e6b1e703d1b24122b.tar.xz rust-openssl-b0415f466c4b62f949b1e47e6b1e703d1b24122b.zip | |
Macroise to_der
Diffstat (limited to 'openssl/src/macros.rs')
| -rw-r--r-- | openssl/src/macros.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs index 0be5ff17..7fa15d1f 100644 --- a/openssl/src/macros.rs +++ b/openssl/src/macros.rs @@ -135,3 +135,38 @@ macro_rules! private_key_to_pem { } } } + +macro_rules! to_der_inner { + (#[$m:meta] $n:ident, $f:path) => { + #[$m] + pub fn $n(&self) -> Result<Vec<u8>, ::error::ErrorStack> { + unsafe { + let len = try!(::cvt($f(::types::OpenSslTypeRef::as_ptr(self), ptr::null_mut()))); + let mut buf = vec![0; len as usize]; + try!(::cvt($f(::types::OpenSslTypeRef::as_ptr(self), &mut buf.as_mut_ptr()))); + Ok(buf) + } + } + }; +} + +macro_rules! to_der { + ($f:path) => { + to_der_inner!(/// Serializes this value to DER. + to_der, $f); + } +} + +macro_rules! private_key_to_der { + ($f:path) => { + to_der_inner!(/// Serializes the private key to DER. + private_key_to_der, $f); + } +} + +macro_rules! public_key_to_der { + ($f:path) => { + to_der_inner!(/// Serializes the public key to DER. + public_key_to_der, $f); + } +} |