From cdff8c8917c2d19274a7282ce14f5efa3de930b2 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 1 Jan 2019 22:45:03 -0500 Subject: [PATCH] refactored mkHash --- ChangeLog.md | 1 + package.yaml | 1 + src/Password.hs | 6 ++---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 7aa86b9..d50f938 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,7 @@ - implemented manual saving - added a warning when changing master password +- some code cleanup as suggested by [Stephen Paul Weber](https://github.com/singpolyma) ## 0.1.1 diff --git a/package.yaml b/package.yaml index 01649c0..67f90e0 100644 --- a/package.yaml +++ b/package.yaml @@ -30,6 +30,7 @@ dependencies: library: source-dirs: src dependencies: + - base16-bytestring - base64-bytestring - SHA - text diff --git a/src/Password.hs b/src/Password.hs index b1ed861..ce2d0e3 100644 --- a/src/Password.hs +++ b/src/Password.hs @@ -59,6 +59,7 @@ import Data.Aeson , (.=) ) import qualified Data.ByteString.Lazy as B +import qualified Data.ByteString.Base16.Lazy as B16 import qualified Data.ByteString.Base64.Lazy as B64 import Data.Char (isUpper, isLower, isDigit, isAlphaNum, toLower) import Data.Digest.Pure.SHA @@ -338,10 +339,7 @@ mkSeed :: String -> PWData -> B.ByteString mkSeed pw d = toUTF8 pw `B.append` (d^.pwSalt) mkHash :: B.ByteString -> B.ByteString -mkHash = raw . show . sha256 where - raw (x:y:xs) = read ("0x" ++ [x] ++ [y]) `B.cons` raw xs - raw [_] = error "odd number of hex digits in hash" - raw "" = B.empty +mkHash = fst . B16.decode . encodeUtf8 . T.pack . show . sha256 nextPolicy :: Char -> PWPolicy -> PWPolicy nextPolicy x p = over pwLength pred $