Skip to content
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

Merged
merged 4 commits into from
Mar 31, 2020
Merged

Base45 to a Set up payload #146

merged 4 commits into from
Mar 31, 2020

Conversation

bhaskar-apple
Copy link
Contributor

Problem

QR code base45 string parser #145

Summary of Changes

Add a new class QRCodeSetupPayloadParser that converts a base45 string to a SetupPayload object

fixes #145

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@gerickson
Copy link
Contributor

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.

@bhaskar-apple
Copy link
Contributor Author

@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.
While the goto paradigm is useful; I think it has its drawbacks and is not applicable everywhere. I would personally refrain from using gotos where possible.

Just as as interesting read, one example of goto failing.
https://www.imperialviolet.org/2014/02/22/applebug.html
Note: not implying goto is the only reason for the failure in this link

@@ -0,0 +1,77 @@
/*
Copy link
Contributor

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 @@
/*
Copy link
Contributor

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.

@woody-apple
Copy link
Contributor

@hawk248 ?

@woody-apple
Copy link
Contributor

@bhaskar-apple can we fix this conflict? @BroderickCarlin or @jelderton can we get one more set of eyes on this? Thanks!

Copy link

@hawk248 hawk248 left a 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.");
Copy link
Contributor

@rwalker-apple rwalker-apple Mar 31, 2020

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;
Copy link
Contributor

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;
Copy link
Contributor

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";
Copy link
Contributor

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()?)

@bhaskar-apple bhaskar-apple merged commit cc85d6d into project-chip:master Mar 31, 2020
woody-apple added a commit that referenced this pull request Mar 31, 2020
mkardous-silabs referenced this pull request in mkardous-silabs/connectedhomeip Oct 24, 2022
…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
mkardous-silabs referenced this pull request in mkardous-silabs/connectedhomeip Dec 14, 2022
…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
jmartinez-silabs referenced this pull request in SiliconLabs/matter Feb 24, 2023
…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
mkardous-silabs referenced this pull request in mkardous-silabs/connectedhomeip May 2, 2023
…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
jmartinez-silabs referenced this pull request in SiliconLabs/matter May 18, 2023
…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
rerasool referenced this pull request in SiliconLabs/matter Jun 23, 2023
…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
shchen-Lab added a commit to shchen-Lab/connectedhomeip that referenced this pull request Aug 23, 2023
jmartinez-silabs referenced this pull request in SiliconLabs/matter Sep 1, 2023
…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
shgutte pushed a commit to shgutte/connectedhomeip that referenced this pull request Oct 5, 2023
…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
jmartinez-silabs referenced this pull request in SiliconLabs/matter Oct 25, 2023
…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
shgutte pushed a commit to shgutte/connectedhomeip that referenced this pull request Jan 11, 2024
…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
jmartinez-silabs referenced this pull request in SiliconLabs/matter Jan 18, 2024
…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
jmartinez-silabs referenced this pull request in SiliconLabs/matter Feb 15, 2024
…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
suveshpratapa pushed a commit to suveshpratapa/connectedhomeip that referenced this pull request May 22, 2024
…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
rcasallas-silabs pushed a commit to rcasallas-silabs/connectedhomeip that referenced this pull request Jun 20, 2024
…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
rcasallas-silabs pushed a commit to rcasallas-silabs/connectedhomeip that referenced this pull request Jun 20, 2024
…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
mykrupp pushed a commit to mykrupp/connectedhomeip that referenced this pull request Jul 18, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QR code base45 string parser
8 participants