File indexing completed on 2024-06-16 03:53:03
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2013 Valentin Rusu <kde@rusu.info> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef BACKENDPERSISTHANDLER_H 0009 #define BACKENDPERSISTHANDLER_H 0010 0011 #define KWMAGIC_LEN 12 0012 0013 #include <qwindowdefs.h> 0014 0015 class QFile; 0016 class QSaveFile; 0017 namespace KWallet 0018 { 0019 class Backend; 0020 0021 enum BackendCipherType { 0022 BACKEND_CIPHER_UNKNOWN, /// this is used by freshly allocated wallets 0023 BACKEND_CIPHER_BLOWFISH, /// use the legacy blowfish cipher type 0024 #ifdef HAVE_GPGMEPP 0025 BACKEND_CIPHER_GPG, /// use GPG backend to encrypt wallet contents 0026 #endif // HAVE_GPGMEPP 0027 }; 0028 0029 class BackendPersistHandler 0030 { 0031 protected: 0032 BackendPersistHandler() 0033 { 0034 } 0035 0036 public: 0037 virtual ~BackendPersistHandler() 0038 { 0039 } 0040 /** 0041 * This is a factory method used to get an instance of the backend suitable 0042 * for reading/writing using the given cipher type 0043 * 0044 * @param cipherType indication of the backend that should be returned 0045 * @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 0046 */ 0047 static BackendPersistHandler *getPersistHandler(BackendCipherType cipherType); 0048 static BackendPersistHandler *getPersistHandler(char magicBuf[KWMAGIC_LEN]); 0049 0050 virtual int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) = 0; 0051 virtual int read(Backend *wb, QFile &sf, WId w) = 0; 0052 }; 0053 0054 class BlowfishPersistHandler : public BackendPersistHandler 0055 { 0056 public: 0057 explicit BlowfishPersistHandler(bool useECBforReading = false) 0058 : _useECBforReading(useECBforReading) 0059 { 0060 } 0061 ~BlowfishPersistHandler() override 0062 { 0063 } 0064 0065 int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) override; 0066 int read(Backend *wb, QFile &sf, WId w) override; 0067 0068 private: 0069 bool _useECBforReading; 0070 }; 0071 0072 #ifdef HAVE_GPGMEPP 0073 class GpgPersistHandler : public BackendPersistHandler 0074 { 0075 public: 0076 GpgPersistHandler() 0077 { 0078 } 0079 ~GpgPersistHandler() override 0080 { 0081 } 0082 0083 int write(Backend *wb, QSaveFile &sf, QByteArray &version, WId w) override; 0084 int read(Backend *wb, QFile &sf, WId w) override; 0085 }; 0086 #endif // HAVE_GPGMEPP 0087 0088 } // namespace 0089 0090 #endif // BACKENDPERSISTHANDLER_H