Return error from parsing the encrypted ReqData
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
4df73b658a
commit
e2874451d1
|
@ -212,8 +212,10 @@ impl ReqInner {
|
|||
}
|
||||
}
|
||||
/// parse the cleartext
|
||||
// FIXME: return Result<>
|
||||
pub fn deserialize_as_cleartext(&mut self, raw: &[u8]) {
|
||||
pub fn deserialize_as_cleartext(
|
||||
&mut self,
|
||||
raw: &[u8],
|
||||
) -> Result<(), Error> {
|
||||
let clear = match self {
|
||||
ReqInner::CipherText(len) => {
|
||||
assert!(
|
||||
|
@ -222,12 +224,13 @@ impl ReqInner {
|
|||
);
|
||||
match ReqData::deserialize(raw) {
|
||||
Ok(clear) => clear,
|
||||
Err(_e) => return,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
_ => return,
|
||||
_ => return Err(Error::Parsing),
|
||||
};
|
||||
*self = ReqInner::ClearText(clear);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,9 +67,11 @@ fn test_handshake_dirsync_req() {
|
|||
{
|
||||
let enc_start =
|
||||
r_a.encrypted_offset() + cipher_send.kind().nonce_len().0;
|
||||
r_a.data.deserialize_as_cleartext(
|
||||
if let Err(e) = r_a.data.deserialize_as_cleartext(
|
||||
&bytes[enc_start..(bytes.len() - cipher_send.kind().tag_len().0)],
|
||||
);
|
||||
) {
|
||||
assert!(false, "DirSync Req Inner serialize: {}", e.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
assert!(
|
||||
|
|
|
@ -184,7 +184,11 @@ impl HandshakeTracker {
|
|||
&mut handshake_raw[req.encrypted_offset()..],
|
||||
) {
|
||||
Ok(cleartext) => {
|
||||
req.data.deserialize_as_cleartext(cleartext)
|
||||
if let Err(e) =
|
||||
req.data.deserialize_as_cleartext(cleartext)
|
||||
{
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(handshake::Error::Key(e).into());
|
||||
|
|
Loading…
Reference in New Issue