]> Cypherpunks.ru repositories - pyderasn.git/commitdiff
Autodecode BitStrings too
authorSergey Matveev <stargrave@stargrave.org>
Sat, 30 Dec 2017 17:01:33 +0000 (20:01 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Dec 2017 17:45:31 +0000 (20:45 +0300)
pyderasn.py

index f2ef0d79b62836fb13b18c837f93936f47439085..acf0e469260588a921f20d5493546a86955e2a2b 100755 (executable)
@@ -251,6 +251,7 @@ done.
 Following types can be automatically decoded (DEFINED BY):
 
 * :py:class:`pyderasn.Any`
+* :py:class:`pyderasn.BitString` (that is multiple of 8 bits)
 * :py:class:`pyderasn.OctetString`
 * :py:class:`pyderasn.SequenceOf`/:py:class:`pyderasn.SetOf`
   ``Any``/``OctetString``-s
@@ -1681,7 +1682,7 @@ class BitString(Obj):
     >>> b.specs
     {'nonRepudiation': 1, 'digitalSignature': 0, 'keyEncipherment': 2}
     """
-    __slots__ = ("specs",)
+    __slots__ = ("specs", "defined")
     tag_default = tag_encode(3)
     asn1_type_name = "BIT STRING"
 
@@ -1718,6 +1719,7 @@ class BitString(Obj):
             )
             if value is None:
                 self._value = default
+        self.defined = None
 
     def _bits2octets(self, bits):
         if len(self.specs) > 0:
@@ -1966,6 +1968,11 @@ class BitString(Obj):
             expl_llen=self.expl_llen if self.expled else None,
             expl_vlen=self.expl_vlen if self.expled else None,
         )
+        defined_by, defined = self.defined or (None, None)
+        if defined_by is not None:
+            yield defined.pps(
+                decode_path=decode_path + (decode_path_defby(defined_by),)
+            )
 
 
 class OctetString(Obj):