Skip to content

Commit

Permalink
WIP: move over to pki-types API
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Sep 18, 2024
1 parent 7b5bdfb commit f44babd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 310 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ repository = "https://github.com/rustls/pemfile"
categories = ["network-programming", "cryptography"]

[dependencies]
base64 = { version = "0.22", default-features = false, features = ["alloc"] }
pki-types = { package = "rustls-pki-types", version = "1.7", git = "https://github.com/rustls/pki-types.git", branch = "jbp-pem" }

[dev-dependencies]
bencher = "0.1.5"

[features]
default = ["std"]
std = ["base64/std", "pki-types/std"]
std = ["pki-types/std"]

[[bench]]
name = "benchmark"
Expand Down
22 changes: 7 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ extern crate std;
#[cfg(feature = "std")]
mod tests;

/// --- Main crate APIs:
mod pemfile;
#[cfg(feature = "std")]
pub use pemfile::{read_all, read_one};
pub use pemfile::{read_one_from_slice, Error, Item};
#[cfg(feature = "std")]
use pki_types::PrivateKeyDer;
#[cfg(feature = "std")]
Expand All @@ -72,6 +67,11 @@ use pki_types::{
PrivatePkcs8KeyDer, PrivateSec1KeyDer, SubjectPublicKeyInfoDer,
};

mod pemfile;
#[cfg(feature = "std")]
pub use pemfile::{read_all, read_one};
pub use pemfile::{read_one_from_slice, Error, Item};

#[cfg(feature = "std")]
use core::iter;
/// --- Legacy APIs:
Expand Down Expand Up @@ -104,10 +104,7 @@ pub fn private_key(rd: &mut dyn io::BufRead) -> Result<Option<PrivateKeyDer<'sta
Item::Pkcs1Key(key) => return Ok(Some(key.into())),
Item::Pkcs8Key(key) => return Ok(Some(key.into())),
Item::Sec1Key(key) => return Ok(Some(key.into())),
Item::X509Certificate(_)
| Item::SubjectPublicKeyInfo(_)
| Item::Crl(_)
| Item::Csr(_) => continue,
_ => continue,
}
}

Expand All @@ -125,12 +122,7 @@ pub fn csr(
for result in iter::from_fn(move || read_one(rd).transpose()) {
match result? {
Item::Csr(csr) => return Ok(Some(csr)),
Item::Pkcs1Key(_)
| Item::Pkcs8Key(_)
| Item::Sec1Key(_)
| Item::X509Certificate(_)
| Item::SubjectPublicKeyInfo(_)
| Item::Crl(_) => continue,
_ => continue,
}
}

Expand Down
Loading

0 comments on commit f44babd

Please sign in to comment.