haskell-crypto / cryptonite

lowlevel set of cryptographic primitives for haskell
Other
226 stars 139 forks source link

Question regarding different `Show` instances for `Digest` between `cryptonite` and `cryptohash` #8

Closed menelaos closed 9 years ago

menelaos commented 9 years ago

The following code snippet yields different results for both packages.

import Crypto.Hash
import qualified Data.ByteString.Char8 as BSC

hash' bs = hash bs :: Digest MD5

show . hash' . BSC.pack $ "foo"
-- Returns
--   "\"acbd18db4cc2f85cedef654fccc4a4d8\"" for cryptonite
--     "acbd18db4cc2f85cedef654fccc4a4d8"   for cryptohash

This is probably due to the different Show instances:

Cryptonite:

instance Show (Digest a) where
    show (Digest bs) = show (B.convertToBase B.Base16 bs :: Bytes)

Cryptohash:

instance Show (Digest a) where
    show (Digest bs) = BC.unpack $ toHex bs

Will the instance in cryptonite stay as it is? This would prevent cryptonite from being used as a drop-in replacement for cryptohash, but maybe it isn't intended as such.

vincenthz commented 9 years ago

yes, I think that should be a bug at this stage. There's no reason the show instance to be different