]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
EOC pprinting 3.8
authorSergey Matveev <stargrave@stargrave.org>
Sat, 26 May 2018 14:08:13 +0000 (17:08 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 26 May 2018 14:20:12 +0000 (17:20 +0300)
VERSION
doc/examples.rst
doc/news.rst
pyderasn.py

diff --git a/VERSION b/VERSION
index 475ba515c04b5b7cf67a1517430691febc39a32e..cc1923a40b1a5e8c7fbdb8f9f6c6bbe26c35604b 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.7
+3.8
index 1d836f53549a33e3900766cea81a3dcd238c6381..e9387a21b9868601eef1b1f1047211dd5b972429 100644 (file)
@@ -236,7 +236,7 @@ Let's parse that output, human::
 
 ::
 
-       52-2 [1,1,1054]-4  . . . . eContent: [0] EXPLICIT BER OCTET STRING 1046 bytes
+       52-2I [1,1,1054]I  . . . . eContent: [0] EXPLICIT BER OCTET STRING 1046 bytes
                        ^                                 ^   ^            ^
                       12                                13   9            10
 
@@ -272,18 +272,12 @@ Let's parse that output, human::
  Possible other flags like OPTIONAL and DEFAULT, if value equals to the
  default one, specified in the schema.
 :12:
- Only applicable to BER encoded data. If object has indefinite length
- encoding, then subtract 2 bytes EOC from its length. If object has
- explicit tag with indefinite length, then subtract another EOC bytes.
- In example above, ``eContent`` field has both indefinite field encoding
- and indefinite length explicit tag. ``BIT STRING``, ``OCTET STRING``
- (and its derivatives), ``SEQUENCE``, ``SET``, ``SEQUENCE OF``, ``SET
- OF``, ``ANY`` could have indefinite length coding.
+ Only applicable to BER encoded data. Indefinite length encoding mark.
 :13:
  Only applicable to BER encoded data. If object has BER-specific
  encoding, then ``BER`` will be shown. It does not depend on indefinite
- length encoding. ``BOOLEAN``, ``BIT STRING``, ``OCTET STRING`` (and its
- derivatives) could be BERed.
+ length encoding. ``EOC``, ``BOOLEAN``, ``BIT STRING``, ``OCTET STRING``
(and its derivatives) could be BERed.
 
 As command line utility
 -----------------------
index b66d171e0c25723b2e115a311a91d8b0b6910bc1..a05a0e4511ae493fc2467ef6bcf2fd7e6a0a92a7 100644 (file)
@@ -1,6 +1,21 @@
 News
 ====
 
+.. _release3.8:
+
+3.8
+---
+BER's EOC is explicitly shown during pprinting. Following notation::
+
+      15-2 [0,0,1576]-4  . content: [0] EXPLICIT [UNIV 16] ANY
+
+is replaced with::
+
+      15-2∞ [0,0,1576]∞  . content: [0] EXPLICIT [UNIV 16] ANY
+    [...]
+    1587    [1,1,   0]   . content:  BER EOC
+    1589    [1,1,   0]   . content: EXPLICIT BER EOC
+
 .. _release3.7:
 
 3.7
index b668507f3a46f9cccdf8d1cfbe3f97ae1cde9826..5c40361e310310b61d1402ddba04901ccd5aeed5 100755 (executable)
@@ -604,6 +604,7 @@ TagClassReprs = {
 EOC = b"\x00\x00"
 EOC_LEN = len(EOC)
 LENINDEF = b"\x80"  # length indefinite mark
+LENINDEF_PP_CHAR = "∞"
 
 
 ########################################################################
@@ -1117,6 +1118,33 @@ class Obj(object):
     def expl_tlvlen(self):
         return self.expl_tlen + self.expl_llen + self.expl_vlen
 
+    def pps_lenindef(self, decode_path):
+        if self.lenindef:
+            yield _pp(
+                asn1_type_name="EOC",
+                obj_name="",
+                decode_path=decode_path,
+                offset=(
+                    self.offset + self.tlvlen -
+                    (EOC_LEN * 2 if self.expl_lenindef else EOC_LEN)
+                ),
+                tlen=1,
+                llen=1,
+                vlen=0,
+                bered=True,
+            )
+        if self.expl_lenindef:
+            yield _pp(
+                asn1_type_name="EOC",
+                obj_name="EXPLICIT",
+                decode_path=decode_path,
+                offset=self.expl_offset + self.expl_tlvlen - EOC_LEN,
+                tlen=1,
+                llen=1,
+                vlen=0,
+                bered=True,
+            )
+
 
 class DecodePathDefBy(object):
     """DEFINED BY representation inside decode path
@@ -1228,25 +1256,22 @@ def pp_console_row(
 ):
     cols = []
     if with_offsets:
-        col = "%5d%s" % (
+        col = "%5d%s%s" % (
             pp.offset,
             (
                 "  " if pp.expl_offset is None else
                 ("-%d" % (pp.offset - pp.expl_offset))
             ),
+            LENINDEF_PP_CHAR if pp.expl_lenindef else " ",
         )
         cols.append(_colorize(col, "red", with_colours, ()))
-        col = "[%d,%d,%4d]" % (pp.tlen, pp.llen, pp.vlen)
-        col = _colorize(col, "green", with_colours, ())
-        ber_deoffset = 0
-        if pp.expl_lenindef:
-            ber_deoffset += 2
-        if pp.lenindef:
-            ber_deoffset += 2
-        col += (
-            "  " if ber_deoffset == 0 else
-            _colorize(("-%d" % ber_deoffset), "red", with_colours)
+        col = "[%d,%d,%4d]%s" % (
+            pp.tlen,
+            pp.llen,
+            pp.vlen,
+            LENINDEF_PP_CHAR if pp.lenindef else " "
         )
+        col = _colorize(col, "green", with_colours, ())
         cols.append(col)
     if len(pp.decode_path) > 0:
         cols.append(" ." * (len(pp.decode_path)))
@@ -1300,7 +1325,7 @@ def pp_console_row(
 
 
 def pp_console_blob(pp):
-    cols = [" " * len("XXXXXYY [X,X,XXXX]YY")]
+    cols = [" " * len("XXXXXYYZ [X,X,XXXX]Z")]
     if len(pp.decode_path) > 0:
         cols.append(" ." * (len(pp.decode_path) + 1))
     if isinstance(pp.blob, binary_type):
@@ -1558,6 +1583,8 @@ class Boolean(Obj):
             expl_lenindef=self.expl_lenindef,
             bered=self.bered,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class Integer(Obj):
@@ -1881,6 +1908,8 @@ class Integer(Obj):
             expl_vlen=self.expl_vlen if self.expled else None,
             expl_lenindef=self.expl_lenindef,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class BitString(Obj):
@@ -2347,6 +2376,8 @@ class BitString(Obj):
             yield defined.pps(
                 decode_path=decode_path + (DecodePathDefBy(defined_by),)
             )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class OctetString(Obj):
@@ -2694,6 +2725,8 @@ class OctetString(Obj):
             yield defined.pps(
                 decode_path=decode_path + (DecodePathDefBy(defined_by),)
             )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class Null(Obj):
@@ -2826,6 +2859,8 @@ class Null(Obj):
             expl_vlen=self.expl_vlen if self.expled else None,
             expl_lenindef=self.expl_lenindef,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class ObjectIdentifier(Obj):
@@ -3115,6 +3150,8 @@ class ObjectIdentifier(Obj):
             expl_vlen=self.expl_vlen if self.expled else None,
             expl_lenindef=self.expl_lenindef,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class Enumerated(Integer):
@@ -3338,6 +3375,8 @@ class CommonString(OctetString):
             expl_vlen=self.expl_vlen if self.expled else None,
             expl_lenindef=self.expl_lenindef,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class UTF8String(CommonString):
@@ -3535,6 +3574,8 @@ class UTCTime(CommonString):
             expl_vlen=self.expl_vlen if self.expled else None,
             expl_lenindef=self.expl_lenindef,
         )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class GeneralizedTime(UTCTime):
@@ -3869,6 +3910,8 @@ class Choice(Obj):
         )
         if self.ready:
             yield self.value.pps(decode_path=decode_path + (self.choice,))
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class PrimitiveTypes(Choice):
@@ -4092,6 +4135,8 @@ class Any(Obj):
             yield defined.pps(
                 decode_path=decode_path + (DecodePathDefBy(defined_by),)
             )
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 ########################################################################
@@ -4578,6 +4623,8 @@ class Sequence(Obj):
             if value is None:
                 continue
             yield value.pps(decode_path=decode_path + (name,))
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class Set(Sequence):
@@ -5007,6 +5054,8 @@ class SequenceOf(Obj):
         )
         for i, value in enumerate(self._value):
             yield value.pps(decode_path=decode_path + (str(i),))
+        for pp in self.pps_lenindef(decode_path):
+            yield pp
 
 
 class SetOf(SequenceOf):