Merge pull request #207 from sorpaas/sp-message-zero

Allow all-zero messages
This commit is contained in:
Andrew Poelstra 2020-08-26 18:02:51 +00:00 committed by GitHub
commit 5c451f78c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 8 deletions

View File

@ -492,10 +492,6 @@ impl Message {
/// [secure signature](https://twitter.com/pwuille/status/1063582706288586752). /// [secure signature](https://twitter.com/pwuille/status/1063582706288586752).
#[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];
@ -1087,10 +1083,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());
} }