Cryptography_add_osrandom_engine should be safe to call multiple times

This commit is contained in:
Paul Kehrer 2014-02-20 21:21:47 -06:00
parent d2f24580aa
commit 7f25030b53
2 changed files with 8 additions and 1 deletions

View file

@ -98,7 +98,7 @@ class Binding(object):
_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):

View file

@ -175,6 +175,13 @@ static RAND_METHOD osrandom_rand = {
};
int Cryptography_add_osrandom_engine(void) {
ENGINE *engine = ENGINE_by_id(Cryptography_osrandom_engine_id);
if (engine != NULL) {
// The engine has already been added,
ENGINE_free(engine);
return 2;
}
ENGINE *e = ENGINE_new();
if (e == NULL) {
return 0;