LCOV - code coverage report
Current view: top level - src/tds/unittests - cbt.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 13 15 86.7 %
Date: 2025-12-05 20:38:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 2025  Frediano Ziglio
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : 
      20             : /*
      21             :  * Purpose: test channel binding code
      22             :  */
      23             : #undef NDEBUG
      24             : #include "../challenge.c"
      25             : 
      26             : #include "common.h"
      27             : 
      28             : static char *
      29             : bin2ascii(char *dest, const void *data, size_t len)
      30             : {
      31          10 :         char *s = dest;
      32          10 :         const unsigned char *src = (const unsigned char *) data;
      33             : 
      34         160 :         for (; len > 0; --len, s += 2)
      35         160 :                 sprintf(s, "%02x", *src++);
      36          10 :         *s = 0;
      37             :         return dest;
      38             : }
      39             : 
      40             : static void
      41          10 : calc_cbt_from_tls_unique_test(const char *tls_unique, const char *cbt)
      42             : {
      43             :         unsigned char cbt_buf[16];
      44             :         char cbt_str[33];
      45             : 
      46          10 :         tds_calc_cbt_from_tls_unique(tls_unique, strlen(tls_unique), cbt_buf);
      47             : 
      48             :         /* convert to hex string and compare */
      49          10 :         bin2ascii(cbt_str, cbt_buf, 16);
      50          10 :         if (strcasecmp(cbt_str, cbt) != 0) {
      51           0 :                 fprintf(stderr, "Wrong calc_cbt_from_tls_unique(%s) -> %s expected %s\n", tls_unique, cbt_buf, cbt);
      52           0 :                 exit(1);
      53             :         }
      54          10 : }
      55             : 
      56          10 : TEST_MAIN()
      57             : {
      58          10 :         calc_cbt_from_tls_unique_test("0123456789abcdef", "1eb7620a5e38cb1f50478b1690621a03");
      59          10 :         return 0;
      60             : }

Generated by: LCOV version 1.13