Some new but untested functions
[gpgme.git] / gpgme / signers.c
1 /* signers.c - maintain signer sets
2  *      Copyright (C) 2001 Werner Koch (dd9jn)
3  *
4  * This file is part of GPGME.
5  *
6  * GPGME is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * GPGME is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19  */
20
21 #include <config.h>
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 (GpgmeCtx c)
37 {
38     int i;
39
40     return_if_fail (c);
41
42     if (!c->signers)
43         return;
44     for (i=0; i < c->signers_size; i++ ) {
45         if (!c->signers[i])
46             break;
47         gpgme_key_unref (c->signers[i]);
48         c->signers[i] = NULL;
49     }
50 }
51
52
53 GpgmeError
54 gpgme_signers_add (GpgmeCtx c, const GpgmeKey key)
55 {
56     int i = 0;
57
58     if (!c || !key)
59         return mk_error (Invalid_Value);
60
61     if (!c->signers)
62         c->signers_size = 0;
63
64     for (i=0; i < c->signers_size && c->signers[i]; i++ )
65         ;
66     if ( !(i < c->signers_size) ) {
67         GpgmeKey *newarr;
68         int j;
69         int n = c->signers_size + 5;
70
71         newarr = xtrycalloc ( n, sizeof *newarr );
72         if ( !newarr )
73             return mk_error (Out_Of_Core);
74         for (j=0; j < c->signers_size; j++ )
75             newarr[j] = c->signers[j];
76         c->signers_size = n;
77     }
78     gpgme_key_ref (key);
79     c->signers[i] = key;
80     return 0;
81 }
82
83
84 GpgmeKey
85 gpgme_signers_enum (const GpgmeCtx c, int seq )
86 {
87     int i;
88
89     return_null_if_fail (c);
90     return_null_if_fail (seq<0);
91
92     if (!c->signers)
93         c->signers_size = 0;
94     for (i=0; i < c->signers_size && c->signers[i]; i++ ) {
95         if (i==seq) {
96             gpgme_key_ref (c->signers[i]);
97             return c->signers[i];
98         }
99     }
100     return NULL;
101 }
102
103
104
105