KVIrc  4.9.2
DeveloperAPIs
KviCryptEngine.h
Go to the documentation of this file.
1 #ifndef _KVI_CRYPT_ENGINE_H_
2 #define _KVI_CRYPT_ENGINE_H_
3 
4 //=============================================================================
5 //
6 // File : KviCryptEngine.h
7 // Creation date : Fri Nov 03 2000 01:45:21 CEST by Szymon Stefanek
8 //
9 // This file is part of the KVIrc IRC client distribution
10 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
11 //
12 // This program is FREE software. You can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the HOPE that it will be USEFUL,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 // See the GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, write to the Free Software Foundation,
24 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 #include "kvi_settings.h"
29 
30 //
31 // Base class for all IRC crypt engines
32 // These intend to encrypt plain text into something
33 // that can be sent through the IRC protocol...
34 // so it should not contain NULL, CR, LF and other
35 // similar stuff...
36 //
37 
38 #include "KviHeapObject.h"
39 
40 #include <QObject>
41 
42 class KviCString;
43 
44 #ifdef COMPILE_CRYPT_SUPPORT
45 class KviCryptEngine;
46 
47 typedef KviCryptEngine * (*crypt_engine_allocator_func)();
48 typedef void (*crypt_engine_deallocator_func)(KviCryptEngine *);
49 #endif //COMPILE_CRYPT_SUPPORT
50 
51 // we must include this declaration to make moc happy even
52 // if we're not compiling the crypt support
53 
54 class KVILIB_API KviCryptEngine : public QObject, public KviHeapObject
55 {
56  Q_OBJECT
57  friend class KviCryptEngineManager;
58 
59 public:
61  {
62  CanEncrypt = 1,
63  CanDecrypt = 2,
64  WantEncryptKey = 4,
65  WantDecryptKey = 8
66  };
67 
69  {
72  EncryptError
73  };
74 
76  {
80  DecryptError
81  };
82 
84  virtual ~KviCryptEngine();
85 
86 #ifdef COMPILE_CRYPT_SUPPORT
87 private:
88  crypt_engine_deallocator_func m_deallocFunc; // this is accessed by KviCryptEngineManager only
89  QString m_szLastError;
90  int m_iMaxEncryptLen;
91 
92 public:
93  void setMaxEncryptLen(int m) { m_iMaxEncryptLen = m; };
94  int maxEncryptLen() { return m_iMaxEncryptLen; };
95  virtual bool init(const char * encKey, int encKeyLen, const char * decKey, int decKeyLen);
96  //
97  // Encrypts utf8 plainText and returns the encrypted
98  // data in outBuffer. The encrypted data must be
99  // suitable for sending through an IRC (eventually DCC
100  // that is less restrictive) connection and must be utf8 encoded: so
101  // no NULL, CR and LF in the output.
102  // 0x01 should be also avoided since
103  // it is the CTCP delimiter.
104  // Converting the result in a HEX string
105  // is a good trick...also Base64 could be used.
106  // Should return false in case of an error.
107  // Theoretically we could allow NULLs in plainText
108  // but this is not the case of KVIrc.
109  //
110  virtual EncryptResult encrypt(const char * plainText, KviCString & outBuffer);
111  //
112  // Decrypts the utf8 data in inBuffer and puts the decrypted utf8
113  // stuff in plainText. inBuffer is the thingie
114  // that we got from outBuffer of encrupt() so it
115  // follows the same rules.
116  // Should return false in case of error.
117  //
118  virtual DecryptResult decrypt(const char * inBuffer, KviCString & plainText);
119  //
120  // Returns the string containing the description
121  // of the last error or an empty string if there
122  // was no error after the last init() call.
123  //
124  const QString & lastError() { return m_szLastError; };
125 protected:
126  //
127  // The following two should have clear meaning
128  //
129  void clearLastError() { m_szLastError = ""; };
130  void setLastError(const QString & err) { m_szLastError = err; };
131 #endif //COMPILE_CRYPT_SUPPORT
132 };
133 
134 #endif // _KVI_CRYPT_ENGINE_H_
EncryptResult
Definition: KviCryptEngine.h:68
Definition: KviHeapObject.h:124
Definition: KviCString.h:105
#define m
Definition: detector.cpp:77
DecryptResult
Definition: KviCryptEngine.h:75
Definition: KviCryptEngine.h:71
Definition: KviCryptEngine.h:54
Definition: KviCryptEngine.h:78
Heap Object.
int init()
Definition: winamp.cpp:118
Definition: KviCryptEngine.h:79
This file contains compile time settings.
Definition: KviCryptEngine.h:77
Definition: KviCryptEngine.h:70
EngineFlag
Definition: KviCryptEngine.h:60
#define KVILIB_API
Definition: kvi_settings.h:125