Skip to content

Commit

Permalink
Fix agronholm#114: Raise TypeError when using a negative tag
Browse files Browse the repository at this point in the history
TODO: Fix c-module
  • Loading branch information
Sekenre committed Jun 24, 2021
1 parent 9f30439 commit fc78572
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cbor2/types.py
Expand Up @@ -44,8 +44,8 @@ class CBORTag:
__slots__ = 'tag', 'value'

def __init__(self, tag, value):
if not isinstance(tag, int):
raise TypeError('CBORTag tags must be integer numbers')
if not isinstance(tag, int) or tag not in range(2**64):
raise TypeError('CBORTag tags must be positive integers less than 2**64')
self.tag = tag
self.value = value

Expand Down
5 changes: 5 additions & 0 deletions tests/test_encoder.py
Expand Up @@ -520,3 +520,8 @@ def test_encode_stringrefs_dict(impl):
'd81901' 'd81900'
)
assert impl.dumps(value, string_referencing=True, canonical=True) == expected


def test_negative_tag(impl):
with pytest.raises(TypeError):
impl.dumps(impl.CBORTag(-1, 'value'))

0 comments on commit fc78572

Please sign in to comment.