File indexing completed on 2025-01-05 04:55:51
0001 /* 0002 utils/assuan.h 0003 0004 This file is part of libkleopatra 0005 SPDX-FileCopyrightText: 2021, 2022 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "kleo_export.h" 0014 0015 #include <memory> 0016 #include <string> 0017 #include <vector> 0018 0019 namespace GpgME 0020 { 0021 class AssuanTransaction; 0022 class Context; 0023 class DefaultAssuanTransaction; 0024 class Error; 0025 } 0026 0027 namespace Kleo 0028 { 0029 /** The Assuan namespace collects functions for communicating with the GnuPG 0030 * agent via the Assuan protocol. */ 0031 namespace Assuan 0032 { 0033 0034 /** Checks if the GnuPG agent is running and accepts connections. */ 0035 KLEO_EXPORT bool agentIsRunning(); 0036 0037 /** Sends the Assuan @p command using the @p transaction and the @p assuanContext 0038 * to the GnuPG agent and waits for the result. The returned transaction can be used 0039 * to retrieve the result. 0040 * If an error occurred, then @p err provides details. */ 0041 KLEO_EXPORT std::unique_ptr<GpgME::AssuanTransaction> sendCommand(std::shared_ptr<GpgME::Context> &assuanContext, 0042 const std::string &command, 0043 std::unique_ptr<GpgME::AssuanTransaction> transaction, 0044 GpgME::Error &err); 0045 0046 /** Sends the Assuan @p command using a default Assuan transaction and the @p assuanContext 0047 * to the GnuPG agent and waits for the result. The returned transaction can be used 0048 * to retrieve the result. 0049 * If an error occurred, then @p err provides details. */ 0050 KLEO_EXPORT std::unique_ptr<GpgME::DefaultAssuanTransaction> 0051 sendCommand(std::shared_ptr<GpgME::Context> &assuanContext, const std::string &command, GpgME::Error &err); 0052 0053 /** Sends the Assuan @p command using a default Assuan transaction and the @p assuanContext 0054 * to the GnuPG agent and waits for the result. Returns the data that was sent by 0055 * GnuPG agent in response to the @p command. 0056 * If an error occurred, then @p err provides details. */ 0057 KLEO_EXPORT std::string sendDataCommand(std::shared_ptr<GpgME::Context> assuanContext, const std::string &command, GpgME::Error &err); 0058 0059 /** Sends the Assuan @p command using a default Assuan transaction and the @p assuanContext 0060 * to the GnuPG agent and waits for the result. Returns the status lines that were sent by 0061 * GnuPG agent in response to the @p command. 0062 * If an error occurred, then @p err provides details. */ 0063 KLEO_EXPORT std::vector<std::pair<std::string, std::string>> 0064 sendStatusLinesCommand(std::shared_ptr<GpgME::Context> assuanContext, const std::string &command, GpgME::Error &err); 0065 0066 /** Sends the Assuan @p command using a default Assuan transaction and the @p assuanContext 0067 * to the GnuPG agent and waits for the result. Returns the status that was sent by 0068 * GnuPG agent in response to the @p command. 0069 * If an error occurred, then @p err provides details. */ 0070 KLEO_EXPORT std::string sendStatusCommand(const std::shared_ptr<GpgME::Context> &assuanContext, const std::string &command, GpgME::Error &err); 0071 0072 } 0073 }