1 #include "dbsqlitecipher.h"
2 #include "sqlitestudio.h"
3 #include "services/extralicensemanager.h"
4 #include "common/unused.h"
5 #include "dbsqlitecipherinstance.h"
6 #include "services/notifymanager.h"
7 #include <limits>
8
DbSqliteCipher()9 DbSqliteCipher::DbSqliteCipher()
10 {
11 }
12
getLabel() const13 QString DbSqliteCipher::getLabel() const
14 {
15 return "SQLCipher";
16 }
17
checkIfDbServedByPlugin(Db * db) const18 bool DbSqliteCipher::checkIfDbServedByPlugin(Db* db) const
19 {
20 return (db && dynamic_cast<DbSqliteCipherInstance*>(db));
21 }
22
getOptionsList() const23 QList<DbPluginOption> DbSqliteCipher::getOptionsList() const
24 {
25 QList<DbPluginOption> opts;
26
27 DbPluginOption opt;
28 opt.type = DbPluginOption::PASSWORD;
29 opt.key = PASSWORD_OPT;
30 opt.label = tr("Password (key)");
31 opt.toolTip = tr("Leave empty to create or connect to decrypted database.");
32 opt.placeholderText = tr("Encryption password");
33 opts << opt;
34
35 opt.type = DbPluginOption::SQL;
36 opt.key = PRAGMAS_OPT;
37 opt.label = tr("Cipher configuration (optional)");
38 opt.toolTip = tr("PRAGMA statements to customize SQLCipher configuration, such as KDF iterations, legacy mode, etc.\n"
39 "They will be executed upon each opening of the database.\n"
40 "See documentation for SQLCipher for details.");
41 opts << opt;
42
43 return opts;
44 }
45
init()46 bool DbSqliteCipher::init()
47 {
48 Q_INIT_RESOURCE(dbsqlitecipher);
49
50 if (!SQLITESTUDIO->getExtraLicenseManager()->addLicense(LICENSE_TITLE, ":/license/sqlcipher.txt"))
51 {
52 qCritical() << "Could not register SQLCipher license.";
53 return false;
54 }
55
56 if (!SQLITESTUDIO->getExtraLicenseManager()->addLicense(OPENSSL_TITLE, ":/license/openssl_lic.txt"))
57 {
58 qCritical() << "Could not register OpenSSL license.";
59 return false;
60 }
61
62 initValid = true;
63 return true;
64 }
65
deinit()66 void DbSqliteCipher::deinit()
67 {
68 SQLITESTUDIO->getExtraLicenseManager()->removeLicense(LICENSE_TITLE);
69 Q_CLEANUP_RESOURCE(dbsqlitecipher);
70 }
71
newInstance(const QString & name,const QString & path,const QHash<QString,QVariant> & options)72 Db *DbSqliteCipher::newInstance(const QString &name, const QString &path, const QHash<QString, QVariant> &options)
73 {
74 return new DbSqliteCipherInstance(name, path, options);
75 }
76