module Gnome.Keyring.Internal.Types
( KeyringName
, CancellationKey (..)
, Error (..)
, Result (..)
, resultToError
, result
, resultAndTuple
) where
import Data.Text.Lazy (Text)
import Foreign (Ptr)
import Control.Exception (Exception)
import Data.Typeable (Typeable)
type KeyringName = Text
newtype CancellationKey = CancellationKey (Ptr ())
data Error
= ErrorDenied
| ErrorNoKeyringDaemon
| ErrorAlreadyUnlocked
| ErrorNoSuchKeyring
| ErrorBadArguments
| ErrorIOError
| ErrorCancelled
| ErrorKeyringAlreadyExists
| ErrorNoMatch
deriving (Show, Eq, Typeable)
instance Exception Error
data Result = RESULT_OK
| RESULT_DENIED
| RESULT_NO_KEYRING_DAEMON
| RESULT_ALREADY_UNLOCKED
| RESULT_NO_SUCH_KEYRING
| RESULT_BAD_ARGUMENTS
| RESULT_IO_ERROR
| RESULT_CANCELLED
| RESULT_KEYRING_ALREADY_EXISTS
| RESULT_NO_MATCH
deriving (Enum,Show)
resultToError :: Result -> Error
resultToError RESULT_DENIED = ErrorDenied
resultToError RESULT_NO_KEYRING_DAEMON = ErrorNoKeyringDaemon
resultToError RESULT_ALREADY_UNLOCKED = ErrorAlreadyUnlocked
resultToError RESULT_NO_SUCH_KEYRING = ErrorNoSuchKeyring
resultToError RESULT_BAD_ARGUMENTS = ErrorBadArguments
resultToError RESULT_IO_ERROR = ErrorIOError
resultToError RESULT_CANCELLED = ErrorCancelled
resultToError RESULT_KEYRING_ALREADY_EXISTS = ErrorKeyringAlreadyExists
resultToError RESULT_NO_MATCH = ErrorNoMatch
resultToError x = error $ "Not an error: " ++ show x
result :: Integral a => a -> Result
result = toEnum . fromIntegral
resultAndTuple :: Integral a => a -> (Result, ())
resultAndTuple x = (result x, ())