-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base45 to a Set up payload #146
Base45 to a Set up payload #146
Conversation
static uint64_t readBits(vector <uint8_t> buf, int &index, size_t numberOfBitsToRead) | ||
{ | ||
uint64_t dest = 0; | ||
if (index + numberOfBitsToRead > buf.size() * 8 || numberOfBitsToRead > 64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe change 64
to sizeof(uint64_t) * 8 (or document why 64, i.e. the return type can only hold 64 bits)?
Also, the caller of this function won't know if this is an error, or the bits were actually 0.
For example, https://github.com/project-chip/connectedhomeip/pull/146/files#diff-958871ab391ca31ed8a2a6cee29fade0R68
if someone to change kVersionFieldLengthInBits
to 65, the QRCodeSetupPayloadParser::payload
will continue to run successfully, but return incorrect values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change to sizeof(uint64_t) * 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if someone to change kVersionFieldLengthInBits to 65, the QRCodeSetupPayloadParser::payload will continue to run successfully, but return incorrect values.
@bhaskar-apple Pankaj has a point here. We should return a proper error here so the caller knows it was an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sagar-apple he does and Rob is working on a patch to fix it both for parsing and encoding.
Overall, as this code starts to adopt more error handling, I'd advocate, since it is new code, picking a convention for error handling. Personally, I'd advocate for a single entry point, single return point style, supported by macros of the sort embodied by here https://github.com/project-chip/connectedhomeip/blob/master/src/lib/support/CodeUtils.h, which in turn, are supported by those here, https://github.com/nestlabs/nlassert/, which were inspired by those here, https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h. |
@gerickson - I agree having a convention for error handling for new code. But I would request not holding this PR before we agree on what that should be. I think we need to have a bit more offline discussion around the convention. I am happy to open a new PR to fix this one as soon as we land on a convention. Just as as interesting read, one example of |
@@ -0,0 +1,77 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would encourage Doxygenizing this new code.
@@ -0,0 +1,42 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would encourage Doxygenizing this new code.
@hawk248 ? |
@bhaskar-apple can we fix this conflict? @BroderickCarlin or @jelderton can we get one more set of eyes on this? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -37,6 +37,7 @@ static void populateBits(uint8_t * bits, int & offset, uint64_t input, size_t nu | |||
// do nothing in the case where we've overflowed. should never happen | |||
if (offset + numberOfBits > kTotalPayloadDataSizeInBits || input >= 1u << numberOfBits) | |||
{ | |||
fprintf(stderr, "Overflow while trying to generate a QR Code. Bailing."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to other reviewers: these should never occur, except during development
unequalPayload.discriminator = 28; | ||
unequalPayload.setUpPINCode = 121233; | ||
|
||
bool result = payload == unequalPayload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're testing the compiler here?
equalPayload.discriminator = 128; | ||
equalPayload.setUpPINCode = 2048; | ||
|
||
bool result = payload == equalPayload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're testing the compiler?
int testInvalidQRCodePayload() | ||
{ | ||
int surprises = 0; | ||
string invalidString = "adas12AA"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be more interesting to have valid base45 string that's too short, or fails verification (payload.is_valid()?)
This reverts commit cc85d6d.
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
Add BLE MangerImpl ShutDown Function
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…tribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
…mmand and attribute handler for unify bridge Merge in WMN_TOOLS/matter from bugix/no_jira_updating_zap_genarted_files to silabs Squashed commit of the following: commit b704f0b222259f9caf9d21885a1c0e49bb7b6741 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 15:46:53 2022 +0200 fixing data type mapping commit 4e866bea88f3f0af41de2d7eb2a90b0a6428d963 Author: Dereje Wassie <[email protected]> Date: Thu Oct 6 13:51:35 2022 +0200 Updated the zap files for genarting command and attribute handler for unify bridge
Problem
QR code base45 string parser #145
Summary of Changes
Add a new class
QRCodeSetupPayloadParser
that converts abase45
string to aSetupPayload
objectfixes #145