X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fapps%2FPswGen%2FGenerator%2Fgenerator.cpp;fp=src%2Fapps%2FPswGen%2FGenerator%2Fgenerator.cpp;h=dddc845a08ea798d090167925d2928655015b4da;hb=473db85d79d6d89b7b8fe617346efa3e94c66cd9;hp=0000000000000000000000000000000000000000;hpb=06f9c5336ba8a2200b68f636520707693eb5ada7;p=evaf diff --git a/src/apps/PswGen/Generator/generator.cpp b/src/apps/PswGen/Generator/generator.cpp new file mode 100644 index 0000000..dddc845 --- /dev/null +++ b/src/apps/PswGen/Generator/generator.cpp @@ -0,0 +1,123 @@ +/** + * @file PswGen/Generator/generator.cpp + * @brief Implementation of the iGenerator interface + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "generator.h" +#include "version.h" + +#include +#include + +#include + +using namespace eVaf; +using namespace evaf::PswGen; +using namespace eVaf::PswGen::Generator; + +//------------------------------------------------------------------- + +Generator::Generator() + : Plugins::iPlugin() + , mReady(false) +{ + setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); + + mGenerator = new Internal::GeneratorImpl; + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +Generator::~Generator() +{ + delete mGenerator; + + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +bool Generator::init(const QString & args) +{ + Q_UNUSED(args); + + if (!mGenerator->init()) + return false; + + mReady = true; + + EVAF_INFO("%s initialized", qPrintable(objectName())); + + return true; +} + +void Generator::done() +{ + mReady = false; + + mGenerator->done(); + + EVAF_INFO("%s finalized", qPrintable(objectName())); +} + + +//------------------------------------------------------------------- + +using namespace eVaf::PswGen::Generator::Internal; + +GeneratorImpl::GeneratorImpl() + : iGenerator() +{ + setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR)); + + Common::iRegistry::instance()->registerInterface("iGenerator", this); + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +GeneratorImpl::~GeneratorImpl() +{ + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +bool GeneratorImpl::init() +{ + EVAF_INFO("%s initialized", qPrintable(objectName())); + + return true; +} + +void GeneratorImpl::done() +{ + EVAF_INFO("%s finalized", qPrintable(objectName())); +} + +QString GeneratorImpl::generatePassword(char const * const name, char const * const masterPassword, int length, uint flags) +{ + QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1(); + QCryptographicHash hash(QCryptographicHash::Md5); + hash.addData(inputString); + QByteArray result = hash.result().toBase64(); + if (length > 0) + return result.left(length); + else + return result; +} + + +//------------------------------------------------------------------- + +VER_EXPORT_VERSION_INFO() +Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Generator)