commit 648d5fd5dcb22ce72a647af07565963c9684e7cc
parent d333e14a63fe5744a31b7cef6ed4119aebe54acd
Author: nolash <dev@holbrook.no>
Date: Thu, 28 Oct 2021 18:55:19 +0200
Padding
Diffstat:
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/hexathon/parse.py b/hexathon/parse.py
@@ -42,14 +42,17 @@ def add_0x(hx, allow_empty=False):
return '0x' + even(hx, allow_empty)
-def unpad(hx):
+def compact(hx):
hx = strip_0x(hx)
i = 0
for i in range(len(hx)):
if hx[i] != '0':
break
- hx = hx[i:]
- return even(hx)
+ return hx[i:]
+
+
+def unpad(hx):
+ return even(compact(hx))
def pad(hx, byte_length):
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = hexathon
-version = 0.0.1a7
+version = 0.0.1a8
description = Common and uncommon hex string operations
author = Louis Holbrook
author_email = dev@holbrook.no
diff --git a/tests/test_basic.py b/tests/test_basic.py
@@ -31,6 +31,13 @@ class HexTest(unittest.TestCase):
self.assertEqual(hexathon.uniform('aBc'), '0abc')
+ def test_unpad(self):
+ self.assertEqual(hexathon.unpad('000abc'), '0abc')
+
+
+ def test_compact(self):
+ self.assertEqual(hexathon.compact('000abc'), 'abc')
+
if __name__ == '__main__':
unittest.main()