packages feed

sha1 0.1.1.0 → 0.1.1.1

raw patch · 5 files changed

+104/−71 lines, 5 filesdep ~natural-arithmeticdep ~run-stsetup-changednew-uploaderPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: natural-arithmetic, run-st

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for sha1 +## 0.1.1.1 -- 2024-01-31++* Update package metadata.+ ## 0.1.1.0 -- 2023-07-27  * Add function for encoding to `ByteArrayN`.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
sha1.cabal view
@@ -1,50 +1,56 @@-cabal-version: 2.2-name: sha1-version: 0.1.1.0-synopsis: SHA-1 Hash+cabal-version:      2.2+name:               sha1+version:            0.1.1.1+synopsis:           SHA-1 Hash description:   This library is a copy of cryptohash-sha1 that works on GC-managed   byte arrays instead of ByteString. The C code is a copied from   that library. If you find an issue with the C code, you should   open an issue on cryptohash-sha1.-homepage: https://github.com/byteverse/sha1-bug-reports: https://github.com/byteverse/sha1/issues-license: BSD-3-Clause-license-file: LICENSE-author: Andrew Martin-maintainer: andrew.thaddeus@gmail.com-copyright: 2020 Andrew Martin-category: Data-build-type: Simple-extra-source-files:-  CHANGELOG.md-  cbits/sha1.h +homepage:           https://github.com/byteverse/sha1+bug-reports:        https://github.com/byteverse/sha1/issues+license:            BSD-3-Clause+license-file:       LICENSE+author:             Andrew Martin+maintainer:         amartin@layer3com.com+copyright:          2020 Andrew Martin+category:           Data+build-type:         Simple+extra-source-files: cbits/sha1.h+extra-doc-files:    CHANGELOG.md+ library-  c-sources: cbits/sha1.c-  cc-options: -Wall -O3-  include-dirs: cbits-  hs-source-dirs: src-  exposed-modules: Hash.Sha1+  c-sources:        cbits/sha1.c+  cc-options:       -Wall+  include-dirs:     cbits+  hs-source-dirs:   src+  exposed-modules:  Hash.Sha1   build-depends:-    , base >=4.12 && <5-    , primitive >=0.7 && <0.8-    , bytebuild >=0.3.4 && <0.4-    , byteslice >=0.2.11.1 && <0.3-    , run-st >=0.1.3+    , base       >=4.12     && <5+    , bytebuild  >=0.3.4    && <0.4+    , byteslice  >=0.2.11.1 && <0.3+    , primitive  >=0.7      && <0.10+    , run-st     >=0.1.3    && <0.2+   default-language: Haskell2010-  ghc-options: -O2 -Wall+  ghc-options:      -O2 -Wall  test-suite test-  Default-Language: Haskell2010-  hs-source-dirs: test-  main-is: Main.hs-  type: exitcode-stdio-1.0+  default-language: Haskell2010+  hs-source-dirs:   test+  main-is:          Main.hs+  type:             exitcode-stdio-1.0   build-depends:     , base-    , bytebuild >=0.3.4-    , byteslice >=0.1.4.0-    , natural-arithmetic >=0.1.1+    , bytebuild           >=0.3.4+    , byteslice           >=0.1.4.0+    , natural-arithmetic  >=0.1.1   && <0.2     , primitive     , sha1-  ghc-options: -O2 -Wall++  ghc-options:      -O2 -Wall++source-repository head+  type:     git+  location: git://github.com/byteverse/sha1.git
src/Hash/Sha1.hs view
@@ -1,6 +1,6 @@-{-# language DataKinds #-}-{-# language MagicHash #-}-{-# language UnliftedFFITypes #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnliftedFFITypes #-}  module Hash.Sha1   ( boundedBuilder@@ -11,9 +11,9 @@ import Control.Monad.ST.Run (runByteArrayST) import Data.Bytes.Builder.Bounded as BB import Data.Bytes.Builder.Bounded.Unsafe as BBU-import Data.Bytes.Types (Bytes(Bytes),ByteArrayN(ByteArrayN))-import Data.Primitive (ByteArray(..),MutableByteArray(..))-import GHC.Exts (Int(I#),Int#,MutableByteArray#,ByteArray#)+import Data.Bytes.Types (ByteArrayN (ByteArrayN), Bytes (Bytes))+import Data.Primitive (ByteArray (..), MutableByteArray (..))+import GHC.Exts (ByteArray#, Int (I#), Int#, MutableByteArray#) import GHC.IO (unsafeIOToST)  import qualified Data.Primitive as PM@@ -27,14 +27,16 @@  -- | Hash the byte sequence, returning the result as a builder. boundedBuilder :: Bytes -> BB.Builder 20-boundedBuilder (Bytes arr off len) = BBU.construct-  (\buf ix -> do-    performHash buf ix arr off len-    pure (ix + 20)-  )+boundedBuilder (Bytes arr off len) =+  BBU.construct+    ( \buf ix -> do+        performHash buf ix arr off len+        pure (ix + 20)+    ) --- | Hash the byte sequence, returning the result as a byte array--- known to have exactly 20 bytes.+{- | Hash the byte sequence, returning the result as a byte array+known to have exactly 20 bytes.+-} byteArrayN :: Bytes -> ByteArrayN 20 byteArrayN (Bytes arr off len) = ByteArrayN $ runByteArrayST $ do   dst <- PM.newByteArray 20
test/Main.hs view
@@ -1,12 +1,13 @@-{-# language BangPatterns #-}+{-# LANGUAGE BangPatterns #-}  import Data.Primitive (ByteArray) import Data.Word (Word8) import Numeric (showHex)  import qualified Arithmetic.Nat as Nat-import qualified Data.Bytes.Builder.Bounded as BB import qualified Data.Bytes as Bytes+import qualified Data.Bytes.Builder.Bounded as BB+import qualified Data.Bytes.Text.Ascii as Ascii import qualified Data.Primitive as PM import qualified GHC.Exts as Exts import qualified Hash.Sha1 as Sha1@@ -23,27 +24,49 @@     else fail "Did not match"  printHash :: ByteArray -> IO ()-printHash !b = putStr (go 0) where-  go !ix = if ix < 20-    then let val = PM.indexByteArray b ix :: Word8 in-      if val < 16-        then '0' : showHex val (go (ix + 1))-        else showHex val (go (ix + 1))-    else "\n"+printHash !b = putStr (go 0)+ where+  go !ix =+    if ix < 20+      then+        let val = PM.indexByteArray b ix :: Word8+         in if val < 16+              then '0' : showHex val (go (ix + 1))+              else showHex val (go (ix + 1))+      else "\n"  actual :: ByteArray-actual = BB.run Nat.constant-  (Sha1.boundedBuilder-    (Bytes.unsafeDrop 5-      (Bytes.fromAsciiString "12345theoceanscovertheearth")+actual =+  BB.run+    Nat.constant+    ( Sha1.boundedBuilder+        ( Bytes.unsafeDrop+            5+            (Ascii.fromString "12345theoceanscovertheearth")+        )     )-  )  expected :: ByteArray-expected = Exts.fromList-  [ 0x2d, 0x4c, 0xbf, 0xa2-  , 0x04, 0xb2, 0x0a, 0xda-  , 0x06, 0xee, 0xbf, 0x8b-  , 0x2c, 0x22, 0x23, 0x0c-  , 0x51, 0xe7, 0x55, 0x8f-  ]+expected =+  Exts.fromList+    [ 0x2d+    , 0x4c+    , 0xbf+    , 0xa2+    , 0x04+    , 0xb2+    , 0x0a+    , 0xda+    , 0x06+    , 0xee+    , 0xbf+    , 0x8b+    , 0x2c+    , 0x22+    , 0x23+    , 0x0c+    , 0x51+    , 0xe7+    , 0x55+    , 0x8f+    ]