/[winpt]/trunk/Src/wptKeyEdit.cpp
ViewVC logotype

Annotation of /trunk/Src/wptKeyEdit.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 175 - (hide annotations)
Tue Feb 7 08:58:04 2006 UTC (19 years ago) by twoaday
File size: 18874 byte(s)
2006-02-04  Timo Schulz  <ts@g10code.de>
                                                                                                                            
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Check for
        at least one ultimately trusted key.
        * wptKeyManager.cpp (km_refresh_key_from_keyserver):
        Only check inet connection if we refresh all keys.
        * wptGPGUtil.cpp (gpg_extract_keys): New.
        * wptClipEncryptDlg.cpp (clip_encrypt_dlg_proc): Use textmode.
        * wptClipSignEncDlg.cpp (clip_signenc_dlg_proc): Likewise.
        * wptClipSignDlg.cpp (get_selected_key): New.
        (one_key_proc): Use it here.
        (count_useable_seckeys): New.
        * wptSigTreeDlg.cpp (sigtree_dlg_proc): New.
        * wptKeyEditDlgs.cpp (diff_time): Removed.
        (w32_mktime): New.
        (keyedit_addsubkey_dlg_proc): Use it here.
                                                                                                                            
2006-02-02  Timo Schulz  <ts@g10code.de>
                                                                                                                            
        * wptW32API.cpp (get_temp_name): New.
        * wptKeyserver.cpp (ldap_recvkey): Use it here.
        * wptKeyPropsDlg.cpp (get_photo_tmpname): Likewise.
        * wptGPGUtil.cpp (create_tempfile): Likewise.
        * wptImportList.cpp (implist_load): Likewise.
        * wptKeyCache.cpp (parse_attr_data): Likewise.
        (w32_tempfile): Removed.
        * wptGPGME.cpp (check_ultimate_trusted_key): New.
                                                                                                                            

