Change the Entry attributes/attachment API to provide a stable key order.

This commit is contained in:
Felix Geyer 2012-04-06 19:33:29 +02:00
parent b3063c6fc8
commit d527e63f1f
6 changed files with 73 additions and 35 deletions

View file

@ -135,14 +135,24 @@ const QList<AutoTypeAssociation>& Entry::autoTypeAssociations() const
return m_autoTypeAssociations;
}
const QHash<QString, QString>& Entry::attributes() const
const QList<QString>& Entry::attributes() const
{
return m_attributes;
return m_attributesKeys;
}
const QHash<QString, QByteArray>& Entry::attachments() const
QString Entry::attributeValue(const QString& key) const
{
return m_binaries;
return m_attributes.value(key);
}
const QList<QString>& Entry::attachments() const
{
return m_binariesKeys;
}
QByteArray Entry::attachmentValue(const QString& key) const
{
return m_binaries.value(key);
}
bool Entry::isAttributeProtected(const QString& key) const
@ -254,7 +264,12 @@ void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
void Entry::setAttribute(const QString& key, const QString& value, bool protect)
{
if (!m_attributes.contains(key)) {
m_attributesKeys.append(key);
}
m_attributes.insert(key, value);
if (protect) {
m_protectedAttributes.insert(key);
}
@ -271,13 +286,19 @@ void Entry::removeAttribute(const QString& key)
{
Q_ASSERT(!isDefaultAttribute(key));
m_attributesKeys.removeOne(key);
m_attributes.remove(key);
m_protectedAttributes.remove(key);
}
void Entry::setAttachment(const QString& key, const QByteArray& value, bool protect)
{
if (!m_binaries.contains(key)) {
m_binariesKeys.append(key);
}
m_binaries.insert(key, value);
if (protect) {
m_protectedAttachments.insert(key);
}
@ -288,6 +309,7 @@ void Entry::setAttachment(const QString& key, const QByteArray& value, bool prot
void Entry::removeAttachment(const QString& key)
{
m_binariesKeys.removeOne(key);
m_binaries.remove(key);
m_protectedAttachments.remove(key);
}

View file

@ -60,8 +60,10 @@ public:
int autoTypeObfuscation() const;
QString defaultAutoTypeSequence() const;
const QList<AutoTypeAssociation>& autoTypeAssociations() const;
const QHash<QString, QString>& attributes() const;
const QHash<QString, QByteArray>& attachments() const;
const QList<QString>& attributes() const;
QString attributeValue(const QString& key) const;
const QList<QString>& attachments() const;
QByteArray attachmentValue(const QString& key) const;
bool isAttributeProtected(const QString& key) const;
bool isAttachmentProtected(const QString& key) const;
QString title() const;
@ -121,7 +123,9 @@ private:
QString m_defaultAutoTypeSequence;
QList<AutoTypeAssociation> m_autoTypeAssociations;
QHash<QString, QString> m_attributes;
QList<QString> m_attributesKeys;
QHash<QString, QByteArray> m_binaries;
QList<QString> m_binariesKeys;
QSet<QString> m_protectedAttributes;
QSet<QString> m_protectedAttachments;

View file

@ -253,7 +253,7 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
writeString("Tags", entry->tags());
writeTimes(entry->timeInfo());
Q_FOREACH (const QString& key, entry->attributes().keys()) {
Q_FOREACH (const QString& key, entry->attributes()) {
m_xml.writeStartElement("String");
bool protect = ( ((key == "Title") && m_meta->protectTitle()) ||
@ -271,11 +271,11 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
if (protect) {
m_xml.writeAttribute("Protected", "True");
QByteArray rawData = m_randomStream->process(entry->attributes().value(key).toUtf8());
QByteArray rawData = m_randomStream->process(entry->attributeValue(key).toUtf8());
value = QString::fromAscii(rawData.toBase64());
}
else {
value = entry->attributes().value(key);
value = entry->attributeValue(key);
}
m_xml.writeCharacters(value);
@ -284,7 +284,7 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
m_xml.writeEndElement();
}
Q_FOREACH (const QString& key, entry->attachments().keys()) {
Q_FOREACH (const QString& key, entry->attachments()) {
m_xml.writeStartElement("Binary");
bool protect = entry->isAttachmentProtected(key) && m_randomStream;
@ -296,11 +296,11 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
if (protect) {
m_xml.writeAttribute("Protected", "True");
QByteArray rawData = m_randomStream->process(entry->attachments().value(key));
QByteArray rawData = m_randomStream->process(entry->attachmentValue(key));
value = QString::fromAscii(rawData.toBase64());
}
else {
value = entry->attachments().value(key);
value = entry->attachmentValue(key);
}
m_xml.writeCharacters(value);