24 |
#endif |
#endif |
25 |
|
|
26 |
#include <windows.h> |
#include <windows.h> |
27 |
#include <windows.h> |
#include <time.h> |
28 |
|
|
29 |
#include "gpgme.h" |
#include "gpgme.h" |
30 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
324 |
|
|
325 |
|
|
326 |
/* Construct an object with the given key in @key. */ |
/* Construct an object with the given key in @key. */ |
327 |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t key) |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
328 |
{ |
{ |
329 |
this->key = key; |
this->key = _key; |
330 |
pass = NULL; |
pass = NULL; |
331 |
type = 0; |
type = 0; |
332 |
name = NULL; |
name = NULL; |
339 |
} |
} |
340 |
|
|
341 |
/* Construct an object and fetch the key with the keyid @keyid. */ |
/* Construct an object and fetch the key with the keyid @keyid. */ |
342 |
GpgKeyEdit::GpgKeyEdit (const char *keyid) |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
343 |
{ |
{ |
344 |
get_pubkey (keyid, &this->key); |
get_pubkey (_keyid, &this->key); |
345 |
pass = NULL; |
pass = NULL; |
346 |
type = 0; |
type = 0; |
347 |
name = NULL; |
name = NULL; |
396 |
|
|
397 |
/* Set the passphrase to @pass. */ |
/* Set the passphrase to @pass. */ |
398 |
void |
void |
399 |
GpgKeyEdit::setPassphrase (const char *pass) |
GpgKeyEdit::setPassphrase (const char *_pass) |
400 |
{ |
{ |
401 |
this->pass = pass; |
this->pass = _pass; |
402 |
} |
} |
403 |
|
|
404 |
/* Set the current key to @key. */ |
/* Set the current key to @key. */ |
405 |
void |
void |
406 |
GpgKeyEdit::setKey (gpgme_key_t key) |
GpgKeyEdit::setKey (gpgme_key_t _key) |
407 |
{ |
{ |
408 |
this->key = key; |
this->key = _key; |
409 |
} |
} |
410 |
|
|
411 |
/* Set the keyid of the destination key to @keyid. */ |
/* Set the keyid of the destination key to @keyid. */ |
412 |
void |
void |
413 |
GpgKeyEdit::setKeyID (const char *keyid) |
GpgKeyEdit::setKeyID (const char *_keyid) |
414 |
{ |
{ |
415 |
if (!keyid) |
if (!_keyid) |
416 |
return; |
return; |
417 |
get_pubkey (keyid, &this->key); |
get_pubkey (_keyid, &this->key); |
418 |
} |
} |
419 |
|
|
420 |
|
|
452 |
signing mode @mode and the signature class @sig_class. |
signing mode @mode and the signature class @sig_class. |
453 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
454 |
gpgme_error_t |
gpgme_error_t |
455 |
GpgKeyEdit::signKey (int mode, int sig_class, const char *exp_date) |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
456 |
{ |
{ |
457 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
458 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
459 |
|
|
460 |
type = mode; |
type = mode; |
461 |
this->exp_date = exp_date; |
this->exp_date = _exp_date; |
462 |
this->sig_class = sig_class; |
this->sig_class = _sig_class; |
463 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
464 |
} |
} |
465 |
|
|
466 |
|
|
467 |
/* Set the ownertrust of the key stored in the object |
/* Set the ownertrust of the key stored in the object |
468 |
to the trust value @trust. |
to the trust value @trust. |
469 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
482 |
name, @cmt as the comment (or NULL) and @email as the email. |
name, @cmt as the comment (or NULL) and @email as the email. |
483 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
484 |
gpgme_error_t |
gpgme_error_t |
485 |
GpgKeyEdit::addUserid (const char *name, const char *cmt, const char *email) |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
486 |
{ |
{ |
487 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
488 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
489 |
|
|
490 |
type = GPG_EDITKEY_ADDUID; |
type = GPG_EDITKEY_ADDUID; |
491 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
492 |
this->name = m_strdup (name); |
this->name = m_strdup (_name); |
493 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
494 |
this->cmt = NULL; |
this->cmt = NULL; |
495 |
if (cmt != NULL) |
if (cmt != NULL) |
496 |
this->cmt = m_strdup (cmt); |
this->cmt = m_strdup (_cmt); |
497 |
free_if_alloc (this->email); |
free_if_alloc (this->email); |
498 |
this->email = m_strdup (email); |
this->email = m_strdup (_email); |
499 |
if (!this->email || !this->name) |
if (!this->email || !this->name) |
500 |
BUG (NULL); |
BUG (NULL); |
501 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
504 |
/* Delete the user-ID with the index @uid_index of the given key. |
/* Delete the user-ID with the index @uid_index of the given key. |
505 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
506 |
gpgme_error_t |
gpgme_error_t |
507 |
GpgKeyEdit::delUserid (int uid_index) |
GpgKeyEdit::delUserid (int _uid_index) |
508 |
{ |
{ |
509 |
if (!this->key) |
if (!this->key) |
510 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
511 |
|
|
512 |
type = GPG_EDITKEY_DELUID; |
type = GPG_EDITKEY_DELUID; |
513 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
514 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
515 |
} |
} |
516 |
|
|
517 |
/* Delete the subkey with the index @key_index. |
/* Delete the subkey with the index @key_index. |
518 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
519 |
gpgme_error_t |
gpgme_error_t |
520 |
GpgKeyEdit::delKey (int key_index) |
GpgKeyEdit::delKey (int _key_index) |
521 |
{ |
{ |
522 |
if (!this->key) |
if (!this->key) |
523 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
524 |
|
|
525 |
type = GPG_EDITKEY_DELKEY; |
type = GPG_EDITKEY_DELKEY; |
526 |
this->key_index = key_index; |
this->key_index = _key_index; |
527 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
528 |
} |
} |
529 |
|
|
533 |
key expires in @valid days. |
key expires in @valid days. |
534 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
535 |
gpgme_error_t |
gpgme_error_t |
536 |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t pubkey_algo, unsigned int pubkey_size, |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
537 |
long valid) |
unsigned int _pubkey_size, long _valid) |
538 |
{ |
{ |
539 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
540 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
541 |
|
|
542 |
type = GPG_EDITKEY_ADDKEY; |
type = GPG_EDITKEY_ADDKEY; |
543 |
this->pubkey_algo = pubkey_algo; |
this->pubkey_algo = _pubkey_algo; |
544 |
this->pubkey_size = pubkey_size; |
this->pubkey_size = _pubkey_size; |
545 |
this->valid = valid; |
this->valid = _valid; |
546 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
547 |
} |
} |
548 |
|
|
550 |
If allow_empty != 0, it is allowed to provide an empty passphrase. |
If allow_empty != 0, it is allowed to provide an empty passphrase. |
551 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
552 |
gpgme_error_t |
gpgme_error_t |
553 |
GpgKeyEdit::changePassphrase (const char *new_pass, int allow_empty) |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
554 |
{ |
{ |
555 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
556 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
557 |
|
|
558 |
type = GPG_EDITKEY_PASSWD; |
type = GPG_EDITKEY_PASSWD; |
559 |
this->new_pass = new_pass; |
this->new_pass = _new_pass; |
560 |
this->flags = allow_empty? 1 : 0; |
this->flags = allow_empty? 1 : 0; |
561 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
562 |
} |
} |
565 |
the index @uid_index. |
the index @uid_index. |
566 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
567 |
gpgme_error_t |
gpgme_error_t |
568 |
GpgKeyEdit::setPrimaryUserid (int uid_index) |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
569 |
{ |
{ |
570 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
571 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
572 |
|
|
573 |
type = GPG_EDITKEY_PRIMARY; |
type = GPG_EDITKEY_PRIMARY; |
574 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
575 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
576 |
} |
} |
577 |
|
|
580 |
if @exp_days is true, exp_timestamp is already converted to days. |
if @exp_days is true, exp_timestamp is already converted to days. |
581 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
582 |
gpgme_error_t |
gpgme_error_t |
583 |
GpgKeyEdit::setKeyExpireDate (int key_index, long exp_timestamp, bool exp_days) |
GpgKeyEdit::setKeyExpireDate (int _key_index, |
584 |
|
long exp_timestamp, bool exp_days) |
585 |
{ |
{ |
586 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
587 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
595 |
} |
} |
596 |
else |
else |
597 |
valid = exp_timestamp; |
valid = exp_timestamp; |
598 |
this->key_index = key_index; |
this->key_index = _key_index; |
599 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
600 |
} |
} |
601 |
|
|
602 |
/* Revoke the userid given by the index @uid_index. |
/* Revoke the userid given by the index @uid_index. |
603 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
604 |
gpgme_error_t |
gpgme_error_t |
605 |
GpgKeyEdit::revokeUserid (int uid_index) |
GpgKeyEdit::revokeUserid (int _uid_index) |
606 |
{ |
{ |
607 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
608 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
609 |
|
|
610 |
type = GPG_EDITKEY_REVUID; |
type = GPG_EDITKEY_REVUID; |
611 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
612 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
613 |
} |
} |
614 |
|
|
617 |
and the signature index @sig_index. |
and the signature index @sig_index. |
618 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
619 |
gpgme_error_t |
gpgme_error_t |
620 |
GpgKeyEdit::revokeSignature (int uid_index, int sig_index) |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
621 |
{ |
{ |
622 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
623 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
624 |
|
|
625 |
type = GPG_EDITKEY_REVSIG; |
type = GPG_EDITKEY_REVSIG; |
626 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
627 |
this->sig_index = sig_index; |
this->sig_index = _sig_index; |
628 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
629 |
} |
} |
630 |
|
|
634 |
more details in @cmt. |
more details in @cmt. |
635 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
636 |
gpgme_error_t |
gpgme_error_t |
637 |
GpgKeyEdit::revokeSubkey (int key_index, int reason, const char *cmt) |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
638 |
{ |
{ |
639 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
640 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
641 |
|
|
642 |
type = GPG_EDITKEY_REVKEY; |
type = GPG_EDITKEY_REVKEY; |
643 |
this->key_index = key_index; |
this->key_index = _key_index; |
644 |
this->reason = reason; |
this->reason = _reason; |
645 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
646 |
this->cmt = NULL; |
this->cmt = NULL; |
647 |
if (cmt) |
if (_cmt) |
648 |
this->cmt = m_strdup (cmt); |
this->cmt = m_strdup (_cmt); |
649 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
650 |
} |
} |
651 |
|
|
705 |
index @uid_index to the prefs given in @new_prefs. |
index @uid_index to the prefs given in @new_prefs. |
706 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
707 |
gpgme_error_t |
gpgme_error_t |
708 |
GpgKeyEdit::setUseridPreferences (int uid_index, const char *new_prefs) |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs) |
709 |
{ |
{ |
710 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
711 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
717 |
The index of the signature is given in @sig_index. |
The index of the signature is given in @sig_index. |
718 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
719 |
gpgme_error_t |
gpgme_error_t |
720 |
GpgKeyEdit::delUseridSignature (int uid_index, int sig_index) |
GpgKeyEdit::delUseridSignature (int _uid_index, int _sig_index) |
721 |
{ |
{ |
722 |
if (!this->key) |
if (!this->key) |
723 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
724 |
type = GPG_EDITKEY_DELSIG; |
type = GPG_EDITKEY_DELSIG; |
725 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
726 |
this->sig_index = sig_index; |
this->sig_index = _sig_index; |
727 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
728 |
} |
} |
729 |
|
|
730 |
/* Set the preferred keyserver for the given key to @url. |
/* Set the preferred keyserver for the given key to @url. |
731 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
732 |
gpgme_error_t |
gpgme_error_t |
733 |
GpgKeyEdit::setPreferredKeyserver (int uid_index, const char *url) |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
734 |
{ |
{ |
735 |
if (!this->key || !this->pass) |
if (!this->key || !this->pass) |
736 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
737 |
if (!url) |
if (!url) |
738 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
739 |
type = GPG_EDITKEY_KEYSERV; |
type = GPG_EDITKEY_KEYSERV; |
740 |
this->url = url; |
this->url = _url; |
741 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
742 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
743 |
} |
} |