LCOV - code coverage report
Current view: top level - tls/extensions - s2n_nst_early_data_indication.c (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 22 22 100.0 %
Date: 2025-08-14 07:26:07 Functions: 4 4 100.0 %
Branches: 15 18 83.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License").
       5                 :            :  * You may not use this file except in compliance with the License.
       6                 :            :  * A copy of the License is located at
       7                 :            :  *
       8                 :            :  *  http://aws.amazon.com/apache2.0
       9                 :            :  *
      10                 :            :  * or in the "license" file accompanying this file. This file is distributed
      11                 :            :  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
      12                 :            :  * express or implied. See the License for the specific language governing
      13                 :            :  * permissions and limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "api/s2n.h"
      17                 :            : #include "stuffer/s2n_stuffer.h"
      18                 :            : #include "tls/extensions/s2n_early_data_indication.h"
      19                 :            : #include "tls/s2n_connection.h"
      20                 :            : #include "tls/s2n_early_data.h"
      21                 :            : #include "utils/s2n_safety.h"
      22                 :            : 
      23                 :            : static bool s2n_nst_early_data_indication_should_send(struct s2n_connection *conn)
      24                 :        422 : {
      25                 :        422 :     uint32_t server_max_early_data = 0;
      26         [ +  + ]:        422 :     return s2n_result_is_ok(s2n_early_data_get_server_max_size(conn, &server_max_early_data))
      27         [ +  + ]:        422 :             && server_max_early_data > 0;
      28                 :        422 : }
      29                 :            : 
      30                 :            : /**
      31                 :            :  * The client version of this extension is empty, so we don't read/write any data.
      32                 :            :  *
      33                 :            :  *= https://www.rfc-editor.org/rfc/rfc8446#section-4.2.10
      34                 :            :  *# The "extension_data" field of this extension contains an
      35                 :            :  *# "EarlyDataIndication" value.
      36                 :            :  *#
      37                 :            :  *#     struct {} Empty;
      38                 :            :  *#
      39                 :            :  *#     struct {
      40                 :            :  *#         select (Handshake.msg_type) {
      41                 :            :  *#             case new_session_ticket:   uint32 max_early_data_size;
      42                 :            :  **
      43                 :            :  *= https://www.rfc-editor.org/rfc/rfc8446#section-4.2.10
      44                 :            :  *#         };
      45                 :            :  *#     } EarlyDataIndication;
      46                 :            :  **/
      47                 :            : 
      48                 :            : static int s2n_nst_early_data_indication_send(struct s2n_connection *conn, struct s2n_stuffer *out)
      49                 :        131 : {
      50                 :        131 :     uint32_t server_max_early_data = 0;
      51         [ +  + ]:        131 :     POSIX_GUARD_RESULT(s2n_early_data_get_server_max_size(conn, &server_max_early_data));
      52         [ +  + ]:        130 :     POSIX_GUARD(s2n_stuffer_write_uint32(out, server_max_early_data));
      53                 :        129 :     return S2N_SUCCESS;
      54                 :        130 : }
      55                 :            : 
      56                 :            : static int s2n_nst_early_data_indiction_recv(struct s2n_connection *conn, struct s2n_stuffer *in)
      57                 :        144 : {
      58 [ +  - ][ +  + ]:        144 :     POSIX_ENSURE_REF(conn);
      59                 :        143 :     uint32_t server_max_early_data = 0;
      60         [ +  + ]:        143 :     POSIX_GUARD(s2n_stuffer_read_uint32(in, &server_max_early_data));
      61         [ -  + ]:        142 :     POSIX_GUARD(s2n_connection_set_server_max_early_data_size(conn, server_max_early_data));
      62                 :        142 :     return S2N_SUCCESS;
      63                 :        142 : }
      64                 :            : 
      65                 :            : static int s2n_nst_early_data_indication_missing(struct s2n_connection *conn)
      66                 :        328 : {
      67         [ -  + ]:        328 :     POSIX_GUARD(s2n_connection_set_server_max_early_data_size(conn, 0));
      68                 :        328 :     return S2N_SUCCESS;
      69                 :        328 : }
      70                 :            : 
      71                 :            : const s2n_extension_type s2n_nst_early_data_indication_extension = {
      72                 :            :     .iana_value = TLS_EXTENSION_EARLY_DATA,
      73                 :            :     .is_response = false,
      74                 :            :     .send = s2n_nst_early_data_indication_send,
      75                 :            :     .recv = s2n_nst_early_data_indiction_recv,
      76                 :            :     .should_send = s2n_nst_early_data_indication_should_send,
      77                 :            :     .if_missing = s2n_nst_early_data_indication_missing,
      78                 :            : };

Generated by: LCOV version 1.14