Skip to content

Commit

Permalink
Remove extraneous bytes check on input buffer (#68)
Browse files Browse the repository at this point in the history
* Remove extraneous bytes check on input buffer

* Keep test, add note
  • Loading branch information
jordy25519 authored Jul 21, 2020
1 parent 355661a commit b6d227d
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,16 @@ impl Decode for DoughnutV0 {
let mut signature = [0_u8; 64];
input.read(&mut signature)?;

if input.read_byte().is_ok() {
Err(codec::Error::from("Doughnut contains unexpected bytes"))
} else {
Ok(Self {
holder,
issuer,
expiry,
not_before,
signature_version,
payload_version,
domains,
signature: H512::from(signature),
})
}
Ok(Self {
holder,
issuer,
expiry,
not_before,
signature_version,
payload_version,
domains,
signature: H512::from(signature),
})
}
}

Expand Down Expand Up @@ -587,10 +583,11 @@ mod test {

let result = DoughnutV0::decode(&mut &encoded[..]);

assert_eq!(
result,
Err(codec::Error::from("Doughnut contains unexpected bytes"))
);
// This used to be a decoding error.
// It may be desirable for some use cases to fail when encountering extraneous bytes
// as a security precaution.
// TODO: reconcile with https://github.com/cennznet/doughnut-rs/issues/67
assert!(result.is_ok());
}

#[test]
Expand Down

0 comments on commit b6d227d

Please sign in to comment.