2002-09-02 Marcus Brinkmann <marcus@g10code.de>
* conversion.c: New file. * util.h: Add prototypes for _gpgme_decode_c_string and _gpgme_hextobyte. * keylist.c (keylist_colon_handler): Call _gpgme_decode_c_string on issuer name. * Makefile.am (libgpgme_la_SOURCES): Add conversion.c * key.c (_gpgme_key_append_name): Replace calls to hextobyte by calls to _gpgme_hextobyte. (hash_key): Likewise.
This commit is contained in:
parent
1731657df0
commit
328bed4901
@ -1,3 +1,15 @@
|
||||
2002-09-02 Marcus Brinkmann <marcus@g10code.de>
|
||||
|
||||
* conversion.c: New file.
|
||||
* util.h: Add prototypes for _gpgme_decode_c_string and
|
||||
_gpgme_hextobyte.
|
||||
* keylist.c (keylist_colon_handler): Call _gpgme_decode_c_string
|
||||
on issuer name.
|
||||
* Makefile.am (libgpgme_la_SOURCES): Add conversion.c
|
||||
* key.c (_gpgme_key_append_name): Replace calls to hextobyte by
|
||||
calls to _gpgme_hextobyte.
|
||||
(hash_key): Likewise.
|
||||
|
||||
2002-09-01 Marcus Brinkmann <marcus@g10code.de>
|
||||
|
||||
* op-support.c (_gpgme_op_reset): Set CTX->pending after calling
|
||||
|
@ -55,36 +55,17 @@ else
|
||||
system_components = ${ath_components} posix-util.c posix-sema.c posix-io.c
|
||||
endif
|
||||
|
||||
libgpgme_la_SOURCES = \
|
||||
gpgme.h types.h \
|
||||
util.h util.c \
|
||||
context.h ops.h \
|
||||
data.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.c key.h \
|
||||
keylist.c \
|
||||
trustlist.c \
|
||||
import.c \
|
||||
export.c \
|
||||
genkey.c \
|
||||
delete.c \
|
||||
edit.c \
|
||||
rungpg.c rungpg.h status-table.h \
|
||||
engine-gpgsm.c engine-gpgsm.h \
|
||||
engine.c engine.h \
|
||||
sema.h io.h \
|
||||
${system_components} \
|
||||
debug.c debug.h \
|
||||
gpgme.c version.c errors.c
|
||||
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 \
|
||||
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 \
|
||||
import.c export.c genkey.c delete.c edit.c \
|
||||
engine.h engine.c rungpg.h rungpg.c status-table.h \
|
||||
engine-gpgsm.c engine-gpgsm.h \
|
||||
sema.h io.h ${system_components} \
|
||||
debug.c debug.h gpgme.c version.c errors.c
|
||||
libgpgme_la_LIBADD = ${assuan_libobjs} @LIBOBJS@
|
||||
|
||||
errors.c : gpgme.h
|
||||
|
136
gpgme/conversion.c
Normal file
136
gpgme/conversion.c
Normal file
@ -0,0 +1,136 @@
|
||||
/* conversion.c - String conversion helper functions.
|
||||
* 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
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include "gpgme.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
int
|
||||
_gpgme_hextobyte (const byte *str)
|
||||
{
|
||||
int val = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
if (*str >= '0' && *str <= '9')
|
||||
val += *str - '0';
|
||||
else if (*str >= 'A' && *str <= 'F')
|
||||
val += 10 + *str - 'A';
|
||||
else if (*str >= 'a' && *str <= 'f')
|
||||
val += 10 + *str - 'a';
|
||||
else
|
||||
return -1;
|
||||
val *= 16;
|
||||
str++;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
GpgmeError
|
||||
_gpgme_decode_c_string (const char *src, char **destp)
|
||||
{
|
||||
char *dest;
|
||||
|
||||
/* We can malloc a buffer of the same length, because the converted
|
||||
string will never be larger. */
|
||||
dest = xtrymalloc (strlen (src));
|
||||
if (!dest)
|
||||
return mk_error (Out_Of_Core);
|
||||
|
||||
while (*src)
|
||||
{
|
||||
if (*src != '\\')
|
||||
*(dest++) = *(src++);
|
||||
else if (src[1] == '\\')
|
||||
{
|
||||
src++;
|
||||
*(dest++) = *(src++);
|
||||
}
|
||||
else if (src[1] == 'n')
|
||||
{
|
||||
src += 2;
|
||||
*(dest++) = '\n';
|
||||
}
|
||||
else if (src[1] == 'r')
|
||||
{
|
||||
src += 2;
|
||||
*(dest++) = '\r';
|
||||
}
|
||||
else if (src[1] == 'v')
|
||||
{
|
||||
src += 2;
|
||||
*(dest++) = '\v';
|
||||
}
|
||||
else if (src[1] == 'b')
|
||||
{
|
||||
src += 2;
|
||||
*(dest++) = '\b';
|
||||
}
|
||||
else if (src[1] == '0')
|
||||
{
|
||||
/* Hmmm: no way to express this */
|
||||
src += 2;
|
||||
*(dest++) = '\\';
|
||||
*(dest++) = '\0';
|
||||
}
|
||||
else if (src[1] == 'x' && isxdigit (src[2]) && isxdigit (src[3]))
|
||||
{
|
||||
int val = _gpgme_hextobyte (&src[2]);
|
||||
if (val == -1)
|
||||
{
|
||||
/* Should not happen. */
|
||||
*(dest++) = *(src++);
|
||||
*(dest++) = *(src++);
|
||||
*(dest++) = *(src++);
|
||||
*(dest++) = *(src++);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!val)
|
||||
{
|
||||
*(dest++) = '\\';
|
||||
*(dest++) = '\0';
|
||||
}
|
||||
else
|
||||
*(byte*)dest++ = val;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* should not happen */
|
||||
src++;
|
||||
*(dest++) = '\\';
|
||||
*(dest++) = *(src++);
|
||||
}
|
||||
}
|
||||
*(dest++) = 0;
|
||||
*destp = dest;
|
||||
|
||||
return 0;
|
||||
}
|
35
gpgme/key.c
35
gpgme/key.c
@ -57,31 +57,6 @@ static struct key_cache_item_s *key_cache_unused_items;
|
||||
the cache. */
|
||||
DEFINE_STATIC_LOCK (key_ref_lock);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int
|
||||
hash_key (const char *fpr, unsigned int *rhash)
|
||||
{
|
||||
@ -90,16 +65,16 @@ hash_key (const char *fpr, unsigned int *rhash)
|
||||
|
||||
if (!fpr)
|
||||
return -1;
|
||||
if ((c = hextobyte (fpr)) == -1)
|
||||
if ((c = _gpgme_hextobyte (fpr)) == -1)
|
||||
return -1;
|
||||
hash = c;
|
||||
if ((c = hextobyte (fpr+2)) == -1)
|
||||
if ((c = _gpgme_hextobyte (fpr+2)) == -1)
|
||||
return -1;
|
||||
hash |= c << 8;
|
||||
if ((c = hextobyte (fpr+4)) == -1)
|
||||
if ((c = _gpgme_hextobyte (fpr+4)) == -1)
|
||||
return -1;
|
||||
hash |= c << 16;
|
||||
if ((c = hextobyte (fpr+6)) == -1)
|
||||
if ((c = _gpgme_hextobyte (fpr+6)) == -1)
|
||||
return -1;
|
||||
hash |= c << 24;
|
||||
|
||||
@ -630,7 +605,7 @@ _gpgme_key_append_name (GpgmeKey key, const char *s)
|
||||
}
|
||||
else if (s[1] == 'x' && isxdigit (s[2]) && isxdigit (s[3]))
|
||||
{
|
||||
int val = hextobyte (&s[2]);
|
||||
int val = _gpgme_hextobyte (&s[2]);
|
||||
if (val == -1)
|
||||
{
|
||||
/* Should not happen. */
|
||||
|
@ -404,14 +404,12 @@ keylist_colon_handler (GpgmeCtx ctx, char *line)
|
||||
case 9: /* ownertrust */
|
||||
set_ownertrust (key, p);
|
||||
break;
|
||||
case 10: /* not used for gpg due to --fixed-list-mode option
|
||||
but gpgsm stores the issuer name */
|
||||
case 10:
|
||||
/* Not used for gpg due to --fixed-list-mode option but
|
||||
GPGSM stores the issuer name. */
|
||||
if (rectype == RT_CRT || rectype == RT_CRS)
|
||||
{
|
||||
key->issuer_name = xtrystrdup (p);
|
||||
if (!key->issuer_name)
|
||||
ctx->error = mk_error (Out_Of_Core);
|
||||
}
|
||||
if (_gpgme_decode_c_string (p, &key->issuer_name))
|
||||
ctx->error = mk_error (Out_Of_Core);
|
||||
break;
|
||||
case 11: /* signature class */
|
||||
break;
|
||||
|
@ -97,6 +97,8 @@ FILE *fopencookie (void *cookie, const char *opentype,
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
|
||||
|
||||
/*-- conversion.c --*/
|
||||
GpgmeError _gpgme_decode_c_string (const char *src, char **destp);
|
||||
int _gpgme_hextobyte (const byte *str);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user