kazu-yamamoto / crypton

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

[Feature] Non-failable version of Crypto.MAC.Poly1305.initalize #28

Open epoberezkin opened 8 months ago

epoberezkin commented 8 months ago

The only reason it can fail is if it receives key not equal to 32 bytes.

Given that this is a very common size, we could add some newtype that cannot accidentally be constructed and pass it here (e.g. with additional function Crypto.Cipher.XSalsa.generate32, which is commonly used for NaCl crypto_box construction).

newtype Bytes32 a = Bytes32 a -- where a would be an instance of ByteArrayAccess

It would eliminate a lot of error handling code in all consumers for errors that can never happen (that currently can only be removed with partial pattern matches on CryptoFailable / using errors)

Happy to make a PR

kazu-yamamoto commented 8 months ago

Please make a PR.