Skip to content
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

Consider adding Eq where possible #296

Open
brycx opened this issue Aug 16, 2022 · 5 comments
Open

Consider adding Eq where possible #296

brycx opened this issue Aug 16, 2022 · 5 comments

Comments

@brycx
Copy link
Member

brycx commented Aug 16, 2022

When #[warn(clippy::derive_partial_eq_without_eq)] is enabled, clippy will suggest to add Eq to some types. We should make sure this makes sense before we add this, because removing them later will be a breaking change.

@brycx brycx added bug Something isn't working and removed bug Something isn't working labels Aug 16, 2022
@brycx brycx added this to the 0.17.3 milestone Aug 16, 2022
@vlmutolo
Copy link
Contributor

The additional semantic requirements for Eq are laid out in the trait's docs. I think this is okay to implement at least for any of our types that are just "bags of bytes". The three relevant properties are:

  • reflexivity: a == a
  • symmetry: a == b implies b == a
  • transitivity: a == b and b == c implies a == c

The type system will enforce that the bag-of-bytes types can only be compared with the same type, which guarantees that the underlying bytes semantically mean the same thing and that we're not, for example, comparing a private key and a hash. That's the only thing I can think of that might break one of the above properties, and it's not an issue.

@brycx
Copy link
Member Author

brycx commented Aug 19, 2022

Just for reference, clippy suggests the additional Eq on the following types:

  • X25519 PublicKey + PrivateKey + SessionKeys (high-level API)
  • BLAKE2b Hasher enum

Good points @vlmutolo. Seems like this shouldn't be too much of an issue then.

@vlmutolo
Copy link
Contributor

In the const generics refactor, the byte containers will all look like Public<C, D>. I think we can derive Eq on PublicData and the various D storage types (e.g. ArrayData). This means that Public will implement Eq if and only if the context parameter C implements Eq. So we can control which types implement Eq just using the context parameter, which is in line with the spirit of the refactor: pushing logic (such as min, max sizes) into the context parameters and letting everything else be the same.

I imagine we'll want to implement Eq for all the current byte container types, but it's good that we'll have the option to not implement it selectively.

@brycx
Copy link
Member Author

brycx commented Aug 21, 2022

Do you think it'd be better to postpone this to post const-generics, that you've been working on @vlmutolo?

@vlmutolo
Copy link
Contributor

vlmutolo commented Oct 2, 2022

I think we can go ahead and add this in the current implementation. I'll also make sure to add it in the const-generics branch.

@brycx brycx modified the milestones: 0.17.3, 0.17.4 Dec 7, 2022
@brycx brycx removed this from the 0.17.4 milestone Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants