From 09fbf4d0a21c9cad25cc3f12b1e3f365f850eb94 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 24 Feb 2014 17:32:01 +0000 Subject: [PATCH] codec: New flag to ignore linear whitespace. Why was this missed the first time around? Set this by default in the `bincode' program. --- codec/baseconv.c | 31 +++++++++++++++++-------------- codec/bincode.1 | 4 +++- codec/bincode.c | 3 ++- codec/codec.3 | 5 +++++ codec/codec.h | 5 +++-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/codec/baseconv.c b/codec/baseconv.c index 1d50735..bdb850f 100644 --- a/codec/baseconv.c +++ b/codec/baseconv.c @@ -48,6 +48,7 @@ #define NV -1 /* Not valid */ #define PC -2 /* Padding character */ #define NL -3 /* Newline character */ +#define SP -4 /* Space character */ /* --- Base64 --- */ @@ -63,27 +64,27 @@ static const char "0123456789-_" }; static const signed char decodemap_base64[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, NV, 63, /* 2x */ + SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, NV, 63, /* 2x */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV, /* 3x */ NV, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 4x */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV, /* 5x */ NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40, /* 6x */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV /* 7x */ }, decodemap_file64[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, 63, NV, NV, NV, NV, NV, 62, NV, NV, NV, NV, /* 2x */ + SP, NV, NV, NV, NV, 63, NV, NV, NV, NV, NV, 62, NV, NV, NV, NV, /* 2x */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV, /* 3x */ NV, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 4x */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV, /* 5x */ NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40, /* 6x */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV /* 7x */ }, decodemap_base64url[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, /* 2x */ + SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, /* 2x */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV, /* 3x */ NV, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 4x */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, 63, /* 5x */ @@ -98,18 +99,18 @@ static const char encodemap_base32hex[] = { "0123456789ABCDEFGHIJKLMNOPQRSTUV" }; static const signed char decodemap_base32[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ + SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ NV, NV, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, PC, NV, NV, /* 3x */ NV, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 4x */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV, /* 5x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 6x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 7x */ }, decodemap_base32hex[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ + SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, NV, NV, NV, PC, NV, NV, /* 3x */ NV, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 4x */ 25, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 5x */ @@ -123,9 +124,9 @@ static const char encodemap_hex[] = { "0123456789ABCDEF" }; static const signed char decodemap_hex[] = { - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV, /* 0x */ + NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV, /* 0x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 1x */ - NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ + SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 2x */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, NV, NV, NV, NV, NV, NV, /* 3x */ NV, 10, 11, 12, 13, 14, 15, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 4x */ NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, /* 5x */ @@ -375,9 +376,11 @@ static int ctxn##_dodecode(ctxn##_ctx *ctx, \ case NL: \ if (f & CDCF_IGNNEWL) break; \ return (CDCERR_INVCH); \ + case SP: \ + if (f & CDCF_IGNSPC) break; \ + return (CDCERR_INVCH); \ default: \ - if (st != ST_MAIN) \ - return (CDCERR_INVEQPAD); \ + if (st != ST_MAIN) return (CDCERR_INVEQPAD); \ BASECONV(x, wd, 8, PUTRAW); \ break; \ } \ diff --git a/codec/bincode.1 b/codec/bincode.1 index 7914f75..4e828b7 100644 --- a/codec/bincode.1 +++ b/codec/bincode.1 @@ -54,7 +54,9 @@ prefix; e.g., may be specified as .RB ` ignnewl '. This option may be repeated: the options are scanned left-to-right. The -only flag set by default is +flags set by default are +.RB ` ignspc ' +and .RB ` ignnewl '. .TP .BI "\-i, \-\-indent=" indent diff --git a/codec/bincode.c b/codec/bincode.c index 0a7d5c5..af1e677 100644 --- a/codec/bincode.c +++ b/codec/bincode.c @@ -65,6 +65,7 @@ static const struct { const char *name; unsigned f; } flagtab[] = { { "igneqmid", CDCF_IGNEQMID }, { "ignzpad", CDCF_IGNZPAD }, { "ignnewl", CDCF_IGNNEWL }, + { "ignspc", CDCF_IGNSPC }, { "igninvch", CDCF_IGNINVCH }, { "ignjunk", CDCF_IGNJUNK }, { 0, 0, } @@ -139,7 +140,7 @@ int main(int argc, char *argv[]) const char *indent = ""; const char *imode, *omode, *ofile = 0; unsigned maxline = 64; - unsigned f = CDCF_IGNNEWL; + unsigned f = CDCF_IGNSPC | CDCF_IGNNEWL; const char *p; char *q; FILE *ifp, *ofp = stdout; diff --git a/codec/codec.3 b/codec/codec.3 index 96174f3..efc0b7e 100644 --- a/codec/codec.3 +++ b/codec/codec.3 @@ -122,6 +122,11 @@ Ignore newline (and carriage-return) characters when decoding: the default for RFC4648 codecs is to reject newline characters. If these characters are significant in the encoding, then this flag is ignored. .TP +.B CDCF_IGNSPC +Ignore whitespace characters (other than newlines) when decoding: the +default for RFC4648 codecs is to reject whitespace characters. If these +characters are significant in the encoding, then this flag is ignored. +.TP .B CDCF_IGNINVCH Ignore any other invalid characters appearing in the input when decoding. diff --git a/codec/codec.h b/codec/codec.h index 2c3e694..6155d5a 100644 --- a/codec/codec.h +++ b/codec/codec.h @@ -58,10 +58,11 @@ typedef struct codec_class { #define CDCF_IGNZPAD 32u /* Ignore zero padding on input */ #define CDCF_IGNNEWL 64u /* Ignore newlines on input */ #define CDCF_IGNINVCH 128u /* Ignore invalid chars on input */ +#define CDCF_IGNSPC 256u /* Ignore whitespace on input */ -#define CDCF_IGNJUNK /* Ignore all bad things */ \ +#define CDCF_IGNJUNK /* Ignore all bad things */ \ (CDCF_IGNEQMID | CDCF_IGNZPAD | \ - CDCF_IGNCASE | CDCF_IGNNEWL | CDCF_IGNINVCH) + CDCF_IGNCASE | CDCF_IGNNEWL | CDCF_IGNSPC | CDCF_IGNINVCH) } codec_class; -- 2.11.0