]> vaikene.ee Git - evaf/blob - src/apps/PswGen/Generator/generator.cpp
Compiler error fixes.
[evaf] / src / apps / PswGen / Generator / generator.cpp
1 /**
2 * @file PswGen/Generator/generator.cpp
3 * @brief Implementation of the iGenerator interface
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #include "generator.h"
21 #include "version.h"
22
23 #include <Common/iLogger>
24 #include <Common/iRegistry>
25
26 #include <QtCore>
27
28 using namespace eVaf;
29 using namespace eVaf::PswGen;
30 using namespace eVaf::PswGen::Generator;
31
32 //-------------------------------------------------------------------
33
34 Module::Module()
35 : Plugins::iPlugin()
36 , mReady(false)
37 {
38 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
39
40 mGenerator = new Internal::GeneratorImpl;
41
42 EVAF_INFO("%s created", qPrintable(objectName()));
43 }
44
45 Module::~Module()
46 {
47 delete mGenerator;
48
49 EVAF_INFO("%s destroyed", qPrintable(objectName()));
50 }
51
52 bool Module::init(const QString & args)
53 {
54 Q_UNUSED(args);
55
56 if (!mGenerator->init())
57 return false;
58
59 mReady = true;
60
61 EVAF_INFO("%s initialized", qPrintable(objectName()));
62
63 return true;
64 }
65
66 void Module::done()
67 {
68 mReady = false;
69
70 mGenerator->done();
71
72 EVAF_INFO("%s finalized", qPrintable(objectName()));
73 }
74
75
76 //-------------------------------------------------------------------
77
78 using namespace eVaf::PswGen::Generator::Internal;
79
80 GeneratorImpl::GeneratorImpl()
81 : iGenerator()
82 {
83 setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR));
84
85 Common::iRegistry::instance()->registerInterface("iGenerator", this);
86
87 EVAF_INFO("%s created", qPrintable(objectName()));
88 }
89
90 GeneratorImpl::~GeneratorImpl()
91 {
92 EVAF_INFO("%s destroyed", qPrintable(objectName()));
93 }
94
95 bool GeneratorImpl::init()
96 {
97 EVAF_INFO("%s initialized", qPrintable(objectName()));
98
99 return true;
100 }
101
102 void GeneratorImpl::done()
103 {
104 EVAF_INFO("%s finalized", qPrintable(objectName()));
105 }
106
107 QString GeneratorImpl::generatePassword(char const * const name, char const * const masterPassword, int length, uint flags)
108 {
109 QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1();
110 QCryptographicHash hash(QCryptographicHash::Md5);
111 hash.addData(inputString);
112 QByteArray result = hash.result().toBase64();
113 if (length > 0)
114 return result.left(length);
115 else
116 return result;
117 }
118
119
120 //-------------------------------------------------------------------
121
122 VER_EXPORT_VERSION_INFO()
123 Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Module)