Limit TLV stream decoding to type ranges
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 30 Sep 2022 20:50:12 +0000 (15:50 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 18 Nov 2022 17:33:07 +0000 (11:33 -0600)
commit94a07d9caee6d38d42954ac783c49afe1cf89697
tree2084b650d1472c65c3ce7df0ea6cf93e3c0586af
parent03d0a4b497338b29fe9aa8c065edcfe26442e6e0
Limit TLV stream decoding to type ranges

BOLT 12 messages are limited to a range of TLV record types. Refactor
decode_tlv_stream into a decode_tlv_stream_range macro for limiting
which types are parsed. Requires a SeekReadable trait for rewinding when
a type outside of the range is seen. This allows for composing TLV
streams of different ranges.

Updates offer parsing accordingly and adds a test demonstrating failure
if a type outside of the range is included.
lightning/src/offers/offer.rs
lightning/src/offers/parse.rs
lightning/src/util/ser.rs
lightning/src/util/ser_macros.rs