pyca / pyopenssl

A Python wrapper around the OpenSSL library
https://pyopenssl.org/
Apache License 2.0
887 stars 421 forks source link

bytearray is a bytes-like object #621

Open njsmith opened 7 years ago

njsmith commented 7 years ago
In [1]: from OpenSSL import SSL

In [2]: ctx = SSL.Context(SSL.SSLv23_METHOD)

In [3]: conn = SSL.Connection(ctx, None)

In [4]: conn.set_accept_state()

In [5]: conn.send(bytearray(10))
TypeError: data must be a memoryview, buffer or byte string

But bytearrays are nice and friendly and deserve your love too!

Actually I'd expect that it should accept anything that implements the buffer interface, using ffi.from_buffer.

Lukasa commented 7 years ago

Realistically I think this probably does work with bytearray objects, and there's just a slightly overzealous isinstance check in front of the code.

Assuming that's true the fix is really easy. I'll quickly prototype that up to see if it works, and if it does I'll submit the patch.

Lukasa commented 7 years ago

See #622.