From 57cab3b7ce19454912b5c50f7710b39873cd2c8f Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Fri, 14 Feb 2020 14:46:13 +0100 Subject: [PATCH] secio: Use `UnexpectedEof` instead of `BrokenPipe`. (#1456) Secio's handshake reports unexpected EOF errors in two places. Presumably because `std::io::ErrorKind::UnexpectedEof` did not exist when secio was first implemented, `ErrorKind::BrokenPipe` is used for this error. Since we nowadays have `UnexpectedEof` at our disposal, secio should use this more appropriate error kind. --- protocols/secio/src/handshake.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/protocols/secio/src/handshake.rs b/protocols/secio/src/handshake.rs index 34c7ffcc..faffccc9 100644 --- a/protocols/secio/src/handshake.rs +++ b/protocols/secio/src/handshake.rs @@ -31,8 +31,7 @@ use log::{debug, trace}; use prost::Message; use rand::{self, RngCore}; use sha2::{Digest as ShaDigestTrait, Sha256}; -use std::cmp::{self, Ordering}; -use std::io::{Error as IoError, ErrorKind as IoErrorKind}; +use std::{cmp::{self, Ordering}, io}; /// Performs a handshake on the given socket. @@ -101,9 +100,8 @@ where let remote_proposition_bytes = match socket.next().await { Some(b) => b?, None => { - let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof"); debug!("unexpected eof while waiting for remote's proposition"); - return Err(err.into()) + return Err(SecioError::IoError(io::ErrorKind::UnexpectedEof.into())) }, }; @@ -229,9 +227,8 @@ where let raw = match socket.next().await { Some(r) => r?, None => { - let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof"); debug!("unexpected eof while waiting for remote's exchange"); - return Err(err.into()) + return Err(SecioError::IoError(io::ErrorKind::UnexpectedEof.into())) }, };