diff options
author | Werner Koch <[email protected]> | 2004-02-13 12:40:23 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2004-02-13 12:40:23 +0000 |
commit | 1a159fd8e383f69ad73e83491c396b1395385563 (patch) | |
tree | 2d2cfd70382ed24bd630a33718733ed121d43a7e /sm/base64.c | |
parent | Removed debugging cruft. (diff) | |
download | gnupg-1a159fd8e383f69ad73e83491c396b1395385563.tar.gz gnupg-1a159fd8e383f69ad73e83491c396b1395385563.zip |
* encrypt.c (init_dek): Check for too weak algorithms.
* import.c (parse_p12, popen_protect_tool): New.
* base64.c (gpgsm_create_reader): New arg ALLOW_MULTI_PEM.
Changed all callers.
(base64_reader_cb): Handle it here.
(gpgsm_reader_eof_seen): New.
(base64_reader_cb): Set a flag for EOF.
(simple_reader_cb): Ditto.
Diffstat (limited to '')
-rw-r--r-- | sm/base64.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/sm/base64.c b/sm/base64.c index 11237dcc1..4cc6ffa27 100644 --- a/sm/base64.c +++ b/sm/base64.c @@ -48,9 +48,10 @@ struct reader_cb_parm_s { int have_lf; unsigned long line_counter; - int autodetect; /* try to detect the input encoding */ - int assume_pem; /* assume input encoding is PEM */ - int assume_base64; /* assume input is base64 encoded */ + int allow_multi_pem; /* Allow processing of multiple PEM objects. */ + int autodetect; /* Try to detect the input encoding. */ + int assume_pem; /* Assume input encoding is PEM. */ + int assume_base64; /* Assume input is base64 encoded. */ int identified; int is_pem; @@ -58,6 +59,8 @@ struct reader_cb_parm_s { int stop_seen; int might_be_smime; + int eof_seen; + struct { int idx; unsigned char val; @@ -171,6 +174,7 @@ base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) c = getc (parm->fp); if (c == EOF) { + parm->eof_seen = 1; if (ferror (parm->fp)) return -1; break; @@ -268,7 +272,22 @@ base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) { parm->identified = 0; parm->linelen = parm->readpos = 0; - /* let us return 0 */ + + /* If the caller want to read multiple PEM objects from one + file, we have to reset our internal state and return a + EOF immediately. The caller is the expected to use + ksba_reader_clear to clear the EOF condition and continue + to read. If we don't want to do that we just return 0 + bytes which will force the ksba_reader to skip until + EOF. */ + if (parm->allow_multi_pem) + { + parm->identified = 0; + parm->autodetect = 0; + parm->assume_pem = 1; + parm->stop_seen = 0; + return -1; /* Send EOF now. */ + } } else if (parm->stop_seen) { /* skip the rest of the line */ @@ -356,6 +375,7 @@ simple_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) c = getc (parm->fp); if (c == EOF) { + parm->eof_seen = 1; if ( ferror (parm->fp) ) return -1; if (n) @@ -494,10 +514,13 @@ base64_finish_write (struct writer_cb_parm_s *parm) The function returns a Base64Context object which must be passed to the gpgme_destroy_reader function. The created KsbaReader object is also returned, but the caller must not call the - ksba_reader_release function on. */ + ksba_reader_release function on. If ALLOW_MULTI_PEM is true, the + reader expects that the caller uses ksba_reader_clear after EOF + until no more objects were found. */ int gpgsm_create_reader (Base64Context *ctx, - CTRL ctrl, FILE *fp, ksba_reader_t *r_reader) + CTRL ctrl, FILE *fp, int allow_multi_pem, + ksba_reader_t *r_reader) { int rc; ksba_reader_t r; @@ -506,6 +529,7 @@ gpgsm_create_reader (Base64Context *ctx, *ctx = xtrycalloc (1, sizeof **ctx); if (!*ctx) return OUT_OF_CORE (errno); + (*ctx)->u.rparm.allow_multi_pem = allow_multi_pem; rc = ksba_reader_new (&r); if (rc) @@ -546,6 +570,12 @@ gpgsm_create_reader (Base64Context *ctx, } +int +gpgsm_reader_eof_seen (Base64Context ctx) +{ + return ctx && ctx->u.rparm.eof_seen; +} + void gpgsm_destroy_reader (Base64Context ctx) { |