fix(qr): Revert to original 12-byte Amnezia header format
The working QR format from Amnezia app uses: - 12-byte header: version (0x07C00100) + compressedLen + uncompressedLen - zlib compressed JSON data Previously I incorrectly changed this to Qt qCompress format (4-byte header). This commit reverts to the correct Amnezia-compatible format.
This commit is contained in:
+5
-4
@@ -63,15 +63,16 @@ class QrUtil
|
|||||||
public static function encodeOldPayloadFromJson(string $jsonText): string
|
public static function encodeOldPayloadFromJson(string $jsonText): string
|
||||||
{
|
{
|
||||||
$json = self::normalizeJson($jsonText);
|
$json = self::normalizeJson($jsonText);
|
||||||
// Qt qCompress format: 4-byte big-endian uncompressed length + zlib compressed data
|
// Amnezia format: 12-byte header [version, compressed_len, uncompressed_len] + zlib compressed data
|
||||||
// This is what Amnezia Android's qUncompress expects
|
// Version 0x07C00100 is required for compatibility with Amnezia apps
|
||||||
$compressed = gzcompress($json, 9);
|
$compressed = gzcompress($json, 9);
|
||||||
if ($compressed === false) {
|
if ($compressed === false) {
|
||||||
throw new RuntimeException('gzcompress failed');
|
throw new RuntimeException('gzcompress failed');
|
||||||
}
|
}
|
||||||
$uncompressedLen = strlen($json);
|
$uncompressedLen = strlen($json);
|
||||||
// Qt format: 4 bytes of uncompressed length (big-endian) + zlib data
|
$compressedLen = strlen($compressed) + 4; // +4 for the uncompressed length field
|
||||||
$header = pack('N', $uncompressedLen);
|
$version = 0x07C00100; // Amnezia magic version number
|
||||||
|
$header = pack('N3', $version, $compressedLen, $uncompressedLen);
|
||||||
return self::urlsafe_b64_encode($header . $compressed);
|
return self::urlsafe_b64_encode($header . $compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user