diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-08-30 22:46:10 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-08-30 22:46:10 -0700 |
commit | 5c02ef3260aa4ffc5920aca4bc5d8aa88b430c14 (patch) | |
tree | b4fcf2d3536847db088510690fe4f3ff09bda22b | |
parent | 6959a168b19e626bfb301e7d8fb82a7a08df9d30 (diff) | |
download | cryptography-5c02ef3260aa4ffc5920aca4bc5d8aa88b430c14.tar.gz cryptography-5c02ef3260aa4ffc5920aca4bc5d8aa88b430c14.tar.bz2 cryptography-5c02ef3260aa4ffc5920aca4bc5d8aa88b430c14.zip |
Replace paths we have no idea how to test with asserts
-rw-r--r-- | cryptography/bindings/openssl/api.py | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 58adaa88..3fdde06f 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -16,18 +16,6 @@ from __future__ import absolute_import, division, print_function import cffi -class OpenSSLError(Exception): - def __init__(self, api): - e = api._lib.ERR_get_error() - if e == 0: - raise SystemError( - "Tried to create an OpenSSLError when there was None" - ) - msg = api._ffi.new("char[]", 120) - api._lib.ERR_error_string(e, msg) - super(OpenSSLError, self).__init__(api._ffi.string(msg)) - - class API(object): """ OpenSSL API wrapper. @@ -77,16 +65,14 @@ class API(object): cipher.name, cipher.key_size, mode.name ) evp_cipher = self._lib.EVP_get_cipherbyname(ciphername.encode("ascii")) - if evp_cipher == self._ffi.NULL: - raise OpenSSLError(self) + assert evp_cipher != self._ffi.NULL # TODO: only use the key and initialization_vector as needed. Sometimes # this needs to be a DecryptInit, when? res = self._lib.EVP_EncryptInit_ex( ctx, evp_cipher, self._ffi.NULL, cipher.key, mode.initialization_vector ) - if res == 0: - raise OpenSSLError(self) + assert res != 0 # We purposely disable padding here as it's handled higher up in the # API. @@ -99,8 +85,7 @@ class API(object): res = self._lib.EVP_EncryptUpdate( ctx, buf, outlen, plaintext, len(plaintext) ) - if res == 0: - raise OpenSSLError(self) + assert res != 0 return self._ffi.buffer(buf)[:outlen[0]] def finalize_encrypt_context(self, ctx): @@ -109,11 +94,9 @@ class API(object): buf = self._ffi.new("unsigned char[]", block_size) outlen = self._ffi.new("int *") res = self._lib.EVP_EncryptFinal_ex(ctx, buf, outlen) - if res == 0: - raise OpenSSLError(self) + assert res != 0 res = self._lib.EVP_CIPHER_CTX_cleanup(ctx) - if res == 0: - raise OpenSSLError(self) + assert res != 0 return self._ffi.buffer(buf)[:outlen[0]] |