LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib/tls13 - psk_ext_parser.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.8 Code Coverage Lines: 39 43 90.7 %
Date: 2019-07-21 03:10:42 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 64 32.8 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2017-2018 Free Software Foundation, Inc.
       3                 :            :  * Copyright (C) 2018 Red Hat, Inc.
       4                 :            :  *
       5                 :            :  * Author: Ander Juaristi, Nikos Mavrogiannopoulos
       6                 :            :  *
       7                 :            :  * This file is part of GnuTLS.
       8                 :            :  *
       9                 :            :  * The GnuTLS is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public License
      11                 :            :  * as published by the Free Software Foundation; either version 2.1 of
      12                 :            :  * the License, or (at your option) any later version.
      13                 :            :  *
      14                 :            :  * This library is distributed in the hope that it will be useful, but
      15                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :            :  * Lesser General Public License for more details.
      18                 :            :  *
      19                 :            :  * You should have received a copy of the GNU Lesser General Public License
      20                 :            :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      21                 :            :  *
      22                 :            :  */
      23                 :            : 
      24                 :            : #include "gnutls_int.h"
      25                 :            : #include "tls13/psk_ext_parser.h"
      26                 :            : 
      27                 :            : /* Returns GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE when no identities
      28                 :            :  * are present, or 0, on success.
      29                 :            :  */
      30                 :        460 : int _gnutls13_psk_ext_parser_init(psk_ext_parser_st *p,
      31                 :            :                                   const unsigned char *data, size_t _len)
      32                 :            : {
      33                 :        460 :         ssize_t len = _len;
      34                 :            : 
      35 [ +  - ][ -  + ]:        460 :         if (!p || !data || !len)
      36         [ #  # ]:          0 :                 return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
      37                 :            : 
      38                 :        460 :         memset(p, 0, sizeof(*p));
      39                 :            : 
      40   [ -  +  #  # ]:        460 :         DECR_LEN(len, 2);
      41         [ -  + ]:        460 :         p->identities_len = _gnutls_read_uint16(data);
      42                 :        460 :         data += 2;
      43                 :            : 
      44         [ -  + ]:        460 :         if (p->identities_len == 0)
      45         [ #  # ]:          0 :                 return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
      46                 :            : 
      47                 :        460 :         p->identities_data = (unsigned char *) data;
      48                 :            : 
      49   [ -  +  #  # ]:        460 :         DECR_LEN(len, p->identities_len);
      50                 :        460 :         data += p->identities_len;
      51                 :            : 
      52   [ -  +  #  # ]:        460 :         DECR_LEN(len, 2);
      53         [ -  + ]:        460 :         p->binders_len = _gnutls_read_uint16(data);
      54                 :        460 :         data += 2;
      55                 :            : 
      56                 :        460 :         p->binders_data = data;
      57   [ -  +  #  # ]:        460 :         DECR_LEN(len, p->binders_len);
      58                 :            : 
      59                 :            :         return 0;
      60                 :            : }
      61                 :            : 
      62                 :            : /* Extract PSK identity and move to the next iteration.
      63                 :            :  *
      64                 :            :  * Returns GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE when no more identities
      65                 :            :  * are present, or 0, on success.
      66                 :            :  */
      67                 :        489 : int _gnutls13_psk_ext_iter_next_identity(psk_ext_iter_st *iter,
      68                 :            :                                          struct psk_st *psk)
      69                 :            : {
      70         [ +  + ]:        489 :         if (iter->identities_len == 0)
      71                 :            :                 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
      72                 :            : 
      73   [ -  +  #  # ]:        471 :         DECR_LEN(iter->identities_len, 2);
      74         [ -  + ]:        471 :         psk->identity.size = _gnutls_read_uint16(iter->identities_data);
      75         [ -  + ]:        471 :         if (psk->identity.size == 0)
      76         [ #  # ]:          0 :                 return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
      77                 :            : 
      78                 :        471 :         iter->identities_data += 2;
      79                 :        471 :         psk->identity.data = (void*)iter->identities_data;
      80                 :            : 
      81   [ -  +  #  # ]:        471 :         DECR_LEN(iter->identities_len, psk->identity.size);
      82                 :        471 :         iter->identities_data += psk->identity.size;
      83                 :            : 
      84   [ -  +  #  # ]:        471 :         DECR_LEN(iter->identities_len, 4);
      85                 :        471 :         psk->ob_ticket_age = _gnutls_read_uint32(iter->identities_data);
      86                 :        471 :         iter->identities_data += 4;
      87                 :            : 
      88                 :        471 :         return 0;
      89                 :            : }
      90                 :            : 
      91                 :            : /* Extract PSK binder and move to the next iteration.
      92                 :            :  *
      93                 :            :  * Returns GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE when no more identities
      94                 :            :  * are present, or 0, on success.
      95                 :            :  */
      96                 :        433 : int _gnutls13_psk_ext_iter_next_binder(psk_ext_iter_st *iter,
      97                 :            :                                        gnutls_datum_t *binder)
      98                 :            : {
      99         [ +  + ]:        433 :         if (iter->binders_len == 0)
     100                 :            :                 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
     101                 :            : 
     102   [ -  +  #  # ]:        432 :         DECR_LEN(iter->binders_len, 1);
     103                 :        432 :         binder->size = *iter->binders_data;
     104         [ -  + ]:        432 :         if (binder->size == 0)
     105         [ #  # ]:          0 :                 return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
     106                 :            : 
     107                 :        432 :         iter->binders_data++;
     108                 :        432 :         binder->data = (uint8_t *)iter->binders_data;
     109   [ -  +  #  # ]:        432 :         DECR_LEN(iter->binders_len, binder->size);
     110                 :        432 :         iter->binders_data += binder->size;
     111                 :            : 
     112                 :        432 :         return 0;
     113                 :            : }

Generated by: LCOV version 1.13