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 3 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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 --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ notes=FIXME,XXX


[TYPECHECK]
disable=bad-option-value

# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
Expand Down
13 changes: 11 additions & 2 deletions adafruit_rsa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
"""

from adafruit_rsa.key import newkeys, PrivateKey, PublicKey
from adafruit_rsa.pkcs1 import encrypt, decrypt, sign, verify, DecryptionError, \
VerificationError, find_signature_hash, sign_hash, compute_hash
from adafruit_rsa.pkcs1 import (
encrypt,
decrypt,
sign,
verify,
DecryptionError,
VerificationError,
find_signature_hash,
sign_hash,
compute_hash,
)

__author__ = "Sybren Stuvel, Barry Mead and Yesudeep Mangalapilly"
__date__ = "2018-09-16"
Expand Down
16 changes: 6 additions & 10 deletions adafruit_rsa/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
MACHINE_WORD_SIZE = 64


INTEGER_TYPES = (int, )
# pylint: disable=redefined-builtin, invalid-name
range = range
zip = zip
INTEGER_TYPES = (int,)


def write_to_stdout(data):
Expand Down Expand Up @@ -112,8 +109,7 @@ def xor_bytes(bytes_1, bytes_2):
return bytes(x ^ y for x, y in zip(bytes_1, bytes_2))


def get_word_alignment(num, force_arch=64,
_machine_word_size=MACHINE_WORD_SIZE):
def get_word_alignment(num, force_arch=64, _machine_word_size=MACHINE_WORD_SIZE):
"""
Returns alignment details for the given number based on the platform
Python is running on.
Expand All @@ -132,10 +128,10 @@ def get_word_alignment(num, force_arch=64,
(word_bits, word_bytes,
max_uint, packing_format_type)
"""
max_uint64 = 0xffffffffffffffff
max_uint32 = 0xffffffff
max_uint16 = 0xffff
max_uint8 = 0xff
max_uint64 = 0xFFFFFFFFFFFFFFFF
max_uint32 = 0xFFFFFFFF
max_uint16 = 0xFFFF
max_uint8 = 0xFF

if force_arch == 64 and _machine_word_size >= 64 and num > max_uint32:
# 64-bit unsigned integer.
Expand Down
22 changes: 14 additions & 8 deletions adafruit_rsa/asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"


class PubKeyHeader(univ.Sequence):
"""OpenSSL Public Key Header"""

componentType = namedtype.NamedTypes(
namedtype.NamedType('oid', univ.ObjectIdentifier()),
namedtype.NamedType('parameters', univ.Null()),
namedtype.NamedType("oid", univ.ObjectIdentifier()),
namedtype.NamedType("parameters", univ.Null()),
)


class OpenSSLPubKey(univ.Sequence):
"""Creates a PKCS#1 DER-encoded NamedType."""
componentType = namedtype.NamedTypes(
namedtype.NamedType('header', PubKeyHeader()),

componentType = namedtype.NamedTypes(
namedtype.NamedType("header", PubKeyHeader()),
# This little hack (the implicit tag) allows us to get a Bit String as Octet String
namedtype.NamedType('key', univ.OctetString().subtype(
implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3))),
namedtype.NamedType(
"key",
univ.OctetString().subtype(
implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3)
),
),
)


Expand All @@ -53,6 +59,6 @@ class AsnPubKey(univ.Sequence):
"""

componentType = namedtype.NamedTypes(
namedtype.NamedType('modulus', univ.Integer()),
namedtype.NamedType('publicExponent', univ.Integer()),
namedtype.NamedType("modulus", univ.Integer()),
namedtype.NamedType("publicExponent", univ.Integer()),
)
10 changes: 6 additions & 4 deletions adafruit_rsa/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# limitations under the License.
"""Common functionality shared by several modules."""

# pylint: disable=redefined-builtin, invalid-name
from adafruit_rsa._compat import zip
# pylint: disable=invalid-name

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"


def bit_length(int_type):
"""Return the number of bits necessary to represent an integer in binary,
excluding the sign and leading zeros"""
Expand All @@ -33,9 +33,11 @@ def bit_length(int_type):

class NotRelativePrimeError(ValueError):
"""Raises if provided a and b not relatively prime."""

def __init__(self, a, b, d, msg=None):
super(NotRelativePrimeError, self).__init__(
msg or "%d and %d are not relatively prime, divider=%i" % (a, b, d))
msg or "%d and %d are not relatively prime, divider=%i" % (a, b, d)
)
self.a = a
self.b = b
self.d = d
Expand Down Expand Up @@ -66,7 +68,7 @@ def bit_size(num):
try:
return bit_length(num)
except AttributeError:
raise TypeError('bit_size(num) only supports integers, not %r' % type(num))
raise TypeError("bit_size(num) only supports integers, not %r" % type(num))


def byte_size(number):
Expand Down
23 changes: 12 additions & 11 deletions adafruit_rsa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"


def fast_pow(x, e, m):
"""Performs fast modular exponentiation, saves RAM on small CPUs/micros.
:param int x: Base
Expand All @@ -38,7 +39,7 @@ def fast_pow(x, e, m):
while E > 0:
if E % 2 == 0:
X = (X * X) % m
E = E//2
E = E // 2
else:
Y = (X * Y) % m
E = E - 1
Expand All @@ -50,33 +51,33 @@ def assert_int(var, name):
if is_integer(var):
return

raise TypeError('%s should be an integer, not %s' % (name, var.__class__))
raise TypeError("%s should be an integer, not %s" % (name, var.__class__))


def encrypt_int(message, ekey, n):
"""Encrypts a message using encryption key 'ekey', working modulo n"""

assert_int(message, 'message')
assert_int(ekey, 'ekey')
assert_int(n, 'n')
assert_int(message, "message")
assert_int(ekey, "ekey")
assert_int(n, "n")

if message < 0:
raise ValueError('Only non-negative numbers are supported')
raise ValueError("Only non-negative numbers are supported")

if message > n:
raise OverflowError("The message %i is too long for n=%i" % (message, n))

#return pow(message, ekey, n)
#print('fast_pow({},{},{})'.format(message,ekey,n))
# return pow(message, ekey, n)
# print('fast_pow({},{},{})'.format(message,ekey,n))
return fast_pow(message, ekey, n)


def decrypt_int(cyphertext, dkey, n):
"""Decrypts a cypher text using the decryption key 'dkey', working modulo n"""

assert_int(cyphertext, 'cyphertext')
assert_int(dkey, 'dkey')
assert_int(n, 'n')
assert_int(cyphertext, "cyphertext")
assert_int(dkey, "dkey")
assert_int(n, "n")

message = fast_pow(cyphertext, dkey, n)
return message
Loading