Skip to content

Commit

Permalink
dep/crypto: add rsa impl in openssl
Browse files Browse the repository at this point in the history
Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Jul 31, 2023
1 parent b1ac507 commit 0d5573a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion attestation-agent/deps/crypto/src/native/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use openssl::{
pkey::Private,
rsa::{Padding, Rsa},
};
use zeroize::Zeroizing;

use crate::PaddingMode;
use crate::rsa::PaddingMode;

#[derive(Debug, Clone)]
pub struct RSAKeyPair {
Expand Down Expand Up @@ -44,4 +45,16 @@ impl RSAKeyPair {
pub fn e(&self) -> Vec<u8> {
self.private_key.e().to_vec()
}

pub fn to_pkcs1_pem(&self) -> Result<Zeroizing<String>> {
let res = self.private_key.private_key_to_pem()?;
let pem = String::from_utf8(res)?;
Ok(Zeroizing::new(pem))
}

pub fn from_pkcs1_pem(pem: &str) -> Result<Self> {
let private_key = Rsa::<Private>::private_key_from_pem(pem.as_bytes())?;

Ok(Self { private_key })
}
}

0 comments on commit 0d5573a

Please sign in to comment.