This didn't implement `cksum -a blake2b` fully.
The attached fixes this up, which I'll fold it into this patch.
I've also augmented the test to check this.

cheers,
Pádraig.
diff --git a/src/digest.c b/src/digest.c
index 7e82166c2..fac2f2419 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -146,14 +146,14 @@
   proper_name ("Scott Miller"), \
   proper_name ("David Madore")
 #endif
-#if !HASH_ALGO_BLAKE2
+#if !HASH_ALGO_BLAKE2 && !HASH_ALGO_CKSUM
 # define DIGEST_HEX_BYTES (DIGEST_BITS / 4)
 #endif
 #define DIGEST_BIN_BYTES (DIGEST_BITS / 8)
 
 /* The minimum length of a valid digest line.  This length does
    not include any newline character at the end of a line.  */
-#if HASH_ALGO_BLAKE2
+#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
 # define MIN_DIGEST_LINE_LENGTH 3 /* With -l 8.  */
 #else
 # define MIN_DIGEST_LINE_LENGTH \
@@ -675,7 +675,10 @@ split_3 (char *s, size_t s_len,
   if (STREQ_LEN (s + i, DIGEST_TYPE_STRING, algo_name_len))
     {
       i += algo_name_len;
-#if HASH_ALGO_BLAKE2
+#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
+# if HASH_ALGO_CKSUM
+      if (cksum_algorithm == blake2b) {
+# endif
       /* Terminate and match algorithm name.  */
       char const *algo_name = &s[i - algo_name_len];
       /* Skip algorithm variants.  */
@@ -704,7 +707,9 @@ split_3 (char *s, size_t s_len,
           i = siend - s;
           b2_length = length;
         }
-
+# if HASH_ALGO_CKSUM
+      }
+# endif
       digest_hex_bytes = b2_length / 4;
 #endif
       if (s[i] == ' ')
@@ -728,8 +733,11 @@ split_3 (char *s, size_t s_len,
 
   *hex_digest = (unsigned char *) &s[i];
 
-#if HASH_ALGO_BLAKE2
+#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
   /* Auto determine length.  */
+# if HASH_ALGO_CKSUM
+  if (cksum_algorithm == blake2b) {
+# endif
   unsigned char const *hp = *hex_digest;
   digest_hex_bytes = 0;
   while (isxdigit (*hp++))
@@ -738,6 +746,9 @@ split_3 (char *s, size_t s_len,
       || blake2_max_len[b2_algorithm] * 2 < digest_hex_bytes)
     return false;
   b2_length = digest_hex_bytes * 4;
+# if HASH_ALGO_CKSUM
+  }
+# endif
 #endif
 
   /* The first field has to be the n-character hexadecimal
@@ -916,6 +927,13 @@ output_file (char const *file, int binary_file, void const *digest,
         printf ("-%"PRIuMAX, b2_length);
 # else
       fputs (DIGEST_TYPE_STRING, stdout);
+#  if HASH_ALGO_CKSUM
+      if (cksum_algorithm == blake2b)
+        {
+          if (b2_length < blake2_max_len[b2_algorithm] * 8)
+            printf ("-%"PRIuMAX, b2_length);
+        }
+#  endif
 # endif
       fputs (" (", stdout);
       print_filename (file, needs_escape);
@@ -1034,7 +1052,8 @@ digest_check (char const *checkfile_name)
 
           properly_formatted_lines = true;
 
-          ok = digest_file (filename, &binary, bin_buffer, &missing, NULL);
+          uintmax_t length;
+          ok = digest_file (filename, &binary, bin_buffer, &missing, &length);
 
           if (!ok)
             {

Reply via email to