Assert x.509 name is shorter than 64KB

Otherwise this function produces incorrect output.
This commit is contained in:
Joseph Birr-Pixton 2020-06-08 20:36:41 +01:00
parent 22a9a49bd4
commit 227d9a2aff
1 changed files with 12 additions and 0 deletions

View File

@ -14,6 +14,8 @@ fn wrap_in_asn1_len(bytes: &mut Vec<u8>) {
bytes.insert(0, 0x82u8);
bytes.insert(1, ((len >> 8) & 0xff) as u8);
bytes.insert(2, (len & 0xff) as u8);
} else {
assert!(len <= 0xffff, "excessively long x.509 name");
}
}
@ -60,3 +62,13 @@ fn test_large() {
assert_eq!(vec![0x30, 0x82, 0x12, 0x34, 0x12, 0x12],
val[..6].to_vec());
}
#[test]
fn test_huge() {
let mut val = Vec::new();
val.resize(0xffff, 0x12);
wrap_in_sequence(&mut val);
assert_eq!(vec![0x30, 0x82, 0xff, 0xff, 0x12, 0x12],
val[..6].to_vec());
assert_eq!(val.len(), 0xffff + 4);
}