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:
parent
3972f476e0
commit
4491ef0a9a
@ -76,27 +76,25 @@ gpgme_error_t
|
|||||||
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
||||||
int last_was_bad, int fd)
|
int last_was_bad, int fd)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_W32_SYSTEM
|
|
||||||
DWORD written;
|
|
||||||
WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
|
|
||||||
#else
|
|
||||||
int res;
|
int res;
|
||||||
char *pass = "abc\n";
|
char pass[] = "abc\n";
|
||||||
int passlen = strlen (pass);
|
int passlen = strlen (pass);
|
||||||
int off = 0;
|
int off = 0;
|
||||||
|
|
||||||
|
(void)opaque;
|
||||||
|
(void)uid_hint;
|
||||||
|
(void)passphrase_info;
|
||||||
|
(void)last_was_bad;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = write (fd, &pass[off], passlen - off);
|
res = gpgme_io_write (fd, &pass[off], passlen - off);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
off += res;
|
off += res;
|
||||||
}
|
}
|
||||||
while (res > 0 && off != passlen);
|
while (res > 0 && off != passlen);
|
||||||
|
|
||||||
return off == passlen ? 0 : gpgme_error_from_errno (errno);
|
return off == passlen ? 0 : gpgme_error_from_errno (errno);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,13 +63,18 @@ passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
|||||||
int last_was_bad, int fd)
|
int last_was_bad, int fd)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
char *pass = "abc\n";
|
char pass[] = "abc\n";
|
||||||
int passlen = strlen (pass);
|
int passlen = strlen (pass);
|
||||||
int off = 0;
|
int off = 0;
|
||||||
|
|
||||||
|
(void)opaque;
|
||||||
|
(void)uid_hint;
|
||||||
|
(void)passphrase_info;
|
||||||
|
(void)last_was_bad;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = write (fd, &pass[off], passlen - off);
|
res = gpgme_io_write (fd, &pass[off], passlen - off);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
off += res;
|
off += res;
|
||||||
}
|
}
|
||||||
|
@ -75,27 +75,25 @@ gpgme_error_t
|
|||||||
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
|
||||||
int last_was_bad, int fd)
|
int last_was_bad, int fd)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_W32_SYSTEM
|
|
||||||
DWORD written;
|
|
||||||
WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0);
|
|
||||||
#else
|
|
||||||
int res;
|
int res;
|
||||||
char *pass = "abc\n";
|
char pass[] = "abc\n";
|
||||||
int passlen = strlen (pass);
|
int passlen = strlen (pass);
|
||||||
int off = 0;
|
int off = 0;
|
||||||
|
|
||||||
|
(void)opaque;
|
||||||
|
(void)uid_hint;
|
||||||
|
(void)passphrase_info;
|
||||||
|
(void)last_was_bad;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = write (fd, &pass[off], passlen - off);
|
res = gpgme_io_write (fd, &pass[off], passlen - off);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
off += res;
|
off += res;
|
||||||
}
|
}
|
||||||
while (res > 0 && off != passlen);
|
while (res > 0 && off != passlen);
|
||||||
|
|
||||||
return off == passlen ? 0 : gpgme_error_from_errno (errno);
|
return off == passlen ? 0 : gpgme_error_from_errno (errno);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user