diff options
author | Werner Koch <[email protected]> | 1998-07-08 09:29:43 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1998-07-08 09:29:43 +0000 |
commit | 5aed77d1dbd95a8a0be4d579fd023775ddc85223 (patch) | |
tree | e9b043aa908c90590b4d2f78639fd24b0a2b83c7 /g10/plaintext.c | |
parent | Added new key infos (diff) | |
download | gnupg-5aed77d1dbd95a8a0be4d579fd023775ddc85223.tar.gz gnupg-5aed77d1dbd95a8a0be4d579fd023775ddc85223.zip |
fixed clearsig stuff
Diffstat (limited to 'g10/plaintext.c')
-rw-r--r-- | g10/plaintext.c | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/g10/plaintext.c b/g10/plaintext.c index 161db58d4..8d7b2a97e 100644 --- a/g10/plaintext.c +++ b/g10/plaintext.c @@ -34,19 +34,61 @@ /**************** + * Defer the last CR,LF + */ +static void +special_md_putc( MD_HANDLE md, int c, int *state ) +{ + if( c == -1 ) { /* flush */ + if( *state == 1 ) { + md_putc(md, '\r'); + } + *state = 0; + return; + } + again: + switch( *state ) { + case 0: + if( c == '\r' ) + *state = 1; + else + md_putc(md, c ); + break; + case 1: + if( c == '\n' ) + *state = 2; + else { + md_putc(md, '\r'); + *state = 0; + goto again; + } + break; + case 2: + md_putc(md, '\r'); + md_putc(md, '\n'); + *state = 0; + goto again; + default: BUG(); + } +} + + +/**************** * Handle a plaintext packet. If MFX is not NULL, update the MDs * Note: we should use the filter stuff here, but we have to add some * easy mimic to set a read limit, so we calculate only the * bytes from the plaintext. */ int -handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput ) +handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, + int nooutput, int clearsig ) { char *fname = NULL; FILE *fp = NULL; int rc = 0; int c; int convert = pt->mode == 't'; + int special_state = 0; /* create the filename as C string */ if( nooutput ) @@ -86,10 +128,14 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput ) rc = G10ERR_READ_FILE; goto leave; } - if( mfx->md ) - md_putc(mfx->md, c ); + if( mfx->md ) { + if( convert && clearsig ) + special_md_putc(mfx->md, c, &special_state ); + else + md_putc(mfx->md, c ); + } if( convert && c == '\r' ) - continue; /* FIXME: this hack is too simple */ + continue; /* fixme: this hack might be too simple */ if( fp ) { if( putc( c, fp ) == EOF ) { log_error("Error writing to '%s': %s\n", @@ -102,10 +148,14 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput ) } else { while( (c = iobuf_get(pt->buf)) != -1 ) { - if( mfx->md ) - md_putc(mfx->md, c ); + if( mfx->md ) { + if( convert && clearsig ) + special_md_putc(mfx->md, c, &special_state ); + else + md_putc(mfx->md, c ); + } if( convert && c == '\r' ) - continue; /* FIXME: this hack is too simple */ + continue; /* fixme: this hack might be too simple */ if( fp ) { if( putc( c, fp ) == EOF ) { log_error("Error writing to '%s': %s\n", @@ -117,6 +167,8 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput ) } iobuf_clear_eof(pt->buf); } + if( mfx->md && convert && clearsig ) + special_md_putc(mfx->md, -1, &special_state ); /* flush */ if( fp && fp != stdout && fclose(fp) ) { log_error("Error closing '%s': %s\n", fname, strerror(errno) ); |