When object is decoded, ``decoded`` property is true and you can safely
use following properties:
-* ``offset`` -- position from initial offset where object's tag is started
+* ``offset`` -- position including initial offset where object's tag starts
* ``tlen`` -- length of object's tag
* ``llen`` -- length of object's length value
* ``vlen`` -- length of object's value
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(
def decoded(self):
"""Is object decoded?
"""
- return self.llen > 0
+ return (self.llen + self.vlen) > 0
def copy(self): # pragma: no cover
"""Make a copy of object, safe to be mutated
def __str__(self): # pragma: no cover
return self.__bytes__() if PY2 else self.__unicode__()
+ def __ne__(self, their):
+ return not(self == their)
+
+ def __gt__(self, their): # pragma: no cover
+ return not(self < their)
+
+ def __le__(self, their): # pragma: no cover
+ return (self == their) or (self < their)
+
+ def __ge__(self, their): # pragma: no cover
+ return (self == their) or (self > their)
+
def _encode(self): # pragma: no cover
raise NotImplementedError()
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:
)
def __lt__(self, their):
- return self._value < their
-
- def __gt__(self, their):
- return self._value > their
+ return self._value < their._value
@property
def named(self):
def copy(self):
obj = self.__class__(_specs=self.specs)
- obj._value = self._value
+ value = self._value
+ if value is not None:
+ value = (value[0], value[1])
+ obj._value = value
obj.tag = self.tag
obj._expl = self._expl
obj.default = self.default
_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:
self._expl == their._expl
)
+ def __lt__(self, their):
+ return self._value < their._value
+
def __call__(
self,
value=None,
)
def __lt__(self, their):
- return self._value < their
-
- def __gt__(self, their):
- return self._value > their
+ return self._value < their._value
def __call__(
self,
asn1_type_name = "IA5"
+LEN_YYMMDDHHMMSSZ = len("YYMMDDHHMMSSZ")
+LEN_YYYYMMDDHHMMSSDMZ = len("YYYYMMDDHHMMSSDMZ")
+LEN_YYYYMMDDHHMMSSZ = len("YYYYMMDDHHMMSSZ")
+
+
class UTCTime(CommonString):
"""``UTCTime`` datetime type
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:
).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:
"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:
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)
You have to make specification of sequence::
class Extension(Sequence):
- __slots__ = ()
schema = (
("extnID", ObjectIdentifier()),
("critical", Boolean(default=False)),
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)