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

Use a much simpler way to generate the colon-separated hex format #28

Merged
merged 1 commit into from
Jan 11, 2020

Conversation

horazont
Copy link
Contributor

@horazont horazont commented Dec 30, 2019

This assumes that ik_pub is a bytes object, otherwise this will go down the drain. Removes the need for re and codecs.

FWIW, using binascii.b2a_hex would be preferred over explicitly invoking codecs I guess.

Example:

>>> import random
>>> noise = random.getrandbits(128).to_bytes(16, "little")
>>> ":".join("{:02x}".format(octet) for octet in noise)
'10:76:1f:19:21:56:15:0e:33:f6:92:bf:ca:b2:ab:19'
>>> import binascii
>>> binascii.b2a_hex(noise)
b'10761f192156150e33f692bfcab2ab19'
>>> import codecs
>>> import re
>>> noise_hex = codecs.getencoder("hex")(noise)[0].decode("US-ASCII").upper()
>>> noise_hex = ":".join(re.findall("..?", noise_hex))
>>> noise_hex
'10:76:1F:19:21:56:15:0E:33:F6:92:BF:CA:B2:AB:19'

Note that this PR introduces lower case format, which I personally find easier to read. To change it to upper case, change the x to a X (or let me know so that I can fix it).

@Syndace
Copy link
Owner

Syndace commented Dec 30, 2019

That's obviously a lot easier and cleaner!

Two things:

  1. I don't care whether it's upper or lower case, but I'd like the output of the code to be consistent with the "wanted format" as defined in the comment above (line 132). Please update either the comment or the x of the format specifier.
  2. As you know I want to switch the license soon(ish). To do so, I need the permission of all contributors. As a future contributor, do you give me the permission to switch the license to MIT?

Thanks!

@horazont
Copy link
Contributor Author

horazont commented Dec 31, 2019

@Syndace This change shall be under CC0.

This allows you to redistribute it with whatever license you like, right now or in the future.

@Syndace Syndace merged commit 12f87d2 into Syndace:master Jan 11, 2020
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.

2 participants