Skip to content

Commit aa64ba6

Browse files
author
Dominikus Gierlach
committed
Use "replace" error strategy for utf-8 decoding
1 parent fe57001 commit aa64ba6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkcs11/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ def __hash__(self):
4141

4242

4343
def _CK_UTF8CHAR_to_str(data):
44-
"""Convert CK_UTF8CHAR to string."""
45-
return data.rstrip(b"\0").decode("utf-8").rstrip()
44+
"""
45+
Convert CK_UTF8CHAR to string.
46+
47+
Substitutes invalid bytes with the replacement character to make usage more
48+
robust with non-compliant tokens.
49+
"""
50+
return data.rstrip(b"\0").decode("utf-8", errors="replace").rstrip()
4651

4752

4853
def _CK_VERSION_to_tuple(data):

0 commit comments

Comments
 (0)