Skip to content
Open
Changes from 2 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
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ impl<T: ConstantTimeEq> ConstantTimeEq for [T] {
}
}

impl ConstantTimeEq for str {
/// Check whether two strings are equal.
///
/// # Note
///
/// This function short-circuits if the lengths of the input strings
/// are different. Otherwise, it should execute in time independent
/// of the values.
#[inline]
fn ct_eq(&self, rhs: &Self) -> Choice {
self.as_bytes().ct_eq(rhs.as_bytes())
}
}

impl ConstantTimeEq for Choice {
#[inline]
fn ct_eq(&self, rhs: &Choice) -> Choice {
Expand Down