tel / saltine

Cryptography that's easy to digest (NaCl/libsodium bindings)
https://github.com/tel/saltine
MIT License
61 stars 29 forks source link

Show instances #26

Closed athanclark closed 3 years ago

athanclark commented 8 years ago

I'm building a simple session cache out of public keys and nonces, and it would be extremely useful if there were hashable instances for all the ByteString-convertable types, like Nonce PublicKey etc. I've just been building my own, out of newtypes and conversions, but I think these instances speak for themselves for how useful they could be. I may just implement it myself and submit a PR if that's okay :)

athanclark commented 8 years ago

I hate to be that person also, but is there any hope there could be a Show instance as well? Just for useful logging / exceptions

linearray commented 5 years ago

Hey Athan,

I think adding Hashable instances is a great idea, especially because the data types are just newtypes over a ByteString that already has a useful instance. If you have a patch, I'll gladly take it, otherwise I can add the instances myself.

I'm not entirely sure about adding Show. The Show instance for ByteStrings is not very fitting, because it will result in something like "\232f\254\209\DC4\158Gu", which is not that great for displaying keys, where you probably want it base64-encoded, so we would need to bring in base64-bytestring just for Show.

athanclark commented 5 years ago

Definitely, but on the same note, ByteStrings are never really meaningful when shown, and it's really only useful for debugging purposes, but I digress :) I'll file a PR in a few hours! Thank you!

linearray commented 5 years ago

I just realised the message branch has Show instances for a lot of types and they truncate output to the first 10 hex characters, which is probably a good idea if you're only interested in debug output. We need to bring in base16-bytestring, but yeah, I think we should do it!

linearray commented 3 years ago

And a few short years later this is in master!