summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2018-08-27 10:11:52 +0200
committerMatěj Cepl <mcepl@cepl.eu>2018-09-05 16:26:52 +0200
commit2f46736078140acedab3db502794c7617964510b (patch)
treebd5d6fb144449df0585900bc929d694654262b1d
parent173ec7473b67f8b4eead99ecaea401d4bb20a65a (diff)
downloadm2crypto-2f46736078140acedab3db502794c7617964510b.tar.gz
Make ctrl_cmd_string method more robust against type of arguments.
Technically speaking we prescribe in the type string that the paramteres should be str, but users don't like to care about the type of parameters. Fixes #228
-rw-r--r--M2Crypto/Engine.py13
-rw-r--r--tests/test_engine.py5
2 files changed, 13 insertions, 5 deletions
diff --git a/M2Crypto/Engine.py b/M2Crypto/Engine.py
index 96394a2..fa79e46 100644
--- a/M2Crypto/Engine.py
+++ b/M2Crypto/Engine.py
@@ -54,8 +54,11 @@ class Engine(object):
return m2.engine_finish(self._ptr)
def ctrl_cmd_string(self, cmd, arg, optional=0):
- # type: (bytes, Optional[bytes], int) -> int
+ # type: (AnyStr, Optional[AnyStr], int) -> None
"""Call ENGINE_ctrl_cmd_string"""
+ cmd = six.ensure_str(cmd)
+ if arg is not None:
+ arg = six.ensure_str(arg)
if not m2.engine_ctrl_cmd_string(self._ptr, cmd, arg, optional):
raise EngineError(Err.get_error())
@@ -121,10 +124,10 @@ def load_dynamic_engine(id, sopath):
sopath = sopath.encode('utf8')
m2.engine_load_dynamic()
e = Engine('dynamic')
- e.ctrl_cmd_string(b'SO_PATH', sopath)
- e.ctrl_cmd_string(b'ID', id)
- e.ctrl_cmd_string(b'LIST_ADD', '1')
- e.ctrl_cmd_string(b'LOAD', None)
+ e.ctrl_cmd_string('SO_PATH', sopath)
+ e.ctrl_cmd_string('ID', id)
+ e.ctrl_cmd_string('LIST_ADD', '1')
+ e.ctrl_cmd_string('LOAD', None)
return e
diff --git a/tests/test_engine.py b/tests/test_engine.py
index c2c6047..5439ee3 100644
--- a/tests/test_engine.py
+++ b/tests/test_engine.py
@@ -30,6 +30,11 @@ class EngineTestCase(unittest.TestCase):
Engine.load_dynamic()
Engine.Engine('dynamic')
+ def test_engine_ctrl_cmd_string(self):
+ Engine.load_dynamic()
+ e = Engine.Engine('dynamic')
+ e.ctrl_cmd_string('ID', 'TESTID')
+
def test_load_private(self):
Engine.load_openssl()
e = Engine.Engine('openssl')