Skip to content

Ran black, updated to pylint 2.x #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2020
PHP-Proxy

PHP-Proxy

Error accessing resource: 429 - Too Many Requests

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
2 changes: 2 additions & 0 deletions adafruit_hashlib/__init__.py
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
# FIPS secure hash algorithms supported by this library
ALGOS_AVAIL = ["sha1", "md5", "sha224", "sha256", "sha384", "sha512"]


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


@property
def algorithms_available():
"""Returns a list containing the names of the hash
8 changes: 5 additions & 3 deletions adafruit_hashlib/_md5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# The MIT License (MIT)
#
# Brent Rubell for Adafruit Industries, 2019
@@ -27,7 +26,10 @@
* Author(s): Brent Rubell
"""
# pylint: disable=too-few-public-methods, invalid-name
class md5():
class md5:
"""RSA MD5 Algorithm class."""

def __init__(self, s=None):
raise NotImplementedError("MD5 digests not currently implemented in this module.")
raise NotImplementedError(
"MD5 digests not currently implemented in this module."
)
49 changes: 27 additions & 22 deletions adafruit_hashlib/_sha1.py
Original file line number Diff line number Diff line change
@@ -46,14 +46,15 @@
K2 = const(0x8F1BBCDC)
K3 = const(0xCA62C1D6)


def _getbuf(data):
"""Converts data into ascii,
returns bytes of data.
:param str bytes bytearray data: Data to convert.

"""
if isinstance(data, str):
return data.encode('ascii')
return data.encode("ascii")
return bytes(data)


@@ -63,7 +64,8 @@ def _left_rotate(n, b):
:param int b: Desired rotation amount, in bits.

"""
return ((n << b) | (n >> (32 - b))) & 0xffffffff
return ((n << b) | (n >> (32 - b))) & 0xFFFFFFFF


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

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

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

a, b, c, d, e = ((_left_rotate(a, 5) + f + e + k + w[i]) & 0xffffffff,
a, _left_rotate(b, 30), c, d)
a, b, c, d, e = (
(_left_rotate(a, 5) + f + e + k + w[i]) & 0xFFFFFFFF,
a,
_left_rotate(b, 30),
c,
d,
)

# Add to chunk's hash result so far
h0 = (h0 + a) & 0xffffffff
h1 = (h1 + b) & 0xffffffff
h2 = (h2 + c) & 0xffffffff
h3 = (h3 + d) & 0xffffffff
h4 = (h4 + e) & 0xffffffff
h0 = (h0 + a) & 0xFFFFFFFF
h1 = (h1 + b) & 0xFFFFFFFF
h2 = (h2 + c) & 0xFFFFFFFF
h3 = (h3 + d) & 0xFFFFFFFF
h4 = (h4 + e) & 0xFFFFFFFF

return h0, h1, h2, h3, h4


# pylint: disable=too-few-public-methods, invalid-name
class sha1():
class sha1:
"""SHA-1 Hash Object

"""

digest_size = SHA_DIGESTSIZE
block_size = SHA_BLOCKSIZE
name = "sha1"

def __init__(self, data=None):
"""Construct a SHA-1 hash object.
:param bytes data: Optional data to process

"""
# Initial Digest Variables
self._h = (0x67452301,
0xEFCDAB89,
0x98BADCFE,
0x10325476,
0xC3D2E1F0)
self._h = (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0)

# bytes object with 0 <= len < 64 used to store the end of the message
# if the message length is not congruent to 64
self._unprocessed = b''
self._unprocessed = b""

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

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

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

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

# Process the final chunk
h = _hash_computation(message[:64], *self._h)
@@ -205,11 +210,11 @@ def digest(self):
method so far.

"""
return b''.join(struct.pack(b'>I', h) for h in self._create_digest())
return b"".join(struct.pack(b">I", h) for h in self._create_digest())

def hexdigest(self):
"""Like digest() except the digest is returned as a string object of
double length, containing only hexadecimal digits.

"""
return ''.join(['%.2x' % i for i in self.digest()])
return "".join(["%.2x" % i for i in self.digest()])
PHP-Proxy

PHP-Proxy

Error accessing resource: 429 - Too Many Requests