restructuring
- renamed newSalt to newPWSalt - added PWSalt type - general style cleanup
This commit is contained in:
parent
098aaeb49f
commit
e28faacc13
|
@ -26,7 +26,7 @@ License along with this program. If not, see
|
||||||
|
|
||||||
module Password (
|
module Password (
|
||||||
-- * Data Types
|
-- * Data Types
|
||||||
PWDatabase, PWData(..), PWPolicy (..),
|
PWDatabase, PWData(..), PWPolicy (..), PWSalt,
|
||||||
-- ** Lenses
|
-- ** Lenses
|
||||||
-- $lenses
|
-- $lenses
|
||||||
-- *** PWData
|
-- *** PWData
|
||||||
|
@ -34,7 +34,7 @@ module Password (
|
||||||
-- *** PWPolicy
|
-- *** PWPolicy
|
||||||
pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
|
pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
|
||||||
-- ** Default Instances
|
-- ** Default Instances
|
||||||
newPWData, newPWPolicy, newSalt,
|
newPWData, newPWPolicy, newPWSalt,
|
||||||
-- * Functions
|
-- * Functions
|
||||||
validatePWPolicy
|
validatePWPolicy
|
||||||
) where
|
) where
|
||||||
|
@ -72,6 +72,9 @@ data PWPolicy = PWPolicy
|
||||||
-- if @"Nothing"@)
|
-- if @"Nothing"@)
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
|
-- | the "salt" used to generate a password
|
||||||
|
type PWSalt = B.ByteString
|
||||||
|
|
||||||
-- $lenses The following functions are automatically generated by
|
-- $lenses The following functions are automatically generated by
|
||||||
-- @makeLenses@. See the
|
-- @makeLenses@. See the
|
||||||
-- [lens](http://hackage.haskell.org/package/lens) package for further
|
-- [lens](http://hackage.haskell.org/package/lens) package for further
|
||||||
|
@ -80,10 +83,6 @@ data PWPolicy = PWPolicy
|
||||||
makeLenses ''PWPolicy
|
makeLenses ''PWPolicy
|
||||||
makeLenses ''PWData
|
makeLenses ''PWData
|
||||||
|
|
||||||
-- | default password policy
|
|
||||||
newPWPolicy :: PWPolicy
|
|
||||||
newPWPolicy = PWPolicy 16 0 0 0 (Just 0)
|
|
||||||
|
|
||||||
-- | builds a new @'PWData'@
|
-- | builds a new @'PWData'@
|
||||||
newPWData
|
newPWData
|
||||||
:: RandomGen g
|
:: RandomGen g
|
||||||
|
@ -93,16 +92,20 @@ newPWData
|
||||||
-- ^ the result and new random generator
|
-- ^ the result and new random generator
|
||||||
newPWData g = (result, g') where
|
newPWData g = (result, g') where
|
||||||
result = PWData newPWPolicy salt
|
result = PWData newPWPolicy salt
|
||||||
(salt, g') = newSalt g
|
(salt, g') = newPWSalt g
|
||||||
|
|
||||||
|
-- | default password policy
|
||||||
|
newPWPolicy :: PWPolicy
|
||||||
|
newPWPolicy = PWPolicy 16 0 0 0 (Just 0)
|
||||||
|
|
||||||
-- | builds a new salt
|
-- | builds a new salt
|
||||||
newSalt
|
newPWSalt
|
||||||
:: RandomGen g
|
:: RandomGen g
|
||||||
=> g
|
=> g
|
||||||
-- ^ the random generator to use
|
-- ^ the random generator to use
|
||||||
-> (B.ByteString, g)
|
-> (PWSalt, g)
|
||||||
-- ^ the result and new random number generator
|
-- ^ the result and new random generator
|
||||||
newSalt g = (result, g2) where
|
newPWSalt g = (result, g2) where
|
||||||
result = B.pack $ take 256 $ randoms g1
|
result = B.pack $ take 256 $ randoms g1
|
||||||
(g1, g2) = split g
|
(g1, g2) = split g
|
||||||
|
|
||||||
|
|
10
test/Spec.hs
10
test/Spec.hs
|
@ -27,8 +27,8 @@ import System.Exit (exitFailure)
|
||||||
import Test.HUnit (errors, failures, runTestTT, Test(TestList))
|
import Test.HUnit (errors, failures, runTestTT, Test(TestList))
|
||||||
|
|
||||||
import qualified Spec.NewPWData as NewPWData
|
import qualified Spec.NewPWData as NewPWData
|
||||||
import qualified Spec.NewSalt as NewSalt
|
import qualified Spec.NewPWPolicy as NewPWPolicy
|
||||||
import qualified Spec.PWPolicy as PWPolicy
|
import qualified Spec.NewPWSalt as NewPWSalt
|
||||||
import qualified Spec.ValidatePWPolicy as ValidatePWPolicy
|
import qualified Spec.ValidatePWPolicy as ValidatePWPolicy
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
|
@ -37,10 +37,10 @@ main = do
|
||||||
exitFailure
|
exitFailure
|
||||||
|
|
||||||
tests = TestList
|
tests = TestList
|
||||||
[ PWPolicy.tests
|
[ NewPWData.tests
|
||||||
|
, NewPWPolicy.tests
|
||||||
|
, NewPWSalt.tests
|
||||||
, ValidatePWPolicy.tests
|
, ValidatePWPolicy.tests
|
||||||
, NewSalt.tests
|
|
||||||
, NewPWData.tests
|
|
||||||
]
|
]
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
|
@ -35,7 +35,7 @@ tests = TestLabel "newPData" $ TestList
|
||||||
|
|
||||||
testSalt x = TestLabel "pwSalt" $
|
testSalt x = TestLabel "pwSalt" $
|
||||||
x^.pwSalt ~?= salt where
|
x^.pwSalt ~?= salt where
|
||||||
(salt, _) = newSalt g
|
(salt, _) = newPWSalt g
|
||||||
|
|
||||||
testPolicy x = TestLabel "pwPolicy" $
|
testPolicy x = TestLabel "pwPolicy" $
|
||||||
x^.pwPolicy ~?= newPWPolicy
|
x^.pwPolicy ~?= newPWPolicy
|
||||||
|
|
|
@ -20,7 +20,7 @@ License along with this program. If not, see
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Spec.PWPolicy (tests) where
|
module Spec.NewPWPolicy (tests) where
|
||||||
|
|
||||||
import Control.Lens ((^.))
|
import Control.Lens ((^.))
|
||||||
import Test.HUnit (Test(..), (~?=))
|
import Test.HUnit (Test(..), (~?=))
|
|
@ -20,7 +20,7 @@ License along with this program. If not, see
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Spec.NewSalt (tests) where
|
module Spec.NewPWSalt (tests) where
|
||||||
|
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import System.Random (mkStdGen)
|
import System.Random (mkStdGen)
|
||||||
|
@ -28,12 +28,12 @@ import Test.HUnit (Test(..), assertBool, (~?=))
|
||||||
|
|
||||||
import Password
|
import Password
|
||||||
|
|
||||||
tests = TestLabel "newSalt" $ TestList
|
tests = TestLabel "newPWSalt" $ TestList
|
||||||
[ testLength salt
|
[ testLength salt
|
||||||
, testDiff salt salt'
|
, testDiff salt salt'
|
||||||
] where
|
] where
|
||||||
(salt, g') = newSalt g
|
(salt, g') = newPWSalt g
|
||||||
(salt', _) = newSalt g'
|
(salt', _) = newPWSalt g'
|
||||||
g = mkStdGen 1
|
g = mkStdGen 1
|
||||||
|
|
||||||
testLength x = TestLabel "salt length" $ B.length x ~?= 256
|
testLength x = TestLabel "salt length" $ B.length x ~?= 256
|
Loading…
Reference in New Issue
Block a user