Skip to content

Commit cb469dc

Browse files
djcjustsmth
andauthored
Implement From<&PublicKey> for PublicKeyComponents (#698)
* Implement From<&PublicKey> for PublicKeyComponents * Requires "ring-io" feature. * Fix up --------- Co-authored-by: Justin W Smith <[email protected]> Co-authored-by: Justin Smith <[email protected]>
1 parent d51401f commit cb469dc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

aws-lc-rs/src/rsa/key.rs

+15
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ impl PublicKey {
338338
pub fn exponent(&self) -> io::Positive<'_> {
339339
io::Positive::new_non_empty_without_leading_zeros(Input::from(self.exponent.as_ref()))
340340
}
341+
342+
/// Returns the length in bytes of the public modulus.
343+
pub fn modulus_len(&self) -> usize {
344+
self.modulus.len()
345+
}
341346
}
342347

343348
/// Low-level API for RSA public keys.
@@ -430,6 +435,16 @@ where
430435
}
431436
}
432437

438+
#[cfg(feature = "ring-io")]
439+
impl From<&PublicKey> for PublicKeyComponents<Vec<u8>> {
440+
fn from(public_key: &PublicKey) -> Self {
441+
PublicKeyComponents {
442+
n: public_key.modulus.to_vec(),
443+
e: public_key.exponent.to_vec(),
444+
}
445+
}
446+
}
447+
433448
impl<B> TryInto<PublicEncryptingKey> for PublicKeyComponents<B>
434449
where
435450
B: AsRef<[u8]> + Debug,

0 commit comments

Comments
 (0)