blob: f371f3054ef826cdad3896b80c896adf0f3c3ff6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ViewPatterns #-}
module Crypto.Hash.Types.Digest.Read where
import Rebase.Prelude hiding (hash)
import Crypto.Hash
import Data.ByteArray.Encoding
import qualified Rebase.Data.Text as Text
instance HashAlgorithm a =>
Read (Digest a) where
readsPrec :: Int -> (String -> [(Digest a, String)])
readsPrec _ (Text.encodeUtf8 . Text.pack -> bytes) =
toList $ (flip (,) "") <$> (digestFromByteString =<< baseConv bytes)
where
baseConv :: ByteString -> Maybe (ByteString)
baseConv = listToMaybe . toList . convertFromBase Base16
|