1 |
/* wptKeyCache.h |
2 |
* Copyright (C) 2005, 2006 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (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 |
14 |
* GNU 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 |
#ifndef WPT_KEYCACHE_H |
21 |
#define WPT_KEYCACHE_H |
22 |
|
23 |
#include <gpgme.h> |
24 |
|
25 |
struct gpg_desig_rev_s; |
26 |
typedef struct gpg_desig_rev_s *gpg_desig_rev_t; |
27 |
|
28 |
/* key cache specific update flags. */ |
29 |
enum keycache_flag_t { |
30 |
KC_FLAG_ADD = 1, |
31 |
KC_FLAG_UPD = 2 |
32 |
}; |
33 |
|
34 |
/* key specifc attributes. */ |
35 |
enum keycache_attr_t { |
36 |
KC_ATTR_PREFSYM = 11, |
37 |
KC_ATTR_PREFKSERV = 24 |
38 |
}; |
39 |
|
40 |
|
41 |
/* contains the UTF8 decoded user id. */ |
42 |
struct native_uid_s { |
43 |
struct native_uid_s *next; |
44 |
unsigned int malloced:1; /* 1 if the follow parts are actually |
45 |
malloced or just referenced pointer. */ |
46 |
unsigned int revoked : 1; |
47 |
gpgme_validity_t validity; |
48 |
|
49 |
gpgme_key_sig_t signatures; |
50 |
|
51 |
char *uid; |
52 |
char *name; |
53 |
char *comment; |
54 |
char *email; |
55 |
}; |
56 |
|
57 |
|
58 |
struct keycache_s { |
59 |
struct keycache_s *next; |
60 |
int flags; |
61 |
gpgme_key_t key; /* actual key context. */ |
62 |
unsigned int default_key:1; /* default signing key. */ |
63 |
struct keycache_s *pubpart; /* corresponding public key. */ |
64 |
struct { |
65 |
unsigned int is_protected:1; /* key is protected. */ |
66 |
unsigned int divert_to_card:1; /* secret key on card. */ |
67 |
unsigned int has_desig_rev:1; /* has desig. revokers. */ |
68 |
} gloflags; |
69 |
struct { |
70 |
unsigned int flags; |
71 |
unsigned char *d; /* attribute (JPG) data. */ |
72 |
unsigned int len; /* attribute data length. */ |
73 |
gpgme_validity_t validity; /* attribute id validity. */ |
74 |
} attrib; |
75 |
unsigned char *sym_prefs;/* symmetric cipher preferences. */ |
76 |
char *pref_keyserver; /* if != NULL preferred keyserver. */ |
77 |
char *card_type; /* if != NULL key stored on smart card. */ |
78 |
struct native_uid_s *uids; |
79 |
gpg_desig_rev_t rev; /* if != NULL list of desig revokers. */ |
80 |
}; |
81 |
|
82 |
struct gpg_keycache_s { |
83 |
struct keycache_s *item; |
84 |
struct keycache_s *tmp; |
85 |
int secret; |
86 |
int pos; |
87 |
void (*cb) (void*, const char*, int, int, int); |
88 |
void *cb_value; |
89 |
int cb_value2; |
90 |
}; |
91 |
typedef struct gpg_keycache_s *gpg_keycache_t; |
92 |
|
93 |
gpgme_error_t gpg_keycache_new (gpg_keycache_t * r_ctx); |
94 |
void gpg_keycache_release (gpg_keycache_t ctx); |
95 |
void gpg_keycache_set_cb (gpg_keycache_t ctx, |
96 |
void (*cb)(void *, const char *, int, int, int), |
97 |
void* cb_value1, int cb_value2); |
98 |
void gpg_keycache_rewind (gpg_keycache_t ctx); |
99 |
int gpg_keycache_get_size (gpg_keycache_t ctx); |
100 |
gpgme_error_t gpg_keycache_add_key (gpg_keycache_t ctx, gpgme_key_t key, |
101 |
void **opaque); |
102 |
gpgme_error_t gpg_keycache_update_key (gpg_keycache_t ctx, int is_sec, |
103 |
void *opaque, const char *keyid); |
104 |
gpgme_error_t gpg_keycache_find_key (gpg_keycache_t ctx, const char *pattern, |
105 |
int flags, gpgme_key_t * r_key); |
106 |
gpgme_error_t gpg_keycache_find_key2 (gpg_keycache_t ctx, |
107 |
const char *pattern, int flags, |
108 |
gpgme_key_t *r_key, |
109 |
struct keycache_s **r_item); |
110 |
gpgme_error_t gpg_keycache_delete_key (gpg_keycache_t ctx, |
111 |
const char * pattern); |
112 |
gpgme_error_t gpg_keycache_init (gpg_keycache_t ctx, const char * pattern, |
113 |
int secret); |
114 |
gpgme_error_t gpg_keycache_next_key (gpg_keycache_t ctx, int flags, |
115 |
gpgme_key_t * r_key); |
116 |
gpgme_error_t gpg_keycache_next_key2 (gpg_keycache_t ctx, int flags, |
117 |
struct keycache_s **c, gpgme_key_t *r_key); |
118 |
gpgme_error_t gpg_keycache_prepare (gpg_keycache_t ctx, |
119 |
const char *pubring, |
120 |
const char *secring); |
121 |
gpgme_error_t gpg_keycache_prepare_single (gpg_keycache_t ctx, |
122 |
const char *keyid, |
123 |
const char *pubr, |
124 |
const char *secr); |
125 |
gpgme_error_t gpg_keycache_sync (gpg_keycache_t pub, gpg_keycache_t sec); |
126 |
gpgme_error_t gpg_keycache_next_updated_key (gpg_keycache_t ctx, |
127 |
struct keycache_s **r_obj, |
128 |
int *r_status); |
129 |
gpgme_error_t gpg_keycache_set_default_key (gpg_keycache_t ctx, |
130 |
const char *pattern); |
131 |
gpgme_error_t gpg_keycache_get_default_key (gpg_keycache_t ctx, |
132 |
gpgme_key_t *r_key); |
133 |
gpgme_error_t gpg_keycache_update_attr (struct keycache_s *item, |
134 |
int attr, int force); |
135 |
|
136 |
#endif /*WPT_KEYCACHE_H*/ |