Author: Richard Plangger <[email protected]>
Branch: py3.5
Changeset: r90230:4a32251b3e93
Date: 2017-02-20 15:34 +0100
http://bitbucket.org/pypy/pypy/changeset/4a32251b3e93/

Log:    implement RAND_egd in pypy's _ssl module, `not bytearray([]) is
        True` (which seems to be the same rule as `not []`), fixes a bug in
        SSLSocket.read

diff --git a/lib_pypy/_cffi_ssl/_stdssl/__init__.py 
b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
--- a/lib_pypy/_cffi_ssl/_stdssl/__init__.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
@@ -434,8 +434,10 @@
 
         sock = self.get_socket_or_connection_gone()
 
-        if not buffer_into:
+        if buffer_into is None:
             dest = ffi.new("char[]", length)
+            if length == 0:
+                return b""
             mem = dest
         else:
             mem = ffi.from_buffer(buffer_into)
@@ -443,6 +445,8 @@
                 length = len(buffer_into)
                 if length > sys.maxsize:
                     raise OverflowError("maximum length can't fit in a C 
'int'")
+                if len(buffer_into) == 0:
+                    return 0
 
         if sock:
             timeout = _socket_timeout(sock)
@@ -1450,3 +1454,11 @@
 
         return lib.SSL_TLSEXT_ERR_OK
 
+if lib.Cryptography_HAS_EGD:
+    def RAND_egd(path):
+        bytecount = lib.RAND_egd_bytes(ffi.from_buffer(path), len(path))
+        if bytecount == -1:
+            raise SSLError("EGD connection failed or EGD did not return "
+                           "enough data to seed the PRNG");
+        return bytecount
+
diff --git a/lib_pypy/_cffi_ssl/_stdssl/certificate.py 
b/lib_pypy/_cffi_ssl/_stdssl/certificate.py
--- a/lib_pypy/_cffi_ssl/_stdssl/certificate.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/certificate.py
@@ -133,7 +133,7 @@
                 v = _bio_get_str(biobuf)
                 idx = v.find(":")
                 if idx == -1:
-                    return None
+                    raise ValueError("Invalid value %s", v)
                 peer_alt_names.append((v[:idx], v[idx+1:]))
 
         free_func_addr = ffi.addressof(lib, "GENERAL_NAME_free")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to