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: 3 additions & 1 deletion .github/workflows/spki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
override: true
- run: cargo build --release --target ${{ matrix.target }}
- run: cargo build --release --target ${{ matrix.target }} --features alloc
- run: cargo build --release --target ${{ matrix.target }} --features alloc,fingerprint
- run: cargo build --release --target ${{ matrix.target }} --features fingerprint
- run: cargo build --release --target ${{ matrix.target }} --features pem
- run: cargo build --release --target ${{ matrix.target }} --features alloc,fingerprint,pem

test:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion der/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::{boxed::Box, vec::Vec};
use core::convert::{TryFrom, TryInto};

#[cfg(feature = "pem")]
use {alloc::string::String, pem_rfc7468 as pem};
use {crate::pem, alloc::string::String};

#[cfg(feature = "std")]
use std::{fs, path::Path};
Expand Down
2 changes: 1 addition & 1 deletion der/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::{convert::Infallible, fmt};
use crate::asn1::ObjectIdentifier;

#[cfg(feature = "pem")]
use pem_rfc7468 as pem;
use crate::pem;

/// Result type.
pub type Result<T> = core::result::Result<T, Error>;
Expand Down
4 changes: 4 additions & 0 deletions der/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,8 @@ pub use crypto_bigint as bigint;
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub use der_derive::{Choice, Sequence};

#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
pub use pem_rfc7468 as pem;

pub(crate) use crate::{arrayvec::ArrayVec, byte_slice::ByteSlice, str_slice::StrSlice};
3 changes: 1 addition & 2 deletions pkcs1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ readme = "README.md"
der = { version = "=0.5.0-pre.1", features = ["bigint", "oid"], path = "../der" }

# optional dependencies
pem-rfc7468 = { version = "0.2", optional = true, path = "../pem-rfc7468" }
zeroize = { version = "1", optional = true, default-features = false, features = ["alloc"] }

[dev-dependencies]
hex-literal = "0.3"

[features]
alloc = ["der/alloc", "zeroize"]
pem = ["alloc", "der/pem", "pem-rfc7468/alloc"]
pem = ["alloc", "der/pem"]
std = ["der/std"]

[package.metadata.docs.rs]
Expand Down
16 changes: 8 additions & 8 deletions pkcs1/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ impl fmt::Display for Error {
}
}

impl From<der::Error> for Error {
fn from(err: der::Error) -> Error {
Error::Asn1(err)
}
}

