{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Crypto.PubKey.RSA.Types
( Error(..)
, Blinder(..)
, PublicKey(..)
, PrivateKey(..)
, KeyPair(..)
, toPublicKey
, toPrivateKey
, private_size
, private_n
, private_e
) where
import Data.Data
import Crypto.Internal.Imports
data Blinder = Blinder !Integer !Integer
deriving (Show,Eq)
data Error =
MessageSizeIncorrect
| MessageTooLong
| MessageNotRecognized
| SignatureTooLong
| InvalidParameters
deriving (Show,Eq)
data PublicKey = PublicKey
{ public_size :: Int
, public_n :: Integer
, public_e :: Integer
} deriving (Show,Read,Eq,Data)
instance NFData PublicKey where
rnf (PublicKey sz n e) = rnf n `seq` rnf e `seq` sz `seq` ()
data PrivateKey = PrivateKey
{ private_pub :: PublicKey
, private_d :: Integer
, private_p :: Integer
, private_q :: Integer
, private_dP :: Integer
, private_dQ :: Integer
, private_qinv :: Integer
} deriving (Show,Read,Eq,Data)
instance NFData PrivateKey where
rnf (PrivateKey pub d p q dp dq qinv) =
rnf pub `seq` rnf d `seq` rnf p `seq` rnf q `seq` rnf dp `seq` rnf dq `seq` qinv `seq` ()
private_size :: PrivateKey -> Int
private_size = public_size . private_pub
private_n :: PrivateKey -> Integer
private_n = public_n . private_pub
private_e :: PrivateKey -> Integer
private_e = public_e . private_pub
newtype KeyPair = KeyPair PrivateKey
deriving (Show,Read,Eq,Data,NFData)
toPublicKey :: KeyPair -> PublicKey
toPublicKey (KeyPair priv) = private_pub priv
toPrivateKey :: KeyPair -> PrivateKey
toPrivateKey (KeyPair priv) = priv