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