asserts for FLAP, SNAC headers

This commit is contained in:
Artem Titoulenko 2021-09-08 12:38:42 -04:00
parent f762506bf4
commit f20f524af0

View file

@ -31,6 +31,7 @@ class TLV {
class SNAC { class SNAC {
static fromBuffer(buf, payloadLength = 0) { static fromBuffer(buf, payloadLength = 0) {
assert(buf.length >= 10, 'Expected 10 bytes for SNAC header');
const family = buf.slice(0,2).readInt16BE(0); const family = buf.slice(0,2).readInt16BE(0);
const service = buf.slice(2,4).readInt16BE(0); const service = buf.slice(2,4).readInt16BE(0);
const flags = buf.slice(4, 6); const flags = buf.slice(4, 6);
@ -85,7 +86,8 @@ class SNAC {
class FLAP { class FLAP {
static fromBuffer(buf) { static fromBuffer(buf) {
assert.equal(buf[0], 0x2a, 'Expected 0x2a FLAP header'); assert.equal(buf[0], 0x2a, 'Expected 0x2a at start of FLAP header');
assert(buf.length >= 6, 'Expected at least 6 bytes for FLAP header');
const channel = buf.readInt8(1); const channel = buf.readInt8(1);
const sequenceNumber = buf.slice(2,4).readInt16BE(0); const sequenceNumber = buf.slice(2,4).readInt16BE(0);
const payloadLength = buf.slice(4, 6).readInt16BE(0); const payloadLength = buf.slice(4, 6).readInt16BE(0);