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

Annotation of /trunk/Src/wptGPGMEWrapper.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (hide annotations)
Fri Jul 21 08:19:24 2006 UTC (18 years, 7 months ago) by twoaday
File size: 3145 byte(s)


1 twoaday 133 /* wptGPGMEWrapper.cpp - Object oriented wrapper for GPGME
2     * Copyright (C) 2006 Timo Schulz
3     *
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     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <stdio.h>
27     #include <string.h>
28    
29     #include "gpgme.h"
30     #include "wptGPG.h"
31     #include "wptGPGME.h"
32 twoaday 195 #include "wptW32API.h"
33 twoaday 133
34    
35     /* Constructor to build gpgme context. */
36     GPGME::GPGME ()
37     {
38     gpgme_new (&ctx);
39     }
40    
41     /* Destructor to release gpgme context. */
42     GPGME::~GPGME ()
43     {
44     if (ctx != NULL)
45     gpgme_release (ctx);
46     }
47    
48 twoaday 167 /* Enable or disable the feature to add the
49     WinPT version to armored output. */
50 twoaday 133 void
51     GPGME::setChangeVersion (bool val)
52     {
53     chg_ver = val;
54     }
55    
56     /* Enable or disable armor. */
57     void
58     GPGME::setArmor (bool val)
59     {
60     gpgme_set_armor (ctx, val? 1 : 0);
61     }
62    
63     bool
64     GPGME::getArmor (void)
65     {
66     return gpgme_get_armor (ctx)? true: false;
67     }
68    
69     /* Export key pattern @patt to file @outfile.
70     Return value: 0 on success. */
71     gpgme_error_t
72     GPGME::exportToFile (const char *patt, const char *outfile)
73     {
74     gpgme_data_t dat;
75     gpgme_error_t err;
76    
77     err = gpgme_data_new (&dat);
78     if (err)
79     return err;
80 twoaday 167 op_begin ();
81 twoaday 133 err = gpgme_op_export (ctx, patt, 0, dat);
82 twoaday 167 op_end ();
83 twoaday 133 if (err) {
84     gpgme_data_release (dat);
85     return err;
86     }
87     err = gpg_data_release_and_set_file (dat, outfile);
88 twoaday 247 if (err)
89     gpgme_data_release (dat);
90 twoaday 133 return err;
91     }
92    
93    
94     /* Export key pattern @patt to the clipboard.
95     Return value: 0 on success. */
96     gpgme_error_t
97     GPGME::exportToClipboard (const char *patt)
98     {
99     gpgme_data_t dat;
100     gpgme_error_t err;
101    
102     err = gpgme_data_new (&dat);
103     if (err)
104     return err;
105 twoaday 167 op_begin ();
106 twoaday 133 err = gpgme_op_export (ctx, patt, 0, dat);
107 twoaday 167 op_end ();
108 twoaday 133 if (err) {
109     gpgme_data_release (dat);
110     return err;
111     }
112     gpg_data_release_and_set_clipboard (dat, chg_ver? 1 : 0);
113     return err;
114     }
115    
116    
117     /* Export key pattern @patt to the buffer @outdata.
118     Return value: 0 on success. */
119     gpgme_error_t
120     GPGME::exportToBuffer (const char *patt, char **outdata)
121     {
122     gpgme_error_t err;
123     gpgme_data_t dat;
124     size_t n;
125     char *p;
126    
127     err = gpgme_data_new (&dat);
128     if (err)
129     return err;
130 twoaday 167 op_begin ();
131 twoaday 133 err = gpgme_op_export (ctx, patt, 0, dat);
132 twoaday 167 op_end ();
133 twoaday 133 if (err) {
134     gpgme_data_release (dat);
135     return err;
136     }
137     p = gpgme_data_release_and_get_mem (dat, &n);
138    
139     *outdata = new char[n+1];
140     memcpy (*outdata, p, n);
141     (*outdata)[n] = 0;
142     gpgme_free (p);
143    
144     return err;
145     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26