X-Git-Url: http://www.git.cypherpunks.ru/?p=pyderasn.git;a=blobdiff_plain;f=pyderasn.py;h=8e7f0283503e0272f19a28e2f17805ad212299fa;hp=d14997bfe24d4569f7732bf238e812263aa92f89;hb=fa45509b038326f83ca441d0ad294acfef33f1eb;hpb=3d77f13bff0bb7b47384a748f3bf080d59dd22da diff --git a/pyderasn.py b/pyderasn.py index d14997b..8e7f028 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -688,10 +688,7 @@ class Obj(object): optional=False, _decoded=(0, 0, 0), ): - if impl is None: - self.tag = getattr(self, "impl", self.tag_default) - else: - self.tag = impl + self.tag = getattr(self, "impl", self.tag_default) if impl is None else impl self._expl = getattr(self, "expl", None) if expl is None else expl if self.tag != self.tag_default and self._expl is not None: raise ValueError( @@ -1261,14 +1258,11 @@ class Integer(Obj): self._value = value specs = getattr(self, "schema", {}) if _specs is None else _specs self.specs = specs if isinstance(specs, dict) else dict(specs) - if bounds is None: - self._bound_min, self._bound_max = getattr( - self, - "bounds", - (float("-inf"), float("+inf")), - ) - else: - self._bound_min, self._bound_max = bounds + self._bound_min, self._bound_max = getattr( + self, + "bounds", + (float("-inf"), float("+inf")), + ) if bounds is None else bounds if value is not None: self._value = self._value_sanitize(value) if default is not None: @@ -1894,14 +1888,11 @@ class OctetString(Obj): _decoded, ) self._value = value - if bounds is None: - self._bound_min, self._bound_max = getattr( - self, - "bounds", - (0, float("+inf")), - ) - else: - self._bound_min, self._bound_max = bounds + self._bound_min, self._bound_max = getattr( + self, + "bounds", + (0, float("+inf")), + ) if bounds is None else bounds if value is not None: self._value = self._value_sanitize(value) if default is not None: @@ -2730,6 +2721,11 @@ class IA5String(CommonString): asn1_type_name = "IA5" +LEN_YYMMDDHHMMSSZ = len("YYMMDDHHMMSSZ") +LEN_YYYYMMDDHHMMSSDMZ = len("YYYYMMDDHHMMSSDMZ") +LEN_YYYYMMDDHHMMSSZ = len("YYYYMMDDHHMMSSZ") + + class UTCTime(CommonString): """``UTCTime`` datetime type @@ -2796,7 +2792,7 @@ class UTCTime(CommonString): return value.strftime(self.fmt).encode("ascii") if isinstance(value, binary_type): value_decoded = value.decode("ascii") - if len(value_decoded) == 2 + 2 + 2 + 2 + 2 + 2 + 1: + if len(value_decoded) == LEN_YYMMDDHHMMSSZ: try: datetime.strptime(value_decoded, self.fmt) except ValueError: @@ -2887,7 +2883,7 @@ class GeneralizedTime(UTCTime): ).encode("ascii") if isinstance(value, binary_type): value_decoded = value.decode("ascii") - if len(value_decoded) == 4 + 2 + 2 + 2 + 2 + 2 + 1: + if len(value_decoded) == LEN_YYYYMMDDHHMMSSZ: try: datetime.strptime(value_decoded, self.fmt) except ValueError: @@ -2895,7 +2891,7 @@ class GeneralizedTime(UTCTime): "invalid GeneralizedTime (without ms) format", ) return value - elif len(value_decoded) >= 4 + 2 + 2 + 2 + 2 + 2 + 1 + 1 + 1: + elif len(value_decoded) >= LEN_YYYYMMDDHHMMSSDMZ: try: datetime.strptime(value_decoded, self.fmt_ms) except ValueError: @@ -2912,7 +2908,7 @@ class GeneralizedTime(UTCTime): def todatetime(self): value = self._value.decode("ascii") - if len(value) == 4 + 2 + 2 + 2 + 2 + 2 + 1: + if len(value) == LEN_YYYYMMDDHHMMSSZ: return datetime.strptime(value, self.fmt) return datetime.strptime(value, self.fmt_ms) @@ -3363,7 +3359,6 @@ class Sequence(Obj): You have to make specification of sequence:: class Extension(Sequence): - __slots__ = () schema = ( ("extnID", ObjectIdentifier()), ("critical", Boolean(default=False)), @@ -3824,14 +3819,11 @@ class SequenceOf(Obj): if schema is None: raise ValueError("schema must be specified") self.spec = schema - if bounds is None: - self._bound_min, self._bound_max = getattr( - self, - "bounds", - (0, float("+inf")), - ) - else: - self._bound_min, self._bound_max = bounds + self._bound_min, self._bound_max = getattr( + self, + "bounds", + (0, float("+inf")), + ) if bounds is None else bounds self._value = [] if value is not None: self._value = self._value_sanitize(value)