diff options
| author | Steven Fackler <[email protected]> | 2016-11-13 17:06:50 +0000 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-11-13 17:06:50 +0000 |
| commit | 48c0009418cbbf7c69c24b35d56e80edb0c80d45 (patch) | |
| tree | 21ab4cb2b259ea883a36865d0971c3ad65ea0722 /openssl/src/macros.rs | |
| parent | Macroise to_der (diff) | |
| download | rust-openssl-48c0009418cbbf7c69c24b35d56e80edb0c80d45.tar.xz rust-openssl-48c0009418cbbf7c69c24b35d56e80edb0c80d45.zip | |
Macroise from_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 7fa15d1f..39944124 100644 --- a/openssl/src/macros.rs +++ b/openssl/src/macros.rs @@ -170,3 +170,38 @@ macro_rules! public_key_to_der { public_key_to_der, $f); } } + +macro_rules! from_der_inner { + (#[$m:meta] $n:ident, $t:ident, $f:path) => { + #[$m] + pub fn $n(der: &[u8]) -> Result<$t, ::error::ErrorStack> { + unsafe { + ::ffi::init(); + let len = ::std::cmp::min(der.len(), ::libc::c_long::max_value() as usize) as ::libc::c_long; + ::cvt_p($f(::std::ptr::null_mut(), &mut der.as_ptr(), len)) + .map($t) + } + } + } +} + +macro_rules! from_der { + ($t:ident, $f:path) => { + from_der_inner!(/// Deserializes a value from DER-formatted data. + from_der, $t, $f); + } +} + +macro_rules! private_key_from_der { + ($t:ident, $f:path) => { + from_der_inner!(/// Deserializes a private key from DER-formatted data. + private_key_from_der, $t, $f); + } +} + +macro_rules! public_key_from_der { + ($t:ident, $f:path) => { + from_der_inner!(/// Deserializes a public key from DER-formatted data. + public_key_from_der, $t, $f); + } +} |