Skip to content

Commit c9c8144

Browse files
author
brentru
committed
lint all the examples
1 parent fe82406 commit c9c8144

File tree

2 files changed

+87
-91
lines changed

2 files changed

+87
-91
lines changed

examples/atecc_csr.py

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
import board
2-
import busio
3-
import time
4-
import adafruit_ssd1306
5-
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ, CFG_TLS
6-
7-
import adafruit_atecc.adafruit_atecc_cert_util as cert_utils
8-
9-
# -- Enter your configuration below -- #
10-
11-
# Lock the ATECC module when the code is run?
12-
LOCK_ATECC = True
13-
# 2-letter country code
14-
MY_COUNTRY = "US"
15-
# State or Province Name
16-
MY_STATE = "New York"
17-
# City Name
18-
MY_CITY = "New York"
19-
# Organization Name
20-
MY_ORG = "Adafruit"
21-
# Organizational Unit Name
22-
MY_SECTION = "Crypto"
23-
# Which ATECC slot (0-4) to use
24-
ATECC_SLOT = 0
25-
# Generate new private key, or use existing key
26-
GENERATE_PRIVATE_KEY = False
27-
28-
# -- END Configuration, code below -- #
29-
30-
# Initialize the i2c bus
31-
i2c = busio.I2C(board.SCL, board.SDA,
32-
frequency=_WAKE_CLK_FREQ)
33-
34-
# Initialize a new atecc object
35-
atecc = ATECC(i2c)
36-
37-
print("ATECC Serial Number: ", atecc.serial_number)
38-
39-
if not atecc.locked:
40-
if not LOCK_ATECC:
41-
raise RuntimeError("The ATECC is not locked, set LOCK_ATECC to True in your code.py to unlock it.")
42-
print("Writing default configuration to the device...")
43-
atecc.write_config(CFG_TLS)
44-
print("Wrote configuration, locking ATECC module...")
45-
# Lock ATECC config, data, and otp zones
46-
atecc.lock_all_zones()
47-
print("ATECC locked!")
48-
49-
print("Generating Certificate Signing Request...")
50-
# Initialize a certificate signing request with provided info
51-
csr = cert_utils.CSR(atecc, ATECC_SLOT, GENERATE_PRIVATE_KEY, MY_COUNTRY, MY_STATE,
52-
MY_CITY, MY_ORG, MY_SECTION)
53-
# Generate CSR
54-
my_csr = csr.generate_csr()
55-
print("-----BEGIN CERTIFICATE REQUEST-----\n")
56-
print(my_csr.decode('utf-8'))
57-
print("-----END CERTIFICATE REQUEST-----")
1+
import board
2+
import busio
3+
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ, CFG_TLS
4+
5+
import adafruit_atecc.adafruit_atecc_cert_util as cert_utils
6+
7+
# -- Enter your configuration below -- #
8+
9+
# Lock the ATECC module when the code is run?
10+
LOCK_ATECC = True
11+
# 2-letter country code
12+
MY_COUNTRY = "US"
13+
# State or Province Name
14+
MY_STATE = "New York"
15+
# City Name
16+
MY_CITY = "New York"
17+
# Organization Name
18+
MY_ORG = "Adafruit"
19+
# Organizational Unit Name
20+
MY_SECTION = "Crypto"
21+
# Which ATECC slot (0-4) to use
22+
ATECC_SLOT = 0
23+
# Generate new private key, or use existing key
24+
GENERATE_PRIVATE_KEY = False
25+
26+
# -- END Configuration, code below -- #
27+
28+
# Initialize the i2c bus
29+
i2c = busio.I2C(board.SCL, board.SDA,
30+
frequency=_WAKE_CLK_FREQ)
31+
32+
# Initialize a new atecc object
33+
atecc = ATECC(i2c)
34+
35+
print("ATECC Serial Number: ", atecc.serial_number)
36+
37+
if not atecc.locked:
38+
if not LOCK_ATECC:
39+
raise RuntimeError("The ATECC is not locked, set LOCK_ATECC to True in code.py.")
40+
print("Writing default configuration to the device...")
41+
atecc.write_config(CFG_TLS)
42+
print("Wrote configuration, locking ATECC module...")
43+
# Lock ATECC config, data, and otp zones
44+
atecc.lock_all_zones()
45+
print("ATECC locked!")
46+
47+
print("Generating Certificate Signing Request...")
48+
# Initialize a certificate signing request with provided info
49+
csr = cert_utils.CSR(atecc, ATECC_SLOT, GENERATE_PRIVATE_KEY, MY_COUNTRY, MY_STATE,
50+
MY_CITY, MY_ORG, MY_SECTION)
51+
# Generate CSR
52+
my_csr = csr.generate_csr()
53+
print("-----BEGIN CERTIFICATE REQUEST-----\n")
54+
print(my_csr.decode('utf-8'))
55+
print("-----END CERTIFICATE REQUEST-----")

examples/atecc_simpletest.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
import board
2-
import busio
3-
import time
4-
import adafruit_ssd1306
5-
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ
6-
7-
# Initialize the i2c bus
8-
i2c = busio.I2C(board.SCL, board.SDA,
9-
frequency=_WAKE_CLK_FREQ)
10-
11-
# Initialize a new atecc object
12-
atecc = ATECC(i2c)
13-
14-
print("ATECC Serial: ", atecc.serial_number)
15-
16-
# Generate a random number with a maximum value of 1024
17-
print("Random Value: ", atecc.random(rnd_max=1024))
18-
19-
# Print out the value from one of the ATECC's counters
20-
# You should see this counter increase on every time the code.py runs.
21-
print("ATECC Counter #1 Value: ", atecc.counter(1, increment_counter=True))
22-
23-
# Initialize the SHA256 calculation engine
24-
atecc.sha_start()
25-
26-
# Append bytes to the SHA digest
27-
print("Appending to the digest...")
28-
atecc.sha_update(b"Nobody inspects")
29-
print("Appending to the digest...")
30-
atecc.sha_update(b" the spammish repetition")
31-
32-
# Return the digest of the data passed to sha_update
33-
message = atecc.sha_digest()
34-
print("SHA Digest: ", message)
1+
import board
2+
import busio
3+
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ
4+
5+
# Initialize the i2c bus
6+
i2c = busio.I2C(board.SCL, board.SDA,
7+
frequency=_WAKE_CLK_FREQ)
8+
9+
# Initialize a new atecc object
10+
atecc = ATECC(i2c)
11+
12+
print("ATECC Serial: ", atecc.serial_number)
13+
14+
# Generate a random number with a maximum value of 1024
15+
print("Random Value: ", atecc.random(rnd_max=1024))
16+
17+
# Print out the value from one of the ATECC's counters
18+
# You should see this counter increase on every time the code.py runs.
19+
print("ATECC Counter #1 Value: ", atecc.counter(1, increment_counter=True))
20+
21+
# Initialize the SHA256 calculation engine
22+
atecc.sha_start()
23+
24+
# Append bytes to the SHA digest
25+
print("Appending to the digest...")
26+
atecc.sha_update(b"Nobody inspects")
27+
print("Appending to the digest...")
28+
atecc.sha_update(b" the spammish repetition")
29+
30+
# Return the digest of the data passed to sha_update
31+
message = atecc.sha_digest()
32+
print("SHA Digest: ", message)

0 commit comments

Comments
 (0)