Allow all-zero messages
This commit is contained in:
parent
9aa768df10
commit
9250ae49ce
|
@ -454,10 +454,6 @@ impl Message {
|
||||||
/// Converts a `MESSAGE_SIZE`-byte slice to a message object
|
/// Converts a `MESSAGE_SIZE`-byte slice to a message object
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_slice(data: &[u8]) -> Result<Message, Error> {
|
pub fn from_slice(data: &[u8]) -> Result<Message, Error> {
|
||||||
if data == [0; constants::MESSAGE_SIZE] {
|
|
||||||
return Err(Error::InvalidMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
match data.len() {
|
match data.len() {
|
||||||
constants::MESSAGE_SIZE => {
|
constants::MESSAGE_SIZE => {
|
||||||
let mut ret = [0; constants::MESSAGE_SIZE];
|
let mut ret = [0; constants::MESSAGE_SIZE];
|
||||||
|
@ -1007,10 +1003,7 @@ mod tests {
|
||||||
Err(InvalidMessage));
|
Err(InvalidMessage));
|
||||||
assert_eq!(Message::from_slice(&[0; constants::MESSAGE_SIZE + 1]),
|
assert_eq!(Message::from_slice(&[0; constants::MESSAGE_SIZE + 1]),
|
||||||
Err(InvalidMessage));
|
Err(InvalidMessage));
|
||||||
assert_eq!(
|
assert!(Message::from_slice(&[0; constants::MESSAGE_SIZE]).is_ok());
|
||||||
Message::from_slice(&[0; constants::MESSAGE_SIZE]),
|
|
||||||
Err(InvalidMessage)
|
|
||||||
);
|
|
||||||
assert!(Message::from_slice(&[1; constants::MESSAGE_SIZE]).is_ok());
|
assert!(Message::from_slice(&[1; constants::MESSAGE_SIZE]).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue