kem: use TryCryptoRng for encapsulate#2049
Conversation
|
Ugh, tried to do a downstream PR for this and it ended up being rather annoying. I'll leave this open for now but I'm a little confused about what to do about cases where we still need to pass a |
Why do you need to do it in implementation crates? With this change you should be able to pass |
|
Because all of the downstream APIs use |
|
|
||
| /// Encapsulates a fresh shared secret | ||
| fn encapsulate<R: CryptoRng + ?Sized>(&self, rng: &mut R) -> Result<(EK, SS), Self::Error>; | ||
| fn encapsulate<R: TryCryptoRng + ?Sized>(&self, rng: &mut R) -> Result<(EK, SS), Self::Error>; |
There was a problem hiding this comment.
It may be worth to add a note to the method docs that users can pass types which implement CryptoRng into this method.
Maybe you meant "upstream" here? So you want to use Have you tried to use |
|
It’s for I tried |
The method is fallible anyway, so errors should be propagated rather than panicking
edac52f to
c068a4b
Compare
|
Okay, |
Companion PR to RustCrypto/traits#2049
Companion PR to RustCrypto/traits#2049
Companion PR to RustCrypto/traits#2049
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
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)
The method is fallible anyway, so errors should be propagated rather than panicking