Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-cipher-context.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4  *
5  *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program 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 Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24 #error "Only <camel/camel.h> can be included directly."
25 #endif
26
27 #ifndef CAMEL_CIPHER_CONTEXT_H
28 #define CAMEL_CIPHER_CONTEXT_H
29
30 #include <camel/camel-mime-part.h>
31 #include <camel/camel-session.h>
32
33 /* Standard GObject macros */
34 #define CAMEL_TYPE_CIPHER_CONTEXT \
35         (camel_cipher_context_get_type ())
36 #define CAMEL_CIPHER_CONTEXT(obj) \
37         (G_TYPE_CHECK_INSTANCE_CAST \
38         ((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContext))
39 #define CAMEL_CIPHER_CONTEXT_CLASS(cls) \
40         (G_TYPE_CHECK_CLASS_CAST \
41         ((cls), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
42 #define CAMEL_IS_CIPHER_CONTEXT(obj) \
43         (G_TYPE_CHECK_INSTANCE_TYPE \
44         ((obj), CAMEL_TYPE_CIPHER_CONTEXT))
45 #define CAMEL_IS_CIPHER_CONTEXT_CLASS(cls) \
46         (G_TYPE_CHECK_CLASS_TYPE \
47         ((cls), CAMEL_TYPE_CIPHER_CONTEXT))
48 #define CAMEL_CIPHER_CONTEXT_GET_CLASS(obj) \
49         (G_TYPE_INSTANCE_GET_CLASS \
50         ((obj), CAMEL_TYPE_CIPHER_CONTEXT, CamelCipherContextClass))
51
52 G_BEGIN_DECLS
53
54 typedef struct _CamelCipherValidity CamelCipherValidity;
55 typedef struct _CamelCipherCertInfo CamelCipherCertInfo;
56
57 typedef struct _CamelCipherContext CamelCipherContext;
58 typedef struct _CamelCipherContextClass CamelCipherContextClass;
59 typedef struct _CamelCipherContextPrivate CamelCipherContextPrivate;
60
61 typedef enum {
62         CAMEL_CIPHER_HASH_DEFAULT,
63         CAMEL_CIPHER_HASH_MD2,
64         CAMEL_CIPHER_HASH_MD5,
65         CAMEL_CIPHER_HASH_SHA1,
66         CAMEL_CIPHER_HASH_SHA256,
67         CAMEL_CIPHER_HASH_SHA384,
68         CAMEL_CIPHER_HASH_SHA512,
69         CAMEL_CIPHER_HASH_RIPEMD160,
70         CAMEL_CIPHER_HASH_TIGER192,
71         CAMEL_CIPHER_HASH_HAVAL5160
72 } CamelCipherHash;
73
74 typedef enum _camel_cipher_validity_sign_t {
75         CAMEL_CIPHER_VALIDITY_SIGN_NONE,
76         CAMEL_CIPHER_VALIDITY_SIGN_GOOD,
77         CAMEL_CIPHER_VALIDITY_SIGN_BAD,
78         CAMEL_CIPHER_VALIDITY_SIGN_UNKNOWN,
79         CAMEL_CIPHER_VALIDITY_SIGN_NEED_PUBLIC_KEY
80 } camel_cipher_validity_sign_t;
81
82 typedef enum _camel_cipher_validity_encrypt_t {
83         CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE,
84         CAMEL_CIPHER_VALIDITY_ENCRYPT_WEAK,
85         CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED, /* encrypted, unknown strenght */
86         CAMEL_CIPHER_VALIDITY_ENCRYPT_STRONG
87 } camel_cipher_validity_encrypt_t;
88
89 typedef enum _camel_cipher_validity_mode_t {
90         CAMEL_CIPHER_VALIDITY_SIGN,
91         CAMEL_CIPHER_VALIDITY_ENCRYPT
92 } camel_cipher_validity_mode_t;
93
94 struct _CamelCipherCertInfo {
95         gchar *name;            /* common name */
96         gchar *email;
97
98         gpointer cert_data;  /* custom certificate data; can be NULL */
99         void (*cert_data_free) (gpointer cert_data); /* called to free cert_data; can be NULL only if cert_data is NULL */
100         gpointer (*cert_data_clone) (gpointer cert_data); /* called to clone cert_data; can be NULL only if cert_data is NULL */
101 };
102
103 struct _CamelCipherValidity {
104         GQueue children;
105
106         struct {
107                 enum _camel_cipher_validity_sign_t status;
108                 gchar *description;
109                 GQueue signers; /* CamelCipherCertInfo's */
110         } sign;
111
112         struct {
113                 enum _camel_cipher_validity_encrypt_t status;
114                 gchar *description;
115                 GQueue encrypters;      /* CamelCipherCertInfo's */
116         } encrypt;
117 };
118
119 struct _CamelCipherContext {
120         CamelObject parent;
121         CamelCipherContextPrivate *priv;
122 };
123
124 struct _CamelCipherContextClass {
125         CamelObjectClass parent_class;
126
127         /* these MUST be set by implementors */
128         const gchar *sign_protocol;
129         const gchar *encrypt_protocol;
130         const gchar *key_protocol;
131
132         /* Non-Blocking Methods */
133         CamelCipherHash (*id_to_hash)           (CamelCipherContext *context,
134                                                  const gchar *id);
135         const gchar *   (*hash_to_id)           (CamelCipherContext *context,
136                                                  CamelCipherHash hash);
137
138         /* Synchronous I/O Methods */
139         gboolean        (*sign_sync)            (CamelCipherContext *context,
140                                                  const gchar *userid,
141                                                  CamelCipherHash hash,
142                                                  CamelMimePart *ipart,
143                                                  CamelMimePart *opart,
144                                                  GCancellable *cancellable,
145                                                  GError **error);
146         CamelCipherValidity *
147                         (*verify_sync)          (CamelCipherContext *context,
148                                                  CamelMimePart *ipart,
149                                                  GCancellable *cancellable,
150                                                  GError **error);
151         gboolean        (*encrypt_sync)         (CamelCipherContext *context,
152                                                  const gchar *userid,
153                                                  GPtrArray *recipients,
154                                                  CamelMimePart *ipart,
155                                                  CamelMimePart *opart,
156                                                  GCancellable *cancellable,
157                                                  GError **error);
158         CamelCipherValidity *
159                         (*decrypt_sync)         (CamelCipherContext *context,
160                                                  CamelMimePart *ipart,
161                                                  CamelMimePart *opart,
162                                                  GCancellable *cancellable,
163                                                  GError **error);
164         gboolean        (*import_keys_sync)     (CamelCipherContext *context,
165                                                  CamelStream *istream,
166                                                  GCancellable *cancellable,
167                                                  GError **error);
168         gboolean        (*export_keys_sync)     (CamelCipherContext *context,
169                                                  GPtrArray *keys,
170                                                  CamelStream *ostream,
171                                                  GCancellable *cancellable,
172                                                  GError **error);
173
174         /* Asynchronous I/O Methods (all have defaults) */
175         void            (*sign)                 (CamelCipherContext *context,
176                                                  const gchar *userid,
177                                                  CamelCipherHash hash,
178                                                  CamelMimePart *ipart,
179                                                  CamelMimePart *opart,
180                                                  gint io_priority,
181                                                  GCancellable *cancellable,
182                                                  GAsyncReadyCallback callback,
183                                                  gpointer user_data);
184         gboolean        (*sign_finish)          (CamelCipherContext *context,
185                                                  GAsyncResult *result,
186                                                  GError **error);
187         void            (*verify)               (CamelCipherContext *context,
188                                                  CamelMimePart *ipart,
189                                                  gint io_priority,
190                                                  GCancellable *cancellable,
191                                                  GAsyncReadyCallback callback,
192                                                  gpointer user_data);
193         CamelCipherValidity *
194                         (*verify_finish)        (CamelCipherContext *context,
195                                                  GAsyncResult *result,
196                                                  GError **error);
197         void            (*encrypt)              (CamelCipherContext *context,
198                                                  const gchar *user_id,
199                                                  GPtrArray *recipients,
200                                                  CamelMimePart *ipart,
201                                                  CamelMimePart *opart,
202                                                  gint io_priority,
203                                                  GCancellable *cancellable,
204                                                  GAsyncReadyCallback callback,
205                                                  gpointer user_data);
206         gboolean        (*encrypt_finish)       (CamelCipherContext *context,
207                                                  GAsyncResult *result,
208                                                  GError **error);
209         void            (*decrypt)              (CamelCipherContext *context,
210                                                  CamelMimePart *ipart,
211                                                  CamelMimePart *opart,
212                                                  gint io_priority,
213                                                  GCancellable *cancellable,
214                                                  GAsyncReadyCallback callback,
215                                                  gpointer user_data);
216         CamelCipherValidity *
217                         (*decrypt_finish)       (CamelCipherContext *context,
218                                                  GAsyncResult *result,
219                                                  GError **error);
220         void            (*import_keys)          (CamelCipherContext *context,
221                                                  CamelStream *istream,
222                                                  gint io_priority,
223                                                  GCancellable *cancellable,
224                                                  GAsyncReadyCallback callback,
225                                                  gpointer user_data);
226         gboolean        (*import_keys_finish)   (CamelCipherContext *context,
227                                                  GAsyncResult *result,
228                                                  GError **error);
229         void            (*export_keys)          (CamelCipherContext *context,
230                                                  GPtrArray *keys,
231                                                  CamelStream *ostream,
232                                                  gint io_priority,
233                                                  GCancellable *cancellable,
234                                                  GAsyncReadyCallback callback,
235                                                  gpointer user_data);
236         gboolean        (*export_keys_finish)   (CamelCipherContext *context,
237                                                  GAsyncResult *result,
238                                                  GError **error);
239 };
240
241 GType           camel_cipher_context_get_type   (void);
242 CamelCipherContext *
243                 camel_cipher_context_new        (CamelSession *session);
244 CamelSession *  camel_cipher_context_get_session
245                                                 (CamelCipherContext *context);
246
247 /* cipher context util routines */
248 CamelCipherHash camel_cipher_context_id_to_hash (CamelCipherContext *context,
249                                                  const gchar *id);
250 const gchar *   camel_cipher_context_hash_to_id (CamelCipherContext *context,
251                                                  CamelCipherHash hash);
252
253 /* FIXME:
254  * There are some inconsistencies here, the api's should probably handle CamelMimePart's as input/outputs,
255  * Something that might generate a multipart/signed should do it as part of that processing, internally
256  * to the cipher, etc etc. */
257
258 /* cipher routines */
259 gboolean        camel_cipher_context_sign_sync  (CamelCipherContext *context,
260                                                  const gchar *userid,
261                                                  CamelCipherHash hash,
262                                                  CamelMimePart *ipart,
263                                                  CamelMimePart *opart,
264                                                  GCancellable *cancellable,
265                                                  GError **error);
266 void            camel_cipher_context_sign       (CamelCipherContext *context,
267                                                  const gchar *userid,
268                                                  CamelCipherHash hash,
269                                                  CamelMimePart *ipart,
270                                                  CamelMimePart *opart,
271                                                  gint io_priority,
272                                                  GCancellable *cancellable,
273                                                  GAsyncReadyCallback callback,
274                                                  gpointer user_data);
275 gboolean        camel_cipher_context_sign_finish
276                                                 (CamelCipherContext *context,
277                                                  GAsyncResult *result,
278                                                  GError **error);
279 CamelCipherValidity *
280                 camel_cipher_context_verify_sync
281                                                 (CamelCipherContext *context,
282                                                  CamelMimePart *ipart,
283                                                  GCancellable *cancellable,
284                                                  GError **error);
285 void            camel_cipher_context_verify     (CamelCipherContext *context,
286                                                  CamelMimePart *ipart,
287                                                  gint io_priority,
288                                                  GCancellable *cancellable,
289                                                  GAsyncReadyCallback callback,
290                                                  gpointer user_data);
291 CamelCipherValidity *
292                 camel_cipher_context_verify_finish
293                                                 (CamelCipherContext *context,
294                                                  GAsyncResult *result,
295                                                  GError **error);
296 gboolean        camel_cipher_context_encrypt_sync
297                                                 (CamelCipherContext *context,
298                                                  const gchar *userid,
299                                                  GPtrArray *recipients,
300                                                  CamelMimePart *ipart,
301                                                  CamelMimePart *opart,
302                                                  GCancellable *cancellable,
303                                                  GError **error);
304 void            camel_cipher_context_encrypt    (CamelCipherContext *context,
305                                                  const gchar *userid,
306                                                  GPtrArray *recipients,
307                                                  CamelMimePart *ipart,
308                                                  CamelMimePart *opart,
309                                                  gint io_priority,
310                                                  GCancellable *cancellable,
311                                                  GAsyncReadyCallback callback,
312                                                  gpointer user_data);
313 gboolean        camel_cipher_context_encrypt_finish
314                                                 (CamelCipherContext *context,
315                                                  GAsyncResult *result,
316                                                  GError **error);
317 CamelCipherValidity *
318                 camel_cipher_context_decrypt_sync
319                                                 (CamelCipherContext *context,
320                                                  CamelMimePart *ipart,
321                                                  CamelMimePart *opart,
322                                                  GCancellable *cancellable,
323                                                  GError **error);
324 void            camel_cipher_context_decrypt    (CamelCipherContext *context,
325                                                  CamelMimePart *ipart,
326                                                  CamelMimePart *opart,
327                                                  gint io_priority,
328                                                  GCancellable *cancellable,
329                                                  GAsyncReadyCallback callback,
330                                                  gpointer user_data);
331 CamelCipherValidity *
332                 camel_cipher_context_decrypt_finish
333                                                 (CamelCipherContext *context,
334                                                  GAsyncResult *result,
335                                                  GError **error);
336
337 /* key/certificate routines */
338 gboolean        camel_cipher_context_import_keys_sync
339                                                 (CamelCipherContext *context,
340                                                  CamelStream *istream,
341                                                  GCancellable *cancellable,
342                                                  GError **error);
343 void            camel_cipher_context_import_keys
344                                                 (CamelCipherContext *context,
345                                                  CamelStream *istream,
346                                                  gint io_priority,
347                                                  GCancellable *cancellable,
348                                                  GAsyncReadyCallback callback,
349                                                  gpointer user_data);
350 gboolean        camel_cipher_context_import_keys_finish
351                                                 (CamelCipherContext *context,
352                                                  GAsyncResult *result,
353                                                  GError **error);
354 gboolean        camel_cipher_context_export_keys_sync
355                                                 (CamelCipherContext *context,
356                                                  GPtrArray *keys,
357                                                  CamelStream *ostream,
358                                                  GCancellable *cancellable,
359                                                  GError **error);
360 void            camel_cipher_context_export_keys
361                                                 (CamelCipherContext *context,
362                                                  GPtrArray *keys,
363                                                  CamelStream *ostream,
364                                                  gint io_priority,
365                                                  GCancellable *cancellable,
366                                                  GAsyncReadyCallback callback,
367                                                  gpointer user_data);
368 gboolean        camel_cipher_context_export_keys_finish
369                                                 (CamelCipherContext *context,
370                                                  GAsyncResult *result,
371                                                  GError **error);
372
373 /* CamelCipherValidity utility functions */
374 CamelCipherValidity *
375                 camel_cipher_validity_new       (void);
376 void            camel_cipher_validity_init      (CamelCipherValidity *validity);
377 gboolean        camel_cipher_validity_get_valid (CamelCipherValidity *validity);
378 void            camel_cipher_validity_set_valid (CamelCipherValidity *validity,
379                                                  gboolean valid);
380 gchar *         camel_cipher_validity_get_description
381                                                 (CamelCipherValidity *validity);
382 void            camel_cipher_validity_set_description
383                                                 (CamelCipherValidity *validity,
384                                                  const gchar *description);
385 void            camel_cipher_validity_clear     (CamelCipherValidity *validity);
386 CamelCipherValidity *
387                 camel_cipher_validity_clone     (CamelCipherValidity *vin);
388 void            camel_cipher_validity_add_certinfo
389                                                 (CamelCipherValidity *vin,
390                                                  camel_cipher_validity_mode_t mode,
391                                                  const gchar *name,
392                                                  const gchar *email);
393 void            camel_cipher_validity_add_certinfo_ex (
394                                                 CamelCipherValidity *vin,
395                                                 camel_cipher_validity_mode_t mode,
396                                                 const gchar *name,
397                                                 const gchar *email,
398                                                 gpointer cert_data,
399                                                 void (*cert_data_free) (gpointer cert_data),
400                                                 gpointer (*cert_data_clone) (gpointer cert_data));
401 void            camel_cipher_validity_envelope  (CamelCipherValidity *parent,
402                                                  CamelCipherValidity *valid);
403 void            camel_cipher_validity_free      (CamelCipherValidity *validity);
404
405 /* utility functions */
406 gint            camel_cipher_canonical_to_stream
407                                                 (CamelMimePart *part,
408                                                  guint32 flags,
409                                                  CamelStream *ostream,
410                                                  GCancellable *cancellable,
411                                                  GError **error);
412
413 G_END_DECLS
414
415 #endif /* CAMEL_CIPHER_CONTEXT_H */