packages feed

clientsession 0.7.5 → 0.8.0

raw patch · 3 files changed

+26/−7 lines, 3 filesdep ~hspecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hspec

API changes (from Hackage documentation)

- Web.ClientSession: Key :: AES256 -> (ByteString -> Skein_512_256) -> Key
- Web.ClientSession: aesKey :: Key -> AES256
- Web.ClientSession: macKey :: Key -> ByteString -> Skein_512_256
+ Web.ClientSession: instance Eq Key
+ Web.ClientSession: instance Serialize Key
+ Web.ClientSession: randomKey :: IO (ByteString, Key)

Files

clientsession.cabal view
@@ -1,5 +1,5 @@ name:            clientsession-version:         0.7.5+version:         0.8.0 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>, Felipe Lessa <felipe.lessa@gmail.com>@@ -41,11 +41,12 @@     build-depends:   base                >=4           && < 5                    , bytestring          >= 0.9        && < 0.10                    , cryptocipher        >= 0.2.5-                   , hspec               >= 0.6        && < 0.10+                   , hspec               >= 1.2        && < 1.3                    , QuickCheck          >= 2          && < 3                    , HUnit                    , transformers                    , containers+                   , cereal              >= 0.3        && < 0.4                    -- finally, our own package                    , clientsession     ghc-options:     -Wall
src/Web/ClientSession.hs view
@@ -38,7 +38,7 @@ --------------------------------------------------------- module Web.ClientSession     ( -- * Automatic key generation-      Key(..)+      Key     , IV     , randomIV     , mkIV@@ -46,6 +46,7 @@     , defaultKeyFile     , getDefaultKey     , initKey+    , randomKey       -- * Actual encryption/decryption     , encrypt     , encryptIO@@ -57,6 +58,7 @@ import qualified Data.IORef as I import System.IO.Unsafe (unsafePerformIO) import Control.Concurrent (forkIO)+import Control.Applicative ((<$>))  -- from directory import System.Directory (doesFileExist)@@ -66,7 +68,7 @@ import qualified Data.ByteString.Base64 as B  -- from cereal-import Data.Serialize (encode, decode)+import Data.Serialize (encode, decode, Serialize (put, get), getBytes, putByteString)  -- from tagged import Data.Tagged (Tagged, untag)@@ -102,8 +104,16 @@                  -- ^ Skein-MAC key.  Instead of storing the key                  -- data, we store a partially applied function                  -- for calculating the MAC (see 'skeinMAC'').+               , keyRaw :: S.ByteString                } +instance Eq Key where+    Key a _ b == Key x _ y = encode a == encode x && b == y++instance Serialize Key where+    put = putByteString . keyRaw+    get = either error id . initKey <$> getBytes 96+ -- | Dummy 'Show' instance. instance Show Key where     show _ = "<Web.ClientSession.Key>"@@ -168,7 +178,9 @@ initKey bs = case buildKey preAesKey of                Nothing -> Left $ "Web.ClientSession.initKey: unknown error with buildKey."                Just k  -> Right $ Key { aesKey = k-                                      , macKey = skeinMAC' preMacKey }+                                      , macKey = skeinMAC' preMacKey+                                      , keyRaw = bs+                                      }     where       (preMacKey, preAesKey) = S.splitAt 64 bs 
tests/runtests.hs view
@@ -19,14 +19,17 @@ import Control.Monad.Trans.Class (lift) import Control.Monad (replicateM_) +import Data.Serialize (encode, decode)+ main :: IO ()-main = hspecX $ describe "client session" $ do+main = hspec $ describe "client session" $ do     it "encrypt/decrypt success" $ property propEncDec     it "encrypt/decrypt failure" $ property propEncDecFailure     it "AES encrypt/decrypt success" $ property propAES     it "AES encryption changes bs" $ property propAESChanges     it "specific values" caseSpecific     it "randomIV is really random" caseRandomIV+    it "serialize instance" $ property propSerialize  propEncDec :: S.ByteString -> Bool propEncDec bs = unsafePerformIO $ do@@ -67,6 +70,9 @@         lift $ assertBool "No duplicated keys" (not $ val `Set.member` set)         put $ Set.insert val set +propSerialize :: MyKey -> Bool+propSerialize (MyKey key) = Right key == decode (encode key)+ instance Arbitrary S.ByteString where     arbitrary = S.pack `fmap` arbitrary @@ -78,7 +84,7 @@         either error (return . MyKey) $ initKey $ S.pack ws  instance Show MyKey where-    show _ = "<Key>"+    show (MyKey key) = "MyKey:" ++ show (encode key)  newtype MyIV = MyIV IV