Skip to content

Commit 20e7b03

Browse files
committed
Rename HashAlgoText to NamedAlgo.
1 parent 7b918a9 commit 20e7b03

File tree

1 file changed

+12
-13
lines changed
  • hnix-store-core/src/System/Nix/Internal

1 file changed

+12
-13
lines changed

hnix-store-core/src/System/Nix/Internal/Hash.hs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-|
22
Description : Cryptographic hashes for hnix-store.
3-
Maintainer : Greg Hale <[email protected]>
43
-}
54
{-# LANGUAGE AllowAmbiguousTypes #-}
65
{-# LANGUAGE DataKinds #-}
@@ -49,17 +48,17 @@ data HashAlgorithm' n
4948
| Truncated n (HashAlgorithm' n)
5049
deriving (Eq, Show)
5150

52-
class HashAlgoText a where
53-
algoString :: Proxy a -> Text
51+
class NamedAlgo a where
52+
algoName :: Text
5453

55-
instance HashAlgoText 'MD5 where
56-
algoString (Proxy :: Proxy 'MD5) = "md5"
54+
instance NamedAlgo 'MD5 where
55+
algoName = "md5"
5756

58-
instance HashAlgoText 'SHA1 where
59-
algoString (Proxy :: Proxy 'SHA1) = "sha1"
57+
instance NamedAlgo 'SHA1 where
58+
algoName = "sha1"
6059

61-
instance HashAlgoText 'SHA256 where
62-
algoString (Proxy :: Proxy 'SHA256) = "sha256"
60+
instance NamedAlgo 'SHA256 where
61+
algoName = "sha256"
6362

6463
type HashAlgorithm = HashAlgorithm' Nat
6564

@@ -96,11 +95,11 @@ hashLazy :: forall a.HasDigest a => BSL.ByteString -> Digest a
9695
hashLazy bsl =
9796
finalize $ foldl' (update @a) (initialize @a) (BSL.toChunks bsl)
9897

99-
digestText32 :: forall a. HashAlgoText a => Digest a -> T.Text
100-
digestText32 d = algoString (Proxy :: Proxy a) <> ":" <> printAsBase32 d
98+
digestText32 :: forall a. NamedAlgo a => Digest a -> T.Text
99+
digestText32 d = algoName @a <> ":" <> printAsBase32 d
101100

102-
digestText16 :: forall a. HashAlgoText a => Digest a -> T.Text
103-
digestText16 (Digest bs) = algoString (Proxy :: Proxy a) <> ":" <> T.decodeUtf8 (Base16.encode bs)
101+
digestText16 :: forall a. NamedAlgo a => Digest a -> T.Text
102+
digestText16 (Digest bs) = algoName @a <> ":" <> T.decodeUtf8 (Base16.encode bs)
104103

105104
-- | Convert any Digest to a base32-encoded string.
106105
-- This is not used in producing store path hashes

0 commit comments

Comments
 (0)