Extract readKeyFromLine.

This commit is contained in:
Louis-Bertrand Varin
2017-01-14 13:25:30 -05:00
parent 1ca5b72073
commit 798041fe11
6 changed files with 54 additions and 42 deletions

View File

@@ -18,12 +18,15 @@
#include "CompositeKey.h"
#include "CompositeKey_p.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()
{
@@ -71,6 +74,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);