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.
This commit is contained in:
Toralf Wittner
2020-02-14 14:46:13 +01:00
committed by GitHub
parent be31f66031
commit 57cab3b7ce

View File

@ -31,8 +31,7 @@ use log::{debug, trace};
use prost::Message; use prost::Message;
use rand::{self, RngCore}; use rand::{self, RngCore};
use sha2::{Digest as ShaDigestTrait, Sha256}; use sha2::{Digest as ShaDigestTrait, Sha256};
use std::cmp::{self, Ordering}; use std::{cmp::{self, Ordering}, io};
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
/// Performs a handshake on the given socket. /// Performs a handshake on the given socket.
@ -101,9 +100,8 @@ where
let remote_proposition_bytes = match socket.next().await { let remote_proposition_bytes = match socket.next().await {
Some(b) => b?, Some(b) => b?,
None => { None => {
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
debug!("unexpected eof while waiting for remote's proposition"); 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 { let raw = match socket.next().await {
Some(r) => r?, Some(r) => r?,
None => { None => {
let err = IoError::new(IoErrorKind::BrokenPipe, "unexpected eof");
debug!("unexpected eof while waiting for remote's exchange"); debug!("unexpected eof while waiting for remote's exchange");
return Err(err.into()) return Err(SecioError::IoError(io::ErrorKind::UnexpectedEof.into()))
}, },
}; };