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

Diff of /trunk/Src/wptKeyManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 128 by twoaday, Mon Dec 19 13:05:59 2005 UTC revision 129 by twoaday, Fri Dec 30 13:56:10 2005 UTC
# Line 47  Line 47 
47  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
48  #include "wptImport.h"  #include "wptImport.h"
49  #include "wptCrypto.h"  #include "wptCrypto.h"
50    #include "wptUTF8.h"
51    
52    
53  /* Return a user friendly key representation in @buf of  /* Return a user friendly key representation in @buf of
# Line 55  static void Line 56  static void
56  key_get_clip_info (const char *keyid, char *buf, size_t buflen)  key_get_clip_info (const char *keyid, char *buf, size_t buflen)
57  {  {
58      gpgme_key_t pk;      gpgme_key_t pk;
59        char *uid;
60    
61      if (get_pubkey (keyid, &pk))      if (get_pubkey (keyid, &pk))
62          BUG (NULL);          BUG (NULL);
63        uid = utf8_to_wincp2 (pk->uids->uid);
64      _snprintf (buf, buflen-1,      _snprintf (buf, buflen-1,
65                 "pub %04d%s/%s %s %s\r\n"                 "pub %04d%s/%s %s %s\r\n"
66                 "    Primary key fingerprint: %s\r\n",                 "    Primary key fingerprint: %s\r\n",
# Line 65  key_get_clip_info (const char *keyid, ch Line 68  key_get_clip_info (const char *keyid, ch
68                 get_key_pubalgo2 (pk->subkeys->pubkey_algo),                 get_key_pubalgo2 (pk->subkeys->pubkey_algo),
69                 pk->subkeys->keyid+8,                 pk->subkeys->keyid+8,
70                 get_key_created (pk->subkeys->timestamp),                 get_key_created (pk->subkeys->timestamp),
71                 pk->uids->uid,                 uid,
72                 get_key_fpr (pk));                 get_key_fpr (pk));
73        safe_free (uid);
74  }  }
75    
76    
# Line 75  static char* Line 79  static char*
79  key_get_info (gpgme_key_t pk, int is_sec)  key_get_info (gpgme_key_t pk, int is_sec)
80  {  {
81      const char *fmt = "%s %04d%s/0x%s %s\n  \"%s\"";      const char *fmt = "%s %04d%s/0x%s %s\n  \"%s\"";
82      char *p;      char *p, *uid;
83      int n;      int n;
84    
85      n = strlen (fmt) + 8 + 2 + 16 + 12 + strlen (pk->uids->uid) + 32;      n = strlen (fmt) + 8 + 2 + 16 + 12 + strlen (pk->uids->uid) + 32;
86      p = new char[n+1];      p = new char[n+1];
87      if (!p)      if (!p)
88          BUG (NULL);          BUG (NULL);
89        uid = utf8_to_wincp2 (pk->uids->uid);
90      _snprintf (p, n, fmt, is_sec? "sec" : "pub",      _snprintf (p, n, fmt, is_sec? "sec" : "pub",
91                 pk->subkeys->length,                 pk->subkeys->length,
92                 get_key_pubalgo2 (pk->subkeys->pubkey_algo),                 get_key_pubalgo2 (pk->subkeys->pubkey_algo),
93                 pk->subkeys->keyid+8, get_key_created (pk->subkeys->timestamp),                 pk->subkeys->keyid+8, get_key_created (pk->subkeys->timestamp),
94                 pk->uids->uid);                 uid);
95        safe_free (uid);
96      return p;      return p;
97  }  }
98    
# Line 356  km_privkey_export (HWND dlg, listview_ct Line 362  km_privkey_export (HWND dlg, listview_ct
362  }  }
363    
364    
365    /* Export the selected recipients from @lv into the file @fname. */
366  int  int
367  km_file_export (HWND dlg, listview_ctrl_t lv, const char * fname)  km_file_export (HWND dlg, listview_ctrl_t lv, const char *fname)
368  {  {
369      gpgme_key_t *rset;      gpgme_key_t *rset;
370      gpgme_data_t keydata;            gpgme_data_t keydata;      
# Line 734  km_send_to_mail_recipient (listview_ctrl Line 741  km_send_to_mail_recipient (listview_ctrl
741      gpgme_error_t rc;      gpgme_error_t rc;
742      char tmp[128];      char tmp[128];
743      char *fname;      char *fname;
744        char *name;
745      int pos;      int pos;
746    
747      if (listview_count_items (lv, 1) > 1) {      if (listview_count_items (lv, 1) > 1) {
# Line 753  km_send_to_mail_recipient (listview_ctrl Line 761  km_send_to_mail_recipient (listview_ctrl
761      GetTempPath (sizeof (tmp)-1, tmp);      GetTempPath (sizeof (tmp)-1, tmp);
762      if (tmp[strlen (tmp)-1] == '\\')      if (tmp[strlen (tmp)-1] == '\\')
763          tmp[strlen (tmp)-1] = 0;          tmp[strlen (tmp)-1] = 0;
764      fname = make_filename (tmp, key->uids->name, "asc");      name = utf8_to_wincp2 (key->uids->name);
765        fname = make_filename (tmp, name, "asc");
766      for (pos=0; pos < (int)strlen (fname); pos++) {      for (pos=0; pos < (int)strlen (fname); pos++) {
767          if (fname[pos] == ' ')          if (fname[pos] == ' ')
768              fname[pos] = '_';              fname[pos] = '_';
# Line 775  km_send_to_mail_recipient (listview_ctrl Line 784  km_send_to_mail_recipient (listview_ctrl
784    
785      gpg_data_release_and_set_file (out, fname);      gpg_data_release_and_set_file (out, fname);
786      gpgme_release (ctx);      gpgme_release (ctx);
787        safe_free (name);
788      free_if_alloc (fname);      free_if_alloc (fname);
789      return rc;      return rc;
790  }  }
# Line 834  km_set_clip_info (const char *uid) Line 844  km_set_clip_info (const char *uid)
844  {      {    
845      char buf[256];      char buf[256];
846            
847      key_get_clip_info (uid, buf, 255);          key_get_clip_info (uid, buf, sizeof (buf)-1);
848      set_clip_text (NULL, buf, strlen (buf));      set_clip_text (NULL, buf, strlen (buf));
849  }  }
850    
# Line 857  km_key_is_v3 (listview_ctrl_t lv, int po Line 867  km_key_is_v3 (listview_ctrl_t lv, int po
867  }  }
868    
869    
 /* Update the default key entry in the status bar for dialog @dlg. */  
 void  
 km_update_default_key_str (HWND dlg)  
 {  
     char *keyid, defkeyinf[512];  
     const char *fmt;  
       
     /* XXX: also show the name? */  
     keyid = get_gnupg_default_key ();  
     if (!keyid)  
         return;  
     if( (keyid[0] >= 'A' && keyid[0] <= 'Z') || (keyid[0] >= 'a' && keyid[0] <= 'z')  
         || (keyid[0] == '0' && keyid[1] == 'x') )  
         fmt = _("Default Key: %s");  
     else  
         fmt = _("Default Key: 0x%s");  
     _snprintf (defkeyinf, sizeof defkeyinf - 1, fmt, keyid);  
     SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf);  
     free_if_alloc (keyid);  
 }  
   
   
 /* Count all keys and show from @lv results in the status bar @sb. */  
 void  
 km_update_status_bar (HWND sb, listview_ctrl_t lv)  
 {  
     char txt_sec[128], txt_pub[128];  
     int nkeys = 0, nsec = 0;  
     int i;  
   
     nkeys = listview_count_items (lv, 0);  
     for (i = 0; i < nkeys; i++) {  
         if (km_check_for_seckey (lv, i, NULL))  
             nsec++;  
     }  
     _snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec);  
     _snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys);  
     SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec);  
     SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub);  
 }  
   
   
