mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Merge pull request #1473 from keepassxreboot/feature/fix-faulty-initialization-windows
Fix Windows regression due to faulty static variable initialization
This commit is contained in:
commit
828dbf76eb
@ -93,7 +93,7 @@ QString FilePath::pluginPath(const QString& name)
|
||||
|
||||
QString FilePath::wordlistPath(const QString& name)
|
||||
{
|
||||
return m_instance->dataPath("wordlists/" + name);
|
||||
return dataPath("wordlists/" + name);
|
||||
}
|
||||
|
||||
QIcon FilePath::applicationIcon()
|
||||
|
@ -17,32 +17,31 @@
|
||||
|
||||
#include "PassphraseGenerator.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "crypto/Random.h"
|
||||
#include "core/FilePath.h"
|
||||
|
||||
const QString PassphraseGenerator::DefaultSeparator = " ";
|
||||
const QString PassphraseGenerator::DefaultWordList = "eff_large.wordlist";
|
||||
const char* PassphraseGenerator::DefaultSeparator = " ";
|
||||
const char* PassphraseGenerator::DefaultWordList = "eff_large.wordlist";
|
||||
|
||||
PassphraseGenerator::PassphraseGenerator()
|
||||
: m_wordCount(0)
|
||||
, m_separator(PassphraseGenerator::DefaultSeparator)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double PassphraseGenerator::calculateEntropy(QString passphrase)
|
||||
double PassphraseGenerator::calculateEntropy(const QString& passphrase)
|
||||
{
|
||||
Q_UNUSED(passphrase);
|
||||
|
||||
if (m_wordlist.size() == 0) {
|
||||
return 0;
|
||||
if (m_wordlist.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return log(m_wordlist.size()) / log(2.0) * m_wordCount;
|
||||
return std::log2(m_wordlist.size()) * m_wordCount;
|
||||
}
|
||||
|
||||
void PassphraseGenerator::setWordCount(int wordCount)
|
||||
@ -56,7 +55,7 @@ void PassphraseGenerator::setWordCount(int wordCount)
|
||||
|
||||
}
|
||||
|
||||
void PassphraseGenerator::setWordList(QString path)
|
||||
void PassphraseGenerator::setWordList(const QString& path)
|
||||
{
|
||||
m_wordlist.clear();
|
||||
|
||||
@ -83,7 +82,7 @@ void PassphraseGenerator::setDefaultWordList()
|
||||
setWordList(path);
|
||||
}
|
||||
|
||||
void PassphraseGenerator::setWordSeparator(QString separator) {
|
||||
void PassphraseGenerator::setWordSeparator(const QString& separator) {
|
||||
m_separator = separator;
|
||||
}
|
||||
|
||||
@ -97,8 +96,8 @@ QString PassphraseGenerator::generatePassphrase() const
|
||||
}
|
||||
|
||||
QStringList words;
|
||||
for (int i = 0; i < m_wordCount; i++) {
|
||||
int wordIndex = randomGen()->randomUInt(m_wordlist.length());
|
||||
for (int i = 0; i < m_wordCount; ++i) {
|
||||
int wordIndex = randomGen()->randomUInt(static_cast<quint32>(m_wordlist.length()));
|
||||
words.append(m_wordlist.at(wordIndex));
|
||||
}
|
||||
|
||||
@ -111,9 +110,5 @@ bool PassphraseGenerator::isValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_wordlist.size() < 1000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return m_wordlist.size() >= 1000;
|
||||
}
|
||||
|
@ -26,26 +26,25 @@ class PassphraseGenerator
|
||||
{
|
||||
public:
|
||||
PassphraseGenerator();
|
||||
Q_DISABLE_COPY(PassphraseGenerator)
|
||||
|
||||
double calculateEntropy(QString passphrase);
|
||||
double calculateEntropy(const QString& passphrase);
|
||||
void setWordCount(int wordCount);
|
||||
void setWordList(QString path);
|
||||
void setWordList(const QString& path);
|
||||
void setDefaultWordList();
|
||||
void setWordSeparator(QString separator);
|
||||
void setWordSeparator(const QString& separator);
|
||||
bool isValid() const;
|
||||
|
||||
QString generatePassphrase() const;
|
||||
|
||||
static const int DefaultWordCount = 7;
|
||||
static const QString DefaultSeparator;
|
||||
static const QString DefaultWordList;
|
||||
static constexpr int DefaultWordCount = 7;
|
||||
static const char* DefaultSeparator;
|
||||
static const char* DefaultWordList;
|
||||
|
||||
private:
|
||||
int m_wordCount;
|
||||
QString m_separator;
|
||||
QVector<QString> m_wordlist;
|
||||
|
||||
Q_DISABLE_COPY(PassphraseGenerator)
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_PASSPHRASEGENERATOR_H
|
||||
|
Loading…
Reference in New Issue
Block a user