exchange/src/util/util.c

59 lines
1.6 KiB
C
Raw Normal View History

2015-01-08 18:37:20 +01:00
/*
This file is part of TALER
2020-01-14 23:57:35 +01:00
Copyright (C) 2014-2020 Taler Systems SA
2015-01-08 18:37:20 +01:00
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
2016-07-07 17:55:25 +02:00
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
2015-01-08 18:37:20 +01:00
*/
/**
* @file util.c
2020-01-19 20:33:07 +01:00
* @brief Common utility functions
2015-01-09 17:12:13 +01:00
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
2015-01-08 18:37:20 +01:00
* @author Florian Dold
* @author Benedikt Mueller
*/
#include "platform.h"
#include "taler_util.h"
2015-08-14 22:05:34 +02:00
/**
2020-03-01 13:04:06 +01:00
* Convert a buffer to an 8-character string representative of the
* contents. This is used for logging binary data when debugging.
2015-08-14 22:05:34 +02:00
*
* @param buf buffer to log
* @param buf_size number of bytes in @a buf
* @return text representation of buf, valid until next
* call to this function
*/
const char *
TALER_b2s (const void *buf,
2019-08-17 21:35:21 +02:00
size_t buf_size)
2015-08-14 22:05:34 +02:00
{
2020-04-02 11:34:52 +02:00
static GNUNET_THREAD_LOCAL char ret[9];
2015-08-14 22:05:34 +02:00
struct GNUNET_HashCode hc;
char *tmp;
GNUNET_CRYPTO_hash (buf,
2019-08-25 16:18:24 +02:00
buf_size,
&hc);
2015-08-14 22:05:34 +02:00
tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
2019-08-17 21:35:21 +02:00
sizeof (hc));
2015-08-14 22:05:34 +02:00
memcpy (ret,
2019-08-25 16:18:24 +02:00
tmp,
8);
2015-08-14 22:05:34 +02:00
GNUNET_free (tmp);
ret[8] = '\0';
return ret;
}
2015-08-14 22:05:34 +02:00
2015-01-08 18:37:20 +01:00
/* end of util.c */