qr-imager 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+17/−13 lines, 3 filesnew-component:exe:qrpipePVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +1/−1
- qr-imager.cabal +4/−3
- src/Data/QRCodes.hs +12/−9
README.md view
@@ -22,4 +22,4 @@ Compiling will generate an executable called `QRPipe` which reads from `stdin` and outputs a file as the second argument, e.g. -```echo 'My name is:" | QRPipe "nametag.png"```+```echo 'My name is:" | qrpipe "nametag.png"```
qr-imager.cabal view
@@ -1,5 +1,5 @@ name: qr-imager-version: 0.1.0.0+version: 0.1.0.1 synopsis: Library to generate QR codes from bytestrings and objects description: Please see README.md homepage: https://github.com/vmchale/QRImager#readme@@ -10,6 +10,7 @@ copyright: Copyright: (c) 2016 Vanessa McHale category: Data build-type: Simple+stability: stable extra-source-files: README.md cabal-version: >=1.10 @@ -28,10 +29,10 @@ , haskell-qrencode default-language: Haskell2010 -executable QRPipe+executable qrpipe hs-source-dirs: app main-is: Main.hs- ghc-options: -threaded -rtsopts -with-rtsopts=-N+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -O3 build-depends: base , qr-imager , bytestring
src/Data/QRCodes.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE FlexibleContexts #-} -module Data.QRCodes (createSecureQRCode- , createQRCode- , byteStringToQR- , byteStringToQRSec- ) where+-- | Module providing several functions for creating QR codes and their signed counterparts+module Data.QRCodes ( createSecureQRCode+ , createQRCode+ , byteStringToQR+ , byteStringToQRSec+ ) where import Data.Aeson import Data.QRCode@@ -30,22 +31,24 @@ import Data.Bits ((.&.)) import Control.Applicative ((<$>)) +-- | Verify a signed token checkSig :: BS.ByteString -> IO (Either JwtError BS.ByteString) checkSig tok = do- key <- read <$> readFile "~/.key.hk" :: IO (Cr.PublicKey, Cr.PrivateKey)+ key <- read <$> readFile ".key.hk" :: IO (Cr.PublicKey, Cr.PrivateKey) let jws = rsaDecode (view _1 key) tok return $ fmap (view _2) jws +-- | Sign a token mkSig :: BS.ByteString -> IO BS.ByteString mkSig string = do- switch <- doesFileExist "~/.key.hk"+ switch <- doesFileExist ".key.hk" if not switch then do putStrLn "generating key..." key <- Cr.generate 512 0x10001- writeFile "~/.key.hk" (show key)+ writeFile ".key.hk" (show key) else return ()- key' <- read <$> readFile "~/.key.hk" :: IO (Cr.PublicKey, Cr.PrivateKey)+ key' <- read <$> readFile ".key.hk" :: IO (Cr.PublicKey, Cr.PrivateKey) signedToken <- rsaEncode RS512 (view _2 key') string let signed = fmap unJwt signedToken liftEither id (return <$> signed)