1 |
/* signers.c - maintain signer sets |
2 |
* Copyright (C) 2001 Werner Koch (dd9jn) |
3 |
* Copyright (C) 2003 Timo Schulz |
4 |
* |
5 |
* This file is part of MyGPGME. |
6 |
* |
7 |
* MyGPGME is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* MyGPGME is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
*/ |
21 |
|
22 |
#include <stdio.h> |
23 |
#include <stdlib.h> |
24 |
#include <assert.h> |
25 |
|
26 |
#include "util.h" |
27 |
#include "context.h" |
28 |
#include "rungpg.h" |
29 |
|
30 |
/* The signers are directly stored in the context. |
31 |
* So this is quite different to a recipient set. |
32 |
*/ |
33 |
|
34 |
|
35 |
void |
36 |
gpgme_signers_clear (gpgme_ctx_t ctx) |
37 |
{ |
38 |
int i; |
39 |
|
40 |
return_if_fail( ctx ); |
41 |
if (!ctx->signers) |
42 |
return; |
43 |
for( i = 0; i < ctx->signers_size; i++ ) { |
44 |
if( !ctx->signers[i] ) |
45 |
break; |
46 |
gpgme_key_unref( ctx->signers[i] ); |
47 |
ctx->signers[i] = NULL; |
48 |
} |
49 |
} |
50 |
|
51 |
|
52 |
gpgme_error_t |
53 |
gpgme_signers_add( gpgme_ctx_t ctx, const gpgme_key_t key ) |
54 |
{ |
55 |
int i = 0; |
56 |
|
57 |
if (!ctx || !key) |
58 |
return mk_error (Invalid_Value); |
59 |
|
60 |
if (!ctx->signers) |
61 |
ctx->signers_size = 0; |
62 |
|
63 |
for (i=0; i < ctx->signers_size && ctx->signers[i]; i++ ) |
64 |
; |
65 |
if ( !(i < ctx->signers_size) ) { |
66 |
gpgme_key_t *newarr; |
67 |
int j; |
68 |
int n = ctx->signers_size + 5; |
69 |
|
70 |
newarr = calloc ( n, sizeof *newarr ); |
71 |
if ( !newarr ) |
72 |
return mk_error (Out_Of_Core); |
73 |
for (j=0; j < ctx->signers_size; j++ ) |
74 |
newarr[j] = ctx->signers[j]; |
75 |
ctx->signers_size = n; |
76 |
safe_free (ctx->signers); |
77 |
ctx->signers = newarr; |
78 |
} |
79 |
gpgme_key_ref (key); |
80 |
ctx->signers[i] = key; |
81 |
return 0; |
82 |
} |
83 |
|
84 |
|
85 |
gpgme_key_t |
86 |
gpgme_signers_enum( const gpgme_ctx_t ctx, int seq ) |
87 |
{ |
88 |
int i; |
89 |
|
90 |
return_null_if_fail( ctx ); |
91 |
return_null_if_fail( seq >= 0 ); |
92 |
|
93 |
if( !ctx->signers ) |
94 |
ctx->signers_size = 0; |
95 |
for (i=0; i < ctx->signers_size && ctx->signers[i]; i++) { |
96 |
if (i==seq) { |
97 |
gpgme_key_ref (ctx->signers[i]); |
98 |
return ctx->signers[i]; |
99 |
} |
100 |
} |
101 |
return NULL; |
102 |
} |