1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-21 10:09:57 +01:00

Use gpgrt_b64* API of libgpg-error.

* common/Makefile.am (common_sources): Remove b64enc.c and b64dec.c.
(module_maint_tests): Remove t-b64.
(t_b64_LDADD): Remove.
* common/util.h: Remove the internal API.
* common/ssh-utils.c (get_fingerprint): Use the gpgrt_b64 API.
(ssh_public_key_in_base64): Likewise.
* dirmngr/crlfetch.c (my_es_read, crl_close_reader): Likewise.
* dirmngr/dirmngr-client.c (data_cb, do_lookup): Likewise.
* dirmngr/misc.c (armor_data): Likewise.
* g10/export.c (export_one_ssh_key, export_secret_ssh_key): Likewise.
* tools/gpg-card.c (cmd_writecert): Likewise.
* tools/mime-parser.c (parse_message_cb, mime_parser_release)
(process_part_data): Likewise.
* tools/wks-util.c (wks_armor_key): Likewise.

--

GnuPG-bug-id: 6734
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2023-09-26 13:34:50 +09:00
parent 34f812475e
commit 26939ea222
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
10 changed files with 75 additions and 99 deletions

View File

@ -65,7 +65,7 @@ common_sources = \
homedir.c \
gettime.c gettime.h \
yesno.c \
b64enc.c b64dec.c zb32.c zb32.h \
zb32.c zb32.h \
convert.c \
percent.c \
mbox-util.c mbox-util.h \
@ -169,7 +169,7 @@ module_tests += t-exectool
endif
if MAINTAINER_MODE
module_maint_tests = t-helpfile t-b64
module_maint_tests = t-helpfile
else
module_maint_tests =
endif
@ -196,7 +196,6 @@ t_gettime_LDADD = $(t_common_ldadd)
t_sysutils_LDADD = $(t_common_ldadd)
t_helpfile_LDADD = $(t_common_ldadd)
t_sexputil_LDADD = $(t_common_ldadd)
t_b64_LDADD = $(t_common_ldadd)
t_exechelp_LDADD = $(t_common_ldadd)
t_exectool_LDADD = $(t_common_ldadd)
t_session_env_LDADD = $(t_common_ldadd)

View File

