diff options
author | Janek Bevendorff <janek@jbev.net> | 2017-01-15 04:20:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-15 04:20:21 +0300 |
commit | e17576a6f71c1ff3671f01be72b93ff6f7c8861a (patch) | |
tree | 941ef6d78f04890998b69803c28e083a8c174c24 /src/keys | |
parent | f33cd1541941a088b90f463d457f4a9f86aa712a (diff) | |
parent | 9dadafe20a2a9c7878b4505c1aa4097c87b955f4 (diff) |
Merge branch 'develop' into feature/yubikey
Diffstat (limited to 'src/keys')
-rw-r--r-- | src/keys/CompositeKey.cpp | 28 | ||||
-rw-r--r-- | src/keys/CompositeKey.h | 2 | ||||
-rw-r--r-- | src/keys/FileKey.cpp | 6 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp index ae654eb74..4e79cd05c 100644 --- a/src/keys/CompositeKey.cpp +++ b/src/keys/CompositeKey.cpp @@ -19,12 +19,15 @@ #include "CompositeKey_p.h" #include "ChallengeResponseKey.h" -#include <QtConcurrent> #include <QElapsedTimer> +#include <QFile> +#include <QtConcurrent> #include "core/Global.h" #include "crypto/CryptoHash.h" #include "crypto/SymmetricCipher.h" +#include "keys/FileKey.h" +#include "keys/PasswordKey.h" CompositeKey::CompositeKey() { @@ -77,6 +80,29 @@ CompositeKey& CompositeKey::operator=(const CompositeKey& key) return *this; } +/* + * Read a key from a line of input. + * If the line references a valid file + * path, the key is loaded from file. + */ +CompositeKey CompositeKey::readFromLine(QString line) +{ + + CompositeKey key; + if (QFile::exists(line)) { + FileKey fileKey; + fileKey.load(line); + key.addKey(fileKey); + } + else { + PasswordKey password; + password.setPassword(line); + key.addKey(password); + } + return key; + +} + QByteArray CompositeKey::rawKey() const { CryptoHash cryptoHash(CryptoHash::Sha256); diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h index b5f973d20..531c2d9b2 100644 --- a/src/keys/CompositeKey.h +++ b/src/keys/CompositeKey.h @@ -19,6 +19,7 @@ #define KEEPASSX_COMPOSITEKEY_H #include <QList> +#include <QString> #include "keys/Key.h" #include "keys/ChallengeResponseKey.h" @@ -43,6 +44,7 @@ public: void addChallengeResponseKey(const ChallengeResponseKey& key); static int transformKeyBenchmark(int msec); + static CompositeKey readFromLine(QString line); private: static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, diff --git a/src/keys/FileKey.cpp b/src/keys/FileKey.cpp index d399f545f..d3cdfe040 100644 --- a/src/keys/FileKey.cpp +++ b/src/keys/FileKey.cpp @@ -190,18 +190,18 @@ bool FileKey::loadXml(QIODevice* device) bool FileKey::loadXmlMeta(QXmlStreamReader& xmlReader) { - bool corectVersion = false; + bool correctVersion = false; while (!xmlReader.error() && xmlReader.readNextStartElement()) { if (xmlReader.name() == "Version") { // TODO: error message about incompatible key file version if (xmlReader.readElementText() == "1.00") { - corectVersion = true; + correctVersion = true; } } } - return corectVersion; + return correctVersion; } QByteArray FileKey::loadXmlKey(QXmlStreamReader& xmlReader) |