cropty 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+33/−5 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +9/−2
- cropty.cabal +2/−1
- src/Cropty.hs +20/−2
- test/Test.hs +2/−0
README.md view
@@ -3,5 +3,12 @@ A little library for doing encryption using a combination of RSA and AEP, using the [cryptonite](https://hackage.haskell.org/package/cryptonite) library for cryptography. -It is meant for use with very large files. I've tested it on a 6 Gigabyte file and it-works within seconds for all functions.+```haskell+import Cropty++main = do+ privateKey <- generatePrivateKey KeySize1024+ secret <- encrypt (privateToPublic privateKey) "Hello!"+ decoded <- decrypt privateKey secret+ assert (secret == decoded)+```
cropty.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: cropty-version: 0.2.0.0+version: 0.3.0.0 synopsis: Encryption and decryption description: Encryption and decryption. homepage: https://github.com/SamuelSchlesinger/cropty@@ -35,6 +35,7 @@ build-depends: base >= 4.12 && < 5, hedgehog >=1.0, unliftio >=0.2,+ binary >=0.8, cropty default-language: Haskell2010 ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T"
src/Cropty.hs view
@@ -59,7 +59,7 @@ import Data.ByteString (ByteString) import GHC.Generics (Generic)-import Data.Binary (Binary(..), encode)+import Data.Binary (Binary(..), encode, decode) import qualified Crypto.PubKey.RSA.Types (Error (..)) import Crypto.Error (CryptoError (..)) import Control.Exception (Exception, throwIO)@@ -307,8 +307,25 @@ , signedEncoded :: ByteString , signature :: Signature , signedBy :: PublicKey- } deriving (Eq, Ord, Show, Read, Generic, Binary)+ } deriving (Eq, Ord, Show, Read, Generic) +instance Binary a => Binary (Signed a) where+ put s = do+ put (signedEncoded s)+ put (signature s)+ put (signedBy s)+ get = do+ signedEncoded <- get+ signature <- get+ signedBy <- get+ pure $ Signed+ { signed = decode $ LBS.fromStrict signedEncoded+ , signedEncoded+ , signature+ , signedBy+ }+ +-- | Create a 'Signed' piece of data. mkSigned :: Binary a => PrivateKey -> a -> IO (Signed a) mkSigned privateKey signed = do let signedEncoded = LBS.toStrict $ encode signed@@ -316,5 +333,6 @@ let signedBy = privateToPublic privateKey pure $ Signed { signed, signedEncoded, signature, signedBy } +-- | Verify a 'Signed' piece of data. verifySigned :: Signed a -> Bool verifySigned s = verify (signedBy s) (signedEncoded s) (signature s)
test/Test.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE BlockArguments #-} module Main where +import Data.Binary (encode, decode) import Cropty import Control.Monad.IO.Class (liftIO) import Hedgehog@@ -29,6 +30,7 @@ x <- forAll gen sig <- liftIO (sign privateKey x) sig' <- liftIO (mkSigned privateKey x)+ assert (decode (encode sig') == sig') assert (verify publicKey x sig) assert (verifySigned sig') guard =<< checkParallel (Group "Encryption/Decryption" [