Perhaps ‘axing’ is a tad strong - lets say, relegated to the status of ‘prefer the other interface’ along side the mutable interface, in favor of this (hopefully) better new approach.
a group of pattern synonyms that contain all the valid ones
One of the difficulty of creating pattern synonyms for valid algorithm combinations is that there’s literally thousands of them - I’d have to rely on TemplateHaskell
in order to make that feasible. I first ran into the issue with unit testing when the sheer number of tests (one per combination) caused the unit tests to terminate without outputting the results - this is why there are so many individual unit test targets now
Note that although I can’t provide convenient aliases for every algorithm combination, I certainly can make sure to do that for all priority / best-in-class algorithms as I did in Botan.Hash.SHA3
, which exports not just the family sha3
but also all of the individual SHA3 variants (sha3_224
, sha3_256
, sha3_384
, sha3_512
).
make newtypes for every section that only accepts parts of certain algos/etc
Things have already been improved beyond yesterday’s update. With the new data families, we are accomplishing exactly this
For example, AES128SecretKey
(formerly AES128CipherKey
, but ) is now actually a newtype
wrapper around a GSecretkey
type from which I can automatically derive everything.
First, GSecretKey
is itself a newtype
wrapper around Bytestring
:
newtype GSecretKey = MkGSecretKey { unGSecretKey :: ByteString }
deriving newtype (Eq, Ord, Encodable)
Then I then wrap the algorithm-specific newtype around that, plus a pattern and function to hide the GSecretKey
:
newtype instance SecretKey AES128 = MkAES128SecretKey GSecretKey
deriving newtype (Eq, Ord, Show, Encodable)
pattern AES128SecretKey :: ByteString -> SecretKey AES128
pattern AES128SecretKey bytes = MkAES128SecretKey (MkGSecretKey bytes)
getAES128SecretKey :: SecretKey AES128 -> ByteString
getAES128SecretKey (AES128SecretKey bs) = bs
And now I can just say:
newSecretKey @AES128
-- 591b3de67f882893a11af874fbf40bdd
Of course, this won’t be just for SecretKey
and BlockCipher
- I’m doing the same with other algorithms and supporting data types such as nonces, ciphertext, mac codes, salts, wherever appropriate.
It’ll all be out in the next update - I’ve already made some mad big strides since yesterday’s update (those dominoes keep tumbling down, and I’ve been in a happy little coding groove for the last few days.