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
"""
# pylint: disable=redefined-outer-name,inconsistent-return-statements
import sys
# pylint: disable=inconsistent-return-statements
import hashlib
import logging
from binascii import hexlify, unhexlify
@ -151,30 +150,18 @@ def encodeAddress(version, stream, ripe):
' 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':
ripe = ripe[2:]
elif ripe[:1] == b'\x00':
ripe = ripe[1:]
if ripe[:2] == b'\x00\x00':
ripe = ripe[2:]
elif ripe[:1] == b'\x00':
ripe = ripe[1:]
elif version == 4:
if len(ripe) != 20:
raise Exception(
'Programming error in encodeAddress: The length of'
' 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
sha = hashlib.new('sha512')
@ -184,7 +171,10 @@ def encodeAddress(version, stream, ripe):
sha.update(currentHash)
checksum = sha.digest()[0:4]
# FIXME: encodeBase58 should take binary data, to reduce conversions
# encodeBase58(storedBinaryData + checksum)
asInt = int(hexlify(storedBinaryData) + hexlify(checksum), 16)
# should it be str? If yes, it should be everywhere in the code
return 'BM-' + encodeBase58(asInt)