Bitcoin Core  22.99.0
P2P Digital Currency
net_permissions.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <net_permissions.h>
7 #include <test/fuzz/fuzz.h>
8 #include <test/fuzz/util.h>
9 #include <util/translation.h>
10 
11 #include <cassert>
12 #include <cstdint>
13 #include <string>
14 #include <vector>
15 
16 FUZZ_TARGET(net_permissions)
17 {
18  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19  const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32);
20  const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
21 
22  NetWhitebindPermissions net_whitebind_permissions;
23  bilingual_str error_net_whitebind_permissions;
24  if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) {
25  (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
26  (void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags);
27  assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags));
28  (void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, NetPermissionFlags::Implicit);
29  (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
30  }
31 
32  NetWhitelistPermissions net_whitelist_permissions;
33  bilingual_str error_net_whitelist_permissions;
34  if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) {
35  (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
36  (void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags);
37  assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags));
38  (void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, NetPermissionFlags::Implicit);
39  (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
40  }
41 }
assert
assert(!tx.IsCoinBase())
NetPermissions::ToStrings
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
Definition: net_permissions.cpp:71
FUZZ_TARGET
FUZZ_TARGET(net_permissions)
Definition: net_permissions.cpp:16
bilingual_str
Bilingual messages:
Definition: translation.h:16
util.h
FuzzedDataProvider::ConsumeRandomLengthString
std::string ConsumeRandomLengthString(size_t max_length)
Definition: FuzzedDataProvider.h:152
ALL_NET_PERMISSION_FLAGS
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
Definition: net.h:50
NetPermissions::ClearFlag
static void ClearFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ClearFlag is only called with f == NetPermissionFlags::Implicit.
Definition: net_permissions.h:67
NetPermissions::HasFlag
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
Definition: net_permissions.h:53
NetWhitelistPermissions::TryParse
static bool TryParse(const std::string &str, NetWhitelistPermissions &output, bilingual_str &error)
Definition: net_permissions.cpp:107
NetPermissionFlags
NetPermissionFlags
Definition: net_permissions.h:18
NetWhitelistPermissions
Definition: net_permissions.h:82
FuzzedDataProvider.h
NetWhitebindPermissions::TryParse
static bool TryParse(const std::string &str, NetWhitebindPermissions &output, bilingual_str &error)
Definition: net_permissions.cpp:84
NetPermissionFlags::Implicit
@ Implicit
NetPermissions::AddFlag
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
Definition: net_permissions.h:58
translation.h
NetPermissions::m_flags
NetPermissionFlags m_flags
Definition: net_permissions.h:51
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
ConsumeWeakEnum
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
Definition: util.h:115
NetWhitebindPermissions
Definition: net_permissions.h:75
net_permissions.h