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

Annotation of /trunk/Src/wptSymEnc.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 2670 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptSymEnc.cpp - Symmetric encryption support
2 twoaday 23 * Copyright (C) 2002, 2003, 2004, 2005 Timo Schulz
3 twoaday 2 *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     * General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include <windows.h>
22 twoaday 23 #include <io.h>
23 twoaday 2
24     #include "wptGPG.h"
25     #include "wptCommonCtl.h"
26     #include "wptContext.h"
27     #include "wptDlgs.h"
28     #include "wptNLS.h"
29     #include "wptUTF8.h"
30     #include "wptTypes.h"
31     #include "wptErrors.h"
32    
33 twoaday 23
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 twoaday 2 int
53 twoaday 23 gpg_encrypt_symmetric (void)
54 twoaday 2 {
55     gpgme_ctx_t ctx;
56 twoaday 23 gpgme_data_t plain=NULL;
57     gpgme_data_t ciph=NULL;
58 twoaday 2 gpgme_error_t rc;
59 twoaday 23 char *pass = NULL;
60 twoaday 2 int cancel = 0;
61    
62 twoaday 22 pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel);
63 twoaday 2 if (cancel)
64 twoaday 23 return 0;
65 twoaday 2 rc = gpgme_new (&ctx);
66     if (rc)
67 twoaday 23 goto leave;
68     rc = gpg_data_new_from_clipboard (&plain, 0);
69 twoaday 2 if (rc)
70 twoaday 23 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)
78 twoaday 2 msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR);
79 twoaday 23 else {
80 twoaday 2 show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished"));
81 twoaday 23 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 twoaday 2 gpgme_release (ctx);
91 twoaday 23 sfree_if_alloc (pass);
92 twoaday 2 return rc? WPTERR_GENERAL : 0;
93 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26