invertedtomato / crc

A flexible CRC implementation supporting most major algorithms. Also includes ability to support custom implementations.
MIT License
29 stars 10 forks source link

Assembly is not strong-named #8

Closed maettu-this closed 1 year ago

maettu-this commented 1 year ago

Hi Ben,

In order to include InvertedTomato.Crc into libraries or applications that use strong-names, InvertedTomato.Crc must be signed with a strong name. Please refer to https://learn.microsoft.com/en-us/dotnet/standard/assembly/create-use-strong-named and https://github.com/dotnet/runtime/blob/main/docs/project/strong-name-signing.md.

Because of the viral nature of strong-naming, it is recommended that publicly published .NET libraries are strong-named. Not strong-naming a .NET library excludes anyone who does need to strong-name their application or library from using it.

Best regards, Matthias

maettu-this commented 1 year ago

Exception message if not strongly-named:

grafik

invertedtomato commented 1 year ago

Strong'd now

maettu-this commented 1 year ago

Funny issue, my VS2022 project can deal with the signature, but NUnit (still using 2.x) fails with something like:

System.IO.FileLoadException: The file or assembly "InvertedTomato.Crc, Version=1.3.4.0, Culture=neutral, PublicKeyToken=0329a176645587db" or a dependency cannot be loaded. The strong name signature cannot be verified.

(best-effort translated from German error message)

Root cause

Your project now uses a 2048-bit key. In case of my computer, sn -k generates 1024-bit keys. When I compile the library with such key, NUnit works just fine. Googling revealed:

If you do not specify a key size, a 1,024-bit key is generated by default if you have the Microsoft enhanced cryptographic provider installed; otherwise, a 512-bit key is generated.

(https://learn.microsoft.com/en-us/dotnet/framework/tools/sn-exe-strong-name-tool)

Potential solution

Could you specify sn -k 1024 for creating the key? Guess it's no big deal to use such basic key. Other libraries, e.g. OxyPlot and IPNetwork also just use a 1024-bit key.

A 1024-bit key file has a size of 596 bytes, whereas your 2048-bit key file is 1.14 KB in size.

invertedtomato commented 1 year ago

Sounds like your tooling needs to be updated. Maybe NUnit? Downgrading things this end doesn't seem like the correct approach

maettu-this commented 1 year ago

Well... sure, the upgrade of NUnit already is scheduled at my end. But you for sure are aware that tackling backlog needs time.

But... if Microsoft states "a 1,024-bit key is generated by default" and the stated libraries apparently follow this, I don't really see why not following this.

invertedtomato commented 1 year ago

Rider appears to generate a 2048bit key by default. Feel free to raise a PR to drop this to 1024 if you like. As it's open-source software it's basically meaningless, so I'm happy if you're keen to do the (albeit minor) effort!

maettu-this commented 1 year ago

14 just created as this indeed bothers momentarily.

maettu-this commented 5 months ago

@invertedtomato just for your information, in case somebody else runs into the very same issue, even recent versions of NUnit cannot cope with InvertedTomato.Crc. The length of the key actually wasn't the only cause of the issue, the use of PublicSign is another. I have raised the NUnit issue 4681 NUnit doesn't seem to be able to deal with PublicSign to eventually get this fixed.