KWallet

backendpersisthandler.h
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2013 Valentin Rusu <kde@rusu.info>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#ifndef BACKENDPERSISTHANDLER_H
9#define BACKENDPERSISTHANDLER_H
10
11#define KWMAGIC_LEN 12
12
13#include <qwindowdefs.h>
14
15class QFile;
16class QSaveFile;
17namespace KWallet
18{
19class Backend;
20
21enum BackendCipherType {
22 BACKEND_CIPHER_UNKNOWN, /// this is used by freshly allocated wallets
23 BACKEND_CIPHER_BLOWFISH, /// use the legacy blowfish cipher type
24#ifdef HAVE_GPGMEPP
25 BACKEND_CIPHER_GPG, /// use GPG backend to encrypt wallet contents
26#endif // HAVE_GPGMEPP
27};
28
29class BackendPersistHandler
30{
31protected:
32 BackendPersistHandler()
33 {
34 }
35
36public:
37 virtual ~BackendPersistHandler()
38 {
39 }
40 /**
41 * This is a factory method used to get an instance of the backend suitable
42 * for reading/writing using the given cipher type
43 *
44 * @param cipherType indication of the backend that should be returned
45 * @return a pointer to an instance of the requested handler type. No need to delete this pointer, it's lifetime is taken care of by this factory
46 */
47 static BackendPersistHandler *getPersistHandler(BackendCipherType cipherType);
48 static BackendPersistHandler *getPersistHandler(char magicBuf[KWMAGIC_LEN]);
49
50 virtual int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) = 0;
51 virtual int read(Backend *wb, QFile &sf, WId w) = 0;
52};
53
54class BlowfishPersistHandler : public BackendPersistHandler
55{
56public:
57 explicit BlowfishPersistHandler(bool useECBforReading = false)
58 : _useECBforReading(useECBforReading)
59 {
60 }
61 ~BlowfishPersistHandler() override
62 {
63 }
64
65 int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) override;
66 int read(Backend *wb, QFile &sf, WId w) override;
67
68private:
69 bool _useECBforReading;
70};
71
72#ifdef HAVE_GPGMEPP
73class GpgPersistHandler : public BackendPersistHandler
74{
75public:
76 GpgPersistHandler()
77 {
78 }
79 ~GpgPersistHandler() override
80 {
81 }
82
83 int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) override;
84 int read(Backend *wb, QFile &sf, WId w) override;
85};
86#endif // HAVE_GPGMEPP
87
88} // namespace
89
90#endif // BACKENDPERSISTHANDLER_H
QVariant read(const QByteArray &data, int versionOverride=0)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.