From 9ea27c12b9b5d2d723d8686f5bde4de0223cb160 Mon Sep 17 00:00:00 2001 From: Lionel Flandrin Date: Tue, 1 Nov 2016 11:55:02 +0100 Subject: Add method to encode a public key as a DER blob --- openssl/src/pkey.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'openssl/src') diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 6236b642..4885ad3c 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -40,7 +40,7 @@ impl Ref { Ok(mem_bio.get_buf().to_owned()) } - /// Stores public key as a PEM + /// Encode public key in PEM format pub fn public_key_to_pem(&self) -> Result, ErrorStack> { let mem_bio = try!(MemBio::new()); unsafe { @@ -49,6 +49,15 @@ impl Ref { Ok(mem_bio.get_buf().to_owned()) } + /// Encode public key in DER format + pub fn public_key_to_der(&self) -> Result, ErrorStack> { + let mem_bio = try!(MemBio::new()); + unsafe { + try!(cvt(ffi::i2d_PUBKEY_bio(mem_bio.as_ptr(), self.as_ptr()))); + } + Ok(mem_bio.get_buf().to_owned()) + } + pub fn public_eq(&self, other: &Ref) -> bool { unsafe { ffi::EVP_PKEY_cmp(self.as_ptr(), other.as_ptr()) == 1 } } -- cgit v1.2.3