Skip to content

Commit

Permalink
0.15: Update rustls deps
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Dec 26, 2023
1 parent 5c5458f commit ed9341d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vndb"
version = "0.14.0"
version = "0.15.0"
authors = ["Douman <douman@gmx.se>"]
description = "Kawaii VNDB API"
license = "MIT"
Expand All @@ -22,12 +22,12 @@ version = "1"
features = ["derive"]

[dependencies.rustls]
version = "0.21"
version = "0.22"
default-features = false
optional = true

[dependencies.webpki-roots]
version = "0.23"
version = "0.26"
optional = true

[dependencies.tokio]
Expand All @@ -36,7 +36,7 @@ optional = true
features = ["net", "io-util"]

[dependencies.tokio-rustls]
version = "0.24"
version = "0.25"
optional = true

[dependencies]
Expand Down
16 changes: 4 additions & 12 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,19 @@ fn parse_response(buf: &[u8]) -> io::Result<Option<crate::protocol::Response>> {
}

#[cfg(feature = "rustls-on")]
fn get_rustls_config() -> (rustls::ServerName, std::sync::Arc<rustls::ClientConfig>) {
fn get_rustls_config() -> (rustls::pki_types::ServerName<'static>, std::sync::Arc<rustls::ClientConfig>) {
use core::mem::MaybeUninit;
use core::convert::TryInto;
use std::sync::Arc;

static mut SERVER_NAME: MaybeUninit<rustls::ServerName> = MaybeUninit::uninit();
static mut SERVER_NAME: MaybeUninit<rustls::pki_types::ServerName<'static>> = MaybeUninit::uninit();
static mut CFG: MaybeUninit<Arc<rustls::ClientConfig>> = MaybeUninit::uninit();
static CFG_ONCE: std::sync::Once = std::sync::Once::new();

CFG_ONCE.call_once(|| {
let mut certs = rustls::RootCertStore::empty();
let webpki_roots = webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
});
certs.add_server_trust_anchors(webpki_roots);
let config = rustls::ClientConfig::builder().with_safe_defaults()
.with_root_certificates(certs)
certs.extend(webpki_roots::TLS_SERVER_ROOTS.into_iter().cloned());
let config = rustls::ClientConfig::builder().with_root_certificates(certs)
.with_no_client_auth();
unsafe {
CFG.as_mut_ptr().write(Arc::new(config));
Expand Down
6 changes: 3 additions & 3 deletions src/client/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Client<net::TcpStream> {

///Re-connects over plain TCP, aborting previous connection if any
pub async fn reconnect(&mut self) -> io::Result<()> {
let _ = self.io.get_mut().shutdown();
let _ = self.io.get_mut().shutdown().await;

self.io = BufReader::new(Self::socket_connect().await?);
self.read_buf.clear();
Expand All @@ -44,7 +44,7 @@ impl Client<tokio_rustls::client::TlsStream<net::TcpStream>> {
let (dns_name, config) = super::get_rustls_config();
let config = tokio_rustls::TlsConnector::from(config);

Ok(config.connect(dns_name, socket).await?)
config.connect(dns_name, socket).await
}

#[inline(always)]
Expand All @@ -55,7 +55,7 @@ impl Client<tokio_rustls::client::TlsStream<net::TcpStream>> {

///Re-connects over TLS, aborting previous connection if any
pub async fn reconnect_tls(&mut self) -> io::Result<()> {
let _ = self.io.get_mut().get_mut().0.shutdown();
let _ = self.io.get_mut().get_mut().0.shutdown().await;

self.io = BufReader::new(Self::socket_connect_tls().await?);
self.read_buf.clear();
Expand Down
25 changes: 13 additions & 12 deletions src/protocol/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ impl<'a> convert::From<request::Get<'a>> for Request<'a> {
impl<'a> fmt::Display for Request<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&Request::Login(ref login) => write!(f, "{}\x04", login),
&Request::Get(ref get) => write!(f, "{}\x04", get),
&Request::DBstats => write!(f, "dbstats\x04")
Request::Login(ref login) => write!(f, "{}\x04", login),
Request::Get(ref get) => write!(f, "{}\x04", get),
Request::DBstats => write!(f, "dbstats\x04")
}
}
}
Expand Down Expand Up @@ -137,16 +137,17 @@ pub enum ResponseParseError {
}

impl fmt::Display for ResponseParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
&ResponseParseError::EmptyResponse => write!(f, "VNDB sent empty response."),
&ResponseParseError::EmptyResults => write!(f, "VNDB sent Results with no payload."),
&ResponseParseError::EmptyDbStats => write!(f, "VNDB sent DBstats with no payload."),
&ResponseParseError::EmptyError => write!(f, "VNDB sent Error with no payload."),
&ResponseParseError::InvalidResults(ref error) => write!(f, "VNDB sent invalid JSON in Results: {}", error),
&ResponseParseError::InvalidDbStats(ref error) => write!(f, "VNDB sent invalid JSON in DBstats: {}", error),
&ResponseParseError::InvalidError(ref error) => write!(f, "VNDB sent invalid JSON in Error: {}", error),
&ResponseParseError::UnknownComamnd => write!(f, "VNDB sent unknown command"),
ResponseParseError::EmptyResponse => fmt.write_str("VNDB sent empty response."),
ResponseParseError::EmptyResults => fmt.write_str("VNDB sent Results with no payload."),
ResponseParseError::EmptyDbStats => fmt.write_str("VNDB sent DBstats with no payload."),
ResponseParseError::EmptyError => fmt.write_str("VNDB sent Error with no payload."),
ResponseParseError::InvalidResults(ref error) => write!(fmt, "VNDB sent invalid JSON in Results: {}", error),
ResponseParseError::InvalidDbStats(ref error) => write!(fmt, "VNDB sent invalid JSON in DBstats: {}", error),
ResponseParseError::InvalidError(ref error) => write!(fmt, "VNDB sent invalid JSON in Error: {}", error),
ResponseParseError::UnknownComamnd => fmt.write_str("VNDB sent unknown command"),
}
}
}
Expand Down

0 comments on commit ed9341d

Please sign in to comment.