EstervVault 1.0.0
Store encrypted data on the local system
Loading...
Searching...
No Matches
vault.hpp
1#pragma once
2
3#include <QByteArray>
4#include <QObject>
5
6#ifndef USE_EMSCRIPTEN
7
8#include <QStandardPaths>
9#endif
10
11#include <openssl/evp.h>
12
13#if defined(USE_QML)
14#include <QtQml>
15#endif
16
17#if defined(VAULT_SHARED)
18#include <QtCore/QtGlobal>
19#ifdef WINDOWS_EXPORT
20#define VAULT_EXPORT Q_DECL_EXPORT
21#else
22#define VAULT_EXPORT Q_DECL_IMPORT
23#endif
24#else
25#define VAULT_EXPORT
26#endif
27
29{
30
31class VAULT_EXPORT Vault : public QObject
32{
33
34 Q_OBJECT
35#ifdef USE_QML
36 Q_PROPERTY(QString file MEMBER m_file NOTIFY fileChanged)
37 Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY isEmptyChanged)
38 QML_ELEMENT
39#endif
40 public:
41 Vault(QObject *parent = nullptr, const QString filename =
42#if defined(USE_EMSCRIPTEN)
43 "vault"
44#else
46 "/estervvault.bin")
47#endif
48 );
49 Q_INVOKABLE QString getDataString(QString password) const;
50 QByteArray getData(QByteArray password) const;
51 void setFile(QString file)
52 {
53 if (file != m_file)
54 {
55 m_file = file;
56 restart();
57 emit fileChanged();
58 }
59 }
60 Q_INVOKABLE bool setDataString(QString plainText, QString password);
61 Q_INVOKABLE bool changePassword(QString oldPass, QString newPass);
62 Q_INVOKABLE bool checkPassword(QString password) const;
63 bool setData(QByteArray password, QByteArray plainText);
64 bool isEmpty() const
65 {
66 return m_isEmpty;
67 }
68
69 signals:
70 void isEmptyChanged();
71 void fileChanged();
72
73 private:
74 bool fromArray(QByteArray);
75 void setIsEmpty(bool isEmpty)
76 {
77 if (isEmpty != m_isEmpty)
78 {
79 m_isEmpty = isEmpty;
80 emit isEmptyChanged();
81 }
82 };
83 bool setContent(QByteArray plainText, QByteArray key);
84 QByteArray getContent(QByteArray key) const;
85 void setRandomIV();
86 void readFromFile();
87 void writeToFile();
88 void restart();
89
90 QString m_file;
91
92 QByteArray m_passHash, m_iv, m_cipherText;
93 EVP_CIPHER_CTX *m_ctx;
94 bool m_isEmpty;
95};
96} // namespace Esterv::Crypto
Definition vault.hpp:32
void setFile(QString file)
Definition vault.hpp:51
bool isEmpty() const
Definition vault.hpp:64
Definition vault.hpp:29
QString writableLocation(QStandardPaths::StandardLocation type)