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

Function fromwire_tlv_uint

wire/fromwire.c:89–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89static u64 fromwire_tlv_uint(const u8 **cursor, size_t *max, size_t maxlen)
90{
91 u8 bytes[8];
92 size_t length;
93 be64 val;
94
95 assert(maxlen <= sizeof(bytes));
96
97 /* BOLT #1:
98 *
99 * - if `length` is not exactly equal to that required for the
100 * known encoding for `type`:
101 * - MUST fail to parse the `tlv_stream`.
102 */
103 length = *max;
104 if (length > maxlen) {
105 SUPERVERBOSE("greater than encoding length");
106 fromwire_fail(cursor, max);
107 return 0;
108 }
109
110 memset(bytes, 0, sizeof(bytes));
111 fromwire(cursor, max, bytes + sizeof(bytes) - length, length);
112
113 /* BOLT #1:
114 * - if variable-length fields within the known encoding for `type` are
115 * not minimal:
116 * - MUST fail to parse the `tlv_stream`.
117 */
118 if (length > 0 && bytes[sizeof(bytes) - length] == 0) {
119 SUPERVERBOSE("not minimal");
120 fromwire_fail(cursor, max);
121 return 0;
122 }
123 BUILD_ASSERT(sizeof(val) == sizeof(bytes));
124 memcpy(&val, bytes, sizeof(bytes));
125 return be64_to_cpu(val);
126}
127
128u16 fromwire_tu16(const u8 **cursor, size_t *max)
129{

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