Struct KeyPair
pub struct KeyPair { /* private fields */ }aws-lc and crypto and std only.Expand description
An RSA key pair, used for signing.
Implementations§
§impl KeyPair
impl KeyPair
pub fn generate(size: KeySize) -> Result<KeyPair, Unspecified>
pub fn generate(size: KeySize) -> Result<KeyPair, Unspecified>
Generate a RSA KeyPair of the specified key-strength.
Supports the following key sizes:
KeySize::Rsa2048KeySize::Rsa3072KeySize::Rsa4096KeySize::Rsa8192
§Errors
Unspecified: Any key generation failure.
pub fn from_pkcs8(pkcs8: &[u8]) -> Result<KeyPair, KeyRejected>
pub fn from_pkcs8(pkcs8: &[u8]) -> Result<KeyPair, KeyRejected>
Parses an unencrypted PKCS#8 DER encoded RSA private key.
Keys can be generated using KeyPair::generate.
§ring-compatibility
aws-lc-rs does not impose the same limitations that ring does for RSA keys. Thus signatures may be generated by keys that are not accepted by ring. In particular:
- RSA private keys ranging between 2048-bit keys and 8192-bit keys are supported.
- The public exponent does not have a required minimum size.
§Errors
error::KeyRejected if bytes do not encode an RSA private key or if the key is otherwise
not acceptable.
pub fn from_der(input: &[u8]) -> Result<KeyPair, KeyRejected>
pub fn from_der(input: &[u8]) -> Result<KeyPair, KeyRejected>
pub fn sign(
&self,
padding_alg: &'static dyn RsaEncoding,
_rng: &dyn SecureRandom,
msg: &[u8],
signature: &mut [u8],
) -> Result<(), Unspecified>
pub fn sign( &self, padding_alg: &'static dyn RsaEncoding, _rng: &dyn SecureRandom, msg: &[u8], signature: &mut [u8], ) -> Result<(), Unspecified>
Sign msg. msg is digested using the digest algorithm from
padding_alg and the digest is then padded using the padding algorithm
from padding_alg. The signature is written into signature;
signature’s length must be exactly the length returned by
public_modulus_len().
This function does not take a precomputed digest; instead, sign
calculates the digest itself. See sign_digest.
§ring Compatibility
Our implementation ignores the SecureRandom parameter.
§Errors
error::Unspecified on error.
With “fips” feature enabled, errors if digest length is greater than u32::MAX.
pub fn sign_digest(
&self,
padding_alg: &'static dyn RsaEncoding,
digest: &Digest,
signature: &mut [u8],
) -> Result<(), Unspecified>
pub fn sign_digest( &self, padding_alg: &'static dyn RsaEncoding, digest: &Digest, signature: &mut [u8], ) -> Result<(), Unspecified>
The digest is padded using the padding algorithm
from padding_alg. The signature is written into signature;
signature’s length must be exactly the length returned by
public_modulus_len().
§ring Compatibility
Our implementation ignores the SecureRandom parameter.
§Errors
error::Unspecified on error.
With “fips” feature enabled, errors if digest length is greater than u32::MAX.
pub fn public_modulus_len(&self) -> usize
pub fn public_modulus_len(&self) -> usize
Returns the length in bytes of the key pair’s public modulus.
A signature has the same length as the public modulus.
pub fn from_components<Public, Private>(
components: &KeyPairComponents<Public, Private>,
) -> Result<KeyPair, KeyRejected>
pub fn from_components<Public, Private>( components: &KeyPairComponents<Public, Private>, ) -> Result<KeyPair, KeyRejected>
Constructs an RSA private key from its big-endian-encoded components.
All components, including the CRT parameters (dP, dQ, qInv), are
required and are validated for consistency with one another: the key is
rejected unless n == p * q, d * e == 1 (mod p-1),
d * e == 1 (mod q-1), dP == d (mod p-1), dQ == d (mod q-1), and
qInv == q**-1 (mod p). No primality tests are performed on p and
q.
Only two-prime (not multi-prime) keys are supported. The public
modulus (n) must be 2048 to 8192 bits. The public exponent (e)
must be odd, greater than 1, and no longer than 33 bits.
The public components (n and e) must be encoded without leading
zero bytes, as documented on PublicKeyComponents. Leading zero
bytes are permitted on the private components.
§ring compatibility
aws-lc-rs does not impose the same limitations that ring does, so keys rejected by ring may be accepted here. In particular:
- The public modulus may be up to 8192 bits, rather than 4096.
- The public exponent has no required minimum size, whereas ring requires it to be at least 65537.
In two respects aws-lc-rs is stricter than ring, so a key accepted by ring may be rejected here:
- ring never uses
dand so does not fully validate it. We do validated, which means a key carrying a placeholder or otherwise inconsistentdis rejected. - ring defers validation of the CRT parameters until the key is used for signing. We validate them here, so an inconsistent key fails at construction rather than at first use.
§Errors
KeyRejected if the components do not form a valid, supported RSA
private key.
Trait Implementations§
§impl AsDer<Pkcs8V1Der<'static>> for KeyPair
impl AsDer<Pkcs8V1Der<'static>> for KeyPair
§fn as_der(&self) -> Result<Pkcs8V1Der<'static>, Unspecified>
fn as_der(&self) -> Result<Pkcs8V1Der<'static>, Unspecified>
impl Send for KeyPair
impl Sync for KeyPair
Auto Trait Implementations§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Unpin for KeyPair
impl UnsafeUnpin for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more