Skip to main content

PublicKey

Struct PublicKey 

Source
pub struct PublicKey { /* private fields */ }
Expand description

An RSA public key parsed from a PKCS#1 SubjectPublicKeyInfo DER blob.

Implementations§

Source§

impl PublicKey

Source

pub fn from_n_e(n_bytes: &[u8], e: &[u8]) -> Result<Self, RsaError>

Build an RSA public key from raw modulus n and public exponent e (both big-endian byte slices).

This is useful when importing keys from formats like JWK where n and e are available directly as bytes rather than inside an ASN.1 DER wrapper.

Source

pub fn from_pkcs1_der(data: &[u8]) -> Result<Self, RsaError>

Parse an RSA public key from the raw PKCS#1 bytes.

The input is the content of the BIT STRING inside the SPKI — an ASN.1 SEQUENCE { INTEGER n, INTEGER e }.

Source

pub fn verify_pkcs1_v1_5( &self, signature: &[u8], message_digest: &[u8], digest_info_prefix: &[u8], ) -> Result<(), RsaError>

Verify a PKCS#1 v1.5 signature.

signature is the raw signature bytes (eg., 256 bytes for RSA-2048). message_digest is the hash of the message to verify. digest_info_prefix is the ASN.1 DigestInfo prefix for the hash algorithm (the constant-length portion before the hash value).

Source

pub fn verify_pss<H: Hasher>( &self, signature: &[u8], message: &[u8], salt_len: usize, ) -> Result<(), RsaError>

Verify an RSA-PSS signature (RFC 8017 §9.1.2).

message_digest is the hash of the TLS signed_data. hash_fn produces a digest of hash_len bytes. salt_len equals the hash length (Go’s PSSSaltLengthEqualsHash).

Source

pub fn n_bytes(&self) -> Vec<u8>

Returns the modulus n as big-endian bytes, trimmed to the actual key size. (e.g. 256 bytes for RSA-2048, 512 bytes for RSA-4096).

Source

pub fn e_bytes(&self) -> SmallVec<u8, 4>

Returns the public exponent e as big-endian bytes, trimmed of leading zeros. (e.g. [1, 0, 1] for 65537).

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