MCPcopy Create free account
hub / github.com/ElementsProject/lightning / fromwire_tlv_uint

Function fromwire_tlv_uint

wire/fromwire.c:115–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115static 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
153u16 fromwire_tu16(const u8 **cursor, size_t *max)
154{

Callers 3

fromwire_tu16Function · 0.85
fromwire_tu32Function · 0.85
fromwire_tu64Function · 0.85

Calls 3

be64_to_cpuFunction · 0.85
fromwire_failFunction · 0.70
fromwireFunction · 0.70

Tested by

no test coverage detected