diff options
author | Will Bond <will@wbond.net> | 2020-07-25 10:24:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-25 10:24:06 -0400 |
commit | e440dc4190cfa9567e40f546ce2dd6bc8303101a (patch) | |
tree | 638bc669ca9d18d057c7f7af39247aa469a16497 /asn1crypto | |
parent | 42644de9362dd5c48d5c454febf04cf09b3fcaac (diff) | |
parent | 8fa8792edd5f6eb29e5b766350ef333543e000d1 (diff) | |
download | asn1crypto-e440dc4190cfa9567e40f546ce2dd6bc8303101a.tar.gz |
Merge pull request #174 from joernheissler/oid-arc-2
Fix parsing of ObjectIdentifier's first octet.
Diffstat (limited to 'asn1crypto')
-rw-r--r-- | asn1crypto/core.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py index 933f8ca..2b79d11 100644 --- a/asn1crypto/core.py +++ b/asn1crypto/core.py @@ -3104,6 +3104,10 @@ class ObjectIdentifier(Primitive, ValueMap): first = part continue elif index == 1: + if first > 2: + raise ValueError("First arc is restricted to 0,1,2") + elif first < 2 and part >= 40: + raise ValueError("Second arc is restricted to 0..39 if first arc is 0 or 1") part = (first * 40) + part encoded_part = chr_cls(0x7F & part) @@ -3145,8 +3149,15 @@ class ObjectIdentifier(Primitive, ValueMap): # Last byte in subidentifier has the eighth bit set to 0 if byte & 0x80 == 0: if len(output) == 0: - output.append(str_cls(part // 40)) - output.append(str_cls(part % 40)) + if part >= 80: + output.append(str_cls(2)) + output.append(str_cls(part - 80)) + elif part >= 40: + output.append(str_cls(1)) + output.append(str_cls(part - 40)) + else: + output.append(str_cls(0)) + output.append(str_cls(part)) else: output.append(str_cls(part)) part = 0 |