aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/backends/test_openssl.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-12-19 19:31:26 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2015-12-19 19:31:26 -0500
commit0021fd9ad002568ef90dc85131797c0eba3eca58 (patch)
treed3ba2eecf77f393f05ae8e4b416c5150bb28bd8e /tests/hazmat/backends/test_openssl.py
parente3f46c6d228161957e0549bfa838ba8791c1bb36 (diff)
parentc8b893f453f7ac47ff6d64ca1467099b0d1d252c (diff)
downloadcryptography-0021fd9ad002568ef90dc85131797c0eba3eca58.tar.gz
cryptography-0021fd9ad002568ef90dc85131797c0eba3eca58.tar.bz2
cryptography-0021fd9ad002568ef90dc85131797c0eba3eca58.zip
Merge pull request #2488 from tiran/password_cb_userdata
Change password callback to use userdata pointer
Diffstat (limited to 'tests/hazmat/backends/test_openssl.py')
-rw-r--r--tests/hazmat/backends/test_openssl.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 85331595..d048fe68 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -503,8 +503,21 @@ class TestOpenSSLSignX509Certificate(object):
class TestOpenSSLSerialisationWithOpenSSL(object):
def test_pem_password_cb_buffer_too_small(self):
- ffi_cb, cb = backend._pem_password_cb(b"aa")
- assert cb(None, 1, False, None) == 0
+ ffi_cb, userdata = backend._pem_password_cb(b"aa")
+ handle = backend._ffi.new_handle(userdata)
+ buf = backend._ffi.new('char *')
+ assert ffi_cb(buf, 1, False, handle) == 0
+ assert userdata.called == 1
+ assert isinstance(userdata.exception, ValueError)
+
+ def test_pem_password_cb(self):
+ password = b'abcdefg'
+ ffi_cb, userdata = backend._pem_password_cb(password)
+ handle = backend._ffi.new_handle(userdata)
+ buf = backend._ffi.new('char *')
+ assert ffi_cb(buf, len(password) + 1, False, handle) == len(password)
+ assert userdata.called == 1
+ assert backend._ffi.string(buf, len(password)) == password
def test_unsupported_evp_pkey_type(self):
key = pretend.stub(type="unsupported")