summaryrefslogtreecommitdiff
path: root/src/OpenSSL/_util.py
diff options
context:
space:
mode:
authorDaniel Holth <dholth@fastmail.fm>2019-11-17 22:45:52 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-11-18 11:45:52 +0800
commit079c963ddd4ebfd13a905829bc341dce85d94fbd (patch)
tree5ca14d29d4e46fd7328d3372e1bd4b0c8db76ae5 /src/OpenSSL/_util.py
parent8543286168ed3bb234395d66fb401714495ff198 (diff)
downloadpyopenssl-079c963ddd4ebfd13a905829bc341dce85d94fbd.tar.gz
use _ffi.from_buffer() to support bytearray (#852)
* use _ffi.from_buffer(buf) in send, to support bytearray * add bytearray test * update CHANGELOG.rst * move from_buffer before 'buffer too long' check * context-managed from_buffer + black * don't shadow buf in send() * test return count for sendall * test sending an array * fix test * also use from_buffer in bio_write * de-format _util.py * formatting * add simple bio_write tests * wrap line
Diffstat (limited to 'src/OpenSSL/_util.py')
-rw-r--r--src/OpenSSL/_util.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py
index cdcacc8..d8e3f66 100644
--- a/src/OpenSSL/_util.py
+++ b/src/OpenSSL/_util.py
@@ -145,3 +145,17 @@ def text_to_bytes_and_warn(label, obj):
)
return obj.encode('utf-8')
return obj
+
+
+try:
+ # newer versions of cffi free the buffer deterministically
+ with ffi.from_buffer(b""):
+ pass
+ from_buffer = ffi.from_buffer
+except AttributeError:
+ # cffi < 0.12 frees the buffer with refcounting gc
+ from contextlib import contextmanager
+
+ @contextmanager
+ def from_buffer(*args):
+ yield ffi.from_buffer(*args)