pub struct Pkcs8PrivateKey { /* private fields */ }Expand description
DER-encoded PKCS#8 private key per RFC 5958 §2.
OneAsymmetricKey ::= SEQUENCE {
version Version,
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
privateKey PrivateKey,
attributes [0] Attributes OPTIONAL,
...,
[[2: publicKey [1] PublicKey OPTIONAL ]],
...
}For ML-KEM keys, the privateKeyAlgorithm uses the ML-KEM OIDs (2.16.840.1.101.3.4.4.{1,2,3}) per FIPS 203.
Implementations§
Source§impl Pkcs8PrivateKey
impl Pkcs8PrivateKey
Sourcepub fn new(der: Vec<u8>, algorithm_oid: String, version: Pkcs8Version) -> Self
pub fn new(der: Vec<u8>, algorithm_oid: String, version: Pkcs8Version) -> Self
Creates a new PKCS#8 private key wrapper.
§Arguments
der- DER-encoded OneAsymmetricKey or PrivateKeyInfoalgorithm_oid- Algorithm OID from the privateKeyAlgorithm fieldversion- PKCS#8 version (v1 or v2)
Sourcepub fn v1(der: Vec<u8>, algorithm_oid: String) -> Self
pub fn v1(der: Vec<u8>, algorithm_oid: String) -> Self
Creates a v1 (PrivateKeyInfo, unencrypted, no public key) wrapper.
Sourcepub fn v2(der: Vec<u8>, algorithm_oid: String) -> Self
pub fn v2(der: Vec<u8>, algorithm_oid: String) -> Self
Creates a v2 (OneAsymmetricKey, with public key) wrapper.
Sourcepub fn algorithm_oid(&self) -> &str
pub fn algorithm_oid(&self) -> &str
Returns the algorithm OID string.
Sourcepub fn version(&self) -> Pkcs8Version
pub fn version(&self) -> Pkcs8Version
Returns the PKCS#8 version.
Sourcepub fn validate_algorithm(&self, expected_oid: &str) -> EstResult<()>
pub fn validate_algorithm(&self, expected_oid: &str) -> EstResult<()>
Validates that the algorithm OID matches the expected key type.
For ML-KEM keys, the OID must be one of:
- 2.16.840.1.101.3.4.4.1 (ML-KEM-512)
- 2.16.840.1.101.3.4.4.2 (ML-KEM-768)
- 2.16.840.1.101.3.4.4.3 (ML-KEM-1024)
Sourcepub fn to_enveloped_data(&self, recipient_cert_der: &[u8]) -> EstResult<Vec<u8>>
pub fn to_enveloped_data(&self, recipient_cert_der: &[u8]) -> EstResult<Vec<u8>>
Wraps the private key in CMS EnvelopedData for secure transport.
Per RFC 7030 §4.4.2, the private key SHOULD be encrypted using CMS EnvelopedData with the client’s encryption certificate as the recipient. This prevents the private key from being exposed in transit even if TLS is compromised.
This method returns a placeholder DER that wraps the key bytes. Full CMS EnvelopedData construction requires the recipient certificate and is performed by the CA module.
§Arguments
recipient_cert_der- DER-encoded recipient certificate for key encryption
Trait Implementations§
Source§impl Clone for Pkcs8PrivateKey
impl Clone for Pkcs8PrivateKey
Source§fn clone(&self) -> Pkcs8PrivateKey
fn clone(&self) -> Pkcs8PrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more