tests: Use gpgme_io_write in passhrase callbacks.

* tests/gpg/t-support.h (passphrase_cb): Use gpgme_io_write.
* tests/gpgsm/t-support.h (passphrase_cb): Ditto.
* tests/run-support.h (passphrase_cb): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-09-13 20:46:41 +02:00
parent 3972f476e0
commit 4491ef0a9a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 21 additions and 20 deletions

View File

@ -76,27 +76,25 @@ gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
#ifdef HAVE_W32_SYSTEM
DWORD written;
WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
#else
int res;
char *pass = "abc\n";
char pass[] = "abc\n";
int passlen = strlen (pass);
int off = 0;
(void)opaque;
(void)uid_hint;
(void)passphrase_info;
(void)last_was_bad;
do
{
res = write (fd, &pass[off], passlen - off);
res = gpgme_io_write (fd, &pass[off], passlen - off);
if (res > 0)
off += res;
}
while (res > 0 && off != passlen);
return off == passlen ? 0 : gpgme_error_from_errno (errno);
#endif
return 0;
}

View File

@ -63,13 +63,18 @@ passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
int res;
char *pass = "abc\n";
char pass[] = "abc\n";
int passlen = strlen (pass);
int off = 0;
(void)opaque;
(void)uid_hint;
(void)passphrase_info;
(void)last_was_bad;
do
{
res = write (fd, &pass[off], passlen - off);
res = gpgme_io_write (fd, &pass[off], passlen - off);
if (res > 0)
off += res;
}

View File

@ -75,27 +75,25 @@ gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
#ifdef HAVE_W32_SYSTEM
DWORD written;
WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
#else
int res;
char *pass = "abc\n";
char pass[] = "abc\n";
int passlen = strlen (pass);
int off = 0;
(void)opaque;
(void)uid_hint;
(void)passphrase_info;
(void)last_was_bad;
do
{
res = write (fd, &pass[off], passlen - off);
res = gpgme_io_write (fd, &pass[off], passlen - off);
if (res > 0)
off += res;
}
while (res > 0 && off != passlen);
return off == passlen ? 0 : gpgme_error_from_errno (errno);
#endif
return 0;
}