refactored mkHash

This commit is contained in:
Jonathan Lamothe 2019-01-01 22:45:03 -05:00
parent f305822ae1
commit cdff8c8917
3 changed files with 4 additions and 4 deletions

@ -4,6 +4,7 @@
- implemented manual saving - implemented manual saving
- added a warning when changing master password - added a warning when changing master password
- some code cleanup as suggested by [Stephen Paul Weber](https://github.com/singpolyma)
## 0.1.1 ## 0.1.1

@ -30,6 +30,7 @@ dependencies:
library: library:
source-dirs: src source-dirs: src
dependencies: dependencies:
- base16-bytestring
- base64-bytestring - base64-bytestring
- SHA - SHA
- text - text

@ -59,6 +59,7 @@ import Data.Aeson
, (.=) , (.=)
) )
import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Base16.Lazy as B16
import qualified Data.ByteString.Base64.Lazy as B64 import qualified Data.ByteString.Base64.Lazy as B64
import Data.Char (isUpper, isLower, isDigit, isAlphaNum, toLower) import Data.Char (isUpper, isLower, isDigit, isAlphaNum, toLower)
import Data.Digest.Pure.SHA import Data.Digest.Pure.SHA
@ -338,10 +339,7 @@ mkSeed :: String -> PWData -> B.ByteString
mkSeed pw d = toUTF8 pw `B.append` (d^.pwSalt) mkSeed pw d = toUTF8 pw `B.append` (d^.pwSalt)
mkHash :: B.ByteString -> B.ByteString mkHash :: B.ByteString -> B.ByteString
mkHash = raw . show . sha256 where mkHash = fst . B16.decode . encodeUtf8 . T.pack . show . sha256
raw (x:y:xs) = read ("0x" ++ [x] ++ [y]) `B.cons` raw xs
raw [_] = error "odd number of hex digits in hash"
raw "" = B.empty
nextPolicy :: Char -> PWPolicy -> PWPolicy nextPolicy :: Char -> PWPolicy -> PWPolicy
nextPolicy x p = over pwLength pred $ nextPolicy x p = over pwLength pred $