[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] add support for BSD-style MD5 checksums
From: |
Joe Orton |
Subject: |
[PATCH] add support for BSD-style MD5 checksums |
Date: |
Tue, 24 Apr 2001 08:57:24 +0100 |
User-agent: |
Mutt/1.2.5i |
The BSD 'md5' program outputs lines like
MD5 (base.tgz) = 21df9ae7c9968b1bf2e2465945c53a5c
This patch allows md5sum to parse these lines.
Regards,
joe
--- md5sum.c.orig Tue Apr 24 08:19:50 2001
+++ md5sum.c Tue Apr 24 08:40:10 2001
@@ -155,17 +155,62 @@
exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
+#define ISWHITE(c) ((c) == ' ' || (c) == '\t')
+
+static int
+bsd_split_3 (char *s, size_t s_len, unsigned char **u, int *binary, char **w)
+{
+ size_t i, j;
+
+ i = 0;
+ while (ISWHITE (s[i]))
+ ++i;
+
+ /* skip "MD5 (" */
+ i += 5;
+ *w = &s[i];
+
+ /* Find end of filename. The BSD 'md5' does not escape filenames, so
+ * search backwards for the last ')'. */
+ j = s_len - 1;
+ while (s[j] != ')' && j > i)
+ j--;
+
+ if (s[j] != ')')
+ return 1;
+
+ s[j++] = '\0';
+
+ while (ISWHITE(s[j]))
+ j++;
+
+ if (s[j] != '=')
+ return 1;
+
+ j++;
+
+ while (ISWHITE(s[j]))
+ j++;
+
+ *binary = 0;
+
+ *u = (unsigned char *) &s[j];
+ return 0;
+}
+
static int
split_3 (char *s, size_t s_len, unsigned char **u, int *binary, char **w)
{
size_t i;
int escaped_filename = 0;
-#define ISWHITE(c) ((c) == ' ' || (c) == '\t')
-
i = 0;
while (ISWHITE (s[i]))
++i;
+
+ /* Check for BSD-style checksum line. */
+ if (strncmp(&s[i], "MD5 (", 5) == 0)
+ return bsd_split_3(s, s_len, u, binary, w);
/* The line must have at least `min_digest_line_length - 1' (or one more, if
the first is a backslash) more characters to contain correct message
digest
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] add support for BSD-style MD5 checksums,
Joe Orton <=