Codechange: create helper class for useful NetworkAuthorizedKeys functions

This commit is contained in:
Rubidium
2024-03-18 18:56:46 +01:00
committed by rubidium42
parent 2485de9462
commit 7580eac2d5
7 changed files with 81 additions and 38 deletions

View File

@@ -33,6 +33,8 @@
#ifndef NETWORK_CRYPTO_H
#define NETWORK_CRYPTO_H
#include "network_type.h"
/**
* Base class for handling the encryption (or decryption) of a network connection.
*/
@@ -158,16 +160,16 @@ public:
*/
class NetworkAuthenticationDefaultAuthorizedKeyHandler : public NetworkAuthenticationAuthorizedKeyHandler {
private:
const std::vector<std::string> *authorized_keys; ///< The authorized keys to check against.
const NetworkAuthorizedKeys *authorized_keys; ///< The authorized keys to check against.
public:
/**
* Create the handler that uses the given authorized keys to check against.
* @param authorized_keys The reference to the authorized keys to check against.
*/
NetworkAuthenticationDefaultAuthorizedKeyHandler(const std::vector<std::string> &authorized_keys) : authorized_keys(&authorized_keys) {}
NetworkAuthenticationDefaultAuthorizedKeyHandler(const NetworkAuthorizedKeys &authorized_keys) : authorized_keys(&authorized_keys) {}
bool CanBeUsed() const override { return !this->authorized_keys->empty(); }
bool IsAllowed(std::string_view peer_public_key) const override;
bool IsAllowed(std::string_view peer_public_key) const override { return authorized_keys->Contains(peer_public_key); }
};