Skip to content
This repository has been archived by the owner on Sep 5, 2018. It is now read-only.

Fix byte2int for array multiple indices #9

Closed
wants to merge 1 commit into from

Conversation

u1735067
Copy link

# py -3
>>> t
b'test'
>>> t[0]
116
>>> t[0:1]
b't'
>>> byte2int(t[0:1])
b't'

-> byte2int isn't working when extracting from "array" using 2 indices.
So let's simply check if it's already an int or not.

```
>>> t
b'test'
>>> t[0]
116
>>> t[0:1]
b't'
>>> byte2int(t[0:1])
b't'
```
@dahu33
Copy link

dahu33 commented Jun 13, 2017

+1 can someone review/merge this one?

@dahu33 dahu33 mentioned this pull request Jun 13, 2017
@dainnilsson
Copy link
Member

I don't really think this is a bug, it seems to me that the function does as it is named, IE it takes a single byte, and returns an int. What would be the point of using it with multiple indexes, if the only valid "second index" is the first index + 1? I'd rather consider the byte2int(x[i:i+1]) usage to be invalid (so the bug is rather in how python-u2flib-host calls the function). Does that make sense? Have I overlooked anything?

@u1735067
Copy link
Author

IE it takes a single byte, and returns an int

>>> t[0:1]
b't'
>>> byte2int(t[0:1])
b't'

Nop (but with Yubico/python-u2flib-host@bdeac17 I agree it should not cause trouble anymore)

@dainnilsson
Copy link
Member

By "takes a single byte" I mean "what you get when you index a value in a "bytes" object". When you slice a "bytes", you get a new "bytes", even if the length happens to be 1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants