21
#include "core/PassphraseGenerator.h"
23
#include <QCommandLineParser>
25
const QCommandLineOption Diceware::WordCountOption =
26
QCommandLineOption(QStringList() << "W"
28
QObject::tr("Word count for the diceware passphrase."),
29
QObject::tr("count", "CLI parameter"));
31
const QCommandLineOption Diceware::WordListOption =
32
QCommandLineOption(QStringList() << "w"
34
QObject::tr("Wordlist for the diceware generator.\n[Default: EFF English]"),
39
name = QString("diceware");
40
description = QObject::tr("Generate a new random diceware passphrase.");
41
options.append(Diceware::WordCountOption);
42
options.append(Diceware::WordListOption);
45
int Diceware::execute(const QStringList& arguments)
47
QSharedPointer<QCommandLineParser> parser = getCommandLineParser(arguments);
48
if (parser.isNull()) {
52
auto& out = Utils::STDOUT;
53
auto& err = Utils::STDERR;
55
PassphraseGenerator dicewareGenerator;
57
QString wordCount = parser->value(Diceware::WordCountOption);
58
if (wordCount.isEmpty()) {
59
dicewareGenerator.setWordCount(PassphraseGenerator::DefaultWordCount);
60
} else if (wordCount.toInt() <= 0) {
61
err << QObject::tr("Invalid word count %1").arg(wordCount) << endl;
64
dicewareGenerator.setWordCount(wordCount.toInt());
67
QString wordListFile = parser->value(Diceware::WordListOption);
68
if (!wordListFile.isEmpty()) {
69
dicewareGenerator.setWordList(wordListFile);
72
if (!dicewareGenerator.isValid()) {
75
err << QObject::tr("The word list is too small (< 1000 items)") << endl;
79
QString password = dicewareGenerator.generatePassphrase();
80
out << password << endl;