Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/key.py
# Copyright (c) 2011 Sam Rushing | # Copyright (c) 2011 Sam Rushing | ||||
"""ECC secp256k1 OpenSSL wrapper. | """ECC secp256k1 OpenSSL wrapper. | ||||
WARNING: This module does not mlock() secrets; your private keys may end up on | WARNING: This module does not mlock() secrets; your private keys may end up on | ||||
disk in swap! Use with caution! | disk in swap! Use with caution! | ||||
This file is modified from python-bitcoinlib. | This file is modified from python-bitcoinlib. | ||||
""" | """ | ||||
import ctypes | import ctypes | ||||
import ctypes.util | import ctypes.util | ||||
import hashlib | import hashlib | ||||
import sys | |||||
ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32') | ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32') | ||||
ssl.BN_new.restype = ctypes.c_void_p | ssl.BN_new.restype = ctypes.c_void_p | ||||
ssl.BN_new.argtypes = [] | ssl.BN_new.argtypes = [] | ||||
ssl.BN_free.restype = None | ssl.BN_free.restype = None | ||||
ssl.BN_free.argtypes = [ctypes.c_void_p] | ssl.BN_free.argtypes = [ctypes.c_void_p] | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | class CPubKey(bytes): | ||||
def verify(self, hash, sig): | def verify(self, hash, sig): | ||||
return self._cec_key.verify(hash, sig) | return self._cec_key.verify(hash, sig) | ||||
def __str__(self): | def __str__(self): | ||||
return repr(self) | return repr(self) | ||||
def __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 '{}({})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) | return '{}({})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) | ||||
else: | |||||
return '{}(b{})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) |