Skip to content

Add C# / .NET implementation of PCF (Partitioned Container Format)#1

Merged
kduma merged 1 commit into
masterfrom
claude/practical-curie-rVFhG
Jun 2, 2026
Merged

Add C# / .NET implementation of PCF (Partitioned Container Format)#1
kduma merged 1 commit into
masterfrom
claude/practical-curie-rVFhG

Conversation

@kduma

@kduma kduma commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This PR adds a complete C# / .NET implementation of PCF v1.0, the first port of the Rust reference implementation. The implementation is fully spec-compliant and verified against the canonical 395-byte test vector from the specification.

Summary

Implements a production-ready PCF reader/writer library for .NET, targeting netstandard2.0 for broad compatibility. The implementation prioritizes auditability and spec compliance over performance, mirroring the design philosophy of the reference implementation.

Key Changes

  • Core Container API (Container.cs): Full read/write support with Create(), Open(), AddPartition(), UpdatePartitionData(), RemovePartition(), and Verify() operations. Implements the documented placement strategy with reserved capacity in the first block and overflow-block chaining for additional partitions.

  • Data Structures:

    • FileHeader.cs: 20-byte file header with magic validation and version checking
    • TableBlockHeader.cs: 74-byte table-block header with partition count and chaining
    • PartitionEntry.cs: 141-byte partition metadata with label encoding/decoding
    • HashAlgo.cs: Registry of 9 hash algorithms (CRC-32/32C/64, MD5, SHA-1/256/512, BLAKE3)
  • Hash Implementations:

    • Crc.cs: Self-contained reflected-CRC routines for all three CRC variants with canonical test vectors
    • Integration with System.Security.Cryptography for SHA and MD5
    • BLAKE3 support via NuGet package
  • Utility Classes:

    • LittleEndian.cs: Explicit little-endian integer encoding (spec section 2.3)
    • Constants.cs: All normative on-disk constants from spec Appendix A
    • PcfError.cs / PcfException.cs: Comprehensive error handling mirroring reference implementation
  • Comprehensive Test Suite:

    • SpecComplianceTests.cs: 40+ tests covering every normative MUST/SHALL in the specification, organized by section
    • RoundtripTests.cs: End-to-end black-box tests for create/read/update/remove/verify workflows
    • CoverageTests.cs: Error paths, algorithm variants, and edge cases
    • TestSupport.cs: Canonical 395-byte test vector from spec section 15
  • Project Configuration:

    • Solution file with src/tests organization
    • .NET 8.0 test project with xUnit
    • CI/CD workflow for ubuntu/macos/windows
    • Comprehensive .gitignore

Notable Implementation Details

  • Block Capacity Tracking: In-memory BlockInfo class tracks reserved capacity per block; after Open(), blocks are treated as having no spare capacity, forcing new additions into overflow blocks. CompactedImage() rebuilds tightly packed files.

  • Hash Field Encoding: Implements spec section 8.2 exactly—digests left-aligned and zero-padded to 64 bytes; CRC values stored as little-endian integers.

  • Overflow Chain: Supports arbitrary numbers of partitions (tested with 300+) via singly-linked table blocks, with automatic linking when blocks fill.

  • Spec Compliance: Validates all conformance checks (C1–C7) on read; rejects reserved type 0, nil UIDs, and invalid labels; verifies both table-block and partition-data hashes.

  • Cross-platform: Targets netstandard2.0 for .NET Framework 4.6.1+ and .NET Core 2.0+ compatibility.

https://claude.ai/code/session_01VVZyLAq1H1PKSFbDjTW7pa

A faithful port of the Rust reference implementation under
implementations/dotnet/, verified byte-for-byte against the spec's
canonical 395-byte test vector (section 15).

- Library (src/Pcf, netstandard2.0): Container reader/writer plus
  Constants, FileHeader, PartitionEntry, TableBlockHeader, the hash
  registry (SHA-1/2, MD5 via BCL; CRC-32/32C/64 self-contained;
  BLAKE3 via the Blake3 package), and PcfException error reporting.
- xUnit tests (tests/Pcf.Tests, net8.0): spec-compliance, roundtrip
  and coverage suites (71 tests), including the exact 395-byte vector.
- GitHub Actions workflow building and testing on Linux/macOS/Windows.
@kduma kduma merged commit a4ff6df into master Jun 2, 2026
10 checks passed
@kduma kduma deleted the claude/practical-curie-rVFhG branch June 2, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants