From f3c9bd653af662bc0520ac6392778ff162b8267a Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 12 Mar 2020 19:08:27 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_atecc/adafruit_atecc.py | 94 +++++++++-------- adafruit_atecc/adafruit_atecc_asn1.py | 26 +++-- adafruit_atecc/adafruit_atecc_cert_util.py | 33 ++++-- docs/conf.py | 116 ++++++++++++--------- examples/atecc_csr.py | 21 ++-- examples/atecc_simpletest.py | 3 +- setup.py | 56 +++++----- 8 files changed, 196 insertions(+), 155 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_atecc/adafruit_atecc.py b/adafruit_atecc/adafruit_atecc.py index 186d4f1..528a27b 100755 --- a/adafruit_atecc/adafruit_atecc.py +++ b/adafruit_atecc/adafruit_atecc.py @@ -77,8 +77,8 @@ _ATECC_608_VER = const(0x60) # Clock constants -_WAKE_CLK_FREQ = 100000 # slower clock speed -_TWLO_TIME = 6e-5 # TWlo, in microseconds +_WAKE_CLK_FREQ = 100000 # slower clock speed +_TWLO_TIME = 6e-5 # TWlo, in microseconds # Command Opcodes (9-1-3) OP_COUNTER = const(0x24) @@ -92,30 +92,34 @@ OP_WRITE = const(0x12) # Maximum execution times, in milliseconds (9-4) -EXEC_TIME = {OP_COUNTER: const(20), - OP_INFO: const(1), - OP_NONCE: const(7), - OP_RANDOM: const(23), - OP_SHA: const(47), - OP_LOCK: const(32), - OP_GEN_KEY: const(115), - OP_SIGN : const(70), - OP_WRITE : const(26)} - - -CFG_TLS = b'\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \ +EXEC_TIME = { + OP_COUNTER: const(20), + OP_INFO: const(1), + OP_NONCE: const(7), + OP_RANDOM: const(23), + OP_SHA: const(47), + OP_LOCK: const(32), + OP_GEN_KEY: const(115), + OP_SIGN: const(70), + OP_WRITE: const(26), +} + + +CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \ \xc0\x00U\x00\x83 \x87 \x87 \x87/\x87/\x8f\x8f\x9f\x8f\xaf \ \x8f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \ \xaf\x8f\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00 \ \x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \ \xff\xff\xff\xff\x00\x00UU\xff\xff\x00\x00\x00\x00\x00\x003 \ \x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \ - \x00<\x00<\x00<\x00\x1c\x00' + \x00<\x00<\x00<\x00\x1c\x00" + class ATECC: """ CircuitPython interface for ATECCx08A Crypto Co-Processor Devices. """ + def __init__(self, i2c_bus, address=_REG_ATECC_DEVICE_ADDR, debug=False): """Initializes an ATECC device. :param busio i2c_bus: I2C Bus object. @@ -132,7 +136,9 @@ def __init__(self, i2c_bus, address=_REG_ATECC_DEVICE_ADDR, debug=False): self._i2c_device = I2CDevice(self._i2c_bus, address) self.idle() if (self.version() >> 8) not in (_ATECC_508_VER, _ATECC_608_VER): - raise RuntimeError("Failed to find 608 or 508 chip. Please check your wiring.") + raise RuntimeError( + "Failed to find 608 or 508 chip. Please check your wiring." + ) def wakeup(self): """Wakes up THE ATECC608A from sleep or idle modes. @@ -148,13 +154,13 @@ def wakeup(self): try: self._i2c_bus.writeto(0x0, zero_bits) except OSError: - pass # this may fail, that's ok - its just to wake up the chip! + pass # this may fail, that's ok - its just to wake up the chip! time.sleep(_TWLO_TIME) - data = self._i2c_bus.scan() # check for an i2c device + data = self._i2c_bus.scan() # check for an i2c device try: if data[0] != 96: - raise TypeError('ATECCx08 not found - please check your wiring!') + raise TypeError("ATECCx08 not found - please check your wiring!") except IndexError: raise IndexError("ATECCx08 not found - please check your wiring!") self._i2c_bus.unlock() @@ -228,20 +234,18 @@ def lock_all_zones(self): self.lock(0) self.lock(1) - def lock(self, zone): """Locks specific ATECC zones. :param int zone: ATECC zone to lock. """ self.wakeup() self._send_command(0x17, 0x80 | zone, 0x0000) - time.sleep(EXEC_TIME[OP_LOCK]/1000) + time.sleep(EXEC_TIME[OP_LOCK] / 1000) res = bytearray(1) self._get_response(res) assert res[0] == 0x00, "Failed locking ATECC!" self.idle() - def info(self, mode, param=None): """Returns device state information :param int mode: Mode encoding, see Table 9-26. @@ -252,7 +256,7 @@ def info(self, mode, param=None): self._send_command(OP_INFO, mode) else: self._send_command(OP_INFO, mode, param) - time.sleep(EXEC_TIME[OP_INFO]/1000) + time.sleep(EXEC_TIME[OP_INFO] / 1000) info_out = bytearray(4) self._get_response(info_out) self.idle() @@ -281,15 +285,16 @@ def nonce(self, data, mode=0, zero=0x0000): calculated_nonce = bytearray(1) else: raise RuntimeError("Invalid mode specified!") - time.sleep(EXEC_TIME[OP_NONCE]/1000) + time.sleep(EXEC_TIME[OP_NONCE] / 1000) self._get_response(calculated_nonce) - time.sleep(1/1000) + time.sleep(1 / 1000) if mode == 0x03: - assert calculated_nonce[0] == 0x00, "Incorrectly calculated nonce in pass-thru mode" + assert ( + calculated_nonce[0] == 0x00 + ), "Incorrectly calculated nonce in pass-thru mode" self.idle() return calculated_nonce - def counter(self, counter=0, increment_counter=True): """Reads the binary count value from one of the two monotonic counters located on the device within the configuration zone. @@ -306,7 +311,7 @@ def counter(self, counter=0, increment_counter=True): self._send_command(OP_COUNTER, 0x01, counter) else: self._send_command(OP_COUNTER, 0x00, counter) - time.sleep(EXEC_TIME[OP_COUNTER]/1000) + time.sleep(EXEC_TIME[OP_COUNTER] / 1000) count = bytearray(4) self._get_response(count) self.idle() @@ -342,7 +347,7 @@ def _random(self, data): data_len = len(data) while data_len: self._send_command(OP_RANDOM, 0x00, 0x0000) - time.sleep(EXEC_TIME[OP_RANDOM]/1000) + time.sleep(EXEC_TIME[OP_RANDOM] / 1000) resp = bytearray(32) self._get_response(resp) copy_len = min(32, data_len) @@ -359,7 +364,7 @@ def sha_start(self): """ self.wakeup() self._send_command(OP_SHA, 0x00) - time.sleep(EXEC_TIME[OP_SHA]/1000) + time.sleep(EXEC_TIME[OP_SHA] / 1000) status = bytearray(1) self._get_response(status) assert status[0] == 0x00, "Error during sha_start." @@ -374,14 +379,13 @@ def sha_update(self, message): """ self.wakeup() self._send_command(OP_SHA, 0x01, 64, message) - time.sleep(EXEC_TIME[OP_SHA]/1000) + time.sleep(EXEC_TIME[OP_SHA] / 1000) status = bytearray(1) self._get_response(status) assert status[0] == 0x00, "Error during SHA Update" self.idle() return status - def sha_digest(self, message=None): """Returns the digest of the data passed to the sha_update method so far. @@ -397,14 +401,13 @@ def sha_digest(self, message=None): self._send_command(OP_SHA, 0x02, len(message), message) else: self._send_command(OP_SHA, 0x02) - time.sleep(EXEC_TIME[OP_SHA]/1000) + time.sleep(EXEC_TIME[OP_SHA] / 1000) digest = bytearray(32) self._get_response(digest) assert len(digest) == 32, "SHA response length does not match expected length." self.idle() return digest - def gen_key(self, key, slot_num, private_key=False): """Generates a private or public key. :param int slot_num: ECC slot (from 0 to 4). @@ -417,7 +420,7 @@ def gen_key(self, key, slot_num, private_key=False): self._send_command(OP_GEN_KEY, 0x04, slot_num) else: self._send_command(OP_GEN_KEY, 0x00, slot_num) - time.sleep(EXEC_TIME[OP_GEN_KEY]/1000) + time.sleep(EXEC_TIME[OP_GEN_KEY] / 1000) self._get_response(key) time.sleep(0.001) self.idle() @@ -442,7 +445,7 @@ def sign(self, slot_id): """ self.wakeup() self._send_command(0x41, 0x80, slot_id) - time.sleep(EXEC_TIME[OP_SIGN]/1000) + time.sleep(EXEC_TIME[OP_SIGN] / 1000) signature = bytearray(64) self._get_response(signature) self.idle() @@ -457,7 +460,7 @@ def write_config(self, data): if i == 84: # can't write continue - self._write(0, i//4, data[i:i+4]) + self._write(0, i // 4, data[i : i + 4]) def _write(self, zone, address, buffer): self.wakeup() @@ -466,7 +469,7 @@ def _write(self, zone, address, buffer): if len(buffer) == 32: zone |= 0x80 self._send_command(0x12, zone, address, buffer) - time.sleep(26/1000) + time.sleep(26 / 1000) status = bytearray(1) self._get_response(status) self.idle() @@ -483,7 +486,7 @@ def _read(self, zone, address, buffer): time.sleep(0.001) self.idle() - def _send_command(self, opcode, param_1, param_2=0x00, data=''): + def _send_command(self, opcode, param_1, param_2=0x00, data=""): """Sends a security command packet over i2c. :param byte opcode: The command Opcode :param byte param_1: The first parameter @@ -491,18 +494,18 @@ def _send_command(self, opcode, param_1, param_2=0x00, data=''): :param byte param_3 data: Optional remaining input data. """ # assembling command packet - command_packet = bytearray(8+len(data)) + command_packet = bytearray(8 + len(data)) # word address command_packet[0] = 0x03 # i/o group: count - command_packet[1] = len(command_packet) - 1 # count + command_packet[1] = len(command_packet) - 1 # count # security command packets command_packet[2] = opcode command_packet[3] = param_1 command_packet[4] = param_2 & 0xFF command_packet[5] = param_2 >> 8 for i, cmd in enumerate(data): - command_packet[6+i] = cmd + command_packet[6 + i] = cmd if self._debug: print("Command Packet Sz: ", len(command_packet)) print("\tSending:", [hex(i) for i in command_packet]) @@ -517,12 +520,11 @@ def _send_command(self, opcode, param_1, param_2=0x00, data=''): # small sleep time.sleep(0.001) - def _get_response(self, buf, length=None, retries=20): self.wakeup() if length is None: length = len(buf) - response = bytearray(length+3) # 1 byte header, 2 bytes CRC, len bytes data + response = bytearray(length + 3) # 1 byte header, 2 bytes CRC, len bytes data with self._i2c_device as i2c: for _ in range(retries): try: @@ -539,7 +541,7 @@ def _get_response(self, buf, length=None, retries=20): if crc != crc2: raise RuntimeError("CRC Mismatch") for i in range(length): - buf[i] = response[i+1] + buf[i] = response[i + 1] return response[1] @staticmethod @@ -553,7 +555,7 @@ def _at_crc(data, length=None): for b in data: for shift in range(8): data_bit = 0 - if b & (1<> 15) & 0x1 crc <<= 1 diff --git a/adafruit_atecc/adafruit_atecc_asn1.py b/adafruit_atecc/adafruit_atecc_asn1.py index 8fb4ef4..db639d3 100755 --- a/adafruit_atecc/adafruit_atecc_asn1.py +++ b/adafruit_atecc/adafruit_atecc_asn1.py @@ -65,11 +65,11 @@ def get_signature(signature, data): r_len = 32 s_len = 32 - while (r == 0x00 and r_len > 1): + while r == 0x00 and r_len > 1: r += 1 r_len -= 1 - while (s == 0x00 and s_len > 1): + while s == 0x00 and s_len > 1: s += 1 s_len -= 1 @@ -107,8 +107,7 @@ def get_signature(signature, data): # pylint: disable=too-many-arguments -def get_issuer_or_subject(data, country, state_prov, locality, - org, org_unit, common): +def get_issuer_or_subject(data, country, state_prov, locality, org, org_unit, common): """Appends issuer or subject, if they exist, to data.""" if country: get_name(country, 0x06, data) @@ -117,9 +116,9 @@ def get_issuer_or_subject(data, country, state_prov, locality, if locality: get_name(locality, 0x07, data) if org: - get_name(org, 0x0a, data) + get_name(org, 0x0A, data) if org_unit: - get_name(org_unit, 0x0b, data) + get_name(org_unit, 0x0B, data) if common: get_name(common, 0x03, data) @@ -142,28 +141,30 @@ def get_name(name, obj_type, data): data.extend(name) return len(name) + 11 + def get_version(data): """Appends X.509 version to data.""" # If no extensions are present, but a UniqueIdentifier # is present, the version SHOULD be 2 (value is 1) [4-1-2] data += b"\x02\x01\x00" + def get_sequence_header(length, data): """Appends sequence header to provided data.""" data += b"\x30" if length > 255: data += b"\x82" - data.append((length >> 8) & 0xff) + data.append((length >> 8) & 0xFF) elif length > 127: data += b"\x81" - length_byte = struct.pack("B", (length) & 0xff) + length_byte = struct.pack("B", (length) & 0xFF) data += length_byte def get_public_key(data, public_key): """Appends public key subject and object identifiers.""" # Subject: Public Key - data += b"\x30" + struct.pack("B", (0x59) & 0xff) + b"\x30\x13" + data += b"\x30" + struct.pack("B", (0x59) & 0xFF) + b"\x30\x13" # Object identifier: EC Public Key data += b"\x06\x07\x2a\x86\x48\xce\x3d\x02\x01" # Object identifier: PRIME 256 v1 @@ -171,6 +172,7 @@ def get_public_key(data, public_key): # Extend the buffer by the public key data += public_key + def get_signature_length(signature): """Return length of ECDSA signature. :param bytearray signature: Signed SHA256 hash. @@ -180,14 +182,14 @@ def get_signature_length(signature): r_len = 32 s_len = 32 - while (r == 0x00 and r_len > 1): + while r == 0x00 and r_len > 1: r += 1 r_len -= 1 if r & 0x80: r_len += 1 - while (s == 0x00 and s_len > 1): + while s == 0x00 and s_len > 1: s += 1 s_len -= 1 @@ -195,6 +197,7 @@ def get_signature_length(signature): s_len += 1 return 21 + r_len + s_len + def get_sequence_header_length(seq_header_len): """Returns length of SEQUENCE header.""" if seq_header_len > 255: @@ -203,6 +206,7 @@ def get_sequence_header_length(seq_header_len): return 3 return 2 + def issuer_or_subject_length(country, state_prov, city, org, org_unit, common): """Returns total length of provided certificate information.""" tot_len = 0 diff --git a/adafruit_atecc/adafruit_atecc_cert_util.py b/adafruit_atecc/adafruit_atecc_cert_util.py index 415c17a..7591ba7 100755 --- a/adafruit_atecc/adafruit_atecc_cert_util.py +++ b/adafruit_atecc/adafruit_atecc_cert_util.py @@ -54,6 +54,7 @@ from adafruit_binascii import b2a_base64 import adafruit_atecc.adafruit_atecc_asn1 as asn1 + class CSR: """Certificate Signing Request Builder. @@ -67,9 +68,11 @@ class CSR: :param str org_unit: Organizational unit name. """ + # pylint: disable=too-many-arguments, too-many-instance-attributes - def __init__(self, atecc, slot_num, private_key, country, state_prov, - city, org, org_unit): + def __init__( + self, atecc, slot_num, private_key, country, state_prov, city, org, org_unit + ): self._atecc = atecc self.private_key = private_key self._slot = slot_num @@ -89,7 +92,6 @@ def generate_csr(self): csr = self._csr_end() return csr - def _csr_begin(self): """Initializes CSR generation. """ assert 0 <= self._slot <= 4, "Provided slot must be between 0 and 4." @@ -100,13 +102,17 @@ def _csr_begin(self): return self._atecc.gen_key(self._key, self._slot, self.private_key) - def _csr_end(self): """Generates and returns a certificate signing request as a base64 string.""" - len_issuer_subject = asn1.issuer_or_subject_length(self._country, self._state_province, - self._locality, self._org, - self._org_unit, self._common) + len_issuer_subject = asn1.issuer_or_subject_length( + self._country, + self._state_province, + self._locality, + self._org, + self._org_unit, + self._common, + ) len_sub_header = asn1.get_sequence_header_length(len_issuer_subject) len_csr_info = self._version_len + len_issuer_subject @@ -126,8 +132,15 @@ def _csr_end(self): asn1.get_sequence_header(len_issuer_subject, csr_info) # Append Issuer or Subject - asn1.get_issuer_or_subject(csr_info, self._country, self._state_province, - self._locality, self._org, self._org_unit, self._common) + asn1.get_issuer_or_subject( + csr_info, + self._country, + self._state_province, + self._locality, + self._org, + self._org_unit, + self._common, + ) # Append Public Key asn1.get_public_key(csr_info, self._key) @@ -145,7 +158,7 @@ def _csr_end(self): if chunk_len > 64: chunk_len = 64 if chunk_len == 64: - self._atecc.sha_update(csr_info[i:i+64]) + self._atecc.sha_update(csr_info[i : i + 64]) else: csr_info_sha_256 = self._atecc.sha_digest(csr_info[i:]) diff --git a/docs/conf.py b/docs/conf.py index 167063b..c0697a6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # Uncomment the below if you use native CircuitPython modules such as @@ -21,29 +22,36 @@ # autodoc module docs will fail to generate with a warning. autodoc_mock_imports = ["micropython", "adafruit-bus-device", "adafruit-binascii"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit ATECC Library' -copyright = u'2019 Brent Rubell' -author = u'Brent Rubell' +project = u"Adafruit ATECC Library" +copyright = u"2019 Brent Rubell" +author = u"Brent Rubell" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -55,7 +63,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -67,7 +75,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -82,59 +90,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitAteccLibrarydoc' +htmlhelp_basename = "AdafruitAteccLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitATECCLibrary.tex', u'AdafruitATECC Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitATECCLibrary.tex", + u"AdafruitATECC Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -142,8 +153,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitATECClibrary', u'Adafruit ATECC Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitATECClibrary", + u"Adafruit ATECC Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -152,7 +168,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitATECCLibrary', u'Adafruit ATECC Library Documentation', - author, 'AdafruitATECCLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitATECCLibrary", + u"Adafruit ATECC Library Documentation", + author, + "AdafruitATECCLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/atecc_csr.py b/examples/atecc_csr.py index 166e40c..289a24b 100755 --- a/examples/atecc_csr.py +++ b/examples/atecc_csr.py @@ -26,8 +26,7 @@ # -- END Configuration, code below -- # # Initialize the i2c bus -i2c = busio.I2C(board.SCL, board.SDA, - frequency=_WAKE_CLK_FREQ) +i2c = busio.I2C(board.SCL, board.SDA, frequency=_WAKE_CLK_FREQ) # Initialize a new atecc object atecc = ATECC(i2c) @@ -36,7 +35,9 @@ if not atecc.locked: if not LOCK_ATECC: - raise RuntimeError("The ATECC is not locked, set LOCK_ATECC to True in code.py.") + raise RuntimeError( + "The ATECC is not locked, set LOCK_ATECC to True in code.py." + ) print("Writing default configuration to the device...") atecc.write_config(CFG_TLS) print("Wrote configuration, locking ATECC module...") @@ -46,10 +47,18 @@ print("Generating Certificate Signing Request...") # Initialize a certificate signing request with provided info -csr = cert_utils.CSR(atecc, ATECC_SLOT, GENERATE_PRIVATE_KEY, MY_COUNTRY, MY_STATE, - MY_CITY, MY_ORG, MY_SECTION) +csr = cert_utils.CSR( + atecc, + ATECC_SLOT, + GENERATE_PRIVATE_KEY, + MY_COUNTRY, + MY_STATE, + MY_CITY, + MY_ORG, + MY_SECTION, +) # Generate CSR my_csr = csr.generate_csr() print("-----BEGIN CERTIFICATE REQUEST-----\n") -print(my_csr.decode('utf-8')) +print(my_csr.decode("utf-8")) print("-----END CERTIFICATE REQUEST-----") diff --git a/examples/atecc_simpletest.py b/examples/atecc_simpletest.py index 353b9b4..d051ff1 100644 --- a/examples/atecc_simpletest.py +++ b/examples/atecc_simpletest.py @@ -3,8 +3,7 @@ from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ # Initialize the i2c bus -i2c = busio.I2C(board.SCL, board.SDA, - frequency=_WAKE_CLK_FREQ) +i2c = busio.I2C(board.SCL, board.SDA, frequency=_WAKE_CLK_FREQ) # Initialize a new atecc object atecc = ATECC(i2c) diff --git a/setup.py b/setup.py index e958489..0fcf673 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,54 +14,45 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-atecc', - + name="adafruit-circuitpython-atecc", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Driver for Microchip\'s ATECCx08 cryptographic co-processors with secure hardware-based key storage', + setup_requires=["setuptools_scm"], + description="Driver for Microchip's ATECCx08 cryptographic co-processors with secure hardware-based key storage", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_ATECC', - + url="https://github.com/adafruit/Adafruit_CircuitPython_ATECC", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[ - 'Adafruit-Blinka', - 'adafruit-circuitpython-busdevice', - 'adafruit-circuitpython-binascii', + "Adafruit-Blinka", + "adafruit-circuitpython-busdevice", + "adafruit-circuitpython-binascii", ], - # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython atecc atecc, microchip, secure, ' - 'element, key, co-processor', - + keywords="adafruit blinka circuitpython micropython atecc atecc, microchip, secure, " + "element, key, co-processor", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - packages=['adafruit_atecc'], + packages=["adafruit_atecc"], )