Commit d2d8cb23 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Store card info map in base class

GnuPG-bug-id: 4876
parent 0137dee0
......@@ -189,7 +189,8 @@ bool Card::operator == (const Card &other) const
&& mAppVersion == other.appVersion()
&& mPinStates == other.pinStates()
&& mCanLearn == other.canLearnKeys()
&& mHasNullPin == other.hasNullPin();
&& mHasNullPin == other.hasNullPin()
&& mCardInfo == other.mCardInfo;
}
bool Card::operator != (const Card &other) const
......@@ -264,11 +265,24 @@ bool Card::parseCardInfo(const std::string &name, const std::string &value)
updateKeyInfo(info);
}
return true;
} else {
mCardInfo.insert({name, value});
}
return false;
}
void Card::addCardInfo(const std::string &name, const std::string &value)
{
mCardInfo.insert({name, value});
}
std::string Card::cardInfo(const std::string &name) const
{
const auto range = mCardInfo.equal_range(name);
return range.first != range.second ? range.first->second : std::string();
}
void Card::updateKeyInfo(const KeyPairInfo& keyPairInfo)
{
for (KeyPairInfo &k : mKeyInfos) {
......
......@@ -10,6 +10,7 @@
#include "keypairinfo.h"
#include <map>
#include <string>
#include <vector>
......@@ -104,6 +105,9 @@ protected:
bool parseCardInfo(const std::string &name, const std::string &value);
void addCardInfo(const std::string &name, const std::string &value);
std::string cardInfo(const std::string &name) const;
private:
void updateKeyInfo(const KeyPairInfo &keyPairInfo);
......@@ -123,6 +127,7 @@ private:
std::vector<PinState> mPinStates;
QString mErrMsg;
std::vector<KeyPairInfo> mKeyInfos;
std::multimap<std::string, std::string> mCardInfo;
};
} // namespace Smartcard
} // namespace Kleopatra
......
......@@ -118,20 +118,18 @@ void OpenPGPCard::setCardInfo(const std::vector< std::pair<std::string, std::str
const std::string keyRef = "OPENPGP." + keyNumber.toStdString();
const auto fpr = values[1].toStdString();
if (keyNumber == QLatin1Char('1') || keyNumber == QLatin1Char('2') || keyNumber == QLatin1Char('3')) {
mMetaInfo.insert("KLEO-FPR-" + keyRef, fpr);
addCardInfo("KLEO-FPR-" + keyRef, fpr);
} else {
// Maybe more keyslots in the future?
qCDebug(KLEOPATRA_LOG) << "Unhandled keyslot";
}
} else {
mMetaInfo.insert(pair.first, pair.second);
}
}
}
std::string OpenPGPCard::keyFingerprint(const std::string &keyRef) const
{
return mMetaInfo.value("KLEO-FPR-" + keyRef);
return cardInfo("KLEO-FPR-" + keyRef);
}
bool OpenPGPCard::operator == (const Card& rhs) const
......@@ -142,7 +140,6 @@ bool OpenPGPCard::operator == (const Card& rhs) const
}
return Card::operator ==(rhs)
&& mMetaInfo == other->mMetaInfo
&& mManufacturer == other->mManufacturer;
}
......@@ -158,5 +155,5 @@ std::string OpenPGPCard::manufacturer() const
std::string OpenPGPCard::pubkeyUrl() const
{
return mMetaInfo.value("PUBKEY-URL");
return cardInfo("PUBKEY-URL");
}
......@@ -12,8 +12,6 @@
#include "card.h"
#include <QMap>
namespace Kleo
{
namespace SmartCard
......@@ -51,7 +49,6 @@ public:
std::string pubkeyUrl() const;
private:
QMap <std::string, std::string> mMetaInfo;
std::string mManufacturer;
};
} // namespace Smartcard
......
......@@ -25,7 +25,7 @@ P15Card::P15Card(const Card &card)
std::string P15Card::appKeyFingerprint(const std::string &appKeyRef) const
{
return mMetaInfo.value("KLEO-FPR-" + appKeyRef);
return cardInfo("KLEO-FPR-" + appKeyRef);
}
void P15Card::setCardInfo(const std::vector< std::pair<std::string, std::string> > &infos)
......@@ -48,13 +48,11 @@ void P15Card::setCardInfo(const std::vector< std::pair<std::string, std::string>
const std::string keyRef = "OPENPGP." + keyNumber.toStdString();
const auto fpr = values[1].toStdString();
if (keyNumber == QLatin1Char('1') || keyNumber == QLatin1Char('2') || keyNumber == QLatin1Char('3')) {
mMetaInfo.insert("KLEO-FPR-" + keyRef, fpr);
addCardInfo("KLEO-FPR-" + keyRef, fpr);
} else {
// Maybe more keyslots in the future?
qCDebug(KLEOPATRA_LOG) << "Unhandled keyslot";
}
} else {
mMetaInfo.insert(pair.first, pair.second);
}
}
}
......@@ -77,6 +75,5 @@ bool P15Card::operator == (const Card& rhs) const
}
return Card::operator ==(rhs)
&& mMetaInfo == other->mMetaInfo
&& mManufacturer == other->mManufacturer;
}
......@@ -10,8 +10,6 @@
#include "card.h"
#include <QMap>
namespace Kleo
{
namespace SmartCard
......@@ -48,8 +46,8 @@ public:
std::string manufacturer() const;
bool operator == (const Card& other) const override;
private:
QMap <std::string, std::string> mMetaInfo;
std::string mManufacturer;
};
} // namespace Smartcard
......
......@@ -122,37 +122,25 @@ void PIVCard::setCardInfo(const std::vector< std::pair<std::string, std::string>
if (parseCardInfo(pair.first, pair.second)) {
continue;
}
mMetaInfo.insert(pair.first, pair.second);
}
}
std::string PIVCard::keyAlgorithm(const std::string &keyRef) const
{
return mMetaInfo.value("KLEO-KEYALGO-" + keyRef);
return cardInfo("KLEO-KEYALGO-" + keyRef);
}
void PIVCard::setKeyAlgorithm(const std::string &keyRef, const std::string &algorithm)
{
mMetaInfo.insert("KLEO-KEYALGO-" + keyRef, algorithm);
addCardInfo("KLEO-KEYALGO-" + keyRef, algorithm);
}
std::string PIVCard::certificateData(const std::string &keyRef) const
{
return mMetaInfo.value("KLEO-CERTIFICATE-" + keyRef);
return cardInfo("KLEO-CERTIFICATE-" + keyRef);
}
void PIVCard::setCertificateData(const std::string &keyRef, const std::string &data)
{
mMetaInfo.insert("KLEO-CERTIFICATE-" + keyRef, data);
}
bool PIVCard::operator == (const Card& rhs) const
{
const auto other = dynamic_cast<const PIVCard *>(&rhs);
if (!other) {
return false;
}
return Card::operator ==(rhs)
&& mMetaInfo == other->mMetaInfo;
addCardInfo("KLEO-CERTIFICATE-" + keyRef, data);
}
......@@ -10,8 +10,6 @@
#include "card.h"
#include <QMap>
namespace Kleo
{
namespace SmartCard
......@@ -45,11 +43,6 @@ public:
std::string certificateData(const std::string &keyRef) const;
void setCertificateData(const std::string &keyRef, const std::string &data);
bool operator == (const Card& other) const override;
private:
QMap <std::string, std::string> mMetaInfo;
};
} // namespace Smartcard
} // namespace Kleopatra
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment