summaryrefslogtreecommitdiff
path: root/src/md5sum.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-08-31 11:11:10 +0000
committerJim Meyering <jim@meyering.net>2003-08-31 11:11:10 +0000
commit7b1f0fa519f576eefb1eafd41e8a5fb3404cf763 (patch)
tree03e31d22b621c3675f259e113ac0e43eab411b79 /src/md5sum.c
parenta78c9ec4f0c1c0aa41328160cf606264c354c9c8 (diff)
downloadcoreutils-7b1f0fa519f576eefb1eafd41e8a5fb3404cf763.tar.xz
(split_3): Accept the BSD format for generic
message digest modes. Currently works with BSD's MD5 and SHA1 formats since these are the two algorithms presently used in coreutils. Updated comments to reflect this change. (bsd_split_3): Updated comments.
Diffstat (limited to 'src/md5sum.c')
-rw-r--r--src/md5sum.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/md5sum.c b/src/md5sum.c
index 247302021..c1685a509 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -161,9 +161,9 @@ text), and name for each FILE.\n"),
#define ISWHITE(c) ((c) == ' ' || (c) == '\t')
-/* Split the checksum string S (of length S_LEN) from a BSD 'md5'
- command into two parts: a hexadecimal digest, and the file name. S
- is modified. */
+/* Split the checksum string S (of length S_LEN) from a BSD 'md5' or
+ 'sha1' command into two parts: a hexadecimal digest, and the file
+ name. S is modified. */
static int
bsd_split_3 (char *s, size_t s_len, unsigned char **hex_digest, char **file_name)
@@ -172,8 +172,8 @@ bsd_split_3 (char *s, size_t s_len, unsigned char **hex_digest, char **file_name
*file_name = s;
- /* Find end of filename. The BSD 'md5' does not escape filenames, so
- search backwards for the last ')'. */
+ /* Find end of filename. The BSD 'md5' and 'sha1' commands do not escape
+ filenames, so search backwards for the last ')'. */
i = s_len - 1;
while (i && s[i] != ')')
i--;
@@ -208,16 +208,23 @@ split_3 (char *s, size_t s_len,
{
size_t i;
int escaped_filename = 0;
+ size_t algo_name_len;
i = 0;
while (ISWHITE (s[i]))
++i;
/* Check for BSD-style checksum line. */
- if (algorithm == ALG_MD5 && strncmp (s + i, "MD5 (", 5) == 0)
+ algo_name_len = strlen (DIGEST_TYPE_STRING (algorithm));
+ if (strncmp (s + i, DIGEST_TYPE_STRING (algorithm), algo_name_len) == 0)
{
- *binary = 0;
- return bsd_split_3 (s + i + 5, s_len - i - 5, hex_digest, file_name);
+ if (strncmp (s + i + algo_name_len, " (", 2) == 0)
+ {
+ *binary = 0;
+ return bsd_split_3 (s + i + algo_name_len + 2,
+ s_len - (i + algo_name_len + 2),
+ hex_digest, file_name);
+ }
}
/* Ignore this line if it is too short.