+
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
10 changes: 0 additions & 10 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 @@ -49,7 +49,7 @@ vendored = ["native-tls?/vendored"]
# Supported as long as rustls supports this.
_ring = ["rustls?/ring"]
_url = ["dep:url"]
_tls = ["dep:rustls-pemfile", "dep:rustls-pki-types"]
_tls = ["dep:rustls-pki-types"]
_test = []
_rustls = []
_doc = ["rustls?/aws-lc-rs"]
Expand All @@ -63,7 +63,6 @@ utf-8 = "0.7.6"
percent-encoding = "2.3.1"

# These are used regardless of TLS implementation.
rustls-pemfile = { version = "2.1.2", optional = true, default-features = false, features = ["std"] }
rustls-pki-types = { version = "1.11.0", optional = true, default-features = false, features = ["std"] }
rustls-platform-verifier = { version = "0.6.0", optional = true, default-features = false }
webpki-roots = { version = "1.0.0", optional = true, default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub enum Error {
/// Breaking changes in that struct will not be reflected in ureq
/// major versions.
#[cfg(feature = "_tls")]
Pem(rustls_pemfile::Error),
Pem(rustls_pki_types::pem::Error),

/// An error originating in Rustls.
///
Expand Down
55 changes: 35 additions & 20 deletions src/tls/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ impl<'a> PrivateKey<'a> {
/// The data may contain one or many PEM items. The iterator produces the recognized PEM
/// items and skip others.
pub fn parse_pem(pem: &[u8]) -> impl Iterator<Item = Result<PemItem<'static>, Error>> + '_ {
PemIter(pem)
use rustls_pki_types::pem::PemObject;
PemIter(<(rustls_pki_types::pem::SectionKind, Vec<u8>)>::pem_slice_iter(pem))
}

/// Kinds of PEM data found by [`parse_pem`]
Expand All @@ -206,43 +207,57 @@ pub enum PemItem<'a> {
PrivateKey(PrivateKey<'a>),
}

struct PemIter<'a>(&'a [u8]);

impl<'a> Iterator for PemIter<'a> {
struct PemIter<I>(I)
where
I: Iterator<
Item = Result<(rustls_pki_types::pem::SectionKind, Vec<u8>), rustls_pki_types::pem::Error>,
>;

impl<I> Iterator for PemIter<I>
where
I: Iterator<
Item = Result<(rustls_pki_types::pem::SectionKind, Vec<u8>), rustls_pki_types::pem::Error>,
>,
{
type Item = Result<PemItem<'static>, Error>;

fn next(&mut self) -> Option<Self::Item> {
loop {
match rustls_pemfile::read_one_from_slice(self.0) {
Ok(Some((cert, rest))) => {
// Move slice along for next iterator next()
self.0 = rest;

match cert {
rustls_pemfile::Item::X509Certificate(der) => {
match self.0.next() {
Some(Ok((section_kind, der_data))) => {
match section_kind {
rustls_pki_types::pem::SectionKind::Certificate => {
return Some(Ok(Certificate {
der: CertDer::Rustls(der),
der: CertDer::Rustls(rustls_pki_types::CertificateDer::from(
der_data,
)),
}
.into()));
}
rustls_pemfile::Item::Pkcs1Key(der) => {
rustls_pki_types::pem::SectionKind::RsaPrivateKey => {
return Some(Ok(PrivateKey {
kind: KeyKind::Pkcs1,
der: PrivateKeyDer::Rustls(der.into()),
der: PrivateKeyDer::Rustls(rustls_pki_types::PrivateKeyDer::from(
rustls_pki_types::PrivatePkcs1KeyDer::from(der_data),
)),
}
.into()));
}
rustls_pemfile::Item::Pkcs8Key(der) => {
rustls_pki_types::pem::SectionKind::PrivateKey => {
return Some(Ok(PrivateKey {
kind: KeyKind::Pkcs8,
der: PrivateKeyDer::Rustls(der.into()),
der: PrivateKeyDer::Rustls(rustls_pki_types::PrivateKeyDer::from(
rustls_pki_types::PrivatePkcs8KeyDer::from(der_data),
)),
}
.into()));
}
rustls_pemfile::Item::Sec1Key(der) => {
rustls_pki_types::pem::SectionKind::EcPrivateKey => {
return Some(Ok(PrivateKey {
kind: KeyKind::Sec1,
der: PrivateKeyDer::Rustls(der.into()),
der: PrivateKeyDer::Rustls(rustls_pki_types::PrivateKeyDer::from(
rustls_pki_types::PrivateSec1KeyDer::from(der_data),
)),
}
.into()));
}
Expand All @@ -253,9 +268,9 @@ impl<'a> Iterator for PemIter<'a> {
}

// It's over
Ok(None) => return None,
None => return None,

Err(e) => {
Some(Err(e)) => {
return Some(Err(Error::Pem(e)));
}
}
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载