~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/md5.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * md5.c:   checksum routines
 
3
 *
 
4
 * ====================================================================
 
5
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
6
 *
 
7
 * This software is licensed as described in the file COPYING, which
 
8
 * you should have received as part of this distribution.  The terms
 
9
 * are also available at http://subversion.tigris.org/license-1.html.
 
10
 * If newer versions of this license are posted there, you may use a
 
11
 * newer version instead, at your option.
 
12
 *
 
13
 * This software consists of voluntary contributions made by many
 
14
 * individuals.  For exact contribution history, see the revision
 
15
 * history and logs, available at http://subversion.tigris.org/.
 
16
 * ====================================================================
 
17
 */
 
18
 
 
19
 
 
20
#include "svn_md5.h"
 
21
 
 
22
 
 
23
 
 
24
/* The MD5 digest for the empty string. */
 
25
static const unsigned char svn_md5__empty_string_digest[] = {
 
26
  212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126
 
27
};
 
28
 
 
29
const unsigned char *
 
30
svn_md5_empty_string_digest (void)
 
31
{
 
32
  return svn_md5__empty_string_digest;
 
33
}
 
34
 
 
35
 
 
36
const char *
 
37
svn_md5_digest_to_cstring_display (const unsigned char digest[],
 
38
                                   apr_pool_t *pool)
 
39
{
 
40
  static const char *hex = "0123456789abcdef";
 
41
  char *str = apr_palloc (pool, (APR_MD5_DIGESTSIZE * 2) + 1);
 
42
  int i;
 
43
  
 
44
  for (i = 0; i < APR_MD5_DIGESTSIZE; i++)
 
45
    {
 
46
      str[i*2]   = hex[digest[i] >> 4];
 
47
      str[i*2+1] = hex[digest[i] & 0x0f];
 
48
    }
 
49
  str[i*2] = '\0';
 
50
  
 
51
  return str;
 
52
}
 
53
  
 
54
 
 
55
const char *
 
56
svn_md5_digest_to_cstring (const unsigned char digest[], apr_pool_t *pool)
 
57
{
 
58
  static const unsigned char zeros_digest[APR_MD5_DIGESTSIZE] = { 0 };
 
59
 
 
60
  if (memcmp (digest, zeros_digest, APR_MD5_DIGESTSIZE) != 0)
 
61
    return svn_md5_digest_to_cstring_display (digest, pool);
 
62
  else
 
63
    return NULL;
 
64
}
 
65
 
 
66
 
 
67
svn_boolean_t
 
68
svn_md5_digests_match (unsigned const char d1[], unsigned const char d2[])
 
69
{
 
70
  static const unsigned char zeros[APR_MD5_DIGESTSIZE] = { 0 };
 
71
 
 
72
  return ((memcmp (d1, zeros, APR_MD5_DIGESTSIZE) == 0)
 
73
          || (memcmp (d2, zeros, APR_MD5_DIGESTSIZE) == 0)
 
74
          || (memcmp (d1, d2, APR_MD5_DIGESTSIZE) == 0));
 
75
}