Further bugfix; convert first, then check length

This commit is contained in:
kdmukai
2025-01-02 18:37:54 -06:00
parent 5267844481
commit 75ba1e07ec
+8 -3
View File
@@ -414,12 +414,17 @@ class DecodeQR:
pass
# Is it byte data?
if not isinstance(s, bytes):
try:
# TODO: remove this check & conversion once above cast to str is removed
s = s.encode()
except UnicodeError:
# Couldn't convert back to bytes; shouldn't happen
raise Exception("Conversion to bytes failed")
# 32 bytes for 24-word CompactSeedQR; 16 bytes for 12-word CompactSeedQR
if len(s) == 32 or len(s) == 16:
try:
if not isinstance(s, bytes):
# TODO: remove this check & conversion once above cast to str is removed
s = s.encode()
bitstream = ""
for b in s:
bitstream += bin(b).lstrip('0b').zfill(8)