Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def atcab_selftest(self, mode, param2=0):
if self._device != "ATECC608A":
raise ATCA_EXCEPTIONS.UnsupportedDeviceError("atcab_selftest")
packet = ATCAPacket(
opcode=ATCA_CONSTANTS.ATCA_SELFTEST,
param1=mode,
param2=param2
)
self.execute(packet)
RSP_DATA_IDX = ATCA_CONSTANTS.ATCA_RSP_DATA_IDX
return packet[RSP_DATA_IDX] & int(not mode) == ATCA_STATUS.ATCA_SUCCESS
def atcab_info_base(self, mode=0):
packet = ATCAPacket(
opcode=ATCA_CONSTANTS.ATCA_INFO,
param1=mode
)
self.execute(packet)
return packet
if cmd_mode in (
ATCA_CONSTANTS.SHA_MODE_SHA256_START,
ATCA_CONSTANTS.SHA_MODE_HMAC_START,
ATCA_CONSTANTS.SHA_MODE_SHA256_PUBLIC
):
txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN
elif cmd_mode in (
ATCA_CONSTANTS.SHA_MODE_SHA256_UPDATE,
ATCA_CONSTANTS.SHA_MODE_SHA256_END,
ATCA_CONSTANTS.SHA_MODE_HMAC_END
):
txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN + len(data)
else:
raise ATCA_EXCEPTIONS.BadArgumentError()
packet = ATCAPacket(
txsize=txsize,
opcode=ATCA_CONSTANTS.ATCA_SHA,
param1=mode,
param2=len(data) if not isinstance(key_slot, int) else key_slot,
request_data=data
)
self.execute(packet)
return packet
def atcab_updateextra(self, mode, value):
packet = ATCAPacket(
opcode=ATCA_CONSTANTS.ATCA_UPDATE_EXTRA,
param1=mode,
param2=value
)
self.execute(packet)
return packet
def atcab_lock(self, mode, crc=0):
packet = ATCAPacket(
txsize=ATCA_CONSTANTS.LOCK_COUNT,
opcode=ATCA_CONSTANTS.ATCA_LOCK,
param1=mode,
param2=crc
)
self.execute(packet)
return packet
def atcab_sign_base(self, mode, key_id):
packet = ATCAPacket(
txsize=ATCA_CONSTANTS.SIGN_COUNT,
opcode=ATCA_CONSTANTS.ATCA_SIGN,
param1=mode,
param2=key_id
)
self.execute(packet)
return packet
VODS = ATCA_CONSTANTS.VERIFY_OTHER_DATA_SIZE
data_size = SS
if has_public_key:
data_size += PKS
elif has_other_data:
data_size += VODS
data = bytearray(data_size)
data[0:SS] = signature
if has_public_key:
data[SS:SS+PKS] = public_key
elif has_other_data:
data[SS:SS+VODS] = other_data
packet = ATCAPacket(
txsize=txsize,
opcode=ATCA_CONSTANTS.ATCA_VERIFY,
param1=mode,
param2=key_id,
request_data=data
)
self.execute(packet)
return packet
txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN
data = bytearray(64)
if zone & ATCA_CONSTANTS.ATCA_ZONE_READWRITE_32:
# 32-byte write
data[0:32] = value
txsize += ATCA_CONSTANTS.ATCA_BLOCK_SIZE
# Only 32-byte writes can have a MAC
if isinstance(mac, _BYTES_LIKE_OBJECT):
data[32:64] = mac
txsize += ATCA_CONSTANTS.WRITE_MAC_SIZE
else:
# 4-byte write
data[0:4] = value
txsize += ATCA_CONSTANTS.ATCA_WORD_SIZE
packet = ATCAPacket(
txsize=txsize,
opcode=ATCA_CONSTANTS.ATCA_WRITE,
param1=zone,
param2=address,
request_data=data[:txsize-ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN]
)
self.execute(packet)
return packet