Repository: poem-web/poem (language: rust)

Issue:
build(deps): update rustls-pemfile requirement from 1.0.0 to 2.0.0
Updates the requirements on [rustls-pemfile](https://github.com/rustls/pemfile) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/rustls/pemfile/releases">rustls-pemfile's releases</a>.</em></p>
<blockquote>
<h2>2.0.0</h2>
<h2>Headlines</h2>
<ul>
<li><strong>Improving API stability.</strong> This crate now uses types from <a href="https://crates.io/crates/rustls-pki-types">rustls-pki-types</a>; we expect this to reduce the number of breaking changes in rustls ecosystem.</li>
<li><strong><code>no_std</code> support.</strong> This crate can now work optionally without <code>std</code>: use the new <code>read_one_from_slice</code> API.</li>
</ul>
<h2>What's Changed</h2>
<ul>
<li>Switch to using the pki-types crate by <a href="https://github.com/djc"><code>@​djc</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/24">rustls/pemfile#24</a></li>
<li>Bump version to 2.0.0-alpha.0 by <a href="https://github.com/djc"><code>@​djc</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/25">rustls/pemfile#25</a></li>
<li>2.0.0-alpha.1: take pki-types 0.2 by <a href="https://github.com/ctz"><code>@​ctz</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/26">rustls/pemfile#26</a></li>
<li>Add private_key() helper by <a href="https://github.com/djc"><code>@​djc</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/27">rustls/pemfile#27</a></li>
<li>Bump actions/checkout from 3 to 4 by <a href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/28">rustls/pemfile#28</a></li>
<li>Allow additionally parsing \r newlines in PEM files by <a href="https://github.com/complexspaces"><code>@​complexspaces</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/30">rustls/pemfile#30</a></li>
<li>add no-std support by <a href="https://github.com/japaric"><code>@​japaric</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/29">rustls/pemfile#29</a></li>
<li>Bump version to alpha.2 by <a href="https://github.com/djc"><code>@​djc</code></a> in <a href="https://redirect.github.com/rustls/pemfile/pull/33">rustls/pemfile#33</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/dependabot"><code>@​dependabot</code></a> made their first contribution in <a href="https://redirect.github.com/rustls/pemfile/pull/28">rustls/pemfile#28</a></li>
<li><a href="https://github.com/japaric"><code>@​japaric</code></a> made their first contribution in <a href="https://redirect.github.com/rustls/pemfile/pull/29">rustls/pemfile#29</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/rustls/pemfile/compare/v/1.0.4...v/2.0.0">https://github.com/rustls/pemfile/compare/v/1.0.4...v/2.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/rustls/pemfile/commit/e0da4cead2584281bf87a3fc047870abc691af40"><code>e0da4ce</code></a> Bump to v2.0.0</li>
<li><a href="https://github.com/rustls/pemfile/commit/12b9d7974b2d509c214caf7864bbafcc6f53a571"><code>12b9d79</code></a> Use pki-types v1</li>
<li><a href="https://github.com/rustls/pemfile/commit/48790bc268dc132ec8ea1550e668b74a7fb3f5a5"><code>48790bc</code></a> Bump version to alpha.2</li>
<li><a href="https://github.com/rustls/pemfile/commit/3aa829c7e8317fac1851357241455642502637d2"><code>3aa829c</code></a> add an opt-out std feature</li>
<li><a href="https://github.com/rustls/pemfile/commit/0227a3ab699b70dcef0ee0a7f0d341cf6e01e488"><code>0227a3a</code></a> add <code>read_one_from_slice</code></li>
<li><a href="https://github.com/rustls/pemfile/commit/6e367488e9f515b87aeecab4f7c179a448c1c89a"><code>6e36748</code></a> introduce an <code>Error</code> enum</li>
<li><a href="https://github.com/rustls/pemfile/commit/b3c85f121d65d23400d06d1db724730bbc480c59"><code>b3c85f1</code></a> refactor <code>read_one</code>'s loop body into a separate function</li>
<li><a href="https://github.com/rustls/pemfile/commit/2c2f1abb9a32738070309cd654afdf0622756032"><code>2c2f1ab</code></a> switch from std::prelude to core::prelude</li>
<li><a href="https://github.com/rustls/pemfile/commit/4cade3f5bea1a10ae19fb318229b903ba012fe49"><code>4cade3f</code></a> Allow additionally parsing \r newlines in PEM files</li>
<li><a href="https://github.com/rustls/pemfile/commit/c72614681cd0335463fb6c49ee10cd1c25912e5a"><code>c726146</code></a> Bump actions/checkout from 3 to 4</li>
<li>Additional commits viewable in <a href="https://github.com/rustls/pemfile/compare/v/1.0.0...v/2.0.0">compare view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Discussion / hints:

Fix patch:
diff --git a/poem/Cargo.toml b/poem/Cargo.toml
index 2a2aed1658..8f5997d5dc 100644
--- a/poem/Cargo.toml
+++ b/poem/Cargo.toml
@@ -99,7 +99,7 @@ sync_wrapper = { version = "0.1.2", features = ["futures"] }
 multer = { version = "3.0.0", features = ["tokio"], optional = true }
 tokio-tungstenite = { version = "0.21.0", optional = true }
 tokio-rustls = { workspace = true, optional = true }
-rustls-pemfile = { version = "1.0.0", optional = true }
+rustls-pemfile = { version = "2.0.0", optional = true }
 async-compression = { version = "0.4.0", optional = true, features = [
     "tokio",
     "gzip",
diff --git a/poem/src/listener/acme/listener.rs b/poem/src/listener/acme/listener.rs
index fea4810ef5..1f5c950d05 100644
--- a/poem/src/listener/acme/listener.rs
+++ b/poem/src/listener/acme/listener.rs
@@ -109,11 +109,14 @@ impl<T: Listener> Listener for AutoCertListener<T> {
         .await?;
 
         let (cache_certs, cert_key) = {
-            let mut certs = None;
+            let mut certs: Option<Vec<_>> = None;
             let mut key = None;
 
             if let Some(cache_cert) = &self.auto_cert.cache_cert {
-                match rustls_pemfile::certs(&mut cache_cert.as_slice()) {
+                match rustls_pemfile::certs(&mut cache_cert.as_slice())
+                    .collect::<Result<_, _>>()
+                    .map_err(|err| IoError::new(ErrorKind::Other, format!("invalid pem: {err}")))
+                {
                     Ok(c) => certs = Some(c),
                     Err(err) => {
                         tracing::warn!("failed to parse cached tls certificates: {}", err)
@@ -122,7 +125,9 @@ impl<T: Listener> Listener for AutoCertListener<T> {
             }
 
             if let Some(cache_key) = &self.auto_cert.cache_key {
-                match rustls_pemfile::pkcs8_private_keys(&mut cache_key.as_slice()) {
+                match rustls_pemfile::pkcs8_private_keys(&mut cache_key.as_slice())
+                    .collect::<Result<Vec<_>, _>>()
+                {
                     Ok(k) => key = k.into_iter().next(),
                     Err(err) => {
                         tracing::warn!("failed to parse cached private key: {}", err)
@@ -157,7 +162,7 @@ impl<T: Listener> Listener for AutoCertListener<T> {
             );
             *cert_resolver.cert.write() = Some(Arc::new(CertifiedKey::new(
                 certs,
-                any_ecdsa_type(&PrivateKeyDer::Pkcs8(key.into())).unwrap(),
+                any_ecdsa_type(&PrivateKeyDer::Pkcs8(key)).unwrap(),
             )));
         }
 
@@ -403,10 +408,8 @@ pub async fn issue_cert<T: AsRef<str>>(
         .await?;
     let pkey_pem = cert.serialize_private_key_pem();
     let cert_chain = rustls_pemfile::certs(&mut acme_cert_pem.as_slice())
-        .map_err(|err| IoError::new(ErrorKind::Other, format!("invalid pem: {err}")))?
-        .into_iter()
-        .map(CertificateDer::from)
-        .collect();
+        .collect::<Result<_, _>>()
+        .map_err(|err| IoError::new(ErrorKind::Other, format!("invalid pem: {err}")))?;
     let cert_key = CertifiedKey::new(cert_chain, pk);
 
     tracing::debug!("certificate obtained");
diff --git a/poem/src/listener/rustls.rs b/poem/src/listener/rustls.rs
index 445123dc3c..b03471e7e2 100644
--- a/poem/src/listener/rustls.rs
+++ b/poem/src/listener/rustls.rs
@@ -10,7 +10,6 @@ use tokio::io::{Error as IoError, ErrorKind, Result as IoResult};
 use tokio_rustls::{
     rustls::{
         crypto::ring::sign::any_supported_type,
-        pki_types::{CertificateDer, PrivateKeyDer},
         server::{ClientHello, ResolvesServerCert, WebPkiClientVerifier},
         sign::CertifiedKey,
         RootCertStore, ServerConfig,
@@ -71,26 +70,21 @@ impl RustlsCertificate {
 impl RustlsCertificate {
     fn create_certificate_key(&self) -> IoResult<CertifiedKey> {
         let cert = rustls_pemfile::certs(&mut self.cert.as_slice())
-            .map(|mut certs| certs.drain(..).map(CertificateDer::from).collect())
+            .collect::<Result<_, _>>()
             .map_err(|_| IoError::new(ErrorKind::Other, "failed to parse tls certificates"))?;
 
-        let priv_key = {
-            loop {
-                let key = match rustls_pemfile::read_one(&mut self.key.as_slice())? {
-                    Some(Item::RSAKey(key)) => key,
-                    Some(Item::PKCS8Key(key)) => key,
-                    Some(Item::ECKey(key)) => key,
-                    None => {
-                        return Err(IoError::new(
-                            ErrorKind::Other,
-                            "failed to parse tls private keys",
-                        ))
-                    }
-                    _ => continue,
-                };
-                if !key.is_empty() {
-                    break PrivateKeyDer::Pkcs8(key.into());
+        let priv_key = loop {
+            match rustls_pemfile::read_one(&mut self.key.as_slice())? {
+                Some(Item::Pkcs1Key(key)) => break key.into(),
+                Some(Item::Pkcs8Key(key)) => break key.into(),
+                Some(Item::Sec1Key(key)) => break key.into(),
+                None => {
+                    return Err(IoError::new(
+                        ErrorKind::Other,
+                        "failed to parse tls private keys",
+                    ))
                 }
+                _ => continue,
             }
         };
 
@@ -269,10 +263,11 @@ impl RustlsConfig {
 
 fn read_trust_anchor(mut trust_anchor: &[u8]) -> IoResult<RootCertStore> {
     let mut store = RootCertStore::empty();
-    let ders = rustls_pemfile::certs(&mut trust_anchor)?;
+    let ders = rustls_pemfile::certs(&mut trust_anchor);
     for der in ders {
+        let der = der.map_err(|err| IoError::new(ErrorKind::Other, err.to_string()))?;
         store
-            .add(CertificateDer::from(der))
+            .add(der)
             .map_err(|err| IoError::new(ErrorKind::Other, err.to_string()))?;
     }
     Ok(store)
diff --git a/poem/src/listener/unix.rs b/poem/src/listener/unix.rs
index 8e678f088e..5072e6cc22 100644
--- a/poem/src/listener/unix.rs
+++ b/poem/src/listener/unix.rs
@@ -46,7 +46,7 @@ impl<T> UnixListener<T> {
     /// Provides owner to be set on actual bind
     pub fn with_owner(self, uid: Option<u32>, gid: Option<u32>) -> Self {
         Self {
-            owner: Some((uid.map(|v| Uid::from_raw(v)), gid.map(|v| Gid::from_raw(v)))),
+            owner: Some((uid.map(Uid::from_raw), gid.map(Gid::from_raw))),
             ..self
         }
     }
@@ -61,7 +61,7 @@ impl<T: AsRef<Path> + Send + Clone> Listener for UnixListener<T> {
             (Some(permissions), Some((uid, gid))) => {
                 let listener = TokioUnixListener::bind(self.path.clone())?;
                 set_permissions(self.path.clone(), permissions)?;
-                chown(self.path.as_ref().as_os_str().into(), uid, gid)?;
+                chown(self.path.as_ref().as_os_str(), uid, gid)?;
                 listener
             }
             (Some(permissions), None) => {
@@ -71,7 +71,7 @@ impl<T: AsRef<Path> + Send + Clone> Listener for UnixListener<T> {
             }
             (None, Some((uid, gid))) => {
                 let listener = TokioUnixListener::bind(self.path.clone())?;
-                chown(self.path.as_ref().as_os_str().into(), uid, gid)?;
+                chown(self.path.as_ref().as_os_str(), uid, gid)?;
                 listener
             }
             (None, None) => TokioUnixListener::bind(self.path)?,


Test patch: