Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ctutils/src/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Choice {
///
/// # Panics
/// - in `debug` builds, panics if the value is anything other than `0` or `1`.
// TODO(tarcieri): deprecate this in favor of non-panicking constructors?
#[inline]
pub const fn new(value: u8) -> Self {
// Compare to what should be the non-secret upper bits of the value, which should always be
Expand Down Expand Up @@ -388,6 +389,17 @@ impl CtSelect for Choice {
}
}

/// Create a new [`Choice`] from the given `u8` value, which MUST be either `0` or `1`.
///
/// # Panics
/// - in `debug` builds, panics if the value is anything other than `0` or `1`.
// TODO(tarcieri): deprecate this in favor of non-panicking constructors?
impl From<u8> for Choice {
fn from(value: u8) -> Self {
Choice::new(value)
}
}

impl From<Choice> for u8 {
fn from(choice: Choice) -> u8 {
choice.to_u8()
Expand Down