zcash_address: Add UA test cases for truncation and invalid padding
This commit is contained in:
parent
77d1f0c778
commit
478625f72d
|
@ -368,6 +368,73 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn padding() {
|
||||
// The test cases below use `Address(vec![Receiver::Orchard([1; 43])])` as base.
|
||||
|
||||
// Invalid padding ([0xff; 16] instead of [0x00; 16])
|
||||
let invalid_padding = [
|
||||
0xe6, 0x59, 0xd1, 0xed, 0xf7, 0x4b, 0xe3, 0x5e, 0x5a, 0x54, 0x0e, 0x41, 0x5d, 0x2f,
|
||||
0x0c, 0x0d, 0x33, 0x42, 0xbd, 0xbe, 0x9f, 0x82, 0x62, 0x01, 0xc1, 0x1b, 0xd4, 0x1e,
|
||||
0x42, 0x47, 0x86, 0x23, 0x05, 0x4b, 0x98, 0xd7, 0x76, 0x86, 0xa5, 0xe3, 0x1b, 0xd3,
|
||||
0x03, 0xca, 0x24, 0x44, 0x8e, 0x72, 0xc1, 0x4a, 0xc6, 0xbf, 0x3f, 0x2b, 0xce, 0xa7,
|
||||
0x7b, 0x28, 0x69, 0xc9, 0x84,
|
||||
];
|
||||
assert_eq!(
|
||||
Address::try_from(&invalid_padding[..]),
|
||||
Err(ParseError::InvalidEncoding)
|
||||
);
|
||||
|
||||
// Truncated padding ([0x00; 15] instead of [0x00; 16])
|
||||
let truncated_padding = [
|
||||
0x20, 0x67, 0xa5, 0xec, 0x48, 0x5c, 0xdb, 0x25, 0xa1, 0x37, 0xf7, 0x73, 0xc3, 0xae,
|
||||
0x62, 0x9e, 0xa5, 0x0e, 0x90, 0x5f, 0xda, 0xea, 0x5a, 0xe7, 0x4c, 0xb1, 0xda, 0xd9,
|
||||
0x24, 0xab, 0x92, 0x2f, 0xe6, 0xa4, 0x77, 0xa0, 0xa6, 0xb5, 0xfc, 0x0c, 0x61, 0xf4,
|
||||
0xe1, 0x89, 0x1e, 0x88, 0xa0, 0x25, 0xd8, 0xc7, 0x39, 0xa4, 0x4a, 0xc9, 0xbf, 0x3c,
|
||||
0x3b, 0xe8, 0xfd, 0x0f,
|
||||
];
|
||||
assert_eq!(
|
||||
Address::try_from(&truncated_padding[..]),
|
||||
Err(ParseError::InvalidEncoding)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncated() {
|
||||
// The test cases below start from an encoding of
|
||||
// `Address(vec![Receiver::Orchard([1; 43]), Receiver::Sapling([2; 43])])`
|
||||
// with the receiver data truncated, but valid padding.
|
||||
|
||||
// - Missing the last data byte of the Sapling receiver.
|
||||
let truncated_sapling_data = [
|
||||
0x7a, 0x1f, 0xfd, 0x14, 0x0d, 0x0c, 0x5b, 0x36, 0x35, 0x37, 0x13, 0x6f, 0xc8, 0xa7,
|
||||
0x69, 0x48, 0x8d, 0x49, 0x0c, 0x41, 0x4d, 0xdf, 0x16, 0xc1, 0x91, 0xeb, 0xc7, 0xcb,
|
||||
0x4f, 0xca, 0x20, 0xa5, 0xa6, 0x9c, 0xcb, 0x63, 0xc6, 0x81, 0xbe, 0x8f, 0xac, 0xb7,
|
||||
0x1b, 0x7a, 0x11, 0x3f, 0xda, 0x36, 0x73, 0x4e, 0x75, 0x0f, 0x0b, 0x1f, 0x62, 0x6f,
|
||||
0x83, 0xba, 0xe0, 0xf4, 0x02, 0x81, 0x63, 0x61, 0x83, 0xbc, 0x48, 0xd8, 0x7d, 0x29,
|
||||
0xdc, 0x4f, 0xf7, 0xfd, 0x85, 0x0f, 0xfd, 0xc9, 0x60, 0x54, 0x4a, 0x87, 0x84, 0xfd,
|
||||
0x49, 0xb4, 0x4f, 0x7d, 0x9a, 0x6f, 0x37, 0x65, 0x35, 0x7c, 0x18, 0xeb, 0xd7, 0x52,
|
||||
0xb7, 0xb5, 0x80, 0x53, 0x64, 0x8d, 0x71,
|
||||
];
|
||||
assert_eq!(
|
||||
Address::try_from(&truncated_sapling_data[..]),
|
||||
Err(ParseError::InvalidEncoding)
|
||||
);
|
||||
|
||||
// - Truncated after the typecode of the Sapling receiver.
|
||||
let truncated_after_sapling_typecode = [
|
||||
0xb3, 0x8f, 0xc3, 0xfd, 0xe9, 0xfa, 0x66, 0x51, 0x8a, 0xac, 0xcf, 0x31, 0x82, 0xcf,
|
||||
0xaa, 0x0b, 0xd9, 0x9e, 0xe5, 0x01, 0xbd, 0xc2, 0xdb, 0x8f, 0xb1, 0xea, 0x08, 0x3b,
|
||||
0x6e, 0xd7, 0x71, 0x22, 0x15, 0xfe, 0xe2, 0xcd, 0x2d, 0xda, 0xbd, 0x79, 0x6a, 0x92,
|
||||
0xd6, 0xb0, 0x69, 0x02, 0x0e, 0xae, 0x95, 0x58, 0xdf, 0x89, 0x80, 0xaa, 0x71, 0xb6,
|
||||
0x01, 0x56, 0x60, 0xb2, 0x61, 0xf1,
|
||||
];
|
||||
assert_eq!(
|
||||
Address::try_from(&truncated_after_sapling_typecode[..]),
|
||||
Err(ParseError::InvalidEncoding)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_typecode() {
|
||||
// Construct and serialize an invalid UA.
|
||||
|
|
Loading…
Reference in New Issue