Qt Cryptographic Architecture
qca_textfilter.h
Go to the documentation of this file.
1 /*
2  * qca_textfilter.h - Qt Cryptographic Architecture
3  * Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
4  * Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22 
33 #ifndef QCA_TEXTFILTER_H
34 #define QCA_TEXTFILTER_H
35 
36 #include "qca_core.h"
37 
38 namespace QCA {
39 
51 class QCA_EXPORT TextFilter : public Filter
52 {
53 public:
61 
68  void setup(Direction dir);
69 
74 
87 
100 
111  QString arrayToString(const MemoryRegion &a);
112 
123  MemoryRegion stringToArray(const QString &s);
124 
135  QString encodeString(const QString &s);
136 
147  QString decodeString(const QString &s);
148 
149 protected:
155 };
156 
164 class QCA_EXPORT Hex : public TextFilter
165 {
166 public:
176 
182  void clear() override;
183 
198  MemoryRegion update(const MemoryRegion &a) override;
199 
208  MemoryRegion final() override;
209 
215  bool ok() const override;
216 
217 private:
218  Q_DISABLE_COPY(Hex)
219 
220  uchar val;
221  bool partial;
222  bool _ok;
223 };
224 
232 class QCA_EXPORT Base64 : public TextFilter
233 {
234 public:
244 
248  bool lineBreaksEnabled() const;
249 
253  int lineBreaksColumn() const;
254 
263  void setLineBreaksEnabled(bool b);
264 
271  void setLineBreaksColumn(int column);
272 
277  void clear() override;
278 
293  MemoryRegion update(const MemoryRegion &a) override;
294 
303  MemoryRegion final() override;
304 
310  bool ok() const override;
311 
312 private:
313  Q_DISABLE_COPY(Base64)
314 
315  QByteArray partial;
316  bool _ok;
317  int col;
318  bool _lb_enabled;
319  int _lb_column;
320 
321  class Private;
322  Private *d;
323 };
324 
325 }
326 
327 #endif
Base64 encoding / decoding
Definition: qca_textfilter.h:233
bool ok() const override
Test if an update() or final() call succeeded.
bool lineBreaksEnabled() const
Returns true if line breaks are enabled.
void setLineBreaksColumn(int column)
Sets the column that linebreaks should be inserted at when encoding.
void clear() override
Reset the internal state.
Base64(Direction dir=Encode)
Standard constructor.
void setLineBreaksEnabled(bool b)
Sets line break mode.
int lineBreaksColumn() const
Returns the line break column.
MemoryRegion update(const MemoryRegion &a) override
Process more data, returning the corresponding encoded or decoded (depending on the Direction set in ...
General superclass for filtering transformation algorithms.
Definition: qca_core.h:1108
Hexadecimal encoding / decoding.
Definition: qca_textfilter.h:165
void clear() override
Reset the internal state.
Hex(Direction dir=Encode)
Standard constructor.
MemoryRegion update(const MemoryRegion &a) override
Process more data, returning the corresponding encoded or decoded (depending on the Direction set in ...
bool ok() const override
Test if an update() or final() call succeeded.
Array of bytes that may be optionally secured.
Definition: qca_tools.h:91
Superclass for text based filtering algorithms.
Definition: qca_textfilter.h:52
MemoryRegion encode(const MemoryRegion &a)
Process an array in the "forward" direction, returning an array.
QString arrayToString(const MemoryRegion &a)
Process an array in the "forward" direction, returning a QString.
Direction direction() const
The direction the TextFilter is set up to use.
Direction _dir
Internal state variable for the Direction that the filter operates in.
Definition: qca_textfilter.h:154
QString decodeString(const QString &s)
Process a string in the "reverse" direction, returning a string.
QString encodeString(const QString &s)
Process a string in the "forward" direction, returning a string.
void setup(Direction dir)
Reset the TextFilter.
TextFilter(Direction dir)
Standard constructor.
MemoryRegion decode(const MemoryRegion &a)
Process an array in the "reverse" direction, returning an array.
MemoryRegion stringToArray(const QString &s)
Process an string in the "reverse" direction, returning a byte array.
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
Direction
Direction settings for symmetric algorithms.
Definition: qca_core.h:141
@ Encode
Operate in the "forward" direction; for example, encrypting.
Definition: qca_core.h:142
Header file for core QCA infrastructure.