From a8aaa9b534d58c7b50f2ef0f3334ad9ba687701c Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 11 Mar 2019 03:14:34 -0400 Subject: [PATCH] Rename HasDigest to ValidAlgo. --- hnix-store-core/src/System/Nix/Hash.hs | 2 +- hnix-store-core/src/System/Nix/Internal/Hash.hs | 16 ++++++++-------- hnix-store-remote/src/System/Nix/Store/Remote.hs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hnix-store-core/src/System/Nix/Hash.hs b/hnix-store-core/src/System/Nix/Hash.hs index f72a4a6..c26e8a2 100644 --- a/hnix-store-core/src/System/Nix/Hash.hs +++ b/hnix-store-core/src/System/Nix/Hash.hs @@ -5,7 +5,7 @@ module System.Nix.Hash ( HNix.Digest , HNix.HashAlgorithm(..) - , HNix.HasDigest(..) + , HNix.ValidAlgo(..) , HNix.NamedAlgo(..) , HNix.hash , HNix.hashLazy diff --git a/hnix-store-core/src/System/Nix/Internal/Hash.hs b/hnix-store-core/src/System/Nix/Internal/Hash.hs index 130e395..04c0f83 100644 --- a/hnix-store-core/src/System/Nix/Internal/Hash.hs +++ b/hnix-store-core/src/System/Nix/Internal/Hash.hs @@ -56,7 +56,7 @@ newtype Digest (a :: HashAlgorithm) = -- | The primitive interface for incremental hashing for a given -- 'HashAlgorithm'. Every 'HashAlgorithm' should have an instance. -class HasDigest (a :: HashAlgorithm) where +class ValidAlgo (a :: HashAlgorithm) where -- | The incremental state for constructing a hash. type AlgoCtx a :: Type @@ -88,7 +88,7 @@ instance NamedAlgo 'SHA256 where -- or -- > :set -XTypeApplications -- > let d = hash @SHA256 "Hello, sha-256!" -hash :: forall a.HasDigest a => BS.ByteString -> Digest a +hash :: forall a.ValidAlgo a => BS.ByteString -> Digest a hash bs = finalize $ update @a (initialize @a) bs @@ -96,7 +96,7 @@ hash bs = -- -- Use is the same as for 'hash'. This runs in constant space, but -- forces the entire bytestring. -hashLazy :: forall a.HasDigest a => BSL.ByteString -> Digest a +hashLazy :: forall a.ValidAlgo a => BSL.ByteString -> Digest a hashLazy bsl = finalize $ foldl' (update @a) (initialize @a) (BSL.toChunks bsl) @@ -108,27 +108,27 @@ encodeBase32 (Digest bs) = Base32.encode bs encodeBase16 :: Digest a -> T.Text encodeBase16 (Digest bs) = T.decodeUtf8 (Base16.encode bs) -instance HasDigest 'MD5 where +instance ValidAlgo 'MD5 where type AlgoCtx 'MD5 = MD5.Ctx initialize = MD5.init update = MD5.update finalize = Digest . MD5.finalize -instance HasDigest 'SHA1 where +instance ValidAlgo 'SHA1 where type AlgoCtx 'SHA1 = SHA1.Ctx initialize = SHA1.init update = SHA1.update finalize = Digest . SHA1.finalize -instance HasDigest 'SHA256 where +instance ValidAlgo 'SHA256 where type AlgoCtx 'SHA256 = SHA256.Ctx initialize = SHA256.init update = SHA256.update finalize = Digest . SHA256.finalize --- | Reuses the underlying 'HasDigest' instance, but does a +-- | Reuses the underlying 'ValidAlgo' instance, but does a -- 'truncateDigest' at the end. -instance (HasDigest a, KnownNat n) => HasDigest ('Truncated n a) where +instance (ValidAlgo a, KnownNat n) => ValidAlgo ('Truncated n a) where type AlgoCtx ('Truncated n a) = AlgoCtx a initialize = initialize @a update = update @a diff --git a/hnix-store-remote/src/System/Nix/Store/Remote.hs b/hnix-store-remote/src/System/Nix/Store/Remote.hs index b1fb806..6009ead 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote.hs @@ -178,7 +178,7 @@ addToStoreNar = undefined -- XXX type PathFilter = Path -> Bool addToStore - :: forall a. (HasDigest a, NamedAlgo a) + :: forall a. (ValidAlgo a, NamedAlgo a) => LBS.ByteString -> FilePath -> Bool