pub struct SigningKey<D>where
D: Digest,{
inner: PrivateKey,
prefix: Vec<u8>,
phantom: PhantomData<D>,
}Expand description
Signing key for RSASSA-PKCS1-v1_5 signatures as described in RFC8017 § 8.2.
With the getrandom feature (enabled by default), signing uses the operating system RNG for
RSA blinding. Without this feature, use the randomized signing traits to supply an RNG.
Blinding does not change the deterministic signature value.
Fields§
§inner: PrivateKey§prefix: Vec<u8>§phantom: PhantomData<D>Implementations§
Source§impl<D> SigningKey<D>where
D: Digest + AssociatedOid,
impl<D> SigningKey<D>where
D: Digest + AssociatedOid,
Sourcepub fn new(key: PrivateKey) -> Self
pub fn new(key: PrivateKey) -> Self
Create a new signing key with a prefix for the digest D.
Source§impl<D> SigningKey<D>where
D: Digest,
impl<D> SigningKey<D>where
D: Digest,
Sourcepub fn new_unprefixed(key: PrivateKey) -> Self
pub fn new_unprefixed(key: PrivateKey) -> Self
Create a new signing key from the give RSA private key with an empty prefix.
§Note: unprefixed signatures are uncommon
In most cases you’ll want to use SigningKey::new.
Sourcepub fn random_unprefixed<R: TryCryptoRng + ?Sized>(
rng: &mut R,
bit_size: usize,
) -> Result<Self>
pub fn random_unprefixed<R: TryCryptoRng + ?Sized>( rng: &mut R, bit_size: usize, ) -> Result<Self>
Generate a new signing key with an empty prefix.
Trait Implementations§
Source§impl<D> AsRef<PrivateKey> for SigningKey<D>where
D: Digest,
impl<D> AsRef<PrivateKey> for SigningKey<D>where
D: Digest,
Source§fn as_ref(&self) -> &PrivateKey
fn as_ref(&self) -> &PrivateKey
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl<D> AssociatedAlgorithmIdentifier for SigningKey<D>where
D: Digest,
Available on crate feature encoding only.
impl<D> AssociatedAlgorithmIdentifier for SigningKey<D>where
D: Digest,
Available on crate feature
encoding only.Source§const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = pkcs1::ALGORITHM_ID
const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = pkcs1::ALGORITHM_ID
AlgorithmIdentifier for this structure.Source§impl<D> Clone for SigningKey<D>
impl<D> Clone for SigningKey<D>
Source§fn clone(&self) -> SigningKey<D>
fn clone(&self) -> SigningKey<D>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<D> Debug for SigningKey<D>
impl<D> Debug for SigningKey<D>
Source§impl<D> DigestSigner<D, Signature> for SigningKey<D>
impl<D> DigestSigner<D, Signature> for SigningKey<D>
Source§impl<D> EncodePrivateKey for SigningKey<D>where
D: Digest,
Available on crate feature encoding only.
impl<D> EncodePrivateKey for SigningKey<D>where
D: Digest,
Available on crate feature
encoding only.Source§fn to_pkcs8_der(&self) -> Result<SecretDocument>
fn to_pkcs8_der(&self) -> Result<SecretDocument>
Serialize a
SecretDocument containing a PKCS#8-encoded private key. Read moreSource§fn to_pkcs8_pem(
&self,
line_ending: LineEnding,
) -> Result<Zeroizing<String>, Error>
fn to_pkcs8_pem( &self, line_ending: LineEnding, ) -> Result<Zeroizing<String>, Error>
Serialize this private key as PEM-encoded PKCS#8 with the given
LineEnding. Read moreSource§fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Write ASN.1 DER-encoded PKCS#8 private key to the given path. Read more
Source§fn write_pkcs8_pem_file(
&self,
path: impl AsRef<Path>,
line_ending: LineEnding,
) -> Result<(), Error>
fn write_pkcs8_pem_file( &self, path: impl AsRef<Path>, line_ending: LineEnding, ) -> Result<(), Error>
Write ASN.1 PEM-encoded PKCS#8 private key to the given path. Read more
Source§impl<D> From<PrivateKey> for SigningKey<D>where
D: Digest + AssociatedOid,
impl<D> From<PrivateKey> for SigningKey<D>where
D: Digest + AssociatedOid,
Source§fn from(key: PrivateKey) -> Self
fn from(key: PrivateKey) -> Self
Converts to this type from the input type.
Source§impl<D> From<SigningKey<D>> for PrivateKeywhere
D: Digest,
impl<D> From<SigningKey<D>> for PrivateKeywhere
D: Digest,
Source§fn from(key: SigningKey<D>) -> Self
fn from(key: SigningKey<D>) -> Self
Converts to this type from the input type.
Source§impl<D> Generate for SigningKey<D>where
D: Digest + AssociatedOid,
Generate a key with the default RSA parameters and a prefix for the digest D.
impl<D> Generate for SigningKey<D>where
D: Digest + AssociatedOid,
Generate a key with the default RSA parameters and a prefix for the digest D.
See PrivateKey::DEFAULT_BITS for the default modulus size.
Source§fn try_generate_from_rng<R: TryCryptoRng + ?Sized>(
rng: &mut R,
) -> Result<Self, R::Error>
fn try_generate_from_rng<R: TryCryptoRng + ?Sized>( rng: &mut R, ) -> Result<Self, R::Error>
Generate random key using the provided
TryCryptoRng. Read moreSource§fn generate_from_rng<R>(rng: &mut R) -> Self
fn generate_from_rng<R>(rng: &mut R) -> Self
Generate random key using the provided
CryptoRng.Source§impl<D> Keypair for SigningKey<D>where
D: Digest,
impl<D> Keypair for SigningKey<D>where
D: Digest,
Source§type VerifyingKey = VerifyingKey<D>
type VerifyingKey = VerifyingKey<D>
Verifying key type for this keypair.
Source§fn verifying_key(&self) -> Self::VerifyingKey
fn verifying_key(&self) -> Self::VerifyingKey
Get the verifying key which can verify signatures produced by the
signing key portion of this keypair.
Source§impl<D> MultipartSigner<Signature> for SigningKey<D>where
D: Digest,
impl<D> MultipartSigner<Signature> for SigningKey<D>where
D: Digest,
Source§fn try_multipart_sign(&self, msg: &[&[u8]]) -> Result<Signature>
fn try_multipart_sign(&self, msg: &[&[u8]]) -> Result<Signature>
Equivalent of
Signer::try_sign() but the message is provided in non-contiguous byte
slices. Read moreSource§fn multipart_sign(&self, msg: &[&[u8]]) -> S
fn multipart_sign(&self, msg: &[&[u8]]) -> S
Equivalent of
Signer::sign() but the message is provided in non-contiguous byte slices.Source§impl<D> PartialEq for SigningKey<D>where
D: Digest,
impl<D> PartialEq for SigningKey<D>where
D: Digest,
Source§impl<D> PrehashSigner<Signature> for SigningKey<D>where
D: Digest,
impl<D> PrehashSigner<Signature> for SigningKey<D>where
D: Digest,
Source§impl<D> RandomizedDigestSigner<D, Signature> for SigningKey<D>
impl<D> RandomizedDigestSigner<D, Signature> for SigningKey<D>
Source§impl<D> RandomizedMultipartSigner<Signature> for SigningKey<D>where
D: Digest,
impl<D> RandomizedMultipartSigner<Signature> for SigningKey<D>where
D: Digest,
Source§fn try_multipart_sign_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
msg: &[&[u8]],
) -> Result<Signature>
fn try_multipart_sign_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, msg: &[&[u8]], ) -> Result<Signature>
Equivalent of
RandomizedSigner::try_sign_with_rng() but the message is provided in
non-contiguous byte slices. Read moreSource§fn multipart_sign_with_rng<R>(&self, rng: &mut R, msg: &[&[u8]]) -> S
fn multipart_sign_with_rng<R>(&self, rng: &mut R, msg: &[&[u8]]) -> S
Equivalent of
RandomizedSigner::sign_with_rng() but the message is provided in
non-contiguous byte slices.Source§impl<D> RandomizedSigner<Signature> for SigningKey<D>where
D: Digest,
impl<D> RandomizedSigner<Signature> for SigningKey<D>where
D: Digest,
Source§fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
msg: &[u8],
) -> Result<Signature>
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, msg: &[u8], ) -> Result<Signature>
Attempt to sign the given message, returning a digital signature on success, or an error if
something went wrong. Read more
Source§impl<D> SignatureAlgorithmIdentifier for SigningKey<D>where
D: Digest + RsaSignatureAssociatedOid,
Available on crate feature encoding only.
impl<D> SignatureAlgorithmIdentifier for SigningKey<D>where
D: Digest + RsaSignatureAssociatedOid,
Available on crate feature
encoding only.Source§const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static>
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static>
AlgorithmIdentifier for the corresponding signature system.Source§impl<D> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SigningKey<D>where
D: Digest + AssociatedOid,
Available on crate feature encoding only.
impl<D> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SigningKey<D>where
D: Digest + AssociatedOid,
Available on crate feature
encoding only.impl<D> ZeroizeOnDrop for SigningKey<D>where
D: Digest,
Auto Trait Implementations§
impl<D> Freeze for SigningKey<D>
impl<D> RefUnwindSafe for SigningKey<D>where
D: RefUnwindSafe,
impl<D> Send for SigningKey<D>where
D: Send,
impl<D> Sync for SigningKey<D>where
D: Sync,
impl<D> Unpin for SigningKey<D>where
D: Unpin,
impl<D> UnsafeUnpin for SigningKey<D>
impl<D> UnwindSafe for SigningKey<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<S, T> AsyncRandomizedSigner<S> for Twhere
T: RandomizedSigner<S>,
impl<S, T> AsyncRandomizedSigner<S> for Twhere
T: RandomizedSigner<S>,
Source§async fn try_sign_with_rng_async<R>(
&self,
rng: &mut R,
msg: &[u8],
) -> Result<S, Error>where
R: TryCryptoRng + ?Sized,
async fn try_sign_with_rng_async<R>(
&self,
rng: &mut R,
msg: &[u8],
) -> Result<S, Error>where
R: TryCryptoRng + ?Sized,
Attempt to sign the given message, returning a digital signature on success, or an error if
something went wrong. Read more
Source§impl<S, T> AsyncSigner<S> for Twhere
T: Signer<S>,
impl<S, T> AsyncSigner<S> for Twhere
T: Signer<S>,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodePrivateKey for Twhere
T: for<'a> TryFrom<PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>, Error = Error>,
impl<T> DecodePrivateKey for Twhere
T: for<'a> TryFrom<PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>, Error = Error>,
Source§fn from_pkcs8_der(bytes: &[u8]) -> Result<T, Error>
fn from_pkcs8_der(bytes: &[u8]) -> Result<T, Error>
Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary format). Read more
Source§fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
Deserialize PKCS#8-encoded private key from PEM. Read more
Source§impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
Source§fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
AlgorithmIdentifier for this structure. Read moreSource§impl<T> DynSignatureAlgorithmIdentifier for Twhere
T: SignatureAlgorithmIdentifier,
impl<T> DynSignatureAlgorithmIdentifier for Twhere
T: SignatureAlgorithmIdentifier,
Source§fn signature_algorithm_identifier(
&self,
) -> Result<AlgorithmIdentifier<Any>, Error>
fn signature_algorithm_identifier( &self, ) -> Result<AlgorithmIdentifier<Any>, Error>
AlgorithmIdentifier for the corresponding signature system. Read moreSource§impl<S, T> RandomizedSignerMut<S> for Twhere
T: RandomizedSigner<S>,
impl<S, T> RandomizedSignerMut<S> for Twhere
T: RandomizedSigner<S>,
Source§fn try_sign_with_rng<R>(&mut self, rng: &mut R, msg: &[u8]) -> Result<S, Error>where
R: TryCryptoRng + ?Sized,
fn try_sign_with_rng<R>(&mut self, rng: &mut R, msg: &[u8]) -> Result<S, Error>where
R: TryCryptoRng + ?Sized,
Attempt to sign the given message, updating the state, and returning a digital signature on
success, or an error if something went wrong. Read more