Skip to content

Commit

Permalink
merge bitcoin#22633: Replace remaining binascii method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Jul 23, 2024
1 parent b37f609 commit ad96ef2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions contrib/linearize/linearize-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import time
import glob
from collections import namedtuple
from binascii import unhexlify

settings = {}

Expand Down Expand Up @@ -324,7 +323,7 @@ def run(self):
settings['max_out_sz'] = int(settings['max_out_sz'])
settings['split_timestamp'] = int(settings['split_timestamp'])
settings['file_timestamp'] = int(settings['file_timestamp'])
settings['netmagic'] = unhexlify(settings['netmagic'].encode('utf-8'))
settings['netmagic'] = bytes.fromhex(settings['netmagic'])
settings['out_of_order_cache_sz'] = int(settings['out_of_order_cache_sz'])
settings['debug_output'] = settings['debug_output'].lower()

Expand Down
3 changes: 1 addition & 2 deletions share/rpcauth/rpcauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

from argparse import ArgumentParser
from base64 import urlsafe_b64encode
from binascii import hexlify
from getpass import getpass
from os import urandom

import hmac

def generate_salt(size):
"""Create size byte hex salt"""
return hexlify(urandom(size)).decode()
return urandom(size).hex()

def generate_password():
"""Create 32 byte b64 password"""
Expand Down
5 changes: 3 additions & 2 deletions src/test/serfloat_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ BOOST_AUTO_TEST_CASE(double_serfloat_tests) {
Python code to generate the below hashes:
def reversed_hex(x):
return binascii.hexlify(''.join(reversed(x)))
return bytes(reversed(x)).hex()
def dsha256(x):
return hashlib.sha256(hashlib.sha256(x).digest()).digest()
reversed_hex(dsha256(''.join(struct.pack('<d', x) for x in range(0,1000)))) == '43d0c82591953c4eafe114590d392676a01585d25b25d433557f0d7878b23f96'
reversed_hex(dsha256(b''.join(struct.pack('<d', x) for x in range(0,1000)))) == '43d0c82591953c4eafe114590d392676a01585d25b25d433557f0d7878b23f96'
*/
BOOST_AUTO_TEST_CASE(doubles)
{
Expand Down
3 changes: 1 addition & 2 deletions test/util/bitcoin-util-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Can also be run manually."""

import argparse
import binascii
import configparser
import difflib
import json
Expand Down Expand Up @@ -167,7 +166,7 @@ def parse_output(a, fmt):
if fmt == 'json': # json: compare parsed data
return json.loads(a)
elif fmt == 'hex': # hex: parse and compare binary data
return binascii.a2b_hex(a.strip())
return bytes.fromhex(a.strip())
else:
raise NotImplementedError("Don't know how to compare %s" % fmt)

Expand Down

0 comments on commit ad96ef2

Please sign in to comment.