@basmilius/apple-encoding 0.9.17 → 0.9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -1
- package/dist/index.mjs +20 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -157,7 +157,7 @@ declare namespace plist_d_exports {
|
|
|
157
157
|
export { parse, serialize };
|
|
158
158
|
}
|
|
159
159
|
declare namespace tlv8_d_exports {
|
|
160
|
-
export { ErrorCode, Flags, Method, State, Value, bail, decode, encode };
|
|
160
|
+
export { ErrorCode, Flags, Method, State, TLV8PairingError, Value, bail, decode, encode };
|
|
161
161
|
}
|
|
162
162
|
declare const Flags: {
|
|
163
163
|
readonly TransientPairing: 0x10;
|
|
@@ -205,6 +205,10 @@ declare const Value: {
|
|
|
205
205
|
readonly Name: 0x11;
|
|
206
206
|
readonly Flags: 0x13;
|
|
207
207
|
};
|
|
208
|
+
declare class TLV8PairingError extends Error {
|
|
209
|
+
readonly code: number | undefined;
|
|
210
|
+
constructor(message: string, code?: number);
|
|
211
|
+
}
|
|
208
212
|
declare function bail(data: Map<number, Buffer>): never;
|
|
209
213
|
declare function encode(entries: [number, number | Buffer | Uint8Array][]): Buffer;
|
|
210
214
|
declare function decode(buf: Buffer): Map<number, Buffer>;
|
package/dist/index.mjs
CHANGED
|
@@ -398,6 +398,7 @@ function uintToLEBytes(value, byteLen) {
|
|
|
398
398
|
return out;
|
|
399
399
|
}
|
|
400
400
|
function readLittleEndian(buf, offset, len) {
|
|
401
|
+
if (offset + len > buf.length) return 0;
|
|
401
402
|
if (len === 1) return buf[offset];
|
|
402
403
|
else if (len === 2) return buf[offset] | buf[offset + 1] << 8;
|
|
403
404
|
else if (len === 4) return buf[offset] | buf[offset + 1] << 8 | buf[offset + 2] << 16 | buf[offset + 3] << 24 >>> 0;
|
|
@@ -670,12 +671,12 @@ function _unpackAt(data, offset, objectList) {
|
|
|
670
671
|
let pos = offset + 1;
|
|
671
672
|
if (count === 15) {
|
|
672
673
|
const arr = [];
|
|
673
|
-
while (data[pos] !== TAG.TERMINATOR) {
|
|
674
|
+
while (pos < data.length && data[pos] !== TAG.TERMINATOR) {
|
|
674
675
|
const result = _unpackAt(data, pos, objectList);
|
|
675
676
|
arr.push(result.value);
|
|
676
677
|
pos = result.offset;
|
|
677
678
|
}
|
|
678
|
-
pos++;
|
|
679
|
+
if (pos < data.length) pos++;
|
|
679
680
|
value = arr;
|
|
680
681
|
} else {
|
|
681
682
|
const arr = new Array(count);
|
|
@@ -693,13 +694,13 @@ function _unpackAt(data, offset, objectList) {
|
|
|
693
694
|
const obj = {};
|
|
694
695
|
let pos = offset + 1;
|
|
695
696
|
if (count === 15) {
|
|
696
|
-
while (data[pos] !== TAG.TERMINATOR) {
|
|
697
|
+
while (pos < data.length && data[pos] !== TAG.TERMINATOR) {
|
|
697
698
|
const keyResult = _unpackAt(data, pos, objectList);
|
|
698
699
|
const valResult = _unpackAt(data, keyResult.offset, objectList);
|
|
699
700
|
obj[keyResult.value] = valResult.value;
|
|
700
701
|
pos = valResult.offset;
|
|
701
702
|
}
|
|
702
|
-
pos++;
|
|
703
|
+
if (pos < data.length) pos++;
|
|
703
704
|
} else for (let i = 0; i < count; i++) {
|
|
704
705
|
const keyResult = _unpackAt(data, pos, objectList);
|
|
705
706
|
const valResult = _unpackAt(data, keyResult.offset, objectList);
|
|
@@ -1254,6 +1255,7 @@ var tlv8_exports = /* @__PURE__ */ __exportAll({
|
|
|
1254
1255
|
Flags: () => Flags,
|
|
1255
1256
|
Method: () => Method,
|
|
1256
1257
|
State: () => State,
|
|
1258
|
+
TLV8PairingError: () => TLV8PairingError,
|
|
1257
1259
|
Value: () => Value,
|
|
1258
1260
|
bail: () => bail,
|
|
1259
1261
|
decode: () => decode,
|
|
@@ -1303,18 +1305,26 @@ const Value = {
|
|
|
1303
1305
|
Name: 17,
|
|
1304
1306
|
Flags: 19
|
|
1305
1307
|
};
|
|
1308
|
+
var TLV8PairingError = class extends Error {
|
|
1309
|
+
code;
|
|
1310
|
+
constructor(message, code) {
|
|
1311
|
+
super(message);
|
|
1312
|
+
this.name = "TLV8PairingError";
|
|
1313
|
+
this.code = code;
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1306
1316
|
function bail(data) {
|
|
1307
1317
|
if (data.has(Value.BackOff)) {
|
|
1308
1318
|
const buffer = data.get(Value.BackOff);
|
|
1309
|
-
|
|
1310
|
-
throw new Error(`Device is busy, try again in ${time} seconds.`);
|
|
1319
|
+
throw new TLV8PairingError(`Device is busy, try again in ${buffer.readUintLE(0, buffer.length)} seconds.`, ErrorCode.BackOff);
|
|
1311
1320
|
}
|
|
1312
1321
|
if (data.has(Value.Error)) {
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
throw new
|
|
1322
|
+
const code = data.get(Value.Error).readUint8();
|
|
1323
|
+
const errorCode = Object.entries(ErrorCode).find(([_, c]) => c === code);
|
|
1324
|
+
if (!errorCode) throw new TLV8PairingError(`Device returned an unknown error code: ${code}`, code);
|
|
1325
|
+
throw new TLV8PairingError(`Device returned an error code: ${errorCode[0]}`, code);
|
|
1316
1326
|
}
|
|
1317
|
-
throw new
|
|
1327
|
+
throw new TLV8PairingError("Invalid response");
|
|
1318
1328
|
}
|
|
1319
1329
|
function encode(entries) {
|
|
1320
1330
|
let totalSize = 0;
|