LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib/tls13 - early_data.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.7 Code Coverage Lines: 36 41 87.8 %
Date: 2019-04-24 03:13:53 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 34 55.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2017 Red Hat, Inc.
       3                 :            :  *
       4                 :            :  * Author: Nikos Mavrogiannopoulos
       5                 :            :  *
       6                 :            :  * This file is part of GnuTLS.
       7                 :            :  *
       8                 :            :  * The GnuTLS is free software; you can redistribute it and/or
       9                 :            :  * modify it under the terms of the GNU Lesser General Public License
      10                 :            :  * as published by the Free Software Foundation; either version 2.1 of
      11                 :            :  * the License, or (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This library is distributed in the hope that it will be useful, but
      14                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :            :  * Lesser General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU Lesser General Public License
      19                 :            :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      20                 :            :  *
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "gnutls_int.h"
      24                 :            : #include "handshake.h"
      25                 :            : #include "tls13/early_data.h"
      26                 :            : 
      27                 :        477 : int _gnutls13_send_early_data(gnutls_session_t session)
      28                 :            : {
      29                 :        477 :         int ret;
      30                 :            : 
      31         [ +  - ]:        477 :         if (!(session->security_parameters.entity == GNUTLS_CLIENT &&
      32         [ +  + ]:        477 :               session->internals.hsk_flags & HSK_EARLY_DATA_IN_FLIGHT))
      33                 :            :                 return 0;
      34                 :            : 
      35         [ +  + ]:          6 :         while (session->internals.early_data_presend_buffer.length > 0) {
      36                 :          6 :                 ret =
      37                 :          3 :                         gnutls_record_send(session,
      38                 :            :                                            session->internals.
      39                 :          3 :                                            early_data_presend_buffer.data,
      40                 :            :                                            session->internals.
      41                 :            :                                            early_data_presend_buffer.
      42                 :            :                                            length);
      43         [ -  + ]:          3 :                 if (ret < 0)
      44         [ #  # ]:          0 :                         return gnutls_assert_val(ret);
      45                 :            : 
      46                 :          3 :                 session->internals.early_data_presend_buffer.data += ret;
      47                 :          3 :                 session->internals.early_data_presend_buffer.length -= ret;
      48                 :            :         }
      49                 :            : 
      50                 :            : 
      51                 :            :         return 0;
      52                 :            : }
      53                 :            : 
      54                 :        461 : int _gnutls13_send_end_of_early_data(gnutls_session_t session, unsigned again)
      55                 :            : {
      56                 :        461 :         int ret;
      57                 :        461 :         mbuffer_st *bufel = NULL;
      58                 :        461 :         gnutls_buffer_st buf;
      59                 :            : 
      60         [ +  - ]:        461 :         if (!(session->security_parameters.entity == GNUTLS_CLIENT &&
      61         [ +  + ]:        461 :               session->internals.hsk_flags & HSK_EARLY_DATA_ACCEPTED))
      62                 :            :                 return 0;
      63                 :            : 
      64         [ +  - ]:          3 :         if (again == 0) {
      65         [ +  - ]:          6 :                 ret = _gnutls_buffer_init_handshake_mbuffer(&buf);
      66         [ -  + ]:          3 :                 if (ret < 0)
      67         [ #  # ]:          0 :                         return gnutls_assert_val(ret);
      68                 :            : 
      69                 :          3 :                 bufel = _gnutls_buffer_to_mbuffer(&buf);
      70                 :            :         }
      71                 :            : 
      72                 :          3 :         return _gnutls_send_handshake(session, bufel, GNUTLS_HANDSHAKE_END_OF_EARLY_DATA);
      73                 :            : }
      74                 :            : 
      75                 :       2019 : int _gnutls13_recv_end_of_early_data(gnutls_session_t session)
      76                 :            : {
      77                 :       2019 :         int ret;
      78                 :       2019 :         gnutls_buffer_st buf;
      79                 :            : 
      80         [ +  - ]:       2019 :         if (!(session->security_parameters.entity == GNUTLS_SERVER &&
      81         [ +  + ]:       2019 :               session->internals.hsk_flags & HSK_EARLY_DATA_ACCEPTED))
      82                 :            :                 return 0;
      83                 :            : 
      84                 :          9 :         ret = _gnutls_recv_handshake(session, GNUTLS_HANDSHAKE_END_OF_EARLY_DATA, 0, &buf);
      85         [ +  + ]:          9 :         if (ret < 0)
      86         [ -  + ]:          5 :                 return gnutls_assert_val(ret);
      87                 :            : 
      88         [ -  + ]:          4 :         if (buf.length != 0) {
      89         [ #  # ]:          0 :                 gnutls_assert();
      90                 :          0 :                 ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
      91                 :          0 :                 goto cleanup;
      92                 :            :         }
      93                 :            : 
      94                 :          4 :         session->internals.hsk_flags &= ~HSK_EARLY_DATA_IN_FLIGHT;
      95                 :            : 
      96                 :          4 :         ret = 0;
      97                 :          4 : cleanup:
      98                 :            : 
      99                 :          4 :         _gnutls_buffer_clear(&buf);
     100                 :          4 :         return ret;
     101                 :            : }

Generated by: LCOV version 1.13