@@ -84,7 +84,7 @@ cdef int buffer_read(void *ctx, unsigned char *buf, const size_t len) nogil:
8484 """ Read from input buffer."""
8585 c_buf = < _tls._C_Buffers * > ctx
8686 if _rb.c_len(c_buf.in_ctx) == 0 :
87- return _tls.MBEDTLS_ERR_SSL_WANT_WRITE
87+ return _tls.MBEDTLS_ERR_SSL_WANT_READ
8888 return _rb.c_readinto(c_buf.in_ctx, buf, len )
8989
9090
@@ -1247,7 +1247,6 @@ cdef class MbedTLSBuffer:
12471247 return 0
12481248 if amt <= 0 :
12491249 return 0
1250- # cdef size_t avail = _tls.mbedtls_ssl_get_bytes_avail(&self._ctx)
12511250 read = _tls.mbedtls_ssl_read(& self ._ctx, & buffer [0 ], amt)
12521251 if read > 0 :
12531252 return read
@@ -1342,26 +1341,28 @@ cdef class MbedTLSBuffer:
13421341 def do_handshake (self ):
13431342 if self ._handshake_state is HandshakeStep.HANDSHAKE_OVER:
13441343 raise ValueError (" handshake already over" )
1345- self ._handle_handshake_response(_tls.mbedtls_ssl_handshake_step(& self ._ctx))
1344+ self ._handle_handshake_response(
1345+ _tls.mbedtls_ssl_handshake_step(& self ._ctx)
1346+ )
13461347
13471348 def _renegotiate (self ):
13481349 """ Initialize an SSL renegotiation on the running connection."""
13491350 self ._handle_handshake_response(_tls.mbedtls_ssl_renegotiate(& self ._ctx))
13501351
13511352 def _handle_handshake_response (self , ret ):
1352- if ret == 0 :
1353- return
1354- elif ret == _tls.MBEDTLS_ERR_SSL_WANT_READ:
1353+ if ret == _tls.MBEDTLS_ERR_SSL_WANT_READ:
13551354 raise WantReadError()
1356- elif ret == _tls.MBEDTLS_ERR_SSL_WANT_WRITE:
1355+ if ret == _tls.MBEDTLS_ERR_SSL_WANT_WRITE:
13571356 raise WantWriteError()
1358- elif ret == _tls.MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED:
1357+ if ret == _tls.MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED:
13591358 self ._reset()
13601359 raise HelloVerifyRequest()
1361- else :
1362- assert ret < 0
1360+ if ret < 0 :
13631361 self ._reset()
13641362 _exc.check_error(ret)
1363+ if ret == 0 and self ._output_buffer:
1364+ raise WantWriteError
1365+ assert ret == 0
13651366
13661367 def _get_channel_binding (self , cb_type = " tls-unique" ):
13671368 return None
0 commit comments