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

Orderd Dictionary/Map #77

Closed
vuln3r opened this issue Dec 23, 2021 · 7 comments
Closed

Orderd Dictionary/Map #77

vuln3r opened this issue Dec 23, 2021 · 7 comments

Comments

@vuln3r
Copy link

vuln3r commented Dec 23, 2021

Hi Folks,

is there any way to get the ordered map back?

return CBOR.map([ 1: "key1", 2: "key2", 3: "key3", 4: "key4", ])

after this, I'm getting a random map each time and need to get ith sorted somehow.

Could you please help me with this?

@vuln3r vuln3r changed the title Orderd Dictionary Orderd Dictionary/Map Dec 23, 2021
@hamchapman
Copy link
Collaborator

hamchapman commented Dec 23, 2021

Did you intentionally list repeated key-value pairs? Ah, I see you updated the example!

Or are you asking about whether or not you can get SwiftCBOR to produce what the (most recent) CBOR RFC defines as "Deterministic Encoding"?

@hamchapman
Copy link
Collaborator

Even if we implemented something like the code in #50 you wouldn't necessarily get back a map ordered in the same way as the map was ordered when inserted it, because dictionaries in Swift aren't ordered (but you would get back something deterministic if we merged something like #50). You can write what looks like an ordered map/dictionary but in reality it's not actually ordered. I know Swift know has some extra packages where you can get things like OrderedDictionary but I haven't tested how encoding works with them.

Understanding more about what you're trying to achieve and why would help, if possible.

@vuln3r
Copy link
Author

vuln3r commented Dec 23, 2021

Yes, my problem is that I need CBOR Map to be exactly as I define it in my example above because I'm using it for the decryption, and if the keys are not in the same position like I did define them then my decryption doesn't work :(

I would say it is more in the way of OrderedDictionary

@vuln3r
Copy link
Author

vuln3r commented Dec 23, 2021

But it could help, because my keys are always Int and if I read it correctly it needs to be sorted from 0 to ++

@vuln3r
Copy link
Author

vuln3r commented Jan 3, 2022

hi @hamchapman do you have any idea how I could solve it? I tried with #50 but it solves my problem partially because I have a map and inside a map another map and so.

@vuln3r
Copy link
Author

vuln3r commented Jan 4, 2022

I've solved it :) it was #50 ... thnx

@vuln3r vuln3r closed this as completed Jan 4, 2022
@phisakel
Copy link

You can use my pull request PR 96

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

No branches or pull requests

3 participants