aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-cipher-context.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-11-01 08:45:05 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-11-01 08:45:05 +0800
commit8ae8cb35257f42c905c86eb424759fdfde97eb41 (patch)
treef4d109c4352dc18263b35b396164e1cedb98fcee /camel/camel-cipher-context.c
parentcfe440f26dada9764f9551771977e5fc76e8d692 (diff)
downloadgsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar.gz
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar.bz2
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar.lz
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar.xz
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.tar.zst
gsoc2013-evolution-8ae8cb35257f42c905c86eb424759fdfde97eb41.zip
Set the virtual method pointers to the import/export methods.
2002-10-31 Jeffrey Stedfast <fejj@ximian.com> * camel-gpg-context.c (camel_gpg_context_class_init): Set the virtual method pointers to the import/export methods. (camel_gpg_context_init): Set the key_protocol string. (gpg_hash_to_id): Handle 2 more hash types. (gpg_id_to_hash): Same. (gpg_ctx_op_step): Slight fixes to support import/export. (gpg_ctx_parse_status): Fix to hack around the fact that importing keys doesn't write to stdout. (gpg_import_keys): Implemented. (gpg_export_keys): Implemented. * camel-cipher-context.c (camel_cipher_context_class_init): Hook up default virtual methods for import/export. (camel_cipher_import_keys): Implemented. (camel_cipher_export_keys): Implemented. svn path=/trunk/; revision=18475
Diffstat (limited to 'camel/camel-cipher-context.c')
-rw-r--r--camel/camel-cipher-context.c101
1 files changed, 88 insertions, 13 deletions
diff --git a/camel/camel-cipher-context.c b/camel/camel-cipher-context.c
index 185002831f..c495a6479c 100644
--- a/camel/camel-cipher-context.c
+++ b/camel/camel-cipher-context.c
@@ -47,22 +47,28 @@ struct _CamelCipherContextPrivate {
#endif
};
-static int cipher_sign (CamelCipherContext *ctx, 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 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 const char *cipher_hash_to_id(CamelCipherContext *context, CamelCipherHash hash);
-static CamelCipherHash cipher_id_to_hash(CamelCipherContext *context, const char *id);
static CamelObjectClass *parent_class;
+
static void
camel_cipher_context_init (CamelCipherContext *context)
{
@@ -91,12 +97,14 @@ camel_cipher_context_class_init (CamelCipherContextClass *camel_cipher_context_c
{
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->hash_to_id = cipher_hash_to_id;
- camel_cipher_context_class->id_to_hash = cipher_id_to_hash;
+ camel_cipher_context_class->import_keys = cipher_import_keys;
+ camel_cipher_context_class->export_keys = cipher_export_keys;
}
CamelType
@@ -326,6 +334,73 @@ camel_cipher_decrypt (CamelCipherContext *context, CamelStream *istream,
return retval;
}
+
+static int
+cipher_import_keys (CamelCipherContext *context, CamelStream *istream, CamelException *ex)
+{
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("You may not import keys with this cipher"));
+
+ return -1;
+}
+
+
+/**
+ * camel_cipher_import_keys:
+ * @ctx: Cipher Context
+ * @istream: input stream (containing keys)
+ * @ex: exception
+ *
+ * Imports a stream of keys/certificates contained within @istream
+ * into the key/certificate database controlled by @ctx.
+ *
+ * Returns 0 on success or -1 on fail.
+ **/
+int
+camel_cipher_import_keys (CamelCipherContext *context, 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);
+
+ return CCC_CLASS (context)->import_keys (context, istream, ex);
+}
+
+
+static int
+cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
+ CamelStream *ostream, CamelException *ex)
+{
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("You may not export keys with this cipher"));
+
+ return -1;
+}
+
+
+/**
+ * camel_cipher_export_keys:
+ * @ctx: Cipher Context
+ * @keys: an array of key ids
+ * @ostream: output stream
+ * @ex: exception
+ *
+ * Exports the keys/certificates in @keys to the stream @ostream from
+ * the key/certificate database controlled by @ctx.
+ *
+ * Returns 0 on success or -1 on fail.
+ **/
+int
+camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
+ 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);
+ g_return_val_if_fail (keys != NULL, -1);
+
+ return CCC_CLASS (context)->export_keys (context, keys, ostream, ex);
+}
+
+
static CamelCipherHash
cipher_id_to_hash(CamelCipherContext *context, const char *id)
{
@@ -337,8 +412,8 @@ CamelCipherHash
camel_cipher_id_to_hash(CamelCipherContext *context, const char *id)
{
g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), CAMEL_CIPHER_HASH_DEFAULT);
-
- return ((CamelCipherContextClass *)((CamelObject *)context)->klass)->id_to_hash(context, id);
+
+ return CCC_CLASS (context)->id_to_hash (context, id);
}
static const char *
@@ -351,8 +426,8 @@ const char *
camel_cipher_hash_to_id(CamelCipherContext *context, CamelCipherHash hash)
{
g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
-
- return ((CamelCipherContextClass *)((CamelObject *)context)->klass)->hash_to_id(context, hash);
+
+ return CCC_CLASS (context)->hash_to_id (context, hash);
}
/* Cipher Validity stuff */