Skip to content

feat: add .NET Framework 4.8 (net48) support#182

Open
daviddesmet wants to merge 2 commits into
masterfrom
feat/net48
Open

feat: add .NET Framework 4.8 (net48) support#182
daviddesmet wants to merge 2 commits into
masterfrom
feat/net48

Conversation

@daviddesmet

Copy link
Copy Markdown
Owner

What

Re-adds net48 as a target framework for Paseto.Core (now net48;net8.0;net10.0), so the library can be consumed from legacy .NET Framework 4.8 apps. Closes #.

Why

A user asked whether net48 could be supported. It can — net48 was targeted before and dropped around 78ee106. Both crypto dependencies (NaCl.Core, BouncyCastle.Cryptography) support netstandard2.0, so they run on net48.

How

Six BCL crypto/encoding APIs used by the library don't exist on net48 and are reimplemented behind #if NETFRAMEWORK, backed by BouncyCastle (already a dependency):

Modern API net48 replacement
HKDF.DeriveKey HkdfBytesGenerator (Internal/Hkdf.cs)
Rfc2898DeriveBytes.Pbkdf2 Pkcs5S2ParametersGenerator (Internal/Pbkdf2.cs)
RandomNumberGenerator.Fill/GetBytes RandomNumberGenerator.Create() (Internal/Rng.cs)
CryptographicOperations.FixedTimeEquals constant-time bit-diff loop (Internal/CryptoBytes.cs)
CryptographicOperations.ZeroMemory Array.Clear under [NoInlining|NoOptimization]
RSA.ExportRSAPrivateKey/PublicKey BouncyCastle PKCS#1 export (Protocol/Version1.cs)

Plus compiler/BCL polyfills for net48: IsExternalInit (init setters), RuntimeHelpers.GetSubArray (array range slicing), NotNullAttribute, Guard.NotNull, and span/HashData fallbacks in Base64UrlEncoder, EncodingHelper, and PaserkSeal.

net48-only packages: System.Memory, IndexRange, System.Text.Json, and Microsoft.NETFramework.ReferenceAssemblies (lets net48 compile on Linux/macOS CI runners). The test project also multi-targets net48 (ReadKey PEM handling rewritten with BouncyCastle), and build.cake runs the net48 test suite on the Windows runner — the runtime security gate.

Verification

  • ✅ net8 suite: 521/521 pass — refactor is regression-free
  • ✅ Source + tests build across all three TFMs in Release
  • ✅ Every net48 crypto shim proven byte-identical to the BCL API it replaces (HKDF-SHA384, PBKDF2-SHA384, constant-time equals, GetSubArray, RSA PKCS#1 keygen/export, and ReadKey for EC / RSA-private / RSA-public, checked against the real PASETO test-vector PEMs)
  • ⚠️ net48 tests execute only on Windows (no .NET Framework runtime on Linux/macOS); the CI Windows runner is the gate. Byte-equivalence was verified locally to de-risk that run

Closes #99

@daviddesmet daviddesmet self-assigned this Jul 5, 2026
@daviddesmet daviddesmet added enhancement New feature or request patch Requiring a patch version update according to semantic versioning .NET Pull requests that update .NET code labels Jul 5, 2026
@daviddesmet

Copy link
Copy Markdown
Owner Author

⚠️ Need to test on Windows before merging.

@daviddesmet

daviddesmet commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

Dropped xunit.categories, swapped the 2 [Category("CI")] → built-in [Trait("Category", "CI")], removed the stale NoWarn, regenerated the lock file.

Cause: Paseto.Tests is strong-named (InternalsVisibleTo public key), but xunit.categories isn't strong-named → net48's AppDomain discovery refuses to load it

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.81%. Comparing base (176d8b1) to head (5fff226).

Files with missing lines Patch % Lines
src/Paseto/Internal/CryptoBytes.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #182      +/-   ##
==========================================
- Coverage   90.82%   90.81%   -0.01%     
==========================================
  Files         108      112       +4     
  Lines        5580     5588       +8     
  Branches      363      363              
==========================================
+ Hits         5068     5075       +7     
- Misses        512      513       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request .NET Pull requests that update .NET code patch Requiring a patch version update according to semantic versioning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find PasetoBuilder in 0.7.2

1 participant