Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new load method returning a tuple (an instance of current class and byte length) #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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