1 |
twoaday |
2 |
#ifdef WITH_CPP_WRAPPER |
2 |
|
|
|
3 |
|
|
#include <stdio.h> |
4 |
|
|
#include <stdlib.h> |
5 |
|
|
#include <string.h> |
6 |
|
|
#include <assert.h> |
7 |
|
|
|
8 |
|
|
#include "gpgme.h" |
9 |
|
|
#include "gpgme-c++.h" |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
gpgme_key::gpgme_key (gpgme_key_t key) |
13 |
|
|
{ |
14 |
|
|
if (!key) |
15 |
|
|
abort (); |
16 |
|
|
key = key; |
17 |
|
|
ctx = NULL; |
18 |
|
|
edit_ctx = NULL; |
19 |
|
|
passphrase = NULL; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
gpgme_key::~gpgme_key (void) |
23 |
|
|
{ |
24 |
|
|
if (key) |
25 |
|
|
gpgme_key_release (key); |
26 |
|
|
if (ctx) |
27 |
|
|
gpgme_release (ctx); |
28 |
|
|
if (edit_ctx) |
29 |
|
|
gpgme_editkey_release (edit_ctx); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
int |
34 |
|
|
gpgme_key::set_passwd (const char * passwd) |
35 |
|
|
{ |
36 |
|
|
if (!passwd) |
37 |
|
|
return GPG_ERR_INV_VALUE; |
38 |
|
|
|
39 |
|
|
if (passphrase) { |
40 |
|
|
delete [] passphrase; |
41 |
|
|
passphrase = NULL; |
42 |
|
|
} |
43 |
|
|
passphrase = new char[strlen (passwd)+1]; |
44 |
|
|
if (!passphrase) |
45 |
|
|
abort (); |
46 |
|
|
strcpy (passphrase, passwd); |
47 |
|
|
return GPG_ERR_SUCCESS; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
unsigned |
51 |
|
|
gpgme_key::ulong_attr (int what, int idx) |
52 |
|
|
{ |
53 |
|
|
assert (key); |
54 |
|
|
return gpgme_key_get_ulong_attr (key, (gpgme_attr_t)what, NULL, idx); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
const char * |
59 |
|
|
gpgme_key::string_attr (int what, int idx) |
60 |
|
|
{ |
61 |
|
|
assert (key); |
62 |
|
|
return gpgme_key_get_string_attr (key, (gpgme_attr_t)what, NULL, idx); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
const void * |
67 |
|
|
gpgme_key::attrib_attr (int * nbytes) |
68 |
|
|
{ |
69 |
|
|
assert (key); |
70 |
|
|
return gpgme_key_get_string_attr (key, GPGME_ATTR_PHOTO, (void **)&nbytes, 0); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
|
74 |
|
|
int |
75 |
|
|
gpgme_key::sign (int sigclass, int local) |
76 |
|
|
{ |
77 |
|
|
gpgme_error_t rc; |
78 |
|
|
|
79 |
|
|
if (!passphrase) |
80 |
|
|
return GPG_ERR_PWD_NOT_SET; |
81 |
|
|
return 0; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
#endif /* WITH_CPP_WRAPPER */ |