Merge pull request #670 from reaperhulk/0.2.1-bump-version
Bump version to 0.2.1 on 0.2.x branch for release
diff --git a/cryptography/hazmat/bindings/openssl/binding.py b/cryptography/hazmat/bindings/openssl/binding.py
index 714ecc0..0469a1e 100644
--- a/cryptography/hazmat/bindings/openssl/binding.py
+++ b/cryptography/hazmat/bindings/openssl/binding.py
@@ -98,7 +98,7 @@
_OSX_PRE_INCLUDE, _OSX_POST_INCLUDE,
libraries)
res = cls.lib.Cryptography_add_osrandom_engine()
- assert res == 1
+ assert res != 0
@classmethod
def is_available(cls):
diff --git a/cryptography/hazmat/bindings/openssl/osrandom_engine.py b/cryptography/hazmat/bindings/openssl/osrandom_engine.py
index 23f2e17..0903a4b 100644
--- a/cryptography/hazmat/bindings/openssl/osrandom_engine.py
+++ b/cryptography/hazmat/bindings/openssl/osrandom_engine.py
@@ -174,8 +174,19 @@
osrandom_rand_status,
};
+/* Returns 1 if successfully added, 2 if engine has previously been added,
+ and 0 for error. */
int Cryptography_add_osrandom_engine(void) {
- ENGINE *e = ENGINE_new();
+ ENGINE *e;
+ e = ENGINE_by_id(Cryptography_osrandom_engine_id);
+ if (e != NULL) {
+ ENGINE_free(e);
+ return 2;
+ } else {
+ ERR_clear_error();
+ }
+
+ e = ENGINE_new();
if (e == NULL) {
return 0;
}
diff --git a/docs/changelog.rst b/docs/changelog.rst
index d800c77..3e92906 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,10 @@
Changelog
=========
+0.2.1 - 2014-02-22
+~~~~~~~~~~~~~~~~~~
+* Fix a bug where importing cryptography from multiple paths could cause initialization to fail.
+
0.2 - 2014-02-20
~~~~~~~~~~~~~~~~
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 35eb7e8..c476390 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -96,3 +96,8 @@
# unlocked
assert lock.acquire(False)
lock.release()
+
+ def test_add_engine_more_than_once(self):
+ b = Binding()
+ res = b.lib.Cryptography_add_osrandom_engine()
+ assert res == 2