3434tagCategoryUntagged = 0x04
3535
3636
37+ def _tagIdToStr (tagId ):
38+ # Decimal rendering of a huge tag ID can exceed the interpreter's
39+ # integer-to-string conversion limit (sys.get_int_max_str_digits(),
40+ # Python 3.11+) and raise ValueError; hexadecimal is not limited
41+ try :
42+ return str (tagId )
43+ except ValueError :
44+ return hex (tagId )
45+
46+
3747class Tag (object ):
3848 """Create ASN.1 tag
3949
@@ -56,7 +66,8 @@ class Tag(object):
5666 """
5767 def __init__ (self , tagClass , tagFormat , tagId ):
5868 if tagId < 0 :
59- raise error .PyAsn1Error ('Negative tag ID (%s) not allowed' % tagId )
69+ raise error .PyAsn1Error (
70+ 'Negative tag ID (%s) not allowed' % _tagIdToStr (tagId ))
6071 self .__tagClass = tagClass
6172 self .__tagFormat = tagFormat
6273 self .__tagId = tagId
@@ -65,7 +76,7 @@ def __init__(self, tagClass, tagFormat, tagId):
6576
6677 def __repr__ (self ):
6778 representation = '[%s:%s:%s]' % (
68- self .__tagClass , self .__tagFormat , self .__tagId )
79+ self .__tagClass , self .__tagFormat , _tagIdToStr ( self .__tagId ) )
6980 return '<%s object, tag %s>' % (
7081 self .__class__ .__name__ , representation )
7182
@@ -194,8 +205,9 @@ def __init__(self, baseTag=(), *superTags):
194205 self .__hash = hash (self .__superTagsClassId )
195206
196207 def __repr__ (self ):
197- representation = '-' .join (['%s:%s:%s' % (x .tagClass , x .tagFormat , x .tagId )
198- for x in self .__superTags ])
208+ representation = '-' .join (
209+ ['%s:%s:%s' % (x .tagClass , x .tagFormat , _tagIdToStr (x .tagId ))
210+ for x in self .__superTags ])
199211 if representation :
200212 representation = 'tags ' + representation
201213 else :
0 commit comments