Skip to content

Commit 06bdd35

Browse files
committed
Migrate from rustls-pemfile to rustls-pki-types
1 parent f5052d9 commit 06bdd35

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ hyper = { version = "1", default-features = false, features = ["client", "http1"
2626
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2"] }
2727
hyper-util = { version = "0.1.4", features = ["client-legacy"] }
2828
ring = "0.17"
29-
rustls-pemfile = "2"
29+
rustls-pki-types = "1"
3030
serde = { version = "1.0", features = ["derive", "rc"] }
3131
serde_json = "1.0"
3232
thiserror = "2.0"

src/types.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use hyper_util::client::legacy::Client;
1515
use hyper_util::rt::TokioExecutor;
1616
use ring::rand::SystemRandom;
1717
use ring::signature::{RsaKeyPair, RSA_PKCS1_SHA256};
18+
use rustls_pki_types::pem::PemObject;
19+
use rustls_pki_types::PrivatePkcs8KeyDer;
1820
use serde::{Deserialize, Deserializer};
1921
use tokio::time::sleep;
2022
use tracing::{debug, warn};
@@ -185,23 +187,18 @@ pub struct Signer {
185187

186188
impl Signer {
187189
pub(crate) fn new(pem_pkcs8: &str) -> Result<Self, Error> {
188-
let key = match rustls_pemfile::private_key(&mut pem_pkcs8.as_bytes()) {
189-
Ok(Some(key)) => key,
190-
Ok(None) => {
191-
return Err(Error::Str(
192-
"no private key found in credentials private key data",
193-
))
194-
}
190+
let key = match PrivatePkcs8KeyDer::from_pem_slice(&mut pem_pkcs8.as_bytes()) {
191+
Ok(key) => key,
195192
Err(err) => {
196-
return Err(Error::Io(
197-
"failed to read credentials private key data",
198-
err,
193+
return Err(Error::Other(
194+
"failed to parse PKCS#8 RSA key pair",
195+
err.into(),
199196
))
200197
}
201198
};
202199

203200
Ok(Signer {
204-
key: RsaKeyPair::from_pkcs8(key.secret_der())
201+
key: RsaKeyPair::from_pkcs8(key.secret_pkcs8_der())
205202
.map_err(|_| Error::Str("invalid private key in credentials"))?,
206203
rng: SystemRandom::new(),
207204
})

0 commit comments

Comments
 (0)