This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkeystore.h
98 lines (77 loc) · 3.1 KB
/
keystore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef QTDATASYNC_KEYSTORE_H
#define QTDATASYNC_KEYSTORE_H
#include <QtCore/qobject.h>
#include "QtDataSync/qtdatasync_global.h"
#include "QtDataSync/exception.h"
namespace QtDataSync {
class KeyStore;
//! An exception to be thrown from within a keystore if an error occurs
class Q_DATASYNC_EXPORT KeyStoreException : public Exception
{
public:
//! Constructor that takes the store it was thrown from and an error message
KeyStoreException(const KeyStore * const keyStore, const QString &what);
//! The name of the type of store the exception was thrown from
QString storeProviderName() const;
QByteArray className() const noexcept override;
QString qWhat() const override;
void raise() const override;
QException *clone() const override;
protected:
//! @private
KeyStoreException(const KeyStoreException * const other);
//! @private
const QString _keyStoreName;
};
class KeyStorePrivate;
//! An interface for a generic keystore to securely store secret cryptographic keys
class Q_DATASYNC_EXPORT KeyStore : public QObject
{
Q_OBJECT
friend class QtDataSync::KeyStoreException;
public:
//! Default constructor for a specific setup
explicit KeyStore(const Defaults &defaults, QObject *parent = nullptr);
~KeyStore() override;
//! Returns the name of the setup this class operates on
QString setupName() const;
//! Returns the provider type the keystore is of
virtual QString providerName() const = 0;
//! Checks if the store is currently open
virtual bool isOpen() const = 0;
//! Opens the store so the library can access it
virtual void openStore() = 0;
//! Closes the connection to the store
virtual void closeStore() = 0;
//! Checks if a key already exists in the store
virtual bool contains(const QString &key) const = 0;
//! Saves a secret key with the given identifier in the store
virtual void save(const QString &key, const QByteArray &pKey) = 0;
//! Loads a previously saved key for the given identifier from the store
virtual QByteArray load(const QString &key) = 0;
//! Removes the key for the given identifier from the store permanently
virtual void remove(const QString &key) = 0;
protected:
//! Returns the defaults of the datasync instance the store is operated from
Defaults defaults() const;
private:
QScopedPointer<KeyStorePrivate> d;
};
//! The keystore plugin to be implemented to provide custom keystores
class Q_DATASYNC_EXPORT KeyStorePlugin
{
Q_DISABLE_COPY(KeyStorePlugin)
public:
inline KeyStorePlugin() = default;
virtual inline ~KeyStorePlugin() = default;
//! Check if the keystore type identified by the provider is currently accessible
virtual bool keystoreAvailable(const QString &provider) const = 0;
//! Create an instance of a keystore for the given provider and parent
virtual KeyStore *createInstance(const QString &provider, const Defaults &defaults, QObject *parent = nullptr) = 0;
};
}
//! The IID to be used to create a keystore plugin
#define QtDataSync_KeyStorePlugin_Iid "de.skycoder42.QtDataSync.KeyStorePlugin"
Q_DECLARE_INTERFACE(QtDataSync::KeyStorePlugin, QtDataSync_KeyStorePlugin_Iid)
//! @file keystore.h The Keystore header
#endif // QTDATASYNC_KEYSTORE_H