Avoid catch-22 with README.main not being distributed but having the
[gnupg.git] / scd / app-common.h
blob4b2e13e3acd5a5cc6c6cdddba7c66ea4b63ee239
1 /* app-common.h - Common declarations for all card applications
2 * Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG 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 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * $Id$
22 #ifndef GNUPG_SCD_APP_COMMON_H
23 #define GNUPG_SCD_APP_COMMON_H
25 #if GNUPG_MAJOR_VERSION == 1
26 # ifdef ENABLE_AGENT_SUPPORT
27 # include "assuan.h"
28 # endif
29 #else
30 # include <ksba.h>
31 #endif
34 #define APP_CHANGE_FLAG_RESET 1
35 #define APP_CHANGE_FLAG_NULLPIN 2
38 struct app_local_s; /* Defined by all app-*.c. */
40 struct app_ctx_s {
41 /* Number of connections currently using this application context.
42 If this is not 0 the application has been initialized and the
43 function pointers may be used. Note that for unsupported
44 operations the particular function pointer is set to NULL */
45 unsigned int ref_count;
47 /* Flag indicating that a reset has been done for that application
48 and that this context is merely lingering and just should not be
49 reused. */
50 int no_reuse;
52 /* Used reader slot. */
53 int slot;
55 /* If this is used by GnuPG 1.4 we need to know the assuan context
56 in case we need to divert the operation to an already running
57 agent. This if ASSUAN_CTX is not NULL we take this as indication
58 that all operations are diverted to gpg-agent. */
59 #if GNUPG_MAJOR_VERSION == 1
60 assuan_context_t assuan_ctx;
61 #endif /*GNUPG_MAJOR_VERSION == 1*/
63 unsigned char *serialno; /* Serialnumber in raw form, allocated. */
64 size_t serialnolen; /* Length in octets of serialnumber. */
65 const char *apptype;
66 unsigned int card_version;
67 int did_chv1;
68 int force_chv1; /* True if the card does not cache CHV1. */
69 int did_chv2;
70 int did_chv3;
71 struct app_local_s *app_local; /* Local to the application. */
72 struct {
73 void (*deinit) (app_t app);
74 gpg_error_t (*learn_status) (app_t app, ctrl_t ctrl, unsigned int flags);
75 gpg_error_t (*readcert) (app_t app, const char *certid,
76 unsigned char **cert, size_t *certlen);
77 gpg_error_t (*readkey) (app_t app, const char *certid,
78 unsigned char **pk, size_t *pklen);
79 gpg_error_t (*getattr) (app_t app, ctrl_t ctrl, const char *name);
80 gpg_error_t (*setattr) (app_t app, const char *name,
81 gpg_error_t (*pincb)(void*, const char *, char **),
82 void *pincb_arg,
83 const unsigned char *value, size_t valuelen);
84 gpg_error_t (*sign) (app_t app,
85 const char *keyidstr, int hashalgo,
86 gpg_error_t (*pincb)(void*, const char *, char **),
87 void *pincb_arg,
88 const void *indata, size_t indatalen,
89 unsigned char **outdata, size_t *outdatalen );
90 gpg_error_t (*auth) (app_t app, const char *keyidstr,
91 gpg_error_t (*pincb)(void*, const char *, char **),
92 void *pincb_arg,
93 const void *indata, size_t indatalen,
94 unsigned char **outdata, size_t *outdatalen);
95 gpg_error_t (*decipher) (app_t app, const char *keyidstr,
96 gpg_error_t (*pincb)(void*, const char *, char **),
97 void *pincb_arg,
98 const void *indata, size_t indatalen,
99 unsigned char **outdata, size_t *outdatalen);
100 gpg_error_t (*writecert) (app_t app, ctrl_t ctrl,
101 const char *certid,
102 gpg_error_t (*pincb)(void*,const char *,char **),
103 void *pincb_arg,
104 const unsigned char *data, size_t datalen);
105 gpg_error_t (*writekey) (app_t app, ctrl_t ctrl,
106 const char *keyid, unsigned int flags,
107 gpg_error_t (*pincb)(void*,const char *,char **),
108 void *pincb_arg,
109 const unsigned char *pk, size_t pklen);
110 gpg_error_t (*genkey) (app_t app, ctrl_t ctrl,
111 const char *keynostr, unsigned int flags,
112 time_t createtime,
113 gpg_error_t (*pincb)(void*, const char *, char **),
114 void *pincb_arg);
115 gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
116 const char *chvnostr, unsigned int flags,
117 gpg_error_t (*pincb)(void*, const char *, char **),
118 void *pincb_arg);
119 gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
120 gpg_error_t (*pincb)(void*, const char *, char **),
121 void *pincb_arg);
122 } fnc;
126 #if GNUPG_MAJOR_VERSION == 1
127 gpg_error_t app_select_openpgp (app_t app);
128 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
129 gpg_error_t app_openpgp_storekey (app_t app, int keyno,
130 unsigned char *template, size_t template_len,
131 time_t created_at,
132 const unsigned char *m, size_t mlen,
133 const unsigned char *e, size_t elen,
134 gpg_error_t (*pincb)(void*, const char *, char **),
135 void *pincb_arg);
136 #else
137 /*-- app-help.c --*/
138 unsigned int app_help_count_bits (const unsigned char *a, size_t len);
139 gpg_error_t app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip);
140 size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
143 /*-- app.c --*/
144 void app_dump_state (void);
145 void application_notify_card_reset (int slot);
146 gpg_error_t check_application_conflict (ctrl_t ctrl, const char *name);
147 gpg_error_t select_application (ctrl_t ctrl, int slot, const char *name,
148 app_t *r_app);
149 char *get_supported_applications (void);
150 void release_application (app_t app);
151 gpg_error_t app_munge_serialno (app_t app);
152 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
153 gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl,
154 unsigned int flags);
155 gpg_error_t app_readcert (app_t app, const char *certid,
156 unsigned char **cert, size_t *certlen);
157 gpg_error_t app_readkey (app_t app, const char *keyid,
158 unsigned char **pk, size_t *pklen);
159 gpg_error_t app_getattr (app_t app, ctrl_t ctrl, const char *name);
160 gpg_error_t app_setattr (app_t app, const char *name,
161 gpg_error_t (*pincb)(void*, const char *, char **),
162 void *pincb_arg,
163 const unsigned char *value, size_t valuelen);
164 gpg_error_t app_sign (app_t app, const char *keyidstr, int hashalgo,
165 gpg_error_t (*pincb)(void*, const char *, char **),
166 void *pincb_arg,
167 const void *indata, size_t indatalen,
168 unsigned char **outdata, size_t *outdatalen );
169 gpg_error_t app_auth (app_t app, const char *keyidstr,
170 gpg_error_t (*pincb)(void*, const char *, char **),
171 void *pincb_arg,
172 const void *indata, size_t indatalen,
173 unsigned char **outdata, size_t *outdatalen);
174 gpg_error_t app_decipher (app_t app, const char *keyidstr,
175 gpg_error_t (*pincb)(void*, const char *, char **),
176 void *pincb_arg,
177 const void *indata, size_t indatalen,
178 unsigned char **outdata, size_t *outdatalen );
179 gpg_error_t app_writecert (app_t app, ctrl_t ctrl,
180 const char *certidstr,
181 gpg_error_t (*pincb)(void*, const char *, char **),
182 void *pincb_arg,
183 const unsigned char *keydata, size_t keydatalen);
184 gpg_error_t app_writekey (app_t app, ctrl_t ctrl,
185 const char *keyidstr, unsigned int flags,
186 gpg_error_t (*pincb)(void*, const char *, char **),
187 void *pincb_arg,
188 const unsigned char *keydata, size_t keydatalen);
189 gpg_error_t app_genkey (app_t app, ctrl_t ctrl,
190 const char *keynostr, unsigned int flags,
191 time_t createtime,
192 gpg_error_t (*pincb)(void*, const char *, char **),
193 void *pincb_arg);
194 gpg_error_t app_get_challenge (app_t app, size_t nbytes,
195 unsigned char *buffer);
196 gpg_error_t app_change_pin (app_t app, ctrl_t ctrl,
197 const char *chvnostr, int reset_mode,
198 gpg_error_t (*pincb)(void*, const char *, char **),
199 void *pincb_arg);
200 gpg_error_t app_check_pin (app_t app, const char *keyidstr,
201 gpg_error_t (*pincb)(void*, const char *, char **),
202 void *pincb_arg);
205 /*-- app-openpgp.c --*/
206 gpg_error_t app_select_openpgp (app_t app);
208 /*-- app-nks.c --*/
209 gpg_error_t app_select_nks (app_t app);
211 /*-- app-dinsig.c --*/
212 gpg_error_t app_select_dinsig (app_t app);
214 /*-- app-p15.c --*/
215 gpg_error_t app_select_p15 (app_t app);
217 /*-- app-geldkarte.c --*/
218 gpg_error_t app_select_geldkarte (app_t app);
221 #endif
225 #endif /*GNUPG_SCD_APP_COMMON_H*/