qr-imager 2.0.0.0 → 2.0.0.1
raw patch · 5 files changed
+11/−13 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- cabal.project.local +1/−1
- qr-imager.cabal +1/−1
- src/Data/QRCodes.hs +5/−5
- src/Data/QRCodes/Signature.hs +3/−5
- src/Data/QRCodes/Utils.hs +1/−1
cabal.project.local view
@@ -1,3 +1,3 @@--- constraints: qr-imager +development+constraints: qr-imager +development tests: true documentation: true
qr-imager.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: qr-imager-version: 2.0.0.0+version: 2.0.0.1 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2016-2018 Vanessa McHale
src/Data/QRCodes.hs view
@@ -27,8 +27,6 @@ import Data.QRCodes.Signature import Data.QRCodes.Utils import Data.Word (Word8)-import Lens.Micro-import Lens.Micro.Extras import System.Process -- | Creates a signed QR code from a strict bytestring and path to keyfile/path.@@ -64,22 +62,24 @@ byteStringToQR :: BS.ByteString -> FilePath -> IO () byteStringToQR input filepath = bsToImg input >>= writePng filepath +snd' (_, y, _) = y+ -- | given a filepath, read the QR code as a string in all lowercase -- -- > readQRString "picture.jpg" readQRString :: FilePath -> IO String-readQRString filepath = map toLower . init . (drop 8 . view _2) <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) ""+readQRString filepath = map toLower . init . (drop 8 . snd') <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) "" -- | given a filepath pointing to a QR code, get the contents & verify signature with the keyfile -- -- > readQRStrSec "output.png" ".key.hk" readQRStrSec :: (Binary a) => FilePath -> FilePath -> IO a readQRStrSec filepath keyfile = decode . BSL.pack <$> do- enc <- map toLower . init . drop 8 . view _2 <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) ""+ enc <- map toLower . init . drop 8 . snd' <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) "" fmap (liftEither BS.unpack) . flip checkSigFile keyfile . resolveUpper $ BS.pack enc -- | Read an image containing a QR code, decode and verify the signature using the given key. readQRStrSec' :: (Binary a) => FilePath -> (PublicKey, PrivateKey) -> IO a readQRStrSec' filepath key = decode . BSL.pack <$> do- enc <- map toLower . init . drop 8 . view _2 <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) ""+ enc <- map toLower . init . drop 8 . snd' <$> readCreateProcessWithExitCode (shell $ "zbarimg " ++ filepath) "" fmap (liftEither BS.unpack) . flip checkSig key . resolveUpper $ BS.pack enc
src/Data/QRCodes/Signature.hs view
@@ -8,8 +8,6 @@ import Jose.Jwa (JwsAlg (RS256)) import Jose.Jws import Jose.Jwt (JwtError, unJwt)-import Lens.Micro-import Lens.Micro.Extras import System.Directory -- | Verify a signed token with a key@@ -21,8 +19,8 @@ -- | Verify a signed token with a key from a given filepath checkSig :: BS.ByteString -> (PublicKey, PrivateKey) -> IO (Either JwtError BS.ByteString) checkSig tok key = do- let jws = rsaDecode (view _1 key) tok- return $ fmap (view _2) jws+ let jws = rsaDecode (fst key) tok+ pure $ fmap snd jws -- | Sign a token. -- If the key file does not exist, a new key will be generated.@@ -42,7 +40,7 @@ -- > mkSig (BS.pack "hello") (generate 256 0x10001) mkSig :: BS.ByteString -> (PublicKey, PrivateKey) -> IO BS.ByteString mkSig string key = do- signedToken <- rsaEncode RS256 (view _2 key) string+ signedToken <- rsaEncode RS256 (snd key) string let signed = fmap unJwt signedToken liftEither id (return <$> signed)
src/Data/QRCodes/Utils.hs view
@@ -13,7 +13,7 @@ -- | function applied to byteStrings before saving to QR code so that uppercase/lowercase signatures can be preserverd preserveUpper :: BS.ByteString -> BS.ByteString preserveUpper = lift pU- where pU = concatMap (\c -> if c `elem` ['A'..'Z'] then toLower c : "!" else return c)+ where pU = (>>= (\c -> if c `elem` ['A'..'Z'] then toLower c : "!" else return c)) -- | resolve coded string to string with uppercase resolveUpper :: BS.ByteString -> BS.ByteString