{-# LINE 1 "OpenSSL/EVP/PKey.hsc" #-}
{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ForeignFunctionInterface  #-}
{-# LANGUAGE CApiFFI                   #-}
{-# LANGUAGE Rank2Types                #-}
{-# OPTIONS_GHC -fno-warn-orphans      #-}
-- |An interface to asymmetric cipher keypair.
module OpenSSL.EVP.PKey
    ( PublicKey(..)
    , KeyPair(..)
    , SomePublicKey
    , SomeKeyPair
    )
    where

import Data.Typeable
import Data.Maybe
import Foreign
import Foreign.C
import OpenSSL.DSA
import OpenSSL.EVP.Digest
import OpenSSL.EVP.Internal
import OpenSSL.RSA
import OpenSSL.Utils

-- |Instances of this class has at least public portion of a
-- keypair. They might or might not have the private key.
class (Eq k, Typeable k, PKey k) => PublicKey k where

    -- |Wrap an arbitrary public key into polymorphic type
    -- 'SomePublicKey'.
    fromPublicKey :: k -> SomePublicKey
    fromPublicKey = k -> SomePublicKey
forall k. PublicKey k => k -> SomePublicKey
SomePublicKey

    -- |Cast from the polymorphic type 'SomePublicKey' to the concrete
    -- type. Return 'Nothing' if failed.
    toPublicKey :: SomePublicKey -> Maybe k
    toPublicKey (SomePublicKey k
pk) = k -> Maybe k
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast k
pk

-- |Instances of this class has both of public and private portions of
-- a keypair.
class PublicKey a => KeyPair a where

    -- |Wrap an arbitrary keypair into polymorphic type 'SomeKeyPair'.
    fromKeyPair :: a -> SomeKeyPair
    fromKeyPair = a -> SomeKeyPair
forall k. KeyPair k => k -> SomeKeyPair
SomeKeyPair

    -- |Cast from the polymorphic type 'SomeKeyPair' to the concrete
    -- type. Return 'Nothing' if failed.
    toKeyPair :: SomeKeyPair -> Maybe a
    toKeyPair (SomeKeyPair k
pk) = k -> Maybe a
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast k
pk




{-# LINE 56 "OpenSSL/EVP/PKey.hsc" #-}
foreign import capi unsafe "openssl/evp.h EVP_PKEY_get_base_id" getType :: Ptr EVP_PKEY -> IO CInt

{-# LINE 63 "OpenSSL/EVP/PKey.hsc" #-}

-- Reconstruct the concrete public-key type from an EVP_PKEY.
withConcretePubKey :: VaguePKey -> (forall k. PublicKey k => k -> IO a) -> IO a
withConcretePubKey :: forall a. VaguePKey -> (forall k. PublicKey k => k -> IO a) -> IO a
withConcretePubKey VaguePKey
pk forall k. PublicKey k => k -> IO a
f
    = VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
forall a. VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
withPKeyPtr VaguePKey
pk ((Ptr EVP_PKEY -> IO a) -> IO a) -> (Ptr EVP_PKEY -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \ Ptr EVP_PKEY
pkeyPtr ->
          do CInt
pkeyType <- Ptr EVP_PKEY -> IO CInt
getType Ptr EVP_PKEY
pkeyPtr
             case CInt
pkeyType of

{-# LINE 71 "OpenSSL/EVP/PKey.hsc" #-}
               (CInt
6)
{-# LINE 72 "OpenSSL/EVP/PKey.hsc" #-}
                   -> do Ptr RSA
rsaPtr   <- Ptr EVP_PKEY -> IO (Ptr RSA)
_get1_RSA Ptr EVP_PKEY
pkeyPtr
                         Just RSAPubKey
rsa <- Ptr RSA -> IO (Maybe RSAPubKey)
forall k. RSAKey k => Ptr RSA -> IO (Maybe k)
absorbRSAPtr Ptr RSA
rsaPtr
                         RSAPubKey -> IO a
forall k. PublicKey k => k -> IO a
f (RSAPubKey
rsa :: RSAPubKey)

{-# LINE 76 "OpenSSL/EVP/PKey.hsc" #-}

{-# LINE 77 "OpenSSL/EVP/PKey.hsc" #-}
               (CInt
116)
{-# LINE 78 "OpenSSL/EVP/PKey.hsc" #-}
                   -> do Ptr DSA
dsaPtr   <- Ptr EVP_PKEY -> IO (Ptr DSA)
_get1_DSA Ptr EVP_PKEY
pkeyPtr
                         Just DSAPubKey
dsa <- Ptr DSA -> IO (Maybe DSAPubKey)
forall k. DSAKey k => Ptr DSA -> IO (Maybe k)
absorbDSAPtr Ptr DSA
dsaPtr
                         DSAPubKey -> IO a
forall k. PublicKey k => k -> IO a
f (DSAPubKey
dsa :: DSAPubKey)

{-# LINE 82 "OpenSSL/EVP/PKey.hsc" #-}
               CInt
_   -> String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"withConcretePubKey: unsupported EVP_PKEY type: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ CInt -> String
forall a. Show a => a -> String
show CInt
pkeyType)

-- Reconstruct the concrete keypair type from an EVP_PKEY.
withConcreteKeyPair :: VaguePKey -> (forall k. KeyPair k => k -> IO a) -> IO a
withConcreteKeyPair :: forall a. VaguePKey -> (forall k. KeyPair k => k -> IO a) -> IO a
withConcreteKeyPair VaguePKey
pk forall k. KeyPair k => k -> IO a
f
    = VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
forall a. VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
withPKeyPtr VaguePKey
pk ((Ptr EVP_PKEY -> IO a) -> IO a) -> (Ptr EVP_PKEY -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \ Ptr EVP_PKEY
pkeyPtr ->
          do CInt
pkeyType <- Ptr EVP_PKEY -> IO CInt
getType Ptr EVP_PKEY
pkeyPtr
             case CInt
pkeyType of

{-# LINE 91 "OpenSSL/EVP/PKey.hsc" #-}
               (CInt
6)
{-# LINE 92 "OpenSSL/EVP/PKey.hsc" #-}
                   -> do Ptr RSA
rsaPtr   <- Ptr EVP_PKEY -> IO (Ptr RSA)
_get1_RSA Ptr EVP_PKEY
pkeyPtr
                         Just RSAKeyPair
rsa <- Ptr RSA -> IO (Maybe RSAKeyPair)
forall k. RSAKey k => Ptr RSA -> IO (Maybe k)
absorbRSAPtr Ptr RSA
rsaPtr
                         RSAKeyPair -> IO a
forall k. KeyPair k => k -> IO a
f (RSAKeyPair
rsa :: RSAKeyPair)

{-# LINE 96 "OpenSSL/EVP/PKey.hsc" #-}

{-# LINE 97 "OpenSSL/EVP/PKey.hsc" #-}
               (CInt
116)
{-# LINE 98 "OpenSSL/EVP/PKey.hsc" #-}
                   -> do Ptr DSA
dsaPtr   <- Ptr EVP_PKEY -> IO (Ptr DSA)
_get1_DSA Ptr EVP_PKEY
pkeyPtr
                         Just DSAKeyPair
dsa <- Ptr DSA -> IO (Maybe DSAKeyPair)
forall k. DSAKey k => Ptr DSA -> IO (Maybe k)
absorbDSAPtr Ptr DSA
dsaPtr
                         DSAKeyPair -> IO a
forall k. KeyPair k => k -> IO a
f (DSAKeyPair
dsa :: DSAKeyPair)

{-# LINE 102 "OpenSSL/EVP/PKey.hsc" #-}
               CInt
_   -> String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"withConcreteKeyPair: unsupported EVP_PKEY type: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ CInt -> String
forall a. Show a => a -> String
show CInt
pkeyType)


-- |This is an opaque type to hold an arbitrary public key in it. The
-- actual key type can be safelly type-casted using 'toPublicKey'.
data SomePublicKey = forall k. PublicKey k => SomePublicKey !k
    deriving Typeable

instance Eq SomePublicKey where
    (SomePublicKey k
a) == :: SomePublicKey -> SomePublicKey -> Bool
== (SomePublicKey k
b)
        = case k -> Maybe k
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast k
b of
            Just k
c  -> k
a k -> k -> Bool
forall a. Eq a => a -> a -> Bool
== k
c
            Maybe k
Nothing -> Bool
False  -- different types

instance PublicKey SomePublicKey where
    fromPublicKey :: SomePublicKey -> SomePublicKey
fromPublicKey = SomePublicKey -> SomePublicKey
forall a. a -> a
id
    toPublicKey :: SomePublicKey -> Maybe SomePublicKey
toPublicKey   = SomePublicKey -> Maybe SomePublicKey
forall a. a -> Maybe a
Just

instance PKey SomePublicKey where
    toPKey :: SomePublicKey -> IO VaguePKey
toPKey        (SomePublicKey k
k) = k -> IO VaguePKey
forall k. PKey k => k -> IO VaguePKey
toPKey k
k
    pkeySize :: SomePublicKey -> Int
pkeySize      (SomePublicKey k
k) = k -> Int
forall k. PKey k => k -> Int
pkeySize k
k
    pkeyDefaultMD :: SomePublicKey -> IO Digest
pkeyDefaultMD (SomePublicKey k
k) = k -> IO Digest
forall k. PKey k => k -> IO Digest
pkeyDefaultMD k
k
    fromPKey :: VaguePKey -> IO (Maybe SomePublicKey)
fromPKey VaguePKey
pk
        = VaguePKey
-> (forall k. PublicKey k => k -> IO (Maybe SomePublicKey))
-> IO (Maybe SomePublicKey)
forall a. VaguePKey -> (forall k. PublicKey k => k -> IO a) -> IO a
withConcretePubKey VaguePKey
pk (Maybe SomePublicKey -> IO (Maybe SomePublicKey)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe SomePublicKey -> IO (Maybe SomePublicKey))
-> (k -> Maybe SomePublicKey) -> k -> IO (Maybe SomePublicKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomePublicKey -> Maybe SomePublicKey
forall a. a -> Maybe a
Just (SomePublicKey -> Maybe SomePublicKey)
-> (k -> SomePublicKey) -> k -> Maybe SomePublicKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> SomePublicKey
forall k. PublicKey k => k -> SomePublicKey
SomePublicKey)


-- |This is an opaque type to hold an arbitrary keypair in it. The
-- actual key type can be safelly type-casted using 'toKeyPair'.
data SomeKeyPair = forall k. KeyPair k => SomeKeyPair !k
    deriving Typeable

instance Eq SomeKeyPair where
    (SomeKeyPair k
a) == :: SomeKeyPair -> SomeKeyPair -> Bool
== (SomeKeyPair k
b)
        = case k -> Maybe k
forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast k
b of
            Just k
c  -> k
a k -> k -> Bool
forall a. Eq a => a -> a -> Bool
== k
c
            Maybe k
Nothing -> Bool
False

instance PublicKey SomeKeyPair where
    -- Cast the keypair to a public key, hiding its private part.
    fromPublicKey :: SomeKeyPair -> SomePublicKey
fromPublicKey (SomeKeyPair k
k)
        = k -> SomePublicKey
forall k. PublicKey k => k -> SomePublicKey
SomePublicKey k
k

    -- It's impossible to cast a public key to a keypair.
    toPublicKey :: SomePublicKey -> Maybe SomeKeyPair
toPublicKey SomePublicKey
_ = Maybe SomeKeyPair
forall a. Maybe a
Nothing

instance KeyPair SomeKeyPair where
    fromKeyPair :: SomeKeyPair -> SomeKeyPair
fromKeyPair = SomeKeyPair -> SomeKeyPair
forall a. a -> a
id
    toKeyPair :: SomeKeyPair -> Maybe SomeKeyPair
toKeyPair   = SomeKeyPair -> Maybe SomeKeyPair
forall a. a -> Maybe a
Just

instance PKey SomeKeyPair where
    toPKey :: SomeKeyPair -> IO VaguePKey
toPKey        (SomeKeyPair k
k) = k -> IO VaguePKey
forall k. PKey k => k -> IO VaguePKey
toPKey k
k
    pkeySize :: SomeKeyPair -> Int
pkeySize      (SomeKeyPair k
k) = k -> Int
forall k. PKey k => k -> Int
pkeySize k
k
    pkeyDefaultMD :: SomeKeyPair -> IO Digest
pkeyDefaultMD (SomeKeyPair k
k) = k -> IO Digest
forall k. PKey k => k -> IO Digest
pkeyDefaultMD k
k
    fromPKey :: VaguePKey -> IO (Maybe SomeKeyPair)
fromPKey VaguePKey
pk
        = VaguePKey
-> (forall k. KeyPair k => k -> IO (Maybe SomeKeyPair))
-> IO (Maybe SomeKeyPair)
forall a. VaguePKey -> (forall k. KeyPair k => k -> IO a) -> IO a
withConcreteKeyPair VaguePKey
pk (Maybe SomeKeyPair -> IO (Maybe SomeKeyPair)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe SomeKeyPair -> IO (Maybe SomeKeyPair))
-> (k -> Maybe SomeKeyPair) -> k -> IO (Maybe SomeKeyPair)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeKeyPair -> Maybe SomeKeyPair
forall a. a -> Maybe a
Just (SomeKeyPair -> Maybe SomeKeyPair)
-> (k -> SomeKeyPair) -> k -> Maybe SomeKeyPair
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> SomeKeyPair
forall k. KeyPair k => k -> SomeKeyPair
SomeKeyPair)



{-# LINE 160 "OpenSSL/EVP/PKey.hsc" #-}
-- The resulting Ptr RSA must be freed by caller.
foreign import capi unsafe "openssl/evp.h EVP_PKEY_get1_RSA"
        _get1_RSA :: Ptr EVP_PKEY -> IO (Ptr RSA)

foreign import capi unsafe "openssl/evp.h EVP_PKEY_set1_RSA"
        _set1_RSA :: Ptr EVP_PKEY -> Ptr RSA -> IO CInt


rsaToPKey :: RSAKey k => k -> IO VaguePKey
rsaToPKey :: forall k. RSAKey k => k -> IO VaguePKey
rsaToPKey k
rsa
    = k -> (Ptr RSA -> IO VaguePKey) -> IO VaguePKey
forall k a. RSAKey k => k -> (Ptr RSA -> IO a) -> IO a
withRSAPtr k
rsa ((Ptr RSA -> IO VaguePKey) -> IO VaguePKey)
-> (Ptr RSA -> IO VaguePKey) -> IO VaguePKey
forall a b. (a -> b) -> a -> b
$ \Ptr RSA
rsaPtr ->
        (Ptr EVP_PKEY -> IO ()) -> IO VaguePKey
forall a. (Ptr EVP_PKEY -> IO a) -> IO VaguePKey
createPKey ((Ptr EVP_PKEY -> IO ()) -> IO VaguePKey)
-> (Ptr EVP_PKEY -> IO ()) -> IO VaguePKey
forall a b. (a -> b) -> a -> b
$ \Ptr EVP_PKEY
pkeyPtr ->
          Ptr EVP_PKEY -> Ptr RSA -> IO CInt
_set1_RSA Ptr EVP_PKEY
pkeyPtr Ptr RSA
rsaPtr IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (CInt -> Bool) -> CInt -> IO ()
forall a. (a -> Bool) -> a -> IO ()
failIf_ (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
1)

rsaFromPKey :: RSAKey k => VaguePKey -> IO (Maybe k)
rsaFromPKey :: forall k. RSAKey k => VaguePKey -> IO (Maybe k)
rsaFromPKey VaguePKey
pk
        = VaguePKey -> (Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k)
forall a. VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
withPKeyPtr VaguePKey
pk ((Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k))
-> (Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k)
forall a b. (a -> b) -> a -> b
$ \ Ptr EVP_PKEY
pkeyPtr ->
          do CInt
pkeyType <- Ptr EVP_PKEY -> IO CInt
getType Ptr EVP_PKEY
pkeyPtr
             case CInt
pkeyType of
               (CInt
6)
{-# LINE 180 "OpenSSL/EVP/PKey.hsc" #-}
                   -> Ptr EVP_PKEY -> IO (Ptr RSA)
_get1_RSA Ptr EVP_PKEY
pkeyPtr IO (Ptr RSA) -> (Ptr RSA -> IO (Maybe k)) -> IO (Maybe k)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr RSA -> IO (Maybe k)
forall k. RSAKey k => Ptr RSA -> IO (Maybe k)
absorbRSAPtr
               CInt
_   -> Maybe k -> IO (Maybe k)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe k
forall a. Maybe a
Nothing

instance PublicKey RSAPubKey
instance PKey RSAPubKey where
    toPKey :: RSAPubKey -> IO VaguePKey
toPKey          = RSAPubKey -> IO VaguePKey
forall k. RSAKey k => k -> IO VaguePKey
rsaToPKey
    fromPKey :: VaguePKey -> IO (Maybe RSAPubKey)
fromPKey        = VaguePKey -> IO (Maybe RSAPubKey)
forall k. RSAKey k => VaguePKey -> IO (Maybe k)
rsaFromPKey
    pkeySize :: RSAPubKey -> Int
pkeySize        = RSAPubKey -> Int
forall k. RSAKey k => k -> Int
rsaSize
    pkeyDefaultMD :: RSAPubKey -> IO Digest
pkeyDefaultMD RSAPubKey
_ = Digest -> IO Digest
forall (m :: * -> *) a. Monad m => a -> m a
return (Digest -> IO Digest)
-> (Maybe Digest -> Digest) -> Maybe Digest -> IO Digest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Digest -> Digest
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Digest -> IO Digest) -> IO (Maybe Digest) -> IO Digest
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> IO (Maybe Digest)
getDigestByName String
"sha1"

instance KeyPair RSAKeyPair
instance PublicKey RSAKeyPair
instance PKey RSAKeyPair where
    toPKey :: RSAKeyPair -> IO VaguePKey
toPKey          = RSAKeyPair -> IO VaguePKey
forall k. RSAKey k => k -> IO VaguePKey
rsaToPKey
    fromPKey :: VaguePKey -> IO (Maybe RSAKeyPair)
fromPKey        = VaguePKey -> IO (Maybe RSAKeyPair)
forall k. RSAKey k => VaguePKey -> IO (Maybe k)
rsaFromPKey
    pkeySize :: RSAKeyPair -> Int
pkeySize        = RSAKeyPair -> Int
forall k. RSAKey k => k -> Int
rsaSize
    pkeyDefaultMD :: RSAKeyPair -> IO Digest
pkeyDefaultMD RSAKeyPair
_ = Digest -> IO Digest
forall (m :: * -> *) a. Monad m => a -> m a
return (Digest -> IO Digest)
-> (Maybe Digest -> Digest) -> Maybe Digest -> IO Digest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Digest -> Digest
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Digest -> IO Digest) -> IO (Maybe Digest) -> IO Digest
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> IO (Maybe Digest)
getDigestByName String
"sha1"

{-# LINE 198 "OpenSSL/EVP/PKey.hsc" #-}



{-# LINE 201 "OpenSSL/EVP/PKey.hsc" #-}
foreign import capi unsafe "openssl/evp.h EVP_PKEY_get1_DSA"
        _get1_DSA :: Ptr EVP_PKEY -> IO (Ptr DSA)

foreign import capi unsafe "openssl/evp.h EVP_PKEY_set1_DSA"
        _set1_DSA :: Ptr EVP_PKEY -> Ptr DSA -> IO CInt

dsaToPKey :: DSAKey k => k -> IO VaguePKey
dsaToPKey :: forall k. DSAKey k => k -> IO VaguePKey
dsaToPKey k
dsa
    = k -> (Ptr DSA -> IO VaguePKey) -> IO VaguePKey
forall k a. DSAKey k => k -> (Ptr DSA -> IO a) -> IO a
withDSAPtr k
dsa ((Ptr DSA -> IO VaguePKey) -> IO VaguePKey)
-> (Ptr DSA -> IO VaguePKey) -> IO VaguePKey
forall a b. (a -> b) -> a -> b
$ \Ptr DSA
dsaPtr ->
        (Ptr EVP_PKEY -> IO ()) -> IO VaguePKey
forall a. (Ptr EVP_PKEY -> IO a) -> IO VaguePKey
createPKey ((Ptr EVP_PKEY -> IO ()) -> IO VaguePKey)
-> (Ptr EVP_PKEY -> IO ()) -> IO VaguePKey
forall a b. (a -> b) -> a -> b
$ \Ptr EVP_PKEY
pkeyPtr ->
          Ptr EVP_PKEY -> Ptr DSA -> IO CInt
_set1_DSA Ptr EVP_PKEY
pkeyPtr Ptr DSA
dsaPtr IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (CInt -> Bool) -> CInt -> IO ()
forall a. (a -> Bool) -> a -> IO ()
failIf_ (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
1)


dsaFromPKey :: DSAKey k => VaguePKey -> IO (Maybe k)
dsaFromPKey :: forall k. DSAKey k => VaguePKey -> IO (Maybe k)
dsaFromPKey VaguePKey
pk
        = VaguePKey -> (Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k)
forall a. VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
withPKeyPtr VaguePKey
pk ((Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k))
-> (Ptr EVP_PKEY -> IO (Maybe k)) -> IO (Maybe k)
forall a b. (a -> b) -> a -> b
$ \ Ptr EVP_PKEY
pkeyPtr ->
          do CInt
pkeyType <- Ptr EVP_PKEY -> IO CInt
getType Ptr EVP_PKEY
pkeyPtr
             case CInt
pkeyType of
               (CInt
116)
{-# LINE 220 "OpenSSL/EVP/PKey.hsc" #-}
                   -> Ptr EVP_PKEY -> IO (Ptr DSA)
_get1_DSA Ptr EVP_PKEY
pkeyPtr IO (Ptr DSA) -> (Ptr DSA -> IO (Maybe k)) -> IO (Maybe k)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr DSA -> IO (Maybe k)
forall k. DSAKey k => Ptr DSA -> IO (Maybe k)
absorbDSAPtr
               CInt
_   -> Maybe k -> IO (Maybe k)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe k
forall a. Maybe a
Nothing

instance PublicKey DSAPubKey
instance PKey DSAPubKey where
    toPKey :: DSAPubKey -> IO VaguePKey
toPKey          = DSAPubKey -> IO VaguePKey
forall k. DSAKey k => k -> IO VaguePKey
dsaToPKey
    fromPKey :: VaguePKey -> IO (Maybe DSAPubKey)
fromPKey        = VaguePKey -> IO (Maybe DSAPubKey)
forall k. DSAKey k => VaguePKey -> IO (Maybe k)
dsaFromPKey
    pkeySize :: DSAPubKey -> Int
pkeySize        = DSAPubKey -> Int
forall k. DSAKey k => k -> Int
dsaSize
    pkeyDefaultMD :: DSAPubKey -> IO Digest
pkeyDefaultMD DSAPubKey
_ = Digest -> IO Digest
forall (m :: * -> *) a. Monad m => a -> m a
return (Digest -> IO Digest)
-> (Maybe Digest -> Digest) -> Maybe Digest -> IO Digest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Digest -> Digest
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Digest -> IO Digest) -> IO (Maybe Digest) -> IO Digest
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> IO (Maybe Digest)
getDigestByName String
"dss1"

instance KeyPair DSAKeyPair
instance PublicKey DSAKeyPair
instance PKey DSAKeyPair where
    toPKey :: DSAKeyPair -> IO VaguePKey
toPKey          = DSAKeyPair -> IO VaguePKey
forall k. DSAKey k => k -> IO VaguePKey
dsaToPKey
    fromPKey :: VaguePKey -> IO (Maybe DSAKeyPair)
fromPKey        = VaguePKey -> IO (Maybe DSAKeyPair)
forall k. DSAKey k => VaguePKey -> IO (Maybe k)
dsaFromPKey
    pkeySize :: DSAKeyPair -> Int
pkeySize        = DSAKeyPair -> Int
forall k. DSAKey k => k -> Int
dsaSize
    pkeyDefaultMD :: DSAKeyPair -> IO Digest
pkeyDefaultMD DSAKeyPair
_ = Digest -> IO Digest
forall (m :: * -> *) a. Monad m => a -> m a
return (Digest -> IO Digest)
-> (Maybe Digest -> Digest) -> Maybe Digest -> IO Digest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Digest -> Digest
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Digest -> IO Digest) -> IO (Maybe Digest) -> IO Digest
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> IO (Maybe Digest)
getDigestByName String
"dss1"

{-# LINE 238 "OpenSSL/EVP/PKey.hsc" #-}