Skip to content

Commit

Permalink
Remove test that did check for the wrong behavior
Browse files Browse the repository at this point in the history
This test checked that a too short field was not actually serialized at
all, which is wrong. Making the encrypted field this short is also not
possible as the nonce alone is 16bytes + 4bytes of ef header + 4 bytes
NTS header...
  • Loading branch information
tdittr committed Oct 31, 2023
1 parent fd50cab commit 3bd9ac6
Showing 1 changed file with 0 additions and 42 deletions.
42 changes: 0 additions & 42 deletions ntp-proto/src/packet/extension_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,48 +1239,6 @@ mod tests {
assert_eq!(slice.len(), 28 + 16);
}

#[test]
fn deserialize_without_cipher_invalid_length() {
// the message will be smaller than the cutoff value of 28
let cookie = ExtensionField::NtsCookie(Cow::Borrowed(&[0; 4]));

let data = ExtensionFieldData {
authenticated: vec![],
encrypted: vec![cookie],
untrusted: vec![],
};

let nonce_length = 11;
let cipher = crate::packet::crypto::IdentityCipher::new(nonce_length);

let mut w = [0u8; 128];
let mut cursor = Cursor::new(w.as_mut_slice());
data.serialize(&mut cursor, &cipher, ExtensionHeaderVersion::V4)
.unwrap();

let n = cursor.position() as usize;
let slice = &w.as_slice()[..n];

let cipher = crate::packet::crypto::NoCipher;

let result =
ExtensionFieldData::deserialize(slice, 0, &cipher, ExtensionHeaderVersion::V4).unwrap();

let DeserializedExtensionField {
efdata,
remaining_bytes,
cookie,
} = result;

assert_eq!(efdata.authenticated, &[]);
assert_eq!(efdata.encrypted, &[]);
assert_eq!(efdata.untrusted, &[]);

assert_eq!(remaining_bytes, slice);

assert!(cookie.is_none());
}

#[test]
fn deserialize_without_cipher() {
let cookie = ExtensionField::NtsCookie(Cow::Borrowed(&[0; 32]));
Expand Down

0 comments on commit 3bd9ac6

Please sign in to comment.