Skip to main content

RsaPublicKey

Struct RsaPublicKey 

Source
pub struct RsaPublicKey {
    pub n: BigUint,
    pub e: BigUint,
}
Expand description

Represents an RSA public key with arbitrary-size modulus and exponent.

Fields§

§n: BigUint§e: BigUint

Implementations§

Source§

impl RsaPublicKey

Source

pub fn from_be_bytes(n: &[u8], e: &[u8]) -> Result<Self>

Creates public key from big-endian modulus and exponent bytes.

§Arguments
  • n: RSA modulus encoded as big-endian bytes.
  • e: RSA public exponent encoded as big-endian bytes.
§Returns

Parsed RsaPublicKey when both fields are non-empty.

§Errors

Returns Error::InvalidLength when fields are empty, or when modulus size is below 2048 bits in default-safe builds (legacy-compatible hazardous mode permits smaller imports), or other RSA component validation errors from [validate_public_components].

Source

pub fn from_u128(n: u128, e: u128) -> Self

Creates public key from small integers for compatibility tests.

§Arguments
  • n: RSA modulus value.
  • e: RSA public exponent value.
§Returns

RsaPublicKey converted from the provided integer values.

Source

pub fn clear(&mut self)

Clears public key material to a zeroized placeholder state.

§Notes

This mirrors explicit key free/reset lifecycle flows from the C surface.

Source

pub fn verify_digest(&self, digest: &[u8], signature: &[u8]) -> Result<()>

Verifies a digest representative by recovering signature with exponent e.

§Arguments
  • digest: Expected digest representative bytes.
  • signature: RSA signature to verify.
§Returns

Ok(()) when the recovered representative equals digest mod n.

Source

pub fn verify_pkcs1_v15_sha256( &self, msg: &[u8], signature: &[u8], ) -> Result<()>

Verifies RSASSA-PKCS1-v1_5 signature for SHA-256 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PKCS#1 v1.5 encoded.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn verify_pkcs1_v15_sha1(&self, msg: &[u8], signature: &[u8]) -> Result<()>

Verifies RSASSA-PKCS1-v1_5 signature for SHA-1 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PKCS#1 v1.5 encoded.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn verify_pkcs1_v15_sha384( &self, msg: &[u8], signature: &[u8], ) -> Result<()>

Verifies RSASSA-PKCS1-v1_5 signature for SHA-384 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PKCS#1 v1.5 encoded.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn verify_pkcs1_v15_sha512( &self, msg: &[u8], signature: &[u8], ) -> Result<()>

Verifies RSASSA-PKCS1-v1_5 signature for SHA-512 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PKCS#1 v1.5 encoded.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn verify_pss_sha256( &self, msg: &[u8], signature: &[u8], salt_len: usize, ) -> Result<()>

Verifies RSASSA-PSS signature for SHA-256 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PSS encoded.
  • salt_len: Expected salt length used by signer.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn verify_pss_sha384( &self, msg: &[u8], signature: &[u8], salt_len: usize, ) -> Result<()>

Verifies RSASSA-PSS signature for SHA-384 hashed message.

§Arguments
  • msg: Original message bytes.
  • signature: RSA signature expected to be PSS encoded.
  • salt_len: Expected salt length used by signer.
§Returns

Ok(()) when signature verification succeeds.

Source

pub fn encrypt_pkcs1_v15_auto( &self, plaintext: &[u8], drbg: &mut HmacDrbgSha256, ) -> Result<Vec<u8>>

Encrypts plaintext using RSAES-PKCS1-v1_5 with DRBG-sourced non-zero padding.

§Arguments
  • plaintext: Plaintext bytes to encrypt.
  • drbg: DRBG used to generate PKCS#1 v1.5 PS bytes.
§Returns

Ciphertext bytes padded to modulus length.

Source

pub fn encrypt_oaep_sha256_auto( &self, plaintext: &[u8], label: &[u8], drbg: &mut HmacDrbgSha256, ) -> Result<Vec<u8>>

Encrypts plaintext using RSAES-OAEP with SHA-256 and DRBG-derived seed.

§Arguments
  • plaintext: Plaintext bytes to encrypt.
  • label: OAEP label bytes hashed into encoding parameters.
  • drbg: DRBG used to generate OAEP seed bytes.
§Returns

Ciphertext bytes padded to modulus length.

Trait Implementations§

Source§

impl Clone for RsaPublicKey

Source§

fn clone(&self) -> RsaPublicKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Formats the value using the given formatter. Read more

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
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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.