kazu-yamamoto / crypton

lowlevel set of cryptographic primitives for haskell
Other
25 stars 16 forks source link

Digest should be nominal in its type parameter #26

Closed googleson78 closed 10 months ago

googleson78 commented 10 months ago

Currently we can freely coerce between the Digests of different hash algorithms. This can lead to safety issues, and to prevent it, we should make Digest have a type role Digest nominal

Example issue:

> import Data.Coerce
> x :: Digest SHA256; x = undefined
> y = coerce @(Digest SHA256) @(Digest Blake2b_256) x
> :t y
y :: Digest Blake2b_256
kazu-yamamoto commented 10 months ago

Merged with a little fix. Thank you for your contribution!