-- revokeIdentity :: MonadIO m => KeyID -> MethodHandlerT m ()
-- revokeIdentity keyID = do
--     let text = "" :: Text
--         reason = Gpg.NoReason
--     ctx <- liftIO $ Gpg.ctxNew Nothing
--     keys <- liftIO $ Gpg.findKeyBy ctx True Gpg.keyFingerprint
--               (Just $ fromKeyID keyID)
--     case keys of
--         [key] -> liftIO $ Gpg.revoke ctx key reason text >> return ()
--         [] -> DBus.methodError $
--                    MsgError{ errorName = "org.pontarius.Error.Revoke"
--                            , errorText = Just "Key not found"
--                            , errorBody = []
--                            }
--         _ -> DBus.methodError $
--                    MsgError{ errorName = "org.pontarius.Error.Revoke"
--                            , errorText = Just "Key not unique"
--                            , errorBody = []
--                            }
--     return ()

setSigningGpgKey :: PSState -> KeyID -> IO Bool
setSigningGpgKey st keyID = do
    let keyFpr = fromKeyID keyID
    ctx <- Gpg.ctxNew Nothing
    keys <- Gpg.getKeys ctx True
    matches <- filterM (liftM (== Just keyFpr) . Gpg.keyFingerprint) keys
    haveKey <- case matches of
        [] -> return False
        (_:_) -> return True
    runPSM st . when haveKey $ setSigningKey "gpg" (toKeyID keyFpr)
    return haveKey
setSigningGpgKey :: PSState -> KeyID -> IO Bool
setSigningGpgKey st keyID = do
    let keyFpr = fromKeyID keyID
    ctx <- Gpg.ctxNew Nothing
    keys <- Gpg.getKeys ctx True
    matches <- filterM (liftM (== Just keyFpr) . Gpg.keyFingerprint) keys
    haveKey <- case matches of
        [] -> return False
        (_:_) -> return True
    runPSM st . when haveKey $ setSigningKey "gpg" (toKeyID keyFpr)
    return haveKey
setSigningGpgKey st keyID = do
    let keyFpr = fromKeyID keyID
    ctx <- Gpg.ctxNew Nothing
    keys <- Gpg.getKeys ctx True
    matches <- filterM (liftM (== Just keyFpr) . Gpg.keyFingerprint) keys
    haveKey <- case matches of
        [] -> return False
        (_:_) -> return True
    runPSM st . when haveKey $ setSigningKey "gpg" (toKeyID keyFpr)
    return haveKey