Skip to content

Commit

Permalink
fix: Fix infoblock setting bugs
Browse files Browse the repository at this point in the history
* restrict info block data string to 31 bytes
* correctly handle empty string
  • Loading branch information
robberwick committed Nov 17, 2024
1 parent 350b456 commit ab1d58d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/blinkstick/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ def string_to_info_block_data(data: str) -> bytes:
@rtype: byte[32]
@return: It fills the rest of bytes with zeros.
"""
byte_array = bytearray([1])
for c in data:
byte_array.append(ord(c))
info_block_data = data[:31]
byte_array = bytearray([1] + [0] * 31)

for i in range(32 - len(data)):
byte_array.append(0)
for i, c in enumerate(info_block_data):
byte_array[i + 1] = ord(c)

return bytes(byte_array)

0 comments on commit ab1d58d

Please sign in to comment.