11#include <config-libkleo.h>
13#include "cryptoconfig.h"
14#include "cryptoconfig_p.h"
18#include <QGpgME/CryptoConfig>
19#include <QGpgME/Protocol>
21#include <unordered_map>
23using namespace QGpgME;
25static std::unordered_map<std::string, std::unordered_map<std::string, int>> fakeCryptoConfigIntValues;
26static std::unordered_map<std::string, std::unordered_map<std::string, QString>> fakeCryptoConfigStringValues;
28int Kleo::getCryptoConfigIntValue(
const char *componentName,
const char *entryName,
int defaultValue)
30 if (!fakeCryptoConfigIntValues.empty()) {
31 const auto componentIt = fakeCryptoConfigIntValues.find(componentName);
32 if (componentIt != std::end(fakeCryptoConfigIntValues)) {
33 const auto entryIt = componentIt->second.find(entryName);
34 if (entryIt != std::end(componentIt->second)) {
35 return entryIt->second;
40 const CryptoConfig *
const config = cryptoConfig();
44 const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
45 if (entry && entry->argType() == CryptoConfigEntry::ArgType_Int) {
46 return entry->intValue();
51QString Kleo::getCryptoConfigStringValue(
const char *componentName,
const char *entryName)
53 if (!fakeCryptoConfigStringValues.empty()) {
54 const auto componentIt = fakeCryptoConfigStringValues.find(componentName);
55 if (componentIt != std::end(fakeCryptoConfigStringValues)) {
56 const auto entryIt = componentIt->second.find(entryName);
57 if (entryIt != std::end(componentIt->second)) {
58 return entryIt->second;
63 const CryptoConfig *
const config = cryptoConfig();
67 const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
68 if (entry && entry->argType() == CryptoConfigEntry::ArgType_String) {
69 return entry->stringValue();
74QList<QUrl> Kleo::getCryptoConfigUrlList(
const char *componentName,
const char *entryName)
76 const CryptoConfig *
const config = cryptoConfig();
80 const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
81 if (entry && entry->isList() && (entry->argType() == CryptoConfigEntry::ArgType_LDAPURL || entry->argType() == CryptoConfigEntry::ArgType_Path)) {
82 return entry->urlValueList();
87void Kleo::Private::setFakeCryptoConfigIntValue(
const std::string &componentName,
const std::string &entryName,
int fakeValue)
89 fakeCryptoConfigIntValues[componentName][entryName] = fakeValue;
92void Kleo::Private::clearFakeCryptoConfigIntValue(
const std::string &componentName,
const std::string &entryName)
94 auto &entryMap = fakeCryptoConfigIntValues[componentName];
95 entryMap.erase(entryName);
96 if (entryMap.empty()) {
97 fakeCryptoConfigIntValues.erase(componentName);
101void Kleo::Private::setFakeCryptoConfigStringValue(
const std::string &componentName,
const std::string &entryName,
const QString &fakeValue)
103 fakeCryptoConfigStringValues[componentName][entryName] = fakeValue;
106void Kleo::Private::clearFakeCryptoConfigStringValue(
const std::string &componentName,
const std::string &entryName)
108 auto &entryMap = fakeCryptoConfigStringValues[componentName];
109 entryMap.erase(entryName);
110 if (entryMap.empty()) {
111 fakeCryptoConfigStringValues.erase(componentName);