diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-08-09 10:42:44 -0700 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-08-09 10:42:44 -0700 |
| commit | de9a3ee2d2bea4b862d783c7dbf12cf15aa763a5 (patch) | |
| tree | ad7472aa129efa0c8d33c98d8f48a0a31f09c55e /cryptography | |
| parent | b1895f6f786b8be3bbaedf0b17ef1337b71bcfa1 (diff) | |
| download | cryptography-de9a3ee2d2bea4b862d783c7dbf12cf15aa763a5.tar.gz cryptography-de9a3ee2d2bea4b862d783c7dbf12cf15aa763a5.tar.bz2 cryptography-de9a3ee2d2bea4b862d783c7dbf12cf15aa763a5.zip | |
Get stuff working on py3k for real
Diffstat (limited to 'cryptography')
| -rw-r--r-- | cryptography/bindings/openssl/api.py | 18 | ||||
| -rw-r--r-- | cryptography/primitives/block/base.py | 1 |
2 files changed, 15 insertions, 4 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 7594fba6..78cbcbc3 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -37,6 +37,8 @@ class API(object): self._lib = ffi.verify(""" #include <openssl/evp.h> """) + self._lib.OpenSSL_add_all_algorithms() + self._lib.ERR_load_crypto_strings() def _populate_ffi(self, ffi): ffi.cdef(""" @@ -46,6 +48,9 @@ class API(object): typedef ... EVP_CIPHER; typedef ... ENGINE; + void OpenSSL_add_all_algorithms(); + void ERR_load_crypto_strings(); + const EVP_CIPHER *EVP_get_cipherbyname(const char *); int EVP_EncryptInit_ex(EVP_CIPHER_CTX *, const EVP_CIPHER *, ENGINE *, unsigned char *, unsigned char *); @@ -61,13 +66,18 @@ class API(object): def create_block_cipher_context(self, cipher, mode): ctx = self._ffi.new("EVP_CIPHER_CTX *") # TODO: compute name using a better algorithm - ciphername = "{0}-{1}-{2}".format(cipher.name, len(cipher.key) * 8, mode.name) + ciphername = "{0}-{1}-{2}".format( + cipher.name, len(cipher.key) * 8, mode.name + ) evp_cipher = self._lib.EVP_get_cipherbyname(ciphername.encode("ascii")) if evp_cipher == self._ffi.NULL: raise OpenSSLError(self) # 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) + res = self._lib.EVP_EncryptInit_ex( + ctx, evp_cipher, self._ffi.NULL, cipher.key, + mode.initialization_vector + ) if res == 0: raise OpenSSLError(self) # TODO: this should depend on mode.padding @@ -77,7 +87,9 @@ class API(object): def update_encrypt_context(self, ctx, plaintext): buf = self._ffi.new("unsigned char[]", len(plaintext)) outlen = self._ffi.new("int *") - res = self._lib.EVP_EncryptUpdate(ctx, buf, outlen, plaintext, len(plaintext)) + res = self._lib.EVP_EncryptUpdate( + ctx, buf, outlen, plaintext, len(plaintext) + ) if res == 0: raise OpenSSLError(self) return self._ffi.buffer(buf)[:outlen[0]] diff --git a/cryptography/primitives/block/base.py b/cryptography/primitives/block/base.py index 8faafadd..6e3565a3 100644 --- a/cryptography/primitives/block/base.py +++ b/cryptography/primitives/block/base.py @@ -9,7 +9,6 @@ class BlockCipher(object): self.mode = mode self._ctx = api.create_block_cipher_context(cipher, mode) - def encrypt(self, plaintext): return api.update_encrypt_context(self._ctx, plaintext) |
