Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkcs1/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub trait EncodeRsaPrivateKey {

/// Write ASN.1 DER-encoded PKCS#1 private key to the given path.
#[cfg(all(feature = "pem", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "pem", feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "std"))))]
fn write_pkcs1_pem_file(&self, path: impl AsRef<Path>, line_ending: LineEnding) -> Result<()> {
self.to_pkcs1_der()?.write_pkcs1_pem_file(path, line_ending)
}
Expand Down Expand Up @@ -155,7 +155,7 @@ pub trait EncodeRsaPublicKey {

/// Write ASN.1 DER-encoded public key to the given path.
#[cfg(all(feature = "pem", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "pem", feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "std"))))]
fn write_pkcs1_pem_file(&self, path: impl AsRef<Path>, line_ending: LineEnding) -> Result<()> {
self.to_pkcs1_der()?.write_pkcs1_pem_file(path, line_ending)
}
Expand Down
6 changes: 3 additions & 3 deletions pkcs8/src/document/private_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! PKCS#8 private key document.

use crate::{Error, FromPrivateKey, PrivateKeyInfo, Result, ToPrivateKey};
use crate::{DecodePrivateKey, EncodePrivateKey, Error, PrivateKeyInfo, Result};
use alloc::{borrow::ToOwned, vec::Vec};
use core::{convert::TryFrom, fmt};
use der::Encodable;
Expand Down Expand Up @@ -91,7 +91,7 @@ impl PrivateKeyDocument {
}
}

impl FromPrivateKey for PrivateKeyDocument {
impl DecodePrivateKey for PrivateKeyDocument {
fn from_pkcs8_private_key_info(private_key: PrivateKeyInfo<'_>) -> Result<Self> {
Ok(Self(Zeroizing::new(private_key.to_vec()?)))
}
Expand Down Expand Up @@ -130,7 +130,7 @@ impl FromPrivateKey for PrivateKeyDocument {
}
}

impl ToPrivateKey for PrivateKeyDocument {
impl EncodePrivateKey for PrivateKeyDocument {
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument> {
Ok(self.clone())
}
Expand Down
4 changes: 2 additions & 2 deletions pkcs8/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ pub(crate) mod encrypted_private_key_info;
pub use crate::{
error::{Error, Result},
private_key_info::PrivateKeyInfo,
traits::FromPrivateKey,
traits::DecodePrivateKey,
version::Version,
};
pub use der::{self, asn1::ObjectIdentifier};
pub use spki::{AlgorithmIdentifier, DecodePublicKey, SubjectPublicKeyInfo};

#[cfg(feature = "alloc")]
pub use {
crate::{document::private_key::PrivateKeyDocument, traits::ToPrivateKey},
crate::{document::private_key::PrivateKeyDocument, traits::EncodePrivateKey},
spki::{EncodePublicKey, PublicKeyDocument},
};

Expand Down
8 changes: 4 additions & 4 deletions pkcs8/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::AlgorithmIdentifier;
const PKCS1_OID: ObjectIdentifier = ObjectIdentifier::new("1.2.840.113549.1.1.1");

/// Parse a private key object from a PKCS#8 encoded document.
pub trait FromPrivateKey: Sized {
pub trait DecodePrivateKey: Sized {
/// Parse the [`PrivateKeyInfo`] from a PKCS#8-encoded document.
fn from_pkcs8_private_key_info(private_key_info: PrivateKeyInfo<'_>) -> Result<Self>;

Expand Down Expand Up @@ -108,7 +108,7 @@ pub trait FromPrivateKey: Sized {
/// Serialize a private key object to a PKCS#8 encoded document.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub trait ToPrivateKey {
pub trait EncodePrivateKey {
/// Serialize a [`PrivateKeyDocument`] containing a PKCS#8-encoded private key.
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument>;

Expand Down Expand Up @@ -162,7 +162,7 @@ pub trait ToPrivateKey {

#[cfg(feature = "pkcs1")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs1")))]
impl<K: pkcs1::DecodeRsaPrivateKey> FromPrivateKey for K {
impl<K: pkcs1::DecodeRsaPrivateKey> DecodePrivateKey for K {
fn from_pkcs8_private_key_info(pkcs8_key: PrivateKeyInfo<'_>) -> Result<Self> {
pkcs8_key.algorithm.assert_algorithm_oid(PKCS1_OID)?;

Expand All @@ -178,7 +178,7 @@ impl<K: pkcs1::DecodeRsaPrivateKey> FromPrivateKey for K {
#[cfg(all(feature = "alloc", feature = "pkcs1"))]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs1")))]
impl<K: pkcs1::EncodeRsaPrivateKey> ToPrivateKey for K {
impl<K: pkcs1::EncodeRsaPrivateKey> EncodePrivateKey for K {
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument> {
let pkcs1_der = self.to_pkcs1_der()?;

Expand Down
2 changes: 1 addition & 1 deletion pkcs8/tests/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pkcs8::{PrivateKeyInfo, Version};
use pkcs8::PrivateKeyDocument;

#[cfg(feature = "std")]
use pkcs8::FromPrivateKey;
use pkcs8::DecodePrivateKey;

/// Elliptic Curve (P-256) PKCS#8 private key encoded as ASN.1 DER
const EC_P256_DER_EXAMPLE: &[u8] = include_bytes!("examples/p256-priv.der");
Expand Down