|
1 | 1 | {-| |
2 | 2 | Description : Cryptographic hashes for hnix-store. |
3 | | -Maintainer : Greg Hale <[email protected]> |
4 | 3 | -} |
5 | 4 | {-# LANGUAGE AllowAmbiguousTypes #-} |
6 | 5 | {-# LANGUAGE DataKinds #-} |
@@ -49,17 +48,17 @@ data HashAlgorithm' n |
49 | 48 | | Truncated n (HashAlgorithm' n) |
50 | 49 | deriving (Eq, Show) |
51 | 50 |
|
52 | | -class HashAlgoText a where |
53 | | - algoString :: Proxy a -> Text |
| 51 | +class NamedAlgo a where |
| 52 | + algoName :: Text |
54 | 53 |
|
55 | | -instance HashAlgoText 'MD5 where |
56 | | - algoString (Proxy :: Proxy 'MD5) = "md5" |
| 54 | +instance NamedAlgo 'MD5 where |
| 55 | + algoName = "md5" |
57 | 56 |
|
58 | | -instance HashAlgoText 'SHA1 where |
59 | | - algoString (Proxy :: Proxy 'SHA1) = "sha1" |
| 57 | +instance NamedAlgo 'SHA1 where |
| 58 | + algoName = "sha1" |
60 | 59 |
|
61 | | -instance HashAlgoText 'SHA256 where |
62 | | - algoString (Proxy :: Proxy 'SHA256) = "sha256" |
| 60 | +instance NamedAlgo 'SHA256 where |
| 61 | + algoName = "sha256" |
63 | 62 |
|
64 | 63 | type HashAlgorithm = HashAlgorithm' Nat |
65 | 64 |
|
@@ -96,11 +95,11 @@ hashLazy :: forall a.HasDigest a => BSL.ByteString -> Digest a |
96 | 95 | hashLazy bsl = |
97 | 96 | finalize $ foldl' (update @a) (initialize @a) (BSL.toChunks bsl) |
98 | 97 |
|
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 |
101 | 100 |
|
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) |
104 | 103 |
|
105 | 104 | -- | Convert any Digest to a base32-encoded string. |
106 | 105 | -- This is not used in producing store path hashes |
|
0 commit comments