QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
keystore.h
Go to the documentation of this file.
1 #ifndef QTDATASYNC_KEYSTORE_H
2 #define QTDATASYNC_KEYSTORE_H
3 
4 #include <QtCore/qobject.h>
5 
6 #include "QtDataSync/qtdatasync_global.h"
7 #include "QtDataSync/exception.h"
8 
9 namespace QtDataSync {
10 
11 class KeyStore;
13 class Q_DATASYNC_EXPORT KeyStoreException : public Exception
14 {
15 public:
17  KeyStoreException(const KeyStore * const keyStore, const QString &what);
18 
20  QString storeProviderName() const;
21 
22  QByteArray className() const noexcept override;
23  QString qWhat() const override;
24  void raise() const override;
25  QException *clone() const override;
26 
27 protected:
29  KeyStoreException(const KeyStoreException * const other);
30 
32  const QString _keyStoreName;
33 };
34 
35 class KeyStorePrivate;
37 class Q_DATASYNC_EXPORT KeyStore : public QObject
38 {
39  Q_OBJECT
40  friend class QtDataSync::KeyStoreException;
41 
42 public:
44  explicit KeyStore(const Defaults &defaults, QObject *parent = nullptr);
45  ~KeyStore() override;
46 
48  QString setupName() const;
49 
51  virtual QString providerName() const = 0;
52 
54  virtual bool isOpen() const = 0;
56  virtual void openStore() = 0;
58  virtual void closeStore() = 0;
59 
61  virtual bool contains(const QString &key) const = 0;
63  virtual void save(const QString &key, const QByteArray &pKey) = 0;
65  virtual QByteArray load(const QString &key) = 0;
67  virtual void remove(const QString &key) = 0;
68 
69 protected:
71  Defaults defaults() const;
72 
73 private:
75 };
76 
78 class Q_DATASYNC_EXPORT KeyStorePlugin
79 {
80  Q_DISABLE_COPY(KeyStorePlugin)
81 public:
82  inline KeyStorePlugin() = default;
83  virtual inline ~KeyStorePlugin() = default;
84 
86  virtual bool keystoreAvailable(const QString &provider) const = 0;
88  virtual KeyStore *createInstance(const QString &provider, const Defaults &defaults, QObject *parent = nullptr) = 0;
89 };
90 
91 }
92 
94 #define QtDataSync_KeyStorePlugin_Iid "de.skycoder42.QtDataSync.KeyStorePlugin"
96 
97 #endif // QTDATASYNC_KEYSTORE_H
QString setupName() const
Returns the name of the setup the exception was thrown from.
The base class for all exceptions of QtDataSync.
Definition: exception.h:13
An interface for a generic keystore to securely store secret cryptographic keys.
Definition: keystore.h:37
The keystore plugin to be implemented to provide custom keystores.
Definition: keystore.h:78
The primary namespace of the QtDataSync library.
#define QtDataSync_KeyStorePlugin_Iid
The IID to be used to create a keystore plugin.
Definition: keystore.h:94
A helper class to get defaults per datasync instance (threadsafe)
Definition: defaults.h:61
An exception to be thrown from within a keystore if an error occurs.
Definition: keystore.h:13