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) -> Self
pub fn new(algorithm: AlgorithmIdentifier<Params>, private_key: Key) -> Self
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(&self, password: impl AsRef<[u8]>) -> Result<SecretDocument>
Available on crate feature getrandom only.
pub fn encrypt(&self, password: impl AsRef<[u8]>) -> Result<SecretDocument>
getrandom only.Encrypt this private key using an encryption key derived from the provided password.
Uses the following algorithms for encryption:
- PBKDF: scrypt with default parameters:
- log₂(N): 15
- r: 8
- p: 1
- Cipher: AES-256-CBC (best available option for PKCS#5 encryption)
§Errors
- Propagates errors from calling
Encode::to_deronSelf. - Returns errors in the event encryption failed.
Sourcepub fn encrypt_with_rng<R: TryCryptoRng>(
&self,
rng: &mut R,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument>
Available on crate feature encryption only.
pub fn encrypt_with_rng<R: TryCryptoRng>( &self, rng: &mut R, password: impl AsRef<[u8]>, ) -> Result<SecretDocument>
encryption only.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>
Available on crate feature encryption only.
pub fn encrypt_with_params( &self, pbes2_params: Parameters, password: impl AsRef<[u8]>, ) -> Result<SecretDocument>
encryption only.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: Clone, Key: Clone, PubKey: Clone> Clone for PrivateKeyInfo<Params, Key, PubKey>
impl<Params: Clone, Key: Clone, PubKey: Clone> Clone for PrivateKeyInfo<Params, Key, PubKey>
Source§fn clone(&self) -> PrivateKeyInfo<Params, Key, PubKey>
fn clone(&self) -> PrivateKeyInfo<Params, Key, PubKey>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Params, Key, PubKey> CtEq for PrivateKeyInfo<Params, Key, PubKey>
Available on crate feature ctutils only.
impl<Params, Key, PubKey> CtEq for PrivateKeyInfo<Params, Key, PubKey>
ctutils only.Source§impl<Params, Key, PubKey> Debug for PrivateKeyInfo<Params, Key, PubKey>
impl<Params, Key, PubKey> Debug for PrivateKeyInfo<Params, Key, PubKey>
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<'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<Params, Key, PubKey> PartialEq for PrivateKeyInfo<Params, Key, PubKey>
Available on crate feature ctutils only.
impl<Params, Key, PubKey> PartialEq for PrivateKeyInfo<Params, Key, PubKey>
ctutils only.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, 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<'a, Params, Key, PubKey> TryFrom<&PrivateKeyInfo<Params, Key, PubKey>> for SecretDocumentwhere
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
Available on crate feature alloc only.
impl<'a, Params, Key, PubKey> TryFrom<&PrivateKeyInfo<Params, Key, PubKey>> for SecretDocumentwhere
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
alloc only.Source§fn try_from(
private_key: &PrivateKeyInfo<Params, Key, PubKey>,
) -> Result<SecretDocument>
fn try_from( private_key: &PrivateKeyInfo<Params, Key, PubKey>, ) -> Result<SecretDocument>
Source§impl<'a, Params, Key, PubKey> TryFrom<PrivateKeyInfo<Params, Key, PubKey>> for SecretDocumentwhere
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
Available on crate feature alloc only.
impl<'a, Params, Key, PubKey> TryFrom<PrivateKeyInfo<Params, Key, PubKey>> for SecretDocumentwhere
Params: Choice<'a, Error = Error> + Encode,
Key: DecodeValue<'a, Error = Error> + FixedTag + 'a + EncodeValue,
PubKey: DecodeValue<'a, Error = Error> + FixedTag + 'a + BitStringLike,
alloc only.Source§fn try_from(
private_key: PrivateKeyInfo<Params, Key, PubKey>,
) -> Result<SecretDocument>
fn try_from( private_key: PrivateKeyInfo<Params, Key, PubKey>, ) -> Result<SecretDocument>
impl<Params, Key, PubKey> Eq for PrivateKeyInfo<Params, Key, PubKey>
ctutils only.