@@ -39,38 +39,23 @@ namespace chip {
39
39
bool PayloadContents::isValidQRCodePayload (ValidationMode mode) const
40
40
{
41
41
// 3-bit value specifying the QR code payload version.
42
- if (version >= 1 << kVersionFieldLengthInBits )
43
- {
44
- return false ;
45
- }
42
+ VerifyOrReturnValue (version < (1 << kVersionFieldLengthInBits ), false );
46
43
47
- if (static_cast <uint8_t >(commissioningFlow) > static_cast <uint8_t >((1 << kCommissioningFlowFieldLengthInBits ) - 1 ))
48
- {
49
- return false ;
50
- }
44
+ VerifyOrReturnValue (static_cast <uint8_t >(commissioningFlow) < (1 << kCommissioningFlowFieldLengthInBits ), false );
51
45
52
46
// Device Commissioning Flow
53
47
// Even in ValidatoinMode::kConsume we can only handle modes that we understand.
54
48
// 0: Standard commissioning flow: such a device, when uncommissioned, always enters commissioning mode upon power-up, subject
55
49
// to the rules in [ref_Announcement_Commencement]. 1: User-intent commissioning flow: user action required to enter
56
50
// commissioning mode. 2: Custom commissioning flow: interaction with a vendor-specified means is needed before commissioning.
57
51
// 3: Reserved
58
- if (commissioningFlow != CommissioningFlow::kStandard && commissioningFlow != CommissioningFlow::kUserActionRequired &&
59
- commissioningFlow != CommissioningFlow::kCustom )
60
- {
61
- return false ;
62
- }
52
+ VerifyOrReturnValue (commissioningFlow == CommissioningFlow::kStandard ||
53
+ commissioningFlow == CommissioningFlow::kUserActionRequired ||
54
+ commissioningFlow == CommissioningFlow::kCustom ,
55
+ false );
63
56
64
57
// General discriminator validity is enforced by the SetupDiscriminator class, but it can't be short for QR a code.
65
- if (discriminator.IsShortDiscriminator ())
66
- {
67
- return false ;
68
- }
69
-
70
- if (setUpPINCode >= 1 << kSetupPINCodeFieldLengthInBits )
71
- {
72
- return false ;
73
- }
58
+ VerifyOrReturnValue (!discriminator.IsShortDiscriminator (), false );
74
59
75
60
// RendevouzInformation must be present for a QR code.
76
61
VerifyOrReturnValue (rendezvousInformation.HasValue (), false );
@@ -86,12 +71,8 @@ bool PayloadContents::isValidQRCodePayload(ValidationMode mode) const
86
71
87
72
bool PayloadContents::isValidManualCode (ValidationMode mode) const
88
73
{
89
- // Discriminator validity is enforced by the SetupDiscriminator class.
90
- if (setUpPINCode >= 1 << kSetupPINCodeFieldLengthInBits )
91
- {
92
- return false ;
93
- }
94
-
74
+ // No additional constraints apply to Manual Pairing Codes.
75
+ // (If the payload has a long discriminator it will be converted automatically.)
95
76
return CheckPayloadCommonConstraints ();
96
77
}
97
78
@@ -114,30 +95,19 @@ bool PayloadContents::CheckPayloadCommonConstraints() const
114
95
// Validation rules in this method apply to all validation modes.
115
96
116
97
// Even in ValidationMode::kConsume we don't understand how to handle any payload version other than 0.
117
- if (version != 0 )
118
- {
119
- return false ;
120
- }
98
+ VerifyOrReturnValue (version == 0 , false );
121
99
122
- if (!IsValidSetupPIN (setUpPINCode))
123
- {
124
- return false ;
125
- }
100
+ VerifyOrReturnValue (IsValidSetupPIN (setUpPINCode), false );
126
101
127
102
// VendorID must be unspecified (0) or in valid range expected.
128
- if (!IsVendorIdValidOperationally (vendorID) && (vendorID != VendorId::Unspecified))
129
- {
130
- return false ;
131
- }
103
+ VerifyOrReturnValue ((vendorID == VendorId::Unspecified) || IsVendorIdValidOperationally (vendorID), false );
132
104
133
105
// A value of 0x0000 SHALL NOT be assigned to a product since Product ID = 0x0000 is used for these specific cases:
134
106
// * To announce an anonymized Product ID as part of device discovery
135
107
// * To indicate an OTA software update file applies to multiple Product IDs equally.
136
108
// * To avoid confusion when presenting the Onboarding Payload for ECM with multiple nodes
137
- if (productID == 0 && vendorID != VendorId::Unspecified)
138
- {
139
- return false ;
140
- }
109
+ // In these special cases the vendorID must be 0 (Unspecified)
110
+ VerifyOrReturnValue (productID != 0 || vendorID == VendorId::Unspecified, false );
141
111
142
112
return true ;
143
113
}
0 commit comments