Skip to content

Commit 7ca5acb

Browse files
committed
Ran black, updated to pylint 2.x
1 parent 39330c6 commit 7ca5acb

File tree

18 files changed

+298
-241
lines changed

18 files changed

+298
-241
lines changed

.pylintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
55-
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error
55+
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option
@@ -124,7 +124,6 @@ notes=FIXME,XXX
124124

125125

126126
[TYPECHECK]
127-
disable=bad-option-value
128127

129128
# List of decorators that produce context managers, such as
130129
# contextlib.contextmanager. Add to this list to register other decorators that

adafruit_rsa/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@
2424
"""
2525

2626
from adafruit_rsa.key import newkeys, PrivateKey, PublicKey
27-
from adafruit_rsa.pkcs1 import encrypt, decrypt, sign, verify, DecryptionError, \
28-
VerificationError, find_signature_hash, sign_hash, compute_hash
27+
from adafruit_rsa.pkcs1 import (
28+
encrypt,
29+
decrypt,
30+
sign,
31+
verify,
32+
DecryptionError,
33+
VerificationError,
34+
find_signature_hash,
35+
sign_hash,
36+
compute_hash,
37+
)
2938

3039
__author__ = "Sybren Stuvel, Barry Mead and Yesudeep Mangalapilly"
3140
__date__ = "2018-09-16"

adafruit_rsa/_compat.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
MACHINE_WORD_SIZE = 64
4040

4141

42-
INTEGER_TYPES = (int, )
43-
# pylint: disable=redefined-builtin, invalid-name
44-
range = range
45-
zip = zip
42+
INTEGER_TYPES = (int,)
4643

4744

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

114111

115-
def get_word_alignment(num, force_arch=64,
116-
_machine_word_size=MACHINE_WORD_SIZE):
112+
def get_word_alignment(num, force_arch=64, _machine_word_size=MACHINE_WORD_SIZE):
117113
"""
118114
Returns alignment details for the given number based on the platform
119115
Python is running on.
@@ -132,10 +128,10 @@ def get_word_alignment(num, force_arch=64,
132128
(word_bits, word_bytes,
133129
max_uint, packing_format_type)
134130
"""
135-
max_uint64 = 0xffffffffffffffff
136-
max_uint32 = 0xffffffff
137-
max_uint16 = 0xffff
138-
max_uint8 = 0xff
131+
max_uint64 = 0xFFFFFFFFFFFFFFFF
132+
max_uint32 = 0xFFFFFFFF
133+
max_uint16 = 0xFFFF
134+
max_uint8 = 0xFF
139135

140136
if force_arch == 64 and _machine_word_size >= 64 and num > max_uint32:
141137
# 64-bit unsigned integer.

adafruit_rsa/asn1.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,28 @@
2525
__version__ = "0.0.0-auto.0"
2626
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"
2727

28+
2829
class PubKeyHeader(univ.Sequence):
2930
"""OpenSSL Public Key Header"""
31+
3032
componentType = namedtype.NamedTypes(
31-
namedtype.NamedType('oid', univ.ObjectIdentifier()),
32-
namedtype.NamedType('parameters', univ.Null()),
33+
namedtype.NamedType("oid", univ.ObjectIdentifier()),
34+
namedtype.NamedType("parameters", univ.Null()),
3335
)
3436

3537

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

41+
componentType = namedtype.NamedTypes(
42+
namedtype.NamedType("header", PubKeyHeader()),
4143
# This little hack (the implicit tag) allows us to get a Bit String as Octet String
42-
namedtype.NamedType('key', univ.OctetString().subtype(
43-
implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3))),
44+
namedtype.NamedType(
45+
"key",
46+
univ.OctetString().subtype(
47+
implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3)
48+
),
49+
),
4450
)
4551

4652

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

5561
componentType = namedtype.NamedTypes(
56-
namedtype.NamedType('modulus', univ.Integer()),
57-
namedtype.NamedType('publicExponent', univ.Integer()),
62+
namedtype.NamedType("modulus", univ.Integer()),
63+
namedtype.NamedType("publicExponent", univ.Integer()),
5864
)

adafruit_rsa/common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
# limitations under the License.
1616
"""Common functionality shared by several modules."""
1717

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

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

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

3434
class NotRelativePrimeError(ValueError):
3535
"""Raises if provided a and b not relatively prime."""
36+
3637
def __init__(self, a, b, d, msg=None):
3738
super(NotRelativePrimeError, self).__init__(
38-
msg or "%d and %d are not relatively prime, divider=%i" % (a, b, d))
39+
msg or "%d and %d are not relatively prime, divider=%i" % (a, b, d)
40+
)
3941
self.a = a
4042
self.b = b
4143
self.d = d
@@ -66,7 +68,7 @@ def bit_size(num):
6668
try:
6769
return bit_length(num)
6870
except AttributeError:
69-
raise TypeError('bit_size(num) only supports integers, not %r' % type(num))
71+
raise TypeError("bit_size(num) only supports integers, not %r" % type(num))
7072

7173

7274
def byte_size(number):

adafruit_rsa/core.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__version__ = "0.0.0-auto.0"
2727
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RSA.git"
2828

29+
2930
def fast_pow(x, e, m):
3031
"""Performs fast modular exponentiation, saves RAM on small CPUs/micros.
3132
:param int x: Base
@@ -38,7 +39,7 @@ def fast_pow(x, e, m):
3839
while E > 0:
3940
if E % 2 == 0:
4041
X = (X * X) % m
41-
E = E//2
42+
E = E // 2
4243
else:
4344
Y = (X * Y) % m
4445
E = E - 1
@@ -50,33 +51,33 @@ def assert_int(var, name):
5051
if is_integer(var):
5152
return
5253

53-
raise TypeError('%s should be an integer, not %s' % (name, var.__class__))
54+
raise TypeError("%s should be an integer, not %s" % (name, var.__class__))
5455

5556

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

59-
assert_int(message, 'message')
60-
assert_int(ekey, 'ekey')
61-
assert_int(n, 'n')
60+
assert_int(message, "message")
61+
assert_int(ekey, "ekey")
62+
assert_int(n, "n")
6263

6364
if message < 0:
64-
raise ValueError('Only non-negative numbers are supported')
65+
raise ValueError("Only non-negative numbers are supported")
6566

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

69-
#return pow(message, ekey, n)
70-
#print('fast_pow({},{},{})'.format(message,ekey,n))
70+
# return pow(message, ekey, n)
71+
# print('fast_pow({},{},{})'.format(message,ekey,n))
7172
return fast_pow(message, ekey, n)
7273

7374

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

77-
assert_int(cyphertext, 'cyphertext')
78-
assert_int(dkey, 'dkey')
79-
assert_int(n, 'n')
78+
assert_int(cyphertext, "cyphertext")
79+
assert_int(dkey, "dkey")
80+
assert_int(n, "n")
8081

8182
message = fast_pow(cyphertext, dkey, n)
8283
return message

0 commit comments

Comments
 (0)