elocrypt 0.4.0 → 0.4.1
raw patch · 7 files changed
+54/−13 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +5/−0
- cli-test/Tests.hs +19/−1
- elocrypt.cabal +2/−2
- src/cli/Main.hs +9/−4
- src/lib/Data/Elocrypt.hs +5/−2
- test/Test/Elocrypt/Instances.hs +6/−0
- test/Test/ElocryptTest.hs +8/−4
README.md view
@@ -14,6 +14,11 @@ cabal install elocrypt ``` +Binaries are also available:+ * [elocrypt-0.4.0-linux-bin.tar.gz](https://github.com/sgillespie/elocrypt/releases/download/v0.4.0/elocrypt-0.4.0-linux-bin.tar.gz)+ * [elocrypt-0.4.0-osx-bin.tar.gz](https://github.com/sgillespie/elocrypt/releases/download/v0.4.0/elocrypt-0.4.0-osx-bin.tar.gz)+ * [elocrypt-0.4.0-windows-bin.exe](https://github.com/sgillespie/elocrypt/releases/download/v0.4.0/elocrypt-0.4.0-windows-bin.exe)+ ## Running Running elocrypt is as simple as: ```
cli-test/Tests.hs view
@@ -36,7 +36,7 @@ instance Arbitrary CliArgs where arbitrary = do- len <- arbitrary `suchThat` (>2) `suchThat` (<=40) :: Gen Int+ len <- arbitrary `suchThat` (>0) `suchThat` (<=40) :: Gen Int num <- arbitrary `suchThat` (>2) `suchThat` (<=20) :: Gen Int args <- sublistOf ["-n %d" `printf` num, show len]@@ -82,6 +82,24 @@ (in', out', err', p) <- run' "dist/build/elocrypt/elocrypt" args response <- readHandle out' return . all (>1) . tail . reverse . map length . map words . lines $ response++prop_shouldNotPrintZeroPasswords :: CliArgs -> Property+prop_shouldNotPrintZeroPasswords (CliArgs args)+ = isNothing (getPosParam args) ==>+ ioProperty $ do+ let args' = args ++ ["0"]+ + (in', out', err', p) <- run' "dist/build/elocrypt/elocrypt" args'+ response <- readHandle out'+ return (response == "")++prop_shouldPrintLongPasswords :: GreaterThan79 Int -> Property+prop_shouldPrintLongPasswords (GT79 a)+ = ioProperty $ do+ (in', out', err', p) <- run' "dist/build/elocrypt/elocrypt" [show a]+ response <- readHandle out'+ return . all (==1) . map length . map words . lines $ response+ -- Utility functions run' :: FilePath -> [String] -> IO (Handle, Handle, Handle, ProcessHandle)
elocrypt.cabal view
@@ -1,5 +1,5 @@ name: elocrypt-version: 0.4.0+version: 0.4.1 synopsis: Generate easy-to-remember, hard-to-guess passwords homepage: https://www.github.com/sgillespie/elocrypt license: OtherLicense@@ -26,7 +26,7 @@ source-repository this type: git location: https://github.com/sgillespie/elocrypt.git- tag: v0.4.0+ tag: v0.4.1 library exposed-modules: Data.Elocrypt,
src/cli/Main.hs view
@@ -11,7 +11,7 @@ import Data.Elocrypt -version = "elocrypt 0.4.0"+version = "elocrypt 0.4.1" termLen = 80 termHeight = 10 @@ -28,14 +28,19 @@ hPutStrLn stderr version exitSuccess - putStrLn (passwords opts gen)+ -- TODO[sgillespie]: REFACTOR ME?+ if (optLength opts == 0)+ then exitSuccess+ else putStrLn (passwords opts gen) passwords :: RandomGen g => Options -> g -> String passwords opts gen = format . group' cols $ ps where ps = take num . newPasswords (optLength opts) $ gen format = concat . intersperse "\n" . map (concat . intersperse " ")- cols = termLen `div` (optLength opts + 2)- num = fromMaybe (cols * termHeight) (optNumber opts)+ cols = if optLength opts <= termLen - 2+ then termLen `div` (optLength opts + 2)+ else 1+ num = fromMaybe ((if cols == 0 then 1 else cols) * termHeight) (optNumber opts) group' :: Int -> [a] -> [[a]] group' _ [] = []
src/lib/Data/Elocrypt.hs view
@@ -85,8 +85,11 @@ mkPassword :: MonadRandom m => Int -- ^ password length -> m String-mkPassword len = first2 >>= reverse' >>= lastN (len - 2) >>= reverse'- where reverse' = return . reverse+mkPassword len = do+ f2 <- reverse `liftM` first2+ if len > 2+ then reverse `liftM` lastN (len - 2) f2+ else return . reverse . take len $ f2 -- |Plural version of mkPassword. Generate an infinite list of passwords using -- the MonadRandom m. MonadRandom is exposed here for extra control.
test/Test/Elocrypt/Instances.hs view
@@ -18,3 +18,9 @@ instance (Num a, Ord a, Arbitrary a) => Arbitrary (GreaterThan2 a) where arbitrary = GT2 `fmap` (arbitrary `suchThat` (>2))++newtype GreaterThan79 a = GT79 { getGT79 :: a }+ deriving (Eq, Ord, Show)++instance (Integral a, Random a) => Arbitrary (GreaterThan79 a) where+ arbitrary = GT79 `fmap` choose (80, 500)
test/Test/ElocryptTest.hs view
@@ -25,17 +25,21 @@ = p /= ps where (p:ps:_) = fst (genPasswords len gen) -prop_newPasswordShouldBeLength :: GreaterThan2 Int -> StdGen -> Bool-prop_newPasswordShouldBeLength (GT2 len) gen = length (newPassword len gen) == len+prop_newPasswordShouldBeLength :: Int -> StdGen -> Property+prop_newPasswordShouldBeLength len gen = len > 0 ==> length (newPassword len gen) == len -prop_newPasswordShouldConsistOfAlphabet :: GreaterThan2 Int -> StdGen -> Bool-prop_newPasswordShouldConsistOfAlphabet (GT2 len) gen+prop_newPasswordShouldConsistOfAlphabet :: Int -> StdGen -> Bool+prop_newPasswordShouldConsistOfAlphabet len gen = all ((flip elem) alphabet) (newPassword len gen) prop_newPasswordsShouldBeUnique :: GreaterThan2 Int -> StdGen -> Bool prop_newPasswordsShouldBeUnique (GT2 len) gen = p /= ps where (p:ps:_) = newPasswords len gen++prop_newPasswordShouldHaveLen :: Int -> StdGen -> Property+prop_newPasswordShouldHaveLen len gen+ = len >= 0 ==> length (newPassword len gen) == len prop_first2ShouldHaveLength2 :: StdGen -> Bool prop_first2ShouldHaveLength2 g = length (evalRand first2 g) == 2