1 werner 36 /* wptKeyEdit.cpp - GPG key edit abstraction
2 twoaday 170 * Copyright (C) 2005, 2006 Timo Schulz
3 werner 36 * Copyright (C) 2005 g10 Code GmbH
4     *
5     * This file is part of WinPT.
6     *
7     * WinPT is free software; you can redistribute it and/or
8     * modify it under the terms of the GNU General Public License
9     * as published by the Free Software Foundation; either version 2
10     * of the License, or (at your option) any later version.
11     *
12     * WinPT 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 GNU
15     * General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with WinPT; if not, write to the Free Software Foundation,
19     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21    
22     #ifdef HAVE_CONFIG_H
23     #include <config.h>
24     #endif
25    
26     #include <windows.h>
27 werner 48 #include <time.h>
28 werner 36
29     #include "gpgme.h"
30     #include "wptCommonCtl.h"
31     #include "wptContext.h"
32     #include "wptKeyEdit.h"
33     #include "wptTypes.h"
34     #include "wptW32API.h"
35     #include "wptGPG.h"
36     #include "wptErrors.h"
37    
38    
39     /* Parse the colon status information of @line and store
40     the information in @rev.
41     Return value: 0 on success. */
42     static gpgme_error_t
43     rev_key_colon_handler (gpg_desig_rev_t *rev, char *line)
44     {
45     char *p, *pend;
46     gpg_desig_rev_t r, t;
47     int field = 0;
48    
49     if (!line || strlen (line) < 3)
50     return gpg_error (GPG_ERR_EOF);
51     if (strncmp (line, "rvk", 3))
52     return 0; /* skip this line. */
53    
54     log_debug ("rev_key: line=%s\r\n", line);
55    
56     r = (gpg_desig_rev_t)calloc (1, sizeof *r);
57     if (!r)
58     return gpg_error (GPG_ERR_ENOMEM);
59     if (!*rev)
60     *rev = r;
61     else {
62     for (t=*rev; t->next; t=t->next)
63     ;
64     t->next = r;
65     }
66    
67     p = strdup (line);
68     if (!p)
69     return gpg_error (GPG_ERR_ENOMEM);
70    
71     for (;;) {
72     field++;
73     pend = strsep (&p, ":");
74     if (pend == NULL)
75     break;
76     switch (field) {
77     case 4: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break;
78     case 10: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break;
79     }
80     }
81     if (p)
82     free (p);
83     return 0;
84     }
85    
86    
87     /* Parse the colon data output of edit key from @line and
88     store the information in the @inf context.
89     Return value: 0 on success. */
90     static gpgme_error_t
91     uid_inf_colon_handler (gpg_uid_info_t *inf, char *line)
92     {
93     gpg_uid_info_t i, t;
94     char *p, *pend;
95     int field = 0, len = 0;
96    
97     if (!line || strlen (line) < 3 || strncmp (line, "uid", 3))
98     return gpg_error (GPG_ERR_EOF);
99    
100     i = (gpg_uid_info_t)calloc (1, sizeof *i);
101     if (!i)
102     return gpg_error (GPG_ERR_ENOMEM);
103     if (!*inf)
104     *inf = i;
105     else {
106     for (t=*inf; t->next; t=t->next)
107     ;
108     t->next = i;
109     }
110    
111     p = strdup (line);
112     if (!p)
113     return gpg_error (GPG_ERR_ENOMEM);;
114     for (;;) {
115     field++;
116     pend = strsep (&p, ":");
117     if (pend == NULL)
118     break;
119    
120     switch (field) {
121     case 2: /* trust info */
122     break;
123    
124     case 10: /* user ID */
125     i->name = (char *)calloc (1, strlen (pend)+1);
126     if (!i->name)
127     return gpg_error (GPG_ERR_ENOMEM);;
128     gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1);
129     if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) {
130     int pos = strchr (i->name, '<')- i->name + 1;
131     int end = strchr (i->name, '>') - i->name;
132     i->email = (char*) calloc (1, end-pos+2);
133     if (!i->email)
134     return gpg_error (GPG_ERR_ENOMEM);;
135     memcpy (i->email, i->name+pos, (end-pos));
136     }
137     break;
138    
139     case 13: /* preferences */
140     if (strstr (pend, "mdc")) {
141     len = strlen (pend) - 4; /* ,mdc */
142     if (strstr (pend, "no-ks-modify")) {
143     i->flags.no_ks_modify = 1;
144     len -= 13; /* ,no-ks-modify */
145     }
146     i->prefs = (char*)calloc (1, len+1);
147     if (!i->prefs)
148     return gpg_error (GPG_ERR_ENOMEM);
149     memcpy (i->prefs, pend, len);
150     i->prefs[len] = '\0';
151     i->flags.mdc = 1;
152     }
153     else {
154     i->prefs = strdup (pend);
155     if (!i->prefs)
156     return gpg_error (GPG_ERR_ENOMEM);
157     i->flags.mdc = 0;
158     }
159     break;
160    
161     case 14: /* index/flags */
162     i->index = atol (pend);
163     if (strchr (pend, 'r'))
164     i->flags.revoked = 1;
165     if (strchr (pend, 'p'))
166     i->flags.primary = 1;
167     break;
168     }
169     }
170     if (p)
171     free (p);
172     return 0;
173     }
174    
175    
176     /* Release the context in @inf. */
177     void
178     gpg_uid_info_release (gpg_uid_info_t list)
179     {
180     gpg_uid_info_t i;
181    
182     while (list) {
183     i = list->next;
184     if (list->name) {
185     if (list->name)
186     free (list->name);
187     list->name = NULL;
188     }
189     if (list->prefs) {
190     if (list->prefs)
191     free (list->prefs);
192     list->prefs = NULL;
193     }
194     free (list);
195     list = i;
196     }
197     }
198    
199    
200     /* Release the context in @rev. */
201     void
202     gpg_desig_rev_release (gpg_desig_rev_t rev)
203     {
204     gpg_desig_rev_t r;
205    
206     while (rev) {
207     r = rev->next;
208     free (rev);
209     rev = r;
210     }
211     }
212    
213    
214     static gpgme_error_t
215     list2_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)
216     {
217     DWORD n;
218     const char *s;
219    
220     if (!strcmp (key, "keyedit.prompt")) {
221     s = "quit\n";
222     WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
223     }
224     return 0;
225     }
226    
227 twoaday 170
228 werner 36 /* Dummy handler to get the colon data and then quit. */
229     static gpgme_error_t
230     list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)
231     {
232     static int step=0;
233     const char *s="";
234     DWORD n;
235    
236     if (!strcmp (key, "keyedit.prompt") && step == 0) {
237     step = 1;
238     s = "list\n";
239     WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
240     }
241     else if (!strcmp (key, "keyedit.prompt") && step == 1) {
242     step = 0;
243     s = "quit\n";
244     WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
245     }
246    
247     return 0;
248     }
249    
250    
251     /* Return all designated revokers for this key. If no revoker
252     was set, @r_rev is NULL.
253     Return value: 0 on success. */
254     gpgme_error_t
255     GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev)
256     {
257 twoaday 129 gpgme_data_t out = NULL;
258 werner 36 gpg_desig_rev_t rev = NULL;
259     gpgme_error_t err;
260     char buf[256];
261    
262     if (!this->key)
263     return gpg_error (GPG_ERR_INV_OBJ);
264    
265     err = gpgme_data_new (&out);
266     if (err)
267     goto leave;
268    
269     err = gpgme_op_edit (ctx, key, list2_handler, NULL, out);
270     if (err)
271     goto leave;
272    
273     gpgme_data_rewind (out);
274     while (gpg_data_readline (out, buf, sizeof (buf)-1) > 0)
275     rev_key_colon_handler (&rev, buf);
276     *r_rev = rev;
277    
278     leave:
279     if (out)
280     gpgme_data_release (out);
281     if (err) {
282     gpg_desig_rev_release (rev);
283     *r_rev = NULL;
284     }
285     return err;
286     }
287    
288 twoaday 170
289 werner 36 /* Retrieve all user ID information of the key set via setKey
290     in @r_inf. The result also contains the user ID number which
291     is needed to securely delete the user-ID. */
292     gpgme_error_t
293     GpgKeyEdit::getUseridInfo (gpg_uid_info_t *r_uinf)
294     {
295     gpgme_data_t out = NULL;
296     gpgme_error_t err;
297     gpg_uid_info_t inf = NULL;
298     char buf[256];
299    
300     if (!this->key)
301     return gpg_error (GPG_ERR_INV_OBJ);
302    
303     err = gpgme_data_new (&out);
304     if (err)
305     goto leave;
306    
307     err = gpgme_op_edit (ctx, key, list_handler, NULL, out);
308     if (err)
309     goto leave;
310    
311     gpgme_data_rewind (out);
312     while (gpg_data_readline (out, buf, sizeof (buf) -1) > 0)
313     uid_inf_colon_handler (&inf, buf);
314    
315     *r_uinf = inf;
316    
317     leave:
318     if (out)
319     gpgme_data_release (out);
320     if (err) {
321     gpg_uid_info_release (inf);
322     *r_uinf = NULL;
323     }
324     return err;
325     }
326    
327    
328 twoaday 170 /* Clear object. */
329     void
330     GpgKeyEdit::clear (void)
331 werner 36 {
332 twoaday 170 pass = NULL;
333 werner 36 name = NULL;
334     cmt = NULL;
335     email = NULL;
336 twoaday 170 type = 0;
337 werner 36 cnt = 0;
338     cmd_sent = 0;
339     resval = 0;
340 twoaday 170 uid_index = sig_index = key_index = -1;
341     }
342    
343    
344     /* Construct an object with the given key in @key. */
345     GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key)
346     {
347     clear ();
348     this->key = _key;
349 werner 36 gpgme_new (&ctx); /* FIXME */
350     }
351    
352     /* Construct an object and fetch the key with the keyid @keyid. */
353 twoaday 69 GpgKeyEdit::GpgKeyEdit (const char *_keyid)
354 werner 36 {
355 twoaday 170 clear ();
356 twoaday 69 get_pubkey (_keyid, &this->key);
357 twoaday 170 gpgme_new (&ctx); /* FIXME */
358 werner 36 }
359    
360     /* Delete the given object. */
361     GpgKeyEdit::~GpgKeyEdit (void)
362     {
363     free_if_alloc (name);
364     free_if_alloc (cmt);
365     free_if_alloc (email);
366     gpgme_release (ctx);
367     }
368    
369    
370     /* Reset the state of the object. */
371     void
372     GpgKeyEdit::reset (void)
373     {
374     cmd_sent = 0;
375 twoaday 129 cnt = 0;
376     //resval = 0;
377 werner 36 }
378    
379    
380     /* Return true if type has a non-zero value. */
381     bool
382     GpgKeyEdit::isValid (void)
383     {
384     return type != 0;
385     }
386    
387    
388     /* Return the GPGME key. */
389     gpgme_key_t
390     GpgKeyEdit::getKey (void)
391     {
392     return key;
393     }
394    
395    
396     /* Set the GPGME callback to @cb. The hook value can be
397     given in @cb_value. */
398     void
399     GpgKeyEdit::setCallback (gpgme_progress_cb_t cb, void *cb_value)
400     {
401     gpgme_set_progress_cb (ctx, cb, cb_value);
402     }
403    
404 twoaday 175
405     /* Clear the stored passphrase. */
406     void
407     GpgKeyEdit::clearPassphrase (void)
408     {
409     if (pass)
410     pass = NULL;
411     }
412    
413    
414 werner 36 /* Set the passphrase to @pass. */
415     void
416 twoaday 69 GpgKeyEdit::setPassphrase (const char *_pass)
417 werner 36 {
418 twoaday 69 this->pass = _pass;
419 werner 36 }
420    
421     /* Set the current key to @key. */
422     void
423 twoaday 69 GpgKeyEdit::setKey (gpgme_key_t _key)
424 werner 36 {
425 twoaday 69 this->key = _key;
426 werner 36 }
427    
428     /* Set the keyid of the destination key to @keyid. */
429     void
430 twoaday 69 GpgKeyEdit::setKeyID (const char *_keyid)
431 werner 36 {
432 twoaday 69 if (!_keyid)
433 werner 36 return;
434 twoaday 69 get_pubkey (_keyid, &this->key);
435 werner 36 }
436    
437    
438     /* Set the local user for the operation to @locusr. */
439     void
440     GpgKeyEdit::setLocalUser (gpgme_key_t locusr)
441     {
442     gpgme_signers_add (ctx, locusr);
443     }
444    
445     /* Set the result of the operation to @val. */
446     void
447     GpgKeyEdit::setResult (int val)
448     {
449     resval |= val;
450     }
451    
452    
453     /* Return the result of the operation. */
454     int
455     GpgKeyEdit::getResult(void)
456     {
457     return resval;
458     }
459    
460    
461    
462     int
463     GpgKeyEdit::getType (void)
464     {
465     return type;
466     }
467    
468     /* Sign the key stored in the object with the
469     signing mode @mode and the signature class @sig_class.
470     Return value: 0 on success. */
471     gpgme_error_t
472 twoaday 69 GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date)
473 werner 36 {
474     if (!this->key || !this->pass)
475     return gpg_error (GPG_ERR_INV_OBJ);
476    
477     type = mode;
478 twoaday 69 this->exp_date = _exp_date;
479     this->sig_class = _sig_class;
480 werner 36 return gpg_editkey (this->ctx, this->key, this);
481     }
482    
483 twoaday 170
484     /* Sign a single user-id with the index @_uid_index.
485     All other parameters are equal to signKey().
486     Return value: 0 on success. */
487     gpgme_error_t
488     GpgKeyEdit::signUserid (int _uid_idx, int mode, int _sig_class,
489     const char *_exp_date)
490     {
491     if (!this->key || !this->pass)
492     return gpg_error (GPG_ERR_INV_OBJ);
493     this->uid_index = _uid_idx;
494     type = mode;
495     this->exp_date = _exp_date;
496     this->sig_class = _sig_class;
497     return gpg_editkey (this->ctx, this->key, this);
498     }
499    
500    
501 werner 36 /* Set the ownertrust of the key stored in the object
502     to the trust value @trust.
503     Return value: 0 on success. */
504     gpgme_error_t
505     GpgKeyEdit::setTrust (gpgme_validity_t trust)
506     {
507     if (!this->key)
508     return gpg_error (GPG_ERR_INV_OBJ);
509    
510     type = GPG_EDITKEY_TRUST;
511     this->trust_id = (int)trust;
512     return gpg_editkey (this->ctx, this->key, this);
513     }
514    
515     /* Add a user ID to the given key with the @name as the
516     name, @cmt as the comment (or NULL) and @email as the email.
517     Return value: 0 on success. */
518     gpgme_error_t
519 twoaday 77 GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email)
520 werner 36 {
521     if (!this->key || !this->pass)
522     return gpg_error (GPG_ERR_INV_OBJ);
523    
524     type = GPG_EDITKEY_ADDUID;
525     free_if_alloc (this->name);
526 twoaday 77 this->name = m_strdup (_name);
527 werner 36 free_if_alloc (this->cmt);
528     this->cmt = NULL;
529 twoaday 129 if (_cmt != NULL)
530 twoaday 77 this->cmt = m_strdup (_cmt);
531 werner 36 free_if_alloc (this->email);
532 twoaday 77 this->email = m_strdup (_email);
533 werner 36 if (!this->email || !this->name)
534     BUG (NULL);
535     return gpg_editkey (this->ctx, this->key, this);
536     }
537    
538     /* Delete the user-ID with the index @uid_index of the given key.
539     Return value: 0 on success. */
540     gpgme_error_t
541 twoaday 69 GpgKeyEdit::delUserid (int _uid_index)
542 werner 36 {
543     if (!this->key)
544     return gpg_error (GPG_ERR_INV_OBJ);
545    
546     type = GPG_EDITKEY_DELUID;
547 twoaday 69 this->uid_index = _uid_index;
548 werner 36 return gpg_editkey (this->ctx, this->key, this);
549     }
550    
551     /* Delete the subkey with the index @key_index.
552     Return value: 0 on success. */
553     gpgme_error_t
554 twoaday 69 GpgKeyEdit::delKey (int _key_index)
555 werner 36 {
556     if (!this->key)
557     return gpg_error (GPG_ERR_INV_OBJ);
558    
559     type = GPG_EDITKEY_DELKEY;
560 twoaday 69 this->key_index = _key_index;
561 werner 36 return gpg_editkey (this->ctx, this->key, this);
562     }
563    
564     /* Add a new subkey to the given key.
565     The new key will have @pubkey_algo as the algorithm
566     and a size of @pubkey_size bits. If valid > 0, the
567     key expires in @valid days.
568     Return value: 0 on success. */
569     gpgme_error_t
570 twoaday 77 GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo,
571     unsigned int _pubkey_size, long _valid)
572 werner 36 {
573     if (!this->key || !this->pass)
574     return gpg_error (GPG_ERR_INV_OBJ);
575    
576     type = GPG_EDITKEY_ADDKEY;
577 twoaday 77 this->pubkey_algo = _pubkey_algo;
578     this->pubkey_size = _pubkey_size;
579     this->valid = _valid;
580 werner 36 return gpg_editkey (this->ctx, this->key, this);
581     }
582    
583     /* Change the passphrase of the given key to @new_pass.
584     If allow_empty != 0, it is allowed to provide an empty passphrase.
585     Return value: 0 on success. */
586     gpgme_error_t
587 twoaday 69 GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty)
588 werner 36 {
589     if (!this->key || !this->pass)
590     return gpg_error (GPG_ERR_INV_OBJ);
591    
592     type = GPG_EDITKEY_PASSWD;
593 twoaday 69 this->new_pass = _new_pass;
594 werner 36 this->flags = allow_empty? 1 : 0;
595     return gpg_editkey (this->ctx, this->key, this);
596     }
597    
598     /* Set the primary user-ID of the given key to user-ID with
599     the index @uid_index.
600     Return value: 0 on success. */
601     gpgme_error_t
602 twoaday 69 GpgKeyEdit::setPrimaryUserid (int _uid_index)
603 werner 36 {
604     if (!this->key || !this->pass)
605     return gpg_error (GPG_ERR_INV_OBJ);
606    
607     type = GPG_EDITKEY_PRIMARY;
608 twoaday 69 this->uid_index = _uid_index;
609 werner 36 return gpg_editkey (this->ctx, this->key, this);
610     }
611    
612     /* Set the expire date of the subkey with the index @key_index.
613     @exp_timestamp is used to calculate the days the key is valid.
614     if @exp_days is true, exp_timestamp is already converted to days.
615     Return value: 0 on success. */
616     gpgme_error_t
617 twoaday 129 GpgKeyEdit::setKeyExpireDate (int _key_index, long exp_timestamp,
618     bool exp_days)
619 werner 36 {
620     if (!this->key || !this->pass)
621     return gpg_error (GPG_ERR_INV_OBJ);
622     if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL))
623     return gpg_error (GPG_ERR_INV_ARG);
624    
625     type = GPG_EDITKEY_EXPIRE;
626     if (!exp_days && exp_timestamp > 0) {
627     valid = exp_timestamp - time (NULL);
628     valid /= 86400;
629     }
630     else
631     valid = exp_timestamp;
632 twoaday 69 this->key_index = _key_index;
633 werner 36 return gpg_editkey (this->ctx, this->key, this);
634     }
635    
636     /* Revoke the userid given by the index @uid_index.
637     Return value: 0 on success. */
638     gpgme_error_t
639 twoaday 69 GpgKeyEdit::revokeUserid (int _uid_index)
640 werner 36 {
641     if (!this->key || !this->pass)
642     return gpg_error (GPG_ERR_INV_OBJ);
643    
644     type = GPG_EDITKEY_REVUID;
645 twoaday 69 this->uid_index = _uid_index;
646 werner 36 return gpg_editkey (this->ctx, this->key, this);
647     }
648    
649    
650     /* Revoke a signature on the user-ID with the index @uid_index
651     and the signature index @sig_index.
652     Return value: 0 on success. */
653     gpgme_error_t
654 twoaday 69 GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index)
655 werner 36 {
656     if (!this->key || !this->pass)
657     return gpg_error (GPG_ERR_INV_OBJ);
658    
659     type = GPG_EDITKEY_REVSIG;
660 twoaday 69 this->uid_index = _uid_index;
661     this->sig_index = _sig_index;
662 werner 36 return gpg_editkey (this->ctx, this->key, this);
663     }
664    
665    
666     /* Revoke the subkey with the index @key_index. Optionally
667     a reason can be provided in @reason with a text to describe
668     more details in @cmt.
669     Return value: 0 on success. */
670     gpgme_error_t
671 twoaday 69 GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt)
672 werner 36 {
673     if (!this->key || !this->pass)
674     return gpg_error (GPG_ERR_INV_OBJ);
675    
676     type = GPG_EDITKEY_REVKEY;
677 twoaday 69 this->key_index = _key_index;
678     this->reason = _reason;
679 werner 36 free_if_alloc (this->cmt);
680     this->cmt = NULL;
681 twoaday 69 if (_cmt)
682     this->cmt = m_strdup (_cmt);
683 werner 36 return gpg_editkey (this->ctx, this->key, this);
684     }
685    
686    
687     /* Add a designated revoker to the key. @uid stores
688     the user-ID of the key who is allowed to be a
689     designated revoker.
690     Return value: 0 on success. */
691     gpgme_error_t
692     GpgKeyEdit::addDesignatedRevoker (const char *uid)
693     {
694     if (!this->key || !this->pass)
695     return gpg_error (GPG_ERR_INV_OBJ);
696    
697     type = GPG_EDITKEY_ADDREV;
698     free_if_alloc (this->name);
699     this->name = m_strdup (uid);
700     return gpg_editkey (this->ctx, this->key, this);
701     }
702    
703     /* Add a photo-ID to the key. The JPG image is given
704     in the file with the name @jpg_file.
705     Return value: 0 on success. */
706     gpgme_error_t
707     GpgKeyEdit::addPhotoid (const char *jpg_file)
708     {
709     if (!this->key || !this->pass)
710     return gpg_error (GPG_ERR_INV_OBJ);
711    
712     type = GPG_EDITKEY_ADDPHOTO;
713     this->url = jpg_file;
714     return gpg_editkey (this->ctx, this->key, this);
715     }
716    
717     /* Enable the given key. */
718     gpgme_error_t
719     GpgKeyEdit::enable (void)
720     {
721     if (!this->key)
722     return gpg_error (GPG_ERR_INV_OBJ);
723     type = GPG_EDITKEY_ENABLE;
724     return gpg_editkey (this->ctx, this->key, this);
725     }
726    
727     /* Disable the given key. */
728     gpgme_error_t
729     GpgKeyEdit::disable (void)
730     {
731     if (!this->key)
732     return gpg_error (GPG_ERR_INV_OBJ);
733     type = GPG_EDITKEY_DISABLE;
734     return gpg_editkey (this->ctx, this->key, this);
735     }
736    
737    
738 twoaday 119 /* Remove unusable parts from a key. */
739     gpgme_error_t
740     GpgKeyEdit::cleanKey (void)
741     {
742     if (!this->key)
743     return gpg_error (GPG_ERR_INV_OBJ);
744     type = GPG_EDITKEY_CLEAN;
745     return gpg_editkey (this->ctx, this->key, this);
746     }
747    
748    
749 werner 36 /* Update the user-ID preferences of the user-ID with the
750     index @uid_index to the prefs given in @new_prefs.
751     Return value: 0 on success. */
752     gpgme_error_t
753 twoaday 69 GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs)
754 werner 36 {
755     if (!this->key || !this->pass)
756     return gpg_error (GPG_ERR_INV_OBJ);
757     return 0;
758     }
759    
760    
761     /* Delete a signature from the user-ID with the index @uid_index.
762     The index of the signature is given in @sig_index.
763     Return value: 0 on success. */
764     gpgme_error_t
765 twoaday 69 GpgKeyEdit::delUseridSignature (int _uid_index, int _sig_index)
766 werner 36 {
767     if (!this->key)
768     return gpg_error (GPG_ERR_INV_OBJ);
769     type = GPG_EDITKEY_DELSIG;
770 twoaday 69 this->uid_index = _uid_index;
771     this->sig_index = _sig_index;
772 werner 36 return gpg_editkey (this->ctx, this->key, this);
773     }
774    
775     /* Set the preferred keyserver for the given key to @url.
776     Return value: 0 on success. */
777     gpgme_error_t
778 twoaday 69 GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url)
779 werner 36 {
780     if (!this->key || !this->pass)
781     return gpg_error (GPG_ERR_INV_OBJ);
782     if (!url)
783     return gpg_error (GPG_ERR_INV_ARG);
784     type = GPG_EDITKEY_KEYSERV;
785 twoaday 69 this->url = _url;
786     this->uid_index = _uid_index;
787 werner 36 return gpg_editkey (this->ctx, this->key, this);
788     }
789 twoaday 170
790    
791     /* Return the saved user-id index. */
792     int
793     GpgKeyEdit::getUseridIndex (void)
794     {
795     return uid_index;
796     }
797    
798    
799     /* Return the saved key index. */
800     int
801     GpgKeyEdit::getKeyIndex (void)
802     {
803     return key_index;
804     }
805    
806    
807     /* Return the saved sig index. */
808     int
809     GpgKeyEdit::getSigIndex (void)
810     {
811     return sig_index;
812     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26