PassphraseGenerator.h
#ifndef GPGFRONTEND_PASSPHRASEGENERATOR_H
#define GPGFRONTEND_PASSPHRASEGENERATOR_H
#include "core/GpgFrontendCore.h"
#include "core/GpgFunctionObject.h"
namespace GpgFrontend {
class GPGFRONTEND_CORE_EXPORT PassphraseGenerator
: public SingletonFunctionObject<PassphraseGenerator> {
public:
explicit PassphraseGenerator(
int channel = SingletonFunctionObject::GetDefaultChannel())
: SingletonFunctionObject<PassphraseGenerator>(channel) {}
std::string Generate(int len) {
std::uniform_int_distribution<int> dist(999, 99999);
auto file_string = boost::format("KeyPackage_%1%") % dist(mt_);
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string tmp_str;
tmp_str.reserve(len);
for (int i = 0; i < len; ++i) {
tmp_str += alphanum[dist(mt_) % (sizeof(alphanum) - 1)];
}
return tmp_str;
}
std::random_device rd_;
std::mt19937 mt_ = std::mt19937(rd_());
};
} // namespace GpgFrontend
#endif // GPGFRONTEND_PASSPHRASEGENERATOR_H
GpgFrontend::PassphraseGenerator
The PassphraseGenerator class.
Definition: PassphraseGenerator.h:42
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:148
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::PassphraseGenerator::Generate
std::string Generate(int len)
generate passphrase
Definition: PassphraseGenerator.h:60
GpgFrontend::PassphraseGenerator::rd_
std::random_device rd_
Random device.
Definition: PassphraseGenerator.h:77
GpgFrontend::PassphraseGenerator::PassphraseGenerator
PassphraseGenerator(int channel=SingletonFunctionObject::GetDefaultChannel())
PassphraseGenerator constructor.
Definition: PassphraseGenerator.h:50
GpgFrontend::SingletonFunctionObject::GetDefaultChannel
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:232