]> mj.ucw.cz Git - libucw.git/commitdiff
Replaced the md5hex module by the hexdumper.
authorMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 19:34:35 +0000 (21:34 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 19:34:35 +0000 (21:34 +0200)
It turned out to necessary to teach the hexdumper to produce
uppercase output, so I have changed the separator to general
flags.

lib/Makefile
lib/md5hex.c [deleted file]
lib/str-hex.c
lib/string.h

index 1196df8f0a458e1b7b1dc201988f1244fd6d9a3d..6c90b319056ad48f358a04450a909394058987e2 100644 (file)
@@ -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 (file)
index d0722f3..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *     UCW Library -- MD5 Binary <-> Hex Conversions
- *
- *     (c) 1997 Martin Mares <mj@ucw.cz>
- *
- *     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 <stdio.h>
-
-void
-md5_to_hex(const byte *s, char *d)
-{
-  int i;
-  for(i=0; i<MD5_SIZE; i++)
-    d += sprintf(d, "%02X", *s++);
-}
-
-void
-hex_to_md5(const char *s, byte *d)
-{
-  uns i, j;
-  for(i=0; i<MD5_SIZE; i++)
-    {
-      if (!Cxdigit(s[0]) || !Cxdigit(s[1]))
-       die("hex_to_md5: syntax error");
-      j = Cxvalue(*s); s++;
-      j = (j << 4) | Cxvalue(*s); s++;
-      *d++ = j;
-    }
-}
index 8485f0c8baaacf61da958a2b392536032cedbec6..2c6946ed0691bc55045a38d3e46ea885ac431593 100644 (file)
@@ -18,12 +18,20 @@ hex_make(uns x)
 }
 
 void
-mem_to_hex(char *dest, const byte *src, uns bytes, uns sep)
+mem_to_hex(char *dest, const byte *src, uns bytes, uns flags)
 {
+  uns sep = flags & 0xff;
+
   while (bytes--)
     {
-      *dest++ = hex_make(*src >> 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, ':');
index 409d17fa0e7a227d826722af85ff8214b1e79a8a..ffcf8fb49d87c4924e005278c94a290ddbf0371e 100644 (file)
@@ -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