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

Function bigsize_get

common/bigsize.c:53–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53size_t bigsize_get(const u8 *p, size_t max, bigsize_t *val)
54{
55 if (max < 1) {
56 SUPERVERBOSE("EOF");
57 return 0;
58 }
59
60 switch (*p) {
61 case 0xfd:
62 if (max < 3) {
63 SUPERVERBOSE("unexpected EOF");
64 return 0;
65 }
66 *val = ((u64)p[1] << 8) + p[2];
67 if (*val < 0xfd) {
68 SUPERVERBOSE("decoded bigsize is not canonical");
69 return 0;
70 }
71 return 3;
72 case 0xfe:
73 if (max < 5) {
74 SUPERVERBOSE("unexpected EOF");
75 return 0;
76 }
77 *val = ((u64)p[1] << 24) + ((u64)p[2] << 16)
78 + ((u64)p[3] << 8) + p[4];
79 if ((*val >> 16) == 0) {
80 SUPERVERBOSE("decoded bigsize is not canonical");
81 return 0;
82 }
83 return 5;
84 case 0xff:
85 if (max < 9) {
86 SUPERVERBOSE("unexpected EOF");
87 return 0;
88 }
89 *val = ((u64)p[1] << 56) + ((u64)p[2] << 48)
90 + ((u64)p[3] << 40) + ((u64)p[4] << 32)
91 + ((u64)p[5] << 24) + ((u64)p[6] << 16)
92 + ((u64)p[7] << 8) + p[8];
93 if ((*val >> 32) == 0) {
94 SUPERVERBOSE("decoded bigsize is not canonical");
95 return 0;
96 }
97 return 9;
98 default:
99 *val = *p;
100 return 1;
101 }
102}
103
104bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max)
105{

Callers 2

fromwire_bigsizeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected