hpg 0.6 → 0.7
raw patch · 5 files changed
+66/−27 lines, 5 files
Files
- OpenBSD/Compat.hs +20/−0
- README.md +3/−3
- hpg.1 +4/−4
- hpg.cabal +4/−2
- hpg.hs +35/−18
+ OpenBSD/Compat.hs view
@@ -0,0 +1,20 @@+{-|+ Copyright (c) 2017 Fritjof Bornebusch <fritjof@alokat.org>+ + Permission to use, copy, modify, and distribute this software for any+ purpose with or without fee is hereby granted, provided that the above+ copyright notice and this permission notice appear in all copies.+ + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.+-}++module OpenBSD.Compat ( pledge ) where++pledge :: Maybe String -> Maybe [FilePath] -> IO ()+pledge _promises _paths = return ()
README.md view
@@ -16,9 +16,9 @@ The **hpg** utility creates passwords of different sizes, between 1 and 2^16 characters. Please note that a-lenght of <8 is not very secure and should be avoided. That is why the default value is 16-if the command is called without any options. The default entropy contains lower and upper-case letters and numbers.+length of <8 is not very secure and should be avoided. For this reason the default password length+is 16 if the command is called without any options. The default entropy contains lower and upper+case letters as well as numbers. **-l**
hpg.1 view
@@ -25,10 +25,10 @@ .Sh DESCRIPTION The .Nm-utility creates passwords of different sizes, between 1 and 2^16 characters. Please note that a-lenght of <8 is not very secure and should be avoided. That is why the default value is 16-if the command is called without any options. The default entropy contains lower and upper-case letters and numbers.+utility creates passwords of different sizes, between 1 and 2^16 -1 characters. Please note that a+length of <8 is not very secure and should be avoided. For this reason the default password length+is 16 if the command is called without any options. The default entropy contains lower and upper+case letters as well as numbers. .Bl -tag -width Dsssigfile .It Fl l Enables lower case letters.
hpg.cabal view
@@ -1,5 +1,5 @@ name: hpg-version: 0.6+version: 0.7 synopsis: a simple password generator description: hpg is a free, open source password generator. It's design is pretty simple and it generates random passwords between@@ -30,6 +30,9 @@ executable hpg main-is: hpg.hs+ hs-source-dirs: .+ other-modules:+ OpenBSD.Compat -- use OpenBSDs pledge(2) if available if os(openbsd)@@ -38,7 +41,6 @@ build-depends: base >= 4.8 && < 4.10, random >= 1.0.1.1 && < 1.2 - hs-source-dirs: . default-language: Haskell2010 if flag(warn-as-error)
hpg.hs view
@@ -18,18 +18,23 @@ module Main ( main ) where +import Data.Word ( Word16 ) import System.Console.GetOpt ( ArgDescr(ReqArg, NoArg), ArgOrder(RequireOrder), getOpt, OptDescr(Option) ) import System.Environment ( getArgs ) import System.Exit ( exitFailure, exitSuccess )-import System.IO ( hPutStr, stderr, stdout )+import System.IO ( hPutStr, hPutStrLn, stderr, stdout ) #ifdef openbsd_HOST_OS import System.OpenBSD.Process ( pledge )+#else+import OpenBSD.Compat ( pledge ) #endif import System.Random ( randomRIO ) +default ( Word16 )+ upperCaseLettersList :: [Char] upperCaseLettersList = ['A'..'Z'] @@ -47,7 +52,7 @@ , optNumbersFlag :: Bool , optSpecialCharactersFlag :: Bool , optUpperCaseFlag :: Bool- , optLengthValue :: Int+ , optLengthValue :: Word16 } startOptions :: Options@@ -89,25 +94,40 @@ , Option "x" [] (ReqArg- (\arg opt -> return opt { optLengthValue = read arg })- "number")+ (\arg opt -> return opt { optLengthValue = do+ let value = read arg :: Integer+ case isWord16 value of+ True -> read arg+ _ -> 0+ })+ "length") "password length" ] +isWord16 :: Integer -> Bool+isWord16 n+ | n < toInteger(minBound::Word16) = False+ | n > toInteger(maxBound::Word16) = False+ | otherwise = True+ exitWithMessage :: String -> IO () exitWithMessage msg = do- hPutStr stderr (msg ++ "\n")+ hPutStrLn stderr msg exitFailure parse :: [String] -> IO ([Options -> IO Options], [String]) parse args = case getOpt RequireOrder options args of (actions, nonOptions,[]) -> return (actions, nonOptions)- (_,_,errors) -> ioError (userError (concat errors ++ header)) - where header = "usage: hpg [-lnsu]\n" ++ - " [-x number]"+ (_,_,errors) -> do+ hPutStrLn stderr (concat errors ++ header)+ exitFailure -randomList :: Int -> [Char] -> IO([Int])+ where header = "usage: hpg [-N]\n" +++ " [-lnsu]\n" ++ + " [-x length]"++randomList :: Word16 -> [Char] -> IO([Int]) randomList 0 _ = return [] randomList n list = do let l = length list@@ -115,7 +135,7 @@ rs <- randomList (n-1) list return (r:rs) -createPassword :: Int -> [Bool] -> IO [Char]+createPassword :: Word16 -> [Bool] -> IO [Char] createPassword lengthValue flags = do let l = createList [lowerCaseLettersList, numbersList,@@ -141,10 +161,7 @@ main :: IO () main = do--#ifdef openbsd_HOST_OS pledge (Just "stdio") Nothing-#endif (actions, _nonOptions) <- getArgs >>= parse opts <- foldl (>>=) (return startOptions) actions@@ -155,13 +172,13 @@ , optUpperCaseFlag = upperCase , optLengthValue = lengthValue } = opts - if lengthValue > 2^(16::Int)- then exitWithMessage "password too long"+ if lengthValue == 0+ then exitWithMessage "invalid password length" else do pwd <- createPassword lengthValue [lowerCase,- numbers,- specialCharacters,- upperCase]+ numbers,+ specialCharacters,+ upperCase] hPutStr stdout pwd case noNewLine of