Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify the update (#3586)
* Simplify the update

* wtf, cant reproduce issue
  • Loading branch information
alex authored and reaperhulk committed May 24, 2017
1 parent a119d2e commit 0517d1a
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/cryptography/hazmat/backends/openssl/ciphers.py
Expand Up @@ -112,13 +112,9 @@ def __init__(self, backend, cipher, mode, operation):
self._ctx = ctx

def update(self, data):
buf = self._backend._ffi.new("unsigned char[]",
len(data) + self._block_size_bytes - 1)
outlen = self._backend._ffi.new("int *")
res = self._backend._lib.EVP_CipherUpdate(self._ctx, buf, outlen, data,
len(data))
self._backend.openssl_assert(res != 0)
return self._backend._ffi.buffer(buf)[:outlen[0]]
buf = bytearray(len(data) + self._block_size_bytes - 1)
n = self.update_into(data, buf)
return bytes(buf[:n])

def update_into(self, data, buf):
if len(buf) < (len(data) + self._block_size_bytes - 1):
Expand Down

6 comments on commit 0517d1a

@rodrigocaballerohurtado

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes an ubuntu 16.04 machine to pop up with error:
"TypeError: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object"

I had to modify my ciphers.py with old code and then it worked.
I've seen that this error was solved by uninstalling cryptography again but in my case, going back to previous code made the day. Can you say if there is a specific version of components to use?

@reaperhulk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like you have an outdated cffi package. Update that and the problem should go away

@rodrigocaballerohurtado

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @reaperhulk,
Thank you so much for the suggestion, I had cffi package installed through apt-get (apt-get install python-cffi) which installed version 1.5.2.
After purging this package (apt-get purge --auto-remove python-cffi) and reinstalling again through pip (pip install --upgrade cffi) package got upgraded to version 1.11
Issue solved, thanks!

@attex
Copy link

@attex attex commented on 0517d1a May 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got Version 1.11.5 and I am still facing an error on Ubuntu 16.04

"TypeError: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object"

@taoxinyi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@attex Same, did you solve this?

@reaperhulk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is likely that you have multiple copies of cffi installed in your python paths. Try installing cryptography in a new virtualenv and if the problem goes away then it is your existing environment.

Please sign in to comment.