aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-02 15:20:50 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-02 15:20:50 -0600
commit9ad4d755bb3a2edfb8e46b60f6dfaff6365f0386 (patch)
tree3c73413bb67b2b447b4df186d84c4f3588a236d1
parentffa70965d610d2f4523a7d9e7ded879a06c6c2c0 (diff)
downloadcryptography-9ad4d755bb3a2edfb8e46b60f6dfaff6365f0386.tar.gz
cryptography-9ad4d755bb3a2edfb8e46b60f6dfaff6365f0386.tar.bz2
cryptography-9ad4d755bb3a2edfb8e46b60f6dfaff6365f0386.zip
handle lib/ffi on backend becoming private
-rw-r--r--cryptography/hazmat/backends/openssl/backend.py42
-rw-r--r--tests/hazmat/backends/test_openssl.py128
2 files changed, 85 insertions, 85 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py
index 0e6e3acf..089684ad 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -51,44 +51,44 @@ class Backend(object):
self.register_osrandom_engine()
def unregister_osrandom_engine(self):
- e = self.lib.ENGINE_get_default_RAND()
- if e != self.ffi.NULL:
- name = self.lib.ENGINE_get_name(e)
- assert name != self.ffi.NULL
- if name == self.lib.Cryptography_osrandom_engine_name:
- self.lib.ENGINE_unregister_RAND(e)
+ e = self._lib.ENGINE_get_default_RAND()
+ if e != self._ffi.NULL:
+ name = self._lib.ENGINE_get_name(e)
+ assert name != self._ffi.NULL
+ if name == self._lib.Cryptography_osrandom_engine_name:
+ self._lib.ENGINE_unregister_RAND(e)
# this resets the RNG to use the new engine
- self.lib.RAND_cleanup()
- res = self.lib.ENGINE_finish(e)
+ self._lib.RAND_cleanup()
+ res = self._lib.ENGINE_finish(e)
assert res == 1
def register_osrandom_engine(self):
- current_rand = self.lib.ENGINE_get_default_RAND()
- if current_rand != self.ffi.NULL:
- name = self.lib.ENGINE_get_name(current_rand)
- assert name != self.ffi.NULL
- if name != self.lib.Cryptography_osrandom_engine_name:
+ current_rand = self._lib.ENGINE_get_default_RAND()
+ if current_rand != self._ffi.NULL:
+ name = self._lib.ENGINE_get_name(current_rand)
+ assert name != self._ffi.NULL
+ if name != self._lib.Cryptography_osrandom_engine_name:
self._register_osrandom_engine()
- res = self.lib.ENGINE_finish(current_rand)
+ res = self._lib.ENGINE_finish(current_rand)
assert res == 1
else:
self._register_osrandom_engine()
def _register_osrandom_engine(self):
- e = self.lib.ENGINE_by_id(self.lib.Cryptography_osrandom_engine_id)
- assert e != self.ffi.NULL
- res = self.lib.ENGINE_init(e)
+ e = self._lib.ENGINE_by_id(self._lib.Cryptography_osrandom_engine_id)
+ assert e != self._ffi.NULL
+ res = self._lib.ENGINE_init(e)
assert res == 1
- res = self.lib.ENGINE_set_default_RAND(e)
+ res = self._lib.ENGINE_set_default_RAND(e)
assert res == 1
# decrement the structural ref incremented by ENGINE_by_id
- res = self.lib.ENGINE_free(e)
+ res = self._lib.ENGINE_free(e)
assert res == 1
# decrement the functional ref incremented by ENGINE_init
- res = self.lib.ENGINE_finish(e)
+ res = self._lib.ENGINE_finish(e)
assert res == 1
# this resets the RNG to use the new engine
- self.lib.RAND_cleanup()
+ self._lib.RAND_cleanup()
def openssl_version_text(self):
"""
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 6fc1e583..b7d999b8 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -82,36 +82,36 @@ dummy_engine = ffi.verify(
def register_dummy_engine():
- current_rand = backend.lib.ENGINE_get_default_RAND()
- assert current_rand != backend.ffi.NULL
- name = backend.lib.ENGINE_get_name(current_rand)
- assert name != backend.ffi.NULL
+ current_rand = backend._lib.ENGINE_get_default_RAND()
+ assert current_rand != backend._ffi.NULL
+ name = backend._lib.ENGINE_get_name(current_rand)
+ assert name != backend._ffi.NULL
assert name != dummy_engine.Cryptography_faux_engine_id
- res = backend.lib.ENGINE_finish(current_rand)
+ res = backend._lib.ENGINE_finish(current_rand)
assert res == 1
- e = backend.lib.ENGINE_by_id(dummy_engine.Cryptography_faux_engine_id)
- assert e != backend.ffi.NULL
- res = backend.lib.ENGINE_init(e)
+ e = backend._lib.ENGINE_by_id(dummy_engine.Cryptography_faux_engine_id)
+ assert e != backend._ffi.NULL
+ res = backend._lib.ENGINE_init(e)
assert res == 1
- res = backend.lib.ENGINE_set_default_RAND(e)
+ res = backend._lib.ENGINE_set_default_RAND(e)
assert res == 1
- res = backend.lib.ENGINE_finish(e)
+ res = backend._lib.ENGINE_finish(e)
assert res == 1
- res = backend.lib.ENGINE_free(e)
+ res = backend._lib.ENGINE_free(e)
assert res == 1
# this resets the RNG to use the new engine
- backend.lib.RAND_cleanup()
+ backend._lib.RAND_cleanup()
def unregister_dummy_engine():
- e = backend.lib.ENGINE_get_default_RAND()
- if e != backend.ffi.NULL:
- name = backend.lib.ENGINE_get_name(e)
- assert name != backend.ffi.NULL
+ e = backend._lib.ENGINE_get_default_RAND()
+ if e != backend._ffi.NULL:
+ name = backend._lib.ENGINE_get_name(e)
+ assert name != backend._ffi.NULL
if name == dummy_engine.Cryptography_faux_engine_name:
- backend.lib.ENGINE_unregister_RAND(e)
- backend.lib.RAND_cleanup()
- res = backend.lib.ENGINE_finish(e)
+ backend._lib.ENGINE_unregister_RAND(e)
+ backend._lib.RAND_cleanup()
+ res = backend._lib.ENGINE_finish(e)
assert res == 1
@@ -188,10 +188,10 @@ class TestOpenSSL(object):
# This test is not in the next class because to check if it's really
# default we don't want to run the setup_method before it
def test_osrandom_engine_is_default(self):
- e = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(e)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_free(e)
+ e = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(e)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_free(e)
assert res == 1
@@ -207,77 +207,77 @@ class TestOpenSSLRandomEngine(object):
# for all these tests.
unregister_dummy_engine()
backend.register_osrandom_engine()
- current_default = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(current_default)
- assert name == backend.lib.Cryptography_osrandom_engine_name
+ current_default = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(current_default)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
def test_register_osrandom_already_default(self):
- e = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(e)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_free(e)
+ e = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(e)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_free(e)
assert res == 1
backend.register_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(e)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_free(e)
+ e = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(e)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_free(e)
assert res == 1
def test_unregister_osrandom_engine_nothing_registered(self):
backend.unregister_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- assert e == backend.ffi.NULL
+ e = backend._lib.ENGINE_get_default_RAND()
+ assert e == backend._ffi.NULL
backend.unregister_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- assert e == backend.ffi.NULL
+ e = backend._lib.ENGINE_get_default_RAND()
+ assert e == backend._ffi.NULL
def test_unregister_osrandom_engine(self):
- e = backend.lib.ENGINE_get_default_RAND()
- assert e != backend.ffi.NULL
- name = backend.lib.ENGINE_get_name(e)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_free(e)
+ e = backend._lib.ENGINE_get_default_RAND()
+ assert e != backend._ffi.NULL
+ name = backend._lib.ENGINE_get_name(e)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_free(e)
assert res == 1
backend.unregister_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- assert e == backend.ffi.NULL
+ e = backend._lib.ENGINE_get_default_RAND()
+ assert e == backend._ffi.NULL
def test_register_osrandom_no_default(self):
backend.unregister_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- assert e == backend.ffi.NULL
+ e = backend._lib.ENGINE_get_default_RAND()
+ assert e == backend._ffi.NULL
backend.register_osrandom_engine()
- e = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(e)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_free(e)
+ e = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(e)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_free(e)
assert res == 1
def test_unregister_osrandom_other_engine_default(self):
register_dummy_engine()
- default = backend.lib.ENGINE_get_default_RAND()
- default_name = backend.lib.ENGINE_get_name(default)
+ default = backend._lib.ENGINE_get_default_RAND()
+ default_name = backend._lib.ENGINE_get_name(default)
assert default_name == dummy_engine.Cryptography_faux_engine_name
- res = backend.lib.ENGINE_finish(default)
+ res = backend._lib.ENGINE_finish(default)
assert res == 1
backend.unregister_osrandom_engine()
- current_default = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(current_default)
+ current_default = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(current_default)
assert name == dummy_engine.Cryptography_faux_engine_name
- res = backend.lib.ENGINE_finish(current_default)
+ res = backend._lib.ENGINE_finish(current_default)
assert res == 1
def test_register_osrandom_other_engine_default(self):
register_dummy_engine()
- default = backend.lib.ENGINE_get_default_RAND()
- default_name = backend.lib.ENGINE_get_name(default)
+ default = backend._lib.ENGINE_get_default_RAND()
+ default_name = backend._lib.ENGINE_get_name(default)
assert default_name == dummy_engine.Cryptography_faux_engine_name
- res = backend.lib.ENGINE_finish(default)
+ res = backend._lib.ENGINE_finish(default)
assert res == 1
backend.register_osrandom_engine()
- current_default = backend.lib.ENGINE_get_default_RAND()
- name = backend.lib.ENGINE_get_name(current_default)
- assert name == backend.lib.Cryptography_osrandom_engine_name
- res = backend.lib.ENGINE_finish(current_default)
+ current_default = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(current_default)
+ assert name == backend._lib.Cryptography_osrandom_engine_name
+ res = backend._lib.ENGINE_finish(current_default)
assert res == 1