Add ability to grab the raw xml string of kdbx databases.

This commit is contained in:
Felix Geyer 2011-07-06 20:21:40 +02:00
parent a104e859cf
commit ef8935431c
2 changed files with 29 additions and 0 deletions

View File

@ -29,6 +29,11 @@
#include "streams/QtIOCompressor"
#include "streams/SymmetricCipherStream.h"
KeePass2Reader::KeePass2Reader()
{
m_saveXml = false;
}
Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& key)
{
m_db = new Database();
@ -102,6 +107,15 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
SymmetricCipher protectedStream(SymmetricCipher::Salsa20, SymmetricCipher::Stream, SymmetricCipher::Decrypt,
protectedStreamKey, KeePass2::INNER_STREAM_SALSA20_IV);
QScopedPointer<QBuffer> buffer;
if (m_saveXml) {
m_xmlData = xmlDevice->readAll();
buffer.reset(new QBuffer(&m_xmlData));
buffer->open(QIODevice::ReadOnly);
xmlDevice = buffer.data();
}
KeePass2XmlReader xmlReader;
xmlReader.readDatabase(xmlDevice, m_db, &protectedStream);
// TODO forward error messages from xmlReader
@ -128,6 +142,16 @@ QString KeePass2Reader::errorString()
return QString();
}
void KeePass2Reader::setSaveXml(bool save)
{
m_saveXml = save;
}
QByteArray KeePass2Reader::xmlData()
{
return m_xmlData;
}
void KeePass2Reader::raiseError(const QString& str)
{
// TODO

View File

@ -31,10 +31,13 @@ class KeePass2Reader
Q_DECLARE_TR_FUNCTIONS(KeePass2Reader);
public:
KeePass2Reader();
Database* readDatabase(QIODevice* device, const CompositeKey& key);
Database* readDatabase(const QString& filename, const CompositeKey& key);
bool error();
QString errorString();
void setSaveXml(bool save);
QByteArray xmlData();
private:
void raiseError(const QString& str);
@ -55,6 +58,8 @@ private:
bool m_error;
QString m_errorStr;
bool m_headerEnd;
bool m_saveXml;
QByteArray m_xmlData;
Database* m_db;
QByteArray m_masterSeed;