restructuring

- renamed newSalt to newPWSalt
- added PWSalt type
- general style cleanup
This commit is contained in:
Jonathan Lamothe
2018-12-18 14:19:19 -05:00
parent 098aaeb49f
commit e28faacc13
5 changed files with 25 additions and 22 deletions

View File

@@ -26,7 +26,7 @@ License along with this program. If not, see
module Password (
-- * Data Types
PWDatabase, PWData(..), PWPolicy (..),
PWDatabase, PWData(..), PWPolicy (..), PWSalt,
-- ** Lenses
-- $lenses
-- *** PWData
@@ -34,7 +34,7 @@ module Password (
-- *** PWPolicy
pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
-- ** Default Instances
newPWData, newPWPolicy, newSalt,
newPWData, newPWPolicy, newPWSalt,
-- * Functions
validatePWPolicy
) where
@@ -72,6 +72,9 @@ data PWPolicy = PWPolicy
-- if @"Nothing"@)
} deriving (Eq, Show)
-- | the "salt" used to generate a password
type PWSalt = B.ByteString
-- $lenses The following functions are automatically generated by
-- @makeLenses@. See the
-- [lens](http://hackage.haskell.org/package/lens) package for further
@@ -80,10 +83,6 @@ data PWPolicy = PWPolicy
makeLenses ''PWPolicy
makeLenses ''PWData
-- | default password policy
newPWPolicy :: PWPolicy
newPWPolicy = PWPolicy 16 0 0 0 (Just 0)
-- | builds a new @'PWData'@
newPWData
:: RandomGen g
@@ -93,16 +92,20 @@ newPWData
-- ^ the result and new random generator
newPWData g = (result, g') where
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
newSalt
newPWSalt
:: RandomGen g
=> g
-- ^ the random generator to use
-> (B.ByteString, g)
-- ^ the result and new random number generator
newSalt g = (result, g2) where
-> (PWSalt, g)
-- ^ the result and new random generator
newPWSalt g = (result, g2) where
result = B.pack $ take 256 $ randoms g1
(g1, g2) = split g