cropty 0.1.1.0 → 0.2.0.0
raw patch · 3 files changed
+30/−2 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Cropty: data Signed a
+ Cropty: instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Cropty.Signed a)
+ Cropty: instance GHC.Classes.Eq a => GHC.Classes.Eq (Cropty.Signed a)
+ Cropty: instance GHC.Classes.Ord a => GHC.Classes.Ord (Cropty.Signed a)
+ Cropty: instance GHC.Generics.Generic (Cropty.Signed a)
+ Cropty: instance GHC.Read.Read a => GHC.Read.Read (Cropty.Signed a)
+ Cropty: instance GHC.Show.Show a => GHC.Show.Show (Cropty.Signed a)
+ Cropty: mkSigned :: Binary a => PrivateKey -> a -> IO (Signed a)
+ Cropty: signature :: Signed a -> Signature
+ Cropty: signed :: Signed a -> a
+ Cropty: signedBy :: Signed a -> PublicKey
+ Cropty: signedEncoded :: Signed a -> ByteString
+ Cropty: verifySigned :: Signed a -> Bool
Files
- cropty.cabal +1/−1
- src/Cropty.hs +27/−1
- test/Test.hs +2/−0
cropty.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: cropty-version: 0.1.1.0+version: 0.2.0.0 synopsis: Encryption and decryption description: Encryption and decryption. homepage: https://github.com/SamuelSchlesinger/cropty
src/Cropty.hs view
@@ -27,6 +27,13 @@ , Signature (Signature, signatureBytes) , sign , verify+ , Signed+ , signed+ , signedBy+ , signature+ , signedEncoded+ , mkSigned+ , verifySigned -- ** Encrypt/Decrypt Small Strings , encryptSmall , decryptSmall@@ -52,7 +59,7 @@ import Data.ByteString (ByteString) import GHC.Generics (Generic)-import Data.Binary (Binary(..))+import Data.Binary (Binary(..), encode) import qualified Crypto.PubKey.RSA.Types (Error (..)) import Crypto.Error (CryptoError (..)) import Control.Exception (Exception, throwIO)@@ -65,6 +72,7 @@ import qualified Crypto.PubKey.RSA.PSS as RSA.PSS import qualified Crypto.Random as Random import qualified Data.ByteString as ByteString+import qualified Data.ByteString.Lazy as LBS -- | -- @import qualified Crypto.PubKey.RSA.Types as RSA (Error (..))@@@ -292,3 +300,21 @@ verify :: PublicKey -> ByteString -> Signature -> Bool verify (PublicKey pubKey) bs (Signature sig) = RSA.PSS.verify (RSA.PSS.defaultPSSParams Hash.SHA512) pubKey bs sig++-- | A convenient type in which to wrap signed things.+data Signed a = Signed+ { signed :: a+ , signedEncoded :: ByteString+ , signature :: Signature+ , signedBy :: PublicKey+ } deriving (Eq, Ord, Show, Read, Generic, Binary)++mkSigned :: Binary a => PrivateKey -> a -> IO (Signed a)+mkSigned privateKey signed = do+ let signedEncoded = LBS.toStrict $ encode signed+ signature <- sign privateKey signedEncoded+ let signedBy = privateToPublic privateKey+ pure $ Signed { signed, signedEncoded, signature, signedBy }+ +verifySigned :: Signed a -> Bool+verifySigned s = verify (signedBy s) (signedEncoded s) (signature s)
test/Test.hs view
@@ -28,7 +28,9 @@ (privateKey, publicKey) <- forAll (element keypairs) x <- forAll gen sig <- liftIO (sign privateKey x)+ sig' <- liftIO (mkSigned privateKey x) assert (verify publicKey x sig)+ assert (verifySigned sig') guard =<< checkParallel (Group "Encryption/Decryption" [ ("Encrypt/Decrypt UTF-8", roundTrip (utf8 (linearFrom 0 1000 10000) unicodeAll)