aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-cipher-context.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-10-30 12:58:33 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-10-30 12:58:33 +0800
commit52759f2d4018b8ff0ce173aa1237b08783f1424c (patch)
treec6b392bea311df4d965b3e234cb769d6bf78e7e0 /camel/camel-cipher-context.c
parent4c9e3c871c301e92711b91f0df0aca2521567db1 (diff)
downloadgsoc2013-evolution-52759f2d4018b8ff0ce173aa1237b08783f1424c.tar.gz
gsoc2013-evolution-52759f2d4018b8ff0ce173aa1237b08783f1424c.tar.zst
gsoc2013-evolution-52759f2d4018b8ff0ce173aa1237b08783f1424c.zip
Added a note about api inconsistencies.
2003-10-30 Not Zed <NotZed@Ximian.com> * camel-cipher-context.h: Added a note about api inconsistencies. 2003-10-30 Not Zed <NotZed@Ximian.com> * camel-multipart-encrypted.c (camel_multipart_encrypted_decrypt): fix for cipher_decrypt changes. * camel-gpg-context.c, camel-cipher-context.c: moved all the init code to the end to save having to keep forward declarations around. (camel_cipher_decrypt): changed to take mimepart input and return a mimepart. (gpg_decrypt): fix for changed args. 2003-10-29 Not Zed <NotZed@Ximian.com> * camel-smime-context.[ch]: replaced entirely with a new implementation which inherits from camel-cipher-context, and add to build. * camel-multipart-encrypted.c (camel_multipart_encrypted_encrypt): fix for cipher_encrypt api changes. (camel_multipart_encrypted_decrypt): use g_ascii_strcasecmp. * camel-gpg-context.c (gpg_encrypt): Fix to handle input/output as parts not streams * camel-cipher-context.c (camel_cipher_encrypt): change to take mimeparts rather than streams as input/output. And remove the 'sign' argument, it is implied if userid is supplied. 2003-10-28 Not Zed <NotZed@Ximian.com> * tests/smime/pgp.c (main): fix for ciphercontext api changes. * camel-multipart-signed.c (camel_multipart_signed_verify): pass in the part to cipher_verify directly. (camel_multipart_signed_sign): let the cipher context setup the part details. * camel-gpg-context.c (gpg_sign): put the signature stream into a mimepart, with appropriate headers/encoding. (swrite): write out a mimepart rather than a stream. (gpg_verify): handle changed args. * camel-cipher-context.c (camel_cipher_sign): write the signature to a mimepart rather than a simple stream. (camel_cipher_verify): take the signature as a mimepart not a stream. 2003-10-22 Not Zed <NotZed@Ximian.com> * camel-utf8.c (camel_ucs2_utf8, camel_utf8_ucs2): helpers for ucs2 stuff. ucs2 is 16 bit truncated unicode. svn path=/trunk/; revision=23127
Diffstat (limited to 'camel/camel-cipher-context.c')
-rw-r--r--camel/camel-cipher-context.c204
1 files changed, 86 insertions, 118 deletions
diff --git a/camel/camel-cipher-context.c b/camel/camel-cipher-context.c
index 717f79e37d..212c0fb98c 100644
--- a/camel/camel-cipher-context.c
+++ b/camel/camel-cipher-context.c
@@ -28,6 +28,7 @@
#include <pthread.h>
#include "camel-cipher-context.h"
+#include "camel-stream.h"
#define CIPHER_LOCK(ctx) g_mutex_lock (((CamelCipherContext *) ctx)->priv->lock)
#define CIPHER_UNLOCK(ctx) g_mutex_unlock (((CamelCipherContext *) ctx)->priv->lock);
@@ -40,82 +41,8 @@ struct _CamelCipherContextPrivate {
GMutex *lock;
};
-static const char *cipher_hash_to_id (CamelCipherContext *context, CamelCipherHash hash);
-static CamelCipherHash cipher_id_to_hash (CamelCipherContext *context, const char *id);
-
-static int cipher_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
- CamelStream *istream, CamelStream *ostream, CamelException *ex);
-static CamelCipherValidity *cipher_verify (CamelCipherContext *context, CamelCipherHash hash,
- CamelStream *istream, CamelStream *sigstream,
- CamelException *ex);
-static int cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *userid,
- GPtrArray *recipients, CamelStream *istream,
- CamelStream *ostream, CamelException *ex);
-static int cipher_decrypt (CamelCipherContext *context, CamelStream *istream,
- CamelStream *ostream, CamelException *ex);
-static int cipher_import_keys (CamelCipherContext *context, CamelStream *istream,
- CamelException *ex);
-static int cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
- CamelStream *ostream, CamelException *ex);
-
-
static CamelObjectClass *parent_class = NULL;
-
-static void
-camel_cipher_context_init (CamelCipherContext *context)
-{
- context->priv = g_new0 (struct _CamelCipherContextPrivate, 1);
- context->priv->lock = g_mutex_new ();
-}
-
-static void
-camel_cipher_context_finalise (CamelObject *o)
-{
- CamelCipherContext *context = (CamelCipherContext *)o;
-
- camel_object_unref (context->session);
-
- g_mutex_free (context->priv->lock);
-
- g_free (context->priv);
-}
-
-static void
-camel_cipher_context_class_init (CamelCipherContextClass *camel_cipher_context_class)
-{
- parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
-
- camel_cipher_context_class->hash_to_id = cipher_hash_to_id;
- camel_cipher_context_class->id_to_hash = cipher_id_to_hash;
- camel_cipher_context_class->sign = cipher_sign;
- camel_cipher_context_class->verify = cipher_verify;
- camel_cipher_context_class->encrypt = cipher_encrypt;
- camel_cipher_context_class->decrypt = cipher_decrypt;
- camel_cipher_context_class->import_keys = cipher_import_keys;
- camel_cipher_context_class->export_keys = cipher_export_keys;
-}
-
-CamelType
-camel_cipher_context_get_type (void)
-{
- static CamelType type = CAMEL_INVALID_TYPE;
-
- if (type == CAMEL_INVALID_TYPE) {
- type = camel_type_register (camel_object_get_type (),
- "CamelCipherContext",
- sizeof (CamelCipherContext),
- sizeof (CamelCipherContextClass),
- (CamelObjectClassInitFunc) camel_cipher_context_class_init,
- NULL,
- (CamelObjectInitFunc) camel_cipher_context_init,
- (CamelObjectFinalizeFunc) camel_cipher_context_finalise);
- }
-
- return type;
-}
-
-
/**
* camel_cipher_context_new:
* @session: CamelSession
@@ -140,7 +67,6 @@ camel_cipher_context_new (CamelSession *session)
return context;
}
-
/**
* camel_cipher_context_construct:
* @context: CamelCipherContext
@@ -158,10 +84,9 @@ camel_cipher_context_construct (CamelCipherContext *context, CamelSession *sessi
context->session = session;
}
-
static int
cipher_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash,
- CamelStream *istream, CamelStream *ostream, CamelException *ex)
+ struct _CamelStream *istream, struct _CamelMimePart *sigpart, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Signing is not supported by this cipher"));
@@ -174,16 +99,16 @@ cipher_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash,
* @userid: private key to use to sign the stream
* @hash: preferred Message-Integrity-Check hash algorithm
* @istream: input stream
- * @ostream: output stream
+ * @sigpart: output signature part.
* @ex: exception
*
- * Signs the input stream and writes the resulting signature to the output stream.
+ * Signs the input stream and writes the resulting signature to output @sigpart.
*
* Return value: 0 for success or -1 for failure.
**/
int
camel_cipher_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
- CamelStream *istream, CamelStream *ostream, CamelException *ex)
+ struct _CamelStream *istream, struct _CamelMimePart *sigpart, CamelException *ex)
{
int retval;
@@ -191,24 +116,22 @@ camel_cipher_sign (CamelCipherContext *context, const char *userid, CamelCipherH
CIPHER_LOCK(context);
- retval = CCC_CLASS (context)->sign (context, userid, hash, istream, ostream, ex);
+ retval = CCC_CLASS (context)->sign (context, userid, hash, istream, sigpart, ex);
CIPHER_UNLOCK(context);
return retval;
}
-
static CamelCipherValidity *
-cipher_verify (CamelCipherContext *context, CamelCipherHash hash, CamelStream *istream,
- CamelStream *sigstream, CamelException *ex)
+cipher_verify (CamelCipherContext *context, CamelCipherHash hash, struct _CamelStream *istream,
+ struct _CamelMimePart *sigpart, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Verifying is not supported by this cipher"));
return NULL;
}
-
/**
* camel_cipher_verify:
* @context: Cipher Context
@@ -226,8 +149,8 @@ cipher_verify (CamelCipherContext *context, CamelCipherHash hash, CamelStream *i
* execute at all.
**/
CamelCipherValidity *
-camel_cipher_verify (CamelCipherContext *context, CamelCipherHash hash, CamelStream *istream,
- CamelStream *sigstream, CamelException *ex)
+camel_cipher_verify (CamelCipherContext *context, CamelCipherHash hash, struct _CamelStream *istream,
+ struct _CamelMimePart *sigpart, CamelException *ex)
{
CamelCipherValidity *valid;
@@ -235,17 +158,16 @@ camel_cipher_verify (CamelCipherContext *context, CamelCipherHash hash, CamelStr
CIPHER_LOCK(context);
- valid = CCC_CLASS (context)->verify (context, hash, istream, sigstream, ex);
+ valid = CCC_CLASS (context)->verify (context, hash, istream, sigpart, ex);
CIPHER_UNLOCK(context);
return valid;
}
-
static int
-cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *userid, GPtrArray *recipients,
- CamelStream *istream, CamelStream *ostream, CamelException *ex)
+cipher_encrypt (CamelCipherContext *context, const char *userid, GPtrArray *recipients,
+ struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Encryption is not supported by this cipher"));
@@ -255,8 +177,7 @@ cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *userid,
/**
* camel_cipher_encrypt:
* @context: Cipher Context
- * @sign: sign as well as encrypt
- * @userid: key id (or email address) to use when signing (assuming @sign is %TRUE)
+ * @userid: key id (or email address) to use when signing, or NULL to not sign.
* @recipients: an array of recipient key ids and/or email addresses
* @istream: cleartext input stream
* @ostream: ciphertext output stream
@@ -268,8 +189,8 @@ cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *userid,
* Return value: 0 for success or -1 for failure.
**/
int
-camel_cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *userid, GPtrArray *recipients,
- CamelStream *istream, CamelStream *ostream, CamelException *ex)
+camel_cipher_encrypt (CamelCipherContext *context, const char *userid, GPtrArray *recipients,
+ struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
{
int retval;
@@ -277,21 +198,19 @@ camel_cipher_encrypt (CamelCipherContext *context, gboolean sign, const char *us
CIPHER_LOCK(context);
- retval = CCC_CLASS (context)->encrypt (context, sign, userid, recipients, istream, ostream, ex);
+ retval = CCC_CLASS (context)->encrypt (context, userid, recipients, ipart, opart, ex);
CIPHER_UNLOCK(context);
return retval;
}
-
-static int
-cipher_decrypt (CamelCipherContext *context, CamelStream *istream,
- CamelStream *ostream, CamelException *ex)
+static struct _CamelMimePart *
+cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Decryption is not supported by this cipher"));
- return -1;
+ return NULL;
}
/**
@@ -306,26 +225,24 @@ cipher_decrypt (CamelCipherContext *context, CamelStream *istream,
*
* Return value: 0 for success or -1 for failure.
**/
-int
-camel_cipher_decrypt (CamelCipherContext *context, CamelStream *istream,
- CamelStream *ostream, CamelException *ex)
+struct _CamelMimePart *
+camel_cipher_decrypt (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex)
{
- int retval;
-
- g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
+ struct _CamelMimePart *opart;
+
+ g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
CIPHER_LOCK(context);
- retval = CCC_CLASS (context)->decrypt (context, istream, ostream, ex);
+ opart = CCC_CLASS (context)->decrypt (context, ipart, ex);
CIPHER_UNLOCK(context);
- return retval;
+ return opart;
}
-
static int
-cipher_import_keys (CamelCipherContext *context, CamelStream *istream, CamelException *ex)
+cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("You may not import keys with this cipher"));
@@ -333,7 +250,6 @@ cipher_import_keys (CamelCipherContext *context, CamelStream *istream, CamelExce
return -1;
}
-
/**
* camel_cipher_import_keys:
* @ctx: Cipher Context
@@ -346,7 +262,7 @@ cipher_import_keys (CamelCipherContext *context, CamelStream *istream, CamelExce
* Returns 0 on success or -1 on fail.
**/
int
-camel_cipher_import_keys (CamelCipherContext *context, CamelStream *istream, CamelException *ex)
+camel_cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream, CamelException *ex)
{
g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
g_return_val_if_fail (CAMEL_IS_STREAM (istream), -1);
@@ -354,10 +270,9 @@ camel_cipher_import_keys (CamelCipherContext *context, CamelStream *istream, Cam
return CCC_CLASS (context)->import_keys (context, istream, ex);
}
-
static int
cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
- CamelStream *ostream, CamelException *ex)
+ struct _CamelStream *ostream, CamelException *ex)
{
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("You may not export keys with this cipher"));
@@ -365,7 +280,6 @@ cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
return -1;
}
-
/**
* camel_cipher_export_keys:
* @ctx: Cipher Context
@@ -380,7 +294,7 @@ cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
**/
int
camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
- CamelStream *ostream, CamelException *ex)
+ struct _CamelStream *ostream, CamelException *ex)
{
g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
g_return_val_if_fail (CAMEL_IS_STREAM (ostream), -1);
@@ -389,7 +303,6 @@ camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
return CCC_CLASS (context)->export_keys (context, keys, ostream, ex);
}
-
static CamelCipherHash
cipher_id_to_hash(CamelCipherContext *context, const char *id)
{
@@ -500,3 +413,58 @@ camel_cipher_validity_free (CamelCipherValidity *validity)
g_free (validity->description);
g_free (validity);
}
+
+/* ********************************************************************** */
+
+static void
+camel_cipher_context_init (CamelCipherContext *context)
+{
+ context->priv = g_new0 (struct _CamelCipherContextPrivate, 1);
+ context->priv->lock = g_mutex_new ();
+}
+
+static void
+camel_cipher_context_finalise (CamelObject *o)
+{
+ CamelCipherContext *context = (CamelCipherContext *)o;
+
+ camel_object_unref (CAMEL_OBJECT (context->session));
+
+ g_mutex_free (context->priv->lock);
+
+ g_free (context->priv);
+}
+
+static void
+camel_cipher_context_class_init (CamelCipherContextClass *camel_cipher_context_class)
+{
+ parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
+
+ camel_cipher_context_class->hash_to_id = cipher_hash_to_id;
+ camel_cipher_context_class->id_to_hash = cipher_id_to_hash;
+ camel_cipher_context_class->sign = cipher_sign;
+ camel_cipher_context_class->verify = cipher_verify;
+ camel_cipher_context_class->encrypt = cipher_encrypt;
+ camel_cipher_context_class->decrypt = cipher_decrypt;
+ camel_cipher_context_class->import_keys = cipher_import_keys;
+ camel_cipher_context_class->export_keys = cipher_export_keys;
+}
+
+CamelType
+camel_cipher_context_get_type (void)
+{
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (type == CAMEL_INVALID_TYPE) {
+ type = camel_type_register (camel_object_get_type (),
+ "CamelCipherContext",
+ sizeof (CamelCipherContext),
+ sizeof (CamelCipherContextClass),
+ (CamelObjectClassInitFunc) camel_cipher_context_class_init,
+ NULL,
+ (CamelObjectInitFunc) camel_cipher_context_init,
+ (CamelObjectFinalizeFunc) camel_cipher_context_finalise);
+ }
+
+ return type;
+}