diff options
author | Werner Koch <wk@gnupg.org> | 2001-12-20 14:25:08 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2001-12-20 14:25:08 +0100 |
commit | 5f116e95400453a6053b9b631eccc6d224b01cc9 (patch) | |
tree | 4f142116fa01e042d72bea79b1d59efba6fd2ec4 /sm/base64.c | |
parent | * keybox-blob.c (_keybox_create_x509_blob): Skip the leading (diff) | |
download | gnupg2-5f116e95400453a6053b9b631eccc6d224b01cc9.tar.xz gnupg2-5f116e95400453a6053b9b631eccc6d224b01cc9.zip |
* base64.c (base64_reader_cb): Try to detect an S/MIME body part.
* certdump.c (print_sexp): Renamed to gpgsm_dump_serial, made
global.
(print_time): Renamed to gpgsm_dump_time, made global.
(gpgsm_dump_serial): Take a real S-Expression as argument and
print the first item.
* keylist.c (list_cert_colon): Ditto.
* keydb.c (keydb_search_issuer_sn): Ditto.
* decrypt.c (print_integer_sexp): Removed and made callers
use gpgsm_dump_serial.
* verify.c (print_time): Removed, made callers use gpgsm_dump_time.
Diffstat (limited to 'sm/base64.c')
-rw-r--r-- | sm/base64.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/sm/base64.c b/sm/base64.c index 4d1620975..b53009b85 100644 --- a/sm/base64.c +++ b/sm/base64.c @@ -49,12 +49,13 @@ struct reader_cb_parm_s { int autodetect; /* try to detect the input encoding */ int assume_pem; /* assume input encoding is PEM */ - int assume_base64; /* assume inpout is base64 encoded */ + int assume_base64; /* assume input is base64 encoded */ int identified; int is_pem; int is_base64; int stop_seen; + int might_be_smime; struct { int idx; @@ -121,6 +122,31 @@ static unsigned char asctobin[256] = { }; +static int +has_only_base64 (const unsigned char *line, int linelen) +{ + if (linelen < 20) + return 0; + for (; linelen; line++, linelen--) + { + if (*line == '\n' || (linelen > 1 && *line == '\r' && line[1] == '\n')) + break; + if ( !strchr (bintoasc, *line) ) + return 0; + } + return 1; /* yes */ +} + +static int +is_empty_line (const unsigned char *line, int linelen) +{ + if (linelen >= 2 && *line == '\r' && line[1] == '\n') + return 1; + if (linelen >= 1 && *line == '\n') + return 1; + return 0; +} + static int base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) @@ -197,6 +223,30 @@ base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) parm->is_pem = 1; parm->linelen = parm->readpos = 0; } + else if ( parm->have_lf && parm->line_counter == 1 + && !strncmp (parm->line, "Content-Type:", 13)) + { /* Might be a S/MIME body */ + parm->might_be_smime = 1; + parm->linelen = parm->readpos = 0; + goto next; + } + else if (parm->might_be_smime == 1 + && is_empty_line (parm->line, parm->linelen)) + { + parm->might_be_smime = 2; + parm->linelen = parm->readpos = 0; + goto next; + } + else if (parm->might_be_smime == 2) + { + parm->might_be_smime = 0; + if ( !has_only_base64 (parm->line, parm->linelen)) + { + parm->linelen = parm->readpos = 0; + goto next; + } + parm->is_pem = 1; + } else { parm->linelen = parm->readpos = 0; |