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

Diff of /trunk/Src/wptSymEnc.cpp

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

revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC
# Line 1  Line 1 
1  /* wptSymEnc.cpp - Symmetric encryption support  /* wptSymEnc.cpp - Symmetric encryption support
2   *      Copyright (C) 2002, 2003, 2004 Timo Schulz   *      Copyright (C) 2002, 2003, 2004, 2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 19  Line 19 
19   */   */
20    
21  #include <windows.h>  #include <windows.h>
22    #include <io.h>
23    
24  #include "wptGPG.h"  #include "wptGPG.h"
25  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
# Line 29  Line 30 
30  #include "wptTypes.h"  #include "wptTypes.h"
31  #include "wptErrors.h"  #include "wptErrors.h"
32    
33    
34    /* Simple passphrase callback. The hook pointer is the passphrase itself.
35       Return value: 0 on success. */
36    gpgme_error_t
37    sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf,
38                       int prev_was_bad, int fd)
39    {
40        const char *pass = (const char*)hook;
41    
42        if (!pass)
43            return gpg_error (GPG_ERR_INV_ARG);
44        write (fd, pass, strlen (pass));
45        write (fd, "\n", 1);
46        return 0;
47    }
48    
49    
50    /* Perform symmetric encryption on the current clipboard data.
51       Return 0 for success. */
52  int  int
53  gpgme_encrypt_symmetric (void)  gpg_encrypt_symmetric (void)
54  {  {
55      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
56        gpgme_data_t plain=NULL;
57        gpgme_data_t ciph=NULL;
58      gpgme_error_t rc;      gpgme_error_t rc;
59      char * pass = NULL;      char *pass = NULL;
60      int cancel = 0;      int cancel = 0;
61            
62      pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel);      pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel);
63      if (cancel)      if (cancel)
64          return WPTERR_GENERAL;          return 0;
65      rc = gpgme_new (&ctx);      rc = gpgme_new (&ctx);
66      if (rc)      if (rc)
67          BUG (0);          goto leave;
68      gpgme_set_passphrase (ctx, pass);      rc = gpg_data_new_from_clipboard (&plain, 0);
69      rc = gpgme_op_clip_symenc (ctx);      if (rc)
70      sfree_if_alloc (pass);          goto leave;
71        rc = gpgme_data_new (&ciph);
72        gpgme_set_armor (ctx, 1);
73    
74        gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass);
75    
76        rc = gpgme_op_encrypt (ctx, NULL, (gpgme_encrypt_flags_t)0, plain, ciph);    
77      if (rc)      if (rc)
78          msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR);          msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR);
79      else      else {
80          show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished"));          show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished"));
81            gpg_data_release_and_set_clipboard (ciph, 0);
82            ciph = NULL;
83        }
84    
85    leave:
86        if (plain)
87            gpgme_data_release (plain);
88        if (ciph)
89            gpgme_data_release (ciph);
90      gpgme_release (ctx);      gpgme_release (ctx);
91        sfree_if_alloc (pass);
92      return rc? WPTERR_GENERAL : 0;      return rc? WPTERR_GENERAL : 0;
 } /* gpgme_encrypt_symmetric */  
93    }

Legend:
Removed from v.22  
changed lines
  Added in v.23

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26