Skip to content

Conversation

@c3rebro
Copy link
Owner

@c3rebro c3rebro commented Dec 29, 2025

Motivation

  • The DESFire access-rights packing used by the library did not follow the datasheet nibble order and produced incorrect permission words on cards.
  • The datasheet requires nibble order: Read (bits 15–12), Write (11–8), Read&Write (7–4), Change (3–0).
  • The change corrects the packing/unpacking to match the spec and prevents producing reversed access-rights words.
  • This is a breaking change for consumers that previously compensated for the reversed order.

Description

  • Added ToAccessRightsWord() and FromAccessRightsWord(ushort) on DESFireFileAccessRights to pack/unpack using the datasheet nibble order.
  • Replaced ad-hoc manual bit packing/unpacking in TWN4ReaderDevice.MifareDesfire.cs with the new helper methods (used for create/change/unpack of file access rights).
  • Added unit tests tests/Elatec.NET.Tests/AccessRightsTests.cs to assert correct pack/unpack behavior.
  • Kept public property names (ReadKeyNo, WriteKeyNo, ReadWriteKeyNo, ChangeKeyNo) unchanged for minimal surface-area impact, but behavior of packing is now spec-compliant.

Testing

  • Ran dotnet test tests/Elatec.NET.Tests/Elatec.NET.Tests.csproj and the test run completed successfully.
  • All tests passed: Passed! - Failed: 0, Passed: 23, Skipped: 0, Total: 23.
  • Project builds during the test run with no test failures.
  • New tests cover ToAccessRightsWord and FromAccessRightsWord packing/unpacking behavior.

Codex Task

@c3rebro c3rebro merged commit aaafc68 into master Dec 29, 2025
1 of 2 checks passed
@c3rebro c3rebro deleted the fix-access-rights-packing-order branch December 29, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants