Browse Source

Revert "Functions for encoding reversed hex"

This reverts commit ef5678956d2eedf9904ce32f12f6367bc26c59e7.
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
ed2158c334
  1. 18
      ccan/ccan/str/hex/hex.c
  2. 18
      ccan/ccan/str/hex/hex.h
  3. 9
      common/json.c
  4. 3
      common/json.h

18
ccan/ccan/str/hex/hex.c

@ -64,21 +64,3 @@ bool hex_encode(const void *buf, size_t bufsize, char *dest, size_t destsize)
return true; return true;
} }
bool hex_encode_reversed(const void *buf, size_t bufsize, char *dest, size_t destsize)
{
size_t i;
if (destsize < hex_str_size(bufsize))
return false;
// Start at end of data, go to index 0.
for (i = bufsize; i--;) {
unsigned int c = ((const unsigned char *)buf)[i];
*(dest++) = hexchar(c >> 4);
*(dest++) = hexchar(c & 0xF);
}
*dest = '\0';
return true;
}

18
ccan/ccan/str/hex/hex.h

@ -41,24 +41,6 @@ bool hex_decode(const char *str, size_t slen, void *buf, size_t bufsize);
*/ */
bool hex_encode(const void *buf, size_t bufsize, char *dest, size_t destsize); bool hex_encode(const void *buf, size_t bufsize, char *dest, size_t destsize);
/**
* hex_encode_reversed - Create a nul-terminated reversed hex string
* @buf: the buffer to read the data from
* @bufsize: the length of @buf
* @dest: the string to fill
* @destsize: the max size of the string
*
* Returns true if the string, including terminator, fit in @destsize;
*
* Example:
* unsigned char buf[] = { 0x1F, 0x2F };
* char str[5];
*
* if (!hex_encode(buf, sizeof(buf), str, sizeof(str)))
* abort();
*/
bool hex_encode_reversed(const void *buf, size_t bufsize, char *dest, size_t destsize);
/** /**
* hex_str_size - Calculate how big a nul-terminated hex string is * hex_str_size - Calculate how big a nul-terminated hex string is
* @bytes: bytes of data to represent * @bytes: bytes of data to represent

9
common/json.c

@ -471,15 +471,6 @@ void json_add_hex(struct json_result *result, const char *fieldname,
json_add_string(result, fieldname, hex); json_add_string(result, fieldname, hex);
} }
void json_add_hex_reversed(struct json_result *result, const char *fieldname,
const void *data, size_t len)
{
char hex[hex_str_size(len)];
hex_encode_reversed(data, len, hex, sizeof(hex));
json_add_string(result, fieldname, hex);
}
void json_add_object(struct json_result *result, ...) void json_add_object(struct json_result *result, ...)
{ {
va_list ap; va_list ap;

3
common/json.h

@ -102,9 +102,6 @@ void json_add_null(struct json_result *result, const char *fieldname);
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */ /* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
void json_add_hex(struct json_result *result, const char *fieldname, void json_add_hex(struct json_result *result, const char *fieldname,
const void *data, size_t len); const void *data, size_t len);
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
void json_add_hex_reversed(struct json_result *result, const char *fieldname,
const void *data, size_t len);
void json_add_object(struct json_result *result, ...); void json_add_object(struct json_result *result, ...);
const char *json_result_string(const struct json_result *result); const char *json_result_string(const struct json_result *result);

Loading…
Cancel
Save