subtle icon indicating copy to clipboard operation
subtle copied to clipboard

Make `Choice` and `CtOption` be `Hash`

Open dvdplm opened this issue 1 year ago • 3 comments
trafficstars

While rare, sometimes it is convenient to use CtOption in hashmaps/sets. This PR suggests adding Hash to CtOption and Choice to allow that use case, see e.g. crypto-bigint::Checked.

It also aligns with std::option::Option, which is also Hash.

dvdplm avatar Aug 22 '24 10:08 dvdplm

One question I have is if making BlackBox be Hash as well is desirable?

dvdplm avatar Aug 22 '24 10:08 dvdplm

What's the use case for Choice being Hash? You want to use a Choice as a key for a HashMap?

I think all of these types, including and especially BlackBox, deliberately keep their internals opaque and only allow access using very specific and deliberate methods. BlackBox for example is only intended to be accessed via its get method and a Hash impl would bypass that.

tarcieri avatar Aug 24 '24 23:08 tarcieri

Choice being Hash is just a consequence of making CtOption Hash.

dvdplm avatar Aug 25 '24 10:08 dvdplm