| 113 | } |
| 114 | |
| 115 | static u64 fromwire_tlv_uint(const u8 **cursor, size_t *max, size_t maxlen) |
| 116 | { |
| 117 | u8 bytes[8]; |
| 118 | size_t length; |
| 119 | be64 val; |
| 120 | |
| 121 | assert(maxlen <= sizeof(bytes)); |
| 122 | |
| 123 | /* BOLT #1: |
| 124 | * |
| 125 | * - if `length` is not exactly equal to that required for the |
| 126 | * known encoding for `type`: |
| 127 | * - MUST fail to parse the `tlv_stream`. |
| 128 | */ |
| 129 | length = *max; |
| 130 | if (length > maxlen) { |
| 131 | SUPERVERBOSE("greater than encoding length"); |
| 132 | fromwire_fail(cursor, max); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | memset(bytes, 0, sizeof(bytes)); |
| 137 | fromwire(cursor, max, bytes + sizeof(bytes) - length, length); |
| 138 | |
| 139 | /* BOLT #1: |
| 140 | * - if variable-length fields within the known encoding for `type` are |
| 141 | * not minimal: |
| 142 | * - MUST fail to parse the `tlv_stream`. |
| 143 | */ |
| 144 | if (length > 0 && bytes[sizeof(bytes) - length] == 0) { |
| 145 | SUPERVERBOSE("not minimal"); |
| 146 | fromwire_fail(cursor, max); |
| 147 | return 0; |
| 148 | } |
| 149 | CROSS_TYPE_ASSIGNMENT(&val, &bytes); |
| 150 | return be64_to_cpu(val); |
| 151 | } |
| 152 | |
| 153 | u16 fromwire_tu16(const u8 **cursor, size_t *max) |
| 154 | { |
no test coverage detected