Clean up hashing-related dependencies (#597)

Background: https://github.com/haskell-nix/hnix/issues/588#issuecomment-634692400
This commit is contained in:
Simon Jakobi 2020-05-30 02:28:50 +02:00 committed by GitHub
parent fc4a9b9fca
commit 707060260a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 52 deletions

View file

@ -910,10 +910,6 @@ library
Nix.Options.Parser Nix.Options.Parser
build-depends: build-depends:
base16-bytestring >= 0.1.1 && < 0.2 base16-bytestring >= 0.1.1 && < 0.2
, cryptohash-md5 >= 0.11.100 && < 0.12
, cryptohash-sha1 >= 0.11.100 && < 0.12
, cryptohash-sha256 >= 0.11.101 && < 0.12
, cryptohash-sha512 >= 0.11.100 && < 0.12
, haskeline >= 0.7.4.2 && < 0.8 , haskeline >= 0.7.4.2 && < 0.8
, pretty-show >= 1.9.5 && < 1.11 , pretty-show >= 1.9.5 && < 1.11
, serialise >= 0.2.1 && < 0.3 , serialise >= 0.2.1 && < 0.3
@ -937,16 +933,11 @@ executable hnix
, bytestring , bytestring
, comonad , comonad
, containers , containers
, cryptohash-md5
, cryptohash-sha1
, cryptohash-sha256
, cryptohash-sha512
, data-fix , data-fix
, deepseq , deepseq
, exceptions , exceptions
, filepath , filepath
, free , free
, hashing
, haskeline , haskeline
, hnix , hnix
, mtl , mtl
@ -989,17 +980,12 @@ test-suite hnix-tests
, base16-bytestring , base16-bytestring
, bytestring , bytestring
, containers , containers
, cryptohash-md5
, cryptohash-sha1
, cryptohash-sha256
, cryptohash-sha512
, data-fix , data-fix
, deepseq >=1.4.3 && <1.5 , deepseq >=1.4.3 && <1.5
, directory , directory
, exceptions , exceptions
, filepath , filepath
, generic-random , generic-random
, hashing
, hedgehog , hedgehog
, hnix , hnix
, interpolate , interpolate
@ -1043,15 +1029,10 @@ benchmark hnix-benchmarks
, bytestring , bytestring
, containers , containers
, criterion , criterion
, cryptohash-md5
, cryptohash-sha1
, cryptohash-sha256
, cryptohash-sha512
, data-fix , data-fix
, deepseq >=1.4.3 && <1.5 , deepseq >=1.4.3 && <1.5
, exceptions , exceptions
, filepath , filepath
, hashing
, hnix , hnix
, mtl , mtl
, optparse-applicative , optparse-applicative

View file

@ -30,23 +30,11 @@ import Control.Monad
import Control.Monad.Catch import Control.Monad.Catch
import Control.Monad.ListM ( sortByM ) import Control.Monad.ListM ( sortByM )
import Control.Monad.Reader ( asks ) import Control.Monad.Reader ( asks )
import Crypto.Hash
-- Using package imports here because there is a bug in cabal2nix that demands import qualified Crypto.Hash.MD5 as MD5
-- us to put the hashing package in the unconditional dependency list. import qualified Crypto.Hash.SHA1 as SHA1
-- See https://github.com/NixOS/cabal2nix/issues/348 for more info import qualified Crypto.Hash.SHA256 as SHA256
#if MIN_VERSION_hashing(0, 1, 0) import qualified Crypto.Hash.SHA512 as SHA512
import "hashing" Crypto.Hash
import qualified "hashing" Crypto.Hash.MD5 as MD5
import qualified "hashing" Crypto.Hash.SHA1 as SHA1
import qualified "hashing" Crypto.Hash.SHA256 as SHA256
import qualified "hashing" Crypto.Hash.SHA512 as SHA512
#else
import qualified "cryptohash-md5" Crypto.Hash.MD5 as MD5
import qualified "cryptohash-sha1" Crypto.Hash.SHA1 as SHA1
import qualified "cryptohash-sha256" Crypto.Hash.SHA256 as SHA256
import qualified "cryptohash-sha512" Crypto.Hash.SHA512 as SHA512
#endif
import qualified Data.Aeson as A import qualified Data.Aeson as A
import Data.Align ( alignWith ) import Data.Align ( alignWith )
import Data.Array import Data.Array
@ -1208,32 +1196,16 @@ hashString nsAlgo ns = Prim $ do
case algo of case algo of
"md5" -> "md5" ->
f $ \s -> f $ \s ->
#if MIN_VERSION_hashing(0, 1, 0)
Text.pack $ show (hash (encodeUtf8 s) :: MD5.MD5) Text.pack $ show (hash (encodeUtf8 s) :: MD5.MD5)
#else
decodeUtf8 $ Base16.encode $ MD5.hash $ encodeUtf8 s
#endif
"sha1" -> "sha1" ->
f $ \s -> f $ \s ->
#if MIN_VERSION_hashing(0, 1, 0)
Text.pack $ show (hash (encodeUtf8 s) :: SHA1.SHA1) Text.pack $ show (hash (encodeUtf8 s) :: SHA1.SHA1)
#else
decodeUtf8 $ Base16.encode $ SHA1.hash $ encodeUtf8 s
#endif
"sha256" -> "sha256" ->
f $ \s -> f $ \s ->
#if MIN_VERSION_hashing(0, 1, 0)
Text.pack $ show (hash (encodeUtf8 s) :: SHA256.SHA256) Text.pack $ show (hash (encodeUtf8 s) :: SHA256.SHA256)
#else
decodeUtf8 $ Base16.encode $ SHA256.hash $ encodeUtf8 s
#endif
"sha512" -> "sha512" ->
f $ \s -> f $ \s ->
#if MIN_VERSION_hashing(0, 1, 0)
Text.pack $ show (hash (encodeUtf8 s) :: SHA512.SHA512) Text.pack $ show (hash (encodeUtf8 s) :: SHA512.SHA512)
#else
decodeUtf8 $ Base16.encode $ SHA512.hash $ encodeUtf8 s
#endif
_ -> _ ->
throwError throwError
$ ErrorCall $ ErrorCall