aboutsummaryrefslogtreecommitdiff
path: root/deps/boringssl/src/ssl/s3_pkt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/boringssl/src/ssl/s3_pkt.cc')
-rw-r--r--deps/boringssl/src/ssl/s3_pkt.cc33
1 files changed, 14 insertions, 19 deletions
diff --git a/deps/boringssl/src/ssl/s3_pkt.cc b/deps/boringssl/src/ssl/s3_pkt.cc
index 457696d..450f7dc 100644
--- a/deps/boringssl/src/ssl/s3_pkt.cc
+++ b/deps/boringssl/src/ssl/s3_pkt.cc
@@ -112,6 +112,8 @@
#include <limits.h>
#include <string.h>
+#include <algorithm>
+
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/mem.h>
@@ -138,10 +140,9 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in,
return -1;
}
- unsigned tot, n, nw;
-
+ // TODO(davidben): Switch this logic to |size_t| and |bssl::Span|.
assert(ssl->s3->wnum <= INT_MAX);
- tot = ssl->s3->wnum;
+ unsigned tot = ssl->s3->wnum;
ssl->s3->wnum = 0;
// Ensure that if we end up with a smaller value of data to write out than
@@ -159,29 +160,23 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in,
const int is_early_data_write =
!ssl->server && SSL_in_early_data(ssl) && ssl->s3->hs->can_early_write;
- n = len - tot;
+ unsigned n = len - tot;
for (;;) {
- // max contains the maximum number of bytes that we can put into a record.
- unsigned max = ssl->max_send_fragment;
- if (is_early_data_write &&
- max > ssl->session->ticket_max_early_data -
- ssl->s3->hs->early_data_written) {
- max =
- ssl->session->ticket_max_early_data - ssl->s3->hs->early_data_written;
- if (max == 0) {
+ size_t max_send_fragment = ssl->max_send_fragment;
+ if (is_early_data_write) {
+ SSL_HANDSHAKE *hs = ssl->s3->hs.get();
+ if (hs->early_data_written >= hs->early_session->ticket_max_early_data) {
ssl->s3->wnum = tot;
- ssl->s3->hs->can_early_write = false;
+ hs->can_early_write = false;
*out_needs_handshake = true;
return -1;
}
+ max_send_fragment = std::min(
+ max_send_fragment, size_t{hs->early_session->ticket_max_early_data -
+ hs->early_data_written});
}
- if (n > max) {
- nw = max;
- } else {
- nw = n;
- }
-
+ const size_t nw = std::min(max_send_fragment, size_t{n});
int ret = do_tls_write(ssl, SSL3_RT_APPLICATION_DATA, &in[tot], nw);
if (ret <= 0) {
ssl->s3->wnum = tot;