end: 0,
};
+ if (!box) {
+ throw new RangeError('nothing to unpack');
+ }
+
const raw = Buffer.from(common.base64URLToBase64(box), 'base64');
let offset = 0;
const v = this.versionParameters[version];
offset += v.versionBytes;
+ const minBytes = v.versionBytes + v.flagsBytes + v.ivBytes + v.saltBytes + v.tagBytes;
+ if (raw.length < minBytes) {
+ throw new RangeError('not enough to unpack');
+ }
+
const flags = raw.slice(offset, offset + v.flagsBytes).readUInt8(0);
offset += v.flagsBytes;