Skip to content

Commit 79d8fb0

Browse files
committed
Validated concat of bytes and fixed errors.
1 parent a9c3ea3 commit 79d8fb0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

adafruit_atecc/adafruit_atecc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555

5656
def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
57-
int(i2c_addr, 16)
57+
int(hex(i2c_addr), 16)
5858
return i2c_addr << 1
5959

6060

@@ -119,7 +119,7 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
119119
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
120120
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
121121
"""
122-
CFG_TLS_HEX = bytes(
122+
CFG_TLS = bytes(
123123
bytearray.fromhex(
124124
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
125125
"20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55"
@@ -139,10 +139,10 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
139139
)
140140

141141
# Convert I2C address to config byte 16 and update CFG_TLS
142-
_CFG_BYTES = bytearray(CFG_TLS)
143-
_CFG_BYTE_16 = hex(_I2C_ADDR << 1)
144-
_CFG_BYTES[16] = ord(_CFG_BYTE_16)
145-
CFG_TLS = bytes(_CFG_BYTES)
142+
_CFG_BYTES_LIST = list(bytearray(CFG_TLS))
143+
_CFG_BYTE_16 = bytes(bytearray.fromhex(hex(_I2C_ADDR << 1).replace("0x", "")))
144+
_CFG_BYTES_LIST_MOD = _CFG_BYTES_LIST[0:16] + list(_CFG_BYTE_16) + _CFG_BYTES_LIST[17:]
145+
CFG_TLS = bytes(_CFG_BYTES_LIST_MOD)
146146

147147

148148
class ATECC:
@@ -300,7 +300,7 @@ def nonce(self, data, mode=0, zero=0x0000):
300300
time.sleep(1 / 1000)
301301
if mode == 0x03:
302302
assert (
303-
calculated_nonce[0] == 0x00
303+
calculated_nonce[0] == 0x00
304304
), "Incorrectly calculated nonce in pass-thru mode"
305305
self.idle()
306306
return calculated_nonce
@@ -470,7 +470,7 @@ def write_config(self, data):
470470
if i == 84:
471471
# can't write
472472
continue
473-
self._write(0, i // 4, data[i : i + 4])
473+
self._write(0, i // 4, data[i: i + 4])
474474

475475
def _write(self, zone, address, buffer):
476476
self.wakeup()

0 commit comments

Comments
 (0)