Skip to content

Commit cae31f7

Browse files
author
Vince Mutolo
committed
restrict PartialEq to exact same type
This is a safer default because it prevents users from creating their own data types and comparing them against Orion's. If we want to allow that, it should be a separate discussion.
1 parent f45f7ec commit cae31f7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/hazardous/base.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,28 @@ where
371371
}
372372

373373
// We define `PartialEq` such that we can compare only with
374-
// other `PublicData` that have the same "context".
375-
impl<B0, B1, C> PartialEq<PublicData<B1, C>> for PublicData<B0, C>
376-
where
377-
B0: AsRef<[u8]>,
378-
B1: AsRef<[u8]>,
374+
// other `Public` that have the same "context".
375+
impl<B: AsRef<[u8]>, C> PartialEq for Public<B, C>
379376
{
380-
fn eq(&self, other: &PublicData<B1, C>) -> bool {
377+
fn eq(&self, other: &Self) -> bool {
381378
self.bytes.as_ref().eq(other.bytes.as_ref())
382379
}
383380
}
384381

385-
// We implement this manually to skip over the PhantomData.
386-
// TODO: Should this be less general? Maybe only implement
387-
// PartialEq<&Self> instead of any U: AsRef<u8>.
388-
impl<B0, B1, C> PartialEq<SecretData<B1, C>> for SecretData<B0, C>
382+
impl<B, C> PartialEq<[u8]> for Public<B, C>
389383
where
390-
B0: AsRef<[u8]>,
391-
B1: AsRef<[u8]>,
384+
B: AsRef<[u8]>,
385+
{
386+
fn eq(&self, other: &[u8]) -> bool {
387+
self.bytes.as_ref().eq(other)
388+
}
389+
}
390+
391+
// We define `PartialEq` such that we can compare only with
392+
// other `Public` that have the same "context".
393+
impl<B: AsRef<[u8]>, C> PartialEq for Secret<B, C>
392394
{
393-
fn eq(&self, other: &SecretData<B1, C>) -> bool {
395+
fn eq(&self, other: &Secret<B, C>) -> bool {
394396
use subtle::ConstantTimeEq;
395397
self.unprotected_as_bytes()
396398
.ct_eq(other.unprotected_as_bytes())

0 commit comments

Comments
 (0)