Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Switch to cryptonite
  • Loading branch information
eikeon committed Jan 19, 2018
1 parent 83cb908 commit 795a23b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
10 changes: 5 additions & 5 deletions main/Main.hs
Expand Up @@ -4,9 +4,9 @@ module Main where

import Crypto.Hash (Digest)
import qualified Crypto.Hash as CH
import Data.ByteArray (convert)
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (toStrict)
import Data.Byteable (toBytes)
import Data.Monoid ((<>))
import Options.Applicative

Expand Down Expand Up @@ -46,10 +46,10 @@ main

-- TODO add BLAKE support
hash :: MH.HashAlgorithm -> InputStream ByteString -> IO MH.Digest
hash MH.SHA1 is = toBytes <$> (hashInputStream is :: IO (Digest CH.SHA1))
hash MH.SHA256 is = toBytes <$> (hashInputStream is :: IO (Digest CH.SHA256))
hash MH.SHA512 is = toBytes <$> (hashInputStream is :: IO (Digest CH.SHA512))
hash MH.SHA3 is = toBytes <$> (hashInputStream is :: IO (Digest CH.SHA3_256))
hash MH.SHA1 is = convert <$> (hashInputStream is :: IO (Digest CH.SHA1))
hash MH.SHA256 is = convert <$> (hashInputStream is :: IO (Digest CH.SHA256))
hash MH.SHA512 is = convert <$> (hashInputStream is :: IO (Digest CH.SHA512))
hash MH.SHA3 is = convert <$> (hashInputStream is :: IO (Digest CH.SHA3_256))
hash MH.BLAKE2B _ = undefined
hash MH.BLAKE2S _ = undefined

Expand Down
15 changes: 8 additions & 7 deletions multihash.cabal
Expand Up @@ -32,14 +32,14 @@ library
default-language: Haskell2010

build-depends: attoparsec >= 0.12 && < 0.14
, base >= 4.7 && < 4.10
, base >= 4.7 && < 5.0
-- , base32-bytestring >= 0.2 && < 0.3
, base58-bytestring >= 0.1 && < 0.2
, base64-bytestring >= 1.0 && < 1.1
, bytestring >= 0.10 && < 0.11
, cryptohash >= 0.11 && < 0.12
, cryptonite >= 0.24 && < 0.25
, hex >= 0.1 && < 0.2
, io-streams >= 1.2 && < 1.4
, io-streams >= 1.2 && < 1.6


executable multihash
Expand All @@ -49,14 +49,15 @@ executable multihash
ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2 -fdicts-cheap
-fno-warn-orphans -fno-warn-unused-do-bind -rtsopts

build-depends: base >= 4.7 && < 4.10
build-depends: base >= 4.7 && < 5.0
-- , base32-bytestring >= 0.2
, base64-bytestring >= 1.0 && < 1.1
, base58-bytestring >= 0.1 && < 0.2
, byteable >= 0.1 && < 0.2
, bytestring >= 0.10 && < 0.11
, cryptohash >= 0.11 && < 0.12
, cryptonite >= 0.24 && < 0.25
, hex >= 0.1 && < 0.2
, io-streams >= 1.2 && < 1.4
, io-streams >= 1.2 && < 1.6
, multihash >= 0.1 && < 0.2
, optparse-applicative >= 0.11 && < 0.14
, optparse-applicative >= 0.11 && < 0.15
, memory >= 0.14.11 && < 0.15.0
16 changes: 11 additions & 5 deletions src/System/IO/Streams/Crypto.hs
@@ -1,9 +1,15 @@
module System.IO.Streams.Crypto where

import Crypto.Hash (Digest, HashAlgorithm (..))
import Data.ByteString (ByteString)
import System.IO.Streams (InputStream, fold)
import Crypto.Hash
( Digest
, HashAlgorithm(..)
, hashFinalize
, hashInit
, hashUpdate
)
import Data.ByteString (ByteString)
import System.IO.Streams (InputStream, fold)

hashInputStream :: (HashAlgorithm h) => InputStream ByteString -> IO (Digest h)
hashInputStream = fmap hashFinalize . fold update hashInit
where update ctx bs = hashUpdates ctx [bs]
hashInputStream = fmap hashFinalize . fold hashUpdate hashInit

2 changes: 1 addition & 1 deletion stack.yaml
@@ -1,4 +1,4 @@
resolver: lts-8.15
resolver: lts-10.3
packages:
- '.'
extra-deps:
Expand Down

0 comments on commit 795a23b

Please sign in to comment.