Commit Graph

4 Commits

Author SHA1 Message Date
Sebastian Falbesoner
890bcb2ade tlv: fix comments for numLeadingZeroBytes{32,64} funcs 2020-05-02 00:42:55 +02:00
Conner Fromknecht
b3b51923dc
tlv/truncated: add non-generic encoders for truncated types
These encoders can be composed to create composite types without
incurring additional allocations that would be required to pass the
truncated types through the generic interface.
2019-11-04 14:10:43 -08:00
Conner Fromknecht
e6fdfbb1cb
tlv/truncated: fix decoding bug in DTUint16 and DTUint32
This commit fixes a bug in DTUint16 and DTUint32, which would cause them
to read too many bytes from the reader. This is due to the fact that
ReadFull was being called on a slice that could be greater than the
underlying type. This is not an issue for DTUint64, since the 8-byte
buffer corresponds to the maximum possible size of a uint64. The
solution is to clamp the buffer to 2 and 4 bytes respectively.

A series of tests are also added to exercise these cases.
2019-08-07 19:42:15 -07:00
Conner Fromknecht
7c94bbb4a2
tlv/truncated: add truncated integer encodings
This commit adds the truncated integer encodings used in the
variable-size onion payloads. The amount and cltv delta both use the
truncated encoding to shave bytes in the overall size, and will likely
be used in the future for additional extensions where size is a
constraint.
2019-08-07 15:04:33 -07:00