A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory

update verification

+35 -5
+35 -5
bundle/manager.go
··· 619 619 return result, nil 620 620 } 621 621 622 - // Verify hash 623 - valid, actualHash, err := m.operations.VerifyHash(path, meta.CompressedHash) 622 + // Verify BOTH compressed and content hashes 623 + compHash, compSize, contentHash, contentSize, err := m.operations.CalculateFileHashes(path) 624 624 if err != nil { 625 625 result.Error = err 626 626 return result, nil 627 627 } 628 628 629 - result.LocalHash = actualHash 630 - result.HashMatch = valid 631 - result.Valid = valid 629 + result.LocalHash = compHash 630 + 631 + // Verify compressed hash 632 + if compHash != meta.CompressedHash { 633 + result.HashMatch = false 634 + result.Valid = false 635 + result.Error = fmt.Errorf("compressed hash mismatch: expected %s, got %s", meta.CompressedHash, compHash) 636 + return result, nil 637 + } 638 + 639 + // Verify content hash 640 + if contentHash != meta.ContentHash { 641 + result.HashMatch = false 642 + result.Valid = false 643 + result.Error = fmt.Errorf("content hash mismatch: expected %s, got %s", meta.ContentHash, contentHash) 644 + return result, nil 645 + } 646 + 647 + // Verify sizes match 648 + if compSize != meta.CompressedSize { 649 + result.Valid = false 650 + result.Error = fmt.Errorf("compressed size mismatch: expected %d, got %d", meta.CompressedSize, compSize) 651 + return result, nil 652 + } 653 + 654 + if contentSize != meta.UncompressedSize { 655 + result.Valid = false 656 + result.Error = fmt.Errorf("uncompressed size mismatch: expected %d, got %d", meta.UncompressedSize, contentSize) 657 + return result, nil 658 + } 659 + 660 + result.HashMatch = true 661 + result.Valid = true 632 662 633 663 return result, nil 634 664 }