@ -259,7 +259,7 @@ get_fingerprint (gcry_sexp_t key, int algo,
}
else
{
struct b64state b64s;
gpgrt_b64state_t b64s;
estream_t stream;
char *p;
long int len;
@ -273,15 +273,15 @@ get_fingerprint (gcry_sexp_t key, int algo,
goto leave;
}
err = b64enc_start_es (&b64s, stream, "");
if (err)
b64s = gpgrt_b64enc_start (stream, "");
if (!b64s)
{
es_fclose (stream);
goto leave;
}
err = b64enc_write (&b64s,
gcry_md_read (md, algo), gcry_md_get_algo_dlen (algo));
err = gpgrt_b64enc_write (b64s, gcry_md_read (md, algo),
gcry_md_get_algo_dlen (algo));
if (err)
{
es_fclose (stream);
@ -289,7 +289,7 @@ get_fingerprint (gcry_sexp_t key, int algo,
}
/* Finish, get the length, and close the stream. */
err = b64enc_finish (&b64s);
err = gpgrt_b64enc_finish (b64s);
len = es_ftell (stream);
es_fclose (stream);
if (err)
@ -566,7 +566,7 @@ ssh_public_key_in_base64 (gcry_sexp_t key, estream_t stream,
const char *identifier = NULL;
void *blob = NULL;
size_t bloblen;
struct b64state b64_state;
gpgrt_b64state_t b64_state;
algo = get_pk_algo_from_key (key);
if (algo == 0)
@ -624,15 +624,15 @@ ssh_public_key_in_base64 (gcry_sexp_t key, estream_t stream,
es_fprintf (stream, "%s ", identifier);
err = b64enc_start_es (&b64_state, stream, "");
if (err)
b64_state = gpgrt_b64enc_start (stream, "");
if (!b64_state)
{
es_free (blob);
return err;
return gpg_error_from_syserror ();
}
err = b64enc_write (&b64_state, blob, bloblen);
b64enc_finish (&b64_state);
err = gpgrt_b64enc_write (b64_state, blob, bloblen);
gpgrt_b64enc_finish (b64_state);
es_free (blob);
if (err)
return err;

View File

@ -143,35 +143,6 @@ ssize_t read_line (FILE *fp,
char **addr_of_buffer, size_t *length_of_buffer,
size_t *max_length);
/*-- b64enc.c and b64dec.c --*/
struct b64state
{
unsigned int flags;
int idx;
int quad_count;
FILE *fp;
estream_t stream;
char *title;
unsigned char radbuf[4];
u32 crc;
int stop_seen:1;
int invalid_encoding:1;
gpg_error_t lasterr;
};
gpg_error_t b64enc_start (struct b64state *state, FILE *fp, const char *title);
gpg_error_t b64enc_start_es (struct b64state *state, estream_t fp,
const char *title);
gpg_error_t b64enc_write (struct b64state *state,
const void *buffer, size_t nbytes);
gpg_error_t b64enc_finish (struct b64state *state);
gpg_error_t b64dec_start (struct b64state *state, const char *title);
gpg_error_t b64dec_proc (struct b64state *state, void *buffer, size_t length,
size_t *r_nbytes);
gpg_error_t b64dec_finish (struct b64state *state);
/*-- sexputil.c */
char *canon_sexp_to_string (const unsigned char *canon, size_t canonlen);
void log_printcanon (const char *text,

View File

@ -39,10 +39,10 @@
2008) we need a context in the reader callback. */
struct reader_cb_context_s
{
estream_t fp; /* The stream used with the ksba reader. */
int checked:1; /* PEM/binary detection ahs been done. */
int is_pem:1; /* The file stream is PEM encoded. */
struct b64state b64state; /* The state used for Base64 decoding. */
estream_t fp; /* The stream used with the ksba reader. */
unsigned int checked:1; /* PEM/binary detection ahs been done. */
unsigned int is_pem:1; /* The file stream is PEM encoded. */
gpgrt_b64state_t b64state; /* The state used for Base64 decoding. */
};
@ -126,14 +126,16 @@ my_es_read (void *opaque, char *buffer, size_t nbytes, size_t *nread)
else
{
cb_ctx->is_pem = 1;
b64dec_start (&cb_ctx->b64state, "");
cb_ctx->b64state = gpgrt_b64dec_start ("");
if (!cb_ctx->b64state)
return gpg_error_from_syserror ();
}
}
if (cb_ctx->is_pem && *nread)
{
size_t nread2;
if (b64dec_proc (&cb_ctx->b64state, buffer, *nread, &nread2))
if (gpgrt_b64dec_proc (cb_ctx->b64state, buffer, *nread, &nread2))
{
/* EOF from decoder. */
*nread = 0;
@ -581,7 +583,7 @@ crl_close_reader (ksba_reader_t reader)
es_fclose (cb_ctx->fp);
/* Release the base64 decoder state. */
if (cb_ctx->is_pem)
b64dec_finish (&cb_ctx->b64state);
gpgrt_b64dec_finish (cb_ctx->b64state);
/* Release the callback context. */
xfree (cb_ctx);
}

View File

@ -441,11 +441,11 @@ static gpg_error_t
data_cb (void *opaque, const void *buffer, size_t length)
{
gpg_error_t err;
struct b64state *state = opaque;
gpgrt_b64state_t state = opaque;
if (buffer)
{
err = b64enc_write (state, buffer, length);
err = gpgrt_b64enc_write (state, buffer, length);
if (err)
log_error (_("error writing base64 encoding: %s\n"),
gpg_strerror (err));
@ -853,14 +853,14 @@ do_lookup (assuan_context_t ctx, const char *pattern)
gpg_error_t err;
const unsigned char *s;
char *line, *p;
struct b64state state;
gpgrt_b64state_t state;
if (opt.verbose)
log_info (_("looking up '%s'\n"), pattern);
err = b64enc_start (&state, stdout, NULL);
if (err)
return err;
state = gpgrt_b64enc_start (es_stdout, NULL);
if (!state)
return gpg_error_from_syserror ();
line = xmalloc (10 + 6 + 13 + strlen (pattern)*3 + 1);
@ -885,13 +885,13 @@ do_lookup (assuan_context_t ctx, const char *pattern)
err = assuan_transact (ctx, line,
data_cb, &state,
data_cb, state,
NULL, NULL,
status_cb, NULL);
if (opt.verbose > 1)
log_info ("response of dirmngr: %s\n", err? gpg_strerror (err): "okay");
err = b64enc_finish (&state);
err = gpgrt_b64enc_finish (state);
xfree (line);
return err;

View File

@ -583,7 +583,7 @@ gpg_error_t
armor_data (char **r_string, const void *data, size_t datalen)
{
gpg_error_t err;
struct b64state b64state;
gpgrt_b64state_t b64state;
estream_t fp;
long length;
char *buffer;
@ -595,9 +595,15 @@ armor_data (char **r_string, const void *data, size_t datalen)
if (!fp)
return gpg_error_from_syserror ();
if ((err=b64enc_start_es (&b64state, fp, "PGP PUBLIC KEY BLOCK"))
|| (err=b64enc_write (&b64state, data, datalen))
|| (err = b64enc_finish (&b64state)))
b64state = gpgrt_b64enc_start (fp, "PGP PUBLIC KEY BLOCK");
if (!b64state)
{
es_fclose (fp);
return gpg_error_from_syserror ();
}
if ((err = gpgrt_b64enc_write (b64state, data, datalen))
|| (err = gpgrt_b64enc_finish (b64state)))
{
es_fclose (fp);
return err;

View File

@ -2706,18 +2706,18 @@ export_one_ssh_key (estream_t fp, PKT_public_key *pk)
blob = get_membuf (&mb, &bloblen);
if (blob)
{
struct b64state b64_state;
gpgrt_b64state_t b64_state;
es_fprintf (fp, "%s ", identifier);
err = b64enc_start_es (&b64_state, fp, "");
if (err)
b64_state = gpgrt_b64enc_start (fp, "");
if (!b64_state)
{
xfree (blob);
goto leave;
}
err = b64enc_write (&b64_state, blob, bloblen);
b64enc_finish (&b64_state);
err = gpgrt_b64enc_write (b64_state, blob, bloblen);
gpgrt_b64enc_finish (b64_state);
es_fprintf (fp, " openpgp:0x%08lX\n", (ulong)keyid_from_pk (pk, NULL));
xfree (blob);
@ -2961,7 +2961,7 @@ export_secret_ssh_key (ctrl_t ctrl, const char *userid)
int pkalgo;
int i;
gcry_mpi_t keyparam[10] = { NULL };
struct b64state b64_state;
gpgrt_b64state_t b64_state;
init_membuf_secure (&mb, 1024);
init_membuf_secure (&mb2, 1024);
@ -3139,11 +3139,11 @@ export_secret_ssh_key (ctrl_t ctrl, const char *userid)
goto leave;
}
err = b64enc_start_es (&b64_state, fp, "OPENSSH PRIVATE_KEY");
if (err)
b64_state = gpgrt_b64enc_start (fp, "OPENSSH PRIVATE_KEY");
if (!b64_state)
goto leave;
err = b64enc_write (&b64_state, blob, bloblen);
b64enc_finish (&b64_state);
err = gpgrt_b64enc_write (b64_state, blob, bloblen);
gpgrt_b64enc_finish (b64_state);
if (err)
goto leave;

View File

@ -2080,13 +2080,15 @@ cmd_writecert (card_info_t info, char *argstr)
&& ascii_memistr (data, datalen, "-----END CERTIFICATE-----")
&& !memchr (data, 0, datalen) && !memchr (data, 1, datalen))
{
struct b64state b64;
gpgrt_b64state_t b64;
err = b64dec_start (&b64, "");
b64 = gpgrt_b64dec_start ("");
if (!b64)
err = gpg_error_from_syserror ();
else
err = gpgrt_b64dec_proc (b64, data, datalen, &datalen);
if (!err)
err = b64dec_proc (&b64, data, datalen, &datalen);
if (!err)
err = b64dec_finish (&b64);
err = gpgrt_b64dec_finish (b64);
if (err)
goto leave;
}

View File

@ -93,7 +93,7 @@ struct mime_parser_context_s
unsigned int boundary : 1;
} show;
struct b64state *b64state; /* NULL or malloced Base64 decoder state. */
gpgrt_b64state_t b64state; /* NULL or malloced Base64 decoder state. */
/* A buffer for reading a mail line, */
char line[5000];
@ -410,15 +410,11 @@ parse_message_cb (void *opaque, rfc822parse_event_t event, rfc822parse_t msg)
{
ctx->decode_part = 2;
if (ctx->b64state)
b64dec_finish (ctx->b64state); /* Reuse state. */
else
{
ctx->b64state = xtrymalloc (sizeof *ctx->b64state);
if (!ctx->b64state)
rc = gpg_error_from_syserror ();
}
if (!rc)
rc = b64dec_start (ctx->b64state, NULL);
gpgrt_b64dec_finish (ctx->b64state); /* Release. */
ctx->b64state = gpgrt_b64dec_start (NULL);
if (!ctx->b64state)
rc = gpg_error_from_syserror ();
}
free (value); /* Right, we need a plain free. */
}
@ -528,10 +524,7 @@ mime_parser_release (mime_parser_t ctx)
return;
if (ctx->b64state)
{
b64dec_finish (ctx->b64state);
xfree (ctx->b64state);
}
gpgrt_b64dec_finish (ctx->b64state);
xfree (ctx);
}
@ -661,7 +654,7 @@ process_part_data (mime_parser_t ctx, char *line, size_t *length)
else if (ctx->decode_part == 2)
{
log_assert (ctx->b64state);
err = b64dec_proc (ctx->b64state, line, *length, &nbytes);
err = gpgrt_b64dec_proc (ctx->b64state, line, *length, &nbytes);
if (err)
return err;
*length = nbytes;

View File

@ -598,7 +598,7 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix)
{
gpg_error_t err;
estream_t newkey;
struct b64state b64state;
gpgrt_b64state_t b64state;
char buffer[4096];
size_t nread;
@ -614,16 +614,19 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix)
if (prefix)
es_fputs (prefix, newkey);
err = b64enc_start_es (&b64state, newkey, "PGP PUBLIC KEY BLOCK");
if (err)
goto leave;
b64state = gpgrt_b64enc_start (newkey, "PGP PUBLIC KEY BLOCK");
if (!b64state)
{
err = gpg_error_from_syserror ();
goto leave;
}
do
{
nread = es_fread (buffer, 1, sizeof buffer, key);
if (!nread)
break;
err = b64enc_write (&b64state, buffer, nread);
err = gpgrt_b64enc_write (b64state, buffer, nread);
if (err)
goto leave;
}
@ -634,7 +637,7 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix)
goto leave;
}
err = b64enc_finish (&b64state);
err = gpgrt_b64enc_finish (b64state);
if (err)
goto leave;