Skip to content

Commit 3b2df50

Browse files
committed
examples: don't force io::Error from errors
1 parent 20c2bb0 commit 3b2df50

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

examples/client.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::error::Error as StdError;
12
use std::fs::File;
23
use std::io;
34
use std::io::BufReader;
@@ -32,7 +33,7 @@ struct Options {
3233
}
3334

3435
#[tokio::main]
35-
async fn main() -> io::Result<()> {
36+
async fn main() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
3637
let options: Options = argh::from_env();
3738

3839
let addr = (options.host.as_str(), options.port)
@@ -46,7 +47,7 @@ async fn main() -> io::Result<()> {
4647
if let Some(cafile) = &options.cafile {
4748
let mut pem = BufReader::new(File::open(cafile)?);
4849
for cert in rustls_pemfile::certs(&mut pem) {
49-
root_cert_store.add(cert?).unwrap();
50+
root_cert_store.add(cert?)?;
5051
}
5152
} else {
5253
root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
@@ -61,10 +62,7 @@ async fn main() -> io::Result<()> {
6162

6263
let (mut stdin, mut stdout) = (tokio_stdin(), tokio_stdout());
6364

64-
let domain = ServerName::try_from(domain.as_str())
65-
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid dnsname"))?
66-
.to_owned();
67-
65+
let domain = ServerName::try_from(domain.as_str())?.to_owned();
6866
let mut stream = connector.connect(domain, stream).await?;
6967
stream.write_all(content.as_bytes()).await?;
7068

examples/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io::{self, BufReader, ErrorKind};
33
use std::net::ToSocketAddrs;
44
use std::path::{Path, PathBuf};
55
use std::sync::Arc;
6+
use std::error::Error as StdError;
67

78
use argh::FromArgs;
89
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
@@ -45,7 +46,7 @@ fn load_key(path: &Path) -> io::Result<PrivateKeyDer<'static>> {
4546
}
4647

4748
#[tokio::main]
48-
async fn main() -> io::Result<()> {
49+
async fn main() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
4950
let options: Options = argh::from_env();
5051

5152
let addr = options
@@ -59,8 +60,7 @@ async fn main() -> io::Result<()> {
5960

6061
let config = rustls::ServerConfig::builder()
6162
.with_no_client_auth()
62-
.with_single_cert(certs, key)
63-
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
63+
.with_single_cert(certs, key)?;
6464
let acceptor = TlsAcceptor::from(Arc::new(config));
6565

6666
let listener = TcpListener::bind(&addr).await?;

0 commit comments

Comments
 (0)