summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-17 16:14:53 -0400
committerAndrew Cady <d@jerkface.net>2018-06-17 16:15:40 -0400
commit019a2a64ffd8286f2f272199bedca1d62589764a (patch)
tree8e4f631bee787bb339386c9318840c0047a4d0c5 /src
initial commit
Diffstat (limited to 'src')
-rw-r--r--src/Crypto/Hash/Types/Digest/Read.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Crypto/Hash/Types/Digest/Read.hs b/src/Crypto/Hash/Types/Digest/Read.hs
new file mode 100644
index 0000000..f371f30
--- /dev/null
+++ b/src/Crypto/Hash/Types/Digest/Read.hs
@@ -0,0 +1,20 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# LANGUAGE InstanceSigs #-}
3{-# LANGUAGE NoImplicitPrelude #-}
4{-# LANGUAGE PartialTypeSignatures #-}
5{-# LANGUAGE ViewPatterns #-}
6module Crypto.Hash.Types.Digest.Read where
7import Rebase.Prelude hiding (hash)
8
9import Crypto.Hash
10import Data.ByteArray.Encoding
11import qualified Rebase.Data.Text as Text
12
13instance HashAlgorithm a =>
14 Read (Digest a) where
15 readsPrec :: Int -> (String -> [(Digest a, String)])
16 readsPrec _ (Text.encodeUtf8 . Text.pack -> bytes) =
17 toList $ (flip (,) "") <$> (digestFromByteString =<< baseConv bytes)
18 where
19 baseConv :: ByteString -> Maybe (ByteString)
20 baseConv = listToMaybe . toList . convertFromBase Base16