/
fluffymax2005
/
libwgcpp
Обзор
Документация
Войти
/
fluffymax2005
/
libwgcpp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
2
CI/CD
Аналитика
Безопасность
master
include/wgpresharedkey.h
118 строк
3 KB
fluffymax2005
.hpp implementations moved to .h files.
07 авг 2026, 21:46
07 авг 2026, 21:46
4e59e8f
Код
Авторство
О чём код?
/* * libwgcpp — C++ wrapper for embeddable-wg-library * Copyright (C) 2026 Ledovskiy Maksim aka fluffymax2005 <santech_montage@mail.ru> * * This file is part of libwgcpp. * * libwgcpp is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. * * libwgcpp 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with libwgcpp. If not, see <https://www.gnu.org/licenses/>. */ /** * @file * @brief Provides implementation for Wireguard preshared key */ #ifndef WGPRESHAREDKEY_H #define WGPRESHAREDKEY_H #include "wgkey.h" #include "threadsafety.h" /** * @class WgPresharedKey * @brief Implementation of Wireguard preshared key. * @tparam ThreadPolicy Thread safety policy for using. MultiThreaded is used by default. */ template<typename ThreadPolicy = MultiThreaded> class WgPresharedKey : public WgKey<ThreadPolicy> { public: /** * @brief Default constructor. Calls WgPresharedKey::generate. Key is ready to insert by constructing */ WgPresharedKey() noexcept; /** * @brief Default copy constructor. Copies <TT>this->key</TT> from <TT>other.key</TT>. */ WgPresharedKey(const WgPresharedKey&) noexcept = default; /** * @brief Default copy assignment. Copies <TT>this->key</TT> from <TT>other.key</TT>. * @return *this. */ WgPresharedKey& operator=(const WgPresharedKey&) noexcept = default; /** * @brief Move constructor. Copies <TT>this->key</TT> from <TT>other.key</TT> and calls <TT>other.key.makeZero</TT>. * @param other other instance */ WgPresharedKey(WgPresharedKey&& other) noexcept; /** * @brief Move assignment. Copies <TT>this->key</TT> from <TT>other.key</TT> and calls <TT>other.key.makeZero</TT>. * @param other other instance * @return *this. */ WgPresharedKey& operator=(WgPresharedKey&& other) noexcept; /** * @brief Check whether key is in valid state. * @retval true if <TT>WgPresharedKey::isGenerated == true</TT>. * @retval false otherwise. */ virtual bool isProper() const noexcept override; /** * @brief Perform generating WgPresharedKey::key */ virtual void generate() override; }; template<typename TP> WgPresharedKey<TP>::WgPresharedKey() noexcept { generate(); } template<typename TP> WgPresharedKey<TP>::WgPresharedKey(WgPresharedKey<TP>&& other) noexcept { if (this != &other) { this->key = other.key; other.makeZero(); } } template<typename TP> WgPresharedKey<TP>& WgPresharedKey<TP>::operator=(WgPresharedKey&& other) noexcept { if (this != &other) { this->key = other.key; other.makeZero(); } return *this; } template<typename TP> bool WgPresharedKey<TP>::isProper() const noexcept { return this->isGenerated; } template<typename TP> void WgPresharedKey<TP>::generate() { typename TP::Lock lock(this->mutex); wg_generate_preshared_key(this->key.data()); this->isGenerated = true; } #endif // WGPRESHAREDKEY_H