Skip to content

kem: make Encapsulate fully infallible#2235

Merged
tarcieri merged 1 commit intomasterfrom
kem/make-encapsulate-infallible
Jan 24, 2026
Merged

kem: make Encapsulate fully infallible#2235
tarcieri merged 1 commit intomasterfrom
kem/make-encapsulate-infallible

Conversation

@tarcieri
Copy link
Member

Switches from TryCryptoRng back to CryptoRng for encapsulate_with_rng.

We originally switched to #2049 with the rationale that the whole trait was fallible anyway, so we might as well handle the RNG errors. But then in #2216 we made the rest of the trait infallible, only using fallibility for the RNG.

Decapsulate is also now fully infallible, but for cases where we need to handle errors there's a TryDecapsulate trait. Prospectively we could do the same thing here, and have a fallible TryEncapsulate trait that uses TryCryptoRng and handles RNG errors. This PR doesn't attempt to add one because it has some trait design issues around how we convert RNG errors into KEM-specific error types.

Closes #2214 (and see also that issue for the problems around error type conversions)

Switches from `TryCryptoRng` back to `CryptoRng` for
`encapsulate_with_rng`.

We originally switched to #2049 with the rationale that the whole trait
was fallible anyway, so we might as well handle the RNG errors. But then
in #2216 we made the rest of the trait infallible, only using
fallibility for the RNG.

`Decapsulate` is also now fully infallible, but for cases where we need
to handle errors there's a `TryDecapsulate` trait. Prospectively we
could do the same thing here, and have a fallible `TryEncapsulate` trait
that uses `TryCryptoRng` and handles RNG errors. This PR doesn't attempt
to add one because it has some trait design issues around how we convert
RNG errors into KEM-specific error types.

Closes #2214
@tarcieri tarcieri merged commit a830d9a into master Jan 24, 2026
10 checks passed
@tarcieri tarcieri deleted the kem/make-encapsulate-infallible branch January 24, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annoying to impl kem::Encapsulate

1 participant