@@ -1386,6 +1386,13 @@ void ssl_do_msg_callback(const SSL *ssl, int is_write, int content_type,
13861386
13871387// Transport buffers.
13881388
1389+ enum SSL_BUFFER_SERDE_VERSION {
1390+ SSL_BUFFER_SERDE_VERSION_ONE = 1 ,
1391+ SSL_BUFFER_SERDE_VERSION_TWO = 2
1392+ };
1393+
1394+ const unsigned kSSLBufferMaxSerDeVersion = SSL_BUFFER_SERDE_VERSION_TWO;
1395+
13891396#define SSLBUFFER_READ_AHEAD_MIN_CAPACITY 512
13901397#define SSLBUFFER_MAX_CAPACITY UINT16_MAX
13911398class SSLBuffer {
@@ -1432,28 +1439,46 @@ class SSLBuffer {
14321439 void DiscardConsumed ();
14331440
14341441 // DoSerialization writes all fields into |cbb|.
1435- bool DoSerialization (CBB * cbb);
1442+ bool DoSerialization (CBB & cbb);
14361443
14371444 // DoDeserialization recovers the states encoded via |DoSerialization|.
1438- bool DoDeserialization (CBS *in);
1445+ bool DoDeserialization (CBS &in);
1446+
1447+ bool SerializeBufferView (CBB &cbb, Span<uint8_t > &view);
1448+ bool DeserializeBufferView (CBS &cbb, Span<uint8_t > &view);
14391449
14401450 private:
14411451 // buf_ is the memory allocated for this buffer.
14421452 uint8_t *buf_ = nullptr ;
1443- // offset_ is the offset into |buf_| which the buffer contents start at.
1453+ // buf_allocated_ is true if |buf_| points to allocated data and must be freed
1454+ // or false if it points into |inline_buf_|.
1455+ bool buf_allocated_ = false ;
1456+ // The total capacity requested for this buffer by |EnsureCap|.
1457+ size_t buf_cap_ = 0 ;
1458+ // buf_size_ is how much memory allocated for |buf_|. This is needed by
1459+ // |DoSerializationV1|. This is the total size of the buffer with the requested capacity + padding.
1460+ size_t buf_size_ = 0 ;
1461+ // header length used to calculate initial offset
1462+ size_t header_len_ = 0 ;
1463+ // offset_ is the offset into |buf_| which the buffer contents start at, and is moved as contents are consumed
14441464 uint16_t offset_ = 0 ;
14451465 // size_ is the size of the buffer contents from |buf_| + |offset_|.
14461466 uint16_t size_ = 0 ;
14471467 // cap_ is how much memory beyond |buf_| + |offset_| is available.
14481468 uint16_t cap_ = 0 ;
14491469 // inline_buf_ is a static buffer for short reads.
14501470 uint8_t inline_buf_[SSL3_RT_HEADER_LENGTH];
1451- // buf_allocated_ is true if |buf_| points to allocated data and must be freed
1452- // or false if it points into |inline_buf_|.
1453- bool buf_allocated_ = false ;
1454- // buf_size_ is how much memory allocated for |buf_|. This is needed by
1455- // |DoSerialization|.
1456- size_t buf_size_ = 0 ;
1471+
1472+ // The V1 version has some intricacies were solved in later serialization versions.
1473+ // This is mainly to capture if a V1 version was restored and whether it needs to be
1474+ // re-serialized as that version.
1475+ uint32_t max_serialization_version_ = SSL_BUFFER_SERDE_VERSION_TWO;
1476+
1477+ bool DoSerializationV1 (CBB &cbb);
1478+ bool DoSerializationV2 (CBB &cbb);
1479+
1480+ bool DoDeserializationV1 (CBS &in);
1481+ bool DoDeserializationV2 (CBS &in);
14571482};
14581483
14591484// ssl_read_buffer_extend_to extends the read buffer to the desired length. For
@@ -4237,6 +4262,10 @@ struct ssl_st {
42374262 // as will fit in the SSLBuffer from the BIO, or just enough to read the record
42384263 // header and then the length of the body
42394264 bool enable_read_ahead : 1 ;
4265+
4266+ // is_suspended_state indicates that the |SSL| object has been serialized and
4267+ // operations should not be performed on the connection.
4268+ bool is_suspended_state : 1 ;
42404269};
42414270
42424271struct ssl_session_st : public bssl ::RefCounted<ssl_session_st> {
0 commit comments