diff options
author | Steven Fackler <sfackler@gmail.com> | 2017-05-06 16:40:33 -0700 |
---|---|---|
committer | Steven Fackler <sfackler@gmail.com> | 2017-05-06 16:40:33 -0700 |
commit | 67b5fd1c9750d3434adca8d700e265a5238de3be (patch) | |
tree | 9d29137337ef254d7488f65163642c249a21cd4c | |
parent | 0efef98848801c62580b443a8e7e2fbb13f9fee7 (diff) | |
download | rust-openssl-67b5fd1c9750d3434adca8d700e265a5238de3be.zip |
Support public key decode from DER
Closes #629
-rw-r--r-- | openssl-sys/src/lib.rs | 1 | ||||
-rw-r--r-- | openssl/src/pkey.rs | 7 | ||||
-rw-r--r-- | openssl/test/key.der.pub | bin | 0 -> 294 bytes |
3 files changed, 8 insertions, 0 deletions
diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 0d03f3be..e3f78cfb 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -2014,6 +2014,7 @@ extern { pub fn i2d_X509_REQ_bio(b: *mut BIO, x: *mut X509_REQ) -> c_int; pub fn i2d_X509_REQ(x: *mut X509_REQ, buf: *mut *mut u8) -> c_int; + pub fn d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY; pub fn i2d_PUBKEY_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int; pub fn i2d_PrivateKey_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int; pub fn i2d_PUBKEY(k: *mut EVP_PKEY, buf: *mut *mut u8) -> c_int; diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 31dc9d82..f8211b25 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -140,6 +140,7 @@ impl PKey { private_key_from_pem!(PKey, ffi::PEM_read_bio_PrivateKey); public_key_from_pem!(PKey, ffi::PEM_read_bio_PUBKEY); + public_key_from_der!(PKey, ffi::d2i_PUBKEY); /// Deserializes a DER-formatted PKCS#8 private key, using a callback to retrieve the password /// if the key is encrpyted. @@ -311,6 +312,12 @@ mod tests { } #[test] + fn test_public_key_from_der() { + let key = include_bytes!("../test/key.der.pub"); + PKey::public_key_from_der(key).unwrap(); + } + + #[test] fn test_pem() { let key = include_bytes!("../test/key.pem"); let key = PKey::private_key_from_pem(key).unwrap(); diff --git a/openssl/test/key.der.pub b/openssl/test/key.der.pub Binary files differnew file mode 100644 index 00000000..395b04a9 --- /dev/null +++ b/openssl/test/key.der.pub |