-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control exposing hashing algorithms using Cabal flags #63
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e5f6100
Put all hashing algorithms behind Cabal flags
ivanbakel d6800fd
Expose Data.Password.Internal source code to tests
ivanbakel 54d924a
Version bump, ChangeLog update
ivanbakel 1b9d29c
Merge remote-tracking branch 'origin/master' into cabal-flags
ivanbakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
cabal-version: 1.12 | ||
|
||
name: password | ||
version: 3.0.2.0 | ||
version: 3.0.2.1 | ||
category: Data | ||
synopsis: Hashing and checking of passwords | ||
description: | ||
|
@@ -46,6 +46,26 @@ extra-source-files: | |
README.md | ||
ChangeLog.md | ||
|
||
flag argon2 | ||
description: Compile with argon2 support? | ||
default: True | ||
manual: True | ||
|
||
flag bcrypt | ||
description: Compile with Scrypt support? | ||
default: True | ||
manual: True | ||
|
||
flag pbkdf2 | ||
description: Compile with PBKDF2 support? | ||
default: True | ||
manual: True | ||
|
||
flag scrypt | ||
description: Compile with Scrypt support? | ||
default: True | ||
manual: True | ||
|
||
custom-setup | ||
setup-depends: | ||
base | ||
|
@@ -60,11 +80,19 @@ library | |
hs-source-dirs: | ||
src | ||
exposed-modules: | ||
Data.Password.Argon2 | ||
Data.Password.Bcrypt | ||
Data.Password.PBKDF2 | ||
Data.Password.Scrypt | ||
Data.Password.Validate | ||
if flag(argon2) | ||
exposed-modules: | ||
Data.Password.Argon2 | ||
if flag(bcrypt) | ||
exposed-modules: | ||
Data.Password.Bcrypt | ||
if flag(pbkdf2) | ||
exposed-modules: | ||
Data.Password.PBKDF2 | ||
if flag(scrypt) | ||
exposed-modules: | ||
Data.Password.Scrypt | ||
other-modules: | ||
Paths_password | ||
Data.Password.Internal | ||
|
@@ -106,22 +134,33 @@ test-suite password-tasty | |
type: | ||
exitcode-stdio-1.0 | ||
hs-source-dirs: | ||
src | ||
test/tasty | ||
main-is: | ||
Spec.hs | ||
other-modules: | ||
Argon2 | ||
, Bcrypt | ||
Data.Password.Internal | ||
, Internal | ||
, PBKDF2 | ||
, Scrypt | ||
, TestPolicy | ||
, Validate | ||
, Paths_password | ||
if flag(argon2) | ||
other-modules: | ||
Argon2 | ||
if flag(bcrypt) | ||
other-modules: | ||
Bcrypt | ||
if flag(pbkdf2) | ||
other-modules: | ||
PBKDF2 | ||
if flag(scrypt) | ||
other-modules: | ||
Scrypt | ||
ghc-options: | ||
-threaded -O2 -rtsopts -with-rtsopts=-N | ||
build-depends: | ||
base >=4.9 && <5 | ||
, base64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did this suddenly come from? Is this (together with |
||
, password | ||
, password-types | ||
, bytestring | ||
|
@@ -132,6 +171,19 @@ test-suite password-tasty | |
, tasty | ||
, tasty-hunit | ||
, tasty-quickcheck | ||
, template-haskell | ||
, text | ||
default-language: | ||
Haskell2010 | ||
if flag(argon2) | ||
cpp-options: | ||
-DCABAL_FLAG_argon2 | ||
if flag(bcrypt) | ||
cpp-options: | ||
-DCABAL_FLAG_bcrypt | ||
if flag(pbkdf2) | ||
cpp-options: | ||
-DCABAL_FLAG_pbkdf2 | ||
if flag(scrypt) | ||
cpp-options: | ||
-DCABAL_FLAG_scrypt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import Test.Tasty.Runners (NumThreads(..)) | ||
|
||
import Data.Password.Types | ||
|
||
#ifdef CABAL_FLAG_argon2 | ||
import Argon2 (testArgon2) | ||
#endif | ||
#ifdef CABAL_FLAG_bcrypt | ||
import Bcrypt (testBcrypt) | ||
#endif | ||
#ifdef CABAL_FLAG_pbkdf2 | ||
import PBKDF2 (testPBKDF2) | ||
#endif | ||
#ifdef CABAL_FLAG_scrypt | ||
import Scrypt (testScrypt) | ||
#endif | ||
import Validate (testValidate) | ||
|
||
main :: IO () | ||
main = defaultMain $ localOption (NumThreads 1) $ | ||
testGroup "Password" | ||
[ testProperty "Password" $ \pass -> | ||
unsafeShowPassword (mkPassword pass) === pass | ||
#ifdef CABAL_FLAG_argon2 | ||
, testArgon2 | ||
#endif | ||
#ifdef CABAL_FLAG_bcrypt | ||
, testBcrypt | ||
#endif | ||
#ifdef CABAL_FLAG_pbkdf2 | ||
, testPBKDF2 | ||
#endif | ||
#ifdef CABAL_FLAG_scrypt | ||
, testScrypt | ||
#endif | ||
, testValidate | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this PR! This seems reasonable to me.
I don't feel super strongly either way, but I think I'd prefer to remove all of the changes in this PR for the tests. If end-users want to disable certain algorithms, then it is okay to me if they can't run the test suite.
Or, you could possibly set the test suite as non-buildable if any of the flags is disabled.
Maybe @Vlix has a strong opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see why you'd want this.
I do have strong opinions about the implementation, but no big reservations about adding this functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdepillabout if you meant if I have strong opinions about adding the flags to the test suite or not, I don't see why we'd make the test-suite non-buildable. Just testing what's "activated" seems like an ok decision (even though it adds flags and CPP to the test suite 🤷 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to implement this in either way, but having a subset of tests be runnable was nice for me, since it checked that the remaining algorithms still worked as expected on Mac.