--- libelwix/src/str.c 2018/05/31 15:35:16 1.8 +++ libelwix/src/str.c 2019/01/23 13:26:28 1.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: str.c,v 1.8 2018/05/31 15:35:16 misho Exp $ +* $Id: str.c,v 1.9 2019/01/23 13:26:28 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2018 +Copyright 2004 - 2019 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -285,6 +285,38 @@ str_Dig2Hex(ait_val_t *digz) memset(str, 0, AIT_LEN(digz) * 2 + 1); for (i = 0, b = AIT_GET_BUF(digz); i < AIT_LEN(digz); i++) { + snprintf(szWork, sizeof szWork, "%02hhX", b[i]); + strncat(str, szWork, 2); + } + + return str; +} + +/* + * str_Dig2Hex2() - Convert from digit array to Hex string + * + * @digz = Digits array + * @diglen = Array length + * return: NULL nothing to do or error; + * !=0 Allocated new converted string (must be e_free()) +*/ +char * +str_Dig2Hex2(u_char * __restrict digz, int diglen) +{ + register int i; + char szWork[3] = { 0, 0, 0 }, *str; + u_char *b; + + if (!digz || !diglen) + return NULL; + + str = e_malloc(diglen * 2 + 1); + if (!str) + return NULL; + else + memset(str, 0, diglen * 2 + 1); + + for (i = 0, b = digz; i < diglen; i++) { snprintf(szWork, sizeof szWork, "%02hhX", b[i]); strncat(str, szWork, 2); }