from datetime import datetime
from math import ceil
from os import environ
+from string import ascii_letters
from string import digits
from six import add_metaclass
try:
from termcolor import colored
-except ImportError:
+except ImportError: # pragma: no cover
def colored(what, *args):
return what
ctx=ctx,
tag_only=tag_only,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
obj, tail = result
eoc_expected, tail = tail[:EOC_LEN], tail[EOC_LEN:]
ctx=ctx,
tag_only=tag_only,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
obj, tail = result
if obj.tlvlen < l and not ctx.get("allow_expl_oob", False):
offset=offset,
)
if t == self.tag:
- if tag_only:
+ if tag_only: # pragma: no cover
return
return self._decode_chunk(lv, offset, decode_path, ctx)
if t == self.tag_constructed:
decode_path=decode_path,
offset=offset,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
lenindef = False
try:
decode_path=decode_path,
offset=offset,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
try:
l, _, v = len_decode(lv)
decode_path=decode_path,
offset=offset,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
try:
l, llen, v = len_decode(lv)
class NumericString(CommonString):
"""Numeric string
- Its value is properly sanitized: only ASCII digits can be stored.
+ Its value is properly sanitized: only ASCII digits with spaces can
+ be stored.
"""
__slots__ = ()
tag_default = tag_encode(18)
encoding = "ascii"
asn1_type_name = "NumericString"
- allowable_chars = set(digits.encode("ascii"))
+ allowable_chars = set(digits.encode("ascii") + b" ")
def _value_sanitize(self, value):
value = super(NumericString, self)._value_sanitize(value)
class PrintableString(CommonString):
+ """Printable string
+
+ Its value is properly sanitized: see X.680 41.4 table 10.
+ """
__slots__ = ()
tag_default = tag_encode(19)
encoding = "ascii"
asn1_type_name = "PrintableString"
+ allowable_chars = set((ascii_letters + digits + " '()+,-./:=?").encode("ascii"))
+
+ def _value_sanitize(self, value):
+ value = super(PrintableString, self)._value_sanitize(value)
+ if not set(value) <= self.allowable_chars:
+ raise DecodeError("non-printable value")
+ return value
class TeletexString(CommonString):
decode_path=decode_path,
offset=offset,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
value, tail = spec.decode(
tlv,
decode_path=decode_path,
offset=offset,
)
- if tag_only:
+ if tag_only: # pragma: no cover
return
lenindef = False
ctx_bered = ctx.get("bered", False)