git.iko.soy/typeable/cabal2nix
on master help sign in
Switch digest calculation code to hopenssl.
commit6a0189ab13484b5a8aa28ff0037dec43d50643ab authorPeter Simons <simons@cryp.to> dateMon 15 May 2017, 16:58 (9 years ago) parent9619f40
5 files changed+14−16
cabal2nix.cabal+2−2 hackage2nix/HackageGit.hs+2−6 package.yaml+2−2 src/Distribution/Nixpkgs/Haskell/Hackage.hs+3−2 src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+5−4
cabal2nix.cabal+2−2
@@ -94,12 +94,12 @@ library
9494 , distribution-nixpkgs
9595 , filepath
9696 , hackage-db
97+ , hopenssl >= 2
9798 , language-nix
9899 , lens
99100 , optparse-applicative
100101 , pretty >= 1.1.2
101102 , process
102− , SHA
103103 , split
104104 , text
105105 , transformers
@@ -141,12 +141,12 @@ executable cabal2nix
141141 , distribution-nixpkgs
142142 , filepath
143143 , hackage-db
144+ , hopenssl >= 2
144145 , language-nix
145146 , lens
146147 , optparse-applicative
147148 , pretty >= 1.1.2
148149 , process
149− , SHA
150150 , split
151151 , text
152152 , transformers
hackage2nix/HackageGit.hs+2−6
@@ -8,8 +8,7 @@ import Control.Lens hiding ( (<.>) )
88import Data.Aeson
99import Data.ByteString.Char8 ( ByteString )
1010import qualified Data.ByteString.Char8 as BS
11−import Data.ByteString.Lazy.Char8 ( fromStrict )
12−import Data.Digest.Pure.SHA ( sha256, showDigest )
11+import OpenSSL.Digest ( digest, digestByName, toHex )
1312import Data.Map as Map
1413import Data.Set as Set
1514import Data.String
@@ -50,10 +49,7 @@ readPackage dirPrefix (PackageIdentifier name version) = do
5049 cabal <- case parsePackageDescription (decodeUTF8 buf) of
5150 ParseOk _ a -> return a
5251 ParseFailed err -> fail (cabalFile ++ ": " ++ show err)
53− return (cabal, mkSHA256 buf)
54−
55−mkSHA256 :: ByteString -> SHA256Hash
56−mkSHA256 = showDigest . sha256 . fromStrict
52+ return (cabal, BS.unpack (toHex (digest (digestByName "sha256") buf)))
5753
5854declareLenses [d|
5955 data Meta = Meta { hashes :: Map String String
package.yaml+2−2
@@ -1,5 +1,5 @@
11name: cabal2nix
2−version: 2.2.1
2+version: 2.3
33synopsis: Convert Cabal files into Nix build instructions.
44author:
55 - Peter Simons
@@ -85,12 +85,12 @@ dependencies:
8585 - distribution-nixpkgs
8686 - filepath
8787 - hackage-db
88+ - hopenssl >= 2
8889 - language-nix
8990 - lens
9091 - optparse-applicative
9192 - pretty >= 1.1.2
9293 - process
93− - SHA
9494 - split
9595 - text
9696 - transformers
src/Distribution/Nixpkgs/Haskell/Hackage.hs+3−2
@@ -1,10 +1,11 @@
11module Distribution.Nixpkgs.Haskell.Hackage ( readHashedHackage, readHashedHackage', module Distribution.Hackage.DB ) where
22
33import Data.ByteString.Lazy ( ByteString )
4−import Data.Digest.Pure.SHA ( sha256, showDigest )
4+import Data.ByteString.Char8 ( unpack )
55import Distribution.Hackage.DB
66import qualified Distribution.Hackage.DB.Parsed as Unparsed ( parsePackage )
77import qualified Distribution.Hackage.DB.Unparsed as Unparsed
8+import OpenSSL.Digest ( digest, digestByName, toHex )
89
910-- | A variant of 'readHackage' that adds the SHA256 digest of the
1011-- original Cabal file to the parsed 'GenericPackageDescription'. That
@@ -24,7 +25,7 @@ readHashedHackage' = fmap parseUnparsedHackage . Unparsed.readHackage'
2425 parsePackage :: String -> Version -> ByteString -> GenericPackageDescription
2526 parsePackage name version buf =
2627 let pkg = Unparsed.parsePackage name version buf
27− hash = showDigest (sha256 buf)
28+ hash = unpack (toHex (digest (digestByName "sha256") buf))
2829 in
2930 pkg { packageDescription = (packageDescription pkg) {
3031 customFieldsPD = ("X-Cabal-File-Hash", hash) : customFieldsPD (packageDescription pkg)
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+5−4
@@ -6,8 +6,8 @@ import qualified Control.Exception as Exception
66import Control.Monad
77import Control.Monad.IO.Class
88import Control.Monad.Trans.Maybe
9−import qualified Data.ByteString.Lazy.Char8 as BS8
10−import Data.Digest.Pure.SHA ( sha256, showDigest )
9+import qualified Data.ByteString.Lazy.Char8 as LBS8
10+import qualified Data.ByteString.Char8 as SBS8
1111import Data.List ( isSuffixOf, isPrefixOf )
1212import Data.Maybe
1313import Data.Version
@@ -18,6 +18,7 @@ import qualified Distribution.Package as Cabal
1818import Distribution.PackageDescription
1919import qualified Distribution.PackageDescription as Cabal
2020import Distribution.Text ( simpleParse )
21+import OpenSSL.Digest ( digest, digestByName, toHex )
2122import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getHomeDirectory, getDirectoryContents )
2223import System.Exit ( exitFailure )
2324import System.FilePath ( (</>), (<.>) )
@@ -145,8 +146,8 @@ cabalFromFile failHard file =
145146 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
146147 -- the reading of the file, so we will always catch the expression here.
147148 MaybeT $ handleIO (\err -> Nothing <$ hPutStrLn stderr ("*** parsing cabal file: " ++ show err)) $ do
148− buf <- BS8.readFile file
149− let hash = showDigest (sha256 buf)
149+ buf <- LBS8.readFile file
150+ let hash = SBS8.unpack (toHex (digest (digestByName "sha256") buf))
150151 case parsePackage' buf of
151152 Left msg -> if failHard
152153 then fail ("*** cannot parse " ++ show file ++ ": " ++ msg)