1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2000-2012 Jeffrey Stedfast
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.
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.
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
22 #ifndef __GMIME_CRYPTO_CONTEXT_H__
23 #define __GMIME_CRYPTO_CONTEXT_H__
25 #include <gmime/gmime-signature.h>
26 #include <gmime/gmime-stream.h>
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))
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))
44 typedef struct _GMimeCryptoContext GMimeCryptoContext;
45 typedef struct _GMimeCryptoContextClass GMimeCryptoContextClass;
47 typedef struct _GMimeDecryptResult GMimeDecryptResult;
48 typedef struct _GMimeDecryptResultClass GMimeDecryptResultClass;
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
60 * A password request callback allowing a #GMimeCryptoContext to
61 * prompt the user for a password for a given key.
63 * Returns: %TRUE on success or %FALSE on error.
65 typedef gboolean (* GMimePasswordRequestFunc) (GMimeCryptoContext *ctx, const char *user_id, const char *prompt_ctx,
66 gboolean reprompt, GMimeStream *response, GError **err);
71 * @parent_object: parent #GObject
72 * @request_passwd: a callback for requesting a password
74 * A crypto context for use with MIME.
76 struct _GMimeCryptoContext {
77 GObject parent_object;
79 GMimePasswordRequestFunc request_passwd;
82 struct _GMimeCryptoContextClass {
83 GObjectClass parent_class;
85 GMimeDigestAlgo (* digest_id) (GMimeCryptoContext *ctx, const char *name);
87 const char * (* digest_name) (GMimeCryptoContext *ctx, GMimeDigestAlgo digest);
89 const char * (* get_signature_protocol) (GMimeCryptoContext *ctx);
91 const char * (* get_encryption_protocol) (GMimeCryptoContext *ctx);
93 const char * (* get_key_exchange_protocol) (GMimeCryptoContext *ctx);
95 int (* sign) (GMimeCryptoContext *ctx, const char *userid,
96 GMimeDigestAlgo digest, GMimeStream *istream,
97 GMimeStream *ostream, GError **err);
99 GMimeSignatureList * (* verify) (GMimeCryptoContext *ctx, GMimeDigestAlgo digest,
100 GMimeStream *istream, GMimeStream *sigstream,
103 int (* encrypt) (GMimeCryptoContext *ctx, gboolean sign,
104 const char *userid, GMimeDigestAlgo digest,
105 GPtrArray *recipients, GMimeStream *istream,
106 GMimeStream *ostream, GError **err);
108 GMimeDecryptResult * (* decrypt) (GMimeCryptoContext *ctx, GMimeStream *istream,
109 GMimeStream *ostream, GError **err);
111 int (* import_keys) (GMimeCryptoContext *ctx, GMimeStream *istream,
114 int (* export_keys) (GMimeCryptoContext *ctx, GPtrArray *keys,
115 GMimeStream *ostream, GError **err);
119 GType g_mime_crypto_context_get_type (void);
121 void g_mime_crypto_context_set_request_password (GMimeCryptoContext *ctx, GMimePasswordRequestFunc request_passwd);
123 /* digest algo mapping */
124 GMimeDigestAlgo g_mime_crypto_context_digest_id (GMimeCryptoContext *ctx, const char *name);
126 const char *g_mime_crypto_context_digest_name (GMimeCryptoContext *ctx, GMimeDigestAlgo digest);
128 /* protocol routines */
129 const char *g_mime_crypto_context_get_signature_protocol (GMimeCryptoContext *ctx);
131 const char *g_mime_crypto_context_get_encryption_protocol (GMimeCryptoContext *ctx);
133 const char *g_mime_crypto_context_get_key_exchange_protocol (GMimeCryptoContext *ctx);
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);
140 GMimeSignatureList *g_mime_crypto_context_verify (GMimeCryptoContext *ctx, GMimeDigestAlgo digest,
141 GMimeStream *istream, GMimeStream *sigstream,
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);
149 GMimeDecryptResult *g_mime_crypto_context_decrypt (GMimeCryptoContext *ctx, GMimeStream *istream,
150 GMimeStream *ostream, GError **err);
152 /* key/certificate routines */
153 int g_mime_crypto_context_import_keys (GMimeCryptoContext *ctx, GMimeStream *istream, GError **err);
155 int g_mime_crypto_context_export_keys (GMimeCryptoContext *ctx, GPtrArray *keys,
156 GMimeStream *ostream, GError **err);
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.
175 * A cipher algorithm.
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
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.
200 * An object containing the results from decrypting an encrypted stream.
202 struct _GMimeDecryptResult {
203 GObject parent_object;
205 GMimeCertificateList *recipients;
206 GMimeSignatureList *signatures;
207 GMimeCipherAlgo cipher;
211 struct _GMimeDecryptResultClass {
212 GObjectClass parent_class;
216 GType g_mime_decrypt_result_get_type (void);
218 GMimeDecryptResult *g_mime_decrypt_result_new (void);
220 void g_mime_decrypt_result_set_recipients (GMimeDecryptResult *result, GMimeCertificateList *recipients);
221 GMimeCertificateList *g_mime_decrypt_result_get_recipients (GMimeDecryptResult *result);
223 void g_mime_decrypt_result_set_signatures (GMimeDecryptResult *result, GMimeSignatureList *signatures);
224 GMimeSignatureList *g_mime_decrypt_result_get_signatures (GMimeDecryptResult *result);
226 void g_mime_decrypt_result_set_cipher (GMimeDecryptResult *result, GMimeCipherAlgo cipher);
227 GMimeCipherAlgo g_mime_decrypt_result_get_cipher (GMimeDecryptResult *result);
229 void g_mime_decrypt_result_set_mdc (GMimeDecryptResult *result, GMimeDigestAlgo mdc);
230 GMimeDigestAlgo g_mime_decrypt_result_get_mdc (GMimeDecryptResult *result);
234 #endif /* __GMIME_CRYPTO_CONTEXT_H__ */