diff options
author | Andrew Cady <d@jerkface.net> | 2018-06-17 16:14:53 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2018-06-17 16:15:40 -0400 |
commit | 019a2a64ffd8286f2f272199bedca1d62589764a (patch) | |
tree | 8e4f631bee787bb339386c9318840c0047a4d0c5 /src |
initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/Crypto/Hash/Types/Digest/Read.hs | 20 |
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 #-} | ||
6 | module Crypto.Hash.Types.Digest.Read where | ||
7 | import Rebase.Prelude hiding (hash) | ||
8 | |||
9 | import Crypto.Hash | ||
10 | import Data.ByteArray.Encoding | ||
11 | import qualified Rebase.Data.Text as Text | ||
12 | |||
13 | instance 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 | ||