Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/key.py
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | class CECKey(): | ||||
def get_ecdh_key(self, other_pubkey, kdf=lambda k: hashlib.sha256(k).digest()): | def get_ecdh_key(self, other_pubkey, kdf=lambda k: hashlib.sha256(k).digest()): | ||||
# FIXME: be warned it's not clear what the kdf should be as a default | # FIXME: be warned it's not clear what the kdf should be as a default | ||||
r = self.get_raw_ecdh_key(other_pubkey) | r = self.get_raw_ecdh_key(other_pubkey) | ||||
return kdf(r) | return kdf(r) | ||||
def sign(self, hash, low_s=True): | def sign(self, hash, low_s=True): | ||||
# FIXME: need unit tests for below cases | # FIXME: need unit tests for below cases | ||||
if not isinstance(hash, bytes): | if not isinstance(hash, bytes): | ||||
raise TypeError('Hash must be bytes instance; got %r' % | raise TypeError( | ||||
hash.__class__) | 'Hash must be bytes instance; got {!r}'.format(hash.__class__)) | ||||
if len(hash) != 32: | if len(hash) != 32: | ||||
raise ValueError('Hash must be exactly 32 bytes long') | raise ValueError('Hash must be exactly 32 bytes long') | ||||
sig_size0 = ctypes.c_uint32() | sig_size0 = ctypes.c_uint32() | ||||
sig_size0.value = ssl.ECDSA_size(self.k) | sig_size0.value = ssl.ECDSA_size(self.k) | ||||
mb_sig = ctypes.create_string_buffer(sig_size0.value) | mb_sig = ctypes.create_string_buffer(sig_size0.value) | ||||
result = ssl.ECDSA_sign(0, hash, len( | result = ssl.ECDSA_sign(0, hash, len( | ||||
hash), mb_sig, ctypes.byref(sig_size0), self.k) | hash), mb_sig, ctypes.byref(sig_size0), self.k) | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | class CPubKey(bytes): | ||||
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 | # Always have represent as b'<secret>' so test cases don't have to | ||||
# change for py2/3 | # change for py2/3 | ||||
if sys.version > '3': | if sys.version > '3': | ||||
return '%s(%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__()) | return '{}({})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) | ||||
else: | else: | ||||
return '%s(b%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__()) | return '{}(b{})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) |