1 
2 #pragma once
3 
4 #include <cstdint>
5 #include <functional>
6 #include <iomanip>
7 #include <optional>
8 #include <sstream>
9 #include <string>
10 #include <type_traits>
11 
12 #include "packet/base_packet_builder.h"
13 #include "packet/bit_inserter.h"
14 #include "packet/custom_field_fixed_size_interface.h"
15 #include "packet/iterator.h"
16 #include "packet/packet_builder.h"
17 #include "packet/packet_struct.h"
18 #include "packet/packet_view.h"
19 #include "packet/checksum_type_checker.h"
20 #include "packet/custom_type_checker.h"
21 
22 #if __has_include(<bluetooth/log.h>)
23 
24 #include <bluetooth/log.h>
25 
26 #ifndef ASSERT
27 #define ASSERT(cond) bluetooth::log::assert_that(cond, #cond)
28 #endif // !defined(ASSERT)
29 
30 #else
31 
32 #ifndef ASSERT
33 #define ASSERT(cond) assert(cond)
34 #endif // !defined(ASSERT)
35 
36 #endif // __has_include(<bluetooth/log.h>)
37 
38 
39 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
40 #include "packet/raw_builder.h"
41 #endif
42 #include "hci/address.h"
43 
44 
45 namespace bluetooth {
46 namespace security {
47 
48 
49 using ::bluetooth::hci::Address;
50 
51 using ::bluetooth::packet::BasePacketBuilder;
52 using ::bluetooth::packet::BitInserter;
53 using ::bluetooth::packet::CustomFieldFixedSizeInterface;
54 using ::bluetooth::packet::CustomTypeChecker;
55 using ::bluetooth::packet::Iterator;
56 using ::bluetooth::packet::kLittleEndian;
57 using ::bluetooth::packet::PacketBuilder;
58 using ::bluetooth::packet::PacketStruct;
59 using ::bluetooth::packet::PacketView;
60 using ::bluetooth::packet::parser::ChecksumTypeChecker;
61 
62 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
63 using ::bluetooth::packet::RawBuilder;
64 #endif
65 enum class Code : uint8_t {PAIRING_REQUEST = 0x1,PAIRING_RESPONSE = 0x2,PAIRING_CONFIRM = 0x3,PAIRING_RANDOM = 0x4,PAIRING_FAILED = 0x5,ENCRYPTION_INFORMATION = 0x6,CENTRAL_IDENTIFICATION = 0x7,IDENTITY_INFORMATION = 0x8,IDENTITY_ADDRESS_INFORMATION = 0x9,SIGNING_INFORMATION = 0xa,SECURITY_REQUEST = 0xb,PAIRING_PUBLIC_KEY = 0xc,PAIRING_DH_KEY_CHECK = 0xd,PAIRING_KEYPRESS_NOTIFICATION = 0xe,};
66 
67 
68 enum class IoCapability : uint8_t {DISPLAY_ONLY = 0x0,DISPLAY_YES_NO = 0x1,KEYBOARD_ONLY = 0x2,NO_INPUT_NO_OUTPUT = 0x3,KEYBOARD_DISPLAY = 0x4,};
69 
70 
71 enum class OobDataFlag : uint8_t {NOT_PRESENT = 0x0,PRESENT = 0x1,};
72 
73 
74 enum class BondingFlags : uint8_t {NO_BONDING = 0x0,BONDING = 0x1,};
75 
76 
77 enum class PairingFailedReason : uint8_t {PASSKEY_ENTRY_FAILED = 0x1,OOB_NOT_AVAILABLE = 0x2,AUTHENTICATION_REQUIREMENTS = 0x3,CONFIRM_VALUE_FAILED = 0x4,PAIRING_NOT_SUPPORTED = 0x5,ENCRYPTION_KEY_SIZE = 0x6,COMMAND_NOT_SUPPORTED = 0x7,UNSPECIFIED_REASON = 0x8,REPEATED_ATTEMPTS = 0x9,INVALID_PARAMETERS = 0xa,DHKEY_CHECK_FAILED = 0xb,NUMERIC_COMPARISON_FAILED = 0xc,BR_EDR_PAIRING_IN_PROGRESS = 0xd,CROSS_TRANSPORT_KEY_DERIVATION_NOT_ALLOWED = 0xe,};
78 
79 
80 enum class AddrType : uint8_t {PUBLIC = 0x0,STATIC_RANDOM = 0x1,};
81 
82 
83 enum class KeypressNotificationType : uint8_t {ENTRY_STARTED = 0x0,DIGIT_ENTERED = 0x1,DIGIT_ERASED = 0x2,CLEARED = 0x3,ENTRY_COMPLETED = 0x4,};
84 
85 
CodeText(const Code & param)86 inline std::string CodeText(const Code& param) {std::stringstream builder;switch (param) {case Code::PAIRING_REQUEST:  builder << "PAIRING_REQUEST"; break;case Code::PAIRING_RESPONSE:  builder << "PAIRING_RESPONSE"; break;case Code::PAIRING_CONFIRM:  builder << "PAIRING_CONFIRM"; break;case Code::PAIRING_RANDOM:  builder << "PAIRING_RANDOM"; break;case Code::PAIRING_FAILED:  builder << "PAIRING_FAILED"; break;case Code::ENCRYPTION_INFORMATION:  builder << "ENCRYPTION_INFORMATION"; break;case Code::CENTRAL_IDENTIFICATION:  builder << "CENTRAL_IDENTIFICATION"; break;case Code::IDENTITY_INFORMATION:  builder << "IDENTITY_INFORMATION"; break;case Code::IDENTITY_ADDRESS_INFORMATION:  builder << "IDENTITY_ADDRESS_INFORMATION"; break;case Code::SIGNING_INFORMATION:  builder << "SIGNING_INFORMATION"; break;case Code::SECURITY_REQUEST:  builder << "SECURITY_REQUEST"; break;case Code::PAIRING_PUBLIC_KEY:  builder << "PAIRING_PUBLIC_KEY"; break;case Code::PAIRING_DH_KEY_CHECK:  builder << "PAIRING_DH_KEY_CHECK"; break;case Code::PAIRING_KEYPRESS_NOTIFICATION:  builder << "PAIRING_KEYPRESS_NOTIFICATION"; break;default:  builder << "Unknown Code";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
87 
88 
89 
IoCapabilityText(const IoCapability & param)90 inline std::string IoCapabilityText(const IoCapability& param) {std::stringstream builder;switch (param) {case IoCapability::DISPLAY_ONLY:  builder << "DISPLAY_ONLY"; break;case IoCapability::DISPLAY_YES_NO:  builder << "DISPLAY_YES_NO"; break;case IoCapability::KEYBOARD_ONLY:  builder << "KEYBOARD_ONLY"; break;case IoCapability::NO_INPUT_NO_OUTPUT:  builder << "NO_INPUT_NO_OUTPUT"; break;case IoCapability::KEYBOARD_DISPLAY:  builder << "KEYBOARD_DISPLAY"; break;default:  builder << "Unknown IoCapability";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
91 
92 
93 
OobDataFlagText(const OobDataFlag & param)94 inline std::string OobDataFlagText(const OobDataFlag& param) {std::stringstream builder;switch (param) {case OobDataFlag::NOT_PRESENT:  builder << "NOT_PRESENT"; break;case OobDataFlag::PRESENT:  builder << "PRESENT"; break;default:  builder << "Unknown OobDataFlag";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
95 
96 
97 
BondingFlagsText(const BondingFlags & param)98 inline std::string BondingFlagsText(const BondingFlags& param) {std::stringstream builder;switch (param) {case BondingFlags::NO_BONDING:  builder << "NO_BONDING"; break;case BondingFlags::BONDING:  builder << "BONDING"; break;default:  builder << "Unknown BondingFlags";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(2/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
99 
100 
101 
PairingFailedReasonText(const PairingFailedReason & param)102 inline std::string PairingFailedReasonText(const PairingFailedReason& param) {std::stringstream builder;switch (param) {case PairingFailedReason::PASSKEY_ENTRY_FAILED:  builder << "PASSKEY_ENTRY_FAILED"; break;case PairingFailedReason::OOB_NOT_AVAILABLE:  builder << "OOB_NOT_AVAILABLE"; break;case PairingFailedReason::AUTHENTICATION_REQUIREMENTS:  builder << "AUTHENTICATION_REQUIREMENTS"; break;case PairingFailedReason::CONFIRM_VALUE_FAILED:  builder << "CONFIRM_VALUE_FAILED"; break;case PairingFailedReason::PAIRING_NOT_SUPPORTED:  builder << "PAIRING_NOT_SUPPORTED"; break;case PairingFailedReason::ENCRYPTION_KEY_SIZE:  builder << "ENCRYPTION_KEY_SIZE"; break;case PairingFailedReason::COMMAND_NOT_SUPPORTED:  builder << "COMMAND_NOT_SUPPORTED"; break;case PairingFailedReason::UNSPECIFIED_REASON:  builder << "UNSPECIFIED_REASON"; break;case PairingFailedReason::REPEATED_ATTEMPTS:  builder << "REPEATED_ATTEMPTS"; break;case PairingFailedReason::INVALID_PARAMETERS:  builder << "INVALID_PARAMETERS"; break;case PairingFailedReason::DHKEY_CHECK_FAILED:  builder << "DHKEY_CHECK_FAILED"; break;case PairingFailedReason::NUMERIC_COMPARISON_FAILED:  builder << "NUMERIC_COMPARISON_FAILED"; break;case PairingFailedReason::BR_EDR_PAIRING_IN_PROGRESS:  builder << "BR_EDR_PAIRING_IN_PROGRESS"; break;case PairingFailedReason::CROSS_TRANSPORT_KEY_DERIVATION_NOT_ALLOWED:  builder << "CROSS_TRANSPORT_KEY_DERIVATION_NOT_ALLOWED"; break;default:  builder << "Unknown PairingFailedReason";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
103 
104 
105 
AddrTypeText(const AddrType & param)106 inline std::string AddrTypeText(const AddrType& param) {std::stringstream builder;switch (param) {case AddrType::PUBLIC:  builder << "PUBLIC"; break;case AddrType::STATIC_RANDOM:  builder << "STATIC_RANDOM"; break;default:  builder << "Unknown AddrType";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
107 
108 
109 
KeypressNotificationTypeText(const KeypressNotificationType & param)110 inline std::string KeypressNotificationTypeText(const KeypressNotificationType& param) {std::stringstream builder;switch (param) {case KeypressNotificationType::ENTRY_STARTED:  builder << "ENTRY_STARTED"; break;case KeypressNotificationType::DIGIT_ENTERED:  builder << "DIGIT_ENTERED"; break;case KeypressNotificationType::DIGIT_ERASED:  builder << "DIGIT_ERASED"; break;case KeypressNotificationType::CLEARED:  builder << "CLEARED"; break;case KeypressNotificationType::ENTRY_COMPLETED:  builder << "ENTRY_COMPLETED"; break;default:  builder << "Unknown KeypressNotificationType";}builder << "(" << std::hex << "0x" << std::setfill('0')<< std::setw(8/4)<< static_cast<uint64_t>(param) << ")";return builder.str();}
111 
112 
113 
114 
115 /* Done ChecksumChecks */
116 static_assert(std::is_base_of_v<CustomFieldFixedSizeInterface<Address>, Address>, "Address is not a valid fixed size custom field type. Please see README for more details.");static_assert(CustomFieldFixedSizeInterface<Address>::length() * 8 == 48, "CustomFieldFixedSizeInterface<Address>::length * 8 should match PDL defined size (in bits) 48");
117 
118 
CreateOptional(PacketView<kLittleEndian> packet)119 class CommandView : public PacketView<kLittleEndian> { public:static CommandView Create(PacketView<kLittleEndian> packet){ return CommandView(std::move(packet)); }static std::optional<CommandView> CreateOptional(PacketView<kLittleEndian> packet){ auto to_validate = CommandView::Create(std::move(packet));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
120 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
121 static CommandView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return CommandView::Create(PacketView<kLittleEndian>(vec));}
122 #endif
123 Code GetCode() const {ASSERT(was_validated_);auto to_bound = begin();auto code_it = to_bound + (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;Code code_value{};Code* code_ptr = &code_value;auto extracted_value = code_it.extract<uint8_t>();*code_ptr = static_cast<Code>(extracted_value);return code_value;}
124 PacketView<kLittleEndian> GetPayload() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;auto payload_it = to_bound.Subrange(field_begin, field_end - field_begin); return GetLittleEndianSubview(field_begin, field_end);}
125 
126 
127 bool IsValid() {
128   if (was_validated_) {
129     return true;
130   } else {
131     was_validated_ = true;
132     return (was_validated_ = Validate());
133   }
134 }
135 protected:
136 virtual bool Validate() const {
137 auto it = begin() + (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;it += 1 /* Total size of the fixed fields */;if (it > end()) return false;
138 
139 return true;}
140 bool was_validated_{false};
141 
142  public:virtual std::string ToString() const  {std::stringstream ss;ss << std::showbase << std::hex << "Command { ";ss << ""  << "code = " << CodeText(GetCode()) << ", payload = " << "PAYLOAD[]";ss << " }";return ss.str();}
143 
144  protected:
145 explicit CommandView(PacketView<kLittleEndian> packet)  : PacketView<kLittleEndian>(packet) { was_validated_ = false;}};
146 
147 
CreateOptional(CommandView parent)148 class PairingRequestView : public CommandView { public:static PairingRequestView Create(CommandView parent){ return PairingRequestView(std::move(parent)); }static std::optional<PairingRequestView> CreateOptional(CommandView parent){ auto to_validate = PairingRequestView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
149 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
150 static PairingRequestView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingRequestView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
151 #endif
152 IoCapability GetIoCapability() const {ASSERT(was_validated_);auto to_bound = begin();auto io_capability_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;IoCapability io_capability_value{};IoCapability* io_capability_ptr = &io_capability_value;auto extracted_value = io_capability_it.extract<uint8_t>();*io_capability_ptr = static_cast<IoCapability>(extracted_value);return io_capability_value;}
153 OobDataFlag GetOobDataFlag() const {ASSERT(was_validated_);auto to_bound = begin();auto oob_data_flag_it = to_bound + (/* Bits: */ 16 + /* Dynamic: */ 0) / 8;OobDataFlag oob_data_flag_value{};OobDataFlag* oob_data_flag_ptr = &oob_data_flag_value;auto extracted_value = oob_data_flag_it.extract<uint8_t>();*oob_data_flag_ptr = static_cast<OobDataFlag>(extracted_value);return oob_data_flag_value;}
154 uint8_t GetAuthReq() const {ASSERT(was_validated_);auto to_bound = begin();auto auth_req_it = to_bound + (/* Bits: */ 24 + /* Dynamic: */ 0) / 8;uint8_t auth_req_value{};uint8_t* auth_req_ptr = &auth_req_value;auto extracted_value = auth_req_it.extract<uint8_t>();*auth_req_ptr = static_cast<uint8_t>(extracted_value);return auth_req_value;}
155 uint8_t GetMaximumEncryptionKeySize() const {ASSERT(was_validated_);auto to_bound = begin();auto maximum_encryption_key_size_it = to_bound + (/* Bits: */ 32 + /* Dynamic: */ 0) / 8;uint8_t maximum_encryption_key_size_value{};uint8_t* maximum_encryption_key_size_ptr = &maximum_encryption_key_size_value;auto extracted_value = maximum_encryption_key_size_it.extract<uint8_t>();extracted_value &= 0x1f;*maximum_encryption_key_size_ptr = static_cast<uint8_t>(extracted_value);return maximum_encryption_key_size_value;}
156 
157 uint8_t GetInitiatorKeyDistribution() const {ASSERT(was_validated_);auto to_bound = begin();auto initiator_key_distribution_it = to_bound + (/* Bits: */ 40 + /* Dynamic: */ 0) / 8;uint8_t initiator_key_distribution_value{};uint8_t* initiator_key_distribution_ptr = &initiator_key_distribution_value;auto extracted_value = initiator_key_distribution_it.extract<uint8_t>();*initiator_key_distribution_ptr = static_cast<uint8_t>(extracted_value);return initiator_key_distribution_value;}
158 uint8_t GetResponderKeyDistribution() const {ASSERT(was_validated_);auto to_bound = begin();auto responder_key_distribution_it = to_bound + (/* Bits: */ 48 + /* Dynamic: */ 0) / 8;uint8_t responder_key_distribution_value{};uint8_t* responder_key_distribution_ptr = &responder_key_distribution_value;auto extracted_value = responder_key_distribution_it.extract<uint8_t>();*responder_key_distribution_ptr = static_cast<uint8_t>(extracted_value);return responder_key_distribution_value;}
159 protected:
160 bool Validate() const override {
161   if (!CommandView::Validate()) {
162     return false;
163   }
164 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 6 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_REQUEST) return false;
165 
166 
167 
168 
169 
170 
171 return true;}
172 
173  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingRequest { ";ss << ""  << "io_capability = " << IoCapabilityText(GetIoCapability()) << ", oob_data_flag = " << OobDataFlagText(GetOobDataFlag()) << ", auth_req = " << static_cast<uint64_t>(GetAuthReq()) << ", maximum_encryption_key_size = " << static_cast<uint64_t>(GetMaximumEncryptionKeySize()) << ", initiator_key_distribution = " << static_cast<uint64_t>(GetInitiatorKeyDistribution()) << ", responder_key_distribution = " << static_cast<uint64_t>(GetResponderKeyDistribution());ss << " }";return ss.str();}
174 
175  protected:
176 explicit PairingRequestView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
177 
178 
CreateOptional(CommandView parent)179 class PairingResponseView : public CommandView { public:static PairingResponseView Create(CommandView parent){ return PairingResponseView(std::move(parent)); }static std::optional<PairingResponseView> CreateOptional(CommandView parent){ auto to_validate = PairingResponseView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
180 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
181 static PairingResponseView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingResponseView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
182 #endif
183 IoCapability GetIoCapability() const {ASSERT(was_validated_);auto to_bound = begin();auto io_capability_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;IoCapability io_capability_value{};IoCapability* io_capability_ptr = &io_capability_value;auto extracted_value = io_capability_it.extract<uint8_t>();*io_capability_ptr = static_cast<IoCapability>(extracted_value);return io_capability_value;}
184 OobDataFlag GetOobDataFlag() const {ASSERT(was_validated_);auto to_bound = begin();auto oob_data_flag_it = to_bound + (/* Bits: */ 16 + /* Dynamic: */ 0) / 8;OobDataFlag oob_data_flag_value{};OobDataFlag* oob_data_flag_ptr = &oob_data_flag_value;auto extracted_value = oob_data_flag_it.extract<uint8_t>();*oob_data_flag_ptr = static_cast<OobDataFlag>(extracted_value);return oob_data_flag_value;}
185 uint8_t GetAuthReq() const {ASSERT(was_validated_);auto to_bound = begin();auto auth_req_it = to_bound + (/* Bits: */ 24 + /* Dynamic: */ 0) / 8;uint8_t auth_req_value{};uint8_t* auth_req_ptr = &auth_req_value;auto extracted_value = auth_req_it.extract<uint8_t>();*auth_req_ptr = static_cast<uint8_t>(extracted_value);return auth_req_value;}
186 uint8_t GetMaximumEncryptionKeySize() const {ASSERT(was_validated_);auto to_bound = begin();auto maximum_encryption_key_size_it = to_bound + (/* Bits: */ 32 + /* Dynamic: */ 0) / 8;uint8_t maximum_encryption_key_size_value{};uint8_t* maximum_encryption_key_size_ptr = &maximum_encryption_key_size_value;auto extracted_value = maximum_encryption_key_size_it.extract<uint8_t>();extracted_value &= 0x1f;*maximum_encryption_key_size_ptr = static_cast<uint8_t>(extracted_value);return maximum_encryption_key_size_value;}
187 
188 uint8_t GetInitiatorKeyDistribution() const {ASSERT(was_validated_);auto to_bound = begin();auto initiator_key_distribution_it = to_bound + (/* Bits: */ 40 + /* Dynamic: */ 0) / 8;uint8_t initiator_key_distribution_value{};uint8_t* initiator_key_distribution_ptr = &initiator_key_distribution_value;auto extracted_value = initiator_key_distribution_it.extract<uint8_t>();*initiator_key_distribution_ptr = static_cast<uint8_t>(extracted_value);return initiator_key_distribution_value;}
189 uint8_t GetResponderKeyDistribution() const {ASSERT(was_validated_);auto to_bound = begin();auto responder_key_distribution_it = to_bound + (/* Bits: */ 48 + /* Dynamic: */ 0) / 8;uint8_t responder_key_distribution_value{};uint8_t* responder_key_distribution_ptr = &responder_key_distribution_value;auto extracted_value = responder_key_distribution_it.extract<uint8_t>();*responder_key_distribution_ptr = static_cast<uint8_t>(extracted_value);return responder_key_distribution_value;}
190 protected:
191 bool Validate() const override {
192   if (!CommandView::Validate()) {
193     return false;
194   }
195 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 6 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_RESPONSE) return false;
196 
197 
198 
199 
200 
201 
202 return true;}
203 
204  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingResponse { ";ss << ""  << "io_capability = " << IoCapabilityText(GetIoCapability()) << ", oob_data_flag = " << OobDataFlagText(GetOobDataFlag()) << ", auth_req = " << static_cast<uint64_t>(GetAuthReq()) << ", maximum_encryption_key_size = " << static_cast<uint64_t>(GetMaximumEncryptionKeySize()) << ", initiator_key_distribution = " << static_cast<uint64_t>(GetInitiatorKeyDistribution()) << ", responder_key_distribution = " << static_cast<uint64_t>(GetResponderKeyDistribution());ss << " }";return ss.str();}
205 
206  protected:
207 explicit PairingResponseView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
208 
209 
CreateOptional(CommandView parent)210 class PairingConfirmView : public CommandView { public:static PairingConfirmView Create(CommandView parent){ return PairingConfirmView(std::move(parent)); }static std::optional<PairingConfirmView> CreateOptional(CommandView parent){ auto to_validate = PairingConfirmView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
211 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
212 static PairingConfirmView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingConfirmView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
213 #endif
214 std::array<uint8_t,16> GetConfirmValue() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto confirm_value_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> confirm_value_value{};std::array<uint8_t,16>* confirm_value_ptr = &confirm_value_value;std::array<uint8_t,16>::iterator ret_it = confirm_value_ptr->begin();auto val_it = confirm_value_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < confirm_value_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return confirm_value_value;}
215 
216 protected:
217 bool Validate() const override {
218   if (!CommandView::Validate()) {
219     return false;
220   }
221 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_CONFIRM) return false;
222 return true;}
223 
224  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingConfirm { ";ss << ""  << "confirm_value = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetConfirmValue()[index]));}ss << "]";ss << " }";return ss.str();}
225 
226  protected:
227 explicit PairingConfirmView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
228 
229 
CreateOptional(CommandView parent)230 class PairingRandomView : public CommandView { public:static PairingRandomView Create(CommandView parent){ return PairingRandomView(std::move(parent)); }static std::optional<PairingRandomView> CreateOptional(CommandView parent){ auto to_validate = PairingRandomView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
231 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
232 static PairingRandomView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingRandomView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
233 #endif
234 std::array<uint8_t,16> GetRandomValue() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto random_value_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> random_value_value{};std::array<uint8_t,16>* random_value_ptr = &random_value_value;std::array<uint8_t,16>::iterator ret_it = random_value_ptr->begin();auto val_it = random_value_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < random_value_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return random_value_value;}
235 
236 protected:
237 bool Validate() const override {
238   if (!CommandView::Validate()) {
239     return false;
240   }
241 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_RANDOM) return false;
242 return true;}
243 
244  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingRandom { ";ss << ""  << "random_value = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetRandomValue()[index]));}ss << "]";ss << " }";return ss.str();}
245 
246  protected:
247 explicit PairingRandomView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
248 
249 
CreateOptional(CommandView parent)250 class PairingFailedView : public CommandView { public:static PairingFailedView Create(CommandView parent){ return PairingFailedView(std::move(parent)); }static std::optional<PairingFailedView> CreateOptional(CommandView parent){ auto to_validate = PairingFailedView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
251 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
252 static PairingFailedView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingFailedView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
253 #endif
254 PairingFailedReason GetReason() const {ASSERT(was_validated_);auto to_bound = begin();auto reason_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;PairingFailedReason reason_value{};PairingFailedReason* reason_ptr = &reason_value;auto extracted_value = reason_it.extract<uint8_t>();*reason_ptr = static_cast<PairingFailedReason>(extracted_value);return reason_value;}
255 protected:
256 bool Validate() const override {
257   if (!CommandView::Validate()) {
258     return false;
259   }
260 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 1 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_FAILED) return false;
261 return true;}
262 
263  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingFailed { ";ss << ""  << "reason = " << PairingFailedReasonText(GetReason());ss << " }";return ss.str();}
264 
265  protected:
266 explicit PairingFailedView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
267 
268 
CreateOptional(CommandView parent)269 class EncryptionInformationView : public CommandView { public:static EncryptionInformationView Create(CommandView parent){ return EncryptionInformationView(std::move(parent)); }static std::optional<EncryptionInformationView> CreateOptional(CommandView parent){ auto to_validate = EncryptionInformationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
270 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
271 static EncryptionInformationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return EncryptionInformationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
272 #endif
273 std::array<uint8_t,16> GetLongTermKey() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto long_term_key_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> long_term_key_value{};std::array<uint8_t,16>* long_term_key_ptr = &long_term_key_value;std::array<uint8_t,16>::iterator ret_it = long_term_key_ptr->begin();auto val_it = long_term_key_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < long_term_key_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return long_term_key_value;}
274 
275 protected:
276 bool Validate() const override {
277   if (!CommandView::Validate()) {
278     return false;
279   }
280 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::ENCRYPTION_INFORMATION) return false;
281 return true;}
282 
283  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "EncryptionInformation { ";ss << ""  << "long_term_key = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetLongTermKey()[index]));}ss << "]";ss << " }";return ss.str();}
284 
285  protected:
286 explicit EncryptionInformationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
287 
288 
CreateOptional(CommandView parent)289 class CentralIdentificationView : public CommandView { public:static CentralIdentificationView Create(CommandView parent){ return CentralIdentificationView(std::move(parent)); }static std::optional<CentralIdentificationView> CreateOptional(CommandView parent){ auto to_validate = CentralIdentificationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
290 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
291 static CentralIdentificationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return CentralIdentificationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
292 #endif
293 uint16_t GetEdiv() const {ASSERT(was_validated_);auto to_bound = begin();auto ediv_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;uint16_t ediv_value{};uint16_t* ediv_ptr = &ediv_value;auto extracted_value = ediv_it.extract<uint16_t>();*ediv_ptr = static_cast<uint16_t>(extracted_value);return ediv_value;}
294 std::array<uint8_t,8> GetRand() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 24 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 64 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto rand_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,8> rand_value{};std::array<uint8_t,8>* rand_ptr = &rand_value;std::array<uint8_t,8>::iterator ret_it = rand_ptr->begin();auto val_it = rand_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < rand_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return rand_value;}
295 
296 protected:
297 bool Validate() const override {
298   if (!CommandView::Validate()) {
299     return false;
300   }
301 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 10 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::CENTRAL_IDENTIFICATION) return false;
302 
303 return true;}
304 
305  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "CentralIdentification { ";ss << ""  << "ediv = " << static_cast<uint64_t>(GetEdiv()) << ", rand = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 8; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetRand()[index]));}ss << "]";ss << " }";return ss.str();}
306 
307  protected:
308 explicit CentralIdentificationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
309 
310 
CreateOptional(CommandView parent)311 class IdentityInformationView : public CommandView { public:static IdentityInformationView Create(CommandView parent){ return IdentityInformationView(std::move(parent)); }static std::optional<IdentityInformationView> CreateOptional(CommandView parent){ auto to_validate = IdentityInformationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
312 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
313 static IdentityInformationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return IdentityInformationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
314 #endif
315 std::array<uint8_t,16> GetIdentityResolvingKey() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto identity_resolving_key_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> identity_resolving_key_value{};std::array<uint8_t,16>* identity_resolving_key_ptr = &identity_resolving_key_value;std::array<uint8_t,16>::iterator ret_it = identity_resolving_key_ptr->begin();auto val_it = identity_resolving_key_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < identity_resolving_key_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return identity_resolving_key_value;}
316 
317 protected:
318 bool Validate() const override {
319   if (!CommandView::Validate()) {
320     return false;
321   }
322 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::IDENTITY_INFORMATION) return false;
323 return true;}
324 
325  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "IdentityInformation { ";ss << ""  << "identity_resolving_key = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetIdentityResolvingKey()[index]));}ss << "]";ss << " }";return ss.str();}
326 
327  protected:
328 explicit IdentityInformationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
329 
330 
CreateOptional(CommandView parent)331 class IdentityAddressInformationView : public CommandView { public:static IdentityAddressInformationView Create(CommandView parent){ return IdentityAddressInformationView(std::move(parent)); }static std::optional<IdentityAddressInformationView> CreateOptional(CommandView parent){ auto to_validate = IdentityAddressInformationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
332 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
333 static IdentityAddressInformationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return IdentityAddressInformationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
334 #endif
335 AddrType GetAddrType() const {ASSERT(was_validated_);auto to_bound = begin();auto addr_type_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;AddrType addr_type_value{};AddrType* addr_type_ptr = &addr_type_value;auto extracted_value = addr_type_it.extract<uint8_t>();*addr_type_ptr = static_cast<AddrType>(extracted_value);return addr_type_value;}
336 Address GetBdAddr() const {ASSERT(was_validated_);auto to_bound = begin();auto bd_addr_it = to_bound + (/* Bits: */ 16 + /* Dynamic: */ 0) / 8;Address bd_addr_value{};Address* bd_addr_ptr = &bd_addr_value;*bd_addr_ptr = bd_addr_it.extract<Address>();return bd_addr_value;}
337 protected:
338 bool Validate() const override {
339   if (!CommandView::Validate()) {
340     return false;
341   }
342 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 7 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::IDENTITY_ADDRESS_INFORMATION) return false;
343 
344 return true;}
345 
346  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "IdentityAddressInformation { ";ss << ""  << "addr_type = " << AddrTypeText(GetAddrType()) << ", bd_addr = " << GetBdAddr().ToString();ss << " }";return ss.str();}
347 
348  protected:
349 explicit IdentityAddressInformationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
350 
351 
CreateOptional(CommandView parent)352 class SigningInformationView : public CommandView { public:static SigningInformationView Create(CommandView parent){ return SigningInformationView(std::move(parent)); }static std::optional<SigningInformationView> CreateOptional(CommandView parent){ auto to_validate = SigningInformationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
353 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
354 static SigningInformationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return SigningInformationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
355 #endif
356 std::array<uint8_t,16> GetSignatureKey() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto signature_key_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> signature_key_value{};std::array<uint8_t,16>* signature_key_ptr = &signature_key_value;std::array<uint8_t,16>::iterator ret_it = signature_key_ptr->begin();auto val_it = signature_key_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < signature_key_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return signature_key_value;}
357 
358 protected:
359 bool Validate() const override {
360   if (!CommandView::Validate()) {
361     return false;
362   }
363 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::SIGNING_INFORMATION) return false;
364 return true;}
365 
366  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "SigningInformation { ";ss << ""  << "signature_key = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetSignatureKey()[index]));}ss << "]";ss << " }";return ss.str();}
367 
368  protected:
369 explicit SigningInformationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
370 
371 
CreateOptional(CommandView parent)372 class SecurityRequestView : public CommandView { public:static SecurityRequestView Create(CommandView parent){ return SecurityRequestView(std::move(parent)); }static std::optional<SecurityRequestView> CreateOptional(CommandView parent){ auto to_validate = SecurityRequestView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
373 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
374 static SecurityRequestView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return SecurityRequestView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
375 #endif
376 uint8_t GetAuthReq() const {ASSERT(was_validated_);auto to_bound = begin();auto auth_req_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;uint8_t auth_req_value{};uint8_t* auth_req_ptr = &auth_req_value;auto extracted_value = auth_req_it.extract<uint8_t>();*auth_req_ptr = static_cast<uint8_t>(extracted_value);return auth_req_value;}
377 protected:
378 bool Validate() const override {
379   if (!CommandView::Validate()) {
380     return false;
381   }
382 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 1 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::SECURITY_REQUEST) return false;
383 return true;}
384 
385  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "SecurityRequest { ";ss << ""  << "auth_req = " << static_cast<uint64_t>(GetAuthReq());ss << " }";return ss.str();}
386 
387  protected:
388 explicit SecurityRequestView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
389 
390 
CreateOptional(CommandView parent)391 class PairingPublicKeyView : public CommandView { public:static PairingPublicKeyView Create(CommandView parent){ return PairingPublicKeyView(std::move(parent)); }static std::optional<PairingPublicKeyView> CreateOptional(CommandView parent){ auto to_validate = PairingPublicKeyView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
392 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
393 static PairingPublicKeyView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingPublicKeyView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
394 #endif
395 std::array<uint8_t,32> GetPublicKeyX() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 256 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 256 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto public_key_x_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,32> public_key_x_value{};std::array<uint8_t,32>* public_key_x_ptr = &public_key_x_value;std::array<uint8_t,32>::iterator ret_it = public_key_x_ptr->begin();auto val_it = public_key_x_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < public_key_x_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return public_key_x_value;}
396 
397 std::array<uint8_t,32> GetPublicKeyY() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 264 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 256 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto public_key_y_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,32> public_key_y_value{};std::array<uint8_t,32>* public_key_y_ptr = &public_key_y_value;std::array<uint8_t,32>::iterator ret_it = public_key_y_ptr->begin();auto val_it = public_key_y_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < public_key_y_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return public_key_y_value;}
398 
399 protected:
400 bool Validate() const override {
401   if (!CommandView::Validate()) {
402     return false;
403   }
404 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 64 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_PUBLIC_KEY) return false;
405 
406 return true;}
407 
408  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingPublicKey { ";ss << ""  << "public_key_x = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 32; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetPublicKeyX()[index]));}ss << "]" << ", public_key_y = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 32; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetPublicKeyY()[index]));}ss << "]";ss << " }";return ss.str();}
409 
410  protected:
411 explicit PairingPublicKeyView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
412 
413 
CreateOptional(CommandView parent)414 class PairingDhKeyCheckView : public CommandView { public:static PairingDhKeyCheckView Create(CommandView parent){ return PairingDhKeyCheckView(std::move(parent)); }static std::optional<PairingDhKeyCheckView> CreateOptional(CommandView parent){ auto to_validate = PairingDhKeyCheckView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
415 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
416 static PairingDhKeyCheckView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingDhKeyCheckView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
417 #endif
418 std::array<uint8_t,16> GetDhKeyCheck() const {ASSERT(was_validated_);size_t end_index = size();auto to_bound = begin();size_t field_begin = (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;size_t field_end = end_index - (/* Bits: */ 0 + /* Dynamic: */ 0) / 8;size_t field_sized_end = field_begin + (/* Bits: */ 128 + /* Dynamic: */ 0) / 8;if (field_sized_end < field_end) { field_end = field_sized_end; }auto dh_key_check_it = to_bound.Subrange(field_begin, field_end - field_begin); std::array<uint8_t,16> dh_key_check_value{};std::array<uint8_t,16>* dh_key_check_ptr = &dh_key_check_value;std::array<uint8_t,16>::iterator ret_it = dh_key_check_ptr->begin();auto val_it = dh_key_check_it;while (val_it.NumBytesRemaining() >= 1 && ret_it < dh_key_check_ptr->end()) {auto val_ptr = ret_it;auto extracted_value = val_it.extract<uint8_t>();*val_ptr = static_cast<uint8_t>(extracted_value);ret_it++;}return dh_key_check_value;}
419 
420 protected:
421 bool Validate() const override {
422   if (!CommandView::Validate()) {
423     return false;
424   }
425 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 16 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_DH_KEY_CHECK) return false;
426 return true;}
427 
428  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingDhKeyCheck { ";ss << ""  << "dh_key_check = " << "ARRAY[";/* uint8_t   ScalarField */for (size_t index = 0; index < 16; index++) {ss << ((index == 0) ? "" : ", ") << static_cast<uint64_t>((GetDhKeyCheck()[index]));}ss << "]";ss << " }";return ss.str();}
429 
430  protected:
431 explicit PairingDhKeyCheckView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
432 
433 
CreateOptional(CommandView parent)434 class PairingKeypressNotificationView : public CommandView { public:static PairingKeypressNotificationView Create(CommandView parent){ return PairingKeypressNotificationView(std::move(parent)); }static std::optional<PairingKeypressNotificationView> CreateOptional(CommandView parent){ auto to_validate = PairingKeypressNotificationView::Create(std::move(parent));if (to_validate.IsValid()) { return to_validate; }else {return {};}}
435 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
436 static PairingKeypressNotificationView FromBytes(std::vector<uint8_t> bytes) {auto vec = std::make_shared<std::vector<uint8_t>>(bytes);return PairingKeypressNotificationView::Create(CommandView::Create(PacketView<kLittleEndian>(vec)));}
437 #endif
438 KeypressNotificationType GetNotificationType() const {ASSERT(was_validated_);auto to_bound = begin();auto notification_type_it = to_bound + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;KeypressNotificationType notification_type_value{};KeypressNotificationType* notification_type_ptr = &notification_type_value;auto extracted_value = notification_type_it.extract<uint8_t>();*notification_type_ptr = static_cast<KeypressNotificationType>(extracted_value);return notification_type_value;}
439 protected:
440 bool Validate() const override {
441   if (!CommandView::Validate()) {
442     return false;
443   }
444 auto it = begin() + (/* Bits: */ 8 + /* Dynamic: */ 0) / 8;it += 1 /* Total size of the fixed fields */;if (it > end()) return false;if (GetCode() != Code::PAIRING_KEYPRESS_NOTIFICATION) return false;
445 return true;}
446 
447  public:virtual std::string ToString() const  override {std::stringstream ss;ss << std::showbase << std::hex << "PairingKeypressNotification { ";ss << ""  << "notification_type = " << KeypressNotificationTypeText(GetNotificationType());ss << " }";return ss.str();}
448 
449  protected:
450 explicit PairingKeypressNotificationView(CommandView parent) : CommandView(std::move(parent)) { was_validated_ = false; }};
451 
452 
Create(Code code,std::unique_ptr<BasePacketBuilder> payload)453 class CommandBuilder : public PacketBuilder<kLittleEndian> { public:  virtual ~CommandBuilder() = default;static std::unique_ptr<CommandBuilder> Create(Code code, std::unique_ptr<BasePacketBuilder> payload) {auto builder = std::unique_ptr<CommandBuilder>(new CommandBuilder(code));builder->payload_ = std::move(payload);return builder;}
454 
455 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
456 static std::unique_ptr<CommandBuilder> FromView(CommandView view) {if (!view.IsValid()) return nullptr;return CommandBuilder::Create(view.GetCode(), std::make_unique<RawBuilder>(std::vector<uint8_t>(view.GetPayload().begin(), view.GetPayload().end())));}
457 #endif
458 
459 protected:void SerializeHeader(BitInserter& i ) const {insert(static_cast<uint8_t>(code_), i, 8);}
460 
461 void SerializeFooter(BitInserter&) const {}
462 
463 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);payload_->Serialize(i);SerializeFooter(i);}
464 
465 protected:size_t BitsOfHeader() const {return 0 + /* Bits: */ 8 + /* Dynamic: */ 0;}
466 
467 size_t BitsOfFooter() const {return 0;}
468 
469 size_t GetPayloadSize() const {if (payload_ != nullptr) {return payload_->size();}else { return size() - (BitsOfHeader() + BitsOfFooter()) / 8;};}
470 
471 public:virtual size_t size() const override {return (BitsOfHeader() / 8)+ payload_->size() + (BitsOfFooter() / 8);}
472 
473  protected:
474 explicit CommandBuilder(Code code) :code_(code) {}
475 
476 
477 Code code_{};std::unique_ptr<BasePacketBuilder> payload_{};};
478 #ifdef PACKET_TESTING
479 #define DEFINE_AND_INSTANTIATE_CommandReflectionTest(...)class CommandReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {CommandView view = CommandView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = CommandBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(CommandReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(Command_reflection, CommandReflectionTest, testing::Values(__VA_ARGS__))
480 #endif
481 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
482 #define DEFINE_CommandReflectionFuzzTest() void RunCommandReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);CommandView view = CommandView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = CommandBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
483 #endif
484 
485 #ifdef PACKET_FUZZ_TESTING
486 #define DEFINE_AND_REGISTER_CommandReflectionFuzzTest(REGISTRY) DEFINE_CommandReflectionFuzzTest(); class CommandReflectionFuzzTestRegistrant {public: explicit CommandReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunCommandReflectionFuzzTest);}}; CommandReflectionFuzzTestRegistrant Command_reflection_fuzz_test_registrant(REGISTRY);
487 #endif
488 
489 
Create(IoCapability io_capability,OobDataFlag oob_data_flag,uint8_t auth_req,uint8_t maximum_encryption_key_size,uint8_t initiator_key_distribution,uint8_t responder_key_distribution)490 class PairingRequestBuilder : public CommandBuilder { public:  virtual ~PairingRequestBuilder() = default;static std::unique_ptr<PairingRequestBuilder> Create(IoCapability io_capability, OobDataFlag oob_data_flag, uint8_t auth_req, uint8_t maximum_encryption_key_size, uint8_t initiator_key_distribution, uint8_t responder_key_distribution) {auto builder = std::unique_ptr<PairingRequestBuilder>(new PairingRequestBuilder(io_capability, oob_data_flag, auth_req, maximum_encryption_key_size, initiator_key_distribution, responder_key_distribution));return builder;}
491 
492 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
493 static std::unique_ptr<PairingRequestBuilder> FromView(PairingRequestView view) {if (!view.IsValid()) return nullptr;return PairingRequestBuilder::Create(view.GetIoCapability(), view.GetOobDataFlag(), view.GetAuthReq(), view.GetMaximumEncryptionKeySize(), view.GetInitiatorKeyDistribution(), view.GetResponderKeyDistribution());}
494 #endif
495 
496 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(static_cast<uint8_t>(io_capability_), i, 8);insert(static_cast<uint8_t>(oob_data_flag_), i, 8);i.insert_byte(auth_req_);insert(maximum_encryption_key_size_, i,5);insert(static_cast<uint8_t>(0) /* Reserved */, i, 3 );
497 i.insert_byte(initiator_key_distribution_);i.insert_byte(responder_key_distribution_);}
498 
499 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
500 
501 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
502 
503 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 5 + /* Dynamic: */ 0 + /* Bits: */ 3 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0;}
504 
505 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
506 
507 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
508 
509  protected:
510 explicit PairingRequestBuilder(IoCapability io_capability, OobDataFlag oob_data_flag, uint8_t auth_req, uint8_t maximum_encryption_key_size, uint8_t initiator_key_distribution, uint8_t responder_key_distribution) :CommandBuilder(Code::PAIRING_REQUEST/* code_ */) ,io_capability_(io_capability),oob_data_flag_(oob_data_flag),auth_req_(auth_req),maximum_encryption_key_size_(maximum_encryption_key_size),initiator_key_distribution_(initiator_key_distribution),responder_key_distribution_(responder_key_distribution) {CheckParameterValues(maximum_encryption_key_size_);}
511 
512 void CheckParameterValues(uint8_t maximum_encryption_key_size) {ASSERT(maximum_encryption_key_size < (static_cast<uint64_t>(1) << 5));}
513 
514 IoCapability io_capability_{};OobDataFlag oob_data_flag_{};uint8_t auth_req_{};uint8_t maximum_encryption_key_size_{};uint8_t initiator_key_distribution_{};uint8_t responder_key_distribution_{};};
515 #ifdef PACKET_TESTING
516 #define DEFINE_AND_INSTANTIATE_PairingRequestReflectionTest(...)class PairingRequestReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingRequestView view = PairingRequestView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingRequestBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingRequestReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingRequest_reflection, PairingRequestReflectionTest, testing::Values(__VA_ARGS__))
517 #endif
518 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
519 #define DEFINE_PairingRequestReflectionFuzzTest() void RunPairingRequestReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingRequestView view = PairingRequestView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingRequestBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
520 #endif
521 
522 #ifdef PACKET_FUZZ_TESTING
523 #define DEFINE_AND_REGISTER_PairingRequestReflectionFuzzTest(REGISTRY) DEFINE_PairingRequestReflectionFuzzTest(); class PairingRequestReflectionFuzzTestRegistrant {public: explicit PairingRequestReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingRequestReflectionFuzzTest);}}; PairingRequestReflectionFuzzTestRegistrant PairingRequest_reflection_fuzz_test_registrant(REGISTRY);
524 #endif
525 
526 
Create(IoCapability io_capability,OobDataFlag oob_data_flag,uint8_t auth_req,uint8_t maximum_encryption_key_size,uint8_t initiator_key_distribution,uint8_t responder_key_distribution)527 class PairingResponseBuilder : public CommandBuilder { public:  virtual ~PairingResponseBuilder() = default;static std::unique_ptr<PairingResponseBuilder> Create(IoCapability io_capability, OobDataFlag oob_data_flag, uint8_t auth_req, uint8_t maximum_encryption_key_size, uint8_t initiator_key_distribution, uint8_t responder_key_distribution) {auto builder = std::unique_ptr<PairingResponseBuilder>(new PairingResponseBuilder(io_capability, oob_data_flag, auth_req, maximum_encryption_key_size, initiator_key_distribution, responder_key_distribution));return builder;}
528 
529 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
530 static std::unique_ptr<PairingResponseBuilder> FromView(PairingResponseView view) {if (!view.IsValid()) return nullptr;return PairingResponseBuilder::Create(view.GetIoCapability(), view.GetOobDataFlag(), view.GetAuthReq(), view.GetMaximumEncryptionKeySize(), view.GetInitiatorKeyDistribution(), view.GetResponderKeyDistribution());}
531 #endif
532 
533 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(static_cast<uint8_t>(io_capability_), i, 8);insert(static_cast<uint8_t>(oob_data_flag_), i, 8);i.insert_byte(auth_req_);insert(maximum_encryption_key_size_, i,5);insert(static_cast<uint8_t>(0) /* Reserved */, i, 3 );
534 i.insert_byte(initiator_key_distribution_);i.insert_byte(responder_key_distribution_);}
535 
536 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
537 
538 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
539 
540 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 5 + /* Dynamic: */ 0 + /* Bits: */ 3 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 8 + /* Dynamic: */ 0;}
541 
542 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
543 
544 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
545 
546  protected:
547 explicit PairingResponseBuilder(IoCapability io_capability, OobDataFlag oob_data_flag, uint8_t auth_req, uint8_t maximum_encryption_key_size, uint8_t initiator_key_distribution, uint8_t responder_key_distribution) :CommandBuilder(Code::PAIRING_RESPONSE/* code_ */) ,io_capability_(io_capability),oob_data_flag_(oob_data_flag),auth_req_(auth_req),maximum_encryption_key_size_(maximum_encryption_key_size),initiator_key_distribution_(initiator_key_distribution),responder_key_distribution_(responder_key_distribution) {CheckParameterValues(maximum_encryption_key_size_);}
548 
549 void CheckParameterValues(uint8_t maximum_encryption_key_size) {ASSERT(maximum_encryption_key_size < (static_cast<uint64_t>(1) << 5));}
550 
551 IoCapability io_capability_{};OobDataFlag oob_data_flag_{};uint8_t auth_req_{};uint8_t maximum_encryption_key_size_{};uint8_t initiator_key_distribution_{};uint8_t responder_key_distribution_{};};
552 #ifdef PACKET_TESTING
553 #define DEFINE_AND_INSTANTIATE_PairingResponseReflectionTest(...)class PairingResponseReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingResponseView view = PairingResponseView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingResponseBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingResponseReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingResponse_reflection, PairingResponseReflectionTest, testing::Values(__VA_ARGS__))
554 #endif
555 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
556 #define DEFINE_PairingResponseReflectionFuzzTest() void RunPairingResponseReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingResponseView view = PairingResponseView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingResponseBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
557 #endif
558 
559 #ifdef PACKET_FUZZ_TESTING
560 #define DEFINE_AND_REGISTER_PairingResponseReflectionFuzzTest(REGISTRY) DEFINE_PairingResponseReflectionFuzzTest(); class PairingResponseReflectionFuzzTestRegistrant {public: explicit PairingResponseReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingResponseReflectionFuzzTest);}}; PairingResponseReflectionFuzzTestRegistrant PairingResponse_reflection_fuzz_test_registrant(REGISTRY);
561 #endif
562 
563 
Create(const std::array<uint8_t,16> & confirm_value)564 class PairingConfirmBuilder : public CommandBuilder { public:  virtual ~PairingConfirmBuilder() = default;static std::unique_ptr<PairingConfirmBuilder> Create(const std::array<uint8_t,16>& confirm_value) {auto builder = std::unique_ptr<PairingConfirmBuilder>(new PairingConfirmBuilder(confirm_value));return builder;}
565 
566 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
567 static std::unique_ptr<PairingConfirmBuilder> FromView(PairingConfirmView view) {if (!view.IsValid()) return nullptr;return PairingConfirmBuilder::Create(view.GetConfirmValue());}
568 #endif
569 
570 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : confirm_value_) {i.insert_byte(val_);}
571 }
572 
573 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
574 
575 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
576 
577 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
578 
579 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
580 
581 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
582 
583  protected:
584 explicit PairingConfirmBuilder(const std::array<uint8_t,16>& confirm_value) :CommandBuilder(Code::PAIRING_CONFIRM/* code_ */) ,confirm_value_(confirm_value) {}
585 
586 
587 std::array<uint8_t,16> confirm_value_{};};
588 #ifdef PACKET_TESTING
589 #define DEFINE_AND_INSTANTIATE_PairingConfirmReflectionTest(...)class PairingConfirmReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingConfirmView view = PairingConfirmView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingConfirmBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingConfirmReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingConfirm_reflection, PairingConfirmReflectionTest, testing::Values(__VA_ARGS__))
590 #endif
591 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
592 #define DEFINE_PairingConfirmReflectionFuzzTest() void RunPairingConfirmReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingConfirmView view = PairingConfirmView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingConfirmBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
593 #endif
594 
595 #ifdef PACKET_FUZZ_TESTING
596 #define DEFINE_AND_REGISTER_PairingConfirmReflectionFuzzTest(REGISTRY) DEFINE_PairingConfirmReflectionFuzzTest(); class PairingConfirmReflectionFuzzTestRegistrant {public: explicit PairingConfirmReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingConfirmReflectionFuzzTest);}}; PairingConfirmReflectionFuzzTestRegistrant PairingConfirm_reflection_fuzz_test_registrant(REGISTRY);
597 #endif
598 
599 
Create(const std::array<uint8_t,16> & random_value)600 class PairingRandomBuilder : public CommandBuilder { public:  virtual ~PairingRandomBuilder() = default;static std::unique_ptr<PairingRandomBuilder> Create(const std::array<uint8_t,16>& random_value) {auto builder = std::unique_ptr<PairingRandomBuilder>(new PairingRandomBuilder(random_value));return builder;}
601 
602 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
603 static std::unique_ptr<PairingRandomBuilder> FromView(PairingRandomView view) {if (!view.IsValid()) return nullptr;return PairingRandomBuilder::Create(view.GetRandomValue());}
604 #endif
605 
606 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : random_value_) {i.insert_byte(val_);}
607 }
608 
609 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
610 
611 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
612 
613 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
614 
615 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
616 
617 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
618 
619  protected:
620 explicit PairingRandomBuilder(const std::array<uint8_t,16>& random_value) :CommandBuilder(Code::PAIRING_RANDOM/* code_ */) ,random_value_(random_value) {}
621 
622 
623 std::array<uint8_t,16> random_value_{};};
624 #ifdef PACKET_TESTING
625 #define DEFINE_AND_INSTANTIATE_PairingRandomReflectionTest(...)class PairingRandomReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingRandomView view = PairingRandomView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingRandomBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingRandomReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingRandom_reflection, PairingRandomReflectionTest, testing::Values(__VA_ARGS__))
626 #endif
627 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
628 #define DEFINE_PairingRandomReflectionFuzzTest() void RunPairingRandomReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingRandomView view = PairingRandomView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingRandomBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
629 #endif
630 
631 #ifdef PACKET_FUZZ_TESTING
632 #define DEFINE_AND_REGISTER_PairingRandomReflectionFuzzTest(REGISTRY) DEFINE_PairingRandomReflectionFuzzTest(); class PairingRandomReflectionFuzzTestRegistrant {public: explicit PairingRandomReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingRandomReflectionFuzzTest);}}; PairingRandomReflectionFuzzTestRegistrant PairingRandom_reflection_fuzz_test_registrant(REGISTRY);
633 #endif
634 
635 
Create(PairingFailedReason reason)636 class PairingFailedBuilder : public CommandBuilder { public:  virtual ~PairingFailedBuilder() = default;static std::unique_ptr<PairingFailedBuilder> Create(PairingFailedReason reason) {auto builder = std::unique_ptr<PairingFailedBuilder>(new PairingFailedBuilder(reason));return builder;}
637 
638 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
639 static std::unique_ptr<PairingFailedBuilder> FromView(PairingFailedView view) {if (!view.IsValid()) return nullptr;return PairingFailedBuilder::Create(view.GetReason());}
640 #endif
641 
642 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(static_cast<uint8_t>(reason_), i, 8);}
643 
644 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
645 
646 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
647 
648 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0;}
649 
650 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
651 
652 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
653 
654  protected:
655 explicit PairingFailedBuilder(PairingFailedReason reason) :CommandBuilder(Code::PAIRING_FAILED/* code_ */) ,reason_(reason) {}
656 
657 
658 PairingFailedReason reason_{};};
659 #ifdef PACKET_TESTING
660 #define DEFINE_AND_INSTANTIATE_PairingFailedReflectionTest(...)class PairingFailedReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingFailedView view = PairingFailedView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingFailedBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingFailedReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingFailed_reflection, PairingFailedReflectionTest, testing::Values(__VA_ARGS__))
661 #endif
662 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
663 #define DEFINE_PairingFailedReflectionFuzzTest() void RunPairingFailedReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingFailedView view = PairingFailedView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingFailedBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
664 #endif
665 
666 #ifdef PACKET_FUZZ_TESTING
667 #define DEFINE_AND_REGISTER_PairingFailedReflectionFuzzTest(REGISTRY) DEFINE_PairingFailedReflectionFuzzTest(); class PairingFailedReflectionFuzzTestRegistrant {public: explicit PairingFailedReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingFailedReflectionFuzzTest);}}; PairingFailedReflectionFuzzTestRegistrant PairingFailed_reflection_fuzz_test_registrant(REGISTRY);
668 #endif
669 
670 
Create(const std::array<uint8_t,16> & long_term_key)671 class EncryptionInformationBuilder : public CommandBuilder { public:  virtual ~EncryptionInformationBuilder() = default;static std::unique_ptr<EncryptionInformationBuilder> Create(const std::array<uint8_t,16>& long_term_key) {auto builder = std::unique_ptr<EncryptionInformationBuilder>(new EncryptionInformationBuilder(long_term_key));return builder;}
672 
673 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
674 static std::unique_ptr<EncryptionInformationBuilder> FromView(EncryptionInformationView view) {if (!view.IsValid()) return nullptr;return EncryptionInformationBuilder::Create(view.GetLongTermKey());}
675 #endif
676 
677 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : long_term_key_) {i.insert_byte(val_);}
678 }
679 
680 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
681 
682 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
683 
684 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
685 
686 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
687 
688 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
689 
690  protected:
691 explicit EncryptionInformationBuilder(const std::array<uint8_t,16>& long_term_key) :CommandBuilder(Code::ENCRYPTION_INFORMATION/* code_ */) ,long_term_key_(long_term_key) {}
692 
693 
694 std::array<uint8_t,16> long_term_key_{};};
695 #ifdef PACKET_TESTING
696 #define DEFINE_AND_INSTANTIATE_EncryptionInformationReflectionTest(...)class EncryptionInformationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {EncryptionInformationView view = EncryptionInformationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = EncryptionInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(EncryptionInformationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(EncryptionInformation_reflection, EncryptionInformationReflectionTest, testing::Values(__VA_ARGS__))
697 #endif
698 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
699 #define DEFINE_EncryptionInformationReflectionFuzzTest() void RunEncryptionInformationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);EncryptionInformationView view = EncryptionInformationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = EncryptionInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
700 #endif
701 
702 #ifdef PACKET_FUZZ_TESTING
703 #define DEFINE_AND_REGISTER_EncryptionInformationReflectionFuzzTest(REGISTRY) DEFINE_EncryptionInformationReflectionFuzzTest(); class EncryptionInformationReflectionFuzzTestRegistrant {public: explicit EncryptionInformationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunEncryptionInformationReflectionFuzzTest);}}; EncryptionInformationReflectionFuzzTestRegistrant EncryptionInformation_reflection_fuzz_test_registrant(REGISTRY);
704 #endif
705 
706 
Create(uint16_t ediv,const std::array<uint8_t,8> & rand)707 class CentralIdentificationBuilder : public CommandBuilder { public:  virtual ~CentralIdentificationBuilder() = default;static std::unique_ptr<CentralIdentificationBuilder> Create(uint16_t ediv, const std::array<uint8_t,8>& rand) {auto builder = std::unique_ptr<CentralIdentificationBuilder>(new CentralIdentificationBuilder(ediv, rand));return builder;}
708 
709 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
710 static std::unique_ptr<CentralIdentificationBuilder> FromView(CentralIdentificationView view) {if (!view.IsValid()) return nullptr;return CentralIdentificationBuilder::Create(view.GetEdiv(), view.GetRand());}
711 #endif
712 
713 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(ediv_, i,16);for (const auto& val_ : rand_) {i.insert_byte(val_);}
714 }
715 
716 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
717 
718 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
719 
720 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 16 + /* Dynamic: */ 0 + /* Bits: */ 64 + /* Dynamic: */ 0;}
721 
722 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
723 
724 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
725 
726  protected:
727 explicit CentralIdentificationBuilder(uint16_t ediv, const std::array<uint8_t,8>& rand) :CommandBuilder(Code::CENTRAL_IDENTIFICATION/* code_ */) ,ediv_(ediv),rand_(rand) {}
728 
729 
730 uint16_t ediv_{};std::array<uint8_t,8> rand_{};};
731 #ifdef PACKET_TESTING
732 #define DEFINE_AND_INSTANTIATE_CentralIdentificationReflectionTest(...)class CentralIdentificationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {CentralIdentificationView view = CentralIdentificationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = CentralIdentificationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(CentralIdentificationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(CentralIdentification_reflection, CentralIdentificationReflectionTest, testing::Values(__VA_ARGS__))
733 #endif
734 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
735 #define DEFINE_CentralIdentificationReflectionFuzzTest() void RunCentralIdentificationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);CentralIdentificationView view = CentralIdentificationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = CentralIdentificationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
736 #endif
737 
738 #ifdef PACKET_FUZZ_TESTING
739 #define DEFINE_AND_REGISTER_CentralIdentificationReflectionFuzzTest(REGISTRY) DEFINE_CentralIdentificationReflectionFuzzTest(); class CentralIdentificationReflectionFuzzTestRegistrant {public: explicit CentralIdentificationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunCentralIdentificationReflectionFuzzTest);}}; CentralIdentificationReflectionFuzzTestRegistrant CentralIdentification_reflection_fuzz_test_registrant(REGISTRY);
740 #endif
741 
742 
Create(const std::array<uint8_t,16> & identity_resolving_key)743 class IdentityInformationBuilder : public CommandBuilder { public:  virtual ~IdentityInformationBuilder() = default;static std::unique_ptr<IdentityInformationBuilder> Create(const std::array<uint8_t,16>& identity_resolving_key) {auto builder = std::unique_ptr<IdentityInformationBuilder>(new IdentityInformationBuilder(identity_resolving_key));return builder;}
744 
745 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
746 static std::unique_ptr<IdentityInformationBuilder> FromView(IdentityInformationView view) {if (!view.IsValid()) return nullptr;return IdentityInformationBuilder::Create(view.GetIdentityResolvingKey());}
747 #endif
748 
749 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : identity_resolving_key_) {i.insert_byte(val_);}
750 }
751 
752 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
753 
754 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
755 
756 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
757 
758 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
759 
760 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
761 
762  protected:
763 explicit IdentityInformationBuilder(const std::array<uint8_t,16>& identity_resolving_key) :CommandBuilder(Code::IDENTITY_INFORMATION/* code_ */) ,identity_resolving_key_(identity_resolving_key) {}
764 
765 
766 std::array<uint8_t,16> identity_resolving_key_{};};
767 #ifdef PACKET_TESTING
768 #define DEFINE_AND_INSTANTIATE_IdentityInformationReflectionTest(...)class IdentityInformationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {IdentityInformationView view = IdentityInformationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = IdentityInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(IdentityInformationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(IdentityInformation_reflection, IdentityInformationReflectionTest, testing::Values(__VA_ARGS__))
769 #endif
770 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
771 #define DEFINE_IdentityInformationReflectionFuzzTest() void RunIdentityInformationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);IdentityInformationView view = IdentityInformationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = IdentityInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
772 #endif
773 
774 #ifdef PACKET_FUZZ_TESTING
775 #define DEFINE_AND_REGISTER_IdentityInformationReflectionFuzzTest(REGISTRY) DEFINE_IdentityInformationReflectionFuzzTest(); class IdentityInformationReflectionFuzzTestRegistrant {public: explicit IdentityInformationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunIdentityInformationReflectionFuzzTest);}}; IdentityInformationReflectionFuzzTestRegistrant IdentityInformation_reflection_fuzz_test_registrant(REGISTRY);
776 #endif
777 
778 
Create(AddrType addr_type,Address bd_addr)779 class IdentityAddressInformationBuilder : public CommandBuilder { public:  virtual ~IdentityAddressInformationBuilder() = default;static std::unique_ptr<IdentityAddressInformationBuilder> Create(AddrType addr_type, Address bd_addr) {auto builder = std::unique_ptr<IdentityAddressInformationBuilder>(new IdentityAddressInformationBuilder(addr_type, bd_addr));return builder;}
780 
781 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
782 static std::unique_ptr<IdentityAddressInformationBuilder> FromView(IdentityAddressInformationView view) {if (!view.IsValid()) return nullptr;return IdentityAddressInformationBuilder::Create(view.GetAddrType(), view.GetBdAddr());}
783 #endif
784 
785 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(static_cast<uint8_t>(addr_type_), i, 8);insert(bd_addr_, i);}
786 
787 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
788 
789 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
790 
791 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0 + /* Bits: */ 48 + /* Dynamic: */ 0;}
792 
793 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
794 
795 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
796 
797  protected:
798 explicit IdentityAddressInformationBuilder(AddrType addr_type, Address bd_addr) :CommandBuilder(Code::IDENTITY_ADDRESS_INFORMATION/* code_ */) ,addr_type_(addr_type),bd_addr_(bd_addr) {}
799 
800 
801 AddrType addr_type_{};Address bd_addr_{};};
802 #ifdef PACKET_TESTING
803 #define DEFINE_AND_INSTANTIATE_IdentityAddressInformationReflectionTest(...)class IdentityAddressInformationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {IdentityAddressInformationView view = IdentityAddressInformationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = IdentityAddressInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(IdentityAddressInformationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(IdentityAddressInformation_reflection, IdentityAddressInformationReflectionTest, testing::Values(__VA_ARGS__))
804 #endif
805 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
806 #define DEFINE_IdentityAddressInformationReflectionFuzzTest() void RunIdentityAddressInformationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);IdentityAddressInformationView view = IdentityAddressInformationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = IdentityAddressInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
807 #endif
808 
809 #ifdef PACKET_FUZZ_TESTING
810 #define DEFINE_AND_REGISTER_IdentityAddressInformationReflectionFuzzTest(REGISTRY) DEFINE_IdentityAddressInformationReflectionFuzzTest(); class IdentityAddressInformationReflectionFuzzTestRegistrant {public: explicit IdentityAddressInformationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunIdentityAddressInformationReflectionFuzzTest);}}; IdentityAddressInformationReflectionFuzzTestRegistrant IdentityAddressInformation_reflection_fuzz_test_registrant(REGISTRY);
811 #endif
812 
813 
Create(const std::array<uint8_t,16> & signature_key)814 class SigningInformationBuilder : public CommandBuilder { public:  virtual ~SigningInformationBuilder() = default;static std::unique_ptr<SigningInformationBuilder> Create(const std::array<uint8_t,16>& signature_key) {auto builder = std::unique_ptr<SigningInformationBuilder>(new SigningInformationBuilder(signature_key));return builder;}
815 
816 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
817 static std::unique_ptr<SigningInformationBuilder> FromView(SigningInformationView view) {if (!view.IsValid()) return nullptr;return SigningInformationBuilder::Create(view.GetSignatureKey());}
818 #endif
819 
820 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : signature_key_) {i.insert_byte(val_);}
821 }
822 
823 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
824 
825 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
826 
827 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
828 
829 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
830 
831 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
832 
833  protected:
834 explicit SigningInformationBuilder(const std::array<uint8_t,16>& signature_key) :CommandBuilder(Code::SIGNING_INFORMATION/* code_ */) ,signature_key_(signature_key) {}
835 
836 
837 std::array<uint8_t,16> signature_key_{};};
838 #ifdef PACKET_TESTING
839 #define DEFINE_AND_INSTANTIATE_SigningInformationReflectionTest(...)class SigningInformationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {SigningInformationView view = SigningInformationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = SigningInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(SigningInformationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(SigningInformation_reflection, SigningInformationReflectionTest, testing::Values(__VA_ARGS__))
840 #endif
841 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
842 #define DEFINE_SigningInformationReflectionFuzzTest() void RunSigningInformationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);SigningInformationView view = SigningInformationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = SigningInformationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
843 #endif
844 
845 #ifdef PACKET_FUZZ_TESTING
846 #define DEFINE_AND_REGISTER_SigningInformationReflectionFuzzTest(REGISTRY) DEFINE_SigningInformationReflectionFuzzTest(); class SigningInformationReflectionFuzzTestRegistrant {public: explicit SigningInformationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunSigningInformationReflectionFuzzTest);}}; SigningInformationReflectionFuzzTestRegistrant SigningInformation_reflection_fuzz_test_registrant(REGISTRY);
847 #endif
848 
849 
Create(uint8_t auth_req)850 class SecurityRequestBuilder : public CommandBuilder { public:  virtual ~SecurityRequestBuilder() = default;static std::unique_ptr<SecurityRequestBuilder> Create(uint8_t auth_req) {auto builder = std::unique_ptr<SecurityRequestBuilder>(new SecurityRequestBuilder(auth_req));return builder;}
851 
852 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
853 static std::unique_ptr<SecurityRequestBuilder> FromView(SecurityRequestView view) {if (!view.IsValid()) return nullptr;return SecurityRequestBuilder::Create(view.GetAuthReq());}
854 #endif
855 
856 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);i.insert_byte(auth_req_);}
857 
858 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
859 
860 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
861 
862 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0;}
863 
864 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
865 
866 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
867 
868  protected:
869 explicit SecurityRequestBuilder(uint8_t auth_req) :CommandBuilder(Code::SECURITY_REQUEST/* code_ */) ,auth_req_(auth_req) {}
870 
871 
872 uint8_t auth_req_{};};
873 #ifdef PACKET_TESTING
874 #define DEFINE_AND_INSTANTIATE_SecurityRequestReflectionTest(...)class SecurityRequestReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {SecurityRequestView view = SecurityRequestView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = SecurityRequestBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(SecurityRequestReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(SecurityRequest_reflection, SecurityRequestReflectionTest, testing::Values(__VA_ARGS__))
875 #endif
876 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
877 #define DEFINE_SecurityRequestReflectionFuzzTest() void RunSecurityRequestReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);SecurityRequestView view = SecurityRequestView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = SecurityRequestBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
878 #endif
879 
880 #ifdef PACKET_FUZZ_TESTING
881 #define DEFINE_AND_REGISTER_SecurityRequestReflectionFuzzTest(REGISTRY) DEFINE_SecurityRequestReflectionFuzzTest(); class SecurityRequestReflectionFuzzTestRegistrant {public: explicit SecurityRequestReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunSecurityRequestReflectionFuzzTest);}}; SecurityRequestReflectionFuzzTestRegistrant SecurityRequest_reflection_fuzz_test_registrant(REGISTRY);
882 #endif
883 
884 
Create(const std::array<uint8_t,32> & public_key_x,const std::array<uint8_t,32> & public_key_y)885 class PairingPublicKeyBuilder : public CommandBuilder { public:  virtual ~PairingPublicKeyBuilder() = default;static std::unique_ptr<PairingPublicKeyBuilder> Create(const std::array<uint8_t,32>& public_key_x, const std::array<uint8_t,32>& public_key_y) {auto builder = std::unique_ptr<PairingPublicKeyBuilder>(new PairingPublicKeyBuilder(public_key_x, public_key_y));return builder;}
886 
887 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
888 static std::unique_ptr<PairingPublicKeyBuilder> FromView(PairingPublicKeyView view) {if (!view.IsValid()) return nullptr;return PairingPublicKeyBuilder::Create(view.GetPublicKeyX(), view.GetPublicKeyY());}
889 #endif
890 
891 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : public_key_x_) {i.insert_byte(val_);}
892 for (const auto& val_ : public_key_y_) {i.insert_byte(val_);}
893 }
894 
895 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
896 
897 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
898 
899 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 256 + /* Dynamic: */ 0 + /* Bits: */ 256 + /* Dynamic: */ 0;}
900 
901 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
902 
903 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
904 
905  protected:
906 explicit PairingPublicKeyBuilder(const std::array<uint8_t,32>& public_key_x, const std::array<uint8_t,32>& public_key_y) :CommandBuilder(Code::PAIRING_PUBLIC_KEY/* code_ */) ,public_key_x_(public_key_x),public_key_y_(public_key_y) {}
907 
908 
909 std::array<uint8_t,32> public_key_x_{};std::array<uint8_t,32> public_key_y_{};};
910 #ifdef PACKET_TESTING
911 #define DEFINE_AND_INSTANTIATE_PairingPublicKeyReflectionTest(...)class PairingPublicKeyReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingPublicKeyView view = PairingPublicKeyView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingPublicKeyBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingPublicKeyReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingPublicKey_reflection, PairingPublicKeyReflectionTest, testing::Values(__VA_ARGS__))
912 #endif
913 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
914 #define DEFINE_PairingPublicKeyReflectionFuzzTest() void RunPairingPublicKeyReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingPublicKeyView view = PairingPublicKeyView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingPublicKeyBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
915 #endif
916 
917 #ifdef PACKET_FUZZ_TESTING
918 #define DEFINE_AND_REGISTER_PairingPublicKeyReflectionFuzzTest(REGISTRY) DEFINE_PairingPublicKeyReflectionFuzzTest(); class PairingPublicKeyReflectionFuzzTestRegistrant {public: explicit PairingPublicKeyReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingPublicKeyReflectionFuzzTest);}}; PairingPublicKeyReflectionFuzzTestRegistrant PairingPublicKey_reflection_fuzz_test_registrant(REGISTRY);
919 #endif
920 
921 
Create(const std::array<uint8_t,16> & dh_key_check)922 class PairingDhKeyCheckBuilder : public CommandBuilder { public:  virtual ~PairingDhKeyCheckBuilder() = default;static std::unique_ptr<PairingDhKeyCheckBuilder> Create(const std::array<uint8_t,16>& dh_key_check) {auto builder = std::unique_ptr<PairingDhKeyCheckBuilder>(new PairingDhKeyCheckBuilder(dh_key_check));return builder;}
923 
924 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
925 static std::unique_ptr<PairingDhKeyCheckBuilder> FromView(PairingDhKeyCheckView view) {if (!view.IsValid()) return nullptr;return PairingDhKeyCheckBuilder::Create(view.GetDhKeyCheck());}
926 #endif
927 
928 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);for (const auto& val_ : dh_key_check_) {i.insert_byte(val_);}
929 }
930 
931 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
932 
933 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
934 
935 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 128 + /* Dynamic: */ 0;}
936 
937 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
938 
939 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
940 
941  protected:
942 explicit PairingDhKeyCheckBuilder(const std::array<uint8_t,16>& dh_key_check) :CommandBuilder(Code::PAIRING_DH_KEY_CHECK/* code_ */) ,dh_key_check_(dh_key_check) {}
943 
944 
945 std::array<uint8_t,16> dh_key_check_{};};
946 #ifdef PACKET_TESTING
947 #define DEFINE_AND_INSTANTIATE_PairingDhKeyCheckReflectionTest(...)class PairingDhKeyCheckReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingDhKeyCheckView view = PairingDhKeyCheckView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingDhKeyCheckBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingDhKeyCheckReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingDhKeyCheck_reflection, PairingDhKeyCheckReflectionTest, testing::Values(__VA_ARGS__))
948 #endif
949 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
950 #define DEFINE_PairingDhKeyCheckReflectionFuzzTest() void RunPairingDhKeyCheckReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingDhKeyCheckView view = PairingDhKeyCheckView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingDhKeyCheckBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
951 #endif
952 
953 #ifdef PACKET_FUZZ_TESTING
954 #define DEFINE_AND_REGISTER_PairingDhKeyCheckReflectionFuzzTest(REGISTRY) DEFINE_PairingDhKeyCheckReflectionFuzzTest(); class PairingDhKeyCheckReflectionFuzzTestRegistrant {public: explicit PairingDhKeyCheckReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingDhKeyCheckReflectionFuzzTest);}}; PairingDhKeyCheckReflectionFuzzTestRegistrant PairingDhKeyCheck_reflection_fuzz_test_registrant(REGISTRY);
955 #endif
956 
957 
Create(KeypressNotificationType notification_type)958 class PairingKeypressNotificationBuilder : public CommandBuilder { public:  virtual ~PairingKeypressNotificationBuilder() = default;static std::unique_ptr<PairingKeypressNotificationBuilder> Create(KeypressNotificationType notification_type) {auto builder = std::unique_ptr<PairingKeypressNotificationBuilder>(new PairingKeypressNotificationBuilder(notification_type));return builder;}
959 
960 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING) || defined(FUZZ_TARGET)
961 static std::unique_ptr<PairingKeypressNotificationBuilder> FromView(PairingKeypressNotificationView view) {if (!view.IsValid()) return nullptr;return PairingKeypressNotificationBuilder::Create(view.GetNotificationType());}
962 #endif
963 
964 protected:void SerializeHeader(BitInserter& i ) const {CommandBuilder::SerializeHeader(i);insert(static_cast<uint8_t>(notification_type_), i, 8);}
965 
966 void SerializeFooter(BitInserter& i ) const {CommandBuilder::SerializeFooter(i);}
967 
968 public:virtual void Serialize(BitInserter& i) const override {SerializeHeader(i);SerializeFooter(i);}
969 
970 protected:size_t BitsOfHeader() const {return 0 + CommandBuilder::BitsOfHeader()  + /* Bits: */ 8 + /* Dynamic: */ 0;}
971 
972 size_t BitsOfFooter() const {return 0 + CommandBuilder::BitsOfFooter() ;}
973 
974 public:virtual size_t size() const override {return (BitsOfHeader() / 8) + (BitsOfFooter() / 8);}
975 
976  protected:
977 explicit PairingKeypressNotificationBuilder(KeypressNotificationType notification_type) :CommandBuilder(Code::PAIRING_KEYPRESS_NOTIFICATION/* code_ */) ,notification_type_(notification_type) {}
978 
979 
980 KeypressNotificationType notification_type_{};};
981 #ifdef PACKET_TESTING
982 #define DEFINE_AND_INSTANTIATE_PairingKeypressNotificationReflectionTest(...)class PairingKeypressNotificationReflectionTest : public testing::TestWithParam<std::vector<uint8_t>> { public: void CompareBytes(std::vector<uint8_t> captured_packet) {PairingKeypressNotificationView view = PairingKeypressNotificationView::FromBytes(captured_packet);if (!view.IsValid()) { log::info("Invalid Packet Bytes (size = {})", view.size());for (size_t i = 0; i < view.size(); i++) { log::info("{:5}:{:02x}", i, *(view.begin() + i)); }}ASSERT_TRUE(view.IsValid());auto packet = PairingKeypressNotificationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);ASSERT_EQ(*packet_bytes, captured_packet);}};TEST_P(PairingKeypressNotificationReflectionTest, generatedReflectionTest) {CompareBytes(GetParam());}INSTANTIATE_TEST_SUITE_P(PairingKeypressNotification_reflection, PairingKeypressNotificationReflectionTest, testing::Values(__VA_ARGS__))
983 #endif
984 #if defined(PACKET_FUZZ_TESTING) || defined(PACKET_TESTING)
985 #define DEFINE_PairingKeypressNotificationReflectionFuzzTest() void RunPairingKeypressNotificationReflectionFuzzTest(const uint8_t* data, size_t size) {auto vec = std::vector<uint8_t>(data, data + size);PairingKeypressNotificationView view = PairingKeypressNotificationView::FromBytes(vec);if (!view.IsValid()) { return; }auto packet = PairingKeypressNotificationBuilder::FromView(view);std::shared_ptr<std::vector<uint8_t>> packet_bytes = std::make_shared<std::vector<uint8_t>>();packet_bytes->reserve(packet->size());BitInserter it(*packet_bytes);packet->Serialize(it);}
986 #endif
987 
988 #ifdef PACKET_FUZZ_TESTING
989 #define DEFINE_AND_REGISTER_PairingKeypressNotificationReflectionFuzzTest(REGISTRY) DEFINE_PairingKeypressNotificationReflectionFuzzTest(); class PairingKeypressNotificationReflectionFuzzTestRegistrant {public: explicit PairingKeypressNotificationReflectionFuzzTestRegistrant(std::vector<void(*)(const uint8_t*, size_t)>& fuzz_test_registry) {fuzz_test_registry.push_back(RunPairingKeypressNotificationReflectionFuzzTest);}}; PairingKeypressNotificationReflectionFuzzTestRegistrant PairingKeypressNotification_reflection_fuzz_test_registrant(REGISTRY);
990 #endif
991 
992 
993 }  //namespace security
994 }  //namespace bluetooth
995 #if __has_include(<bluetooth/log.h>)
996 namespace std {
997 template <>
998 struct formatter<bluetooth::security::Code> : enum_formatter<bluetooth::security::Code> {};
999 template <>
1000 struct formatter<bluetooth::security::IoCapability> : enum_formatter<bluetooth::security::IoCapability> {};
1001 template <>
1002 struct formatter<bluetooth::security::OobDataFlag> : enum_formatter<bluetooth::security::OobDataFlag> {};
1003 template <>
1004 struct formatter<bluetooth::security::BondingFlags> : enum_formatter<bluetooth::security::BondingFlags> {};
1005 template <>
1006 struct formatter<bluetooth::security::PairingFailedReason> : enum_formatter<bluetooth::security::PairingFailedReason> {};
1007 template <>
1008 struct formatter<bluetooth::security::AddrType> : enum_formatter<bluetooth::security::AddrType> {};
1009 template <>
1010 struct formatter<bluetooth::security::KeypressNotificationType> : enum_formatter<bluetooth::security::KeypressNotificationType> {};
1011 } // namespace std
1012 #endif // __has_include(<bluetooth/log.h>)
1013