diff --git a/src/format/KeePass2Reader.cpp b/src/format/KeePass2Reader.cpp index c6dd31c5f..54c426658 100644 --- a/src/format/KeePass2Reader.cpp +++ b/src/format/KeePass2Reader.cpp @@ -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 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 diff --git a/src/format/KeePass2Reader.h b/src/format/KeePass2Reader.h index c2e3c31b7..5f7187b8c 100644 --- a/src/format/KeePass2Reader.h +++ b/src/format/KeePass2Reader.h @@ -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;