Skip to content

Commit

Permalink
A new load method returning a tuple (an instance of current class and…
Browse files Browse the repository at this point in the history
… byte length)

In case there is a byte pool with many records they need to be extracted
separately. Each record might have variable length depending on data in
it.
  • Loading branch information
Ladislav Andel committed Feb 3, 2020
1 parent c09b87c commit afd05cb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions asn1crypto/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ def load(cls, encoded_data, strict=False, **kwargs):
value, _ = _parse_build(encoded_data, spec=spec, spec_params=kwargs, strict=strict)
return value

@classmethod
def load_p(cls, encoded_data, strict=False, **kwargs):
"""
Loads a BER/DER-encoded byte string using the current class as the spec
:param encoded_data:
A byte string of BER or DER-encoded data
:param strict:
A boolean indicating if trailing data should be forbidden - if so, a
ValueError will be raised when trailing data exists
:return:
An instance of the current class and byte length in tuple
"""

if not isinstance(encoded_data, byte_cls):
raise TypeError('encoded_data must be a byte string, not %s' % type_name(encoded_data))

spec = None
if cls.tag is not None:
spec = cls

value, length = _parse_build(encoded_data, spec=spec, spec_params=kwargs, strict=strict)
return value, length

def __init__(self, explicit=None, implicit=None, no_explicit=False, tag_type=None, class_=None, tag=None,
optional=None, default=None, contents=None, method=None):
"""
Expand Down

0 comments on commit afd05cb

Please sign in to comment.