-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto-common: add RngError
type
#1382
Conversation
Adds a common error type which can be used with both `getrandom` and `rand_core`. This eliminates the need to have `getrandom` as part of the public API.
crypto-common/src/lib.rs
Outdated
/// The error type returned when a random number generator fails. | ||
#[cfg(any(feature = "getrandom", feature = "rand_core"))] | ||
#[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
pub struct RngError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially it could carry along an inner code e.g. the raw_os_error
as reported by either getrandom::Error
or rand_core::Error
, although I don't think it's bad for it to be completely opaque
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should replace the errors in such way. They may carry crucial information for finding why an error has occurred. If you don't want to expose getrandom
in public API, you could convert getrandom::Error
into rand_core::Error
using From
/Into
, but it would mean that you have to pull rand_core
when only the getrandom
feature is enabled.
Personally, I think the current code is fine.
BTW it may be worth to add |
Do you want anything more than the The downside of the current approach is there are two different error types to deal with depending on which functions you're calling. |
Note the
I don't think |
Alright, I guess I'll close this |
Adds a common error type which can be used with both
getrandom
andrand_core
.This eliminates the need to have
getrandom
as part of the public API.