diff options
author | wbond <will@wbond.net> | 2020-07-25 10:43:31 -0400 |
---|---|---|
committer | wbond <will@wbond.net> | 2020-07-25 10:43:31 -0400 |
commit | 704889494451461ffdb75d192c2a2db1258660db (patch) | |
tree | d7225fec15ffcbed31aead987c180cda107c04b4 | |
parent | e440dc4190cfa9567e40f546ce2dd6bc8303101a (diff) | |
download | asn1crypto-704889494451461ffdb75d192c2a2db1258660db.tar.gz |
Tweak error messages on invalid OIDs
-rw-r--r-- | asn1crypto/core.py | 15 | ||||
-rw-r--r-- | tests/test_core.py | 6 |
2 files changed, 16 insertions, 5 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py index 2b79d11..7133367 100644 --- a/asn1crypto/core.py +++ b/asn1crypto/core.py @@ -3105,9 +3105,20 @@ class ObjectIdentifier(Primitive, ValueMap): continue elif index == 1: if first > 2: - raise ValueError("First arc is restricted to 0,1,2") + raise ValueError(unwrap( + ''' + First arc must be one of 0, 1 or 2, not %s + ''', + repr(first) + )) elif first < 2 and part >= 40: - raise ValueError("Second arc is restricted to 0..39 if first arc is 0 or 1") + raise ValueError(unwrap( + ''' + Second arc must be less than 40 if first arc is 0 or + 1, not %s + ''', + repr(part) + )) part = (first * 40) + part encoded_part = chr_cls(0x7F & part) diff --git a/tests/test_core.py b/tests/test_core.py index c339ae5..9821c63 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1355,11 +1355,11 @@ class CoreTests(unittest.TestCase): self.assertEqual(native, core.ObjectIdentifier.load(der_bytes).native) def test_broken_object_identifier(self): - with self.assertRaisesRegex(ValueError, "First arc is restricted"): + with self.assertRaisesRegex(ValueError, "First arc must be "): core.ObjectIdentifier("3.4.5") - with self.assertRaisesRegex(ValueError, "Second arc is restricted"): + with self.assertRaisesRegex(ValueError, "Second arc must be "): core.ObjectIdentifier("1.100.1000") - with self.assertRaisesRegex(ValueError, "Second arc is restricted"): + with self.assertRaisesRegex(ValueError, "Second arc must be "): core.ObjectIdentifier("0.40") |