From 55085af2087a03713a522c67970a2a738c5f5068 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Tue, 22 Oct 2019 19:04:32 +0530 Subject: [PATCH] py3 quality fixes --- src/highlevelcrypto.py | 4 +++- src/pyelliptic/arithmetic.py | 7 ++++--- src/pyelliptic/openssl.py | 2 +- src/shared.py | 10 ++++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index b9088f32..329ad68c 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -16,7 +16,9 @@ def makeCryptor(privkey): private_key = a.changebase(privkey, 16, 256, minlen=32) public_key = pointMult(private_key) privkey_bin = '\x02\xca\x00\x20'.encode('raw_unicode_escape') + private_key - pubkey_bin = '\x02\xca\x00\x20'.encode('raw_unicode_escape') + public_key[1:-32] + '\x00\x20'.encode('utf-8') + public_key[-32:] + pubkey_bin = '\x02\xca\x00\x20'.encode( + 'raw_unicode_escape') + public_key[1:-32] + '\x00\x20'.encode( + 'utf-8') + public_key[-32:] cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin) return cryptor diff --git a/src/pyelliptic/arithmetic.py b/src/pyelliptic/arithmetic.py index 2a5d29a9..031db6ae 100644 --- a/src/pyelliptic/arithmetic.py +++ b/src/pyelliptic/arithmetic.py @@ -1,4 +1,4 @@ -0# pylint: disable=missing-docstring,too-many-function-args +# pylint: disable=missing-docstring,too-many-function-args import hashlib import re @@ -30,7 +30,7 @@ def get_code_string(base): elif base == 58: return "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" elif base == 256: - '''raw_unicode_escape is used because in the python3 after range(161) its genreate the' + '''raw_unicode_escape is used because in the python3 after range(161) its genreate the speical character so avoiding that function we have used the raw_unicode method ''' return bytes(range(0, 256)) else: @@ -39,7 +39,7 @@ def get_code_string(base): def encode(val, base, minlen=0): code_string = get_code_string(base) - result = str.encode('') if type(code_string) == bytes else '' + result = str.encode('') if type(code_string) is bytes else '' while val > 0: result = code_string[val % base:val % base + 1] + result val = val // base @@ -47,6 +47,7 @@ def encode(val, base, minlen=0): result = code_string[0] * (minlen - len(result)) + result return result + def decode(string, base): code_string = get_code_string(base) result = 0 diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index 23de093e..3545fa52 100644 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -679,7 +679,7 @@ def loadOpenSSL(): path.join(sys._MEIPASS, 'libssl.so'), path.join(sys._MEIPASS, 'libcrypto.so.1.1.0'), path.join(sys._MEIPASS, 'libssl.so.1.1.0'), - path.join(sys._MEIPASS, 'libcrypto.so.1.0.2'), + path.join(sys._MEIPASS, 'libcrypto.so.1.0.2'), path.join(sys._MEIPASS, 'libssl.so.1.0.2'), path.join(sys._MEIPASS, 'libcrypto.so.1.0.1'), path.join(sys._MEIPASS, 'libssl.so.1.0.1'), diff --git a/src/shared.py b/src/shared.py index 9ab64f68..09830bde 100644 --- a/src/shared.py +++ b/src/shared.py @@ -89,6 +89,7 @@ def isAddressInMyAddressBookSubscriptionsListOrWhitelist(address): return True return False + def decodeWalletImportFormat(WIFstring): fullString = arithmetic.changebase(WIFstring, 58, 256) privkey = fullString[:-4] @@ -171,8 +172,9 @@ def reloadBroadcastSendersForWhichImWatching(): # we should create Cryptor objects in a dictionary which we will # use to attempt to decrypt encrypted broadcast messages. if addressVersionNumber <= 3: - privEncryptionKey = hashlib.sha512((encodeVarint(addressVersionNumber) \ - + encodeVarint(streamNumber) + hash)).digest()[:32] + privEncryptionKey = hashlib.sha512(( + encodeVarint(addressVersionNumber) + + encodeVarint(streamNumber) + hash)).digest()[:32] MyECSubscriptionCryptorObjects[hash] = \ highlevelcrypto.makeCryptor(hexlify(privEncryptionKey)) else: @@ -191,8 +193,8 @@ def fixPotentiallyInvalidUTF8Data(text): unicode(text, 'utf-8') return text except: - return 'Part of the message is corrupt. The message cannot be' \ - ' displayed the normal way.\n\n' + repr(text) + return 'Part of the message is corrupt. The message cannot be'\ + ' displayed the normal way.\n\n' + repr(text) # Checks sensitive file permissions for inappropriate umask