870  /* Set trust of selected key in @lv (at @pos) to ultimate. */  /* Set trust of selected key in @lv (at @pos) to ultimate. */
871  int  int
872  km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos)  km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos)
# Line 951  km_find_key (HWND dlg, listview_ctrl_t l Line 919  km_find_key (HWND dlg, listview_ctrl_t l
919      }      }
920      free_if_alloc (name);      free_if_alloc (name);
921  }  }
922    
923    
924    /* Return a user-friendly name for a key derrived from
925       name. If @is_secret is 1, a secret key name will be generated. */
926    char*
927    km_gen_export_filename (const char *keyid, int is_secret)
928    {
929        gpgme_key_t key;
930        char *p, *uid;
931    
932        if (get_pubkey (keyid, &key))
933            return m_strdup (keyid);
934        uid = utf8_to_wincp2 (key->uids->name);
935        if (!uid)
936            return m_strdup (keyid);
937        p = new char[strlen (uid) + 8 + 16];
938        if (!p)
939            BUG (0);
940        sprintf (p, "%s%s.asc", uid, is_secret? "_sec" : "");
941        for (size_t i=0; i < strlen (p); i++) {
942            if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')
943                p[i] = '_';
944        }
945        safe_free (uid);
946        return p;
947    }

Legend:
Removed from v.128  
changed lines
  Added in v.129

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26