On this page· 6
Check a pack with standard tools
- file format 6
- Rust SDK 1.0 preview
Five standard commands, and no PLXI software, rebuild the 544-byte quickstart pack, measure it, read its header line, recompute its digest and read the first bytes of its footer.
A shell with xxd, and head, tail, wc and sha256sum from GNU coreutils. Tested on Linux.
head -c -96 prints all but the last 96 bytes of its input. Negative counts are a GNU coreutils option.
1. Save the listing below as a file named
sample.hex. It is the pack written as hexadecimal text, 30 bytes to a line.sample.hextext504c5849207636207265636f7264733d3320637364745f6f66667365743d 3020637364745f73697a653d30207368613235363d303638663136316533 333764613462326230633331396133353339623963363266346231353731 356430663363346465386531363634653565663636626232382020202020 202020202020202020202020202020202020202020202020202020202020 202020202020202020202020202020202020202020202020202020202020 202020202020202020202020202020202020202020202020202020202020 202020202020202020202020202020202020202020202020202020202020 202020202020202020202020202020200a7b226b223a22656e74222c2276 223a312c226964223a226531222c2274223a22506572736f6e222c226e61 6d65223a22416461222c2273616c69656e6365223a302e352c2273747562 223a66616c73657d0a7b226b223a22656e74222c2276223a312c22696422 3a226532222c2274223a22506572736f6e222c2273747562223a66616c73 657d0a7b226b223a2272656c222c2276223a312c22737263223a22653122 2c22746774223a226532222c226b696e64223a226b6e6f7773227d0a504c 5846060000000300000000000000c0010000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 0000068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5 ef66bb2819 lines, 544 bytes.
2. Turn the listing back into bytes with
xxd -r -p sample.hex sample.plxi. Thenwc -c < sample.plxiprints544.The pack is 544 bytes: a 257-byte header line, 191 bytes of records, and a 96-byte footer. Spec §2
3. Read the header line with
head -c 257 sample.plxi.PLXI v6 records=3 csdt_offset=0 csdt_size=0 sha256=068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5ef66bb28The header line is the first 257 bytes: six tokens separated by single spaces, spaces up to byte 256, then a line feed.
v6is the file format version.records=3is the number of records.csdt_offset=0andcsdt_size=0mean the pack has no appendix. The digest followssha256=as 64 hexadecimal digits. Spec §34. Recompute the digest with
tail -c +258 sample.plxi | head -c -96 | sha256sum.068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5ef66bb28 -tail -c +258starts at byte 258 counting from 1, which is offset 257 counting from 0: the first byte after the header line.head -c -96drops the footer. What is left is exactly the span the digest covers. Spec §6The value printed equals the value after
sha256=in the header line. The same 32 bytes are stored, in binary, as the last 32 bytes of the footer. Spec §10.05. Read the footer's first four bytes with
tail -c 96 sample.plxi | head -c 4. They are the ASCII textPLXF.
Changing the first Person in the records to person changes one byte inside the covered span. Step 4 then prints a79241b4…37377 instead of 068f161e…bb28, and no longer matches the header line or the footer.
A PLXI reader refuses such a file with the error kind checksum_mismatch.
They check the digest and nothing else. A PLXI reader also checks the header line against the footer, the layout of the file, every record line, and the record count. Verify
The digest shows that bytes changed. It does not show who wrote the pack. Integrity
xxd -r -p sample.hex sample.plxi
wc -c < sample.plxi
head -c 257 sample.plxi
tail -c +258 sample.plxi | head -c -96 | sha256sum
tail -c 96 sample.plxi | head -c 4; echo
544
PLXI v6 records=3 csdt_offset=0 csdt_size=0 sha256=068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5ef66bb28
068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5ef66bb28 -
PLXFRan with bash check-a-pack.sh · exit status 0