-
Notifications
You must be signed in to change notification settings - Fork 710
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
Document or remove some uses of unsafe
#1657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,14 @@ impl PublicExponent { | |
|
||
// TODO: Use `NonZeroU64::new(...).unwrap()` when `feature(const_panic)` is | ||
// stable. | ||
pub(super) const _3: Self = Self(unsafe { NonZeroU64::new_unchecked(3) }); | ||
pub(super) const _65537: Self = Self(unsafe { NonZeroU64::new_unchecked(65537) }); | ||
pub(super) const _3: Self = Self(match NonZeroU64::new(3) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the TODO above this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that, but it might be good to keep it since |
||
Some(nz) => nz, | ||
None => unreachable!(), | ||
}); | ||
pub(super) const _65537: Self = Self(match NonZeroU64::new(65537) { | ||
Some(nz) => nz, | ||
None => unreachable!(), | ||
}); | ||
|
||
// This limit was chosen to bound the performance of the simple | ||
// exponentiation-by-squaring implementation in `elem_exp_vartime`. In | ||
|
@@ -29,7 +35,10 @@ impl PublicExponent { | |
// | ||
// TODO: Use `NonZeroU64::new(...).unwrap()` when `feature(const_panic)` is | ||
// stable. | ||
const MAX: Self = Self(unsafe { NonZeroU64::new_unchecked((1u64 << 33) - 1) }); | ||
const MAX: Self = Self(match NonZeroU64::new((1u64 << 33) - 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: Remove the TODO. |
||
Some(nz) => nz, | ||
None => unreachable!(), | ||
}); | ||
|
||
pub(super) fn from_be_bytes( | ||
input: untrusted::Input, | ||
|
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 think a lot of what's in endian.rs likely duplicates the zerocopy functionality that is being derived here. I suspect we could get rid of even more of the
unsafe
by removing that duplication.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.
Good idea. We've got the byteorder module which provides analogous types, although they don't provide alignment guarantees, which can pessimize code.
We've got an open issue to support versions of those types with platform-native alignment, but I haven't had time to work on it yet. If that's the thing that would unblock this, I'd be happy to prioritize it.