2003-06-05 23:20:29 +00:00
|
|
|
/* t-support.h - Helper routines for regression tests.
|
2018-11-16 12:27:33 +00:00
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
|
|
|
* Copyright (C) 2001, 2002, 2003, 2004 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 Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*/
|
2003-06-05 23:20:29 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2003-09-14 00:30:53 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <locale.h>
|
2003-06-05 23:20:29 +00:00
|
|
|
|
|
|
|
#include <gpgme.h>
|
|
|
|
|
2020-03-27 10:50:24 +00:00
|
|
|
#ifndef DIM
|
|
|
|
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
|
|
|
#endif
|
|
|
|
|
2003-06-05 23:20:29 +00:00
|
|
|
#define fail_if_err(err) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (err) \
|
|
|
|
{ \
|
2003-11-19 15:15:33 +00:00
|
|
|
fprintf (stderr, "%s:%d: %s: %s (%d.%d)\n", \
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
__FILE__, __LINE__, gpgme_strsource (err), \
|
|
|
|
gpgme_strerror (err), \
|
|
|
|
gpgme_err_source (err), gpgme_err_code (err)); \
|
2003-06-05 23:20:29 +00:00
|
|
|
exit (1); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
print_data (gpgme_data_t dh)
|
|
|
|
{
|
|
|
|
#define BUF_SIZE 512
|
|
|
|
char buf[BUF_SIZE + 1];
|
|
|
|
int ret;
|
2016-09-13 18:48:06 +00:00
|
|
|
|
2003-06-05 23:20:29 +00:00
|
|
|
ret = gpgme_data_seek (dh, 0, SEEK_SET);
|
|
|
|
if (ret)
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
fail_if_err (gpgme_error_from_errno (errno));
|
2003-06-05 23:20:29 +00:00
|
|
|
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
|
|
|
|
fwrite (buf, ret, 1, stdout);
|
|
|
|
if (ret < 0)
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
fail_if_err (gpgme_error_from_errno (errno));
|
2003-06-05 23:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gpgme_error_t
|
|
|
|
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
|
|
|
int last_was_bad, int fd)
|
|
|
|
{
|
2009-06-22 14:50:17 +00:00
|
|
|
int res;
|
2016-09-13 18:46:41 +00:00
|
|
|
char pass[] = "abc\n";
|
2009-06-22 14:50:17 +00:00
|
|
|
int passlen = strlen (pass);
|
|
|
|
int off = 0;
|
|
|
|
|
2016-09-13 18:46:41 +00:00
|
|
|
(void)opaque;
|
|
|
|
(void)uid_hint;
|
|
|
|
(void)passphrase_info;
|
|
|
|
(void)last_was_bad;
|
|
|
|
|
2009-06-22 14:50:17 +00:00
|
|
|
do
|
|
|
|
{
|
2016-09-13 18:46:41 +00:00
|
|
|
res = gpgme_io_write (fd, &pass[off], passlen - off);
|
2009-06-22 14:50:17 +00:00
|
|
|
if (res > 0)
|
|
|
|
off += res;
|
|
|
|
}
|
|
|
|
while (res > 0 && off != passlen);
|
|
|
|
|
|
|
|
return off == passlen ? 0 : gpgme_error_from_errno (errno);
|
2003-06-05 23:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
make_filename (const char *fname)
|
|
|
|
{
|
|
|
|
const char *srcdir = getenv ("srcdir");
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
if (!srcdir)
|
|
|
|
srcdir = ".";
|
|
|
|
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
|
2016-09-13 18:48:06 +00:00
|
|
|
if (!buf)
|
2003-06-05 23:20:29 +00:00
|
|
|
exit (8);
|
|
|
|
strcpy (buf, srcdir);
|
|
|
|
strcat (buf, "/");
|
|
|
|
strcat (buf, fname);
|
|
|
|
return buf;
|
|
|
|
}
|
2003-09-14 00:30:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
init_gpgme (gpgme_protocol_t proto)
|
|
|
|
{
|
|
|
|
gpgme_error_t err;
|
|
|
|
|
|
|
|
gpgme_check_version (NULL);
|
2007-07-12 15:25:20 +00:00
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2003-09-14 00:30:53 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
|
|
|
|
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
|
2007-07-12 15:25:20 +00:00
|
|
|
#endif
|
2003-09-14 00:30:53 +00:00
|
|
|
|
|
|
|
err = gpgme_engine_check_version (proto);
|
|
|
|
fail_if_err (err);
|
|
|
|
}
|