diff options
author | Saturneric <[email protected]> | 2022-02-06 09:34:14 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2022-02-06 09:34:39 +0000 |
commit | cacca627a62ab2eba9eb4d37cfea40629ca0a89a (patch) | |
tree | c596c3c2252ebb0e3792ab4c561d7c7cd3f3e4b0 /src/core/function/PassphraseGenerator.h | |
parent | <refactor>(core, ui): Adjust the core code directory structure. (diff) | |
download | GpgFrontend-cacca627a62ab2eba9eb4d37cfea40629ca0a89a.tar.gz GpgFrontend-cacca627a62ab2eba9eb4d37cfea40629ca0a89a.zip |
<refactor>(src): Move and split the Global Settings Station
1. Move Global Settings Station to core
2. Separate the logic of DataObject
3. Resolve dependencies
Diffstat (limited to 'src/core/function/PassphraseGenerator.h')
-rw-r--r-- | src/core/function/PassphraseGenerator.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/core/function/PassphraseGenerator.h b/src/core/function/PassphraseGenerator.h new file mode 100644 index 00000000..5e55b2dd --- /dev/null +++ b/src/core/function/PassphraseGenerator.h @@ -0,0 +1,73 @@ +/** + * Copyright (C) 2021 Saturneric + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric<[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#ifndef GPGFRONTEND_PASSPHRASEGENERATOR_H +#define GPGFRONTEND_PASSPHRASEGENERATOR_H + +#include "core/GpgFrontendCore.h" +#include "core/GpgFunctionObject.h" + +namespace GpgFrontend { + +/** + * @brief The PassphraseGenerator class + * + * This class is used to generate a passphrase. + */ +class PassphraseGenerator + : public SingletonFunctionObject<PassphraseGenerator> { + public: + + /** + * @brief PassphraseGenerator constructor + * + * @param channel The channel to use + */ + explicit PassphraseGenerator( + int channel = SingletonFunctionObject::GetDefaultChannel()) + : SingletonFunctionObject<PassphraseGenerator>(channel) {} + + /** + * @brief generate passphrase + * + * @param len length of the passphrase + * @return std::string passphrase + */ + std::string Generate(int len) { + std::uniform_int_distribution<int> dist(999, 99999); + auto file_string = boost::format("KeyPackage_%1%") % dist(mt_); + return file_string.str(); + } + + std::random_device rd_; ///< Random device + std::mt19937 mt_ = std::mt19937(rd_()); ///< Mersenne twister +}; + +} // namespace GpgFrontend + +#endif // GPGFRONTEND_PASSPHRASEGENERATOR_H |