| 93 | enum field_layer { LAYER_OFFER, LAYER_INVREQ, LAYER_INVOICE, LAYER_UNKNOWN }; |
| 94 | |
| 95 | static enum field_layer tlv_layer(bigsize_t num) |
| 96 | { |
| 97 | /* BOLT #12: |
| 98 | * A writer of an offer: |
| 99 | * - MUST NOT set any TLV fields outside the inclusive ranges: |
| 100 | 1 to 79 and 1000000000 to 1999999999. */ |
| 101 | if ((num >= 1 && num <= 79) |
| 102 | || (num >= 1000000000 && num <= 1999999999)) |
| 103 | return LAYER_OFFER; |
| 104 | /* BOLT #12: |
| 105 | * ## Requirements for Invoice Requests |
| 106 | * The writer: |
| 107 | *... |
| 108 | * MUST NOT set any non-signature TLV fields outside the inclusive |
| 109 | * ranges: 0 to 159 and 1000000000 to 2999999999 |
| 110 | */ |
| 111 | if ((num >= 80 && num <= 159) |
| 112 | || (num >= 2000000000 && num <= 2999999999)) |
| 113 | return LAYER_INVREQ; |
| 114 | /* BOLT #12: |
| 115 | * *signature TLV elements*: TLV types 240 through 1000 (inclusive) |
| 116 | */ |
| 117 | /* So, by implication, <= 239 is the invoice field, BUT we also |
| 118 | * copy the signature field */ |
| 119 | if ((num >= 160 && num <= 239) |
| 120 | || (num >= 3000000000 && num <= 3999999999) |
| 121 | || num == TLV_INVOICE_SIGNATURE) |
| 122 | return LAYER_INVOICE; |
| 123 | |
| 124 | return LAYER_UNKNOWN; |
| 125 | } |
| 126 | |
| 127 | static bool u64arr_contains(const bigsize_t *types, bigsize_t type) |
| 128 | { |
no outgoing calls
no test coverage detected