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

Diff of /trunk/Src/wptGPG.cpp

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

revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC revision 197 by twoaday, Mon Apr 10 07:38:06 2006 UTC
# Line 200  get_gnupg_prog (void) Line 200  get_gnupg_prog (void)
200     Return value: the keyid of the secret key. */     Return value: the keyid of the secret key. */
201  static char *  static char *
202  default_key_from_cache (int *ret_no_useable)  default_key_from_cache (int *ret_no_useable)
203  {  {    
204        gpgme_key_t key, pk;
205        gpg_keycache_t sec, pub;
206      const char *s;      const char *s;
207      char *keyid = NULL;      char *keyid = NULL;
     gpgme_key_t key;  
     gpg_keycache_t sec = keycache_get_ctx (0);  
208    
209        sec = keycache_get_ctx (0);
210      if (!sec)      if (!sec)
211          BUG (0);          BUG (0);
212        pub = keycache_get_ctx (1);
213      gpg_keycache_rewind (sec);      gpg_keycache_rewind (sec);
214      while (!gpg_keycache_next_key (sec, 1, &key)) {      while (!gpg_keycache_next_key (sec, 1, &key)) {
215          if (key_is_useable (key)) {          if (key_is_useable (key) && !get_pubkey (key->subkeys->keyid, &pk)) {
216              s = key->subkeys->keyid;              s = key->subkeys->keyid;
217              if (s)                  if (s)    
218                  keyid = m_strdup (s+8);                  keyid = m_strdup (s+8);
219              break;              break;
220          }          }
221      }      }
222      if (!keyid)      if (!keyid)
223          *ret_no_useable = 1;          *ret_no_useable = 1;    
224      return keyid;      return keyid;
225  }  }
226    
# Line 257  get_gnupg_default_key (void) Line 259  get_gnupg_default_key (void)
259  {      {    
260      gpg_optfile_t opt = NULL;      gpg_optfile_t opt = NULL;
261      gpg_option_t e;      gpg_option_t e;
262      char * keyid = NULL, * optfile = NULL;      char *keyid = NULL, *optfile = NULL;
263      int no_usable=0, rc = 0;      int no_usable=0, rc = 0;
264    
265      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
# Line 268  get_gnupg_default_key (void) Line 270  get_gnupg_default_key (void)
270          free_if_alloc (optfile);          free_if_alloc (optfile);
271          return default_key_from_cache (&no_usable);          return default_key_from_cache (&no_usable);
272      }      }
273      e = find_option( opt, "default-key" );      e = find_option (opt, "default-key");
274      if ( e )      if (e)
275          keyid = m_strdup( e->val );          keyid = m_strdup (e->val);
276      if( !e ) {      if (!e) {
277          e = find_option( opt, "local-user" );          e = find_option (opt, "local-user");
278          if( e )          if (e)
279              keyid = m_strdup( e->val );              keyid = m_strdup (e->val);
280      }      }
281      if( !e ) {      if (!e) {
282          e = find_option( opt, "encrypt-to" );          e = find_option (opt, "encrypt-to");
283          if( e )          if (e)
284              keyid = m_strdup( e->val );              keyid = m_strdup (e->val);
285      }      }
286      free_if_alloc (optfile);      free_if_alloc (optfile);
287      release_gpg_options (opt);      release_gpg_options (opt);    
288    
289      if (!keyid)      if (!keyid)
290          keyid = default_key_from_cache (&no_usable);          keyid = default_key_from_cache (&no_usable);
291      return keyid;      return keyid;
292  } /* get_gnupg_default_key */  }
293    
294    
295  /* Check if GPG4WIN is available and if so, use the  /* Check if GPG4WIN is available and if so, use the
# Line 583  set_gnupg_default_key (const char *key) Line 585  set_gnupg_default_key (const char *key)
585          e->val = m_strdup (key);          e->val = m_strdup (key);
586          e->used = 1;          e->used = 1;
587      }      }
588      else      else if (key)
589          add_entry (opt, ENTRY_MULTI, "default-key", key);          add_entry (opt, ENTRY_MULTI, "default-key", key);
590      rc = commit_gpg_options (optfile, opt);      rc = commit_gpg_options (optfile, opt);
591    

Legend:
Removed from v.181  
changed lines
  Added in v.197

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26