aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/macros.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-13 17:56:48 +0000
committerSteven Fackler <[email protected]>2016-11-13 17:56:48 +0000
commitccef9e339dc3717761fc9e70c34f1df86b608579 (patch)
tree83778d79877e81416f67ed06c5d0b0d01a309c04 /openssl/src/macros.rs
parentMacroise to_pem (diff)
downloadrust-openssl-ccef9e339dc3717761fc9e70c34f1df86b608579.tar.xz
rust-openssl-ccef9e339dc3717761fc9e70c34f1df86b608579.zip
Macroise from_pem
Diffstat (limited to 'openssl/src/macros.rs')
-rw-r--r--openssl/src/macros.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs
index a57f36eb..b36e8319 100644
--- a/openssl/src/macros.rs
+++ b/openssl/src/macros.rs
@@ -42,15 +42,8 @@ macro_rules! type_ {
macro_rules! private_key_from_pem {
($t:ident, $f:path) => {
- /// Deserializes a PEM-formatted private key.
- pub fn private_key_from_pem(pem: &[u8]) -> Result<$t, ::error::ErrorStack> {
- unsafe {
- ::init();
- let bio = try!(::bio::MemBioSlice::new(pem));
- cvt_p($f(bio.as_ptr(), ::std::ptr::null_mut(), None, ::std::ptr::null_mut()))
- .map($t)
- }
- }
+ from_pem_inner!(/// Deserializes a PEM-formatted private key.
+ private_key_from_pem, $t, $f);
/// Deserializes a PEM-formatted private key, using the supplied password if the key is
/// encrypted.
@@ -232,3 +225,31 @@ macro_rules! public_key_from_der {
public_key_from_der, $t, $f);
}
}
+
+macro_rules! from_pem_inner {
+ (#[$m:meta] $n:ident, $t:ident, $f:path) => {
+ #[$m]
+ pub fn $n(pem: &[u8]) -> Result<$t, ::error::ErrorStack> {
+ unsafe {
+ ::init();
+ let bio = try!(::bio::MemBioSlice::new(pem));
+ cvt_p($f(bio.as_ptr(), ::std::ptr::null_mut(), None, ::std::ptr::null_mut()))
+ .map($t)
+ }
+ }
+ }
+}
+
+macro_rules! public_key_from_pem {
+ ($t:ident, $f:path) => {
+ from_pem_inner!(/// Deserializes a public key from PEM-formatted data.
+ public_key_from_pem, $t, $f);
+ }
+}
+
+macro_rules! from_pem {
+ ($t:ident, $f:path) => {
+ from_pem_inner!(/// Deserializes a value from PEM-formatted data.
+ from_pem, $t, $f);
+ }
+}