From: Martin Mares Date: Wed, 25 Jun 2008 19:34:35 +0000 (+0200) Subject: Replaced the md5hex module by the hexdumper. X-Git-Tag: holmes-import~416 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b2c4b501ef864afd65287d0dad9d9daedeef0c2c;p=libucw.git Replaced the md5hex module by the hexdumper. It turned out to necessary to teach the hexdumper to produce uppercase output, so I have changed the separator to general flags. --- diff --git a/lib/Makefile b/lib/Makefile index 1196df8f..6c90b319 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -27,7 +27,7 @@ LIBUCW_MODS= \ url \ mainloop exitstatus runcmd sighandler \ lizard lizard-safe adler32 \ - md5 md5hex \ + md5 \ base64 base224 \ sync \ qache \ diff --git a/lib/md5hex.c b/lib/md5hex.c deleted file mode 100644 index d0722f3e..00000000 --- a/lib/md5hex.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * UCW Library -- MD5 Binary <-> Hex Conversions - * - * (c) 1997 Martin Mares - * - * This software may be freely distributed and used according to the terms - * of the GNU Lesser General Public License. - */ - -#include "lib/lib.h" -#include "lib/chartype.h" -#include "lib/md5.h" -#include "lib/string.h" - -#include - -void -md5_to_hex(const byte *s, char *d) -{ - int i; - for(i=0; i> 4); - *dest++ = hex_make(*src & 0x0f); + dest[0] = hex_make(*src >> 4); + dest[1] = hex_make(*src & 0x0f); + if (flags & MEM_TO_HEX_UPCASE) + { + dest[0] = Cupcase(dest[0]); + dest[1] = Cupcase(dest[1]); + } + dest += 2; if (sep && bytes) *dest++ = sep; src++; @@ -40,8 +48,9 @@ hex_parse(uns c) } const char * -hex_to_mem(byte *dest, const char *src, uns max_bytes, uns sep) +hex_to_mem(byte *dest, const char *src, uns max_bytes, uns flags) { + uns sep = flags & 0xff; while (max_bytes-- && Cxdigit(src[0]) && Cxdigit(src[1])) { *dest++ = (hex_parse(src[0]) << 4) | hex_parse(src[1]); @@ -66,6 +75,8 @@ int main(void) byte y[4]; char a[16]; + mem_to_hex(a, x, 4, MEM_TO_HEX_UPCASE); + puts(a); mem_to_hex(a, x, 4, ':'); puts(a); const char *z = hex_to_mem(y, a, 4, ':'); diff --git a/lib/string.h b/lib/string.h index 409d17fa..ffcf8fb4 100644 --- a/lib/string.h +++ b/lib/string.h @@ -31,12 +31,10 @@ int str_match_pattern_nocase(const char *patt, const char *str); /* str-hex.c */ -void mem_to_hex(char *dest, const byte *src, uns bytes, uns sep); -const char *hex_to_mem(byte *dest, const char *src, uns max_bytes, uns sep); +void mem_to_hex(char *dest, const byte *src, uns bytes, uns flags); +const char *hex_to_mem(byte *dest, const char *src, uns max_bytes, uns flags); -/* md5hex.c */ - -void md5_to_hex(const byte *s, char *d); -void hex_to_md5(const char *s, byte *d); +// Bottom 8 bits of flags are an optional separator of bytes, the rest is: +#define MEM_TO_HEX_UPCASE 0x100 #endif