Skip to content

Commit ebd4920

Browse files
committed
remove deprecated rustls-pemfile
1 parent a19aa13 commit ebd4920

3 files changed

Lines changed: 26 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 13 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ derive_more = { version = "2.1.1", default-features = false, features = ["from",
7878
rand = "0.9.2"
7979
hickory-resolver = { version = "0.25.2", features = ["tls-aws-lc-rs", "webpki-roots"] }
8080
aws-lc-rs = "1.15.2"
81-
rustls-pemfile = "2.2.0"
8281
humansize = "2.1.3"
8382
ppp = "2.3.0"
8483
url = "2.5.4"

src/smtp/server.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tokio_rustls::{
1818
rustls::{
1919
self, crypto,
2020
crypto::CryptoProvider,
21-
pki_types::{CertificateDer, PrivateKeyDer},
21+
pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
2222
},
2323
};
2424
use tokio_util::sync::CancellationToken;
@@ -27,11 +27,13 @@ use tracing::{debug, error, info, trace};
2727
#[derive(Debug, Error)]
2828
pub enum SmtpServerError {
2929
#[error("failed to load private key: {0}")]
30-
PrivateKey(io::Error),
30+
PrivateKey(rustls::pki_types::pem::Error),
3131
#[error("no private key found in the key file")]
3232
PrivateKeyNotFound,
3333
#[error("failed to load certificate: {0}")]
34-
Certificate(io::Error),
34+
Certificate(rustls::pki_types::pem::Error),
35+
#[error("failed perform IO operation: {0}")]
36+
Io(io::Error),
3537
#[error("failed to listen on address: {0}")]
3638
Listen(io::Error),
3739
#[error("failed to configure TLS: {0}")]
@@ -71,19 +73,16 @@ impl SmtpServer {
7173
async fn load_tls_config(
7274
&self,
7375
) -> Result<(Vec<CertificateDer<'static>>, PrivateKeyDer<'static>), SmtpServerError> {
74-
let mut cert_reader = io::BufReader::new(
75-
File::open(&self.config.cert_file).map_err(SmtpServerError::Certificate)?,
76-
);
77-
let mut key_reader = io::BufReader::new(
78-
File::open(&self.config.key_file).map_err(SmtpServerError::PrivateKey)?,
79-
);
76+
let mut cert_reader =
77+
io::BufReader::new(File::open(&self.config.cert_file).map_err(SmtpServerError::Io)?);
78+
let mut key_reader =
79+
io::BufReader::new(File::open(&self.config.key_file).map_err(SmtpServerError::Io)?);
8080

81-
let certs = rustls_pemfile::certs(&mut cert_reader)
82-
.collect::<Result<Vec<_>, io::Error>>()
81+
let certs = CertificateDer::pem_reader_iter(&mut cert_reader)
82+
.collect::<Result<Vec<_>, tokio_rustls::rustls::pki_types::pem::Error>>()
8383
.map_err(SmtpServerError::Certificate)?;
84-
let key = rustls_pemfile::private_key(&mut key_reader)
85-
.map_err(SmtpServerError::PrivateKey)?
86-
.ok_or(SmtpServerError::PrivateKeyNotFound)?;
84+
let key =
85+
PrivateKeyDer::from_pem_reader(&mut key_reader).map_err(SmtpServerError::PrivateKey)?;
8786

8887
Ok((certs, key))
8988
}

0 commit comments

Comments
 (0)