Skip to content

Commit 855ee44

Browse files
committed
Add CoreRsaPrivateSigningKey::generate
1 parent 81adbec commit 855ee44

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/core/jwk/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,17 @@ pub struct CoreRsaPrivateSigningKey {
563563
kid: Option<JsonWebKeyId>,
564564
}
565565
impl CoreRsaPrivateSigningKey {
566+
/// Generate a new `CoreRsaPrivateSigningKey` where N denotes its bit size.
567+
pub fn generate<const N: usize>(kid: Option<JsonWebKeyId>) -> Result<Self, rsa::Error> {
568+
let mut rng = rand::rngs::OsRng;
569+
570+
Ok(Self {
571+
key_pair: rsa::RsaPrivateKey::new(&mut rng, 2048)?,
572+
rng: Box::new(rng),
573+
kid,
574+
})
575+
}
576+
566577
/// Converts an RSA private key (in PEM format) to a JWK representing its public key.
567578
pub fn from_pem(pem: &str, kid: Option<JsonWebKeyId>) -> Result<Self, String> {
568579
Self::from_pem_internal(pem, Box::new(rand::rngs::OsRng), kid)

0 commit comments

Comments
 (0)