]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - pyderasn.py
Separate fast and long testing modes with nose configuration
[pyderasn.git] / pyderasn.py
index ea1b0b926ca295cea669fedaa2ed7d2c279f7f98..21b4306319db9630c936577b5a7d8595afa717d3 100755 (executable)
@@ -666,6 +666,7 @@ from math import ceil
 from os import environ
 from string import ascii_letters
 from string import digits
+from sys import version_info
 from unicodedata import category as unicat
 
 from six import add_metaclass
@@ -690,7 +691,7 @@ except ImportError:  # pragma: no cover
     def colored(what, *args, **kwargs):
         return what
 
-__version__ = "6.2"
+__version__ = "6.3"
 
 __all__ = (
     "Any",
@@ -764,7 +765,7 @@ EOC = b"\x00\x00"
 EOC_LEN = len(EOC)
 LENINDEF = b"\x80"  # length indefinite mark
 LENINDEF_PP_CHAR = "I" if PY2 else "∞"
-NAMEDTUPLE_KWARGS = {} if PY2 else {"module": __name__}
+NAMEDTUPLE_KWARGS = {} if version_info < (3, 6) else {"module": __name__}
 SET01 = frozenset("01")
 DECIMALS = frozenset(digits)
 DECIMAL_SIGNS = ".,"
@@ -5133,7 +5134,7 @@ def get_def_by_path(defines_by_path, sub_decode_path):
         if len(path) != len(sub_decode_path):
             continue
         for p1, p2 in zip(path, sub_decode_path):
-            if (p1 != any) and (p1 != p2):
+            if (not p1 is any) and (p1 != p2):
                 break
         else:
             return define
@@ -5418,19 +5419,17 @@ class Sequence(Obj):
             return spec.default
         return None
 
-    def _encoded_values(self):
-        raws = []
+    def _values_for_encoding(self):
         for name, spec in iteritems(self.specs):
             value = self._value.get(name)
             if value is None:
                 if spec.optional:
                     continue
                 raise ObjNotReady(name)
-            raws.append(value.encode())
-        return raws
+            yield value
 
     def _encode(self):
-        v = b"".join(self._encoded_values())
+        v = b"".join(v.encode() for v in self._values_for_encoding())
         return b"".join((self.tag, len_encode(len(v)), v))
 
     def _decode(self, tlv, offset, decode_path, ctx, tag_only):
@@ -5665,8 +5664,8 @@ class Set(Sequence):
     .. _allow_unordered_set_ctx:
 
     DER prohibits unordered values encoding and will raise an error
-    during decode. If If :ref:`bered <bered_ctx>` context option is set,
-    then no error will occure. Also you can disable strict values
+    during decode. If :ref:`bered <bered_ctx>` context option is set,
+    then no error will occur. Also you can disable strict values
     ordering check by setting ``"allow_unordered_set": True``
     :ref:`context <ctx>` option.
     """
@@ -5675,7 +5674,7 @@ class Set(Sequence):
     asn1_type_name = "SET"
 
     def _encode(self):
-        raws = self._encoded_values()
+        raws = [v.encode() for v in self._values_for_encoding()]
         raws.sort()
         v = b"".join(raws)
         return b"".join((self.tag, len_encode(len(v)), v))
@@ -5816,13 +5815,14 @@ class Set(Sequence):
             tail = v[EOC_LEN:]
             obj.lenindef = True
         obj._value = values
-        if not obj.ready:
-            raise DecodeError(
-                "not all values are ready",
-                klass=self.__class__,
-                decode_path=decode_path,
-                offset=offset,
-            )
+        for name, spec in iteritems(self.specs):
+            if name not in values and not spec.optional:
+                raise DecodeError(
+                    "%s value is not ready" % name,
+                    klass=self.__class__,
+                    decode_path=decode_path,
+                    offset=offset,
+                )
         obj.ber_encoded = ber_encoded
         return obj, tail
 
@@ -6041,11 +6041,11 @@ class SequenceOf(Obj):
     def __getitem__(self, key):
         return self._value[key]
 
-    def _encoded_values(self):
-        return [v.encode() for v in self._value]
+    def _values_for_encoding(self):
+        return iter(self._value)
 
     def _encode(self):
-        v = b"".join(self._encoded_values())
+        v = b"".join(v.encode() for v in self._values_for_encoding())
         return b"".join((self.tag, len_encode(len(v)), v))
 
     def _decode(self, tlv, offset, decode_path, ctx, tag_only, ordering_check=False):
@@ -6208,7 +6208,7 @@ class SetOf(SequenceOf):
     asn1_type_name = "SET OF"
 
     def _encode(self):
-        raws = self._encoded_values()
+        raws = [v.encode() for v in self._values_for_encoding()]
         raws.sort()
         v = b"".join(raws)
         return b"".join((self.tag, len_encode(len(v)), v))