Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
* removed hyphens from UUID rendering for PassIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Ambo committed Nov 8, 2012
1 parent ddebbe7 commit 91a826b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Passbook.hs
Expand Up @@ -58,7 +58,10 @@ import Codec.Archive.Zip
import Control.Monad (liftM)
import Control.Monad.IO.Class (liftIO)
import Data.Aeson
import Data.Binary (Word32)
import Data.Bits (shiftR, (.&.))
import qualified Data.ByteString.Lazy as LB
import Data.Char (intToDigit)
import Data.Conduit
import Data.Conduit.Binary hiding (sinkFile)
import Data.Conduit.Filesystem
Expand Down Expand Up @@ -242,7 +245,23 @@ signOpenWithId passIn passOut cert key pass passId = shelly $ silently $ do

-- |Generates a random UUID for a Pass using "Data.UUID" and "System.Random"
genPassId :: IO ST.Text
genPassId = liftM (ST.pack . toString) randomIO
genPassId = liftM (ST.pack . showPassId) randomIO

-- |Shows a UUID without the hyphens
showPassId :: UUID -> String
showPassId uuid = let (w0, w1, w2, w3) = toWords uuid
in hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
where hexw :: Word32 -> String -> String
hexw w s = hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
: hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0 : s

hexw' :: Word32 -> String -> String
hexw' w s = hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
: hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0 : s

hexn :: Word32 -> Int -> Char
hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)


-- |Render and store a pass.json at the desired location.
renderPass :: FilePath -> Pass -> IO ()
Expand Down

0 comments on commit 91a826b

Please sign in to comment.