aboutsummaryrefslogtreecommitdiffstats
path: root/agent/preset-passphrase.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2008-09-03 09:37:32 +0000
committerWerner Koch <[email protected]>2008-09-03 09:37:32 +0000
commit5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3 (patch)
tree187e260d1af072d35a529fd43b765e71bab34108 /agent/preset-passphrase.c
parent2008-08-30 Moritz <[email protected]> (diff)
downloadgnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.tar.gz
gnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.zip
Fix gpg-preset-passphrase bug.
Cleanups
Diffstat (limited to 'agent/preset-passphrase.c')
-rw-r--r--agent/preset-passphrase.c40
1 files changed, 6 insertions, 34 deletions
diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c
index 42c7d6c95..cb906ad89 100644
--- a/agent/preset-passphrase.c
+++ b/agent/preset-passphrase.c
@@ -113,37 +113,6 @@ my_strusage (int level)
/* Include the implementation of map_spwq_error. */
MAP_SPWQ_ERROR_IMPL
-/* Convert the string SRC into HEX encoding. Caller needs to xfree
- the returned string. */
-static char *
-make_hexstring (const char *src)
-{
- int len = 2 * strlen (src) + 1;
- char *dst;
- char *res;
-
- res = dst = xtrymalloc (len);
- if (!dst)
- {
- log_error ("can not escape string: %s\n",
- gpg_strerror (gpg_error_from_syserror ()));
- return NULL;
- }
-
-#define _tohex(nr) ((nr) < 10 ? ((nr) + '0') : (((nr) - 10) + 'A'))
-#define tohex1(p) _tohex (*((unsigned char *) p) & 15)
-#define tohex2(p) _tohex ((*((unsigned char *) p) >> 4) & 15)
-
- while (*src)
- {
- *(dst++) = tohex2 (src);
- *(dst++) = tohex1 (src);
- src++;
- }
- *dst = '\0';
- return res;
-}
-
static void
preset_passphrase (const char *keygrip)
@@ -175,11 +144,14 @@ preset_passphrase (const char *keygrip)
/* FIXME: How to handle empty passwords? */
}
- passphrase_esc = make_hexstring (opt_passphrase
- ? opt_passphrase : passphrase);
+ {
+ const char *s = opt_passphrase ? opt_passphrase : passphrase;
+ passphrase_esc = bin2hex (s, strlen (s), NULL);
+ }
if (!passphrase_esc)
{
- /* Error message printed by callee. */
+ log_error ("can not escape string: %s\n",
+ gpg_strerror (gpg_error_from_syserror ()));
return;
}