Skip to content

Commit 54c7b65

Browse files
Merge pull request #13 from adafruit/linting
Fixed duplicate-code warning
2 parents c5733f7 + 05dc21b commit 54c7b65

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

adafruit_hashlib/_sha256.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ def sha224_init():
307307
return sha_info
308308

309309

310-
def getbuf(s):
311-
if isinstance(s, str):
312-
return s.encode("ascii")
313-
return bytes(s)
310+
def getbuf(string):
311+
if isinstance(string, str):
312+
return string.encode("ascii")
313+
return bytes(string)
314314

315315

316316
def sha_update(sha_info, buffer):
@@ -320,25 +320,25 @@ def sha_update(sha_info, buffer):
320320
"""
321321
if isinstance(buffer, str):
322322
raise TypeError("Unicode strings must be encoded before hashing")
323-
count = len(buffer)
323+
size = len(buffer)
324324
buffer_idx = 0
325-
clo = (sha_info["count_lo"] + (count << 3)) & 0xFFFFFFFF
325+
clo = (sha_info["count_lo"] + (size << 3)) & 0xFFFFFFFF
326326
if clo < sha_info["count_lo"]:
327327
sha_info["count_hi"] += 1
328328
sha_info["count_lo"] = clo
329329

330-
sha_info["count_hi"] += count >> 29
330+
sha_info["count_hi"] += size >> 29
331331

332332
if sha_info["local"]:
333333
i = SHA_BLOCKSIZE - sha_info["local"]
334-
if i > count:
335-
i = count
334+
if i > size:
335+
i = size
336336

337-
# copy buffer
337+
# copy sha buffer
338338
for x in enumerate(buffer[buffer_idx : buffer_idx + i]):
339339
sha_info["data"][sha_info["local"] + x[0]] = x[1]
340340

341-
count -= i
341+
size -= i
342342
buffer_idx += i
343343

344344
sha_info["local"] += i
@@ -348,17 +348,17 @@ def sha_update(sha_info, buffer):
348348
else:
349349
return
350350

351-
while count >= SHA_BLOCKSIZE:
352-
# copy buffer
351+
while size >= SHA_BLOCKSIZE:
352+
# copy sha buffer
353353
sha_info["data"] = list(buffer[buffer_idx : buffer_idx + SHA_BLOCKSIZE])
354-
count -= SHA_BLOCKSIZE
354+
size -= SHA_BLOCKSIZE
355355
buffer_idx += SHA_BLOCKSIZE
356356
sha_transform(sha_info)
357357

358-
# copy buffer
358+
# copy sha buffer
359359
pos = sha_info["local"]
360-
sha_info["data"][pos : pos + count] = list(buffer[buffer_idx : buffer_idx + count])
361-
sha_info["local"] = count
360+
sha_info["data"][pos : pos + size] = list(buffer[buffer_idx : buffer_idx + size])
361+
sha_info["local"] = size
362362

363363

364364
def sha_final(sha_info):

0 commit comments

Comments
 (0)