Updated rustls_pemfile
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9e396262ff
commit
5609708848
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -1444,7 +1444,7 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls 0.21.10",
|
||||
"rustls-pemfile",
|
||||
"rustls-pemfile 1.0.4",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
@ -1557,7 +1557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00"
|
||||
dependencies = [
|
||||
"openssl-probe",
|
||||
"rustls-pemfile",
|
||||
"rustls-pemfile 1.0.4",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
]
|
||||
@ -1571,6 +1571,22 @@ dependencies = [
|
||||
"base64 0.21.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pemfile"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35e4980fa29e4c4b212ffb3db068a564cbf560e51d3944b7c88bd8bf5bec64f4"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e9d979b3ce68192e42760c7810125eb6cf2ea10efae545a156063e61f314e2a"
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.101.7"
|
||||
@ -1821,7 +1837,7 @@ dependencies = [
|
||||
"rand",
|
||||
"reqwest",
|
||||
"rustls 0.20.9",
|
||||
"rustls-pemfile",
|
||||
"rustls-pemfile 2.0.0",
|
||||
"serde",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
|
@ -23,7 +23,7 @@ tokio-tungstenite = { version = "0.18.0", features = ["__rustls-tls", "rustls-tl
|
||||
urlencoding = "2.1.3"
|
||||
hyper-rustls = { version = "0.23.2", features = ["rustls-native-certs"] }
|
||||
bytes = "1.5.0"
|
||||
rustls-pemfile = "1.0.4"
|
||||
rustls-pemfile = "2.0.0"
|
||||
rustls = { version = "0.20.7", features = ["dangerous_configuration"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -2,16 +2,15 @@ use std::error::Error;
|
||||
use std::io::{Cursor, ErrorKind};
|
||||
|
||||
use rustls::{Certificate, PrivateKey};
|
||||
use rustls_pemfile::{read_one, Item};
|
||||
use rustls_pemfile::Item;
|
||||
|
||||
/// Parse PEM certificates bytes into a [`rustls::Certificate`] structure
|
||||
///
|
||||
/// An error is returned if not any certificate could be found
|
||||
pub fn parse_pem_certificates(certs: &[u8]) -> Result<Vec<Certificate>, Box<dyn Error>> {
|
||||
let certs = rustls_pemfile::certs(&mut Cursor::new(certs))?
|
||||
.into_iter()
|
||||
.map(Certificate)
|
||||
.collect::<Vec<_>>();
|
||||
let certs = rustls_pemfile::certs(&mut Cursor::new(certs))
|
||||
.map(|c| c.map(|c| Certificate(c.to_vec())))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
if certs.is_empty() {
|
||||
Err(std::io::Error::new(
|
||||
@ -26,7 +25,7 @@ pub fn parse_pem_certificates(certs: &[u8]) -> Result<Vec<Certificate>, Box<dyn
|
||||
|
||||
/// Parse PEM private key bytes into a [`rustls::PrivateKey`] structure
|
||||
pub fn parse_pem_private_key(privkey: &[u8]) -> Result<PrivateKey, Box<dyn Error>> {
|
||||
let key = match read_one(&mut Cursor::new(privkey))? {
|
||||
let key = match rustls_pemfile::read_one(&mut Cursor::new(privkey))? {
|
||||
None => {
|
||||
Err(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
@ -34,8 +33,8 @@ pub fn parse_pem_private_key(privkey: &[u8]) -> Result<PrivateKey, Box<dyn Error
|
||||
))?;
|
||||
unreachable!()
|
||||
}
|
||||
Some(Item::PKCS8Key(key)) => key,
|
||||
Some(Item::RSAKey(key)) => key,
|
||||
Some(Item::Pkcs8Key(key)) => key.secret_pkcs8_der().to_vec(),
|
||||
Some(Item::Pkcs1Key(key)) => key.secret_pkcs1_der().to_vec(),
|
||||
_ => {
|
||||
Err(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
|
Loading…
Reference in New Issue
Block a user