Skip to content

Commit 91db76f

Browse files
authored
Merge pull request #10 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents ad95ab1 + d1b0c7f commit 91db76f

File tree

9 files changed

+808
-410
lines changed

9 files changed

+808
-410
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_hashlib/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
# FIPS secure hash algorithms supported by this library
5454
ALGOS_AVAIL = ["sha1", "md5", "sha224", "sha256", "sha384", "sha512"]
5555

56+
5657
def new(algo, data=b""):
5758
"""Creates a new hashlib object.
5859
:param str algo: Name of the desired algorithm.
@@ -64,6 +65,7 @@ def new(algo, data=b""):
6465
except KeyError:
6566
raise ValueError(algo)
6667

68+
6769
@property
6870
def algorithms_available():
6971
"""Returns a list containing the names of the hash

adafruit_hashlib/_md5.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# The MIT License (MIT)
32
#
43
# Brent Rubell for Adafruit Industries, 2019
@@ -27,7 +26,10 @@
2726
* Author(s): Brent Rubell
2827
"""
2928
# pylint: disable=too-few-public-methods, invalid-name
30-
class md5():
29+
class md5:
3130
"""RSA MD5 Algorithm class."""
31+
3232
def __init__(self, s=None):
33-
raise NotImplementedError("MD5 digests not currently implemented in this module.")
33+
raise NotImplementedError(
34+
"MD5 digests not currently implemented in this module."
35+
)

adafruit_hashlib/_sha1.py

+27-22
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@
4646
K2 = const(0x8F1BBCDC)
4747
K3 = const(0xCA62C1D6)
4848

49+
4950
def _getbuf(data):
5051
"""Converts data into ascii,
5152
returns bytes of data.
5253
:param str bytes bytearray data: Data to convert.
5354
5455
"""
5556
if isinstance(data, str):
56-
return data.encode('ascii')
57+
return data.encode("ascii")
5758
return bytes(data)
5859

5960

@@ -63,7 +64,8 @@ def _left_rotate(n, b):
6364
:param int b: Desired rotation amount, in bits.
6465
6566
"""
66-
return ((n << b) | (n >> (32 - b))) & 0xffffffff
67+
return ((n << b) | (n >> (32 - b))) & 0xFFFFFFFF
68+
6769

6870
# pylint: disable=invalid-name, too-many-arguments
6971
def _hash_computation(chunk, h0, h1, h2, h3, h4):
@@ -79,7 +81,7 @@ def _hash_computation(chunk, h0, h1, h2, h3, h4):
7981

8082
# Break chunk into sixteen 4-byte big-endian words w[i]
8183
for i in range(16):
82-
w[i] = struct.unpack(b'>I', chunk[i * 4:i * 4 + 4])[0]
84+
w[i] = struct.unpack(b">I", chunk[i * 4 : i * 4 + 4])[0]
8385

8486
# Extend the sixteen 4-byte words into eighty 4-byte words
8587
for i in range(16, 80):
@@ -107,42 +109,45 @@ def _hash_computation(chunk, h0, h1, h2, h3, h4):
107109
f = b ^ c ^ d
108110
k = K3
109111

110-
a, b, c, d, e = ((_left_rotate(a, 5) + f + e + k + w[i]) & 0xffffffff,
111-
a, _left_rotate(b, 30), c, d)
112+
a, b, c, d, e = (
113+
(_left_rotate(a, 5) + f + e + k + w[i]) & 0xFFFFFFFF,
114+
a,
115+
_left_rotate(b, 30),
116+
c,
117+
d,
118+
)
112119

113120
# Add to chunk's hash result so far
114-
h0 = (h0 + a) & 0xffffffff
115-
h1 = (h1 + b) & 0xffffffff
116-
h2 = (h2 + c) & 0xffffffff
117-
h3 = (h3 + d) & 0xffffffff
118-
h4 = (h4 + e) & 0xffffffff
121+
h0 = (h0 + a) & 0xFFFFFFFF
122+
h1 = (h1 + b) & 0xFFFFFFFF
123+
h2 = (h2 + c) & 0xFFFFFFFF
124+
h3 = (h3 + d) & 0xFFFFFFFF
125+
h4 = (h4 + e) & 0xFFFFFFFF
119126

120127
return h0, h1, h2, h3, h4
121128

122129

123130
# pylint: disable=too-few-public-methods, invalid-name
124-
class sha1():
131+
class sha1:
125132
"""SHA-1 Hash Object
126133
127134
"""
135+
128136
digest_size = SHA_DIGESTSIZE
129137
block_size = SHA_BLOCKSIZE
130138
name = "sha1"
139+
131140
def __init__(self, data=None):
132141
"""Construct a SHA-1 hash object.
133142
:param bytes data: Optional data to process
134143
135144
"""
136145
# Initial Digest Variables
137-
self._h = (0x67452301,
138-
0xEFCDAB89,
139-
0x98BADCFE,
140-
0x10325476,
141-
0xC3D2E1F0)
146+
self._h = (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0)
142147

143148
# bytes object with 0 <= len < 64 used to store the end of the message
144149
# if the message length is not congruent to 64
145-
self._unprocessed = b''
150+
self._unprocessed = b""
146151

147152
# Length in bytes of all data that has been processed so far
148153
self._msg_byte_len = 0
@@ -159,15 +164,15 @@ def _create_digest(self):
159164
message_len = self._msg_byte_len + len(message)
160165

161166
# add trailing '1' bit (+ 0's padding) to string [FIPS 5.1.1]
162-
message += b'\x80'
167+
message += b"\x80"
163168

164169
# append 0 <= k < 512 bits '0', so that the resulting message length (in bytes)
165170
# is congruent to 56 (mod 64)
166-
message += b'\x00' * ((56 - (message_len + 1) % 64) % 64)
171+
message += b"\x00" * ((56 - (message_len + 1) % 64) % 64)
167172

168173
# append ml, the original message length, as a 64-bit big-endian integer.
169174
message_bit_length = message_len * 8
170-
message += struct.pack(b'>Q', message_bit_length)
175+
message += struct.pack(b">Q", message_bit_length)
171176

172177
# Process the final chunk
173178
h = _hash_computation(message[:64], *self._h)
@@ -205,11 +210,11 @@ def digest(self):
205210
method so far.
206211
207212
"""
208-
return b''.join(struct.pack(b'>I', h) for h in self._create_digest())
213+
return b"".join(struct.pack(b">I", h) for h in self._create_digest())
209214

210215
def hexdigest(self):
211216
"""Like digest() except the digest is returned as a string object of
212217
double length, containing only hexadecimal digits.
213218
214219
"""
215-
return ''.join(['%.2x' % i for i in self.digest()])
220+
return "".join(["%.2x" % i for i in self.digest()])

0 commit comments

Comments
 (0)