use _ffi.from_buffer() to support bytearray#852
Conversation
|
Let’s put a test for a few invalid types here so we’ll know if cffi ever changes its exceptions on this. |
|
Same fix will need to apply to sendall(). Not sure about bio, since it is the other side of the encryption. |
|
Technically speaking, you should call The reason is: the way Python's buffer protocol works, as long as someone holds a reference to the raw data in the buffer, the original object is pinned. So for example, if you call Extra annoyances:
|
|
OK @njsmith how do you like this one? It has a compat no-op context manager for from_buffer. Unfortunately from_buffer is smarter than the test mock. I moved the length test past from_buffer in one of the commits because the error message from from_buffer() "wrong type" is nicer than the error message from len() "doesn't have a length" |
src/OpenSSL/SSL.py
Outdated
| total_sent += result | ||
| left_to_send -= result | ||
|
|
||
| return total_sent |
|
OK folks, it's about as good as I'm likely to make it. Includes a bugfix for Includes a test to make sure |
|
I'm not very familiar with pyopenssl's internals, but FWIW this looks fine to me. |
|
@dholth btw, you have a flake8 failure: |
|
Missed it by that much
On Tue, Jul 9, 2019, at 5:59 PM, Nathaniel J. Smith wrote:
@dholth <https://github.com/dholth> btw, you have a flake8 failure:
`tests/test_ssl.py:2103:80: E501 line too long (80 > 79 characters)
`
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#852?email_source=notifications&email_token=AABSZEU5GNR6SKVWROUUQW3P6UC5FA5CNFSM4H65NEKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZRVGJY#issuecomment-509825831>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AABSZEV4U5VX3YGTUTRBP3DP6UC5FANCNFSM4H65NEKA>.
|
|
This likely improves performance too, with the simplified checking and doesn't-copy nature of from_buffer. |
reaperhulk
left a comment
There was a problem hiding this comment.
Sorry about the ridiculous amount of time this review took. Thanks for working on this, looks good!
|
This change was a lifesaver. |
pyOpenSSL 19.1.0 fixes the byte array issue[1] which startd failing the patrole stable/train|stein jobs - https://zuul.opendev.org/t/openstack/build/2f1e7e415b074b62ae54845bd72dbef5 those jobs passing with this patch: - https://zuul.opendev.org/t/openstack/build/65878b6e4790458f9f6bb141470cdd84 pyOpenSSL 19.1.0 need cryptography 2.8 [1] pyca/pyopenssl#852 Change-Id: I254a9abce41551c19990a8285aa592189bf00206
pyOpenSSL 19.1.0 fixes the byte array issue[1] which startd failing the patrole stable/train|stein jobs - https://zuul.opendev.org/t/openstack/build/2f1e7e415b074b62ae54845bd72dbef5 those jobs passing with this patch: - https://zuul.opendev.org/t/openstack/build/65878b6e4790458f9f6bb141470cdd84 pyOpenSSL 19.1.0 need cryptography 2.8 [1] pyca/pyopenssl#852 Conflicts: upper-constraints.txt Change-Id: I254a9abce41551c19990a8285aa592189bf00206 (cherry picked from commit a8446d3)
If you try to send a dict it produces this error message:
TypeError: a bytes-like object is required, not 'dict'It doesn't accept
bytearraywithoutfrom_buffer(cffi doesn't automatically convert that type forchar*arguments)