How to use the cryptoauthlib.status function in cryptoauthlib

To help you get started, we’ve selected a few cryptoauthlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
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
github dmazzella / ucryptoauthlib / cryptoauthlib / device.py View on Github external
p_t = utime.ticks_ms()
                while utime.ticks_diff(utime.ticks_ms(), p_t) <= min(d_t, 250):
                    try:
                        self._bus.readfrom_into(self._address, resp[0:1])
                        self._bus.readfrom_into(self._address, resp[1:resp[0]])
                    except OSError:
                        continue
                    else:
                        break

                # Check response
                err, exc = self.is_error(resp)
                if err == ATCA_STATUS.ATCA_SUCCESS:
                    packet._response_data = resp[:resp[0]]
                    return
                elif err == ATCA_STATUS.ATCA_WAKE_SUCCESS:
                    return
                elif err == ATCA_STATUS.ATCA_WATCHDOG_ABOUT_TO_EXPIRE:
                    self.sleep()
                else:
                    if exc is not None:
                        packet._response_data = resp[:resp[0]]
                        raise exc(ubinascii.hexlify(packet._response_data))
            except OSError:
                retries -= 1
        else:
            raise ATCA_EXCEPTIONS.GenericError("max retry")
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
def is_error(self, data):
        # error packets are always 4 bytes long
        if data[ATCA_CONSTANTS.ATCA_COUNT_IDX] == 0x04:
            return ATCA_STATUS.decode_error(
                data[ATCA_CONSTANTS.ATCA_RSP_DATA_IDX]
            )
        else:
            return ATCA_STATUS.ATCA_SUCCESS, None
github dmazzella / ucryptoauthlib / cryptoauthlib / device.py View on Github external
# Cyclic reading up to the completion of the calculation and in
                # any case no later than the tEXEC
                d_t = packet.delay
                p_t = utime.ticks_ms()
                while utime.ticks_diff(utime.ticks_ms(), p_t) <= min(d_t, 250):
                    try:
                        self._bus.readfrom_into(self._address, resp[0:1])
                        self._bus.readfrom_into(self._address, resp[1:resp[0]])
                    except OSError:
                        continue
                    else:
                        break

                # Check response
                err, exc = self.is_error(resp)
                if err == ATCA_STATUS.ATCA_SUCCESS:
                    packet._response_data = resp[:resp[0]]
                    return
                elif err == ATCA_STATUS.ATCA_WAKE_SUCCESS:
                    return
                elif err == ATCA_STATUS.ATCA_WATCHDOG_ABOUT_TO_EXPIRE:
                    self.sleep()
                else:
                    if exc is not None:
                        packet._response_data = resp[:resp[0]]
                        raise exc(ubinascii.hexlify(packet._response_data))
            except OSError:
                retries -= 1
        else:
            raise ATCA_EXCEPTIONS.GenericError("max retry")