@@ -56,7 +56,7 @@ newtype Digest (a :: HashAlgorithm) =
5656
5757-- | The primitive interface for incremental hashing for a given
5858-- 'HashAlgorithm'. Every 'HashAlgorithm' should have an instance.
59- class HasDigest (a :: HashAlgorithm ) where
59+ class ValidAlgo (a :: HashAlgorithm ) where
6060 -- | The incremental state for constructing a hash.
6161 type AlgoCtx a :: Type
6262
@@ -88,15 +88,15 @@ instance NamedAlgo 'SHA256 where
8888-- or
8989-- > :set -XTypeApplications
9090-- > let d = hash @SHA256 "Hello, sha-256!"
91- hash :: forall a . HasDigest a => BS. ByteString -> Digest a
91+ hash :: forall a . ValidAlgo a => BS. ByteString -> Digest a
9292hash bs =
9393 finalize $ update @ a (initialize @ a ) bs
9494
9595-- | Hash an entire (lazy) 'BSL.ByteString' as a single call.
9696--
9797-- Use is the same as for 'hash'. This runs in constant space, but
9898-- forces the entire bytestring.
99- hashLazy :: forall a . HasDigest a => BSL. ByteString -> Digest a
99+ hashLazy :: forall a . ValidAlgo a => BSL. ByteString -> Digest a
100100hashLazy bsl =
101101 finalize $ foldl' (update @ a ) (initialize @ a ) (BSL. toChunks bsl)
102102
@@ -108,27 +108,27 @@ encodeBase32 (Digest bs) = Base32.encode bs
108108encodeBase16 :: Digest a -> T. Text
109109encodeBase16 (Digest bs) = T. decodeUtf8 (Base16. encode bs)
110110
111- instance HasDigest 'MD5 where
111+ instance ValidAlgo 'MD5 where
112112 type AlgoCtx 'MD5 = MD5. Ctx
113113 initialize = MD5. init
114114 update = MD5. update
115115 finalize = Digest . MD5. finalize
116116
117- instance HasDigest 'SHA1 where
117+ instance ValidAlgo 'SHA1 where
118118 type AlgoCtx 'SHA1 = SHA1. Ctx
119119 initialize = SHA1. init
120120 update = SHA1. update
121121 finalize = Digest . SHA1. finalize
122122
123- instance HasDigest 'SHA256 where
123+ instance ValidAlgo 'SHA256 where
124124 type AlgoCtx 'SHA256 = SHA256. Ctx
125125 initialize = SHA256. init
126126 update = SHA256. update
127127 finalize = Digest . SHA256. finalize
128128
129- -- | Reuses the underlying 'HasDigest ' instance, but does a
129+ -- | Reuses the underlying 'ValidAlgo ' instance, but does a
130130-- 'truncateDigest' at the end.
131- instance (HasDigest a , KnownNat n ) => HasDigest ('Truncated n a ) where
131+ instance (ValidAlgo a , KnownNat n ) => ValidAlgo ('Truncated n a ) where
132132 type AlgoCtx ('Truncated n a ) = AlgoCtx a
133133 initialize = initialize @ a
134134 update = update @ a
0 commit comments