~nutznboltz-deactivatedaccount/ubuntu/precise/gnutls26/fix-lp926350

« back to all changes in this revision

Viewing changes to guile/src/extra.c

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
Tags: 2.12.11-1
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
/* Written by Ludovic Court�s <ludo@chbouib.org>.  */
22
22
 
23
23
#ifdef HAVE_CONFIG_H
24
 
# include <config.h>
 
24
#include <config.h>
25
25
#endif
26
26
 
27
27
#include <stdio.h>
54
54
#define GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH  2048
55
55
 
56
56
SCM_DEFINE (scm_gnutls_import_openpgp_certificate,
57
 
            "import-openpgp-certificate", 2, 0, 0, (SCM data, SCM format),
58
 
            "Return a new OpenPGP certificate object resulting from the "
59
 
            "import of @var{data} (a uniform array) according to "
60
 
            "@var{format}.")
 
57
            "import-openpgp-certificate", 2, 0, 0, (SCM data, SCM format),
 
58
            "Return a new OpenPGP certificate object resulting from the "
 
59
            "import of @var{data} (a uniform array) according to "
 
60
            "@var{format}.")
61
61
#define FUNC_NAME s_scm_gnutls_import_openpgp_certificate
62
62
{
63
63
  int err;
72
72
  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
73
73
 
74
74
  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
75
 
                                 FUNC_NAME);
 
75
                                 FUNC_NAME);
76
76
  c_data_d.data = (unsigned char *) c_data;
77
77
  c_data_d.size = c_data_len;
78
78
 
98
98
#undef FUNC_NAME
99
99
 
100
100
SCM_DEFINE (scm_gnutls_import_openpgp_private_key,
101
 
            "import-openpgp-private-key", 2, 1, 0, (SCM data, SCM format,
102
 
                                                    SCM pass),
103
 
            "Return a new OpenPGP private key object resulting from the "
104
 
            "import of @var{data} (a uniform array) according to "
105
 
            "@var{format}.  Optionally, a passphrase may be provided.")
 
101
            "import-openpgp-private-key", 2, 1, 0, (SCM data, SCM format,
 
102
                                                    SCM pass),
 
103
            "Return a new OpenPGP private key object resulting from the "
 
104
            "import of @var{data} (a uniform array) according to "
 
105
            "@var{format}.  Optionally, a passphrase may be provided.")
106
106
#define FUNC_NAME s_scm_gnutls_import_openpgp_private_key
107
107
{
108
108
  int err;
127
127
    }
128
128
 
129
129
  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
130
 
                                 FUNC_NAME);
 
130
                                 FUNC_NAME);
131
131
  c_data_d.data = (unsigned char *) c_data;
132
132
  c_data_d.size = c_data_len;
133
133
 
139
139
    }
140
140
 
141
141
  err = gnutls_openpgp_privkey_import (c_key, &c_data_d, c_format, c_pass,
142
 
                                       0 /* currently unused */ );
 
142
                                       0 /* currently unused */ );
143
143
  scm_gnutls_release_array (&c_data_handle);
144
144
 
145
145
  if (EXPECT_FALSE (err))
154
154
#undef FUNC_NAME
155
155
 
156
156
SCM_DEFINE (scm_gnutls_openpgp_certificate_id, "openpgp-certificate-id",
157
 
            1, 0, 0,
158
 
            (SCM key),
159
 
            "Return the ID (an 8-element u8vector) of certificate "
160
 
            "@var{key}.")
 
157
            1, 0, 0,
 
158
            (SCM key),
 
159
            "Return the ID (an 8-element u8vector) of certificate "
 
160
            "@var{key}.")
161
161
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id
162
162
{
163
163
  int err;
180
180
#undef FUNC_NAME
181
181
 
182
182
SCM_DEFINE (scm_gnutls_openpgp_certificate_id_x, "openpgp-certificate-id!",
183
 
            2, 0, 0,
184
 
            (SCM key, SCM id),
185
 
            "Store the ID (an 8 byte sequence) of certificate "
186
 
            "@var{key} in @var{id} (a u8vector).")
 
183
            2, 0, 0,
 
184
            (SCM key, SCM id),
 
185
            "Store the ID (an 8 byte sequence) of certificate "
 
186
            "@var{key} in @var{id} (a u8vector).")
187
187
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id_x
188
188
{
189
189
  int err;
194
194
 
195
195
  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
196
196
  c_id = scm_gnutls_get_writable_array (id, &c_id_handle, &c_id_size,
197
 
                                        FUNC_NAME);
 
197
                                        FUNC_NAME);
198
198
 
199
199
  if (EXPECT_FALSE (c_id_size < 8))
