pub struct RsaPublicKey<const LIMBS: usize> { /* private fields */ }Expand description
An RSA public key (n, e).
Implementations§
Source§impl<const LIMBS: usize> RsaPublicKey<LIMBS>
impl<const LIMBS: usize> RsaPublicKey<LIMBS>
Source§impl<const LIMBS: usize> RsaPublicKey<LIMBS>
impl<const LIMBS: usize> RsaPublicKey<LIMBS>
Sourcepub fn to_pkcs1_der(&self) -> Vec<u8> ⓘ
pub fn to_pkcs1_der(&self) -> Vec<u8> ⓘ
Encodes the key as a PKCS#1 RSAPublicKey DER structure.
Sourcepub fn from_pkcs1_der(der: &[u8]) -> Result<Self, Error>
pub fn from_pkcs1_der(der: &[u8]) -> Result<Self, Error>
Decodes a PKCS#1 RSAPublicKey DER structure. Rejects moduli below
MIN_RSA_BITS and degenerate public
exponents (even/zero n; e < 3, e even, e ≥ n) per the structural
shape check derived from RFC 8017 §3.1. The size floor mirrors the boxed
parser so the two import paths refuse the same attacker-injected moduli.
Sourcepub fn to_pkcs1_pem(&self) -> String
pub fn to_pkcs1_pem(&self) -> String
Encodes the key as a PKCS#1 PEM document (-----BEGIN RSA PUBLIC KEY-----).
Sourcepub fn from_pkcs1_pem(pem: &str) -> Result<Self, Error>
pub fn from_pkcs1_pem(pem: &str) -> Result<Self, Error>
Decodes a PKCS#1 PEM public key.
Sourcepub fn to_spki_der(&self) -> Vec<u8> ⓘ
pub fn to_spki_der(&self) -> Vec<u8> ⓘ
Encodes the key as an X.509 SubjectPublicKeyInfo (SPKI) DER
structure (RFC 5280 §4.1.2.7). The AlgorithmIdentifier is
rsaEncryption (OID 1.2.840.113549.1.1.1) with explicit NULL
parameters (RFC 3279 §2.3.1); the BIT STRING body is the PKCS#1
RSAPublicKey DER produced by to_pkcs1_der.
Sourcepub fn to_spki_pem(&self) -> String
pub fn to_spki_pem(&self) -> String
Encodes the key as a PEM -----BEGIN PUBLIC KEY----- document
(RFC 7468). Distinct from the legacy RSA PUBLIC KEY label which
carries a bare PKCS#1 body.
Sourcepub fn from_spki_der(der: &[u8]) -> Result<Self, Error>
pub fn from_spki_der(der: &[u8]) -> Result<Self, Error>
Parses an X.509 SubjectPublicKeyInfo (SPKI) DER structure for an
RSA public key. Validates that the algorithm OID is rsaEncryption,
the parameters field is an explicit NULL (strict per RFC 3279
§2.3.1 / fix H-7), and the inner BIT STRING decodes as a valid
PKCS#1 RSAPublicKey.
Sourcepub fn from_spki_pem(pem: &str) -> Result<Self, Error>
pub fn from_spki_pem(pem: &str) -> Result<Self, Error>
Parses an SPKI PEM document (-----BEGIN PUBLIC KEY-----, RFC 7468).
The legacy RSA PUBLIC KEY PKCS#1 label is not accepted here —
use from_pkcs1_pem for that form.
Source§impl<const LIMBS: usize> RsaPublicKey<LIMBS>
impl<const LIMBS: usize> RsaPublicKey<LIMBS>
Sourcepub fn encrypt_pkcs1v15<R: RngCore + CryptoRng>(
&self,
msg: &[u8],
rng: &mut R,
) -> Result<Vec<u8>, Error>
pub fn encrypt_pkcs1v15<R: RngCore + CryptoRng>( &self, msg: &[u8], rng: &mut R, ) -> Result<Vec<u8>, Error>
Encrypts msg with PKCS#1 v1.5 (RFC 8017 §7.2.1). Returns the
LIMBS*8-byte ciphertext.
§Errors
Error::MessageTooLong if msg.len() > k - 11, where k = LIMBS*8.
Sourcepub fn encrypt_oaep<D: Digest, R: RngCore + CryptoRng>(
&self,
msg: &[u8],
label: &[u8],
rng: &mut R,
) -> Result<Vec<u8>, Error>
pub fn encrypt_oaep<D: Digest, R: RngCore + CryptoRng>( &self, msg: &[u8], label: &[u8], rng: &mut R, ) -> Result<Vec<u8>, Error>
Encrypts msg with RSAES-OAEP (RFC 8017 §7.1.1), using hash D for both
the label hash and MGF1, and the empty label by default — pass label
to bind context. Returns the LIMBS*8-byte ciphertext.
rng must be a cryptographically secure CSPRNG (see CryptoRng) —
OAEP’s security reduction depends on the seed being unpredictable.
§Errors
Error::MessageTooLong if msg.len() > k - 2·hLen - 2.
Sourcepub fn verify_pkcs1v15<D: Pkcs1Digest>(
&self,
msg: &[u8],
sig: &[u8],
) -> Result<(), Error>
pub fn verify_pkcs1v15<D: Pkcs1Digest>( &self, msg: &[u8], sig: &[u8], ) -> Result<(), Error>
Verifies a PKCS#1 v1.5 signature over msg, hashing with D.
§Errors
Error::Verification if the signature is invalid;
Error::InvalidLength if sig is not LIMBS*8 bytes.
Trait Implementations§
Source§impl<const LIMBS: usize> Clone for RsaPublicKey<LIMBS>
impl<const LIMBS: usize> Clone for RsaPublicKey<LIMBS>
Source§fn clone(&self) -> RsaPublicKey<LIMBS>
fn clone(&self) -> RsaPublicKey<LIMBS>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const LIMBS: usize> Debug for RsaPublicKey<LIMBS>
impl<const LIMBS: usize> Debug for RsaPublicKey<LIMBS>
impl<const LIMBS: usize> Eq for RsaPublicKey<LIMBS>
Source§impl<const LIMBS: usize> PartialEq for RsaPublicKey<LIMBS>
impl<const LIMBS: usize> PartialEq for RsaPublicKey<LIMBS>
Source§fn eq(&self, other: &RsaPublicKey<LIMBS>) -> bool
fn eq(&self, other: &RsaPublicKey<LIMBS>) -> bool
self and other values to be equal, and is used by ==.