Skip to content

Commit

Permalink
Merge pull request #119 from tarcieri/ctoption-into-option
Browse files Browse the repository at this point in the history
Add `CtOption::into_option`
  • Loading branch information
isislovecruft authored Feb 9, 2024
2 parents dc3bce7 + 4ffd51d commit 74360d7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,22 @@ impl<T> CtOption<T> {

Self::conditional_select(&self, &f, is_none)
}

/// Convert the `CtOption<T>` wrapper into an `Option<T>`, depending on whether
/// the underlying `is_some` `Choice` was a `0` or a `1` once unwrapped.
///
/// # Note
///
/// This function exists to avoid ending up with ugly, verbose and/or bad handled
/// conversions from the `CtOption<T>` wraps to an `Option<T>` or `Result<T, E>`.
/// This implementation doesn't intend to be constant-time nor try to protect the
/// leakage of the `T` since the `Option<T>` will do it anyways.
///
/// It's equivalent to the corresponding `From` impl, however this version is
/// friendlier for type inference.
pub fn into_option(self) -> Option<T> {
self.into()
}
}

impl<T: ConditionallySelectable> ConditionallySelectable for CtOption<T> {
Expand Down

0 comments on commit 74360d7

Please sign in to comment.