ImagingTools Core SDK
CEncryptionBasedPersistenceComp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// ACF includes
6#include <ifile/IFilePersistence.h>
7#include <ilog/TLoggerCompWrap.h>
8
9// ImtCore includes
10#include <imtcrypt/IEncryption.h>
11#include <imtcrypt/IEncryptionKeysProvider.h>
12#include <imtcrypt/IEncryptedFilePersistence.h>
13
14
15namespace imtcrypt
16{
17
18
24class CEncryptionBasedPersistenceComp: public ilog::CLoggerComponentBase,
26{
27public:
28 typedef ilog::CLoggerComponentBase BaseClass;
29
30 I_BEGIN_COMPONENT(CEncryptionBasedPersistenceComp);
31 I_REGISTER_INTERFACE(ifile::IFilePersistence);
32 I_REGISTER_INTERFACE(imtcrypt::IEncryptedFilePersistence);
33 I_ASSIGN(m_encryptionCompPtr, "Encryption", "Encrypt/Decrypt instances", true, "Encryption");
34 I_ASSIGN(m_encryptionKeysProviderCompPtr, "EncryptionKeysProvider", "Keys provider instances", true, "EncryptionKeysProvider");
35 I_ASSIGN(m_basePersistenceCompPtr, "BasePersistence", "Base file export instances", true, "BasePersistence");
36 I_ASSIGN(m_encryptionAlgorithm, "EncryptionAlgorithm", "Algoritm for encrypt/decrypt (0 - RSA, 1 - AES)", true, 1);
37 I_ASSIGN_MULTI_1(m_fileExtensionsAttrPtr, "FileExtensions", "List of possible file extensions", true, "txt");
38 I_ASSIGN_MULTI_1(m_typeDescriptionsAttrPtr, "TypeDescriptions", "List of descriptions for each extension", true, "Text file");
39 I_END_COMPONENT;
40
41protected:
42 // reimplemented (imtcrypt::IEncryptedFilePersistence)
43 virtual ifile::IFilePersistence::OperationState LoadFromEncryptedFile(const QByteArray& key, const QString& filePath, istd::IChangeable& data) const override;
44
45
46 // reimplemented (ifile::IFilePersistence)
47 virtual bool IsOperationSupported(
48 const istd::IChangeable* dataObjectPtr,
49 const QString* filePathPtr = NULL,
50 int flags = -1,
51 bool beQuiet = true) const override;
52 virtual OperationState LoadFromFile(
53 istd::IChangeable& data,
54 const QString& filePath = QString(),
55 ibase::IProgressManager* progressManagerPtr = NULL) const override;
56 virtual OperationState SaveToFile(
57 const istd::IChangeable& data,
58 const QString& filePath = QString(),
59 ibase::IProgressManager* progressManagerPtr = NULL) const override;
60
61 // reimplemented (ifile::IFileTypeInfo)
62 virtual bool GetFileExtensions(QStringList& result, const istd::IChangeable* dataObjectPtr = NULL, int flags = -1, bool doAppend = false) const;
63 virtual QString GetTypeDescription(const QString* extensionPtr = NULL) const;
64
65
66 class LocalKeyProvider : public imtcrypt::IEncryptionKeysProvider
67 {
68 public:
73 LocalKeyProvider(const imtcrypt::IEncryption::EncryptionAlgorithm& algorithm, const QByteArray& keyFirst, const QByteArray& keySecond);
74 LocalKeyProvider(){};
75
76 // reimplemented (imtcrypt::IEncryptionKeysProvider)
77 virtual QByteArray GetEncryptionKey(KeyType type) const;
78 private:
79 bool IsRequestOk(KeyType type) const;
80
81 QByteArray m_keyFirst;
82 QByteArray m_keySecond;
83 imtcrypt::IEncryption::EncryptionAlgorithm m_algorithm = imtcrypt::IEncryption::EA_AES;
84 };
85
86private:
87 I_REF(imtcrypt::IEncryption, m_encryptionCompPtr);
88 I_REF(imtcrypt::IEncryptionKeysProvider, m_encryptionKeysProviderCompPtr);
89 I_REF(ifile::IFilePersistence, m_basePersistenceCompPtr);
90 I_ATTR(int, m_encryptionAlgorithm);
91 I_MULTIATTR(QString, m_fileExtensionsAttrPtr);
92 I_MULTITEXTATTR(m_typeDescriptionsAttrPtr);
93};
94
95
96} //namespace imtcrypt
97
98
Cryptography and Encryption Services Module.