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

Annotation of /trunk/Src/wptSymEnc.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 2934 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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    
23     #include "wptGPG.h"
24     #include "wptCommonCtl.h"
25     #include "wptContext.h"
26     #include "wptDlgs.h"
27     #include "wptNLS.h"
28     #include "wptUTF8.h"
29     #include "wptTypes.h"
30     #include "wptErrors.h"
31    
32 twoaday 23
33     /* Simple passphrase callback. The hook pointer is the passphrase itself.
34     Return value: 0 on success. */
35     gpgme_error_t
36     sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf,
37     int prev_was_bad, int fd)
38     {
39     const char *pass = (const char*)hook;
40 twoaday 24 HANDLE hd = (HANDLE)fd;
41     DWORD n;
42 twoaday 23
43     if (!pass)
44     return gpg_error (GPG_ERR_INV_ARG);
45 twoaday 24
46 twoaday 25 /* XXX: check for passphrase.enter. */
47 twoaday 24 if (!WriteFile (hd, pass, strlen (pass), &n, NULL))
48     log_debug ("sym_passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
49     if (!WriteFile (hd, "\n", 1, &n, NULL))
50     log_debug ("sym_passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
51    
52 twoaday 23 return 0;
53     }
54    
55    
56     /* Perform symmetric encryption on the current clipboard data.
57     Return 0 for success. */
58 twoaday 2 int
59 twoaday 23 gpg_encrypt_symmetric (void)
60 twoaday 2 {
61     gpgme_ctx_t ctx;
62 twoaday 23 gpgme_data_t plain=NULL;
63     gpgme_data_t ciph=NULL;
64 twoaday 2 gpgme_error_t rc;
65 twoaday 23 char *pass = NULL;
66 twoaday 2 int cancel = 0;
67    
68 twoaday 22 pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel);
69 twoaday 2 if (cancel)
70 twoaday 23 return 0;
71 twoaday 2 rc = gpgme_new (&ctx);
72     if (rc)
73 twoaday 23 goto leave;
74     rc = gpg_data_new_from_clipboard (&plain, 0);
75 twoaday 2 if (rc)
76 twoaday 23 goto leave;
77     rc = gpgme_data_new (&ciph);
78     gpgme_set_armor (ctx, 1);
79    
80     gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass);
81    
82     rc = gpgme_op_encrypt (ctx, NULL, (gpgme_encrypt_flags_t)0, plain, ciph);
83     if (rc)
84 twoaday 2 msg_box (NULL, gpgme_strerror (rc), _("Symmetric Encryption"), MB_ERR);
85 twoaday 23 else {
86 twoaday 2 show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished"));
87 twoaday 24 gpg_data_release_and_set_clipboard (ciph, 1);
88 twoaday 23 ciph = NULL;
89     }
90    
91     leave:
92     if (plain)
93     gpgme_data_release (plain);
94     if (ciph)
95     gpgme_data_release (ciph);
96 twoaday 2 gpgme_release (ctx);
97 twoaday 23 sfree_if_alloc (pass);
98 twoaday 2 return rc? WPTERR_GENERAL : 0;
99 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26