Files
michaelschiemer/tests/debug/test-reed-solomon-validation.php
Michael Schiemer 95147ff23e refactor(deployment): Remove WireGuard VPN dependency and restore public service access
Remove WireGuard integration from production deployment to simplify infrastructure:
- Remove docker-compose-direct-access.yml (VPN-bound services)
- Remove VPN-only middlewares from Grafana, Prometheus, Portainer
- Remove WireGuard middleware definitions from Traefik
- Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers

All monitoring services now publicly accessible via subdomains:
- grafana.michaelschiemer.de (with Grafana native auth)
- prometheus.michaelschiemer.de (with Basic Auth)
- portainer.michaelschiemer.de (with Portainer native auth)

All services use Let's Encrypt SSL certificates via Traefik.
2025-11-05 12:48:25 +01:00

106 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder;
use App\Framework\QrCode\QrCodeGenerator;
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
use App\Framework\QrCode\ValueObjects\EncodingMode;
echo "=== Reed-Solomon Validation Test ===\n\n";
// Test with known data
$testData = 'HELLO WORLD';
$config = new QrCodeConfig(
version: QrCodeVersion::fromNumber(1),
errorCorrectionLevel: ErrorCorrectionLevel::M,
encodingMode: EncodingMode::BYTE
);
// Get data codewords
$generator = new \App\Framework\QrCode\QrCodeGenerator(new \App\Framework\QrCode\QrCodeRenderer());
$reflection = new \ReflectionClass($generator);
$encodeMethod = $reflection->getMethod('encodeData');
$encodeMethod->setAccessible(true);
$dataCodewords = $encodeMethod->invoke($generator, $testData, $config);
echo "Data codewords (" . count($dataCodewords) . "):\n";
echo implode(', ', $dataCodewords) . "\n\n";
// Generate EC codewords
$reedSolomon = new ReedSolomonEncoder();
$ecInfo = ReedSolomonEncoder::getECInfo(1, 'M');
$ecCodewords = $reedSolomon->encode($dataCodewords, $ecInfo['ecCodewords']);
echo "EC codewords (" . count($ecCodewords) . "):\n";
echo implode(', ', $ecCodewords) . "\n\n";
// Known reference for "HELLO WORLD" Version 1 Level M:
// Data codewords: 64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233
// EC codewords should be calculated from these
echo "=== Validation ===\n";
echo "Expected data codewords (16):\n";
echo "64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233\n\n";
$expectedData = [64, 180, 132, 84, 196, 196, 242, 5, 116, 245, 174, 59, 64, 109, 236, 233];
$matches = 0;
for ($i = 0; $i < min(count($dataCodewords), count($expectedData)); $i++) {
if ($dataCodewords[$i] === $expectedData[$i]) {
$matches++;
} else {
echo "❌ Data codeword {$i}: got {$dataCodewords[$i]}, expected {$expectedData[$i]}\n";
}
}
if ($matches === count($expectedData)) {
echo "✅ All data codewords match reference!\n\n";
} else {
echo "{$matches}/" . count($expectedData) . " data codewords match\n\n";
}
// Test Reed-Solomon encoding
// For Version 1, Level M: 16 data codewords, 10 EC codewords
// Using known generator polynomial for 10 EC codewords
echo "=== Reed-Solomon Generator Polynomial Test ===\n";
// Test GF multiplication
$gf = new ReedSolomonEncoder();
$reflectionRS = new \ReflectionClass($gf);
$gfMultiplyMethod = $reflectionRS->getMethod('gfMultiply');
$gfMultiplyMethod->setAccessible(true);
// Test some known GF multiplications
$testCases = [
[1, 2, 2], // 1 * 2 = 2
[2, 3, 6], // 2 * 3 = 6
[87, 1, 87], // Generator polynomial coefficient
];
echo "Testing GF multiplication:\n";
foreach ($testCases as [$a, $b, $expected]) {
$result = $gfMultiplyMethod->invoke($gf, $a, $b);
$match = $result === $expected ? '✅' : '❌';
echo " {$a} * {$b} = {$result} (expected: {$expected}) {$match}\n";
}
echo "\n=== EC Codeword Verification ===\n";
echo "EC codewords generated: " . count($ecCodewords) . " (expected: 10)\n";
if (count($ecCodewords) === 10) {
echo "✅ EC codeword count is correct\n";
} else {
echo "❌ EC codeword count is wrong!\n";
}
// Verify EC codewords by checking if they can correct errors
// This is a simplified check - full verification would require decoding
echo "\nNote: Full EC verification requires decoding with error injection.\n";
echo "If EC codewords are wrong, the QR code won't be scannable even if data is correct.\n";