LCOV - code coverage report
Current view: top level - lib/src - xcode.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 18 19 94.7 %
Date: 2012-05-28 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 8 87.5 %

           Branch data     Line data    Source code
       1                 :            : /* xcode.c --- Encode and decode application payload in libgsasl session.
       2                 :            :  * Copyright (C) 2002-2012 Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of GNU SASL Library.
       5                 :            :  *
       6                 :            :  * GNU SASL Library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public License
       8                 :            :  * as published by the Free Software Foundation; either version 2.1 of
       9                 :            :  * the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * GNU SASL Library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License License along with GNU SASL Library; if not, write to the
      18                 :            :  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      19                 :            :  * Boston, MA 02110-1301, USA.
      20                 :            :  *
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "internal.h"
      24                 :            : 
      25                 :            : static int
      26                 :         66 : _gsasl_code (Gsasl_session * sctx,
      27                 :            :              Gsasl_code_function code,
      28                 :            :              const char *input, size_t input_len,
      29                 :            :              char **output, size_t * output_len)
      30                 :            : {
      31                 :            : 
      32         [ +  + ]:         66 :   if (code == NULL)
      33                 :            :     {
      34                 :         46 :       *output_len = input_len;
      35                 :         46 :       *output = malloc (*output_len);
      36         [ -  + ]:         46 :       if (!*output)
      37                 :          0 :         return GSASL_MALLOC_ERROR;
      38                 :            : 
      39                 :         46 :       memcpy (*output, input, input_len);
      40                 :         46 :       return GSASL_OK;
      41                 :            :     }
      42                 :            : 
      43                 :         66 :   return code (sctx, sctx->mech_data, input, input_len, output, output_len);
      44                 :            : }
      45                 :            : 
      46                 :            : /**
      47                 :            :  * gsasl_encode:
      48                 :            :  * @sctx: libgsasl session handle.
      49                 :            :  * @input: input byte array.
      50                 :            :  * @input_len: size of input byte array.
      51                 :            :  * @output: newly allocated output byte array.
      52                 :            :  * @output_len: size of output byte array.
      53                 :            :  *
      54                 :            :  * Encode data according to negotiated SASL mechanism.  This might mean
      55                 :            :  * that data is integrity or privacy protected.
      56                 :            :  *
      57                 :            :  * The @output buffer is allocated by this function, and it is the
      58                 :            :  * responsibility of caller to deallocate it by calling free(@output).
      59                 :            :  *
      60                 :            :  * Return value: Returns %GSASL_OK if encoding was successful,
      61                 :            :  *   otherwise an error code.
      62                 :            :  **/
      63                 :            : int
      64                 :         33 : gsasl_encode (Gsasl_session * sctx,
      65                 :            :               const char *input, size_t input_len,
      66                 :            :               char **output, size_t * output_len)
      67                 :            : {
      68                 :            :   Gsasl_code_function code;
      69                 :            : 
      70         [ +  + ]:         33 :   if (sctx->clientp)
      71                 :         19 :     code = sctx->mech->client.encode;
      72                 :            :   else
      73                 :         14 :     code = sctx->mech->server.encode;
      74                 :            : 
      75                 :         33 :   return _gsasl_code (sctx, code, input, input_len, output, output_len);
      76                 :            : }
      77                 :            : 
      78                 :            : /**
      79                 :            :  * gsasl_decode:
      80                 :            :  * @sctx: libgsasl session handle.
      81                 :            :  * @input: input byte array.
      82                 :            :  * @input_len: size of input byte array.
      83                 :            :  * @output: newly allocated output byte array.
      84                 :            :  * @output_len: size of output byte array.
      85                 :            :  *
      86                 :            :  * Decode data according to negotiated SASL mechanism.  This might mean
      87                 :            :  * that data is integrity or privacy protected.
      88                 :            :  *
      89                 :            :  * The @output buffer is allocated by this function, and it is the
      90                 :            :  * responsibility of caller to deallocate it by calling free(@output).
      91                 :            :  *
      92                 :            :  * Return value: Returns %GSASL_OK if encoding was successful,
      93                 :            :  *   otherwise an error code.
      94                 :            :  **/
      95                 :            : int
      96                 :         33 : gsasl_decode (Gsasl_session * sctx,
      97                 :            :               const char *input, size_t input_len,
      98                 :            :               char **output, size_t * output_len)
      99                 :            : {
     100                 :            :   Gsasl_code_function code;
     101                 :            : 
     102         [ +  + ]:         33 :   if (sctx->clientp)
     103                 :         19 :     code = sctx->mech->client.decode;
     104                 :            :   else
     105                 :         14 :     code = sctx->mech->server.decode;
     106                 :            : 
     107                 :         33 :   return _gsasl_code (sctx, code, input, input_len, output, output_len);
     108                 :            : }

Generated by: LCOV version 1.9