tlv: Add validity check codegen for the tlv namespaces

Since the parser itself just parses and doesn't include validation anymore we
need to put that functionality somewhere. The validation consists of enforcing
that the types are in monotonically increasing order without duplicates and
that for the even types we know how to handle it.
This commit is contained in:
Christian Decker
2019-11-18 20:02:55 +01:00
committed by Rusty Russell
parent 5794c83b4d
commit 2519f934aa
3 changed files with 50 additions and 0 deletions

View File

@@ -68,6 +68,18 @@ struct ${tlv.struct_name()} {
struct ${tlv.struct_name()} *${tlv.struct_name()}_new(const tal_t *ctx);
bool fromwire_${tlv.name}(const u8 **cursor, size_t *max, struct ${tlv.struct_name()} *record);
/**
* Check that the TLV stream is valid.
*
* Enforces the followin validity rules:
* - Types must be in monotonic non-repeating order
* - We must understand all even types
*
* Returns the index of the field that was invalid, or -1 if the stream is
* valid.
*/
int ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record);
% if tlv.name in options.expose_tlv_type:
#define TLVS_${tlv.name.upper()}_ARRAY_SIZE ${len(tlv.messages)}
extern const struct tlv_record_type tlvs_${tlv.name}[];