Refactoring crypto base changes #1806

Merged
g1itch merged 14 commits from crypto-sort into v0.6 2021-08-17 15:07:33 +02:00
Showing only changes of commit 519bdfe175 - Show all commits

View File

@ -1,8 +1,7 @@
""" """
Operations with addresses Operations with addresses
""" """
# pylint: disable=redefined-outer-name,inconsistent-return-statements # pylint: disable=inconsistent-return-statements
import sys
import hashlib import hashlib
import logging import logging
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
@ -151,12 +150,6 @@ def encodeAddress(version, stream, ripe):
' a given ripe hash was not 20.' ' a given ripe hash was not 20.'
) )
if isinstance(ripe, str):
if ripe[:2] == '\x00\x00':
ripe = ripe[2:]
elif ripe[:1] == '\x00':
ripe = ripe[1:]
else:
if ripe[:2] == b'\x00\x00': if ripe[:2] == b'\x00\x00':
ripe = ripe[2:] ripe = ripe[2:]
elif ripe[:1] == b'\x00': elif ripe[:1] == b'\x00':
@ -166,14 +159,8 @@ def encodeAddress(version, stream, ripe):
raise Exception( raise Exception(
'Programming error in encodeAddress: The length of' 'Programming error in encodeAddress: The length of'
' a given ripe hash was not 20.') ' a given ripe hash was not 20.')
ripe = ripe.lstrip('\x00') ripe = ripe.lstrip(b'\x00')
if sys.version_info[0] == 3:
if isinstance(ripe, str):
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe.encode('utf-8')
else:
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
else:
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
# Generate the checksum # Generate the checksum
@ -184,7 +171,10 @@ def encodeAddress(version, stream, ripe):
sha.update(currentHash) sha.update(currentHash)
checksum = sha.digest()[0:4] checksum = sha.digest()[0:4]
# FIXME: encodeBase58 should take binary data, to reduce conversions
# encodeBase58(storedBinaryData + checksum)
asInt = int(hexlify(storedBinaryData) + hexlify(checksum), 16) asInt = int(hexlify(storedBinaryData) + hexlify(checksum), 16)
# should it be str? If yes, it should be everywhere in the code
return 'BM-' + encodeBase58(asInt) return 'BM-' + encodeBase58(asInt)