#[cfg(feature = "pem")]
impl From<pem_rfc7468::Error> for Error {
fn from(err: pem_rfc7468::Error) -> Error {
impl From<pem::Error> for Error {
fn from(err: pem::Error) -> Error {
Error::Pem(err)
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl From<der::Error> for Error {
fn from(err: der::Error) -> Error {
Error::Asn1(err)
}
}

#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Expand Down
7 changes: 2 additions & 5 deletions pkcs1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ pub use self::{
version::Version,
};

#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
pub use pem_rfc7468::LineEnding;

#[cfg(feature = "alloc")]
pub use crate::{
private_key::{
Expand All @@ -71,4 +67,5 @@ pub use crate::{
};

#[cfg(feature = "pem")]
use pem_rfc7468 as pem;
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
pub use der::pem::{self, LineEnding};
7 changes: 3 additions & 4 deletions pkcs8/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ spki = { version = "=0.5.0-pre", path = "../spki" }
rand_core = { version = "0.6", optional = true, default-features = false }
pkcs1 = { version = "=0.3.0-pre", optional = true, features = ["alloc"], path = "../pkcs1" }
pkcs5 = { version = "=0.4.0-pre", optional = true, path = "../pkcs5" }
pem-rfc7468 = { version = "0.2", optional = true, path = "../pem-rfc7468" }
subtle = { version = "2", optional = true, default-features = false }
zeroize = { version = "1", optional = true, default-features = false, features = ["alloc"] }

[dev-dependencies]
hex-literal = "0.3"

[features]
alloc = ["der/alloc", "zeroize"]
alloc = ["der/alloc", "spki/alloc", "zeroize"]
3des = ["encryption", "pkcs5/3des"]
des-insecure = ["encryption", "pkcs5/des-insecure"]
encryption = ["alloc", "pkcs5/alloc", "pkcs5/pbes2", "rand_core"]
pem = ["alloc", "pem-rfc7468/alloc"]
pem = ["alloc", "der/pem", "spki/pem"]
sha1 = ["encryption", "pkcs5/sha1"]
std = ["alloc", "der/std"]
std = ["alloc", "der/std", "spki/std"]

[package.metadata.docs.rs]
all-features = true
Expand Down
1 change: 0 additions & 1 deletion pkcs8/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
#[cfg(feature = "pkcs5")]
pub(crate) mod encrypted_private_key;
pub(crate) mod private_key;
pub(crate) mod public_key;
2 changes: 1 addition & 1 deletion pkcs8/src/document/encrypted_private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl EncryptedPrivateKeyDocument {
pub fn to_pem(&self, line_ending: LineEnding) -> Result<Zeroizing<String>> {
pem::encode_string(PEM_TYPE_LABEL, line_ending, &self.0)
.map(Zeroizing::new)
.map_err(|_| Error::Pem)
.map_err(Error::Pem)
}

/// Load [`EncryptedPrivateKeyDocument`] from an ASN.1 DER-encoded file on
Expand Down
2 changes: 1 addition & 1 deletion pkcs8/src/encrypted_private_key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> EncryptedPrivateKeyInfo<'a> {
pub fn to_pem(&self, line_ending: LineEnding) -> Result<Zeroizing<alloc::string::String>> {
pem::encode_string(PEM_TYPE_LABEL, line_ending, self.to_der()?.as_ref())
.map(Zeroizing::new)
.map_err(|_| Error::Pem)
.map_err(Error::Pem)
}
}

Expand Down
15 changes: 8 additions & 7 deletions pkcs8/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use core::fmt;

#[cfg(feature = "pem")]
use crate::pem;

/// Result type
pub type Result<T> = core::result::Result<T, Error>;

Expand Down Expand Up @@ -40,9 +43,8 @@ pub enum Error {
ParametersMalformed,

/// PEM encoding errors.
// TODO(tarcieri): propagate `pem_rfc7468::Error`
#[cfg(feature = "pem")]
Pem,
Pem(pem::Error),

/// Permission denied reading file.
#[cfg(feature = "std")]
Expand All @@ -67,7 +69,7 @@ impl fmt::Display for Error {
Error::Io => f.write_str("I/O error"),
Error::ParametersMalformed => f.write_str("PKCS#8 algorithm parameters malformed"),
#[cfg(feature = "pem")]
Error::Pem => f.write_str("PKCS#8 PEM error"),
Error::Pem(err) => write!(f, "PKCS8 {}", err),
#[cfg(feature = "std")]
Error::PermissionDenied => f.write_str("permission denied"),
#[cfg(feature = "pkcs1")]
Expand All @@ -92,10 +94,9 @@ impl From<der::ErrorKind> for Error {
}

#[cfg(feature = "pem")]
impl From<pem_rfc7468::Error> for Error {
fn from(_: pem_rfc7468::Error) -> Error {
// TODO(tarcieri): propagate `pem_rfc7468::Error`
Error::Pem
impl From<pem::Error> for Error {
fn from(err: pem::Error) -> Error {
Error::Pem(err)
}
}

Expand Down
15 changes: 6 additions & 9 deletions pkcs8/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ pub(crate) mod encrypted_private_key_info;
pub use crate::{
error::{Error, Result},
private_key_info::PrivateKeyInfo,
traits::{FromPrivateKey, FromPublicKey},
traits::FromPrivateKey,
version::Version,
};
pub use der::{self, asn1::ObjectIdentifier};
pub use spki::{AlgorithmIdentifier, SubjectPublicKeyInfo};
pub use spki::{AlgorithmIdentifier, FromPublicKey, SubjectPublicKeyInfo};

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

#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
pub use pem_rfc7468::LineEnding;
pub use der::pem::{self, LineEnding};

#[cfg(feature = "pkcs5")]
pub use encrypted_private_key_info::EncryptedPrivateKeyInfo;
Expand All @@ -164,6 +164,3 @@ pub use pkcs5;

#[cfg(all(feature = "alloc", feature = "pkcs5"))]
pub use crate::document::encrypted_private_key::EncryptedPrivateKeyDocument;

#[cfg(feature = "pem")]
use pem_rfc7468 as pem;
2 changes: 1 addition & 1 deletion pkcs8/src/private_key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> PrivateKeyInfo<'a> {
pub fn to_pem(&self, line_ending: LineEnding) -> Result<Zeroizing<String>> {
pem::encode_string(PEM_TYPE_LABEL, line_ending, self.to_der()?.as_ref())
.map(Zeroizing::new)
.map_err(|_| Error::Pem)
.map_err(Error::Pem)
}
}

Expand Down
Loading