Avoid passing NULL to printf while debugging.
[gnupg.git] / scd / app-common.h
blobdc1581e504a596f585015b4516c0015b242edffe
1 /* app-common.h - Common declarations for all card applications
2 * Copyright (C) 2003, 2005 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 int initialized; /* The application has been initialied and the
42 function pointers may be used. Note that for
43 unsupported operations the particular
44 function pointer is set to NULL */
46 int ref_count; /* Number of connections currently using this
47 application context. fixme: We might want to
48 merg this witghn INITIALIZED above. */
50 int slot; /* Used reader. */
52 /* If this is used by GnuPG 1.4 we need to know the assuan context
53 in case we need to divert the operation to an already running
54 agent. This if ASSUAN_CTX is not NULL we take this as indication
55 that all operations are diverted to gpg-agent. */
56 #if GNUPG_MAJOR_VERSION == 1
57 assuan_context_t assuan_ctx;
58 #endif /*GNUPG_MAJOR_VERSION == 1*/
60 unsigned char *serialno; /* Serialnumber in raw form, allocated. */
61 size_t serialnolen; /* Length in octets of serialnumber. */
62 const char *apptype;
63 unsigned int card_version;
64 int did_chv1;
65 int force_chv1; /* True if the card does not cache CHV1. */
66 int did_chv2;
67 int did_chv3;
68 struct app_local_s *app_local; /* Local to the application. */
69 struct {
70 void (*deinit) (app_t app);
71 gpg_error_t (*learn_status) (app_t app, ctrl_t ctrl);
72 gpg_error_t (*readcert) (app_t app, const char *certid,
73 unsigned char **cert, size_t *certlen);
74 gpg_error_t (*readkey) (app_t app, const char *certid,
75 unsigned char **pk, size_t *pklen);
76 gpg_error_t (*getattr) (app_t app, ctrl_t ctrl, const char *name);
77 gpg_error_t (*setattr) (app_t app, const char *name,
78 gpg_error_t (*pincb)(void*, const char *, char **),
79 void *pincb_arg,
80 const unsigned char *value, size_t valuelen);
81 gpg_error_t (*sign) (app_t app,
82 const char *keyidstr, int hashalgo,
83 gpg_error_t (*pincb)(void*, const char *, char **),
84 void *pincb_arg,
85 const void *indata, size_t indatalen,
86 unsigned char **outdata, size_t *outdatalen );
87 gpg_error_t (*auth) (app_t app, const char *keyidstr,
88 gpg_error_t (*pincb)(void*, const char *, char **),
89 void *pincb_arg,
90 const void *indata, size_t indatalen,
91 unsigned char **outdata, size_t *outdatalen);
92 gpg_error_t (*decipher) (app_t app, const char *keyidstr,
93 gpg_error_t (*pincb)(void*, const char *, char **),
94 void *pincb_arg,
95 const void *indata, size_t indatalen,
96 unsigned char **outdata, size_t *outdatalen);
97 gpg_error_t (*writekey) (app_t app, ctrl_t ctrl,
98 const char *certid, unsigned int flags,
99 gpg_error_t (*pincb)(void*,const char *,char **),
100 void *pincb_arg,
101 const unsigned char *pk, size_t pklen);
102 gpg_error_t (*genkey) (app_t app, ctrl_t ctrl,
103 const char *keynostr, unsigned int flags,
104 time_t createtime,
105 gpg_error_t (*pincb)(void*, const char *, char **),
106 void *pincb_arg);
107 gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
108 const char *chvnostr, unsigned int flags,
109 gpg_error_t (*pincb)(void*, const char *, char **),
110 void *pincb_arg);
111 gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
112 gpg_error_t (*pincb)(void*, const char *, char **),
113 void *pincb_arg);
114 } fnc;
118 #if GNUPG_MAJOR_VERSION == 1
119 gpg_error_t app_select_openpgp (app_t app);
120 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
121 gpg_error_t app_openpgp_storekey (app_t app, int keyno,
122 unsigned char *template, size_t template_len,
123 time_t created_at,
124 const unsigned char *m, size_t mlen,
125 const unsigned char *e, size_t elen,
126 gpg_error_t (*pincb)(void*, const char *, char **),
127 void *pincb_arg);
128 #else
129 /*-- app-help.c --*/
130 gpg_error_t app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip);
131 size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
134 /*-- app.c --*/
135 void app_dump_state (void);
136 void application_notify_card_removed (int slot);
137 gpg_error_t check_application_conflict (ctrl_t ctrl, const char *name);
138 gpg_error_t select_application (ctrl_t ctrl, int slot, const char *name,
139 app_t *r_app);
140 void release_application (app_t app);
141 gpg_error_t app_munge_serialno (app_t app);
142 gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp);
143 gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl);
144 gpg_error_t app_readcert (app_t app, const char *certid,
145 unsigned char **cert, size_t *certlen);
146 gpg_error_t app_readkey (app_t app, const char *keyid,
147 unsigned char **pk, size_t *pklen);
148 gpg_error_t app_getattr (app_t app, ctrl_t ctrl, const char *name);
149 gpg_error_t app_setattr (app_t app, const char *name,
150 gpg_error_t (*pincb)(void*, const char *, char **),
151 void *pincb_arg,
152 const unsigned char *value, size_t valuelen);
153 gpg_error_t app_sign (app_t app, const char *keyidstr, int hashalgo,
154 gpg_error_t (*pincb)(void*, const char *, char **),
155 void *pincb_arg,
156 const void *indata, size_t indatalen,
157 unsigned char **outdata, size_t *outdatalen );
158 gpg_error_t app_auth (app_t app, const char *keyidstr,
159 gpg_error_t (*pincb)(void*, const char *, char **),
160 void *pincb_arg,
161 const void *indata, size_t indatalen,
162 unsigned char **outdata, size_t *outdatalen);
163 gpg_error_t app_decipher (app_t app, const char *keyidstr,
164 gpg_error_t (*pincb)(void*, const char *, char **),
165 void *pincb_arg,
166 const void *indata, size_t indatalen,
167 unsigned char **outdata, size_t *outdatalen );
168 gpg_error_t app_writekey (app_t app, ctrl_t ctrl,
169 const char *keyidstr, unsigned int flags,
170 gpg_error_t (*pincb)(void*, const char *, char **),
171 void *pincb_arg,
172 const unsigned char *keydata, size_t keydatalen);
173 gpg_error_t app_genkey (app_t app, ctrl_t ctrl,
174 const char *keynostr, unsigned int flags,
175 time_t createtime,
176 gpg_error_t (*pincb)(void*, const char *, char **),
177 void *pincb_arg);
178 gpg_error_t app_get_challenge (app_t app, size_t nbytes,
179 unsigned char *buffer);
180 gpg_error_t app_change_pin (app_t app, ctrl_t ctrl,
181 const char *chvnostr, int reset_mode,
182 gpg_error_t (*pincb)(void*, const char *, char **),
183 void *pincb_arg);
184 gpg_error_t app_check_pin (app_t app, const char *keyidstr,
185 gpg_error_t (*pincb)(void*, const char *, char **),
186 void *pincb_arg);
189 /*-- app-openpgp.c --*/
190 gpg_error_t app_select_openpgp (app_t app);
192 /*-- app-nks.c --*/
193 gpg_error_t app_select_nks (app_t app);
195 /*-- app-dinsig.c --*/
196 gpg_error_t app_select_dinsig (app_t app);
198 /*-- app-p15.c --*/
199 gpg_error_t app_select_p15 (app_t app);
202 #endif
206 #endif /*GNUPG_SCD_APP_COMMON_H*/