Return error from parsing the encrypted ReqData

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2023-06-09 20:05:59 +02:00
parent 4df73b658a
commit e2874451d1
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
3 changed files with 16 additions and 7 deletions

View File

@ -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(())
}
}

View File

@ -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!(

View File

@ -184,7 +184,11 @@ impl HandshakeTracker {
&mut handshake_raw[req.encrypted_offset()..],
) {
Ok(cleartext) => {
if let Err(e) =
req.data.deserialize_as_cleartext(cleartext)
{
return Err(e.into());
}
}
Err(e) => {
return Err(handshake::Error::Key(e).into());