200
200
    {
214
214
#undef FUNC_NAME
215
215
 
216
216
SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerpint_x,
217
 
            "openpgp-certificate-fingerprint!",
218
 
            2, 0, 0,
219
 
            (SCM key, SCM fpr),
220
 
            "Store in @var{fpr} (a u8vector) the fingerprint of @var{key}.  "
221
 
            "Return the number of bytes stored in @var{fpr}.")
 
217
            "openpgp-certificate-fingerprint!",
 
218
            2, 0, 0,
 
219
            (SCM key, SCM fpr),
 
220
            "Store in @var{fpr} (a u8vector) the fingerprint of @var{key}.  "
 
221
            "Return the number of bytes stored in @var{fpr}.")
222
222
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerpint_x
223
223
{
224
224
  int err;
231
231
  SCM_VALIDATE_ARRAY (2, fpr);
232
232
 
233
233
  c_fpr = scm_gnutls_get_writable_array (fpr, &c_fpr_handle, &c_fpr_len,
234
 
                                         FUNC_NAME);
 
234
                                         FUNC_NAME);
235
235
 
236
236
  err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
237
237
  scm_gnutls_release_array (&c_fpr_handle);
245
245
#undef FUNC_NAME
246
246
 
247
247
SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerprint,
248
 
            "openpgp-certificate-fingerprint",
249
 
            1, 0, 0,
250
 
            (SCM key),
251
 
            "Return a new u8vector denoting the fingerprint of " "@var{key}.")
 
248
            "openpgp-certificate-fingerprint",
 
249
            1, 0, 0,
 
250
            (SCM key),
 
251
            "Return a new u8vector denoting the fingerprint of " "@var{key}.")
252
252
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerprint
253
253
{
254
254
  int err;
269
269
      c_actual_len = 0;
270
270
      err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
271
271
      if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
272
 
        {
273
 
          /* Grow C_FPR.  */
274
 
          unsigned char *c_new;
 
272
        {
 
273
          /* Grow C_FPR.  */
 
274
          unsigned char *c_new;
275
275
 
276
 
          c_new = (unsigned char *) realloc (c_fpr, c_fpr_len * 2);
277
 
          if (EXPECT_FALSE (c_new == NULL))
278
 
            {
279
 
              free (c_fpr);
280
 
              scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
281
 
            }
282
 
          else
283
 
            {
284
 
              c_fpr_len *= 2;
285
 
              c_fpr = c_new;
286
 
            }
287
 
        }
 
276
          c_new = (unsigned char *) realloc (c_fpr, c_fpr_len * 2);
 
277
          if (EXPECT_FALSE (c_new == NULL))
 
278
            {
 
279
              free (c_fpr);
 
280
              scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
 
281
            }
 
282
          else
 
283
            {
 
284
              c_fpr_len *= 2;
 
285
              c_fpr = c_new;
 
286
            }
 
287
        }
288
288
    }
289
289
  while (err == GNUTLS_E_SHORT_MEMORY_BUFFER);
290
290
 
304
304
#undef FUNC_NAME
305
305
 
306
306
SCM_DEFINE (scm_gnutls_openpgp_certificate_name, "openpgp-certificate-name",
307
 
            2, 0, 0,
308
 
            (SCM key, SCM index),
309
 
            "Return the @var{index}th name of @var{key}.")
 
307
            2, 0, 0,
 
308
            (SCM key, SCM index),
 
309
            "Return the @var{index}th name of @var{key}.")
310
310
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_name
311
311
{
312
312
  int err;
329
329
#undef FUNC_NAME
330
330
 
331
331
SCM_DEFINE (scm_gnutls_openpgp_certificate_names, "openpgp-certificate-names",
332
 
            1, 0, 0, (SCM key), "Return the list of names for @var{key}.")
 
332
            1, 0, 0, (SCM key), "Return the list of names for @var{key}.")
333
333
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_names
334
334
{
335
335
  int err;
345
345
    {
346
346
      err = gnutls_openpgp_crt_get_name (c_key, c_index, c_name, &c_name_len);
347
347
      if (!err)
348
 
        {
349
 
          result = scm_cons (scm_from_locale_string (c_name), result);
350
 
          c_index++;
351
 
        }
 
348
        {
 
349
          result = scm_cons (scm_from_locale_string (c_name), result);
 
350
          c_index++;
 
351
        }
352
352
    }
353
353
  while (!err);
354
354
 
361
361
#undef FUNC_NAME
362
362
 
363
363
SCM_DEFINE (scm_gnutls_openpgp_certificate_algorithm,
364
 
            "openpgp-certificate-algorithm",
365
 
            1, 0, 0,
366
 
            (SCM key),
367
 
            "Return two values: the certificate algorithm used by "
368
 
            "@var{key} and the number of bits used.")
 
364
            "openpgp-certificate-algorithm",
 
365
            1, 0, 0,
 
366
            (SCM key),
 
367
            "Return two values: the certificate algorithm used by "
 
368
            "@var{key} and the number of bits used.")
