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.Text (Text)
20 import Gargantext.Prelude
21 import qualified Data.ByteString.Lazy.Char8 as Char
22 import qualified Data.Digest.Pure.SHA as SHA (sha256, showDigest)
23 import qualified Data.Set as Set
24 import qualified Data.Text as Text
26 --------------------------------------------------------------------------
27 -- | Use this datatype to keep traceability of hashes
31 -- | Class to make hashes
32 class IsHashable a where
35 -- | Main API to hash text
36 -- using sha256 for now
37 instance IsHashable Char.ByteString where
42 instance {-# OVERLAPPING #-} IsHashable String where
43 hash = hash . Char.pack
45 instance IsHashable Text where
46 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