Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Shernicoff committed May 1, 2023
1 parent d9944ce commit 69de468
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions adafruit_atecc/adafruit_atecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
# to have this in a try/except to enable type hinting for the IDEs while
# not breaking the runtime on the controller.
try:
from typing import Any, Sized
from typing import Any, Sized, Optional
from busio import I2C
except ImportError:
pass

from micropython import const
from adafruit_bus_device.i2c_device import I2CDevice, I2C
from adafruit_bus_device.i2c_device import I2CDevice
from adafruit_binascii import hexlify, unhexlify

__version__ = "0.0.0+auto.0"
Expand Down Expand Up @@ -260,7 +261,7 @@ def lock_all_zones(self):
self.lock(0)
self.lock(1)

def lock(self, zone: Any):
def lock(self, zone: int):
"""Locks specific ATECC zones.
:param int zone: ATECC zone to lock.
"""
Expand All @@ -272,7 +273,7 @@ def lock(self, zone: Any):
assert res[0] == 0x00, "Failed locking ATECC!"
self.idle()

def info(self, mode: int, param: Any = None) -> bytearray:
def info(self, mode: int, param: Optional[Any] = None) -> bytearray:
"""
Returns device state information
Expand Down Expand Up @@ -394,7 +395,7 @@ def _random(self, data: bytearray) -> bytearray:
return data

# SHA-256 Commands
def sha_start(self):
def sha_start(self) -> bytearray:
"""
Initializes the SHA-256 calculation engine
and the SHA context in memory.
Expand All @@ -409,7 +410,7 @@ def sha_start(self):
self.idle()
return status

def sha_update(self, message: Any) -> bytearray:
def sha_update(self, message: bytes) -> bytearray:
"""
Appends bytes to the message. Can be repeatedly called.
Expand Down Expand Up @@ -535,11 +536,11 @@ def _write(self, zone: Any, address: int, buffer: bytearray):
self._get_response(status)
self.idle()

def _read(self, zone: Any, address: int, buffer: bytearray):
def _read(self, zone: int, address: int, buffer: bytearray):
"""
Reads from the I2C
:param Any zone: Zone to read from
:param int zone: Zone to read from
:param int address: The address to read from
:param bytearray buffer: The buffer to read to
"""
Expand Down
6 changes: 3 additions & 3 deletions adafruit_atecc/adafruit_atecc_asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_name(name: str, obj_type: int, data: bytearray) -> int:
return len(name) + 11


def get_version(data: bytearray):
def get_version(data: bytearray) -> None:
"""
Appends X.509 version to data.
Expand All @@ -165,7 +165,7 @@ def get_version(data: bytearray):
data += b"\x02\x01\x00"


def get_sequence_header(length: int, data: bytearray):
def get_sequence_header(length: int, data: bytearray) -> None:
"""
Appends sequence header to provided data.
Expand All @@ -182,7 +182,7 @@ def get_sequence_header(length: int, data: bytearray):
data += length_byte


def get_public_key(data: bytearray, public_key: bytearray):
def get_public_key(data: bytearray, public_key: bytearray) -> None:
"""
Appends public key subject and object identifiers.
Expand Down
6 changes: 3 additions & 3 deletions adafruit_atecc/adafruit_atecc_cert_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def __init__(
self._cert = None
self._key = None

def generate_csr(self):
def generate_csr(self) -> bytearray:
"""Generates and returns a certificate signing request."""
self._csr_begin()
csr = self._csr_end()
return csr

def _csr_begin(self):
def _csr_begin(self) -> None:
"""Initializes CSR generation."""
assert 0 <= self._slot <= 4, "Provided slot must be between 0 and 4."
# Create a new key
Expand All @@ -97,7 +97,7 @@ def _csr_begin(self):
return
self._atecc.gen_key(self._key, self._slot, self.private_key)

def _csr_end(self):
def _csr_end(self) -> bytearray:
"""Generates and returns
a certificate signing request as a base64 string."""
len_issuer_subject = asn1.issuer_or_subject_length(
Expand Down

0 comments on commit 69de468

Please sign in to comment.