Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Various exceptions/errors.
"""
class Error(Exception):
"""Base exception of all asn1tools exceptions.
"""
class CompileError(Error):
"""General ASN.1 compile error.
"""
class EncodeError(Error):
"""General ASN.1 encode error.
"""
class DecodeError(Error):
"""General ASN.1 decode error.
"""
def get_member_checker(self, checker, name):
for member in checker.members:
if member.name == name:
return member
raise Error('No member checker found for {}.'.format(name))
def error(self, message):
return Error('{}: {}'.format(self.location_error(), message))
def error(self, message):
return Error('{}: {}'.format(self.location_error(), message))
def restricted_utc_time_to_datetime(string):
"""Convert given restricted ASN.1 UTC time string `string` to a
``datetime.datetime`` object.
"""
try:
if string[-1] != 'Z':
raise ValueError
if len(string) != 13:
raise ValueError
return datetime.strptime(string[:-1], '%y%m%d%H%M%S')
except (ValueError, IndexError):
raise Error(
"Expected a restricted UTC time string, but got '{}'.".format(
string))
from pyparsing import NotAny
from pyparsing import NoMatch
from pyparsing import QuotedString
from pyparsing import Combine
from pyparsing import ParseResults
from pyparsing import lineno
from .errors import Error
LOGGER = logging.getLogger(__name__)
EXTENSION_MARKER = None
class ParseError(Error):
pass
class InternalParserError(Error):
pass
class Tokens(object):
def __init__(self, tag, tokens):
self.tag = tag
self.tokens = tokens
def __getitem__(self, index):
return self.tokens[index]
def get_member_checker(self, checker, name):
for member in checker.members:
if member.name == name:
return member
raise Error('No member checker found for {}.'.format(name))