From fbc33b1df6792a34e77de9a8deec4b46e6ef67a5 Mon Sep 17 00:00:00 2001 From: "jai.s" Date: Fri, 18 Sep 2020 20:31:04 +0530 Subject: [PATCH] Solved test_blind_sig issue --- .travis.yml | 2 +- src/debug.py | 2 +- src/pyelliptic/openssl.py | 29 ++++++++++++++++++++--------- src/tests/test_blindsig.py | 8 ++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c53654d..1df0c371 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,5 @@ install: - python setup.py install script: - python checkdeps.py - - xvfb-run src/bitmessagemain.py -t + - xvfb-run pybitmessage -t - python setup.py test diff --git a/src/debug.py b/src/debug.py index 12c55784..fa6e4758 100755 --- a/src/debug.py +++ b/src/debug.py @@ -52,7 +52,7 @@ helper_startup.loadConfig() # logging.config.fileConfig interface # examples are here: # https://bitmessage.org/forum/index.php/topic,4820.msg11163.html#msg11163 -log_level = 'DEBUG' +log_level = 'WARNING' def log_uncaught_exceptions(ex_cls, ex, tb): """The last resort logging function used for sys.excepthook""" diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index 6d091067..c2572a86 100755 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -659,7 +659,7 @@ class _OpenSSL(object): """ returns the length of a BN (OpenSSl API) """ - return int((self.BN_num_bits(x) + 7) / 8) + return int((self.BN_num_bits(x) + 7) // 8) def BN_is_odd_compatible(self, x): """ @@ -721,16 +721,27 @@ class _OpenSSL(object): """ returns a create_string_buffer (ctypes) """ - buffer_ = None - if data != 0: - if sys.version_info.major == 3 and isinstance(data, type('')): - data = data.encode() - buffer_ = self.create_string_buffer(bytes(data), size) - else: - buffer_ = self.create_string_buffer(bytes(size)) - return buffer_ + return self.create_string_buffer_with_bytes(data, size) + def create_string_buffer_with_bytes(self, data, size): + buffer_ = None + try: + if data != 0: + if sys.version_info.major == 3 and isinstance(data, type('')): + data = data.encode() + buffer_ = self.create_string_buffer(data, size) + else: + buffer_ = self.create_string_buffer(size) + except: + if data != 0: + if sys.version_info.major == 3 and isinstance(data, type('')): + data = data.encode() + buffer_ = self.create_string_buffer(bytes(data), size) + else: + buffer_ = self.create_string_buffer(bytes(size)) + return buffer_ + def loadOpenSSL(): """Method find and load the OpenSSL library""" # pylint: disable=global-statement, protected-access, too-many-branches diff --git a/src/tests/test_blindsig.py b/src/tests/test_blindsig.py index 552cff1e..f429fc51 100755 --- a/src/tests/test_blindsig.py +++ b/src/tests/test_blindsig.py @@ -31,7 +31,7 @@ class TestBlindSig(unittest.TestCase): # only 64 byte messages are planned to be used in Bitmessage msg = os.urandom(64) msg_blinded = requester_obj.create_signing_request(point_r, msg) - self.assertEqual(len(msg_blinded), 33) + self.assertEqual(len(msg_blinded), 32) # check self.assertNotEqual(sha256(msg).digest(), msg_blinded) @@ -39,18 +39,18 @@ class TestBlindSig(unittest.TestCase): # (3) Signature Generation signature_blinded = signer_obj.blind_sign(msg_blinded) assert isinstance(signature_blinded, bytes) - self.assertEqual(len(signature_blinded), 33) + self.assertEqual(len(signature_blinded), 32) # (4) Extraction signature = requester_obj.unblind(signature_blinded) assert isinstance(signature, bytes) - self.assertEqual(len(signature), 66) + self.assertEqual(len(signature), 65) self.assertNotEqual(signature, signature_blinded) # (5) Verification verifier_obj = ECCBlind(pubkey=signer_obj.pubkey()) - self.assertTrue(verifier_obj.verify(msg, signature[1:])) + self.assertTrue(verifier_obj.verify(msg, signature)) def test_is_odd(self): """Test our implementation of BN_is_odd"""