Add support for Diceware wordlists in numbered and/or PGP-signed formats (#6791)
This allows one to directly use Diceware-compatible wordlists without having to convert the file to the plain wordlist format. The accepted formats are described in the Diceware documentation: https://diceware.readthedocs.io/en/stable/wordlists.html
This commit is contained in:
@@ -68,8 +68,28 @@ void PassphraseGenerator::setWordList(const QString& path)
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
m_wordlist.append(in.readLine());
|
||||
QString line = in.readLine();
|
||||
bool isSigned = line.startsWith("-----BEGIN PGP SIGNED MESSAGE-----");
|
||||
if (isSigned) {
|
||||
while (!line.isNull() && !line.trimmed().isEmpty()) {
|
||||
line = in.readLine();
|
||||
}
|
||||
}
|
||||
QRegExp rx("^[0-9]+(-[0-9]+)*\\s+([^\\s]+)$");
|
||||
while (!line.isNull()) {
|
||||
if (isSigned && line.startsWith("-----BEGIN PGP SIGNATURE-----")) {
|
||||
break;
|
||||
}
|
||||
// Handle dash-escaped lines (if the wordlist is signed)
|
||||
if (isSigned && line.startsWith("- ")) {
|
||||
line.remove(0, 2);
|
||||
}
|
||||
line = line.trimmed();
|
||||
line.replace(rx, "\\2");
|
||||
if (!line.isEmpty()) {
|
||||
m_wordlist.append(line);
|
||||
}
|
||||
line = in.readLine();
|
||||
}
|
||||
|
||||
if (m_wordlist.size() < 4000) {
|
||||
|
||||
Reference in New Issue
Block a user