summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2020-03-22 16:54:33 +0300
committerSergey Matveev <stargrave@stargrave.org>2020-03-22 17:25:25 +0300
commit498f47100e12f1bef247b29460ac4621fa0fc9f9 (patch)
tree075c0c9249c600e105196a522f5506c350ff6372
parent9f480925ffb629c03c541bfe8846ff918b19f7ef (diff)
downloadpyderasn-498f47100e12f1bef247b29460ac4621fa0fc9f9.tar.xz
Integer.tohex()
-rw-r--r--doc/news.rst1
-rwxr-xr-xpyderasn.py19
2 files changed, 13 insertions, 7 deletions
diff --git a/doc/news.rst b/doc/news.rst
index 4464185..ca8f5a4 100644
--- a/doc/news.rst
+++ b/doc/news.rst
@@ -7,6 +7,7 @@ News
---
* Fix DEFINED BY pprinting when invoking as __main__ module
+* Integer has ``tohex()`` for getting hexadecimal representation of its value
.. _release7.3:
diff --git a/pyderasn.py b/pyderasn.py
index aed2ed1..162c140 100755
--- a/pyderasn.py
+++ b/pyderasn.py
@@ -917,7 +917,7 @@ _______
Integer
_______
.. autoclass:: pyderasn.Integer
- :members: __init__, named
+ :members: __init__, named, tohex
BitString
_________
@@ -2378,13 +2378,8 @@ def pp_console_row(
cols.append(_colourize("(%s)" % oid_name, "green", with_colours))
break
if pp.asn1_type_name == Integer.asn1_type_name:
- hex_repr = hex(int(pp.obj._value))[2:].upper()
- if len(hex_repr) % 2 != 0:
- hex_repr = "0" + hex_repr
cols.append(_colourize(
- "(%s)" % colonize_hex(hex_repr),
- "green",
- with_colours,
+ "(%s)" % colonize_hex(pp.obj.tohex()), "green", with_colours,
))
if with_blob:
if pp.blob.__class__ == binary_type:
@@ -2851,6 +2846,16 @@ class Integer(Obj):
self._assert_ready()
return int(self._value)
+ def tohex(self):
+ """Hexadecimal representation
+
+ Use :py:func:`pyderasn.colonize_hex` for colonizing it.
+ """
+ hex_repr = hex(int(self))[2:].upper()
+ if len(hex_repr) % 2 != 0:
+ hex_repr = "0" + hex_repr
+ return hex_repr
+
def __hash__(self):
self._assert_ready()
return hash(b"".join((