Add CLI tests and improve coding style and i18n

The CLI module was lacking unit test coverage and showed some severe
coding style violations, which this patch addresses.

In addition, all uses of qCritical() with untranslatble raw char*
sequences were removed in favor of proper locale strings. These are
written to STDERR through QTextStreams and support output
redirection for testing purposes. With this change, error messages don't
depend on the global Qt logging settings and targets anymore and go
directly to the terminal or into a file if needed.

This patch also fixes a bug discovered during unit test development,
where the extract command would just dump the raw XML contents without
decrypting embedded Salsa20-protected values first, making the XML
export mostly useless, since passwords are scrambled.

Lastly, all CLI commands received a dedicated -h/--help option.
This commit is contained in:
Janek Bevendorff
2018-09-29 19:00:47 +02:00
parent 18b22834c1
commit 113c8eb702
67 changed files with 2259 additions and 1250 deletions

View File

@@ -94,7 +94,7 @@ QString SymmetricCipher::errorString() const
SymmetricCipher::Algorithm SymmetricCipher::cipherToAlgorithm(const QUuid& cipher)
{
if (cipher == KeePass2::CIPHER_AES) {
if (cipher == KeePass2::CIPHER_AES256) {
return Aes256;
} else if (cipher == KeePass2::CIPHER_CHACHA20) {
return ChaCha20;
@@ -109,15 +109,17 @@ SymmetricCipher::Algorithm SymmetricCipher::cipherToAlgorithm(const QUuid& ciphe
QUuid SymmetricCipher::algorithmToCipher(Algorithm algo)
{
switch (algo) {
case Aes128:
return KeePass2::CIPHER_AES128;
case Aes256:
return KeePass2::CIPHER_AES;
return KeePass2::CIPHER_AES256;
case ChaCha20:
return KeePass2::CIPHER_CHACHA20;
case Twofish:
return KeePass2::CIPHER_TWOFISH;
default:
qWarning("SymmetricCipher::algorithmToCipher: invalid algorithm %d", algo);
return QUuid();
return {};
}
}