Review comment Fix

This commit is contained in:
skarnataki
2023-09-27 10:57:51 +00:00
committed by Lucas Abel
parent 16d33199eb
commit 5ce353bcde
3 changed files with 186 additions and 131 deletions

View File

@@ -167,7 +167,7 @@ class DataElement:
UUID: lambda x: DataElement(
DataElement.UUID, core.UUID.from_bytes(bytes(reversed(x)))
),
TEXT_STRING: lambda x: DataElement(DataElement.TEXT_STRING, x),
TEXT_STRING: lambda x: DataElement(DataElement.TEXT_STRING, x.decode('latin1')),
BOOLEAN: lambda x: DataElement(DataElement.BOOLEAN, x[0] == 1),
SEQUENCE: lambda x: DataElement(
DataElement.SEQUENCE, DataElement.list_from_bytes(x)
@@ -376,7 +376,9 @@ class DataElement:
raise ValueError('invalid value_size')
elif self.type == DataElement.UUID:
data = bytes(reversed(bytes(self.value)))
elif self.type in (DataElement.TEXT_STRING, DataElement.URL):
elif self.type == DataElement.TEXT_STRING:
data = self.value.encode('latin1')
elif self.type == DataElement.URL:
data = self.value.encode('utf8')
elif self.type == DataElement.BOOLEAN:
data = bytes([1 if self.value else 0])