Fix assembly definition public key token computation#312
Open
jmbryan4 wants to merge 1 commit intorichlander:mainfrom
Open
Fix assembly definition public key token computation#312jmbryan4 wants to merge 1 commit intorichlander:mainfrom
jmbryan4 wants to merge 1 commit intorichlander:mainfrom
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
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