369
369
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_algorithm
370
370
{
371
371
  gnutls_openpgp_crt_t c_key;
376
376
  c_algo = gnutls_openpgp_crt_get_pk_algorithm (c_key, &c_bits);
377
377
 
378
378
  return (scm_values (scm_list_2 (scm_from_gnutls_pk_algorithm (c_algo),
379
 
                                  scm_from_uint (c_bits))));
 
379
                                  scm_from_uint (c_bits))));
380
380
}
381
381
 
382
382
#undef FUNC_NAME
383
383
 
384
384
SCM_DEFINE (scm_gnutls_openpgp_certificate_version,
385
 
            "openpgp-certificate-version",
386
 
            1, 0, 0,
387
 
            (SCM key),
388
 
            "Return the version of the OpenPGP message format (RFC2440) "
389
 
            "honored by @var{key}.")
 
385
            "openpgp-certificate-version",
 
386
            1, 0, 0,
 
387
            (SCM key),
 
388
            "Return the version of the OpenPGP message format (RFC2440) "
 
389
            "honored by @var{key}.")
390
390
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_version
391
391
{
392
392
  int c_version;
401
401
#undef FUNC_NAME
402
402
 
403
403
SCM_DEFINE (scm_gnutls_openpgp_certificate_usage, "openpgp-certificate-usage",
404
 
            1, 0, 0,
405
 
            (SCM key),
406
 
            "Return a list of values denoting the key usage of @var{key}.")
 
404
            1, 0, 0,
 
405
            (SCM key),
 
406
            "Return a list of values denoting the key usage of @var{key}.")
407
407
#define FUNC_NAME s_scm_gnutls_openpgp_certificate_usage
408
408
{
409
409
  int err;
426
426
/* OpenPGP keyrings.  */
427
427
 
428
428
SCM_DEFINE (scm_gnutls_import_openpgp_keyring, "import-openpgp-keyring",
429
 
            2, 0, 0,
430
 
            (SCM data, SCM format),
431
 
            "Import @var{data} (a u8vector) according to @var{format} "
432
 
            "and return the imported keyring.")
 
429
            2, 0, 0,
 
430
            (SCM data, SCM format),
 
431
            "Import @var{data} (a u8vector) according to @var{format} "
 
432
            "and return the imported keyring.")
433
433
#define FUNC_NAME s_scm_gnutls_import_openpgp_keyring
434
434
{
435
435
  int err;
444
444
  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
445
445
 
446
446
  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
447
 
                                 FUNC_NAME);
 
447
                                 FUNC_NAME);
448
448
 
449
449
  c_data_d.data = (unsigned char *) c_data;
450
450
  c_data_d.size = c_data_len;
471
471
#undef FUNC_NAME
472
472
 
473
473
SCM_DEFINE (scm_gnutls_openpgp_keyring_contains_key_id_p,
474
 
            "openpgp-keyring-contains-key-id?",
475
 
            2, 0, 0,
476
 
            (SCM keyring, SCM id),
477
 
            "Return @code{#f} if key ID @var{id} is in @var{keyring}, "
478
 
            "@code{#f} otherwise.")
 
474
            "openpgp-keyring-contains-key-id?",
 
475
            2, 0, 0,
 
476
            (SCM keyring, SCM id),
 
477
            "Return @code{#f} if key ID @var{id} is in @var{keyring}, "
 
478
            "@code{#f} otherwise.")
479
479
#define FUNC_NAME s_scm_gnutls_openpgp_keyring_contains_key_id_p
480
480
{
481
481
  int c_result;
495
495
    }
496
496
 
497
497
  c_result = gnutls_openpgp_keyring_check_id (c_keyring,
498
 
                                              (unsigned char *) c_id,
499
 
                                              0 /* unused */ );
 
498
                                              (unsigned char *) c_id,
 
499
                                              0 /* unused */ );
500
500
 
501
501
  scm_gnutls_release_array (&c_id_handle);
502
502
 
509
509
/* Certificates.  */
510
510
 
511
511
SCM_DEFINE (scm_gnutls_set_certificate_credentials_openpgp_keys_x,
512
 
            "set-certificate-credentials-openpgp-keys!",
513
 
            3, 0, 0,
514
 
            (SCM cred, SCM pub, SCM sec),
515
 
            "Use certificate @var{pub} and secret key @var{sec} in "
516
 
            "certificate credentials @var{cred}.")
 
512
            "set-certificate-credentials-openpgp-keys!",
 
513
            3, 0, 0,
 
514
            (SCM cred, SCM pub, SCM sec),
 
515
            "Use certificate @var{pub} and secret key @var{sec} in "
 
516
            "certificate credentials @var{cred}.")
517
517
#define FUNC_NAME s_scm_gnutls_set_certificate_credentials_openpgp_keys_x
518
518
{
519
519
  int err;