/[gpgoe]/trunk/src/OECrypto.c
ViewVC logotype

Diff of /trunk/src/OECrypto.c

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

revision 12 by twoaday, Fri Apr 7 10:46:41 2006 UTC revision 16 by twoaday, Tue Apr 11 06:56:23 2006 UTC
# Line 242  create_in_data (gpgme_data_t *in, const Line 242  create_in_data (gpgme_data_t *in, const
242    
243      enc_buf = encode? native_to_utf8 (buf) : xstrdup (buf);      enc_buf = encode? native_to_utf8 (buf) : xstrdup (buf);
244      err = gpgme_data_new_from_mem (in, enc_buf, strlen (enc_buf), 1);      err = gpgme_data_new_from_mem (in, enc_buf, strlen (enc_buf), 1);
245      free (enc_buf);      free_if_alloc (enc_buf);
246      return err;      return err;
247  }  }
248    
# Line 265  map_gpgme_data (gpgme_data_t out, char * Line 265  map_gpgme_data (gpgme_data_t out, char *
265  /* Try to extract the needed key information and retrieve  /* Try to extract the needed key information and retrieve
266     the keys if possible. */     the keys if possible. */
267  static gpgme_error_t  static gpgme_error_t
268  get_keys (plugin_ctx_t ctx, recip_list_t *r_list,  get_keys (plugin_ctx_t ctx, recip_list_t *r_list, gpgme_key_t **r_keys)
           gpgme_key_t **r_keys, int *r_n)  
269  {  {
270      gpgme_key_t *keys;      gpgme_key_t *keys;
271      recip_list_t addrs = NULL, n;      recip_list_t addrs = NULL, n;
# Line 298  get_keys (plugin_ctx_t ctx, recip_list_t Line 297  get_keys (plugin_ctx_t ctx, recip_list_t
297      }      }
298      *r_list = addrs;      *r_list = addrs;
299      *r_keys = keys;      *r_keys = keys;
     *r_n = nkeys;  
300      return 0;      return 0;
301  }  }
302    
# Line 314  encrypt_msg (plugin_ctx_t ctx, char **r_ Line 312  encrypt_msg (plugin_ctx_t ctx, char **r_
312      gpgme_ctx_t gctx = NULL;      gpgme_ctx_t gctx = NULL;
313      gpgme_data_t in = NULL, out = NULL;      gpgme_data_t in = NULL, out = NULL;
314      recip_list_t list = NULL;      recip_list_t list = NULL;
     int nkeys=0;  
315      char *msg = *r_msg;      char *msg = *r_msg;
316    
317      assert (ctx);      assert (ctx);
318    
319      err = get_keys (ctx, &list, &keys, &nkeys);      err = get_keys (ctx, &list, &keys);
320      if (err)      if (err)
321          return err;          return err;
322    
# Line 338  encrypt_msg (plugin_ctx_t ctx, char **r_ Line 335  encrypt_msg (plugin_ctx_t ctx, char **r_
335      gpgme_release (gctx);      gpgme_release (gctx);
336      gpgme_data_release (in);      gpgme_data_release (in);
337      release_recipient (list);      release_recipient (list);
338      free (keys);      free_if_alloc (keys);
339    
340      if (err)      if (err)
341          gpgme_data_release (out);          gpgme_data_release (out);
# Line 392  sign_encrypt_msg (plugin_ctx_t ctx, char Line 389  sign_encrypt_msg (plugin_ctx_t ctx, char
389      gpgme_key_t *keys;      gpgme_key_t *keys;
390      pass_cb_t cb_val;      pass_cb_t cb_val;
391      recip_list_t list = NULL;      recip_list_t list = NULL;
     int ec, nkeys = 0;  
392    
393      ec = get_keys (ctx, &list, &keys, &nkeys);      err = get_keys (ctx, &list, &keys);
394      if (ec)      if (err)
395          return ec;          return err;
396    
397      cb_val = new_pass_cb (ctx->main_wnd);      cb_val = new_pass_cb (ctx->main_wnd);
398    
# Line 416  sign_encrypt_msg (plugin_ctx_t ctx, char Line 412  sign_encrypt_msg (plugin_ctx_t ctx, char
412      gpgme_release (gctx);      gpgme_release (gctx);
413      gpgme_data_release (in);      gpgme_data_release (in);
414      release_recipient (list);      release_recipient (list);
415      free (keys);      free_if_alloc (keys);
416      free_pass_cb (cb_val);      free_pass_cb (cb_val);
417    
418      if (err)      if (err)
# Line 499  store_decrypt_info (char *buf, size_t bu Line 495  store_decrypt_info (char *buf, size_t bu
495  }  }
496    
497    
498    /* Decrypt the message given in @r_msg.
499       The old message will be freed and replaced with the plaintext. */
500    gpgme_error_t
501    oe_decrypt_msg (HWND main_wnd, char **r_msg)
502    {
503        gpgme_ctx_t gctx = NULL;
504        gpgme_data_t in = NULL, out = NULL;
505        gpgme_error_t err;
506        pass_cb_t cb_val;
507        char *msg = *r_msg;
508    
509        cb_val = new_pass_cb (main_wnd);
510        err = gpgme_new (&gctx);
511        if (!err)
512            err = gpgme_data_new_from_mem (&in, msg, strlen (msg), 1);
513        if (!err)
514            err = gpgme_data_new (&out);
515        if (!err) {
516            gpgme_set_passphrase_cb (gctx, passphrase_cb, cb_val);
517            err = gpgme_op_decrypt (gctx, in, out);
518        }
519    
520        gpgme_release (gctx);
521        gpgme_data_release (in);
522        free_pass_cb (cb_val);
523        
524        if (err)
525            gpgme_data_release (out);
526        else
527            map_gpgme_data (out, r_msg);
528    
529        return err;
530    }
531    
532    
533  /* Decrypt the message @r_msg. If the type @type is actually a signature,  /* Decrypt the message @r_msg. If the type @type is actually a signature,
534     the verify function is called instead of decryption. */     the verify function is called instead of decryption. */
535  static gpgme_error_t  static gpgme_error_t
# Line 649  oe_handle_mail (plugin_ctx_t ctx) Line 680  oe_handle_mail (plugin_ctx_t ctx)
680          if (!rc && (msg_type & PGP_MESSAGE) && msg && strlen (msg) > 0) {          if (!rc && (msg_type & PGP_MESSAGE) && msg && strlen (msg) > 0) {
681              struct viewer_ctx_s viewer;              struct viewer_ctx_s viewer;
682              viewer.msg = msg;              viewer.msg = msg;
683                viewer.main_wnd = ctx->main_wnd;
684              DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_VIEWER, ctx->main_wnd,              DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_VIEWER, ctx->main_wnd,
685                              viewer_dlg_proc, (LPARAM)&viewer);                              viewer_dlg_proc, (LPARAM)&viewer);
686          }          }

Legend:
Removed from v.12  
changed lines
  Added in v.16

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26