Fix assembly definition public key token computation#312
Merged
richlander merged 2 commits intorichlander:mainfrom May 4, 2026
Merged
Conversation
89ec99c to
9e3d904
Compare
assemblyDef.PublicKey holds the full RSA public key (~160 bytes). The PKT is derived by SHA-1 hashing it, taking the last 8 bytes of the hash, and reversing them (ECMA-335 §6.2.1.3). The previous code took the last 8 raw bytes of the key itself, producing a wrong value for every strong-named assembly. Adds a regression test that verifies the computed PKT matches the ground truth from AssemblyName.GetPublicKeyToken(). Fixes richlander#311
9e3d904 to
0aa467d
Compare
… SDK regression
Direct stdout-to-file redirection ('cmd > file.md') truncates the AOT
binary's output to ~256 bytes on the .NET 11 preview 3 SDK
(11.0.100-preview.3.26207.106) currently used by GitHub-hosted runners.
Piping through 'cat' keeps the output complete.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
|
Thanks @jmbryan4 — the PKT computation fix is correct (SHA-1 → last 8 → reverse, per ECMA-335 §6.2.1.3) and the regression test against The Once CI re-runs (it's currently |
richlander
approved these changes
May 4, 2026
3 tasks
Owner
|
Change is in 0.7.8. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #311.
What
assemblyDef.PublicKeyholds the full RSA public key (~160 bytes). The correct PKT derivation (ECMA-335 §6.2.1.3) is:The previous code took the last 8 raw bytes of the key itself, producing a wrong value for every strong-named assembly.
Verification
The correct PKT can be independently verified at nuget.info — the
publicKeyTokenshown there matches the fix's output, not the old output.cc7b13ffcd2ddd511d05d9bed22b38cb7cec85d7bea7798e85b4305c123b37abb03f5f7f11d50a3a6dc093344d5ad293adb9793829ddae6007891c9d872ad2bbChanges
src/DotnetInspector.Metadata/AssemblyInspector.cs— apply correct SHA-1 + reverse algorithmtests/DotnetInspector.Metadata.Tests/AssemblyInspectorTests.cs— regression test comparing againstAssemblyName.GetPublicKeyToken()scripts/baseline.txt,docs/lap-around.md— update expected PKT values for System.Text.Json