Skip to content

Commit

Permalink
Merge pull request #81 from Vlix/moving-over-to-crypton-backend
Browse files Browse the repository at this point in the history
Moving over to `crypton` backend
  • Loading branch information
Vlix authored Oct 19, 2024
2 parents db4cd2e + 1053817 commit a17a93c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 36 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
cabal:
name: cabal / ghc-${{matrix.ghc}} / ${{ matrix.os }}
continue-on-error: ${{ matrix.ghc == '9.10.1'}}
continue-on-error: ${{ matrix.ghc == '9.10.1' }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -21,22 +21,25 @@ jobs:
- "9.0.2"
- "9.2.8"
- "9.4.8"
- "9.6.5"
- "9.6.6"
- "9.8.2"
- "9.10.1"
exclude:
os: macOS-latest
ghc: "9.0.2"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
#if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master'

- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache cabal-store
with:
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
Expand Down Expand Up @@ -68,20 +71,20 @@ jobs:
- "--resolver lts-19" # GHC 9.0.2
- "--resolver lts-20" # GHC 9.2.8
- "--resolver lts-21" # GHC 9.4.8
- "--resolver lts-22" # GHC 9.6.5
- "--resolver lts-22" # GHC 9.6.6
- "--resolver nightly" # GHC 9.8.2

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
#if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master'

- uses: haskell/actions/setup@v2
- uses: haskell-actions/setup@v2
name: Setup Haskell Stack
with:
stack-version: ${{ matrix.stack }}
enable-stack: true

- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache ~/.stack
with:
path: ~/.stack
Expand Down
2 changes: 1 addition & 1 deletion password-cli/password-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ executable password-cli
build-depends:
base
, bytestring >= 0.9 && < 1
, password ^>= 3.0.3.0
, password ^>= 3.0.3.0 || ^>= 3.1.0.0
, password-types ^>= 1.0
, optparse-applicative >= 0.14.3 && < 0.19
, text >= 1.2 && < 3
Expand Down
8 changes: 8 additions & 0 deletions password/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog for `password`

## 3.1.0.0

- Switched default cryptographic backend library from `cryptonite` to `crypton`.
The `crypton` flag is now a no-op, and the `cryptonite` flag is needed to build
the `password` library using the `cryptonite` library.
Thanks to [@Vlix](https://github.com/Vlix)
[#81](https://github.com/cdepillabout/password/pull/81)

## 3.0.4.0

- Support `base64` package up to and including `base64-1.0`.
Expand Down
31 changes: 14 additions & 17 deletions password/password.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 1.12

name: password
version: 3.0.4.0
version: 3.1.0.0
category: Data
synopsis: Hashing and checking of passwords
description:
Expand Down Expand Up @@ -58,13 +58,13 @@ flag bcrypt

flag crypton
description: Use the [crypton] library as the cryptographic backend.
(Does nothing since version 3.1.0.0; might be removed in a future major version)
default: False
manual: True

flag cryptonite
description:
Use the [cryptonite] library as the cryptographic backend.
(Does nothing until a future major version)
default: False
manual: True

Expand Down Expand Up @@ -120,15 +120,12 @@ library
-Wall
default-language:
Haskell2010
-- At some future major version bump, this should
-- be changed to the [cryptonite] flag and that
-- `if flag(cryptonite) build-depends: cryptonite`
if flag(crypton)
if flag(cryptonite)
build-depends:
crypton >= 0.31 && < 1.1
cryptonite >= 0.15.1 && < 0.31
else
build-depends:
cryptonite >= 0.15.1 && < 0.31
crypton >= 0.31 && < 1.1

test-suite doctests
type:
Expand All @@ -143,10 +140,8 @@ test-suite doctests
base >=4.9 && <5
, base-compat
, doctest
, password
, QuickCheck
, quickcheck-instances
, template-haskell
default-language:
Haskell2010

Expand Down Expand Up @@ -195,14 +190,19 @@ test-suite password-tasty
, bytestring
, memory
, quickcheck-instances
, scrypt
, tasty
, tasty-hunit
, tasty-quickcheck
, template-haskell
, text
default-language:
Haskell2010

if os(darwin)
cpp-options: -DIS_MAC_OS
else
build-depends: scrypt

if flag(argon2)
cpp-options:
-DCABAL_FLAG_argon2
Expand All @@ -215,12 +215,9 @@ test-suite password-tasty
if flag(scrypt)
cpp-options:
-DCABAL_FLAG_scrypt
-- At some future major version bump, this should
-- be changed to the [cryptonite] flag and that
-- `if flag(cryptonite) build-depends: cryptonite`
if flag(crypton)
if flag(cryptonite)
build-depends:
crypton
cryptonite
else
build-depends:
cryptonite
crypton
5 changes: 3 additions & 2 deletions password/src/Data/Password/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ module Data.Password.Validate

import Data.Char (chr, isAsciiLower, isAsciiUpper, isDigit, ord)
import Data.Function (on)
import Data.List (foldl')

#if !MIN_VERSION_base(4,20,0)
import Data.Foldable (foldl')
#endif
import Data.Text (Text)
import qualified Data.Text as T
import Language.Haskell.TH (Exp, Q, appE)
Expand Down
7 changes: 7 additions & 0 deletions password/test/tasty/Scrypt.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
module Scrypt where

import Data.Maybe (fromJust)
Expand All @@ -7,7 +8,9 @@ import Test.Tasty
import Test.Tasty.QuickCheck
import Test.QuickCheck.Instances.Text ()

#ifndef IS_MAC_OS
import qualified Crypto.Scrypt as Scrypt
#endif
import Data.Password.Types
import Data.Password.Scrypt

Expand All @@ -24,14 +27,17 @@ testScrypt = testGroup "scrypt"
checkPassword
extractParams
testsParams8Rounds
#ifndef IS_MAC_OS
, testProperty "scrypt <-> cryptonite" $ withMaxSuccess 10 checkScrypt
#endif
]
where
hash8Rounds = hashPasswordWithParams testsParams8Rounds
testsParams8Rounds = defaultParams{ scryptRounds = 8, scryptSalt = 16 }
hash4Rounds = hashPasswordWithParams testsParams4Rounds
testsParams4Rounds = defaultParams{ scryptRounds = 4, scryptSalt = 16 }

#ifndef IS_MAC_OS
checkScrypt :: Text -> Property
checkScrypt pass = ioProperty $ do
s@(Scrypt.Salt salt) <- Scrypt.newSalt
Expand All @@ -41,3 +47,4 @@ checkScrypt pass = ioProperty $ do
PasswordHash ourHash =
hashPasswordWithSalt defaultParams{ scryptRounds = 8 } (Salt salt) $ mkPassword pass
return $ scryptHash === encodeUtf8 ourHash
#endif
5 changes: 3 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-22.24
resolver: lts-22.38

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand All @@ -41,7 +41,8 @@ packages:
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
extra-deps: []
extra-deps:
- crypton-1.0.1

# Override default flag values for local packages and extra-deps
# flags: {}
Expand Down
17 changes: 12 additions & 5 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
packages:
- completed:
hackage: crypton-1.0.1@sha256:f41316fbc6ad878396e476355e27b70ac35c344d74e3eefafe709e03b192be9e,14527
pantry-tree:
sha256: b8f0a33755a0871d325300024592cd9306e393941248184e9c4faf417d4adfcd
size: 23276
original:
hackage: crypton-1.0.1
snapshots:
- completed:
sha256: 28a863b358647f2d952fe7085ba11561aeb63eca6bc6fd1ce8fcf1cfe63717f5
size: 719127
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/24.yaml
original: lts-22.24
sha256: 0964f3e2c04e21abf42e271490e6974bc923aac2f2fd595fcb53ad0c237dbed1
size: 720034
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/38.yaml
original: lts-22.38

0 comments on commit a17a93c

Please sign in to comment.