Merge pull request #36 from hubertmis/fix-token

Fix token handling
This commit is contained in:
Giacomo Tanganelli 2021-01-17 12:01:30 +01:00 committed by GitHub
commit 8e0704e706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View file

@ -119,17 +119,16 @@ class Message(object):
"""
Set the Token of the message.
:type value: String
:type value: Bytes
:param value: the Token
:raise AttributeError: if value is longer than 256
"""
if value is None:
self._token = value
return
if isinstance(value, int):
value = bytes([value])
if not isinstance(value, bytes):
value = bytes(value, "utf-8")
value = bytes(value)
if len(value) > 256:
raise AttributeError
self._token = value

View file

@ -157,10 +157,8 @@ class Serializer(object):
values = [tmp, message.code, message.mid]
if message.token is not None and tkl > 0:
for b in message.token:
fmt += "B"
values.append(b)
fmt += "%ss" % tkl
values.append(message.token)
options = Serializer.as_sorted_list(message.options) # already sorted
lastoptionnumber = 0