Add method to encode a public key as a DER blob
This commit is contained in:
parent
43911db26c
commit
9ea27c12b9
|
|
@ -1693,6 +1693,8 @@ extern {
|
||||||
pub fn i2d_X509_bio(b: *mut BIO, x: *mut X509) -> c_int;
|
pub fn i2d_X509_bio(b: *mut BIO, x: *mut X509) -> c_int;
|
||||||
pub fn i2d_X509_REQ_bio(b: *mut BIO, x: *mut X509_REQ) -> c_int;
|
pub fn i2d_X509_REQ_bio(b: *mut BIO, x: *mut X509_REQ) -> c_int;
|
||||||
|
|
||||||
|
pub fn i2d_PUBKEY_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int;
|
||||||
|
|
||||||
pub fn i2d_RSA_PUBKEY(k: *mut RSA, buf: *mut *mut u8) -> c_int;
|
pub fn i2d_RSA_PUBKEY(k: *mut RSA, buf: *mut *mut u8) -> c_int;
|
||||||
pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
|
pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
|
||||||
pub fn i2d_RSAPrivateKey(k: *const RSA, buf: *mut *mut u8) -> c_int;
|
pub fn i2d_RSAPrivateKey(k: *const RSA, buf: *mut *mut u8) -> c_int;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ impl Ref<PKey> {
|
||||||
Ok(mem_bio.get_buf().to_owned())
|
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<Vec<u8>, ErrorStack> {
|
pub fn public_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
|
||||||
let mem_bio = try!(MemBio::new());
|
let mem_bio = try!(MemBio::new());
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -49,6 +49,15 @@ impl Ref<PKey> {
|
||||||
Ok(mem_bio.get_buf().to_owned())
|
Ok(mem_bio.get_buf().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode public key in DER format
|
||||||
|
pub fn public_key_to_der(&self) -> Result<Vec<u8>, 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<PKey>) -> bool {
|
pub fn public_eq(&self, other: &Ref<PKey>) -> bool {
|
||||||
unsafe { ffi::EVP_PKEY_cmp(self.as_ptr(), other.as_ptr()) == 1 }
|
unsafe { ffi::EVP_PKEY_cmp(self.as_ptr(), other.as_ptr()) == 1 }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue