Skip to content

v0.18.0: Implementation of generic newtypes#615

Merged
brycx merged 2 commits intov0.18.0from
generic-newtypes
Apr 25, 2026
Merged

v0.18.0: Implementation of generic newtypes#615
brycx merged 2 commits intov0.18.0from
generic-newtypes

Conversation

@brycx
Copy link
Copy Markdown
Member

@brycx brycx commented Apr 25, 2026

closes #249 #274

First and by far the largest set of breaking changes for version 0.18.0. A re-design of the newtypes used across the library has been a long time coming, at least since #249 and work started in #274. The work behind this new interface has largely been done by @vlmutolo in #274 and this PR uses the same interface, with a few tweaks.

The new interface includes:

  • Generalized structs Public<T: TypeSpec> and Secret<T: TypeSpec> where the public trait TypeSpec is implemented for zero-sized structs to contextualize the uses across different primitives/schemes.
  • Public<T> and Secret<T> can additionally implement GenerateSecret/GeneratePublic to indicate that either one can be generated using a CSPRNG, within a given context. A major change here is also that all randomness-generation has become fallible. There is no Default that panics and there is no generate() that panics. This has been motivated by an effort to use it without hiding possible panic!()s and making auditing hereof easier.

The generalized approach offers much more flexibility for current and future types to be added. A good example is that the previous newtypes weren't usable to ML-KEM encapsulation/decapsulation keys due to additional checking requirements, etc. This generalized approach has allowed us to implement it for these as well. The result is also a more consistent API experience across different parts of the library.

Finally, removing the use of macros has reduced code-expansion from this, amount of duplicate tests being run (for newtypes having the same underlying primitive/sizes, etc.).

The amount of changes here justify a new "Discussion" for v0.18.0 that includes a migration guide.

@brycx brycx added usability Issues or improvements related to UX breaking change A breaking change labels Apr 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 99.23208% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.24%. Comparing base (a5c3085) to head (f7630bd).

Files with missing lines Patch % Lines
src/hazardous/kem/ml_kem/internal/mod.rs 96.37% 10 Missing ⚠️
src/high_level/pwhash.rs 92.85% 3 Missing ⚠️
tests/stream/mod.rs 50.00% 3 Missing ⚠️
src/hazardous/kem/ml_kem/mlkem1024.rs 98.59% 2 Missing ⚠️
src/hazardous/kem/ml_kem/mlkem512.rs 98.59% 2 Missing ⚠️
src/hazardous/kem/ml_kem/mlkem768.rs 98.59% 2 Missing ⚠️
src/hazardous/kem/xwing.rs 99.17% 2 Missing ⚠️
src/generics/data.rs 99.43% 1 Missing ⚠️
src/hazardous/aead/streaming.rs 98.41% 1 Missing ⚠️
src/hazardous/kem/x25519_hkdf_sha256.rs 97.36% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           v0.18.0     #615      +/-   ##
===========================================
+ Coverage    99.14%   99.24%   +0.09%     
===========================================
  Files          108      113       +5     
  Lines        19957    21243    +1286     
===========================================
+ Hits         19787    21082    +1295     
+ Misses         170      161       -9     

☔ View full report in Codecov by Sentry.
📢 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.

@brycx brycx merged commit aea4a0b into v0.18.0 Apr 25, 2026
29 checks passed
@brycx brycx deleted the generic-newtypes branch April 25, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change A breaking change usability Issues or improvements related to UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant