move data_to_string_alloc to GNUnet

This commit is contained in:
Christian Grothoff 2015-01-28 20:31:28 +01:00
parent 62d3d35250
commit bc8f6e81a4
4 changed files with 11 additions and 55 deletions

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
(C) 2014 Christian Grothoff (and other contributing authors) (C) 2014, 2015 Christian Grothoff (and other contributing authors)
TALER is free software; you can redistribute it and/or modify it under the 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 terms of the GNU General Public License as published by the Free Software
@ -13,15 +13,13 @@
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file include/taler_util.h * @file include/taler_util.h
* @brief Interface for common utility functions * @brief Interface for common utility functions
* @author Sree Harsha Totakura <sreeharsha@totakura.in> * @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/ */
#ifndef TALER_UTIL_H_
#ifndef UTIL_H_ #define TALER_UTIL_H_
#define UTIL_H_
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <gcrypt.h> #include <gcrypt.h>
@ -234,22 +232,6 @@ TALER_amount_normalize (struct TALER_Amount amount);
char * char *
TALER_amount_to_string (struct TALER_Amount amount); TALER_amount_to_string (struct TALER_Amount amount);
/* ****************** FIXME: move to GNUnet? ************** */
/**
* Return the base32crockford encoding of the given buffer.
*
* The returned string will be freshly allocated, and must be free'd
* with #GNUNET_free().
*
* @param buffer with data
* @param size size of the buffer
* @return freshly allocated, null-terminated string
*/
char *
TALER_data_to_string_alloc (const void *buf,
size_t size);
/* ****************** Coin crypto primitives ************* */ /* ****************** Coin crypto primitives ************* */

View File

@ -180,7 +180,8 @@ get_cointype_dir (const struct CoinTypeParams *p)
unsigned int i; unsigned int i;
hash_coin_type (p, &hash); hash_coin_type (p, &hash);
hash_str = TALER_data_to_string_alloc (&hash, sizeof (struct GNUNET_HashCode)); hash_str = GNUNET_STRINGS_data_to_string_alloc (&hash,
sizeof (struct GNUNET_HashCode));
GNUNET_assert (HASH_CUTOFF <= strlen (hash_str) + 1); GNUNET_assert (HASH_CUTOFF <= strlen (hash_str) + 1);
GNUNET_assert (NULL != hash_str); GNUNET_assert (NULL != hash_str);
hash_str[HASH_CUTOFF] = 0; hash_str[HASH_CUTOFF] = 0;
@ -363,7 +364,8 @@ mint_keys_update_signkeys ()
{ {
struct TALER_MINT_SignKeyIssuePriv signkey_issue; struct TALER_MINT_SignKeyIssuePriv signkey_issue;
ssize_t nwrite; ssize_t nwrite;
printf ("Generating signing key for %s.\n", GNUNET_STRINGS_absolute_time_to_string (anchor)); printf ("Generating signing key for %s.\n",
GNUNET_STRINGS_absolute_time_to_string (anchor));
create_signkey_issue_priv (anchor, signkey_duration, &signkey_issue); create_signkey_issue_priv (anchor, signkey_duration, &signkey_issue);
nwrite = GNUNET_DISK_fn_write (skf, &signkey_issue, sizeof (struct TALER_MINT_SignKeyIssue), nwrite = GNUNET_DISK_fn_write (skf, &signkey_issue, sizeof (struct TALER_MINT_SignKeyIssue),
(GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_USER_READ)); (GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_USER_READ));
@ -498,7 +500,8 @@ mint_keys_update_cointype (const char *coin_alias)
struct TALER_MINT_DenomKeyIssuePriv denomkey_issue; struct TALER_MINT_DenomKeyIssuePriv denomkey_issue;
int ret; int ret;
printf ("Generating denomination key for type '%s', start %s.\n", printf ("Generating denomination key for type '%s', start %s.\n",
coin_alias, GNUNET_STRINGS_absolute_time_to_string (p.anchor)); coin_alias,
GNUNET_STRINGS_absolute_time_to_string (p.anchor));
printf ("Target path: %s\n", dkf); printf ("Target path: %s\n", dkf);
create_denomkey_issue (&p, &denomkey_issue); create_denomkey_issue (&p, &denomkey_issue);
ret = TALER_MINT_write_denom_key (dkf, &denomkey_issue); ret = TALER_MINT_write_denom_key (dkf, &denomkey_issue);

View File

@ -133,7 +133,8 @@ TALER_JSON_from_data (const void *data, size_t size)
{ {
char *buf; char *buf;
json_t *json; json_t *json;
buf = TALER_data_to_string_alloc (data, size);
buf = GNUNET_STRINGS_data_to_string_alloc (data, size);
json = json_string (buf); json = json_string (buf);
GNUNET_free (buf); GNUNET_free (buf);
return json; return json;

View File

@ -28,36 +28,6 @@
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <gcrypt.h> #include <gcrypt.h>
/**
* Return the base32crockford encoding of the given buffer.
*
* The returned string will be freshly allocated, and must be free'd
* with GNUNET_free().
*
* @param buffer with data
* @param size size of the buffer
* @return freshly allocated, null-terminated string
*/
char *
TALER_data_to_string_alloc (const void *buf, size_t size)
{
char *str_buf;
size_t len = size * 8;
char *end;
if (len % 5 > 0)
len += 5 - len % 5;
len /= 5;
str_buf = GNUNET_malloc (len + 1);
end = GNUNET_STRINGS_data_to_string (buf, size, str_buf, len);
if (NULL == end)
{
GNUNET_free (str_buf);
return NULL;
}
*end = '\0';
return str_buf;
}
/** /**