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).
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.
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?
This assumes that
ik_pub
is abytes
object, otherwise this will go down the drain. Removes the need forre
andcodecs
.FWIW, using
binascii.b2a_hex
would be preferred over explicitly invokingcodecs
I guess.Example:
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 aX
(or let me know so that I can fix it).