~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-proposed

« back to all changes in this revision

Viewing changes to sm/fingerprint.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-05-15 13:54:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515135455-89qfyalmgjy6gcqw
Tags: 2.0.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
  - Include /doc files as done with gnupg
  - debian/rules: add doc/com-certs.pem to the docs for gpgsm
  - debian/copyright: update download url
  - debian/README.Debian: remove note the gnupg2 isn't released yet.
  - debian/control: Change Maintainer/XSBC-Original-Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
  if (r_len)
62
62
    *r_len = len;
63
63
 
 
64
  /* Fist check whether we have cached the fingerprint.  */
 
65
  if (algo == GCRY_MD_SHA1)
 
66
    {
 
67
      size_t buflen;
 
68
 
 
69
      assert (len >= 20);
 
70
      if (!ksba_cert_get_user_data (cert, "sha1-fingerprint", 
 
71
                                    array, len, &buflen)
 
72
          && buflen == 20)
 
73
        return array;
 
74
    }
 
75
 
 
76
  /* No, need to compute it.  */
64
77
  rc = gcry_md_open (&md, algo, 0);
65
78
  if (rc)
66
79
    {
80
93
  gcry_md_final (md);
81
94
  memcpy (array, gcry_md_read(md, algo), len );
82
95
  gcry_md_close (md);
 
96
 
 
97
  /* Cache an SHA-1 fingerprint.  */
 
98
  if ( algo == GCRY_MD_SHA1 )
 
99
    ksba_cert_set_user_data (cert, "sha1-fingerprint", array, 20);
 
100
 
83
101
  return array;
84
102
}
85
103
 
90
108
{
91
109
  unsigned char digest[MAX_DIGEST_LEN];
92
110
  char *buf;
93
 
  int len, i;
 
111
  int len;
94
112
 
95
113
  if (!algo)
96
114
    algo = GCRY_MD_SHA1;
99
117
  assert (len <= MAX_DIGEST_LEN );
100
118
  gpgsm_get_fingerprint (cert, algo, digest, NULL);
101
119
  buf = xmalloc (len*3+1);
102
 
  *buf = 0;
103
 
  for (i=0; i < len; i++ )
104
 
    sprintf (buf+strlen(buf), i? ":%02X":"%02X", digest[i]);
 
120
  bin2hexcolon (digest, len, buf);
105
121
  return buf;
106
122
}
107
123
 
112
128
{
113
129
  unsigned char digest[MAX_DIGEST_LEN];
114
130
  char *buf;
115
 
  int len, i;
 
131
  int len;
116
132
 
117
133
  if (!algo)
118
134
    algo = GCRY_MD_SHA1;
120
136
  len = gcry_md_get_algo_dlen (algo);
121
137
  assert (len <= MAX_DIGEST_LEN );
122
138
  gpgsm_get_fingerprint (cert, algo, digest, NULL);
123
 
  buf = xmalloc (len*3+1);
124
 
  *buf = 0;
125
 
  for (i=0; i < len; i++ )
126
 
    sprintf (buf+strlen(buf), "%02X", digest[i]);
 
139
  buf = xmalloc (len*2+1);
 
140
  bin2hex (digest, len, buf);
127
141
  return buf;
128
142
}
129
143
 
190
204
gpgsm_get_keygrip_hexstring (ksba_cert_t cert)
191
205
{
192
206
  unsigned char grip[20];
193
 
  char *buf, *p;
194
 
  int i;
 
207
  char *buf;
195
208
 
196
209
  gpgsm_get_keygrip (cert, grip);
197
 
  buf = p = xmalloc (20*2+1);
198
 
  for (i=0; i < 20; i++, p += 2 )
199
 
    sprintf (p, "%02X", grip[i]);
 
210
  buf = xmalloc (20*2+1);
 
211
  bin2hex (grip, 20, buf);
200
212
  return buf;
201
213
}
202
214