Skip to content

Commit

Permalink
Support PKCS#1 RSA public keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jul 5, 2017
1 parent 026ed1f commit 51a226e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions openssl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,8 @@ extern "C" {

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 i2d_RSAPublicKey(k: *const RSA, buf: *mut *mut u8) -> c_int;
pub fn d2i_RSAPublicKey(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 d2i_RSAPrivateKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;

Expand Down
9 changes: 8 additions & 1 deletion openssl/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ foreign_type! {
}

impl RsaRef {
// FIXME these need to specify output format
private_key_to_pem!(ffi::PEM_write_bio_RSAPrivateKey);
public_key_to_pem!(ffi::PEM_write_bio_RSA_PUBKEY);

private_key_to_der!(ffi::i2d_RSAPrivateKey);
public_key_to_der!(ffi::i2d_RSA_PUBKEY);

to_der_inner!(/// Serializes the public key to DER-encoded PKCS#1.
public_key_to_der_pkcs1, ffi::i2d_RSAPublicKey);

// FIXME should return u32
pub fn size(&self) -> usize {
unsafe {
Expand Down Expand Up @@ -255,11 +259,15 @@ impl Rsa {
}
}

// FIXME these need to identify input formats
private_key_from_pem!(Rsa, ffi::PEM_read_bio_RSAPrivateKey);
private_key_from_der!(Rsa, ffi::d2i_RSAPrivateKey);
public_key_from_pem!(Rsa, ffi::PEM_read_bio_RSA_PUBKEY);
public_key_from_der!(Rsa, ffi::d2i_RSA_PUBKEY);

from_der_inner!(/// Deserializes a public key from DER-encoded PKCS#1 data.
public_key_from_der_pkcs1, Rsa, ffi::d2i_RSAPublicKey);

#[deprecated(since = "0.9.2", note = "use private_key_from_pem_callback")]
pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<Rsa, ErrorStack>
where F: FnOnce(&mut [c_char]) -> usize
Expand Down Expand Up @@ -440,5 +448,4 @@ mod test {
let len = k1.private_decrypt(&emesg, &mut dmesg, PKCS1_PADDING).unwrap();
assert_eq!(msg, &dmesg[..len]);
}

}

0 comments on commit 51a226e

Please sign in to comment.