pub struct RsaPublicKey { /* private fields */ }
Available on crate feature rsa only.
Expand description

Represents the public part of an RSA key.

Implementations§

source§

impl RsaPublicKey

source

pub fn encrypt<R, P>( &self, rng: &mut R, padding: P, msg: &[u8] ) -> Result<Vec<u8>, Error>

Encrypt the given message.

source

pub fn verify<S>( &self, scheme: S, hashed: &[u8], sig: &[u8] ) -> Result<(), Error>
where S: SignatureScheme,

Verify a signed message.

hashed must be the result of hashing the input using the hashing function passed in through hash.

If the message is valid Ok(()) is returned, otherwise an Err indicating failure.

source§

impl RsaPublicKey

source

pub const MIN_PUB_EXPONENT: u64 = 2u64

Minimum value of the public exponent e.

source

pub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64

Maximum value of the public exponent e.

source

pub const MAX_SIZE: usize = 4_096usize

Maximum size of the modulus n in bits.

source

pub fn new(n: BigUint, e: BigUint) -> Result<RsaPublicKey, Error>

Create a new public key from its components.

This function accepts public keys with a modulus size up to 4096-bits, i.e. RsaPublicKey::MAX_SIZE.

source

pub fn new_with_max_size( n: BigUint, e: BigUint, max_size: usize ) -> Result<RsaPublicKey, Error>

Create a new public key from its components.

source

pub fn new_unchecked(n: BigUint, e: BigUint) -> RsaPublicKey

Create a new public key, bypassing checks around the modulus and public exponent size.

This method is not recommended, and only intended for unusual use cases. Most applications should use RsaPublicKey::new or RsaPublicKey::new_with_max_size instead.

Trait Implementations§

source§

impl AsRef<RsaPublicKey> for RsaPrivateKey

source§

fn as_ref(&self) -> &RsaPublicKey

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for RsaPublicKey

source§

fn clone(&self) -> RsaPublicKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RsaPublicKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl EncodePublicKey for RsaPublicKey

source§

fn to_public_key_der(&self) -> Result<Document, Error>

Serialize a [Document] containing a SPKI-encoded public key.
source§

impl From<&RsaPrivateKey> for RsaPublicKey

source§

fn from(private_key: &RsaPrivateKey) -> RsaPublicKey

Converts to this type from the input type.
source§

impl<'a> From<&'a RsaPublicKey> for JsonWebKey<'a>

source§

fn from(key: &'a RsaPublicKey) -> JsonWebKey<'a>

Converts to this type from the input type.
source§

impl From<RsaPrivateKey> for RsaPublicKey

source§

fn from(private_key: RsaPrivateKey) -> RsaPublicKey

Converts to this type from the input type.
source§

impl<D> From<VerifyingKey<D>> for RsaPublicKey
where D: Digest,

source§

fn from(key: VerifyingKey<D>) -> RsaPublicKey

Converts to this type from the input type.
source§

impl<D> From<VerifyingKey<D>> for RsaPublicKey
where D: Digest,

source§

fn from(key: VerifyingKey<D>) -> RsaPublicKey

Converts to this type from the input type.
source§

impl Hash for RsaPublicKey

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for RsaPublicKey

source§

fn eq(&self, other: &RsaPublicKey) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PublicKeyParts for RsaPublicKey

source§

fn n(&self) -> &BigUint

Returns the modulus of the key.
source§

fn e(&self) -> &BigUint

Returns the public exponent of the key.
source§

fn size(&self) -> usize

Returns the modulus size in bytes. Raw signatures and ciphertexts for or by this public key will have the same size.
source§

impl TryFrom<&JsonWebKey<'_>> for RsaPublicKey

§

type Error = JwkError

The type returned in the event of a conversion error.
source§

fn try_from(jwk: &JsonWebKey<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RsaPublicKey> for StrongKey<RsaPublicKey>

§

type Error = WeakKeyError<RsaPublicKey>

The type returned in the event of a conversion error.
source§

fn try_from(key: RsaPublicKey) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<SubjectPublicKeyInfo<AnyRef<'_>, BitStringRef<'_>>> for RsaPublicKey

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( spki: SubjectPublicKeyInfo<AnyRef<'_>, BitStringRef<'_>> ) -> Result<RsaPublicKey, Error>

Performs the conversion.
source§

impl Eq for RsaPublicKey

source§

impl StructuralEq for RsaPublicKey

source§

impl StructuralPartialEq for RsaPublicKey

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> DecodePublicKey for T
where T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,

§

fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>

Deserialize object from ASN.1 DER-encoded [SubjectPublicKeyInfo] (binary format).
§

impl<T> DecodeRsaPublicKey for T
where T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,

§

fn from_pkcs1_der(public_key: &[u8]) -> Result<T, Error>

Deserialize object from ASN.1 DER-encoded [RsaPublicKey] (binary format).
§

impl<T> EncodeRsaPublicKey for T
where T: EncodePublicKey,

§

fn to_pkcs1_der(&self) -> Result<Document, Error>

Serialize a [Document] containing a PKCS#1-encoded public key.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V