diff options
author | saturneric <[email protected]> | 2023-10-23 10:27:25 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-10-23 10:27:25 +0000 |
commit | 8fdeb3af49999f29e017b7f7a70bd36f020ba721 (patch) | |
tree | db90267c3c88d488570a8e359bd511b64c5686d8 /src/core/function/PassphraseGenerator.cpp | |
parent | feat: improve project structure and add GRT for modules (diff) | |
download | GpgFrontend-8fdeb3af49999f29e017b7f7a70bd36f020ba721.tar.gz GpgFrontend-8fdeb3af49999f29e017b7f7a70bd36f020ba721.zip |
perf: reduce header includes and improve build speed
Diffstat (limited to 'src/core/function/PassphraseGenerator.cpp')
-rw-r--r-- | src/core/function/PassphraseGenerator.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/function/PassphraseGenerator.cpp b/src/core/function/PassphraseGenerator.cpp index 84ca8e8c..261f1606 100644 --- a/src/core/function/PassphraseGenerator.cpp +++ b/src/core/function/PassphraseGenerator.cpp @@ -27,3 +27,25 @@ */ #include "PassphraseGenerator.h" + +#include <boost/format.hpp> + +namespace GpgFrontend { + +std::string PassphraseGenerator::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; +} +} // namespace GpgFrontend
\ No newline at end of file |