[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: rev 4332 - in trunk/subversion: include libsvn_fs libsvn_subr tests/libsvn_fs

From: Greg Stein <gstein_at_lyra.org>
Date: 2003-01-11 03:00:55 CET

On Fri, Jan 10, 2003 at 05:22:15PM -0600, kfogel@tigris.org wrote:
>...
> +++ trunk/subversion/include/svn_string.h Fri Jan 10 17:21:59 2003
> @@ -318,6 +318,14 @@
> const char *list,
> apr_pool_t *pool);
>
> +/* Return a string showing the octal representation of @a digest,
> + * which must be MD5_DIGESTSIZE bytes long. Allocate the string in
> + * @a pool.
> + */
> +const char *svn_cstring_from_md5_digest (unsigned char digest[],

Actually, the function constructs a hex representation.

>...
> +++ trunk/subversion/libsvn_fs/reps-strings.c Fri Jan 10 17:22:01 2003
> @@ -52,23 +52,6 @@
> };
>
>
> -/* Return a string showing the octal representation of DIGEST, which
> - * must be MD5_DIGESTSIZE bytes long.
> - */
> -static const char *
> -digest_to_cstring (unsigned char digest[], apr_pool_t *pool)

With this function gone, you should be able to remove the <stdio.h> include.
Generally, we want to avoid that header.

>...
> +++ trunk/subversion/libsvn_subr/svn_string.c Fri Jan 10 17:22:01 2003
> @@ -20,8 +20,10 @@
>
>
>
> +#include <stdio.h>

We ought to lose this.

>...
> +const char *
> +svn_cstring_from_md5_digest (unsigned char digest[], apr_pool_t *pool)
> +{
> + char *str = apr_palloc (pool, MD5_DIGESTSIZE * 3);
> + int i;
> +
> + for (i = 0; i < MD5_DIGESTSIZE; i++)
> + sprintf (str + (i * 3), "%.2x ", digest[i]);
> +
> + str[(i * 3) - 1] = '\0';
> + return str;
> +}

sprintf() can be absolutely awful on certain platforms. We've pretty well
killed it from httpd for that reason, and there isn't much reason to use it
given apr_snprintf().

But even so, the above code produces a non-standard MD5 checksum. I've never
seen one with spaces. Take a look at the output of "md5sum", or at MD5
values generated by other apps. For example:

$ md5sum HACKING
b2e35372f4c2dfc1250619b8aa30e711 HACKING
$

I think the function would look something like:

{
  static const char hex = "0123456789abcdef";
  char *str = apr_palloc(pool, MD5_DIGESTSIZE*2 + 1);
  int i;
  
  for (i = MD5_DIGESTSIZE; i--; )
  {
    str[i*2] = hex[digest[i] >> 4];
    str[i*2+1] = hext[digest[i] & 0x0f];
  }
  str[MD5_DIGESTSIZE*2] = '\0';
  return str;
}

>...

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jan 11 02:59:36 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.