Initialize the gmime for upstream
[platform/upstream/gmime.git] / gmime / gmime-crypto-context.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*  GMime
3  *  Copyright (C) 2000-2012 Jeffrey Stedfast
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public License
7  *  as published by the Free Software Foundation; either version 2.1
8  *  of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free
17  *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
18  *  02110-1301, USA.
19  */
20
21
22 #ifndef __GMIME_CRYPTO_CONTEXT_H__
23 #define __GMIME_CRYPTO_CONTEXT_H__
24
25 #include <gmime/gmime-signature.h>
26 #include <gmime/gmime-stream.h>
27
28 G_BEGIN_DECLS
29
30 #define GMIME_TYPE_CRYPTO_CONTEXT            (g_mime_crypto_context_get_type ())
31 #define GMIME_CRYPTO_CONTEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_CRYPTO_CONTEXT, GMimeCryptoContext))
32 #define GMIME_CRYPTO_CONTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_CRYPTO_CONTEXT, GMimeCryptoContextClass))
33 #define GMIME_IS_CRYPTO_CONTEXT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_CRYPTO_CONTEXT))
34 #define GMIME_IS_CRYPTO_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_CRYPTO_CONTEXT))
35 #define GMIME_CRYPTO_CONTEXT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_CRYPTO_CONTEXT, GMimeCryptoContextClass))
36
37 #define GMIME_TYPE_DECRYPT_RESULT            (g_mime_decrypt_result_get_type ())
38 #define GMIME_DECRYPT_RESULT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_DECRYPT_RESULT, GMimeDecryptResult))
39 #define GMIME_DECRYPT_RESULT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_DECRYPT_RESULT, GMimeDecryptResultClass))
40 #define GMIME_IS_DECRYPT_RESULT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_DECRYPT_RESULT))
41 #define GMIME_IS_DECRYPT_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_DECRYPT_RESULT))
42 #define GMIME_DECRYPT_RESULT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_DECRYPT_RESULT, GMimeDecryptResultClass))
43
44 typedef struct _GMimeCryptoContext GMimeCryptoContext;
45 typedef struct _GMimeCryptoContextClass GMimeCryptoContextClass;
46
47 typedef struct _GMimeDecryptResult GMimeDecryptResult;
48 typedef struct _GMimeDecryptResultClass GMimeDecryptResultClass;
49
50
51 /**
52  * GMimePasswordRequestFunc:
53  * @ctx: the #GMimeCryptoContext making the request
54  * @user_id: the user_id of the password being requested
55  * @prompt_ctx: a string containing some helpful context for the prompt
56  * @reprompt: %TRUE if this password request is a reprompt due to a previously bad password response
57  * @response: a stream for the application to write the password to (followed by a newline '\n' character)
58  * @err: a #GError for the callback to set if an error occurs
59  *
60  * A password request callback allowing a #GMimeCryptoContext to
61  * prompt the user for a password for a given key.
62  *
63  * Returns: %TRUE on success or %FALSE on error.
64  **/
65 typedef gboolean (* GMimePasswordRequestFunc) (GMimeCryptoContext *ctx, const char *user_id, const char *prompt_ctx,
66                                                gboolean reprompt, GMimeStream *response, GError **err);
67
68
69 /**
70  * GMimeCryptoContext:
71  * @parent_object: parent #GObject
72  * @request_passwd: a callback for requesting a password
73  *
74  * A crypto context for use with MIME.
75  **/
76 struct _GMimeCryptoContext {
77         GObject parent_object;
78         
79         GMimePasswordRequestFunc request_passwd;
80 };
81
82 struct _GMimeCryptoContextClass {
83         GObjectClass parent_class;
84         
85         GMimeDigestAlgo          (* digest_id)   (GMimeCryptoContext *ctx, const char *name);
86         
87         const char *             (* digest_name) (GMimeCryptoContext *ctx, GMimeDigestAlgo digest);
88         
89         const char *             (* get_signature_protocol) (GMimeCryptoContext *ctx);
90         
91         const char *             (* get_encryption_protocol) (GMimeCryptoContext *ctx);
92         
93         const char *             (* get_key_exchange_protocol) (GMimeCryptoContext *ctx);
94         
95         int                      (* sign)        (GMimeCryptoContext *ctx, const char *userid,
96                                                   GMimeDigestAlgo digest, GMimeStream *istream,
97                                                   GMimeStream *ostream, GError **err);
98         
99         GMimeSignatureList *     (* verify)      (GMimeCryptoContext *ctx, GMimeDigestAlgo digest,
100                                                   GMimeStream *istream, GMimeStream *sigstream,
101                                                   GError **err);
102         
103         int                      (* encrypt)     (GMimeCryptoContext *ctx, gboolean sign,
104                                                   const char *userid, GMimeDigestAlgo digest,
105                                                   GPtrArray *recipients, GMimeStream *istream,
106                                                   GMimeStream *ostream, GError **err);
107         
108         GMimeDecryptResult *     (* decrypt)     (GMimeCryptoContext *ctx, GMimeStream *istream,
109                                                   GMimeStream *ostream, GError **err);
110         
111         int                      (* import_keys) (GMimeCryptoContext *ctx, GMimeStream *istream,
112                                                   GError **err);
113         
114         int                      (* export_keys) (GMimeCryptoContext *ctx, GPtrArray *keys,
115                                                   GMimeStream *ostream, GError **err);
116 };
117
118
119 GType g_mime_crypto_context_get_type (void);
120
121 void g_mime_crypto_context_set_request_password (GMimeCryptoContext *ctx, GMimePasswordRequestFunc request_passwd);
122
123 /* digest algo mapping */
124 GMimeDigestAlgo g_mime_crypto_context_digest_id (GMimeCryptoContext *ctx, const char *name);
125
126 const char *g_mime_crypto_context_digest_name (GMimeCryptoContext *ctx, GMimeDigestAlgo digest);
127
128 /* protocol routines */
129 const char *g_mime_crypto_context_get_signature_protocol (GMimeCryptoContext *ctx);
130
131 const char *g_mime_crypto_context_get_encryption_protocol (GMimeCryptoContext *ctx);
132
133 const char *g_mime_crypto_context_get_key_exchange_protocol (GMimeCryptoContext *ctx);
134
135 /* crypto routines */
136 int g_mime_crypto_context_sign (GMimeCryptoContext *ctx, const char *userid,
137                                 GMimeDigestAlgo digest, GMimeStream *istream,
138                                 GMimeStream *ostream, GError **err);
139
140 GMimeSignatureList *g_mime_crypto_context_verify (GMimeCryptoContext *ctx, GMimeDigestAlgo digest,
141                                                   GMimeStream *istream, GMimeStream *sigstream,
142                                                   GError **err);
143
144 int g_mime_crypto_context_encrypt (GMimeCryptoContext *ctx, gboolean sign,
145                                    const char *userid, GMimeDigestAlgo digest,
146                                    GPtrArray *recipients, GMimeStream *istream,
147                                    GMimeStream *ostream, GError **err);
148
149 GMimeDecryptResult *g_mime_crypto_context_decrypt (GMimeCryptoContext *ctx, GMimeStream *istream,
150                                                    GMimeStream *ostream, GError **err);
151
152 /* key/certificate routines */
153 int g_mime_crypto_context_import_keys (GMimeCryptoContext *ctx, GMimeStream *istream, GError **err);
154
155 int g_mime_crypto_context_export_keys (GMimeCryptoContext *ctx, GPtrArray *keys,
156                                        GMimeStream *ostream, GError **err);
157
158
159
160 /**
161  * GMimeCipherAlgo:
162  * @GMIME_CIPHER_ALGO_DEFAULT: The default (or unknown) cipher.
163  * @GMIME_CIPHER_ALGO_IDEA: The IDEA cipher.
164  * @GMIME_CIPHER_ALGO_3DES: The 3DES cipher.
165  * @GMIME_CIPHER_ALGO_CAST5: The CAST5 cipher.
166  * @GMIME_CIPHER_ALGO_BLOWFISH: The Blowfish cipher.
167  * @GMIME_CIPHER_ALGO_AES: The AES (aka RIJANDALE) cipher.
168  * @GMIME_CIPHER_ALGO_AES192: The AES-192 cipher.
169  * @GMIME_CIPHER_ALGO_AES256: The AES-256 cipher.
170  * @GMIME_CIPHER_ALGO_TWOFISH: The Twofish cipher.
171  * @GMIME_CIPHER_ALGO_CAMELLIA128: The Camellia-128 cipher.
172  * @GMIME_CIPHER_ALGO_CAMELLIA192: The Camellia-192 cipher.
173  * @GMIME_CIPHER_ALGO_CAMELLIA256: The Camellia-256 cipher.
174  *
175  * A cipher algorithm.
176  **/
177 typedef enum {
178         GMIME_CIPHER_ALGO_DEFAULT     = 0,
179         GMIME_CIPHER_ALGO_IDEA        = 1,
180         GMIME_CIPHER_ALGO_3DES        = 2,
181         GMIME_CIPHER_ALGO_CAST5       = 3,
182         GMIME_CIPHER_ALGO_BLOWFISH    = 4,
183         GMIME_CIPHER_ALGO_AES         = 7,
184         GMIME_CIPHER_ALGO_AES192      = 8,
185         GMIME_CIPHER_ALGO_AES256      = 9,
186         GMIME_CIPHER_ALGO_TWOFISH     = 10,
187         GMIME_CIPHER_ALGO_CAMELLIA128 = 11,
188         GMIME_CIPHER_ALGO_CAMELLIA192 = 12,
189         GMIME_CIPHER_ALGO_CAMELLIA256 = 13
190 } GMimeCipherAlgo;
191
192 /**
193  * GMimeDecryptResult:
194  * @parent_object: parent #GObject
195  * @recipients: A #GMimeCertificateList
196  * @signatures: A #GMimeSignatureList if signed or %NULL otherwise.
197  * @cipher: The cipher algorithm used to encrypt the stream.
198  * @mdc: The MDC digest algorithm used, if any.
199  *
200  * An object containing the results from decrypting an encrypted stream.
201  **/
202 struct _GMimeDecryptResult {
203         GObject parent_object;
204         
205         GMimeCertificateList *recipients;
206         GMimeSignatureList *signatures;
207         GMimeCipherAlgo cipher;
208         GMimeDigestAlgo mdc;
209 };
210
211 struct _GMimeDecryptResultClass {
212         GObjectClass parent_class;
213         
214 };
215
216 GType g_mime_decrypt_result_get_type (void);
217
218 GMimeDecryptResult *g_mime_decrypt_result_new (void);
219
220 void g_mime_decrypt_result_set_recipients (GMimeDecryptResult *result, GMimeCertificateList *recipients);
221 GMimeCertificateList *g_mime_decrypt_result_get_recipients (GMimeDecryptResult *result);
222
223 void g_mime_decrypt_result_set_signatures (GMimeDecryptResult *result, GMimeSignatureList *signatures);
224 GMimeSignatureList *g_mime_decrypt_result_get_signatures (GMimeDecryptResult *result);
225
226 void g_mime_decrypt_result_set_cipher (GMimeDecryptResult *result, GMimeCipherAlgo cipher);
227 GMimeCipherAlgo g_mime_decrypt_result_get_cipher (GMimeDecryptResult *result);
228
229 void g_mime_decrypt_result_set_mdc (GMimeDecryptResult *result, GMimeDigestAlgo mdc);
230 GMimeDigestAlgo g_mime_decrypt_result_get_mdc (GMimeDecryptResult *result);
231
232 G_END_DECLS
233
234 #endif /* __GMIME_CRYPTO_CONTEXT_H__ */