summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/binentrygen.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/binentrygen.cpp') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/binentrygen.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/binentrygen.cpp b/pwmanager/pwmanager/binentrygen.cpp
new file mode 100644
index 0000000..7d5ae45
--- a/dev/null
+++ b/pwmanager/pwmanager/binentrygen.cpp
@@ -0,0 +1,71 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20
21#include "binentrygen.h"
22#include "base64.h"
23#include "pwmexception.h"
24
25
26void BinEntryGen::encode(const QByteArray &data,
27 PwMDataItem *ret,
28 DataType type)
29{
30 ret->clear();
31 ret->name = tostr(static_cast<int>(type));
32 ret->binary = true;
33 if (data.size() == 0)
34 return;
35 Base64 b64;
36 string d(data.data(), data.size());
37 ret->pw = b64.encode(d);
38}
39
40void BinEntryGen::decode(const PwMDataItem &data,
41 QByteArray *ret,
42 DataType *type)
43{
44 BUG_ON(!data.binary);
45 int t = strtol(data.name.c_str(), 0, 10);
46 *type = static_cast<DataType>(t);
47 switch (*type) {
48 case None:
49 case KWalletMap:
50 case KWalletStream:
51 break;
52 default:
53 *type = None;
54 }
55 if (data.pw == "") {
56 ret->fill(0);
57 ret->resize(0);
58 return;
59 }
60 Base64 b64;
61 string d(b64.decode(data.pw));
62 ret->duplicate(d.c_str(), d.length());
63}
64
65BinEntryGen::DataType BinEntryGen::binType(const PwMDataItem &data)
66{
67 if (!data.binary)
68 return None;
69 int type = strtol(data.name.c_str(), 0, 10);
70 return (static_cast<DataType>(type));
71}