Refactoring crypto base changes #1806
|
@ -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,30 +150,18 @@ 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] == b'\x00\x00':
|
||||||
if ripe[:2] == '\x00\x00':
|
ripe = ripe[2:]
|
||||||
ripe = ripe[2:]
|
elif ripe[:1] == b'\x00':
|
||||||
elif ripe[:1] == '\x00':
|
ripe = ripe[1:]
|
||||||
ripe = ripe[1:]
|
|
||||||
else:
|
|
||||||
if ripe[:2] == b'\x00\x00':
|
|
||||||
ripe = ripe[2:]
|
|
||||||
elif ripe[:1] == b'\x00':
|
|
||||||
ripe = ripe[1:]
|
|
||||||
elif version == 4:
|
elif version == 4:
|
||||||
if len(ripe) != 20:
|
if len(ripe) != 20:
|
||||||
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:
|
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
|
||||||
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
|
|
||||||
|
|
||||||
# Generate the checksum
|
# Generate the checksum
|
||||||
sha = hashlib.new('sha512')
|
sha = hashlib.new('sha512')
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user