Skip to content

Commit

Permalink
Merge bitcoin#12993: tests: Remove compatibility code not needed now …
Browse files Browse the repository at this point in the history
…when we're on Python 3

b95f9a6 tests: Remove compatibility code not needed now when we're on Python 3 (practicalswift)

Pull request description:

  Remove compatibility code not needed now when we're on Python 3.

Tree-SHA512: adc6422794ee08ee8d4c69268e74f0d3eb97c7d3c26c9573698c3305572f20d4840cf9f79fd6fbbe367699bbd95533f90fb6d8569b9787f3f9ca20a3f4c75dd7
  • Loading branch information
laanwj committed Apr 16, 2018
2 parents 6df0c6c + b95f9a6 commit 0d69921
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
11 changes: 2 additions & 9 deletions share/rpcauth/rpcauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

import hashlib
import sys
import os
from random import SystemRandom
Expand All @@ -25,15 +24,9 @@
salt = "".join([x[2:] for x in hexseq])

#Create 32 byte b64 password
password = base64.urlsafe_b64encode(os.urandom(32))

digestmod = hashlib.sha256

if sys.version_info.major >= 3:
password = password.decode('utf-8')
digestmod = 'SHA256'
password = base64.urlsafe_b64encode(os.urandom(32)).decode("utf-8")

m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), digestmod)
m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), "SHA256")
result = m.hexdigest()

print("String to be appended to bitcoin.conf:")
Expand Down
8 changes: 1 addition & 7 deletions test/functional/test_framework/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ctypes
import ctypes.util
import hashlib
import sys

ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library ('ssl') or 'libeay32')

Expand Down Expand Up @@ -223,10 +222,5 @@ def __str__(self):
return repr(self)

def __repr__(self):
# Always have represent as b'<secret>' so test cases don't have to
# change for py2/3
if sys.version > '3':
return '%s(%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())
else:
return '%s(b%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())
return '%s(%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())

31 changes: 11 additions & 20 deletions test/functional/test_framework/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
from .mininode import CTransaction, CTxOut, sha256, hash256, uint256_from_str, ser_uint256, ser_string
from binascii import hexlify
import hashlib

import sys
bchr = chr
bord = ord
if sys.version > '3':
long = int
bchr = lambda x: bytes([x])
bord = lambda x: x

import struct

from .bignum import bn2vch
Expand All @@ -40,9 +31,9 @@ class CScriptOp(int):
def encode_op_pushdata(d):
"""Encode a PUSHDATA op, returning bytes"""
if len(d) < 0x4c:
return b'' + bchr(len(d)) + d # OP_PUSHDATA
return b'' + bytes([len(d)]) + d # OP_PUSHDATA
elif len(d) <= 0xff:
return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1
return b'\x4c' + bytes([len(d)]) + d # OP_PUSHDATA1
elif len(d) <= 0xffff:
return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
elif len(d) <= 0xffffffff:
Expand Down Expand Up @@ -388,7 +379,7 @@ def encode(obj):
r.append(0x80 if neg else 0)
elif neg:
r[-1] |= 0x80
return bytes(bchr(len(r)) + r)
return bytes(bytes([len(r)]) + r)


class CScript(bytes):
Expand All @@ -405,17 +396,17 @@ class CScript(bytes):
def __coerce_instance(cls, other):
# Coerce other into bytes
if isinstance(other, CScriptOp):
other = bchr(other)
other = bytes([other])
elif isinstance(other, CScriptNum):
if (other.value == 0):
other = bchr(CScriptOp(OP_0))
other = bytes([CScriptOp(OP_0)])
else:
other = CScriptNum.encode(other)
elif isinstance(other, int):
if 0 <= other <= 16:
other = bytes(bchr(CScriptOp.encode_op_n(other)))
other = bytes(bytes([CScriptOp.encode_op_n(other)]))
elif other == -1:
other = bytes(bchr(OP_1NEGATE))
other = bytes(bytes([OP_1NEGATE]))
else:
other = CScriptOp.encode_op_pushdata(bn2vch(other))
elif isinstance(other, (bytes, bytearray)):
Expand Down Expand Up @@ -458,7 +449,7 @@ def raw_iter(self):
i = 0
while i < len(self):
sop_idx = i
opcode = bord(self[i])
opcode = self[i]
i += 1

if opcode > OP_PUSHDATA4:
Expand All @@ -474,21 +465,21 @@ def raw_iter(self):
pushdata_type = 'PUSHDATA1'
if i >= len(self):
raise CScriptInvalidError('PUSHDATA1: missing data length')
datasize = bord(self[i])
datasize = self[i]
i += 1

elif opcode == OP_PUSHDATA2:
pushdata_type = 'PUSHDATA2'
if i + 1 >= len(self):
raise CScriptInvalidError('PUSHDATA2: missing data length')
datasize = bord(self[i]) + (bord(self[i+1]) << 8)
datasize = self[i] + (self[i+1] << 8)
i += 2

elif opcode == OP_PUSHDATA4:
pushdata_type = 'PUSHDATA4'
if i + 3 >= len(self):
raise CScriptInvalidError('PUSHDATA4: missing data length')
datasize = bord(self[i]) + (bord(self[i+1]) << 8) + (bord(self[i+2]) << 16) + (bord(self[i+3]) << 24)
datasize = self[i] + (self[i+1] << 8) + (self[i+2] << 16) + (self[i+3] << 24)
i += 4

else:
Expand Down

0 comments on commit 0d69921

Please sign in to comment.