From e05f7e1273e95f7dd5b54e84a54cf6b8197c1a2c Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 22 Sep 2021 11:31:52 -0700 Subject: [PATCH] Make `rsa::{self, public::{self, *}}` public. --- src/lib.rs | 2 +- src/rsa.rs | 2 +- src/rsa/public.rs | 2 +- src/rsa/public/exponent.rs | 4 ++-- src/rsa/public/key.rs | 7 ++++++- src/rsa/public/modulus.rs | 1 + 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 97e82a4ce..6d689c5d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,7 @@ pub mod pkcs8; pub mod rand; #[cfg(feature = "alloc")] -mod rsa; +pub mod rsa; pub mod signature; diff --git a/src/rsa.rs b/src/rsa.rs index f69af30aa..a04d65a5f 100644 --- a/src/rsa.rs +++ b/src/rsa.rs @@ -17,7 +17,7 @@ // naming conventions. Also the standard camelCase names are used for `KeyPair` // components. -//! Low-level RSA primitives. +//! RSA. use crate::{ arithmetic::bigint, diff --git a/src/rsa/public.rs b/src/rsa/public.rs index cbe72eb32..19c42b326 100644 --- a/src/rsa/public.rs +++ b/src/rsa/public.rs @@ -12,7 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -//! Low-level RSA public key API. +//! RSA public keys. mod components; mod exponent; diff --git a/src/rsa/public/exponent.rs b/src/rsa/public/exponent.rs index b9e0d1419..68d06c79d 100644 --- a/src/rsa/public/exponent.rs +++ b/src/rsa/public/exponent.rs @@ -1,7 +1,7 @@ use crate::error; use core::num::NonZeroU64; -/// The exponent `e` of the RSA public key. +/// The exponent `e` of an RSA public key. #[derive(Clone, Copy, Debug)] pub struct Exponent(NonZeroU64); @@ -30,7 +30,7 @@ impl Exponent { // stable. const MAX: Self = Self(unsafe { NonZeroU64::new_unchecked((1u64 << 33) - 1) }); - pub fn from_be_bytes( + pub(super) fn from_be_bytes( input: untrusted::Input, min_value: Self, ) -> Result { diff --git a/src/rsa/public/key.rs b/src/rsa/public/key.rs index 633bdd0d6..df5459908 100644 --- a/src/rsa/public/key.rs +++ b/src/rsa/public/key.rs @@ -15,6 +15,7 @@ use super::{Exponent, Modulus}; use crate::{bits, error}; +/// An RSA Public Key. #[derive(Debug)] pub struct Key { n: Modulus, @@ -22,7 +23,7 @@ pub struct Key { } impl Key { - pub fn from_modulus_and_exponent( + pub(in super::super) fn from_modulus_and_exponent( n: untrusted::Input, e: untrusted::Input, n_min_bits: bits::BitLength, @@ -52,10 +53,14 @@ impl Key { Ok(Self { n, e }) } + /// The public modulus. + #[inline] pub fn n(&self) -> &Modulus { &self.n } + /// The public exponent. + #[inline] pub fn e(&self) -> Exponent { self.e } diff --git a/src/rsa/public/modulus.rs b/src/rsa/public/modulus.rs index 2fe7eb3db..39a01074c 100644 --- a/src/rsa/public/modulus.rs +++ b/src/rsa/public/modulus.rs @@ -1,6 +1,7 @@ use crate::{arithmetic::bigint, bits, error, rsa::N}; use core::ops::RangeInclusive; +/// The modulus (n) of an RSA public key. pub struct Modulus { value: bigint::Modulus, bits: bits::BitLength,