source: SMSSender/common/persistence/impl/encryptedstoragehelper_base.h @ 319:1ec456878bcb

separation-frontend-backend
Last change on this file since 319:1ec456878bcb was 319:1ec456878bcb, checked in by Sämy Zehnder <saemy.zehnder@…>, 7 years ago
  • Adjusts header guards to follow common pattern based on the filename.
File size: 4.1 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
19#define COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
20
21#include <QScopedPointer>
22
23#include "common/persistence/imainstorage.h"
24#include "common/persistence/istoragehelper.h"
25
26namespace Persistence {
27
28class BaseEncryptedMainStorage : public IMainStorage {
29public:
30    explicit BaseEncryptedMainStorage(IMainStorage *mainStorage, const QString &encryptionKey)
31        : m_mainStorage(mainStorage)
32        , m_encryptionKey(encryptionKey)
33    {}
34
35    inline QVariant readValue(const QString &_namespace, const QString &key, const QVariant &defaultValue = QVariant()) { return m_mainStorage->readValue(_namespace, key, defaultValue); }
36    inline bool readBool(const QString &_namespace, const QString &key, bool defaultValue = false) { return m_mainStorage->readBool(_namespace, key, defaultValue); }
37    inline int readInt(const QString &_namespace, const QString &key, int defaultValue = 0) { return m_mainStorage->readInt(_namespace, key, defaultValue); }
38    inline QString readString(const QString &_namespace, const QString &key, const QString &defaultValue = QString()) { return m_mainStorage->readString(_namespace, key, defaultValue); }
39    inline QString readEncryptedString(const QString &_namespace, const QString &key, const QString &password, const QString &defaultValue) { return m_mainStorage->readEncryptedString(_namespace, key, password, defaultValue); }
40    inline QString readEncryptedString(const QString &_namespace, const QString &key, const QString &defaultValue) { return readEncryptedString(_namespace, key, m_encryptionKey, defaultValue); }
41
42    inline void writeValue(const QString &_namespace, const QString &key, const QVariant &value) { m_mainStorage->writeValue(_namespace, key, value); }
43    inline void writeBool(const QString &_namespace, const QString &key, bool value) { m_mainStorage->writeBool(_namespace, key, value); }
44    inline void writeInt(const QString &_namespace, const QString &key, int value) { m_mainStorage->writeInt(_namespace, key, value); }
45    inline void writeString(const QString &_namespace, const QString &key, const QString &value) { m_mainStorage->writeString(_namespace, key, value); }
46    inline void writeEncryptedString(const QString &_namespace, const QString &key, const QString &password, const QString &value) { m_mainStorage->writeEncryptedString(_namespace, key, password, value); }
47    inline void writeEncryptedString(const QString &_namespace, const QString &key, const QString &value) { writeEncryptedString(_namespace, key, m_encryptionKey, value); }
48
49    inline void removeValue(const QString &_namespace, const QString &key) { m_mainStorage->removeValue(_namespace, key); }
50    inline void removeValues(const QString &_namespace) { m_mainStorage->removeValues(_namespace); }
51
52protected:
53    inline void init(const QSqlDatabase &db) { Q_UNUSED(db); Q_ASSERT(false); }
54    inline QSqlDatabase database() { Q_ASSERT(false); return QSqlDatabase(); }
55
56    IMainStorage * const m_mainStorage;
57
58private:
59    const QString m_encryptionKey;
60};
61
62class EncryptedStorageHelper : public IStorageHelper {
63public:
64    EncryptedStorageHelper(IMainStorage *storage, const QString &encryptionKey);
65
66protected:
67    BaseEncryptedMainStorage *storage() const;
68
69private:
70    QScopedPointer<BaseEncryptedMainStorage> m_storage;
71};
72
73}
74
75#endif // COMMON_PERSISTENCE_IMPL_ENCRYPTEDSTORAGEHELPER_BASE_H
Note: See TracBrowser for help on using the repository browser.