[OpenPGP:SDK svn] r328 - openpgpsdk/trunk/src

Subversion ben at algroup.co.uk
Thu Jan 5 14:21:07 GMT 2006


Author: ben
Date: 2006-01-05 14:21:07 +0000 (Thu, 05 Jan 2006)
New Revision: 328

Modified:
   openpgpsdk/trunk/src/armour.c
Log:
More whitespace leniency.


Modified: openpgpsdk/trunk/src/armour.c
===================================================================
--- openpgpsdk/trunk/src/armour.c	2006-01-05 13:57:53 UTC (rev 327)
+++ openpgpsdk/trunk/src/armour.c	2006-01-05 14:21:07 UTC (rev 328)
@@ -69,7 +69,8 @@
     }
     
 static int read_char(dearmour_arg_t *arg,ops_error_t **errors,
-		     ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo,
+		     ops_reader_info_t *rinfo,
+		     ops_parse_cb_info_t *cbinfo,
 		     ops_boolean_t skip)
     {
     unsigned char c[1];
@@ -98,6 +99,35 @@
     return c[0];
     }
 
+static int eat_whitespace(int first,
+			  dearmour_arg_t *arg,ops_error_t **errors,
+			  ops_reader_info_t *rinfo,
+			  ops_parse_cb_info_t *cbinfo,
+			  ops_boolean_t skip)
+    {
+    int c=first;
+
+    while(c == ' ' || c == '\t')
+	c=read_char(arg,errors,rinfo,cbinfo,skip);
+
+    return c;
+    }
+
+static int read_and_eat_whitespace(dearmour_arg_t *arg,
+				   ops_error_t **errors,
+				   ops_reader_info_t *rinfo,
+				   ops_parse_cb_info_t *cbinfo,
+				   ops_boolean_t skip)
+    {
+    int c;
+
+    do
+	c=read_char(arg,errors,rinfo,cbinfo,skip);
+    while(c == ' ' || c == '\t');
+
+    return c;
+    }
+
 static void flush(dearmour_arg_t *arg,ops_parse_cb_info_t *cbinfo)
     {
     ops_parser_content_t content;
@@ -441,7 +471,7 @@
 	{
 	// then we saw padding
 	assert(c == '=');
-	c=read_char(arg,errors,rinfo,cbinfo,ops_true);
+	c=read_and_eat_whitespace(arg,errors,rinfo,cbinfo,ops_true);
 	if(c != '\n')
 	    ERR(cbinfo,"No newline at base64 end");
 	c=read_char(arg,errors,rinfo,cbinfo,ops_false);
@@ -457,8 +487,7 @@
 	    ERR(cbinfo,"Error in checksum");
 	c=read_char(arg,errors,rinfo,cbinfo,ops_true);
 	if(arg->allow_trailing_whitespace)
-	    while(c == ' ' || c == '\t')
-		c=read_char(arg,errors,rinfo,cbinfo,ops_true);
+	    c=eat_whitespace(c,arg,errors,rinfo,cbinfo,ops_true);
 	if(c != '\n')
 	    ERR(cbinfo,"Badly terminated checksum");
 	c=read_char(arg,errors,rinfo,cbinfo,ops_false);
@@ -580,10 +609,9 @@
 	     if((c=unarmoured_read_char(arg,errors,rinfo,cbinfo,ops_true)) < 0)
 		 return OPS_R_EOF;
 	     if(arg->allow_trailing_whitespace)
-		 while(c == ' ' || c == '\t')
-		     if((c=unarmoured_read_char(arg,errors,rinfo,cbinfo,
-						ops_true)) < 0)
-			 return OPS_R_EOF;
+		 if((c=eat_whitespace(c,arg,errors,rinfo,cbinfo,
+				      ops_true)) < 0)
+		    return OPS_R_EOF;
 	     if(c != '\n')
 		 /* wasn't a header line after all */
 		 break;
@@ -680,6 +708,10 @@
 	     /* Consume final NL */
 	     if((c=read_char(arg,errors,rinfo,cbinfo,ops_true)) < 0)
 		 return OPS_R_EARLY_EOF;
+	     if(arg->allow_trailing_whitespace)
+		 if((c=eat_whitespace(c,arg,errors,rinfo,cbinfo,
+				      ops_true)) < 0)
+		    return OPS_R_EOF;
 	     if(c != '\n')
 		 /* wasn't a trailer line after all */
 		 ERR(cbinfo,"Bad ASCII armour trailer (3)");



More information about the OpenPGPsdk-svn mailing list