appium-ios-remotexpc 0.0.3 → 0.0.5
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/CHANGELOG.md +12 -0
- package/build/src/base-plist-service.d.ts +51 -0
- package/build/src/base-plist-service.d.ts.map +1 -0
- package/build/src/base-plist-service.js +61 -0
- package/build/src/base-socket-service.d.ts +15 -0
- package/build/src/base-socket-service.d.ts.map +1 -0
- package/build/src/base-socket-service.js +46 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +7 -0
- package/build/src/lib/apple-tv/constants.d.ts +77 -0
- package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
- package/build/src/lib/apple-tv/constants.js +106 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts +22 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/chacha20-poly1305.js +97 -0
- package/build/src/lib/apple-tv/encryption/ed25519.d.ts +16 -0
- package/build/src/lib/apple-tv/encryption/ed25519.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/ed25519.js +93 -0
- package/build/src/lib/apple-tv/encryption/hkdf.d.ts +18 -0
- package/build/src/lib/apple-tv/encryption/hkdf.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/hkdf.js +73 -0
- package/build/src/lib/apple-tv/encryption/index.d.ts +5 -0
- package/build/src/lib/apple-tv/encryption/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/index.js +4 -0
- package/build/src/lib/apple-tv/encryption/opack2.d.ts +57 -0
- package/build/src/lib/apple-tv/encryption/opack2.d.ts.map +1 -0
- package/build/src/lib/apple-tv/encryption/opack2.js +203 -0
- package/build/src/lib/apple-tv/errors.d.ts +17 -0
- package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
- package/build/src/lib/apple-tv/errors.js +30 -0
- package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
- package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
- package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
- package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
- package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
- package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/index.js +3 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
- package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
- package/build/src/lib/apple-tv/types.d.ts +36 -0
- package/build/src/lib/apple-tv/types.d.ts.map +1 -0
- package/build/src/lib/apple-tv/types.js +1 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
- package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
- package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/index.js +2 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
- package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
- package/build/src/lib/lockdown/index.d.ts +87 -0
- package/build/src/lib/lockdown/index.d.ts.map +1 -0
- package/build/src/lib/lockdown/index.js +324 -0
- package/build/src/lib/pair-record/index.d.ts +3 -0
- package/build/src/lib/pair-record/index.d.ts.map +1 -0
- package/build/src/lib/pair-record/index.js +2 -0
- package/build/src/lib/pair-record/pair-record.d.ts +48 -0
- package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
- package/build/src/lib/pair-record/pair-record.js +85 -0
- package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
- package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/binary-plist-creator.js +475 -0
- package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
- package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/binary-plist-parser.js +449 -0
- package/build/src/lib/plist/constants.d.ts +36 -0
- package/build/src/lib/plist/constants.d.ts.map +1 -0
- package/build/src/lib/plist/constants.js +43 -0
- package/build/src/lib/plist/index.d.ts +14 -0
- package/build/src/lib/plist/index.d.ts.map +1 -0
- package/build/src/lib/plist/index.js +16 -0
- package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
- package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
- package/build/src/lib/plist/length-based-splitter.js +228 -0
- package/build/src/lib/plist/plist-creator.d.ts +8 -0
- package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/plist-creator.js +33 -0
- package/build/src/lib/plist/plist-decoder.d.ts +25 -0
- package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
- package/build/src/lib/plist/plist-decoder.js +103 -0
- package/build/src/lib/plist/plist-encoder.d.ts +10 -0
- package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
- package/build/src/lib/plist/plist-encoder.js +27 -0
- package/build/src/lib/plist/plist-parser.d.ts +9 -0
- package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/plist-parser.js +109 -0
- package/build/src/lib/plist/plist-service.d.ts +86 -0
- package/build/src/lib/plist/plist-service.d.ts.map +1 -0
- package/build/src/lib/plist/plist-service.js +180 -0
- package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
- package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
- package/build/src/lib/plist/unified-plist-creator.js +14 -0
- package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
- package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
- package/build/src/lib/plist/unified-plist-parser.js +23 -0
- package/build/src/lib/plist/utils.d.ts +97 -0
- package/build/src/lib/plist/utils.d.ts.map +1 -0
- package/build/src/lib/plist/utils.js +287 -0
- package/build/src/lib/remote-xpc/constants.d.ts +20 -0
- package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/constants.js +21 -0
- package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
- package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
- package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
- package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/handshake.js +95 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
- package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
- package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
- package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
- package/build/src/lib/tunnel/index.d.ts +69 -0
- package/build/src/lib/tunnel/index.d.ts.map +1 -0
- package/build/src/lib/tunnel/index.js +205 -0
- package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
- package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
- package/build/src/lib/tunnel/packet-stream-client.js +152 -0
- package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
- package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
- package/build/src/lib/tunnel/packet-stream-server.js +109 -0
- package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
- package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
- package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
- package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
- package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
- package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
- package/build/src/lib/types.d.ts +238 -0
- package/build/src/lib/types.d.ts.map +1 -0
- package/build/src/lib/types.js +4 -0
- package/build/src/lib/usbmux/index.d.ts +177 -0
- package/build/src/lib/usbmux/index.d.ts.map +1 -0
- package/build/src/lib/usbmux/index.js +490 -0
- package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
- package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
- package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
- package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
- package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
- package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
- package/build/src/service-connection.d.ts +34 -0
- package/build/src/service-connection.d.ts.map +1 -0
- package/build/src/service-connection.js +51 -0
- package/build/src/services/index.d.ts +6 -0
- package/build/src/services/index.d.ts.map +1 -0
- package/build/src/services/index.js +5 -0
- package/build/src/services/ios/base-service.d.ts +35 -0
- package/build/src/services/ios/base-service.d.ts.map +1 -0
- package/build/src/services/ios/base-service.js +55 -0
- package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
- package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
- package/build/src/services/ios/diagnostic-service/index.js +169 -0
- package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
- package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
- package/build/src/services/ios/diagnostic-service/keys.js +770 -0
- package/build/src/services/ios/syslog-service/index.d.ts +91 -0
- package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
- package/build/src/services/ios/syslog-service/index.js +323 -0
- package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
- package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
- package/build/src/services/ios/tunnel-service/index.js +57 -0
- package/build/src/services.d.ts +14 -0
- package/build/src/services.d.ts.map +1 -0
- package/build/src/services.js +48 -0
- package/package.json +12 -3
- package/src/lib/apple-tv/constants.ts +42 -0
- package/src/lib/apple-tv/encryption/chacha20-poly1305.ts +147 -0
- package/src/lib/apple-tv/encryption/ed25519.ts +126 -0
- package/src/lib/apple-tv/encryption/hkdf.ts +95 -0
- package/src/lib/apple-tv/encryption/index.ts +11 -0
- package/src/lib/apple-tv/encryption/opack2.ts +257 -0
- package/.github/dependabot.yml +0 -38
- package/.github/workflows/format-check.yml +0 -43
- package/.github/workflows/lint-and-build.yml +0 -40
- package/.github/workflows/pr-title.yml +0 -16
- package/.github/workflows/publish.js.yml +0 -43
- package/.github/workflows/test-validation.yml +0 -40
- package/.mocharc.json +0 -8
- package/.prettierignore +0 -3
- package/.prettierrc +0 -17
- package/.releaserc +0 -48
- package/assets/images/ios-arch.png +0 -0
- package/eslint.config.js +0 -45
- package/npm-shrinkwrap.json +0 -2711
- package/test/integration/diagnostics-test.ts +0 -44
- package/test/integration/read-pair-record-test.ts +0 -39
- package/test/integration/tunnel-test.ts +0 -104
- package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
- package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
- package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
- package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
- package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
- package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
- package/test/unit/fixtures/index.ts +0 -88
- package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
- package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
- package/test/unit/plist/error-handling.spec.ts +0 -101
- package/test/unit/plist/fixtures/sample.binary.plist +0 -0
- package/test/unit/plist/fixtures/sample.xml.plist +0 -38
- package/test/unit/plist/plist-parser.spec.ts +0 -283
- package/test/unit/plist/plist.spec.ts +0 -205
- package/test/unit/plist/tag-position-handling.spec.ts +0 -90
- package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
- package/test/unit/plist/utils.spec.ts +0 -249
- package/test/unit/plist/xml-cleaning.spec.ts +0 -60
- package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
- package/test/unit/usbmux/usbmux-specs.ts +0 -71
- package/tsconfig.json +0 -36
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { Services } from '../../src/index.js';
|
|
4
|
-
import type { DiagnosticsService } from '../../src/lib/types.js';
|
|
5
|
-
|
|
6
|
-
describe('Diagnostics Service', function () {
|
|
7
|
-
// Increase timeout for integration tests
|
|
8
|
-
this.timeout(60000);
|
|
9
|
-
|
|
10
|
-
let remoteXPC: any;
|
|
11
|
-
let diagService: DiagnosticsService;
|
|
12
|
-
const udid = process.env.UDID || '';
|
|
13
|
-
|
|
14
|
-
before(async function () {
|
|
15
|
-
diagService = await Services.startDiagnosticsService(udid);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
after(async function () {
|
|
19
|
-
// Close RemoteXPC connection
|
|
20
|
-
if (remoteXPC) {
|
|
21
|
-
try {
|
|
22
|
-
await remoteXPC.close();
|
|
23
|
-
} catch (error) {
|
|
24
|
-
// Ignore cleanup errors in tests
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should query power information using ioregistry', async function () {
|
|
30
|
-
const rawInfo = await diagService.ioregistry({
|
|
31
|
-
ioClass: 'IOPMPowerSource',
|
|
32
|
-
returnRawJson: true,
|
|
33
|
-
});
|
|
34
|
-
expect(rawInfo).to.be.an('object');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should query wifi information using ioregistry ', async function () {
|
|
38
|
-
const wifiInfo = await diagService.ioregistry({
|
|
39
|
-
name: 'AppleBCMWLANSkywalkInterface',
|
|
40
|
-
returnRawJson: true,
|
|
41
|
-
});
|
|
42
|
-
expect(wifiInfo).to.be.an('object');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { createUsbmux } from '../../src/lib/usbmux/index.js';
|
|
4
|
-
|
|
5
|
-
describe('Pair Record', function () {
|
|
6
|
-
// Increase timeout for integration tests
|
|
7
|
-
this.timeout(60000);
|
|
8
|
-
|
|
9
|
-
let usb: any;
|
|
10
|
-
|
|
11
|
-
before(async function () {
|
|
12
|
-
usb = await createUsbmux();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
after(async function () {
|
|
16
|
-
if (usb) {
|
|
17
|
-
await usb.close();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should read pair record', async function () {
|
|
22
|
-
try {
|
|
23
|
-
await usb.readPairRecord('');
|
|
24
|
-
// If no error is thrown, the test passes
|
|
25
|
-
expect(true).to.be.true;
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.log(err);
|
|
28
|
-
// If the error is expected (e.g., no pair record found), the test can still pass
|
|
29
|
-
// Otherwise, fail the test
|
|
30
|
-
expect(err).to.not.be.undefined;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should list devices', async function () {
|
|
35
|
-
const devices = await usb.listDevices();
|
|
36
|
-
console.log(devices);
|
|
37
|
-
expect(devices).to.be.an('array');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { logger } from '@appium/support';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
PacketStreamClient,
|
|
6
|
-
TunnelManager,
|
|
7
|
-
} from '../../src/lib/tunnel/index.js';
|
|
8
|
-
import type { SyslogService } from '../../src/lib/types.js';
|
|
9
|
-
import {
|
|
10
|
-
createRemoteXPCConnection,
|
|
11
|
-
startSyslogService,
|
|
12
|
-
} from '../../src/services.js';
|
|
13
|
-
|
|
14
|
-
const log = logger.getLogger('TunnelTest');
|
|
15
|
-
|
|
16
|
-
describe('Tunnel and Syslog Service', function () {
|
|
17
|
-
// Increase timeout for integration tests
|
|
18
|
-
this.timeout(60000);
|
|
19
|
-
|
|
20
|
-
let remoteXpc: any;
|
|
21
|
-
let syslogService: SyslogService;
|
|
22
|
-
let service: any;
|
|
23
|
-
let packetStreamClient: PacketStreamClient | null = null;
|
|
24
|
-
const udid = process.env.UDID || '';
|
|
25
|
-
|
|
26
|
-
before(async function () {
|
|
27
|
-
const { remoteXPC, tunnelConnection } =
|
|
28
|
-
await createRemoteXPCConnection(udid);
|
|
29
|
-
remoteXpc = remoteXPC;
|
|
30
|
-
packetStreamClient = new PacketStreamClient(
|
|
31
|
-
'localhost',
|
|
32
|
-
tunnelConnection.packetStreamPort,
|
|
33
|
-
);
|
|
34
|
-
try {
|
|
35
|
-
await packetStreamClient.connect();
|
|
36
|
-
log.info('Connected to packet stream server');
|
|
37
|
-
} catch (err) {
|
|
38
|
-
log.warn(`Failed to connect to packet stream server: ${err}`);
|
|
39
|
-
packetStreamClient = null;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
after(async function () {
|
|
44
|
-
if (packetStreamClient) {
|
|
45
|
-
await packetStreamClient.disconnect();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
await TunnelManager.closeAllTunnels();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should list all services', function () {
|
|
52
|
-
const services = remoteXpc.getServices();
|
|
53
|
-
expect(services).to.be.an('array');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should find os_trace_relay service', function () {
|
|
57
|
-
service = remoteXpc.findService('com.apple.os_trace_relay.shim.remote');
|
|
58
|
-
expect(service).to.not.be.undefined;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should start syslog service (requires active tunnel with packet source)', async function () {
|
|
62
|
-
syslogService = await startSyslogService(udid);
|
|
63
|
-
if (!packetStreamClient) {
|
|
64
|
-
this.skip();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Refresh the service object before using it
|
|
69
|
-
service = remoteXpc.findService('com.apple.os_trace_relay.shim.remote');
|
|
70
|
-
expect(service).to.not.be.undefined;
|
|
71
|
-
|
|
72
|
-
await syslogService.start(service, packetStreamClient, {
|
|
73
|
-
pid: -1,
|
|
74
|
-
});
|
|
75
|
-
expect(true).to.be.true;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should capture and emit syslog messages (requires active tunnel with packet source)', async function () {
|
|
79
|
-
if (!packetStreamClient) {
|
|
80
|
-
this.skip();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Refresh the service object before using it again
|
|
85
|
-
service = remoteXpc.findService('com.apple.os_trace_relay.shim.remote');
|
|
86
|
-
expect(service).to.not.be.undefined;
|
|
87
|
-
|
|
88
|
-
const messages: string[] = [];
|
|
89
|
-
syslogService.on('message', (message: string) => {
|
|
90
|
-
messages.push(message);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
await syslogService.start(service, packetStreamClient, {
|
|
94
|
-
pid: -1,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Wait for a few seconds to collect messages
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
99
|
-
|
|
100
|
-
await syslogService.stop();
|
|
101
|
-
|
|
102
|
-
expect(messages.length).to.be.greaterThan(0);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { TLV8Error } from '../../../../src/lib/apple-tv/errors.js';
|
|
4
|
-
import {
|
|
5
|
-
decodeTLV8,
|
|
6
|
-
decodeTLV8ToDict,
|
|
7
|
-
} from '../../../../src/lib/apple-tv/tlv/decoder.js';
|
|
8
|
-
|
|
9
|
-
describe('TLV8 Decoder', function () {
|
|
10
|
-
describe('decodeTLV8', function () {
|
|
11
|
-
it('should decode a single TLV8 item', function () {
|
|
12
|
-
const buffer = Buffer.from([0x01, 0x03, 0x42, 0x43, 0x44]);
|
|
13
|
-
|
|
14
|
-
const result = decodeTLV8(buffer);
|
|
15
|
-
|
|
16
|
-
expect(result).to.have.lengthOf(1);
|
|
17
|
-
expect(result[0].type).to.equal(0x01);
|
|
18
|
-
expect(result[0].data).to.deep.equal(Buffer.from([0x42, 0x43, 0x44]));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should decode multiple TLV8 items', function () {
|
|
22
|
-
const buffer = Buffer.from([
|
|
23
|
-
0x01, 0x01, 0x42, 0x02, 0x02, 0x43, 0x44, 0x03, 0x03, 0x45, 0x46, 0x47,
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
const result = decodeTLV8(buffer);
|
|
27
|
-
|
|
28
|
-
expect(result).to.have.lengthOf(3);
|
|
29
|
-
|
|
30
|
-
expect(result[0].type).to.equal(0x01);
|
|
31
|
-
expect(result[0].data).to.deep.equal(Buffer.from([0x42]));
|
|
32
|
-
|
|
33
|
-
expect(result[1].type).to.equal(0x02);
|
|
34
|
-
expect(result[1].data).to.deep.equal(Buffer.from([0x43, 0x44]));
|
|
35
|
-
|
|
36
|
-
expect(result[2].type).to.equal(0x03);
|
|
37
|
-
expect(result[2].data).to.deep.equal(Buffer.from([0x45, 0x46, 0x47]));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should handle empty buffer', function () {
|
|
41
|
-
const buffer = Buffer.alloc(0);
|
|
42
|
-
|
|
43
|
-
const result = decodeTLV8(buffer);
|
|
44
|
-
|
|
45
|
-
expect(result).to.deep.equal([]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should decode fragmented data', function () {
|
|
49
|
-
const buffer = Buffer.from([
|
|
50
|
-
0x05,
|
|
51
|
-
0xff,
|
|
52
|
-
...Buffer.alloc(255, 0xab),
|
|
53
|
-
0x05,
|
|
54
|
-
0x01,
|
|
55
|
-
0xab,
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
const result = decodeTLV8(buffer);
|
|
59
|
-
|
|
60
|
-
expect(result).to.have.lengthOf(2);
|
|
61
|
-
expect(result[0].type).to.equal(0x05);
|
|
62
|
-
expect(result[0].data).to.deep.equal(Buffer.alloc(255, 0xab));
|
|
63
|
-
expect(result[1].type).to.equal(0x05);
|
|
64
|
-
expect(result[1].data).to.deep.equal(Buffer.from([0xab]));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should throw error for insufficient data for type and length', function () {
|
|
68
|
-
const buffer = Buffer.from([0x01]);
|
|
69
|
-
|
|
70
|
-
expect(() => decodeTLV8(buffer)).to.throw(
|
|
71
|
-
TLV8Error,
|
|
72
|
-
'Invalid TLV8: insufficient data for type and length at offset 0',
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should throw error for insufficient data for value', function () {
|
|
77
|
-
const buffer = Buffer.from([0x01, 0x05, 0x42, 0x43]);
|
|
78
|
-
|
|
79
|
-
expect(() => decodeTLV8(buffer)).to.throw(
|
|
80
|
-
TLV8Error,
|
|
81
|
-
'Invalid TLV8: insufficient data for value at offset 2',
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('decodeTLV8ToDict', function () {
|
|
87
|
-
it('should decode to dictionary with unique types', function () {
|
|
88
|
-
const buffer = Buffer.from([
|
|
89
|
-
0x01, 0x01, 0x42, 0x02, 0x02, 0x43, 0x44, 0x03, 0x03, 0x45, 0x46, 0x47,
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
const result = decodeTLV8ToDict(buffer);
|
|
93
|
-
|
|
94
|
-
expect(result[0x01]).to.deep.equal(Buffer.from([0x42]));
|
|
95
|
-
expect(result[0x02]).to.deep.equal(Buffer.from([0x43, 0x44]));
|
|
96
|
-
expect(result[0x03]).to.deep.equal(Buffer.from([0x45, 0x46, 0x47]));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should concatenate data for repeated types', function () {
|
|
100
|
-
const buffer = Buffer.from([
|
|
101
|
-
0x05,
|
|
102
|
-
0xff,
|
|
103
|
-
...Buffer.alloc(255, 0xab),
|
|
104
|
-
0x05,
|
|
105
|
-
0x01,
|
|
106
|
-
0xab,
|
|
107
|
-
0x06,
|
|
108
|
-
0x02,
|
|
109
|
-
0xcc,
|
|
110
|
-
0xdd,
|
|
111
|
-
0x05,
|
|
112
|
-
0x02,
|
|
113
|
-
0xee,
|
|
114
|
-
0xff,
|
|
115
|
-
]);
|
|
116
|
-
|
|
117
|
-
const result = decodeTLV8ToDict(buffer);
|
|
118
|
-
|
|
119
|
-
expect(result[0x05]).to.deep.equal(
|
|
120
|
-
Buffer.concat([
|
|
121
|
-
Buffer.alloc(255, 0xab),
|
|
122
|
-
Buffer.from([0xab]),
|
|
123
|
-
Buffer.from([0xee, 0xff]),
|
|
124
|
-
]),
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
expect(result[0x06]).to.deep.equal(Buffer.from([0xcc, 0xdd]));
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should handle empty buffer', function () {
|
|
131
|
-
const buffer = Buffer.alloc(0);
|
|
132
|
-
|
|
133
|
-
const result = decodeTLV8ToDict(buffer);
|
|
134
|
-
|
|
135
|
-
expect(result).to.deep.equal({});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should throw error for malformed data', function () {
|
|
139
|
-
const buffer = Buffer.from([0x01, 0x05, 0x42]);
|
|
140
|
-
|
|
141
|
-
expect(() => decodeTLV8ToDict(buffer)).to.throw(TLV8Error);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { TLV8_MAX_FRAGMENT_SIZE } from '../../../../src/lib/apple-tv/constants.js';
|
|
4
|
-
import { encodeTLV8 } from '../../../../src/lib/apple-tv/tlv/encoder.js';
|
|
5
|
-
import type { TLV8Item } from '../../../../src/lib/apple-tv/types.js';
|
|
6
|
-
|
|
7
|
-
describe('TLV8 Encoder', function () {
|
|
8
|
-
describe('encodeTLV8', function () {
|
|
9
|
-
it('should encode a single TLV8 item', function () {
|
|
10
|
-
const items: TLV8Item[] = [
|
|
11
|
-
{ type: 0x01, data: Buffer.from([0x42, 0x43, 0x44]) },
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
const result = encodeTLV8(items);
|
|
15
|
-
|
|
16
|
-
expect(result).to.deep.equal(Buffer.from([0x01, 0x03, 0x42, 0x43, 0x44]));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should encode multiple TLV8 items', function () {
|
|
20
|
-
const items: TLV8Item[] = [
|
|
21
|
-
{ type: 0x01, data: Buffer.from([0x42]) },
|
|
22
|
-
{ type: 0x02, data: Buffer.from([0x43, 0x44]) },
|
|
23
|
-
{ type: 0x03, data: Buffer.from([0x45, 0x46, 0x47]) },
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
const result = encodeTLV8(items);
|
|
27
|
-
|
|
28
|
-
expect(result).to.deep.equal(
|
|
29
|
-
Buffer.from([
|
|
30
|
-
0x01, 0x01, 0x42, 0x02, 0x02, 0x43, 0x44, 0x03, 0x03, 0x45, 0x46,
|
|
31
|
-
0x47,
|
|
32
|
-
]),
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should handle empty items array', function () {
|
|
37
|
-
const items: TLV8Item[] = [];
|
|
38
|
-
|
|
39
|
-
const result = encodeTLV8(items);
|
|
40
|
-
|
|
41
|
-
expect(result).to.deep.equal(Buffer.alloc(0));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should fragment data exceeding TLV8_MAX_FRAGMENT_SIZE', function () {
|
|
45
|
-
const largeData = Buffer.alloc(256, 0xab);
|
|
46
|
-
const items: TLV8Item[] = [{ type: 0x05, data: largeData }];
|
|
47
|
-
|
|
48
|
-
const result = encodeTLV8(items);
|
|
49
|
-
|
|
50
|
-
expect(result.length).to.equal(
|
|
51
|
-
2 + TLV8_MAX_FRAGMENT_SIZE + 2 + (256 - TLV8_MAX_FRAGMENT_SIZE),
|
|
52
|
-
);
|
|
53
|
-
expect(result[0]).to.equal(0x05);
|
|
54
|
-
expect(result[1]).to.equal(TLV8_MAX_FRAGMENT_SIZE);
|
|
55
|
-
expect(result.subarray(2, 2 + TLV8_MAX_FRAGMENT_SIZE)).to.deep.equal(
|
|
56
|
-
Buffer.alloc(TLV8_MAX_FRAGMENT_SIZE, 0xab),
|
|
57
|
-
);
|
|
58
|
-
expect(result[2 + TLV8_MAX_FRAGMENT_SIZE]).to.equal(0x05);
|
|
59
|
-
expect(result[3 + TLV8_MAX_FRAGMENT_SIZE]).to.equal(
|
|
60
|
-
256 - TLV8_MAX_FRAGMENT_SIZE,
|
|
61
|
-
);
|
|
62
|
-
expect(result[4 + TLV8_MAX_FRAGMENT_SIZE]).to.equal(0xab);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should handle data exactly at TLV8_MAX_FRAGMENT_SIZE boundary', function () {
|
|
66
|
-
const boundaryData = Buffer.alloc(TLV8_MAX_FRAGMENT_SIZE, 0xef);
|
|
67
|
-
const items: TLV8Item[] = [{ type: 0x08, data: boundaryData }];
|
|
68
|
-
|
|
69
|
-
const result = encodeTLV8(items);
|
|
70
|
-
|
|
71
|
-
expect(result.length).to.equal(2 + TLV8_MAX_FRAGMENT_SIZE);
|
|
72
|
-
expect(result[0]).to.equal(0x08);
|
|
73
|
-
expect(result[1]).to.equal(TLV8_MAX_FRAGMENT_SIZE);
|
|
74
|
-
expect(result.subarray(2)).to.deep.equal(boundaryData);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should handle all possible type values', function () {
|
|
78
|
-
const items: TLV8Item[] = [
|
|
79
|
-
{ type: 0x00, data: Buffer.from([0x00]) },
|
|
80
|
-
{ type: 0x7f, data: Buffer.from([0x7f]) },
|
|
81
|
-
{ type: 0xff, data: Buffer.from([0xff]) },
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
const result = encodeTLV8(items);
|
|
85
|
-
|
|
86
|
-
expect(result).to.deep.equal(
|
|
87
|
-
Buffer.from([0x00, 0x01, 0x00, 0x7f, 0x01, 0x7f, 0xff, 0x01, 0xff]),
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { PairingDataComponentType } from '../../../../src/lib/apple-tv/constants.js';
|
|
4
|
-
import { decodeTLV8ToDict } from '../../../../src/lib/apple-tv/tlv/decoder.js';
|
|
5
|
-
import {
|
|
6
|
-
createPairVerificationData,
|
|
7
|
-
createSetupManualPairingData,
|
|
8
|
-
} from '../../../../src/lib/apple-tv/tlv/pairing-tlv.js';
|
|
9
|
-
|
|
10
|
-
describe('Pairing TLV', function () {
|
|
11
|
-
describe('createSetupManualPairingData', function () {
|
|
12
|
-
it('should create valid base64-encoded TLV8 data', function () {
|
|
13
|
-
const result = createSetupManualPairingData();
|
|
14
|
-
|
|
15
|
-
expect(result).to.be.a('string');
|
|
16
|
-
expect(() => Buffer.from(result, 'base64')).to.not.throw();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should contain correct METHOD and STATE values', function () {
|
|
20
|
-
const result = createSetupManualPairingData();
|
|
21
|
-
const decoded = Buffer.from(result, 'base64');
|
|
22
|
-
const tlvDict = decodeTLV8ToDict(decoded);
|
|
23
|
-
|
|
24
|
-
expect(tlvDict[PairingDataComponentType.METHOD]).to.exist;
|
|
25
|
-
expect(tlvDict[PairingDataComponentType.METHOD]).to.deep.equal(
|
|
26
|
-
Buffer.from([0x00]),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
expect(tlvDict[PairingDataComponentType.STATE]).to.exist;
|
|
30
|
-
expect(tlvDict[PairingDataComponentType.STATE]).to.deep.equal(
|
|
31
|
-
Buffer.from([0x01]),
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should always return the same value', function () {
|
|
36
|
-
const result1 = createSetupManualPairingData();
|
|
37
|
-
const result2 = createSetupManualPairingData();
|
|
38
|
-
|
|
39
|
-
expect(result1).to.equal(result2);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('createPairVerificationData', function () {
|
|
44
|
-
it('should create valid base64-encoded TLV8 data with public key', function () {
|
|
45
|
-
const publicKey = Buffer.from([0x01, 0x02, 0x03, 0x04]);
|
|
46
|
-
const result = createPairVerificationData(publicKey);
|
|
47
|
-
|
|
48
|
-
expect(result).to.be.a('string');
|
|
49
|
-
expect(() => Buffer.from(result, 'base64')).to.not.throw();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should contain correct STATE and PUBLIC_KEY values', function () {
|
|
53
|
-
const publicKey = Buffer.from([0xaa, 0xbb, 0xcc, 0xdd]);
|
|
54
|
-
const result = createPairVerificationData(publicKey);
|
|
55
|
-
const decoded = Buffer.from(result, 'base64');
|
|
56
|
-
const tlvDict = decodeTLV8ToDict(decoded);
|
|
57
|
-
|
|
58
|
-
expect(tlvDict[PairingDataComponentType.STATE]).to.exist;
|
|
59
|
-
expect(tlvDict[PairingDataComponentType.STATE]).to.deep.equal(
|
|
60
|
-
Buffer.from([0x01]),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(tlvDict[PairingDataComponentType.PUBLIC_KEY]).to.exist;
|
|
64
|
-
expect(tlvDict[PairingDataComponentType.PUBLIC_KEY]).to.deep.equal(
|
|
65
|
-
publicKey,
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should handle typical X25519 public key (32 bytes)', function () {
|
|
70
|
-
const x25519PublicKey = Buffer.alloc(32, 0xef);
|
|
71
|
-
const result = createPairVerificationData(x25519PublicKey);
|
|
72
|
-
const decoded = Buffer.from(result, 'base64');
|
|
73
|
-
const tlvDict = decodeTLV8ToDict(decoded);
|
|
74
|
-
|
|
75
|
-
expect(tlvDict[PairingDataComponentType.PUBLIC_KEY]).to.deep.equal(
|
|
76
|
-
x25519PublicKey,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should handle large public key that requires fragmentation', function () {
|
|
81
|
-
const largeKey = Buffer.alloc(300, 0x42);
|
|
82
|
-
const result = createPairVerificationData(largeKey);
|
|
83
|
-
const decoded = Buffer.from(result, 'base64');
|
|
84
|
-
const tlvDict = decodeTLV8ToDict(decoded);
|
|
85
|
-
|
|
86
|
-
expect(tlvDict[PairingDataComponentType.PUBLIC_KEY]).to.deep.equal(
|
|
87
|
-
largeKey,
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should produce different results for different public keys', function () {
|
|
92
|
-
const key1 = Buffer.from([0x01, 0x02, 0x03]);
|
|
93
|
-
const key2 = Buffer.from([0x04, 0x05, 0x06]);
|
|
94
|
-
|
|
95
|
-
const result1 = createPairVerificationData(key1);
|
|
96
|
-
const result2 = createPairVerificationData(key2);
|
|
97
|
-
|
|
98
|
-
expect(result1).to.not.equal(result2);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { TLV8_MAX_FRAGMENT_SIZE } from '../../../../src/lib/apple-tv/constants.js';
|
|
4
|
-
import {
|
|
5
|
-
decodeTLV8,
|
|
6
|
-
decodeTLV8ToDict,
|
|
7
|
-
} from '../../../../src/lib/apple-tv/tlv/decoder.js';
|
|
8
|
-
import { encodeTLV8 } from '../../../../src/lib/apple-tv/tlv/encoder.js';
|
|
9
|
-
import type { TLV8Item } from '../../../../src/lib/apple-tv/types.js';
|
|
10
|
-
|
|
11
|
-
describe('TLV8 Integration Tests', function () {
|
|
12
|
-
describe('Round-trip encoding and decoding', function () {
|
|
13
|
-
it('should maintain data integrity for simple items', function () {
|
|
14
|
-
const originalItems: TLV8Item[] = [
|
|
15
|
-
{ type: 0x01, data: Buffer.from([0x42, 0x43, 0x44]) },
|
|
16
|
-
{ type: 0x02, data: Buffer.from([0x45, 0x46]) },
|
|
17
|
-
{ type: 0x03, data: Buffer.from([0x47]) },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
const encoded = encodeTLV8(originalItems);
|
|
21
|
-
const decoded = decodeTLV8(encoded);
|
|
22
|
-
|
|
23
|
-
expect(decoded).to.deep.equal(originalItems);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should handle fragmented data round-trip', function () {
|
|
27
|
-
const largeData = Buffer.alloc(512);
|
|
28
|
-
for (let i = 0; i < 512; i++) {
|
|
29
|
-
largeData[i] = i % 256;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const originalItems: TLV8Item[] = [{ type: 0x05, data: largeData }];
|
|
33
|
-
|
|
34
|
-
const encoded = encodeTLV8(originalItems);
|
|
35
|
-
const decoded = decodeTLV8(encoded);
|
|
36
|
-
|
|
37
|
-
expect(decoded).to.have.lengthOf(3);
|
|
38
|
-
expect(decoded[0].type).to.equal(0x05);
|
|
39
|
-
expect(decoded[1].type).to.equal(0x05);
|
|
40
|
-
expect(decoded[2].type).to.equal(0x05);
|
|
41
|
-
|
|
42
|
-
const reassembled = Buffer.concat(decoded.map((item) => item.data));
|
|
43
|
-
expect(reassembled).to.deep.equal(largeData);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should handle mixed fragmented and non-fragmented items', function () {
|
|
47
|
-
const smallData = Buffer.from([0xaa, 0xbb]);
|
|
48
|
-
const largeData = Buffer.alloc(300, 0xcc);
|
|
49
|
-
const mediumData = Buffer.alloc(100, 0xdd);
|
|
50
|
-
|
|
51
|
-
const originalItems: TLV8Item[] = [
|
|
52
|
-
{ type: 0x01, data: smallData },
|
|
53
|
-
{ type: 0x02, data: largeData },
|
|
54
|
-
{ type: 0x03, data: mediumData },
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const encoded = encodeTLV8(originalItems);
|
|
58
|
-
const decoded = decodeTLV8(encoded);
|
|
59
|
-
|
|
60
|
-
expect(decoded).to.have.lengthOf(4);
|
|
61
|
-
|
|
62
|
-
expect(decoded[0]).to.deep.equal({ type: 0x01, data: smallData });
|
|
63
|
-
|
|
64
|
-
expect(decoded[1].type).to.equal(0x02);
|
|
65
|
-
expect(decoded[1].data.length).to.equal(255);
|
|
66
|
-
expect(decoded[2].type).to.equal(0x02);
|
|
67
|
-
expect(decoded[2].data.length).to.equal(45);
|
|
68
|
-
|
|
69
|
-
expect(decoded[3]).to.deep.equal({ type: 0x03, data: mediumData });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('Round-trip with decodeTLV8ToDict', function () {
|
|
74
|
-
it('should correctly reassemble fragmented data in dictionary', function () {
|
|
75
|
-
const largeData = Buffer.alloc(512, 0xee);
|
|
76
|
-
const originalItems: TLV8Item[] = [{ type: 0x10, data: largeData }];
|
|
77
|
-
|
|
78
|
-
const encoded = encodeTLV8(originalItems);
|
|
79
|
-
const decodedDict = decodeTLV8ToDict(encoded);
|
|
80
|
-
|
|
81
|
-
expect(decodedDict[0x10]).to.deep.equal(largeData);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should handle multiple types with fragmentation', function () {
|
|
85
|
-
const data1 = Buffer.alloc(300, 0x11);
|
|
86
|
-
const data2 = Buffer.alloc(50, 0x22);
|
|
87
|
-
const data3 = Buffer.alloc(400, 0x33);
|
|
88
|
-
|
|
89
|
-
const originalItems: TLV8Item[] = [
|
|
90
|
-
{ type: 0x01, data: data1 },
|
|
91
|
-
{ type: 0x02, data: data2 },
|
|
92
|
-
{ type: 0x03, data: data3 },
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
const encoded = encodeTLV8(originalItems);
|
|
96
|
-
const decodedDict = decodeTLV8ToDict(encoded);
|
|
97
|
-
|
|
98
|
-
expect(decodedDict[0x01]).to.deep.equal(data1);
|
|
99
|
-
expect(decodedDict[0x02]).to.deep.equal(data2);
|
|
100
|
-
expect(decodedDict[0x03]).to.deep.equal(data3);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('Edge cases', function () {
|
|
105
|
-
it('should handle maximum size data at boundary', function () {
|
|
106
|
-
const boundaryData = Buffer.alloc(TLV8_MAX_FRAGMENT_SIZE);
|
|
107
|
-
for (let i = 0; i < TLV8_MAX_FRAGMENT_SIZE; i++) {
|
|
108
|
-
boundaryData[i] = i % 256;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const items: TLV8Item[] = [{ type: 0x42, data: boundaryData }];
|
|
112
|
-
|
|
113
|
-
const encoded = encodeTLV8(items);
|
|
114
|
-
const decoded = decodeTLV8(encoded);
|
|
115
|
-
|
|
116
|
-
expect(decoded).to.have.lengthOf(1);
|
|
117
|
-
expect(decoded[0]).to.deep.equal(items[0]);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should handle empty items array', function () {
|
|
121
|
-
const items: TLV8Item[] = [];
|
|
122
|
-
|
|
123
|
-
const encoded = encodeTLV8(items);
|
|
124
|
-
const decoded = decodeTLV8(encoded);
|
|
125
|
-
const decodedDict = decodeTLV8ToDict(encoded);
|
|
126
|
-
|
|
127
|
-
expect(encoded).to.deep.equal(Buffer.alloc(0));
|
|
128
|
-
expect(decoded).to.deep.equal([]);
|
|
129
|
-
expect(decodedDict).to.deep.equal({});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should preserve exact byte sequences through round-trip', function () {
|
|
133
|
-
const problematicData = Buffer.from([
|
|
134
|
-
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0x02, 0x03, 0x00, 0xff, 0x00,
|
|
135
|
-
0xff,
|
|
136
|
-
]);
|
|
137
|
-
|
|
138
|
-
const items: TLV8Item[] = [{ type: 0x77, data: problematicData }];
|
|
139
|
-
|
|
140
|
-
const encoded = encodeTLV8(items);
|
|
141
|
-
const decoded = decodeTLV8(encoded);
|
|
142
|
-
|
|
143
|
-
expect(decoded[0].data).to.deep.equal(problematicData);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|