diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-02-04 16:19:37 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-02-04 16:19:37 -0600 |
commit | 27864789563c90edb42772a9af1602be87029abc (patch) | |
tree | cc9e19b60b3c3fd4fa13638f3482ad5a501051a2 | |
parent | 1389acbfa1fb90cdabe93810c30b481e9d3e4042 (diff) | |
download | cryptography-27864789563c90edb42772a9af1602be87029abc.tar.gz cryptography-27864789563c90edb42772a9af1602be87029abc.tar.bz2 cryptography-27864789563c90edb42772a9af1602be87029abc.zip |
add some more comments to clarify what the ENGINE_ calls in backend do
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 4dd544cf..31ffe0d1 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -61,34 +61,48 @@ class Backend(object): self.activate_osrandom_engine() def deactivate_osrandom_engine(self): + # obtains a new structural reference e = self._lib.ENGINE_get_default_RAND() if e != self._ffi.NULL: + # this obtains the name of the engine but does not obtain a + # structural or functional reference name = self._lib.ENGINE_get_name(e) assert name != self._ffi.NULL if name == self._lib.Cryptography_osrandom_engine_name: + # removes the engine provided from the list of available RAND + # engines. self._lib.ENGINE_unregister_RAND(e) # this resets the RNG to use the new engine self._lib.RAND_cleanup() + # decrement the structural reference from get_default_RAND res = self._lib.ENGINE_finish(e) assert res == 1 def activate_osrandom_engine(self): + # obtains a new structural reference current_rand = self._lib.ENGINE_get_default_RAND() if current_rand != self._ffi.NULL: + # this obtains the name of the engine but does not obtain a + # structural or functional reference name = self._lib.ENGINE_get_name(current_rand) assert name != self._ffi.NULL if name != self._lib.Cryptography_osrandom_engine_name: self._activate_osrandom_engine() + # decrement the structural reference from get_default_RAND res = self._lib.ENGINE_finish(current_rand) assert res == 1 else: self._activate_osrandom_engine() def _activate_osrandom_engine(self): + # Fetches an engine by id and returns it. This creates a structural + # reference. e = self._lib.ENGINE_by_id(self._lib.Cryptography_osrandom_engine_id) assert e != self._ffi.NULL + # Initialize the engine for use. This adds a functional reference. res = self._lib.ENGINE_init(e) assert res == 1 + # Set the engine as the default RAND provider. res = self._lib.ENGINE_set_default_RAND(e) assert res == 1 # decrement the structural ref incremented by ENGINE_by_id @@ -97,7 +111,7 @@ class Backend(object): # decrement the functional ref incremented by ENGINE_init res = self._lib.ENGINE_finish(e) assert res == 1 - # this resets the RNG to use the new engine + # Reset the RNG to use the new engine self._lib.RAND_cleanup() def openssl_version_text(self): |