Noteworthy changes in version 0.4.0 (unreleased)
------------------------------------------------
+ * New data object interface, which is more flexible and transparent.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+GpgmeDataReadCb NEW
+GpgmeDataWriteCb NEW
+GpgmeDataSeekCb NEW
+GpgmeDataReleaseCb NEW
+GpgmeDataCbs NEW
+gpgme_data_read CHANGED: Match read() closely.
+gpgme_data_write CHANGED: Match write() closely.
+gpgme_data_seek NEW
+gpgme_data_from_fd NEW
+gpgme_data_from_stream NEW
+gpgme_data_from_cbs NEW
+gpgme_data_rewind DEPRECATED: Replaced by gpgme_data_seek().
+gpgme_data_new_from_read_cb DEPRECATED: Replaced by gpgme_data_from_cbs().
+gpgme_data_get_type REMOVED: No replacement.
+gpgme_op_verify CHANGED: Take different data objects for
+ signed text and plain text.
+gpgme_op_verify_start CHANGED: See gpgme_op_verify.
+gpgme_check_engine REMOVED: Deprecated since 0.3.0.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Noteworthy changes in version 0.3.11 (2002-09-20)
-------------------------------------------------
** validity/trust
* Engines
+** Optimize the case where a data object has an underlying fd we can pass
+ directly to the engine.
** Move code common to all engines up from gpg to engine.
** engine operations can return General Error on unknown protocol
(it's an internal error, as select_protocol checks already).
* Operations
** Passphrase callback should not copy password. !!!
-** Export status handler need much more work.
+** Export status handler need much more work. !!!
** Import should return a useful error when one happened.
** Genkey should return something more useful than General_Error.
** Factor out common code in _op_*_start functions.
+2002-10-08 Marcus Brinkmann <marcus@g10code.de>
+
+ New data object component:
+
+ * gpgme.h (GpgmeDataReadCb, GpgmeDataWriteCb, GpgmeDataSeekCb,
+ GpgmeDataReleaseCb): New types.
+ (struct GpgmeDataCbs): New structure.
+ (gpgme_data_read): Changed prototype to match that of read() closely.
+ (gpgme_data_write): Similar for write().
+ (gpgme_data_seek, gpgme_data_new_from_cbs, gpgme_data_new_from_fd,
+ gpgme_data_new_from_stream): New prototypes.
+ (gpgme_data_get_type, gpgme_check_engine): Prototype removed.
+
+ * Makefile.am (libgpgme_la_SOURCES): Add data.h, data-fd.c,
+ data-stream.c, data-mem.c, data-user.c and data-compat.c.
+ * data.c: Reimplemented from scratch.
+ * (data-compat.c, data-fd.c, data.h, data-mem.c, data-stream.c,
+ data-user.c): New file.
+ * context.h (struct gpgme_data_s): Removed.
+ * conversion.c: Include <errno.h> and <sys/types.h>.
+ (_gpgme_data_append): New function.
+ * data.c (_gpgme_data_append_string): Move to ...
+ * conversion.c (_gpgme_data_append_string): ... here.
+ * data.c (_gpgme_data_append_for_xml): Move to ...
+ * conversion.c (_gpgme_data_append_for_xml): ... here.
+ * data.c (_gpgme_data_append_string_for_xml): Move to ...
+ * conversion.c (_gpgme_data_append_string_for_xml): ... here.
+ * data.c (_gpgme_data_append_percentstring_for_xml): Move to ...
+ * conversion.c (_gpgme_data_append_percentstring_for_xml): ... here.
+
+ * ops.h (_gpgme_data_get_mode, _gpgme_data_set_mode): Prototype
+ removed.
+ * types.h (GpgmeDataMode): Type removed.
+
+ * decrypt.c (_gpgme_decrypt_start): Don't check data type or mode.
+ * edit.c (_gpgme_op_edit_start): Likewise.
+ * encrypt.c (_gpgme_op_encrypt_start): Likewise.
+ * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise.
+ * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise.
+ * export.c (_gpgme_op_export_start): Likewise.
+ * genkey.c (_gpgme_op_genkey_start): Likewise.
+ * import.c (_gpgme_op_import_start): Likewise.
+ * sign.c (_gpgme_op_sign_start): Likewise.
+ * verify.c (_gpgme_op_verify_start): Likewise.
+
+ * encrypt.c (gpgme_op_encrypt): Remove hack that returns invalid
+ no recipient if no data was returned.
+ * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns
+ no recipient if no data was returned.
+ * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns
+ no recipient if no data was returned.
+
+ * engine.c (_gpgme_engine_op_verify): Add new argument to
+ differentiate detached from normal signatures.
+ * engine.h (_gpgme_engine_op_verify): Likewise for prototype.
+ * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Likewise. Don't check
+ mode of data argument.
+ * engine-gpgsm.h (_gpgme_gpgsm_op_verify): Likewise for prototype.
+ * gpgme.h (gpgme_op_verify_start): Likewise for prototype.
+ (gpgme_op_verify): Likewise for prototype.
+ * rungpg.c (_gpgme_gpg_op_verify): Likewise.
+ * rungpg.h (_gpgme_gpg_op_verify): Likewise for prototype.
+ * verify.c (_gpgme_op_verify_start): Likewise.
+ (gpgme_op_verify_start): Likewise.
+ (gpgme_op_verify): Likewise.
+
+ * rungpg.c (struct arg_and_data_s): New member INBOUND to hold
+ direction of data object.
+ (_gpgme_gpg_add_data): Add new argument INBOUND. Use it to
+ determine direction of data object.
+ (_gpgme_gpg_add_pm_data, _gpgme_gpg_set_command_handler,
+ _gpgme_gpg_op_decrypt, _gpgme_gpg_op_edit, _gpgme_gpg_op_encrypt,
+ _gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export,
+ _gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_sign,
+ _gpgme_gpg_op_verify): Add new argument to _gpgme_gpg_add_data
+ invocation.
+ (build_argv): Use new member INBOUND to determine direction of
+ file descriptor. Don't check the data type.
+ * rungpg.h (_gpgme_gpg_add_data): Add new argument to prototype.
+
+ * gpgme.c (gpgme_get_op_info): Don't call
+ _gpgme_data_get_as_string if CTX->op_info is NULL.
+
+ * version.c (gpgme_check_engine): Function removed.
+
2002-09-30 Werner Koch <wk@gnupg.org>
* keylist.c (keylist_colon_handler): Take care when printing a
libgpgme_la_SOURCES = \
gpgme.h types.h util.h util.c conversion.c context.h ops.h \
- data.c recipient.c signers.c wait.c wait.h op-support.c \
+ data.h data.c data-fd.c data-stream.c data-mem.c data-user.c \
+ data-compat.c \
+ recipient.c signers.c wait.c wait.h op-support.c \
encrypt.c encrypt-sign.c decrypt.c decrypt-verify.c verify.c \
sign.c passphrase.c progress.c \
key.h key.c keylist.c trustlist.c \
-/* context.h
+/* context.h
* Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001, 2002 g10 Code GmbH
*
};
-/* Currently we need it at several places, so we put the definition
- * into this header file */
+/* Currently we need it at several places, so we put the definition
+ into this header file. */
struct gpgme_context_s
{
int initialized;
- /* A gpg request is still pending. */
+ /* An engine request is still pending. */
int pending;
int use_cms;
GpgmeData help_data_1;
};
-
-struct gpgme_data_s {
- size_t len;
- const char *data;
- GpgmeDataType type;
- GpgmeDataMode mode;
- GpgmeDataEncoding encoding;
-
- int (*read_cb)( void *, char *, size_t, size_t *);
- void *read_cb_value;
- int read_cb_eof;
-
- size_t readpos;
- size_t writepos;
- size_t private_len;
- char *private_buffer;
-};
-
/* Forward declaration of a structure to store certification
- signatures. */
+ signatures. */
struct certsig_s;
-/* Structure to store user IDs. */
-struct user_id_s {
- struct user_id_s *next;
- unsigned int revoked:1;
- unsigned int invalid:1;
- GpgmeValidity validity;
- struct certsig_s *certsigs;
- const char *name_part; /* all 3 point into strings behind name */
- const char *email_part; /* or to read-only strings */
- const char *comment_part;
- char name[1];
+/* Structure to store user IDs. */
+struct user_id_s
+{
+ struct user_id_s *next;
+ unsigned int revoked : 1;
+ unsigned int invalid : 1;
+ GpgmeValidity validity;
+ struct certsig_s *certsigs;
+ const char *name_part; /* All 3 point into strings behind name */
+ const char *email_part; /* or to read-only strings. */
+ const char *comment_part;
+ char name[1];
};
-struct gpgme_recipients_s {
- struct user_id_s *list;
- int checked; /* wether the recipients are all valid */
+
+struct gpgme_recipients_s
+{
+ struct user_id_s *list;
+ int checked; /* Wether the recipients are all valid. */
};
gpgme_wait ((c), 1); \
} while (0)
-#endif /* CONTEXT_H */
+#endif /* CONTEXT_H */
#endif
#include <string.h>
+#include <errno.h>
#include <ctype.h>
+#include <sys/types.h>
+
#include "gpgme.h"
#include "util.h"
return 0;
}
+
+\f
+GpgmeError
+_gpgme_data_append (GpgmeData dh, const char *buffer, size_t length)
+{
+ if (!dh || !buffer)
+ return mk_error (Invalid_Value);
+
+ do
+ {
+ ssize_t amt = gpgme_data_write (dh, buffer, length);
+ if (amt == 0 || (amt < 0 && errno != EINTR))
+ return mk_error (File_Error);
+ buffer += amt;
+ length -= amt;
+ }
+ while (length > 0);
+
+ return 0;
+}
+
+
+GpgmeError
+_gpgme_data_append_string (GpgmeData dh, const char *str)
+{
+ if (!str)
+ return 0;
+
+ return _gpgme_data_append (dh, str, strlen (str));
+}
+
+
+GpgmeError
+_gpgme_data_append_for_xml (GpgmeData dh, const char *buffer, size_t len)
+{
+ const char *text, *str;
+ size_t count;
+ int err = 0;
+
+ if (!dh || !buffer)
+ return mk_error (Invalid_Value);
+
+ do
+ {
+ text = NULL;
+ str = buffer;
+ for (count = len; count && !text; str++, count--)
+ {
+ if (*str == '<')
+ text = "<";
+ else if (*str == '>')
+ text = ">"; /* Not sure whether this is really needed. */
+ else if (*str == '&')
+ text = "&";
+ else if (!*str)
+ text = "�";
+ }
+ if (text)
+ {
+ str--;
+ count++;
+ }
+ if (str != buffer)
+ err = _gpgme_data_append (dh, buffer, str - buffer);
+ if (!err && text)
+ {
+ err = _gpgme_data_append_string (dh, text);
+ str++;
+ count--;
+ }
+ buffer = str;
+ len = count;
+ }
+ while (!err && len);
+ return err;
+}
+
+
+/* Append a string to DATA and convert it so that the result will be
+ valid XML. */
+GpgmeError
+_gpgme_data_append_string_for_xml (GpgmeData dh, const char *str)
+{
+ return _gpgme_data_append_for_xml (dh, str, strlen (str));
+}
+
+
+/* Append a string with percent style (%XX) escape characters as
+ XML. */
+GpgmeError
+_gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *str)
+{
+ const byte *src;
+ byte *buf, *dst;
+ int val;
+ GpgmeError err;
+
+ buf = xtrymalloc (strlen (str));
+ dst = buf;
+ for (src = str; *src; src++)
+ {
+ if (*src == '%' && (val = _gpgme_hextobyte (src + 1)) != -1)
+ {
+ *dst++ = val;
+ src += 2;
+ }
+ else
+ *dst++ = *src;
+ }
+
+ err = _gpgme_data_append_for_xml (dh, buf, dst - buf);
+ xfree (buf);
+ return err;
+}
-/* data.c
- * Copyright (C) 2000 Werner Koch (dd9jn)
- * Copyright (C) 2001, 2002 g10 Code GmbH
- *
- * This file is part of GPGME.
- *
- * GPGME is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GPGME is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
+/* data.c - An abstraction for data objects.
+ Copyright (C) 2002 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GPGME is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GPGME; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */
+
+#if HAVE_CONFIG_H
#include <config.h>
-#include <stdio.h>
+#endif
+
#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
+#include <unistd.h>
#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <string.h>
+#include "data.h"
#include "util.h"
-#include "context.h"
#include "ops.h"
#include "io.h"
-/* When expanding an internal buffer, always extend it by ALLOC_CHUNK
- bytes at a time. */
-#define ALLOC_CHUNK 1024
-
-
-/**
- * gpgme_data_new:
- * @r_dh: returns the new data object
- *
- * Create a new data object without any content.
- *
- * Return value: An error value or 0 on success
- **/
+\f
GpgmeError
-gpgme_data_new (GpgmeData *r_dh)
+_gpgme_data_new (GpgmeData *r_dh, struct gpgme_data_cbs *cbs)
{
GpgmeData dh;
if (!r_dh)
return mk_error (Invalid_Value);
- *r_dh = NULL;
- dh = xtrycalloc (1, sizeof *dh);
+ *r_dh = NULL;
+ dh = xtrycalloc (1, sizeof (*dh));
if (!dh)
return mk_error (Out_Of_Core);
- dh->mode = GPGME_DATA_MODE_INOUT;
-
- *r_dh = dh;
- return 0;
-}
-
-
-/**
- * gpgme_data_new_from_mem:
- * @r_dh: Returns a new data object.
- * @buffer: Initialize with this.
- * @size: Size of the buffer
- * @copy: Flag wether a copy of the buffer should be used.
- *
- * Create a new data object and initialize with data from the memory.
- * A @copy with value %TRUE creates a copy of the memory, a value of
- * %FALSE uses the original memory of @buffer and the caller has to
- * make sure that this buffer is valid until gpgme_data_release() is
- * called.
- *
- * Return value: An error value or 0 for success.
- **/
-GpgmeError
-gpgme_data_new_from_mem (GpgmeData *r_dh, const char *buffer, size_t size,
- int copy)
-{
- GpgmeData dh;
- GpgmeError err;
-
- if (!r_dh)
- return mk_error (Invalid_Value);
- *r_dh = NULL;
- if (!buffer)
- return mk_error (Invalid_Value);
-
- err = gpgme_data_new (&dh);
- if (err)
- return err;
-
- dh->type = GPGME_DATA_TYPE_MEM;
- dh->len = size;
- if (!copy)
- dh->data = buffer;
- else
- {
- dh->private_buffer = xtrymalloc (size);
- if (!dh->private_buffer)
- {
- gpgme_data_release (dh);
- return mk_error (Out_Of_Core);
- }
- dh->private_len = size;
- memcpy (dh->private_buffer, buffer, size);
- dh->data = dh->private_buffer;
- dh->writepos = size;
- }
+ dh->cbs = cbs;
*r_dh = dh;
return 0;
}
-/**
- * gpgme_data_new_with_read_cb:
- * @r_dh: returns the new data object
- * @read_cb: callback function
- * @read_cb_value: value passed to the callback function
- *
- * Create a new data object which is a wrapper around the callback function.
- * The callback function is defined as:
- * <literal>
- * typedef int (*read_cb) (void *cb_value,
- * char *buffer,
- * size_t count,
- * size_t *nread);
- * </literal>
- *
- * The callback should return a maximium of @count bytes in @buffer
- * and the number actually read in @nread. It may return 0 in @nread
- * if there are no bytes currently available. To indicate EOF the
- * function should return with an error code of %-1 and set @nread to
- * 0. The callback may support passing %NULL for @buffer and @nread
- * and %0 for count as an indication to reset its internal read
- * pointer.
- *
- * Return value: An error value or 0 for success.
- **/
-GpgmeError
-gpgme_data_new_with_read_cb (GpgmeData *r_dh,
- int (*read_cb) (void *,char *, size_t ,size_t *),
- void *read_cb_value)
+void
+_gpgme_data_release (GpgmeData dh)
{
- GpgmeData dh;
- GpgmeError err;
-
- if (!r_dh)
- return mk_error (Invalid_Value);
- *r_dh = NULL;
-
- if (!read_cb)
- return mk_error (Invalid_Value);
-
- err = gpgme_data_new (&dh);
- if (err)
- return err;
-
- dh->type = GPGME_DATA_TYPE_CB;
- dh->mode = GPGME_DATA_MODE_OUT;
- dh->read_cb = read_cb;
- dh->read_cb_value = read_cb_value;
-
- *r_dh = dh;
- return 0;
+ if (dh)
+ xfree (dh);
}
-
-/**
- * gpgme_data_new_from_file:
- * @r_dh: returns the new data object
- * @fname: filename
- * @copy: Flag, whether the file should be copied.
- *
- * Create a new data object and initialize it with the content of
- * the file @file. If @copy is %True the file is immediately read in
- * and closed. @copy of %False is not yet supportted.
- *
- * Return value: An error code or 0 on success. If the error code is
- * %GPGME_File_Error, the OS error code is held in %errno.
- **/
-GpgmeError
-gpgme_data_new_from_file (GpgmeData *r_dh, const char *fname, int copy)
+\f
+/* Read up to SIZE bytes into buffer BUFFER from the data object with
+ the handle DH. Return the number of characters read, 0 on EOF and
+ -1 on error. If an error occurs, errno is set. */
+int
+gpgme_data_read (GpgmeData dh, void *buffer, size_t size)
{
- GpgmeData dh;
- GpgmeError err;
- struct stat st;
- FILE *fp;
-
- if (!r_dh)
- return mk_error (Invalid_Value);
- *r_dh = NULL;
- if (!fname)
- return mk_error (Invalid_Value);
-
- /* We only support copy for now. In future we might want to honor
- the copy flag and just store a file pointer. */
- if (!copy)
- return mk_error (Not_Implemented);
-
- err = gpgme_data_new (&dh);
- if (err)
- return err;
-
- fp = fopen (fname, "rb");
- if (!fp)
- {
- int save_errno = errno;
- gpgme_data_release (dh);
- errno = save_errno;
- return mk_error (File_Error);
- }
-
- if (fstat(fileno(fp), &st))
- {
- int save_errno = errno;
- fclose (fp);
- gpgme_data_release (dh);
- errno = save_errno;
- return mk_error (File_Error);
- }
-
- /* We should check the length of the file and don't allow for too
- large files. */
- dh->private_buffer = xtrymalloc (st.st_size);
- if (!dh->private_buffer)
+ if (!dh)
{
- fclose (fp);
- gpgme_data_release (dh);
- return mk_error (Out_Of_Core);
+ errno = EINVAL;
+ return -1;
}
- dh->private_len = st.st_size;
-
- while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1
- && ferror (fp) && errno == EINTR);
-
- if (ferror (fp))
+ if (!dh->cbs->read)
{
- int save_errno = errno;
- fclose (fp);
- gpgme_data_release (dh);
- errno = save_errno;
- return mk_error (File_Error);
+ errno = EOPNOTSUPP;
+ return -1;
}
-
- fclose (fp);
-
- dh->type = GPGME_DATA_TYPE_MEM;
- dh->len = dh->private_len;
- dh->data = dh->private_buffer;
- dh->writepos = dh->len;
-
- *r_dh = dh;
- return 0;
+ return (*dh->cbs->read) (dh, buffer, size);
}
-/**
- * gpgme_data_new_from_filepart:
- * @r_dh: returns the new data object
- * @fname: filename
- * @fp: filepointer
- * @offset: Start reading at this offset
- * @length: Read this many bytes
- *
- * Create a new data object and initialize it with @length bytes
- * starting at @offset of @file or @fp. Either a filename or an open
- * filepointer may be given.
- *
- *
- * Return value: An error code or 0 on success. If the error code is
- * %GPGME_File_Error, the OS error code is held in %errno.
- **/
-GpgmeError
-gpgme_data_new_from_filepart (GpgmeData *r_dh, const char *fname, FILE *fp,
- off_t offset, size_t length)
+/* Write up to SIZE bytes from buffer BUFFER to the data object with
+ the handle DH. Return the number of characters written, or -1 on
+ error. If an error occurs, errno is set. */
+ssize_t
+gpgme_data_write (GpgmeData dh, const void *buffer, size_t size)
{
- GpgmeData dh;
- GpgmeError err;
- int save_errno = 0;
-
- if (!r_dh)
- return mk_error (Invalid_Value);
- *r_dh = NULL;
-
- if ((fname && fp) || (!fname && !fp))
- return mk_error (Invalid_Value);
-
- err = gpgme_data_new (&dh);
- if (err)
- return err;
-
- if (!length)
- goto out;
-
- if (fname)
- {
- fp = fopen (fname, "rb");
- if (!fp)
- {
- err = mk_error (File_Error);
- goto out;
- }
- }
-
- if (fseek (fp, (long) offset, SEEK_SET))
- {
- err = mk_error (File_Error);
- goto out;
- }
-
- dh->private_buffer = xtrymalloc (length);
- if (!dh->private_buffer)
+ if (!dh)
{
- err = mk_error (Out_Of_Core);
- goto out;
+ errno = EINVAL;
+ return -1;
}
- dh->private_len = length;
-
- while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1
- && ferror (fp) && errno == EINTR);
-
- if (ferror (fp))
+ if (!dh->cbs->write)
{
- err = mk_error (File_Error);
- goto out;
+ errno = EOPNOTSUPP;
+ return -1;
}
-
- dh->type = GPGME_DATA_TYPE_MEM;
- dh->len = dh->private_len;
- dh->data = dh->private_buffer;
- dh->writepos = dh->len;
-
- out:
- if (err)
- save_errno = errno;
-
- if (fname && fp)
- fclose (fp);
-
- if (err)
- {
- gpgme_data_release (dh);
- errno = save_errno;
- }
- else
- *r_dh = dh;
- return err;
+ return (*dh->cbs->write) (dh, buffer, size);
}
-/**
- * gpgme_data_release:
- * @dh: Data object
- *
- * Release the data object @dh. @dh may be NULL in which case nothing
- * happens.
- **/
-void
-gpgme_data_release (GpgmeData dh)
+/* Set the current position from where the next read or write starts
+ in the data object with the handle DH to OFFSET, relativ to
+ WHENCE. */
+off_t
+gpgme_data_seek (GpgmeData dh, off_t offset, int whence)
{
- if (dh)
+ if (!dh)
{
- xfree (dh->private_buffer);
- xfree (dh);
+ errno = EINVAL;
+ return -1;
}
-}
-
-
-/*
- * Release the data object @dh. @dh may be NULL in which case nothing
- * happens.
- *
- * Return value: An allocated memory object with the content of the
- * data object. The function makes sure that the returned string can
- * safely be accessed using the string fucntions.
- **/
-char *
-_gpgme_data_release_and_return_string (GpgmeData dh)
-{
- char *val = NULL;
-
- if (dh)
+ if (!dh->cbs->read)
{
- if (_gpgme_data_append (dh, "", 1)) /* append EOS */
- xfree (dh->private_buffer );
- else
- {
- val = dh->private_buffer;
- if (!val && dh->data)
- {
- val = xtrymalloc (dh->len);
- if (val)
- memcpy (val, dh->data, dh->len);
- }
- }
- xfree (dh);
+ errno = EOPNOTSUPP;
+ return -1;
}
- return val;
+ return (*dh->cbs->seek) (dh, offset, whence);
}
-/**
- * gpgme_data_release_and_get_mem:
- * @dh: the data object
- * @r_len: returns the length of the memory
- *
- * Release the data object @dh and return its content and the length
- * of that content. The caller has to free this data. @dh maybe NULL
- * in which case NULL is returned. If there is not enough memory for
- * allocating the return value, NULL is returned and the object is
- * released.
- *
- * Return value: a pointer to an allocated buffer of length @r_len.
- **/
-char *
-gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len)
+/* Release the data object with the handle DH. */
+void
+gpgme_data_release (GpgmeData dh)
{
- char *val = NULL;
+ if (!dh)
+ return;
- if (r_len)
- *r_len = 0;
- if (dh)
- {
- size_t len = dh->len;
- val = dh->private_buffer;
- if (!val && dh->data)
- {
- val = xtrymalloc (len);
- if (val)
- memcpy (val, dh->data, len);
- }
- xfree (dh);
- if (val && r_len)
- *r_len = len;
- }
- return val;
+ if (dh->cbs->release)
+ (*dh->cbs->release) (dh);
+ _gpgme_data_release (dh);
}
-/**
- * gpgme_data_get_type:
- * @dh: the data object
- *
- * Get the type of the data object.
- * Data types are prefixed with %GPGME_DATA_TYPE_
- *
- * Return value: the data type
- **/
-GpgmeDataType
-gpgme_data_get_type (GpgmeData dh)
-{
- if (!dh || (!dh->data && !dh->read_cb))
- return GPGME_DATA_TYPE_NONE;
-
- return dh->type;
-}
-
-/* Get the current encoding meta information. */
+/* Get the current encoding meta information for the data object with
+ handle DH. */
GpgmeDataEncoding
gpgme_data_get_encoding (GpgmeData dh)
{
- return dh? dh->encoding : GPGME_DATA_ENCODING_NONE;
+ return dh ? dh->encoding : GPGME_DATA_ENCODING_NONE;
}
-/* Set the encoding meta information for DB to ENC */
+
+/* Set the encoding meta information for the data object with handle
+ DH to ENC. */
GpgmeError
gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc)
{
if (!dh)
- return GPGME_Invalid_Value;
+ return mk_error (Invalid_Value);
if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR)
return GPGME_Invalid_Value;
dh->encoding = enc;
return 0;
}
-void
-_gpgme_data_set_mode (GpgmeData dh, GpgmeDataMode mode)
-{
- assert (dh);
- dh->mode = mode;
-}
-
-
-GpgmeDataMode
-_gpgme_data_get_mode (GpgmeData dh)
-{
- assert (dh);
- return dh->mode;
-}
-
-
-/**
- * gpgme_data_rewind:
- * @dh: the data object
- *
- * Prepare the data object in a way, that a gpgme_data_read() does start
- * at the beginning of the data. This has to be done for all types
- * of data objects.
- *
- * Return value: An error code or 0 on success
- **/
-GpgmeError
-gpgme_data_rewind (GpgmeData dh)
-{
- if (!dh)
- return mk_error (Invalid_Value);
-
- switch (dh->type)
- {
- case GPGME_DATA_TYPE_NONE:
- case GPGME_DATA_TYPE_MEM:
- dh->readpos = 0;
- return 0;
-
- case GPGME_DATA_TYPE_CB:
- dh->len = dh->readpos = 0;
- dh->read_cb_eof = 0;
- if (dh->read_cb (dh->read_cb_value, NULL, 0, NULL))
- return mk_error (Not_Implemented);
- return 0;
-
- default:
- return mk_error (General_Error);
- }
-}
-
-/**
- * gpgme_data_read:
- * @dh: the data object
- * @buffer: A buffer
- * @length: The length of that bufer
- * @nread: Returns the number of bytes actually read.
- *
- * Copy data from the current read position (which may be set by
- * gpgme_data_rewind()) to the supplied @buffer, max. @length bytes
- * are copied and the actual number of bytes are returned in @nread.
- * If there are no more bytes available %GPGME_EOF is returned and @nread
- * is set to 0.
- *
- * With a @buffer of NULL, the function does only return the number of
- * bytes available and does not move the read pointer. This does only
- * work for certain data types, all other will respond with an
- * %GPGME_Invalid_Type.
- *
- * Return value: An error code or 0 on success, EOF is indcated by the
- * error code GPGME_EOF.
- **/
-GpgmeError
-gpgme_data_read (GpgmeData dh, void *buffer, size_t length, size_t *nread)
-{
- size_t nbytes;
-
- if (!dh)
- return mk_error (Invalid_Value);
-
- switch (dh->type)
- {
- case GPGME_DATA_TYPE_NONE:
- *nread = 0;
- return mk_error(EOF);
- break;
-
- case GPGME_DATA_TYPE_MEM:
- nbytes = dh->len - dh->readpos;
- if (!nbytes)
- {
- *nread = 0;
- return mk_error(EOF);
- }
-
- if (!buffer)
- *nread = nbytes;
- else
- {
- if (nbytes > length)
- nbytes = length;
- memcpy (buffer, dh->data + dh->readpos, nbytes);
- *nread = nbytes;
- dh->readpos += nbytes;
- }
- return 0;
-
- case GPGME_DATA_TYPE_CB:
- if (!buffer)
- {
- *nread = 0;
- return mk_error (Invalid_Type);
- }
- nbytes = dh->len - dh->readpos;
- if (nbytes)
- {
- /* We have unread data - return this. */
- if (nbytes > length)
- nbytes = length;
- memcpy (buffer, dh->data + dh->readpos, nbytes);
- *nread = nbytes;
- dh->readpos += nbytes;
- }
- else
- {
- /* Get the data from the callback. */
- if (!dh->read_cb || dh->read_cb_eof)
- {
- *nread = 0;
- return mk_error (EOF);
- }
- if (dh->read_cb (dh->read_cb_value, buffer, length, nread))
- {
- *nread = 0;
- dh->read_cb_eof = 1;
- return mk_error (EOF);
- }
- }
- return 0;
-
- default:
- return mk_error (General_Error);
- }
-}
-
-
-GpgmeError
-_gpgme_data_unread (GpgmeData dh, const char *buffer, size_t length)
-{
- if (!dh)
- return mk_error (Invalid_Value);
-
- if (dh->type == GPGME_DATA_TYPE_MEM)
- {
- /* Check that we don't unread more than we have yet read. */
- if (dh->readpos < length)
- return mk_error (Invalid_Value);
- /* No need to use the buffer for this data type. */
- dh->readpos -= length;
- }
- else
- return mk_error (General_Error);
-
- return 0;
-}
-
-
-/*
- * This function does make sense when we know that it contains no nil chars.
- */
-char *
-_gpgme_data_get_as_string (GpgmeData dh)
-{
- char *val = NULL;
-
- if (dh)
- {
- val = xtrymalloc (dh->len+1);
- if (val)
- {
- memcpy (val, dh->data, dh->len);
- val[dh->len] = 0;
- }
- }
- return val;
-}
-
-
-/**
- * gpgme_data_write:
- * @dh: the context
- * @buffer: data to be written to the data object
- * @length: length of this data
- *
- * Write the content of @buffer to the data object @dh at the current write
- * position.
- *
- * Return value: 0 on success or an error code
- **/
-GpgmeError
-gpgme_data_write (GpgmeData dh, const void *buffer, size_t length)
-{
- if (!dh || !buffer)
- return mk_error (Invalid_Value);
-
- return _gpgme_data_append (dh, (const char *)buffer, length );
-}
-
-
-GpgmeError
-_gpgme_data_append (GpgmeData dh, const char *buffer, size_t length)
-{
- assert (dh);
-
- if (dh->type == GPGME_DATA_TYPE_NONE)
- {
- /* Convert it to a mem data type. */
- assert (!dh->private_buffer);
- dh->type = GPGME_DATA_TYPE_MEM;
- dh->private_len = length < ALLOC_CHUNK? ALLOC_CHUNK : length;
- dh->private_buffer = xtrymalloc (dh->private_len);
- if (!dh->private_buffer)
- {
- dh->private_len = 0;
- return mk_error (Out_Of_Core);
- }
- dh->writepos = 0;
- dh->data = dh->private_buffer;
- }
- else if (dh->type != GPGME_DATA_TYPE_MEM)
- return mk_error (Invalid_Type);
-
- if (dh->mode != GPGME_DATA_MODE_INOUT
- && dh->mode != GPGME_DATA_MODE_IN)
- return mk_error (Invalid_Mode);
-
- if (!dh->private_buffer)
- {
- /* We have to copy it now. */
- assert (dh->data);
- dh->private_len = dh->len+length;
- if (dh->private_len < ALLOC_CHUNK)
- dh->private_len = ALLOC_CHUNK;
- dh->private_buffer = xtrymalloc (dh->private_len);
- if (!dh->private_buffer)
- {
- dh->private_len = 0;
- return mk_error (Out_Of_Core);
- }
- memcpy (dh->private_buffer, dh->data, dh->len);
- dh->writepos = dh->len;
- dh->data = dh->private_buffer;
- }
-
- /* Allocate more memory if needed. */
- if (dh->writepos + length > dh->private_len)
- {
- char *p;
- size_t newlen = dh->private_len
- + (length < ALLOC_CHUNK? ALLOC_CHUNK : length);
- p = xtryrealloc (dh->private_buffer, newlen);
- if (!p)
- return mk_error (Out_Of_Core);
- dh->private_buffer = p;
- dh->private_len = newlen;
- dh->data = dh->private_buffer;
- assert (!(dh->writepos + length > dh->private_len));
- }
-
- memcpy (dh->private_buffer + dh->writepos, buffer, length);
- dh->writepos += length;
- dh->len += length;
-
- return 0;
-}
-
-
-GpgmeError
-_gpgme_data_append_string (GpgmeData dh, const char *s)
-{
- return _gpgme_data_append (dh, s, s ? strlen(s) : 0);
-}
-
-
-GpgmeError
-_gpgme_data_append_for_xml (GpgmeData dh,
- const char *buffer, size_t len)
-{
- const char *text, *s;
- size_t n;
- int rc = 0;
-
- if (!dh || !buffer)
- return mk_error (Invalid_Value);
-
- do
- {
- for (text=NULL, s = buffer, n = len; n && !text; s++, n--)
- {
- if (*s == '<')
- text = "<";
- else if (*s == '>')
- text = ">"; /* Not sure whether this is really needed. */
- else if (*s == '&')
- text = "&";
- else if (!*s)
- text = "�";
- }
- if (text)
- {
- s--;
- n++;
- }
- if (s != buffer)
- rc = _gpgme_data_append (dh, buffer, s-buffer);
- if (!rc && text)
- {
- rc = _gpgme_data_append_string (dh, text);
- s++;
- n--;
- }
- buffer = s;
- len = n;
- }
- while (!rc && len);
- return rc;
-}
-
-
-/*
- * Append a string to DATA and convert it so that the result will be
- * valid XML.
- */
-GpgmeError
-_gpgme_data_append_string_for_xml (GpgmeData dh, const char *string)
-{
- return _gpgme_data_append_for_xml (dh, string, strlen (string));
-}
-
-
-static int
-hextobyte(const byte *s)
-{
- int c;
-
- if (*s >= '0' && *s <= '9')
- c = 16 * (*s - '0');
- else if (*s >= 'A' && *s <= 'F')
- c = 16 * (10 + *s - 'A');
- else if (*s >= 'a' && *s <= 'f')
- c = 16 * (10 + *s - 'a');
- else
- return -1;
- s++;
- if (*s >= '0' && *s <= '9')
- c += *s - '0';
- else if (*s >= 'A' && *s <= 'F')
- c += 10 + *s - 'A';
- else if (*s >= 'a' && *s <= 'f')
- c += 10 + *s - 'a';
- else
- return -1;
- return c;
-}
-
-/*
- * Append a string with percent style (%XX) escape characters as XML.
- */
-GpgmeError
-_gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *string)
-{
- const byte *s;
- byte *buf, *d;
- int val;
- GpgmeError err;
-
- d = buf = xtrymalloc (strlen (string));
- for (s = string; *s; s++)
- {
- if (*s == '%' && (val = hextobyte (s+1)) != -1)
- {
- *d++ = val;
- s += 2;
- }
- else
- *d++ = *s;
- }
-
- err = _gpgme_data_append_for_xml (dh, buf, d - buf);
- xfree (buf);
- return err;
-}
-
+\f
/* Functions to support the wait interface. */
void
{
GpgmeData dh = opaque;
GpgmeError err;
- int nread;
- char buf[200];
-
- assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_IN);
+ char buffer[BUFFER_SIZE];
+ ssize_t buflen;
- nread = _gpgme_io_read (fd, buf, 200);
- if (nread < 0)
- {
- DEBUG3 ("read_mem_data: read failed on fd %d (n=%d): %s",
- fd, nread, strerror (errno) );
- _gpgme_io_close (fd); /* XXX ??? */
- return;
- }
- else if (!nread)
+ buflen = read (fd, buffer, BUFFER_SIZE);
+ if (buflen <= 0)
{
_gpgme_io_close (fd);
- return; /* eof */
+ return;
}
- /* We could improve this with a GpgmeData function which takes
- * the read function or provides a memory area for writing to it.
- */
-
- err = _gpgme_data_append (dh, buf, nread);
+
+ err = _gpgme_data_append (dh, buffer, buflen);
if (err)
{
- DEBUG1 ("_gpgme_append_data failed: %s\n",
- gpgme_strerror(err));
+ DEBUG1 ("_gpgme_data_append failed: %s\n", gpgme_strerror (err));
/* Fixme: we should close the pipe or read it to /dev/null in
- * this case. Returnin EOF is not sufficient */
- _gpgme_io_close (fd); /* XXX ??? */
+ * this case. Returning EOF is not sufficient */
+ _gpgme_io_close (fd); /* XXX ??? */
return;
}
-
return;
}
-static int
-write_mem_data (GpgmeData dh, int fd)
-{
- size_t nbytes;
- int nwritten;
- nbytes = dh->len - dh->readpos;
- if (!nbytes)
- {
- return 1;
- }
-
- /* FIXME: Arggg, the pipe blocks on large write request, although
- * select told us that it is okay to write - need to figure out
- * why this happens? Stevens says nothing about this problem (or
- * is it my Linux kernel 2.4.0test1)
- * To avoid that we have set the pipe to nonblocking.
- */
-
- nwritten = _gpgme_io_write (fd, dh->data+dh->readpos, nbytes);
- if (nwritten == -1 && errno == EAGAIN)
- return 0;
- if (nwritten < 1)
- {
- DEBUG3 ("write_mem_data(%d): write failed (n=%d): %s",
- fd, nwritten, strerror (errno));
- return 1;
- }
-
- dh->readpos += nwritten;
- return 0;
-}
-
-static int
-write_cb_data (GpgmeData dh, int fd)
+void
+_gpgme_data_outbound_handler (void *opaque, int fd)
{
- size_t nbytes;
- int err, nwritten;
- char buffer[512];
+ GpgmeData dh = opaque;
+ ssize_t nwritten;
- err = gpgme_data_read (dh, buffer, DIM(buffer), &nbytes);
- if (err == GPGME_EOF)
+ if (!dh->pending_len)
{
- return 1;
+ ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE);
+ if (amt <= 0)
+ {
+ _gpgme_io_close (fd);
+ return;
+ }
+ dh->pending_len = amt;
}
-
- nwritten = _gpgme_io_write (fd, buffer, nbytes);
+
+ nwritten = _gpgme_io_write (fd, dh->pending, dh->pending_len);
if (nwritten == -1 && errno == EAGAIN )
- return 0;
- if (nwritten < 1)
- {
- DEBUG3 ("write_cb_data(%d): write failed (n=%d): %s",
- fd, nwritten, strerror (errno));
- return 1;
- }
+ return;
- if (nwritten < nbytes)
+ if (nwritten <= 0)
{
- /* ugly, ugly: It does currently only for for MEM type data */
- if (_gpgme_data_unread (dh, buffer + nwritten, nbytes - nwritten))
- DEBUG1 ("wite_cb_data: unread of %d bytes failed\n",
- nbytes - nwritten);
- return 1;
+ DEBUG3 ("_gpgme_data_outbound_handler (%d): write failed (n=%d): %s",
+ fd, nwritten, strerror (errno));
+ _gpgme_io_close (fd);
+ return;
}
-
- return 0;
-}
-void
-_gpgme_data_outbound_handler (void *opaque, int fd)
-{
- GpgmeData dh = opaque;
-
- assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_OUT);
- switch (gpgme_data_get_type (dh))
- {
- case GPGME_DATA_TYPE_MEM:
- if (write_mem_data (dh, fd))
- _gpgme_io_close (fd);
- break;
- case GPGME_DATA_TYPE_CB:
- if (write_cb_data (dh, fd))
- _gpgme_io_close (fd);
- break;
- default:
- assert (0);
- }
+ if (nwritten < dh->pending_len)
+ memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten);
+ dh->pending_len -= nwritten;
+ return;
}
goto leave;
/* Check the supplied data. */
- if (!ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE)
+ if (!ciph)
{
err = mk_error (No_Data);
goto leave;
}
- _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_OUT);
-
- if (gpgme_data_get_type (plain) != GPGME_DATA_TYPE_NONE)
+ if (!plain)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN);
err = _gpgme_passphrase_start (ctx);
if (err)
ctx->result.edit->fnc_value = fnc_value;
/* Check the supplied data. */
- if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE)
+ if (!out)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (out, GPGME_DATA_MODE_IN);
err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
ctx, out);
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
/* Check the supplied data */
- if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE)
+ if (!plain)
{
err = mk_error (No_Data);
goto leave;
}
- _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT);
- if (!cipher || gpgme_data_get_type (cipher) != GPGME_DATA_TYPE_NONE)
+ if (!cipher)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (cipher, GPGME_DATA_MODE_IN);
err = _gpgme_engine_op_encrypt_sign (ctx->engine, recp, plain, cipher,
ctx->use_armor, ctx /* FIXME */);
GpgmeData plain, GpgmeData cipher)
{
GpgmeError err = _gpgme_op_encrypt_sign_start (ctx, 1, recp, plain, cipher);
-
if (!err)
- {
- err = _gpgme_wait_one (ctx);
- /* Old gpg versions don't return status info for invalid
- recipients, so we simply check whether we got any output at
- all, and if not we assume that we don't have valid
- recipients. */
- if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE)
- ctx->error = mk_error (No_Recipients);
- err = ctx->error;
- }
+ err = _gpgme_wait_one (ctx);
return err;
}
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
/* Check the supplied data */
- if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE)
+ if (!plain)
{
err = mk_error (No_Data);
goto leave;
}
- _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT);
- if (!ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE)
+ if (!ciph)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_IN);
err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor);
{
int err = _gpgme_op_encrypt_start (ctx, 1, recp, plain, cipher);
if (!err)
- {
- err = _gpgme_wait_one (ctx);
- /* Old gpg versions don't return status info for invalid
- recipients, so we simply check whether we got any output at
- all, and if not we assume that we don't have valid
- recipients. */
- if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE)
- ctx->error = mk_error (No_Recipients);
- err = ctx->error;
- }
+ err = _gpgme_wait_one (ctx);
return err;
}
GpgmeError
-_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text)
+_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData signed_text,
+ GpgmeData plaintext)
{
GpgmeError err;
map_input_enc (gpgsm->input_cb.data));
if (err)
return err;
- if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN)
+ if (plaintext)
{
/* Normal or cleartext signature. */
- gpgsm->output_cb.data = text;
+ gpgsm->output_cb.data = plaintext;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server,
0);
_gpgme_io_close (gpgsm->message_cb.fd);
else
{
/* Detached signature. */
- gpgsm->message_cb.data = text;
+ gpgsm->message_cb.data = signed_text;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "MESSAGE",
gpgsm->message_fd_server, 0);
_gpgme_io_close (gpgsm->output_cb.fd);
GpgmeCtx ctx /* FIXME */);
GpgmeError _gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern);
GpgmeError _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig,
- GpgmeData text);
+ GpgmeData signed_text, GpgmeData plaintext);
GpgmeError _gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque);
void _gpgme_gpgsm_set_io_cbs (GpgsmObject gpgsm, struct GpgmeIOCbs *io_cbs);
void _gpgme_gpgsm_io_event (GpgsmObject gpgsm, GpgmeEventIO type, void *type_data);
}
GpgmeError
-_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text)
+_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig,
+ GpgmeData signed_text, GpgmeData plaintext)
{
if (!engine)
return mk_error (Invalid_Value);
switch (engine->protocol)
{
case GPGME_PROTOCOL_OpenPGP:
- return _gpgme_gpg_op_verify (engine->engine.gpg, sig, text);
+ return _gpgme_gpg_op_verify (engine->engine.gpg, sig,
+ signed_text, plaintext);
case GPGME_PROTOCOL_CMS:
- return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig, text);
+ return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig,
+ signed_text, plaintext);
default:
break;
}
GpgmeError _gpgme_engine_op_trustlist (EngineObject engine,
const char *pattern);
GpgmeError _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig,
- GpgmeData text);
+ GpgmeData signed_text, GpgmeData plaintext);
GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque);
void _gpgme_engine_set_io_cbs (EngineObject engine,
if (err)
goto leave;
- if (!keydata || gpgme_data_get_type (keydata) != GPGME_DATA_TYPE_NONE)
+ if (!keydata)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_IN);
_gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
{
GpgmeError err = _gpgme_op_export_start (ctx, 1, recipients, keydata);
if (!err)
- {
- err = _gpgme_wait_one (ctx);
- /* XXX We don't get status information. */
- if (!ctx->error && gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE)
- ctx->error = mk_error (No_Recipients);
- err = ctx->error;
- }
+ err = _gpgme_wait_one (ctx);
+ /* XXX We don't get enough status information. */
return err;
}
gpgme_data_release (ctx->help_data_1);
ctx->help_data_1 = NULL;
- if (!pubkey && !seckey)
- ; /* okay: Add key to the keyrings */
- else if (pubkey && gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE)
- {
- err = mk_error (Invalid_Value);
- goto leave;
- }
- else if (seckey && gpgme_data_get_type (seckey) != GPGME_DATA_TYPE_NONE)
- {
- err = mk_error (Invalid_Value);
- goto leave;
- }
-
- if (pubkey)
- /* FIXME: Need some more things here. */
- _gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN);
-
- if (seckey)
- /* FIXME: Need some more things here. */
- _gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN);
-
if ((parms = strstr (parms, "<GnupgKeyParms "))
&& (s = strchr (parms, '>'))
&& (sx = strstr (parms, "format=\"internal\""))
if (err)
goto leave;
-
- _gpgme_data_set_mode (ctx->help_data_1, GPGME_DATA_MODE_OUT);
_gpgme_engine_set_status_handler (ctx->engine, genkey_status_handler, ctx);
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
char *
gpgme_get_op_info (GpgmeCtx ctx, int reserved)
{
- if (!ctx || reserved)
+ if (!ctx || reserved || !ctx->op_info)
return NULL; /* Invalid value. */
return _gpgme_data_get_as_string (ctx->op_info);
/* Functions to handle data objects. */
+/* Read up to SIZE bytes into buffer BUFFER from the data object with
+ the handle HANDLE. Return the number of characters read, 0 on EOF
+ and -1 on error. If an error occurs, errno is set. */
+typedef int (*GpgmeDataReadCb) (void *handle, void *buffer, size_t size);
+
+/* Write up to SIZE bytes from buffer BUFFER to the data object with
+ the handle HANDLE. Return the number of characters written, or -1
+ on error. If an error occurs, errno is set. */
+typedef ssize_t (*GpgmeDataWriteCb) (void *handle, const void *buffer,
+ size_t size);
+
+/* Set the current position from where the next read or write starts
+ in the data object with the handle HANDLE to OFFSET, relativ to
+ WHENCE. */
+typedef int (*GpgmeDataSeekCb) (void *handle, off_t offset, int whence);
+
+/* Close the data object with the handle DL. */
+typedef void (*GpgmeDataReleaseCb) (void *handle);
+
+struct GpgmeDataCbs
+{
+ GpgmeDataReadCb read;
+ GpgmeDataWriteCb write;
+ GpgmeDataSeekCb seek;
+ GpgmeDataReleaseCb release;
+};
+
+/* Read up to SIZE bytes into buffer BUFFER from the data object with
+ the handle DH. Return the number of characters read, 0 on EOF and
+ -1 on error. If an error occurs, errno is set. */
+int gpgme_data_read (GpgmeData dh, void *buffer, size_t size);
+
+/* Write up to SIZE bytes from buffer BUFFER to the data object with
+ the handle DH. Return the number of characters written, or -1 on
+ error. If an error occurs, errno is set. */
+ssize_t gpgme_data_write (GpgmeData dh, const void *buffer, size_t size);
+
+/* Set the current position from where the next read or write starts
+ in the data object with the handle DH to OFFSET, relativ to
+ WHENCE. */
+off_t gpgme_data_seek (GpgmeData dh, off_t offset, int whence);
+
/* Create a new data buffer and return it in R_DH. */
GpgmeError gpgme_data_new (GpgmeData *r_dh);
+/* Destroy the data buffer DH. */
+void gpgme_data_release (GpgmeData dh);
+
/* Create a new data buffer filled with SIZE bytes starting from
BUFFER. If COPY is zero, copying is delayed until necessary, and
the data is taken from the original location when needed. */
const char *buffer, size_t size,
int copy);
+/* Destroy the data buffer DH and return a pointer to its content.
+ The memory has be to released with free by the user. It's size is
+ returned in R_LEN. */
+char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len);
+
+GpgmeError gpgme_data_new_from_cbs (GpgmeData *dh,
+ struct GpgmeDataCbs *cbs,
+ void *handle);
+
+GpgmeError gpgme_data_new_from_fd (GpgmeData *dh, int fd);
+
+GpgmeError gpgme_data_new_from_stream (GpgmeData *dh, FILE *stream);
+
+/* Return the encoding attribute of the data buffer DH */
+GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh);
+
+/* Set the encoding attribute of data buffer DH to ENC */
+GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc);
+
+
+
/* Create a new data buffer which retrieves the data from the callback
- function READ_CB. */
+ function READ_CB. Deprecated, please use gpgme_data_new_from_cbs
+ instead. */
GpgmeError gpgme_data_new_with_read_cb (GpgmeData *r_dh,
int (*read_cb) (void*,char *,size_t,size_t*),
void *read_cb_value);
/* Create a new data buffer filled with the content of file FNAME.
- COPY must be non-zero (delayed reads are not supported yet). */
+ COPY must be non-zero. For delayed read, please use
+ gpgme_data_new_from_fd or gpgme_data_new_from stream instead. */
GpgmeError gpgme_data_new_from_file (GpgmeData *r_dh,
const char *fname,
int copy);
const char *fname, FILE *fp,
off_t offset, size_t length);
-/* Destroy the data buffer DH. */
-void gpgme_data_release (GpgmeData dh);
-
-/* Destroy the data buffer DH and return a pointer to its content.
- The memory has be to released with free by the user. It's size is
- returned in R_LEN. */
-char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len);
-
-/* Return the type of the data buffer DH. */
-GpgmeDataType gpgme_data_get_type (GpgmeData dh);
-
-/* Return the encoding attribute of the data buffer DH */
-GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh);
-
-/* Set the encoding attribute of data buffer DH to ENC */
-GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc);
-
-/* Reset the read pointer in DH. */
+/* Reset the read pointer in DH. Deprecated, please use
+ gpgme_data_seek instead. */
GpgmeError gpgme_data_rewind (GpgmeData dh);
-/* Read LENGTH bytes from the data object DH and store them in the
- memory starting at BUFFER. The number of bytes actually read is
- returned in NREAD. */
-GpgmeError gpgme_data_read (GpgmeData dh, void *buffer,
- size_t length, size_t *nread);
-
-/* Write LENGTH bytes starting from BUFFER into the data object DH. */
-GpgmeError gpgme_data_write (GpgmeData dh, const void *buffer, size_t length);
-
/* Key and trust functions. */
GpgmeSigMode mode);
/* Verify within CTX that SIG is a valid signature for TEXT. */
-GpgmeError gpgme_op_verify_start (GpgmeCtx ctx,
- GpgmeData sig, GpgmeData text);
-GpgmeError gpgme_op_verify (GpgmeCtx ctx,
- GpgmeData sig, GpgmeData text,
+GpgmeError gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig,
+ GpgmeData signed_text, GpgmeData plaintext);
+GpgmeError gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig,
+ GpgmeData signed_text, GpgmeData plaintext,
GpgmeSigStat *r_status);
/* Import the key in KEYDATA into the keyring. */
/* Check that the library fulfills the version requirement. */
const char *gpgme_check_version (const char *req_version);
-/* Check that the backend engine is available. DEPRECATED. */
-GpgmeError gpgme_check_engine (void);
-
/* Retrieve information about the backend engines. */
const char *gpgme_get_engine_info (void);
goto leave;
/* Check the supplied data */
- if (gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE)
+ if (!keydata)
{
err = mk_error (No_Data);
goto leave;
}
- _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_OUT);
_gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx);
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
int _gpgme_recipients_all_valid ( const GpgmeRecipients rset );
-/*-- data.c --*/
+/*-- data.c and conversion.c --*/
char * _gpgme_data_release_and_return_string ( GpgmeData dh );
-GpgmeDataMode _gpgme_data_get_mode ( GpgmeData dh );
-void _gpgme_data_set_mode ( GpgmeData dh, GpgmeDataMode mode );
char * _gpgme_data_get_as_string ( GpgmeData dh );
GpgmeError _gpgme_data_append ( GpgmeData dh,
const char *buffer, size_t length );
#include "status-table.h"
-/* This type is used to build a list of gpg arguments and
- * data sources/sinks */
-struct arg_and_data_s {
- struct arg_and_data_s *next;
- GpgmeData data; /* If this is not NULL .. */
- int dup_to;
- int print_fd; /* print the fd number and not the special form of it */
- char arg[1]; /* .. this is used */
+/* This type is used to build a list of gpg arguments and data
+ sources/sinks. */
+struct arg_and_data_s
+{
+ struct arg_and_data_s *next;
+ GpgmeData data; /* If this is not NULL, use arg below. */
+ int inbound; /* True if this is used for reading from gpg. */
+ int dup_to;
+ int print_fd; /* Print the fd number and not the special form of it. */
+ char arg[1]; /* Used if data above is not used. */
};
struct fd_data_map_s
}
GpgmeError
-_gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to )
+_gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound)
{
- struct arg_and_data_s *a;
+ struct arg_and_data_s *a;
- assert (gpg);
- assert (data);
- if (gpg->pm.active)
- return 0;
+ assert (gpg);
+ assert (data);
+ if (gpg->pm.active)
+ return 0;
- a = xtrymalloc ( sizeof *a - 1 );
- if ( !a ) {
- gpg->arg_error = 1;
- return mk_error(Out_Of_Core);
+ a = xtrymalloc (sizeof *a - 1);
+ if (!a)
+ {
+ gpg->arg_error = 1;
+ return mk_error(Out_Of_Core);
}
- a->next = NULL;
- a->data = data;
- if ( dup_to == -2 ) {
- a->print_fd = 1;
- a->dup_to = -1;
+ a->next = NULL;
+ a->data = data;
+ a->inbound = inbound;
+ if (dup_to == -2)
+ {
+ a->print_fd = 1;
+ a->dup_to = -1;
}
- else {
- a->print_fd = 0;
- a->dup_to = dup_to;
+ else
+ {
+ a->print_fd = 0;
+ a->dup_to = dup_to;
}
- *gpg->argtail = a;
- gpg->argtail = &a->next;
- return 0;
+ *gpg->argtail = a;
+ gpg->argtail = &a->next;
+ return 0;
}
GpgmeError
rc = gpgme_data_new_with_read_cb ( &tmp, pipemode_cb, gpg );
if (!rc )
- rc = _gpgme_gpg_add_data (gpg, tmp, 0);
+ rc = _gpgme_gpg_add_data (gpg, tmp, 0, 0);
}
if ( !rc ) {
/* here we can reset the handler stuff */
if (err)
return err;
- _gpgme_gpg_add_arg ( gpg, "--command-fd" );
- _gpgme_gpg_add_data (gpg, tmp, -2);
+ _gpgme_gpg_add_arg (gpg, "--command-fd");
+ _gpgme_gpg_add_data (gpg, tmp, -2, 0);
gpg->cmd.cb_data = tmp;
gpg->cmd.fnc = fnc;
gpg->cmd.fnc_value = fnc_value;
{
if (a->data)
{
- switch (_gpgme_data_get_mode (a->data))
- {
- case GPGME_DATA_MODE_NONE:
- case GPGME_DATA_MODE_INOUT:
- xfree (fd_data_map);
- free_argv (argv);
- return mk_error (Invalid_Mode);
- case GPGME_DATA_MODE_IN:
- /* Create a pipe to read from gpg. */
- fd_data_map[datac].inbound = 1;
- break;
- case GPGME_DATA_MODE_OUT:
- /* Create a pipe to pass it down to gpg. */
- fd_data_map[datac].inbound = 0;
- break;
- }
+ /* Create a pipe to pass it down to gpg. */
+ fd_data_map[datac].inbound = a->inbound;
- switch (gpgme_data_get_type (a->data))
- {
- case GPGME_DATA_TYPE_NONE:
- if (fd_data_map[datac].inbound)
- break; /* Allowed. */
- xfree (fd_data_map);
- free_argv (argv);
- return mk_error (Invalid_Type);
- case GPGME_DATA_TYPE_MEM:
- case GPGME_DATA_TYPE_CB:
- break;
- case GPGME_DATA_TYPE_FD:
- case GPGME_DATA_TYPE_FILE:
- xfree (fd_data_map);
- free_argv (argv);
- return mk_error (Not_Implemented);
- }
-
/* Create a pipe. */
{
int fds[2];
}
static GpgmeError
-pipemode_copy (char *buffer, size_t length, size_t *nread, GpgmeData data )
+pipemode_copy (char *buffer, size_t length, size_t *nread, GpgmeData data)
{
- GpgmeError err;
- size_t nbytes;
- char tmp[1000], *s, *d;
-
- /* we can optimize this whole thing but for now we just
- * return after each escape character */
- if (length > 990)
- length = 990;
-
- err = gpgme_data_read ( data, tmp, length, &nbytes );
- if (err)
- return err;
- for (s=tmp, d=buffer; nbytes; s++, nbytes--) {
- *d++ = *s;
- if (*s == '@' ) {
- *d++ = '@';
- break;
- }
+ size_t nbytes;
+ char tmp[1000], *src, *dst;
+
+ /* We can optimize this whole thing but for now we just return after
+ each escape character. */
+ if (length > 990)
+ length = 990;
+
+ nbytes = gpgme_data_read (data, tmp, length);
+ if (nbytes < 0)
+ return mk_error (File_Error);
+ for (src = tmp, dst = buffer; nbytes; src++, nbytes--)
+ {
+ *dst++ = *src;
+ if (*src == '@')
+ {
+ *dst++ = '@';
+ break;
+ }
}
- *nread = d - buffer;
- return 0;
+ *nread = dst - buffer;
+ return 0;
}
if (!err)
err = _gpgme_gpg_add_arg (gpg, "-");
if (!err)
- err = _gpgme_gpg_add_data (gpg, plain, 1);
+ err = _gpgme_gpg_add_data (gpg, plain, 1, 1);
if (!err)
- err = _gpgme_gpg_add_data (gpg, ciph, 0);
+ err = _gpgme_gpg_add_data (gpg, ciph, 0, 0);
return err;
}
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--edit-key");
if (!err)
- err = _gpgme_gpg_add_data (gpg, out, 1);
+ err = _gpgme_gpg_add_data (gpg, out, 1, 1);
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err)
if (!err)
err = _gpgme_gpg_add_arg (gpg, "-");
if (!err)
- err = _gpgme_gpg_add_data (gpg, ciph, 1);
+ err = _gpgme_gpg_add_data (gpg, ciph, 1, 1);
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err)
- err = _gpgme_gpg_add_data (gpg, plain, 0);
+ err = _gpgme_gpg_add_data (gpg, plain, 0, 0);
return err;
}
if (!err)
err = _gpgme_gpg_add_arg (gpg, "-");
if (!err)
- err = _gpgme_gpg_add_data (gpg, ciph, 1);
+ err = _gpgme_gpg_add_data (gpg, ciph, 1, 1);
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err)
- err = _gpgme_gpg_add_data (gpg, plain, 0);
+ err = _gpgme_gpg_add_data (gpg, plain, 0, 0);
return err;
}
if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor");
if (!err)
- err = _gpgme_gpg_add_data (gpg, keydata, 1);
+ err = _gpgme_gpg_add_data (gpg, keydata, 1, 1);
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor");
if (!err)
- err = _gpgme_gpg_add_data (gpg, help_data, 0);
+ err = _gpgme_gpg_add_data (gpg, help_data, 0, 0);
return err;
}
err = _gpgme_gpg_add_arg (gpg, "--import");
if (!err)
- err = _gpgme_gpg_add_data (gpg, keydata, 0);
+ err = _gpgme_gpg_add_data (gpg, keydata, 0, 0);
return err;
}
/* Tell the gpg object about the data. */
if (!err)
- err = _gpgme_gpg_add_data (gpg, in, 0);
+ err = _gpgme_gpg_add_data (gpg, in, 0, 0);
if (!err)
- err = _gpgme_gpg_add_data (gpg, out, 1);
+ err = _gpgme_gpg_add_data (gpg, out, 1, 1);
return err;
}
}
GpgmeError
-_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text)
+_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext)
{
GpgmeError err = 0;
- if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN)
+ if (plaintext)
{
/* Normal or cleartext signature. */
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err)
- err = _gpgme_gpg_add_data (gpg, sig, 0);
+ err = _gpgme_gpg_add_data (gpg, sig, 0, 0);
if (!err)
- err = _gpgme_gpg_add_data (gpg, text, 1);
+ err = _gpgme_gpg_add_data (gpg, plaintext, 1, 1);
}
else
{
if (!err)
err = _gpgme_gpg_add_pm_data (gpg, sig, 0);
if (!err)
- err = _gpgme_gpg_add_pm_data (gpg, text, 1);
+ err = _gpgme_gpg_add_pm_data (gpg, signed_text, 1);
}
else
{
if (!err)
err = _gpgme_gpg_add_arg (gpg, "--");
if (!err)
- err = _gpgme_gpg_add_data (gpg, sig, -1);
- if (text)
+ err = _gpgme_gpg_add_data (gpg, sig, -1, 0);
+ if (signed_text)
{
if (!err)
err = _gpgme_gpg_add_arg (gpg, "-");
if (!err)
- err = _gpgme_gpg_add_data (gpg, text, 0);
+ err = _gpgme_gpg_add_data (gpg, signed_text, 0, 0);
}
}
}
void _gpgme_gpg_housecleaning (void);
void _gpgme_gpg_enable_pipemode ( GpgObject gpg );
GpgmeError _gpgme_gpg_add_arg ( GpgObject gpg, const char *arg );
-GpgmeError _gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to );
+GpgmeError _gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound);
GpgmeError _gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what );
void _gpgme_gpg_set_status_handler (GpgObject gpg,
GpgStatusHandler fnc,
GpgmeSigMode mode, int use_armor,
int use_textmode, GpgmeCtx ctx /* FIXME */);
GpgmeError _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern);
-GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text);
+GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig,
+ GpgmeData signed_text,
+ GpgmeData plaintext);
GpgmeError _gpgme_gpg_spawn (GpgObject gpg, void *opaque);
void _gpgme_gpg_set_io_cbs (GpgObject gpg, struct GpgmeIOCbs *io_cbs);
void _gpgme_gpg_io_event (GpgObject gpg, GpgmeEventIO type, void *type_data);
goto leave;
/* Check the supplied data. */
- if (gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE)
+ if (!in)
{
err = mk_error (No_Data);
goto leave;
}
- _gpgme_data_set_mode (in, GPGME_DATA_MODE_OUT);
- if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE)
+ if (!out)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (out, GPGME_DATA_MODE_IN);
err = _gpgme_passphrase_start (ctx);
if (err)
#endif
-typedef enum {
- GPGME_DATA_MODE_NONE = 0,
- GPGME_DATA_MODE_IN = 1,
- GPGME_DATA_MODE_OUT = 2,
- GPGME_DATA_MODE_INOUT = 3
-} GpgmeDataMode;
-
-
/*
* Declaration of internal objects
*/
static GpgmeError
_gpgme_op_verify_start (GpgmeCtx ctx, int synchronous,
- GpgmeData sig, GpgmeData text)
+ GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext)
{
int err = 0;
int pipemode = 0; /* !!text; use pipemode for detached sigs. */
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
/* Check the supplied data. */
- if (gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE)
+ if (!sig)
{
err = mk_error (No_Data);
goto leave;
}
- if (!text)
+ if (!signed_text && !plaintext)
{
err = mk_error (Invalid_Value);
goto leave;
}
- _gpgme_data_set_mode (sig, GPGME_DATA_MODE_OUT);
- if (gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE)
- /* Normal or cleartext signature. */
- _gpgme_data_set_mode (text, GPGME_DATA_MODE_IN);
- else
- /* Detached signature. */
- _gpgme_data_set_mode (text, GPGME_DATA_MODE_OUT);
-
- err = _gpgme_engine_op_verify (ctx->engine, sig, text);
+ err = _gpgme_engine_op_verify (ctx->engine, sig, signed_text, plaintext);
if (!err) /* And kick off the process. */
err = _gpgme_engine_start (ctx->engine, ctx);
}
GpgmeError
-gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData text)
+gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData signed_text,
+ GpgmeData plaintext)
{
- return _gpgme_op_verify_start (ctx, 0, sig, text);
+ return _gpgme_op_verify_start (ctx, 0, sig, signed_text, plaintext);
}
/*
* the signature itself did go wrong.
**/
GpgmeError
-gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData text,
- GpgmeSigStat *r_stat)
+gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData signed_text,
+ GpgmeData plaintext, GpgmeSigStat *r_stat)
{
GpgmeError err;
ctx->notation = NULL;
*r_stat = GPGME_SIG_STAT_NONE;
- err = _gpgme_op_verify_start (ctx, 1, sig, text);
+ err = _gpgme_op_verify_start (ctx, 1, sig, signed_text, plaintext);
if (!err)
{
err = _gpgme_wait_one (ctx);
}
-/**
- * gpgme_check_engine:
- *
- * Check whether the installed crypto engine for the OpenPGP protocol
- * matches the requirement of GPGME. This function is deprecated,
- * instead use gpgme_engine_get_info() with the specific protocol you
- * need.
- *
- * Return value: 0 or an error code.
- **/
-GpgmeError
-gpgme_check_engine ()
-{
- return gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
-}
-
\f
#define LINELENGTH 80
+2002-10-09 Marcus Brinkmann <marcus@g10code.de>
+
+ * gpg/t-decrypt.c (print_data): Update to new gpgme_data_read
+ interface, and use gpgme_engine_check_version instead
+ gpgme_check_version.
+ * gpg/t-decrypt-verify.c (print_data): Likewise.
+ * gpg/t-edit.c (main): Likewise.
+ * gpg/t-encrypt.c (print_data): Likewise.
+ * gpg/t-encrypt-sign.c (print_data): Likewise.
+ * gpg/t-encrypt-sym.c (print_data): Likewise.
+ * gpg/t-eventloop.c (print_data): Likewise.
+ * gpg/t-export.c (print_data): Likewise.
+ * gpg/t-sign.c (print_data): Likewise.
+ * gpg/t-signers.c (print_data): Likewise.
+ * gpgsm/t-decrypt.c (print_data): Likewise.
+ * gpgsm/t-encrypt.c (print_data): Likewise.
+ * gpgsm/t-export.c (print_data): Likewise.
+ * gpgsm/t-sign.c (print_data): Likewise.
+ * gpg/t-verify.c (main): Likewise for gpgme_op_verify.
+ * gpgsm/t-verify.c (main): Likewise for gpgme_op_verify.
+ * t-data.c (read_once_test): Likewise.
+ (write_test): Update for new behaviour of data objects.
+ (main): Remove type test.
+
2002-09-30 Werner Koch <wk@gnupg.org>
* gpgsm/t-keylist.c (doit): Add arg SECRET.
exit (1); } \
} while(0)
+
static void
print_data (GpgmeData dh)
{
char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind (dh);
- fail_if_err (err);
- while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
- fwrite ( buf, nread, 1, stdout );
- if (err != GPGME_EOF)
- fail_if_err (err);
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
+
static const char *
passphrase_cb (void *opaque, const char *desc, void **r_hd)
{
} while(0)
static void
-print_data ( GpgmeData dh )
+print_op_info (GpgmeCtx ctx)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
+ char *str = gpgme_get_op_info (ctx, 0);
+
+ if (!str)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (str);
+ free (str);
}
- if (err != GPGME_EOF)
- fail_if_err (err);
+}
+
+
+static void
+print_data (GpgmeData dh)
+{
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
flush_data (GpgmeData dh)
{
char buf[100];
- size_t nread;
- GpgmeError err;
-
- while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
- fwrite (buf, nread, 1, stdout);
- if (err != GPGME_EOF)
- fail_if_err (err);
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
} while(0)
static void
-print_op_info (GpgmeCtx c)
+print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (c, 0);
-
- if (!s)
- puts ("<!-- no operation info available -->");
- else {
- puts (s);
- free (s);
+ char *str = gpgme_get_op_info (ctx, 0);
+
+ if (!str)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (str);
+ free (str);
}
}
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
GpgmeRecipients rset;
char *p;
- err = gpgme_check_engine ();
+ err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
puts ( gpgme_get_engine_info() );
print_data (GpgmeData dh)
{
char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind (dh);
- fail_if_err (err);
- while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
- fwrite ( buf, nread, 1, stdout );
- if (err != GPGME_EOF)
- fail_if_err (err);
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
char *p;
size_t len;
- err = gpgme_check_engine ();
+ err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
do
static void
print_op_info (GpgmeCtx c)
{
- char *s = gpgme_get_op_info (c, 0);
-
- if (!s)
- puts ("<!-- no operation info available -->");
- else {
- puts (s);
- free (s);
+ char *s = gpgme_get_op_info (c, 0);
+
+ if (!s)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (s);
+ free (s);
}
}
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
int
-main (int argc, char **argv )
+main (int argc, char **argv)
{
GpgmeCtx ctx;
GpgmeError err;
GpgmeData in, out;
GpgmeRecipients rset;
- err = gpgme_check_engine ();
+ err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
puts ( gpgme_get_engine_info() );
static void
print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (ctx, 0);
+ char *str = gpgme_get_op_info (ctx, 0);
- if (!s)
+ if (!str)
puts ("<!-- no operation info available -->");
else
{
- puts (s);
- free (s);
+ puts (str);
+ free (str);
}
}
print_data (GpgmeData dh)
{
char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind (dh);
- fail_if_err (err);
- while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
- fwrite (buf, nread, 1, stdout);
- if (err != GPGME_EOF)
- fail_if_err (err);
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
for (i = 0; i < FDLIST_MAX; i++)
fdlist[i].fd = -1;
- err = gpgme_check_engine ();
+ err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
puts (gpgme_get_engine_info ());
exit (1); } \
} while(0)
+
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
-
-
int
main (int argc, char **argv )
{
}
pattern = argc? *argv : NULL;
- err = gpgme_check_engine();
+ err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
err = gpgme_new (&ctx);
} while(0)
static void
-print_op_info (GpgmeCtx c)
+print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (c, 0);
-
- if (!s)
- puts ("<!-- no operation info available -->");
- else {
- puts (s);
- free (s);
+ char *str = gpgme_get_op_info (ctx, 0);
+
+ if (!str)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (str);
+ free (str);
}
}
+
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
+
static const char *
passphrase_cb ( void *opaque, const char *desc, void **r_hd )
{
} while(0)
static void
-print_op_info (GpgmeCtx c)
+print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (c, 0);
+ char *str = gpgme_get_op_info (ctx, 0);
- if (!s)
+ if (!str)
puts ("<!-- no operation info available -->");
else
{
- puts (s);
- free (s);
+ puts (str);
+ free (str);
}
}
+
static void
print_data (GpgmeData dh)
{
char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind (dh);
- fail_if_err (err);
- while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
- fwrite (buf, nread, 1, stdout);
- if (err != GPGME_EOF)
- fail_if_err (err);
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
+
static const char *
passphrase_cb (void *opaque, const char *desc, void **r_hd)
{
fail_if_err (err);
puts ("checking a valid message:\n");
- err = gpgme_op_verify (ctx, sig, text, &status );
+ err = gpgme_op_verify (ctx, sig, text, NULL, &status);
fail_if_err (err);
- print_sig_stat ( ctx, status );
+ print_sig_stat (ctx, status);
if (status != GPGME_SIG_STAT_GOOD)
{
fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__);
exit (1);
}
- if ( (nota=gpgme_get_notation (ctx)) )
+ if ((nota = gpgme_get_notation (ctx)))
printf ("---Begin Notation---\n%s---End Notation---\n", nota );
puts ("checking a manipulated message:\n");
gpgme_data_release (text);
- err = gpgme_data_new_from_mem ( &text,
- test_text1f, strlen (test_text1f), 0 );
+ err = gpgme_data_new_from_mem (&text,
+ test_text1f, strlen (test_text1f), 0);
fail_if_err (err);
- gpgme_data_rewind ( sig );
- err = gpgme_op_verify (ctx, sig, text, &status );
+ gpgme_data_rewind (sig);
+ err = gpgme_op_verify (ctx, sig, text, NULL, &status);
fail_if_err (err);
print_sig_stat (ctx, status);
fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__);
exit (1);
}
- if ( (nota=gpgme_get_notation (ctx)) )
+ if ((nota = gpgme_get_notation (ctx)))
printf ("---Begin Notation---\n%s---End Notation---\n", nota );
puts ("checking a normal signature:");
gpgme_data_release (sig);
gpgme_data_release (text);
- err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0);
+ err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0);
fail_if_err (err);
err = gpgme_data_new (&text);
fail_if_err (err);
- err = gpgme_op_verify (ctx, sig, text, &status);
+ err = gpgme_op_verify (ctx, sig, NULL, text, &status);
fail_if_err (err);
nota = gpgme_data_release_and_get_mem (text, &len);
} while(0)
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
+
int
main (int argc, char **argv )
{
} while(0)
static void
-print_op_info (GpgmeCtx c)
+print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (c, 0);
-
- if (!s)
- puts ("<!-- no operation info available -->");
- else {
- puts (s);
- free (s);
+ char *str = gpgme_get_op_info (ctx, 0);
+
+ if (!str)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (str);
+ free (str);
}
}
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
-
int
main (int argc, char **argv )
{
} while(0)
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
-
int
main (int argc, char **argv )
{
} while(0)
static void
-print_op_info (GpgmeCtx c)
+print_op_info (GpgmeCtx ctx)
{
- char *s = gpgme_get_op_info (c, 0);
+ char *str = gpgme_get_op_info (ctx, 0);
- if (!s)
- puts ("<!-- no operation info available -->");
- else {
- puts (s);
- free (s);
+ if (!str)
+ puts ("<!-- no operation info available -->");
+ else
+ {
+ puts (str);
+ free (str);
}
}
+
static void
-print_data ( GpgmeData dh )
+print_data (GpgmeData dh)
{
- char buf[100];
- size_t nread;
- GpgmeError err;
-
- err = gpgme_data_rewind ( dh );
- fail_if_err (err);
- while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
- fwrite ( buf, nread, 1, stdout );
- }
- if (err != GPGME_EOF)
- fail_if_err (err);
+ char buf[100];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (GPGME_File_Error);
+ while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (GPGME_File_Error);
}
+
int
-main (int argc, char **argv )
+main (int argc, char **argv)
{
GpgmeCtx ctx;
GpgmeError err;
fail_if_err (err);
puts ("checking a valid message:\n");
- err = gpgme_op_verify (ctx, sig, text, &status );
- print_sig_stat ( ctx, status );
- print_sig_stat ( ctx, status );
- print_sig_stat ( ctx, status );
- print_sig_stat ( ctx, status );
+ err = gpgme_op_verify (ctx, sig, text, NULL, &status);
+ print_sig_stat (ctx, status);
+ print_sig_stat (ctx, status);
+ print_sig_stat (ctx, status);
+ print_sig_stat (ctx, status);
fail_if_err (err);
if ( (nota=gpgme_get_notation (ctx)) )
- printf ("---Begin Notation---\n%s---End Notation---\n", nota );
+ printf ("---Begin Notation---\n%s---End Notation---\n", nota);
puts ("checking a manipulated message:\n");
gpgme_data_release (text);
err = gpgme_data_new_from_mem ( &text,
- test_text1f, strlen (test_text1f), 0 );
+ test_text1f, strlen (test_text1f), 0);
fail_if_err (err);
gpgme_data_rewind ( sig );
- err = gpgme_op_verify (ctx, sig, text, &status );
+ err = gpgme_op_verify (ctx, sig, text, NULL, &status);
- print_sig_stat ( ctx, status );
+ print_sig_stat (ctx, status);
fail_if_err (err);
- if ( (nota=gpgme_get_notation (ctx)) )
- printf ("---Begin Notation---\n%s---End Notation---\n", nota );
+ if ((nota=gpgme_get_notation (ctx)))
+ printf ("---Begin Notation---\n%s---End Notation---\n", nota);
gpgme_data_release (sig);
gpgme_data_release (text);
-
-} while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 );
+
+ } while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 );
gpgme_release (ctx);
return 0;
void
read_once_test (round_t round, GpgmeData data)
{
- GpgmeError err;
char buffer[1024];
size_t read;
- err = gpgme_data_read (data, buffer, sizeof (buffer), &read);
- fail_if_err (err);
+ read = gpgme_data_read (data, buffer, sizeof (buffer));
if (read != strlen (text) || strncmp (buffer, text, strlen (text)))
{
exit (1);
}
- err = gpgme_data_read (data, buffer, sizeof (buffer), &read);
- if (err != GPGME_EOF)
+ read = gpgme_data_read (data, buffer, sizeof (buffer));
+ if (read)
{
fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n",
__FILE__, __LINE__, round);
if (round == TEST_INOUT_NONE)
{
- err = gpgme_data_read (data, buffer, sizeof (buffer), &read);
- if (!err)
+ read = gpgme_data_read (data, buffer, sizeof (buffer));
+ if (read > 0)
{
fprintf (stderr, "%s:%d: (%i) gpgme_data_read succeded unexpectedly\n",
__FILE__, __LINE__, round);
{
GpgmeError err;
char buffer[1024];
- size_t read;
+ size_t amt;
- err = gpgme_data_write (data, text, strlen (text));
- fail_if_err (err);
+ amt = gpgme_data_write (data, text, strlen (text));
+ if (amt != strlen (text))
+ fail_if_err (GPGME_File_Error);
- read_once_test (round, data);
err = gpgme_data_rewind (data);
fail_if_err (err);
read_once_test (round, data);
else
{
- err = gpgme_data_read (data, buffer, sizeof (buffer), &read);
- fail_if_err (err);
+ amt = gpgme_data_read (data, buffer, sizeof (buffer));
- if (read != strlen (text2) || strncmp (buffer, text2, strlen (text2)))
+ if (amt != strlen (text2) || strncmp (buffer, text2, strlen (text2)))
{
fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n",
__FILE__, __LINE__, round);
exit (1);
}
- err = gpgme_data_read (data, buffer, sizeof (buffer), &read);
- if (err != GPGME_EOF)
+ amt = gpgme_data_read (data, buffer, sizeof (buffer));
+ if (amt)
{
fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n",
__FILE__, __LINE__, round);
}
int
-main (int argc, char **argv )
+main (int argc, char **argv)
{
round_t round = TEST_INITIALIZER;
const char *text_filename = make_filename ("t-data-1.txt");
"unexpectedly\n", __FILE__, __LINE__);
exit (1);
}
- if (gpgme_data_get_type (NULL) != GPGME_DATA_TYPE_NONE)
- {
- fprintf (stderr, "%s:%d: gpgme_data_get_type on NULL incorrect\n",
- __FILE__, __LINE__);
- exit (1);
- }
continue;
case TEST_INOUT_NONE:
err = gpgme_data_new (&data);
case TEST_INOUT_MEM_FROM_FILE_NO_COPY:
err = gpgme_data_new_from_file (&data, text_filename, 0);
/* This is not implemented yet. */
- if (err == GPGME_Not_Implemented)
+ if (err == GPGME_Not_Implemented || err == GPGME_Invalid_Value)
continue;
break;
case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME:
}
fail_if_err (err);
- switch (round)
- {
- case TEST_INOUT_NONE:
- if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_NONE)
- err = GPGME_Invalid_Type;
- break;
- case TEST_INOUT_MEM_NO_COPY:
- case TEST_INOUT_MEM_COPY:
- case TEST_INOUT_MEM_FROM_FILE_COPY:
- case TEST_INOUT_MEM_FROM_FILE_NO_COPY:
- case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME:
- case TEST_INOUT_MEM_FROM_FILE_PART_BY_FP:
- if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_MEM)
- err = GPGME_Invalid_Type;
- break;
- case TEST_OUT_CB:
- if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_CB)
- err = GPGME_Invalid_Type;
- break;
- case TEST_INITIALIZER:
- case TEST_INVALID_ARGUMENT:
- case TEST_INOUT_MEM_FROM_INEXISTANT_FILE:
- case TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART:
- case TEST_END:
- /* Shouldn't happen. */
- fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__);
- exit (1);
- }
read_test (round, data);
if (round != TEST_OUT_CB)
write_test (round, data);