2 Module : Gargantext.Prelude.Crypto.Hash
3 Description : Useful Tools near Prelude of the project
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 module Gargantext.Prelude.Crypto.Hash
17 import Prelude (String)
19 import Data.List (foldl)
20 import Data.Text (Text)
21 import Gargantext.Prelude
22 import qualified Data.ByteString.Lazy.Char8 as Char
23 import qualified Data.Digest.Pure.SHA as SHA (sha256, showDigest)
24 import qualified Data.Set as Set
25 import qualified Data.Text as Text
27 --------------------------------------------------------------------------
28 -- | Use this datatype to keep traceability of hashes
32 -- | Class to make hashes
33 class IsHashable a where
36 -- | Main API to hash text
37 -- using sha256 for now
38 instance IsHashable Char.ByteString where
43 instance {-# OVERLAPPING #-} IsHashable String where
44 hash = hash . Char.pack
46 instance IsHashable Text where
47 hash = hash . Text.unpack
49 instance IsHashable (Set Hash) where
50 hash = hash . foldl (<>) "" . Set.toList
52 instance {-# OVERLAPPABLE #-} IsHashable a => IsHashable [a] where
53 hash = hash . Set.fromList . map hash