diff options
author | wbond <will@wbond.net> | 2019-09-23 07:15:09 -0400 |
---|---|---|
committer | wbond <will@wbond.net> | 2019-09-23 07:15:09 -0400 |
commit | 2199e11bcb179f679f9880a6aa2047da880efae2 (patch) | |
tree | 85fc705768196a62279ce672703fe4ca5351d6c1 /asn1crypto | |
parent | f855b33b3d64bbf5e1b9e8ae53e54eede1b8bcc7 (diff) | |
download | asn1crypto-2199e11bcb179f679f9880a6aa2047da880efae2.tar.gz |
Fix passing class_ to core.Asn1Value(), add support for passing method
Diffstat (limited to 'asn1crypto')
-rw-r--r-- | asn1crypto/core.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py index a6c0631..0b24312 100644 --- a/asn1crypto/core.py +++ b/asn1crypto/core.py @@ -231,7 +231,7 @@ class Asn1Value(object): return value def __init__(self, explicit=None, implicit=None, no_explicit=False, tag_type=None, class_=None, tag=None, - optional=None, default=None, contents=None): + optional=None, default=None, contents=None, method=None): """ The optional parameter is not used, but rather included so we don't have to delete it from the parameter dictionary when passing as keyword @@ -276,6 +276,12 @@ class Asn1Value(object): :param contents: A byte string of the encoded contents of the value + :param method: + The method for the value - no default value since this is + normally set on a class. Valid values include: + - "primitive" or 0 + - "constructed" or 1 + :raises: ValueError - when implicit, explicit, tag_type, class_ or tag are invalid values """ @@ -385,7 +391,7 @@ class Asn1Value(object): self.implicit = True else: if class_ is not None: - if class_ not in CLASS_NUM_TO_NAME_MAP: + if class_ not in CLASS_NAME_TO_NUM_MAP: raise ValueError(unwrap( ''' class_ must be one of "universal", "application", @@ -395,9 +401,27 @@ class Asn1Value(object): )) self.class_ = CLASS_NAME_TO_NUM_MAP[class_] + if self.class_ is None: + self.class_ = 0 + if tag is not None: self.tag = tag + if method is not None: + if method not in set(["primitive", 0, "constructed", 1]): + raise ValueError(unwrap( + ''' + method must be one of "primitive" or "constructed", + not %s + ''', + repr(method) + )) + if method == "primitive": + method = 0 + elif method == "constructed": + method = 1 + self.method = method + if no_explicit: self.explicit = None |