url \
mainloop exitstatus runcmd sighandler \
lizard lizard-safe adler32 \
- md5 md5hex \
+ md5 \
base64 base224 \
sync \
qache \
+++ /dev/null
-/*
- * 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;
- }
-}
}
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++;
}
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]);
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, ':');
/* 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