Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Strict ordering for DAG-CBOR-encoded map keys #493

Merged
merged 4 commits into from
Feb 1, 2022

Conversation

cdata
Copy link
Contributor

@cdata cdata commented Jan 26, 2022

This change proposes a fix for #492 . Ipld::Map keys are sorted according to the strictness guidelines in the DAG-CBOR spec when encoding them as DAG-CBOR.

@cdata cdata marked this pull request as ready for review January 26, 2022 07:19
@koivunej
Copy link
Collaborator

koivunej commented Jan 31, 2022

Thanks for reporting and offering a fix for this. The build is currently broken, will try to get to fixing that in near future.

I'm thinking the eventual solution is to have a newtype and comparator with expected PartialOrd implementation.. Do I understand this correctly, that String or Vec or [T] would sort correctly except that it doesn't consider the length as the first sort?

@koivunej
Copy link
Collaborator

Maybe it's because of RFC 8949 includes the sorting on the cbor serialized keys which start with the length information. Now it makes sense.

@cdata could you rebase this on top of master? The build was broken but now it should work.

@cdata
Copy link
Contributor Author

cdata commented Jan 31, 2022

Thanks for reporting and offering a fix for this. The build is currently broken, will try to get to fixing that in near future.

I'm thinking the eventual solution is to have a newtype and comparator with expected PartialOrd implementation.. Do I understand this correctly, that String or Vec or [T] would sort correctly except that it doesn't consider the length as the first sort?

Yes, I believe that analysis of the problem is correct.

The change has been rebased onto the latest master version.

src/ipld/dag_cbor.rs Outdated Show resolved Hide resolved
src/ipld/dag_cbor.rs Outdated Show resolved Hide resolved
src/ipld/dag_cbor.rs Outdated Show resolved Hide resolved
cdata and others added 2 commits January 31, 2022 14:50
Co-authored-by: Joonas Koivunen <[email protected]>
Co-authored-by: Joonas Koivunen <[email protected]>
@koivunej
Copy link
Collaborator

koivunej commented Feb 1, 2022

Thank you for the fix!

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 1, 2022

Build succeeded:

@bors bors bot merged commit 3eff4e1 into rs-ipfs:master Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants