implemented newPWData
This commit is contained in:
parent
72d8609674
commit
098aaeb49f
|
@ -34,7 +34,7 @@ module Password (
|
|||
-- *** PWPolicy
|
||||
pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
|
||||
-- ** Default Instances
|
||||
newPWPolicy, newSalt,
|
||||
newPWData, newPWPolicy, newSalt,
|
||||
-- * Functions
|
||||
validatePWPolicy
|
||||
) where
|
||||
|
@ -84,6 +84,17 @@ makeLenses ''PWData
|
|||
newPWPolicy :: PWPolicy
|
||||
newPWPolicy = PWPolicy 16 0 0 0 (Just 0)
|
||||
|
||||
-- | builds a new @'PWData'@
|
||||
newPWData
|
||||
:: RandomGen g
|
||||
=> g
|
||||
-- ^ the random generator to use
|
||||
-> (PWData, g)
|
||||
-- ^ the result and new random generator
|
||||
newPWData g = (result, g') where
|
||||
result = PWData newPWPolicy salt
|
||||
(salt, g') = newSalt g
|
||||
|
||||
-- | builds a new salt
|
||||
newSalt
|
||||
:: RandomGen g
|
||||
|
|
|
@ -26,6 +26,7 @@ import Control.Monad (when)
|
|||
import System.Exit (exitFailure)
|
||||
import Test.HUnit (errors, failures, runTestTT, Test(TestList))
|
||||
|
||||
import qualified Spec.NewPWData as NewPWData
|
||||
import qualified Spec.NewSalt as NewSalt
|
||||
import qualified Spec.PWPolicy as PWPolicy
|
||||
import qualified Spec.ValidatePWPolicy as ValidatePWPolicy
|
||||
|
@ -39,6 +40,7 @@ tests = TestList
|
|||
[ PWPolicy.tests
|
||||
, ValidatePWPolicy.tests
|
||||
, NewSalt.tests
|
||||
, NewPWData.tests
|
||||
]
|
||||
|
||||
--jl
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
{-
|
||||
|
||||
passman
|
||||
Copyright (C) 2018 Jonathan Lamothe
|
||||
<jlamothe1980@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this program. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
-}
|
||||
|
||||
module Spec.NewPWData (tests) where
|
||||
|
||||
import Control.Lens ((^.))
|
||||
import System.Random (mkStdGen)
|
||||
import Test.HUnit (Test (..), (~?=))
|
||||
|
||||
import Password
|
||||
|
||||
tests = TestLabel "newPData" $ TestList
|
||||
[ testSalt x
|
||||
, testPolicy x
|
||||
] where (x, _) = newPWData g
|
||||
|
||||
testSalt x = TestLabel "pwSalt" $
|
||||
x^.pwSalt ~?= salt where
|
||||
(salt, _) = newSalt g
|
||||
|
||||
testPolicy x = TestLabel "pwPolicy" $
|
||||
x^.pwPolicy ~?= newPWPolicy
|
||||
|
||||
g = mkStdGen 1
|
||||
|
||||
--jl
|
Loading…
Reference in New Issue
Block a user