    {-# LINE 1 "OpenSSL/Objects.hsc" #-}
    {-# LANGUAGE EmptyDataDecls           #-}
    {-# LANGUAGE ForeignFunctionInterface #-}
    {-# LANGUAGE CApiFFI                  #-}
    module OpenSSL.Objects
        ( ObjNameType(..)
        , getObjNames
        )
        where

    import           Data.IORef
    import           Foreign
    import           Foreign.C

    type ObjName  = Ptr OBJ_NAME
    data {-# CTYPE "openssl/objects.h" "OBJ_NAME" #-} OBJ_NAME

    type DoAllCallback = ObjName -> Ptr () -> IO ()

    foreign import capi safe "openssl/objects.h OBJ_NAME_do_all"
            _NAME_do_all :: CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()

    foreign import capi safe "openssl/objects.h OBJ_NAME_do_all_sorted"
            _NAME_do_all_sorted :: CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()

    foreign import ccall "wrapper"
            mkDoAllCallback :: DoAllCallback -> IO (FunPtr DoAllCallback)

    data ObjNameType = MDMethodType
                     | CipherMethodType
                     | PKeyMethodType
                     | CompMethodType

    objNameTypeToInt :: ObjNameType -> CInt
    objNameTypeToInt :: ObjNameType -> CInt
    objNameTypeToInt ObjNameType
    MDMethodType     = CInt
    1
    {-# LINE 38 "OpenSSL/Objects.hsc" #-}
    objNameTypeToInt CipherMethodType = 2
    {-# LINE 39 "OpenSSL/Objects.hsc" #-}
    objNameTypeToInt PKeyMethodType   = 3
    {-# LINE 40 "OpenSSL/Objects.hsc" #-}
    objNameTypeToInt CompMethodType   = 4
    {-# LINE 41 "OpenSSL/Objects.hsc" #-}

    iterateObjNames :: ObjNameType -> Bool -> (ObjName -> IO ()) -> IO ()
    iterateObjNames :: ObjNameType -> Bool -> (ObjName -> IO ()) -> IO ()
    iterateObjNames ObjNameType
    nameType Bool
    wantSorted ObjName -> IO ()
    cb
        = do cbPtr <- DoAllCallback -> IO (FunPtr DoAllCallback)
    mkDoAllCallback (DoAllCallback -> IO (FunPtr DoAllCallback))
    -> DoAllCallback -> IO (FunPtr DoAllCallback)
    forall a b. (a -> b) -> a -> b
    $ \ ObjName
    name Ptr ()
    _ -> ObjName -> IO ()
    cb ObjName
    name
             let action = if Bool
    wantSorted then
                              CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()
    _NAME_do_all_sorted
                          else
                              CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()
    _NAME_do_all
             action (objNameTypeToInt nameType) cbPtr nullPtr
             freeHaskellFunPtr cbPtr

    objNameStr :: ObjName -> IO String
    objNameStr :: ObjName -> IO String
    objNameStr ObjName
    name
        = ((\ObjName
    hsc_ptr -> ObjName -> Int -> IO CString
    forall b. Ptr b -> Int -> IO CString
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff ObjName
    hsc_ptr Int
    8)) ObjName
    name IO CString -> (CString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CString -> IO String
    peekCString
    {-# LINE 57 "OpenSSL/Objects.hsc" #-}

    getObjNames :: ObjNameType -> Bool -> IO [String]
    getObjNames :: ObjNameType -> Bool -> IO [String]
    getObjNames ObjNameType
    nameType Bool
    wantSorted
        = do listRef <- [String] -> IO (IORef [String])
    forall a. a -> IO (IORef a)
    newIORef []
             iterateObjNames nameType wantSorted $ \ ObjName
    name ->
                 do nameStr <- ObjName -> IO String
    objNameStr ObjName
    name
                    modifyIORef listRef (++ [nameStr])
             readIORef listRef