Commit cbb992b2 authored by Julien Muchembled's avatar Julien Muchembled

neo.lib.util: bin & dump roughly do the same thing as a2b_hex & b2a_hex from binascii

parent f4220e19
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import re import re
import socket import socket
from binascii import a2b_hex, b2a_hex
from hashlib import sha1 from hashlib import sha1
from Queue import deque from Queue import deque
from struct import pack, unpack from struct import pack, unpack
...@@ -39,26 +40,15 @@ def add64(packed, offset): ...@@ -39,26 +40,15 @@ def add64(packed, offset):
def dump(s): def dump(s):
"""Dump a binary string in hex.""" """Dump a binary string in hex."""
if s is None: if s is not None:
return None
if isinstance(s, str): if isinstance(s, str):
ret = [] return b2a_hex(s)
for c in s:
ret.append('%02x' % ord(c))
return ''.join(ret)
else:
return repr(s) return repr(s)
def bin(s): def bin(s):
"""Inverse of dump method.""" """Inverse of dump method."""
if s is None: if s is not None:
return None return a2b_hex(s)
ret = []
while len(s):
ret.append(chr(int(s[:2], 16)))
s = s[2:]
return ''.join(ret)
def makeChecksum(s): def makeChecksum(s):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment