1 /*
2  *  Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 2 or (at your option)
7  *  version 3 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <cstdlib>
18 #include <stdio.h>
19 
20 #include "Info.h"
21 #include "Utils.h"
22 
23 #include "core/Database.h"
24 #include "core/Global.h"
25 #include "core/Metadata.h"
26 #include "format/KeePass2.h"
27 
Info()28 Info::Info()
29 {
30     name = QString("db-info");
31     description = QObject::tr("Show a database's information.");
32 }
33 
executeWithDatabase(QSharedPointer<Database> database,QSharedPointer<QCommandLineParser>)34 int Info::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser>)
35 {
36     auto& out = Utils::STDOUT;
37 
38     out << QObject::tr("UUID: ") << database->uuid().toString() << endl;
39     out << QObject::tr("Name: ") << database->metadata()->name() << endl;
40     out << QObject::tr("Description: ") << database->metadata()->description() << endl;
41     for (auto& cipher : asConst(KeePass2::CIPHERS)) {
42         if (cipher.first == database->cipher()) {
43             out << QObject::tr("Cipher: ") << cipher.second << endl;
44         }
45     }
46     out << QObject::tr("KDF: ") << database->kdf()->toString() << endl;
47     if (database->metadata()->recycleBinEnabled()) {
48         out << QObject::tr("Recycle bin is enabled.") << endl;
49     } else {
50         out << QObject::tr("Recycle bin is not enabled.") << endl;
51     }
52     return EXIT_SUCCESS;
53 }
54