pub struct PrivateKeyInfo<Params, Key, PubKey> {
pub algorithm: AlgorithmIdentifier<Params>,
pub private_key: Key,
pub public_key: Option<PubKey>,
}Expand description
PKCS#8 PrivateKeyInfo.
ASN.1 structure containing an AlgorithmIdentifier, private key
data in an algorithm specific format, and optional attributes
(ignored by this implementation).
Supports PKCS#8 v1 as described in RFC 5208 and PKCS#8 v2 as described in RFC 5958. PKCS#8 v2 keys include an additional public key field.
§PKCS#8 v1 PrivateKeyInfo
Described in RFC 5208 Section 5:
PrivateKeyInfo ::= SEQUENCE {
version Version,
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
privateKey PrivateKey,
attributes [0] IMPLICIT Attributes OPTIONAL }
Version ::= INTEGER
PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
PrivateKey ::= OCTET STRING
Attributes ::= SET OF Attribute§PKCS#8 v2 OneAsymmetricKey
PKCS#8 OneAsymmetricKey as described in RFC 5958 Section 2:
PrivateKeyInfo ::= OneAsymmetricKey
OneAsymmetricKey ::= SEQUENCE {
version Version,
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
privateKey PrivateKey,
attributes [0] Attributes OPTIONAL,
...,
[[2: publicKey [1] PublicKey OPTIONAL ]],
...
}
Version ::= INTEGER { v1(0), v2(1) } (v1, ..., v2)
PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
PrivateKey ::= OCTET STRING
Attributes ::= SET OF Attribute
PublicKey ::= BIT STRINGFields§
§algorithm: AlgorithmIdentifier<Params>X.509 AlgorithmIdentifier for the private key type.
private_key: KeyPrivate key data. Exact content format is different between algorithms.
public_key: Option<PubKey>Public key data, optionally available if version is V2.
Implementations§
Source§impl<Params, Key, PubKey> PrivateKeyInfo<Params, Key, PubKey>
impl<Params, Key, PubKey> PrivateKeyInfo<Params, Key, PubKey>
Sourcepub fn new(
algorithm: AlgorithmIdentifier<Params>,
private_key: Key,
) -> PrivateKeyInfo<Params, Key, PubKey>
pub fn new( algorithm: AlgorithmIdentifier<Params>, private_key: Key, ) -> PrivateKeyInfo<Params, Key, PubKey>
Create a new PKCS#8 PrivateKeyInfo message.
This is a helper method which initializes attributes and public_key
to None, helpful if you aren’t using those.
Sourcepub fn version(&self) -> Version
pub fn version(&self) -> Version
Get the PKCS#8 Version for this structure.
Version::V1 if public_key is None, Version::V2 if Some.
Source§impl<'a, Params, Key, PubKey> PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
impl<'a, Params, Key, PubKey> PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
Sourcepub fn encrypt_with_rng<R>(
&self,
rng: &mut R,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument, Error>where
R: TryCryptoRng,
pub fn encrypt_with_rng<R>(
&self,
rng: &mut R,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument, Error>where
R: TryCryptoRng,
Encrypt this private key using an encryption key derived from the provided password.
This function allows the RNG used to derive the salt/IV to be specified directly.
§Errors
- Propagates errors from calling
Encode::to_deronSelf. - Returns errors in the event encryption failed.
Sourcepub fn encrypt_with_params(
&self,
pbes2_params: Parameters,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument, Error>
pub fn encrypt_with_params( &self, pbes2_params: Parameters, password: impl AsRef<[u8]>, ) -> Result<SecretDocument, Error>
Encrypt this private key using a symmetric encryption key derived from the provided password
and pbes2::Parameters.
§Errors
- Propagates errors from calling
Encode::to_deronSelf. - Returns errors in the event encryption failed.
Trait Implementations§
Source§impl<Params, Key, PubKey> Clone for PrivateKeyInfo<Params, Key, PubKey>
impl<Params, Key, PubKey> Clone for PrivateKeyInfo<Params, Key, PubKey>
Source§fn clone(&self) -> PrivateKeyInfo<Params, Key, PubKey>
fn clone(&self) -> PrivateKeyInfo<Params, Key, PubKey>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Params, Key, PubKey> Debug for PrivateKeyInfo<Params, Key, PubKey>
impl<Params, Key, PubKey> Debug for PrivateKeyInfo<Params, Key, PubKey>
Source§impl DecodePrivateKey for PrivateKeyInfo<Any, OctetString, BitString>
impl DecodePrivateKey for PrivateKeyInfo<Any, OctetString, BitString>
Source§fn from_pkcs8_der(
bytes: &[u8],
) -> Result<PrivateKeyInfo<Any, OctetString, BitString>, Error>
fn from_pkcs8_der( bytes: &[u8], ) -> Result<PrivateKeyInfo<Any, OctetString, BitString>, Error>
Source§fn from_pkcs8_pem(
pem: &str,
) -> Result<PrivateKeyInfo<Any, OctetString, BitString>, Error>
fn from_pkcs8_pem( pem: &str, ) -> Result<PrivateKeyInfo<Any, OctetString, BitString>, Error>
Source§fn from_pkcs8_encrypted_der(
bytes: &[u8],
password: impl AsRef<[u8]>,
) -> Result<Self, Error>
fn from_pkcs8_encrypted_der( bytes: &[u8], password: impl AsRef<[u8]>, ) -> Result<Self, Error>
Source§fn from_pkcs8_encrypted_pem(
s: &str,
password: impl AsRef<[u8]>,
) -> Result<Self, Error>
fn from_pkcs8_encrypted_pem( s: &str, password: impl AsRef<[u8]>, ) -> Result<Self, Error>
Source§impl<'a, Params, Key, PubKey> DecodeValue<'a> for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a,
impl<'a, Params, Key, PubKey> DecodeValue<'a> for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a,
Source§impl EncodePrivateKey for PrivateKeyInfo<Any, OctetString, BitString>
impl EncodePrivateKey for PrivateKeyInfo<Any, OctetString, BitString>
Source§fn to_pkcs8_der(&self) -> Result<SecretDocument, Error>
fn to_pkcs8_der(&self) -> Result<SecretDocument, Error>
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>
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>
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>
Source§impl EncodePrivateKey for PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>
impl EncodePrivateKey for PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>
Source§fn to_pkcs8_der(&self) -> Result<SecretDocument, Error>
fn to_pkcs8_der(&self) -> Result<SecretDocument, Error>
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>
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>
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>
Source§impl<'a, Params, Key, PubKey> EncodeValue for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: EncodeValue + FixedTag,
PubKey: BitStringLike,
impl<'a, Params, Key, PubKey> EncodeValue for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: EncodeValue + FixedTag,
PubKey: BitStringLike,
Source§impl OwnedToRef for PrivateKeyInfo<Any, OctetString, BitString>
impl OwnedToRef for PrivateKeyInfo<Any, OctetString, BitString>
Source§type Borrowed<'a> = PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>
type Borrowed<'a> = PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>
Source§fn owned_to_ref(
&self,
) -> <PrivateKeyInfo<Any, OctetString, BitString> as OwnedToRef>::Borrowed<'_>
fn owned_to_ref( &self, ) -> <PrivateKeyInfo<Any, OctetString, BitString> as OwnedToRef>::Borrowed<'_>
Source§impl<Params, Key, PubKey> PemLabel for PrivateKeyInfo<Params, Key, PubKey>
Available on crate feature pem only.
impl<Params, Key, PubKey> PemLabel for PrivateKeyInfo<Params, Key, PubKey>
pem only.Source§impl<'a> RefToOwned<'a> for PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>
impl<'a> RefToOwned<'a> for PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>
Source§type Owned = PrivateKeyInfo<Any, OctetString, BitString>
type Owned = PrivateKeyInfo<Any, OctetString, BitString>
Source§fn ref_to_owned(
&self,
) -> <PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>> as RefToOwned<'a>>::Owned
fn ref_to_owned( &self, ) -> <PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>> as RefToOwned<'a>>::Owned
impl<'a, Params, Key, PubKey> Sequence<'a> for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
Source§impl<'a, Params, Key, PubKey> TryFrom<&'a [u8]> for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
impl<'a, Params, Key, PubKey> TryFrom<&'a [u8]> for PrivateKeyInfo<Params, Key, PubKey>where
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
Source§impl<C> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SecretKey<C>
impl<C> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SecretKey<C>
Source§fn try_from(
private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>,
) -> Result<SecretKey<C>, Error>
fn try_from( private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>, ) -> Result<SecretKey<C>, Error>
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,
encoding only.Source§fn try_from(
private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>,
) -> Result<SigningKey<D>, Error>
fn try_from( private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>, ) -> Result<SigningKey<D>, Error>
Source§impl TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for RsaPrivateKey
impl TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for RsaPrivateKey
Source§fn try_from(
private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>,
) -> Result<RsaPrivateKey, Error>
fn try_from( private_key_info: PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>, ) -> Result<RsaPrivateKey, Error>
Source§impl<C> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SigningKey<C>where
C: EcdsaCurve + AssociatedOid + CurveArithmetic,
<C as CurveArithmetic>::AffinePoint: FromSec1Point<C> + ToSec1Point<C>,
<C as Curve>::FieldBytesSize: ModulusSize,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>>,
Available on crate feature pkcs8 only.
impl<C> TryFrom<PrivateKeyInfo<AnyRef<'_>, &OctetStringRef, BitStringRef<'_>>> for SigningKey<C>where
C: EcdsaCurve + AssociatedOid + CurveArithmetic,
<C as CurveArithmetic>::AffinePoint: FromSec1Point<C> + ToSec1Point<C>,
<C as Curve>::FieldBytesSize: ModulusSize,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>>,
pkcs8 only.