Changeset 225
- Timestamp:
- 10/08/05 18:25:43
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (7 diffs)
- openpgpsdk/trunk/include/packet-parse.h (modified) (1 diff)
- openpgpsdk/trunk/include/packet.h (modified) (3 diffs)
- openpgpsdk/trunk/src/armour.c (modified) (22 diffs)
- openpgpsdk/trunk/src/packet-parse.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r221 r225 20 20 { 21 21 int i=0; 22 for(i=0 ; i<indent ; i++) 22 23 for(i=0 ; i < indent ; i++) 23 24 printf(" "); 24 25 } … … 116 117 } 117 118 118 static void print_hexdump( char *name,119 static void print_hexdump(const char *name, 119 120 const unsigned char *data, 120 121 unsigned int len) … … 127 128 } 128 129 129 static void print_hexdump_data( char *name,130 const unsigned char *data,131 unsigned int len)130 static void print_hexdump_data(const char *name, 131 const unsigned char *data, 132 unsigned int len) 132 133 { 133 134 print_name(name); … … 138 139 } 139 140 140 static void print_data( char *name,const ops_data_t *data)141 { 142 print_hexdump( name, data->contents,data->len);143 } 144 145 146 static void print_boolean(c har *name, unsigned char bool)141 static void print_data(const char *name,const ops_data_t *data) 142 { 143 print_hexdump(name,data->contents,data->len); 144 } 145 146 147 static void print_boolean(const char *name, unsigned char bool) 147 148 { 148 149 print_name(name); … … 155 156 } 156 157 157 static void print_tagname(c har *str)158 static void print_tagname(const char *str) 158 159 { 159 160 print_indent(); … … 175 176 } 176 177 177 static void print_unsigned_int( char *name, unsigned int val) 178 static void print_block(const char *name,const unsigned char *str, 179 size_t length) 180 { 181 int o=length; 182 183 print_indent(); 184 printf(">>>>> %s >>>>>\n",name); 185 186 print_indent(); 187 for( ; length > 0 ; --length) 188 { 189 if(*str >= 0x20 && *str < 0x7f && *str != '%') 190 putchar(*str); 191 else if(*str == '\n') 192 { 193 putchar(*str); 194 print_indent(); 195 } 196 else 197 printf("%%%02x",*str); 198 ++str; 199 } 200 if(o && str[-1] != '\n') 201 { 202 putchar('\n'); 203 print_indent(); 204 fputs("[no newline]",stdout); 205 } 206 else 207 print_indent(); 208 printf("<<<<< %s <<<<<\n",name); 209 } 210 211 static void print_unsigned_int(char *name, unsigned int val) 178 212 { 179 213 print_name(name); … … 741 775 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 742 776 print_tagname("SIGNED CLEARTEXT BODY"); 743 printf("----------------\n%.*s\n----------------\n", 744 (int)content->signed_cleartext_body.length, 745 content->signed_cleartext_body.data); 777 print_block("signed cleartext",content->signed_cleartext_body.data, 778 content->signed_cleartext_body.length); 779 break; 780 781 case OPS_PTAG_CT_UNARMOURED_TEXT: 782 print_tagname("UNARMOURED TEXT"); 783 print_block("unarmoured text",content->unarmoured_text.data, 784 content->unarmoured_text.length); 785 break; 786 787 case OPS_PTAG_CT_ARMOUR_TRAILER: 788 print_tagname("ARMOUR TRAILER"); 789 print_string("type",content->armour_header.type); 746 790 break; 747 791 openpgpsdk/trunk/include/packet-parse.h
r221 r225 26 26 OPS_R_OK =0, /*!< success */ 27 27 OPS_R_EOF =1, /*!< reached end of file, no data has been returned */ 28 OPS_R_EARLY_EOF =2, /*!< could not read the requested amount of bytes and OPS_RETURN_LENGTH was not set and at least 1 byte was read */ 28 OPS_R_EARLY_EOF =2, /*!< could not read the requested 29 number of bytes and either 30 OPS_RETURN_LENGTH was not set and at 31 least 1 byte was read, or there was 32 an abnormal end to the file (or 33 armoured block) */ 29 34 OPS_R_PARTIAL_READ =3, /*!< if OPS_RETURN_LENGTH is set and the buffer was not filled */ 35 _OPS_R_BLOCK_END =4, /*!< the end of an armoured block 36 [interal use only] */ 30 37 }; 31 38 openpgpsdk/trunk/include/packet.h
r221 r225 195 195 OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER =0x300+6, 196 196 OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY =0x300+7, 197 OPS_PTAG_CT_UNARMOURED_TEXT =0x300+8, 197 198 }; 198 199 … … 690 691 unsigned char data[8192]; 691 692 } ops_signed_cleartext_body_t; 693 694 typedef struct 695 { 696 unsigned length; 697 unsigned char *data; 698 } ops_unarmoured_text_t; 692 699 693 700 typedef union … … 732 739 ops_signed_cleartext_header_t signed_cleartext_header; 733 740 ops_signed_cleartext_body_t signed_cleartext_body; 741 ops_unarmoured_text_t unarmoured_text; 734 742 } ops_parser_content_union_t; 735 743 openpgpsdk/trunk/src/armour.c
r224 r225 27 27 ops_boolean_t eof64; 28 28 unsigned long checksum; 29 // unarmoured text blocks 30 unsigned char unarmoured[8192]; 31 size_t num_unarmoured; 29 32 } dearmour_arg_t; 30 33 … … 56 59 57 60 return c[0]; 58 } 61 } 62 63 static void flush(dearmour_arg_t *arg) 64 { 65 ops_parser_content_t content; 66 67 content.content.unarmoured_text.data=arg->unarmoured; 68 content.content.unarmoured_text.length=arg->num_unarmoured; 69 CB(OPS_PTAG_CT_UNARMOURED_TEXT,&content); 70 arg->num_unarmoured=0; 71 } 72 73 static int unarmoured_read_char(dearmour_arg_t *arg,ops_boolean_t skip) 74 { 75 int c; 76 77 do 78 { 79 c=read_char(arg,ops_false); 80 if(c < 0) 81 return c; 82 arg->unarmoured[arg->num_unarmoured++]=c; 83 if(arg->num_unarmoured == sizeof arg->unarmoured) 84 flush(arg); 85 } 86 while(skip && c == '\r'); 87 88 return c; 89 } 59 90 60 91 static ops_reader_ret_t process_dash_escaped(dearmour_arg_t *arg) … … 70 101 71 102 if((c=read_char(arg,ops_false)) < 0) 72 return OPS_R_E OF;103 return OPS_R_EARLY_EOF; 73 104 if(arg->prev_nl && c == '-') 74 105 { 75 106 if((c=read_char(arg,ops_false)) < 0) 76 return OPS_R_E OF;107 return OPS_R_EARLY_EOF; 77 108 if(c != ' ') 78 109 { … … 83 114 { 84 115 if((c=read_char(arg,ops_false)) < 0) 85 return OPS_R_E OF;116 return OPS_R_EARLY_EOF; 86 117 if(c != '-') 87 118 ERR("Bad dash-escaping (2)"); … … 92 123 /* otherwise we read the next character */ 93 124 if((c=read_char(arg,ops_false)) < 0) 94 return OPS_R_E OF;125 return OPS_R_EARLY_EOF; 95 126 } 96 127 body->data[body->length++]=c; … … 139 170 { 140 171 arg->eof64=ops_true; 141 return OPS_R_E OF;172 return OPS_R_EARLY_EOF; 142 173 } 143 174 if(c == '-') … … 187 218 { 188 219 arg->buffered=2; 220 arg->eof64=ops_true; 189 221 l >>= 2; 190 222 } … … 228 260 if(l != arg->checksum) 229 261 ERR("Checksum mismatch"); 262 c=read_char(arg,ops_true); 263 if(c != '\n') 264 ERR("Badly terminated checksum"); 265 c=read_char(arg,ops_false); 266 if(c != '-') 267 ERR("Bad base64 trailer (2)"); 230 268 } 231 269 … … 249 287 250 288 arg->checksum ^= arg->buffer[n] << 16; 251 for (i = 0; i < 8; i++)289 for(i=0 ; i < 8 ; i++) 252 290 { 253 291 arg->checksum <<= 1; … … 262 300 263 301 // This reader is rather strange in that it can generate callbacks for 264 // content - this is because plaintext is not encapsulated in PGP packets... 302 // content - this is because plaintext is not encapsulated in PGP 303 // packets... it also calls back for the text between the blocks. 265 304 266 305 static ops_reader_ret_t armoured_data_reader(unsigned char *dest, … … 273 312 ops_parser_content_t content; 274 313 ops_reader_ret_t ret; 314 ops_boolean_t first; 315 316 if(arg->eof64 && !arg->buffered) 317 return _OPS_R_BLOCK_END; 275 318 276 319 while(length > 0) … … 284 327 { 285 328 case OUTSIDE_BLOCK: 329 /* This code returns EOF rather than EARLY_EOF because if 330 we don't see a header line at all, then it is just an 331 EOF (and not a BLOCK_END) */ 286 332 while(!arg->seen_nl) 287 if((c= read_char(arg,ops_true)) < 0)333 if((c=unarmoured_read_char(arg,ops_true)) < 0) 288 334 return OPS_R_EOF; 289 335 336 /* flush at this point so we definitely have room for the 337 header, and so we can easily erase it from the buffer */ 338 flush(arg); 290 339 /* Find and consume the 5 leading '-' */ 291 for(count=0 ; count < 5 ; )292 { 293 if((c= read_char(arg,ops_false)) < 0)340 for(count=0 ; count < 5 ; ++count) 341 { 342 if((c=unarmoured_read_char(arg,ops_false)) < 0) 294 343 return OPS_R_EOF; 295 if(c == '-') 296 ++count; 297 else 298 count=0; 344 if(c != '-') 345 goto reloop; 299 346 } 300 347 … … 302 349 for(n=0 ; n < sizeof buf-1 ; ) 303 350 { 304 if((c= read_char(arg,ops_false)) < 0)351 if((c=unarmoured_read_char(arg,ops_false)) < 0) 305 352 return OPS_R_EOF; 306 353 if(c == '-') … … 317 364 for(count=1 ; count < 5 ; ++count) 318 365 { 319 if((c= read_char(arg,ops_false)) < 0)366 if((c=unarmoured_read_char(arg,ops_false)) < 0) 320 367 return OPS_R_EOF; 321 368 if(c != '-') … … 325 372 326 373 /* Consume final NL */ 327 if((c= read_char(arg,ops_true)) < 0)374 if((c=unarmoured_read_char(arg,ops_true)) < 0) 328 375 return OPS_R_EOF; 329 376 if(c != '\n') … … 331 378 break; 332 379 380 /* Now we've seen the header, scrub it from the buffer */ 381 arg->num_unarmoured=0; 382 383 /* But now we've seen a header line, then errors are 384 EARLY_EOF */ 333 385 if(!parse_headers(arg)) 334 return OPS_R_E OF;386 return OPS_R_EARLY_EOF; 335 387 336 388 if(!strcmp(buf,"BEGIN PGP SIGNED MESSAGE")) … … 352 404 353 405 case BASE64: 406 first=ops_true; 354 407 while(length > 0) 355 408 { 356 409 if(!arg->buffered) 357 410 { 358 if(arg->eof64) 359 return OPS_R_EOF; 360 ret=decode64(arg); 361 if(ret != OPS_R_OK) 362 return ret; 411 if(!arg->eof64) 412 { 413 ret=decode64(arg); 414 if(ret != OPS_R_OK) 415 return ret; 416 } 363 417 if(!arg->buffered) 364 return OPS_R_EOF; 418 { 419 assert(arg->eof64); 420 if(first) 421 { 422 arg->state=AT_TRAILER_NAME; 423 break; 424 } 425 return OPS_R_EARLY_EOF; 426 } 365 427 } 366 428 … … 369 431 ++dest; 370 432 --length; 433 first=ops_false; 371 434 } 372 435 break; … … 376 439 { 377 440 if((c=read_char(arg,ops_false)) < 0) 378 return OPS_R_E OF;441 return OPS_R_EARLY_EOF; 379 442 if(c == '-') 380 443 goto got_minus2; … … 392 455 { 393 456 if((c=read_char(arg,ops_false)) < 0) 394 return OPS_R_E OF;457 return OPS_R_EARLY_EOF; 395 458 if(c != '-') 396 459 /* wasn't a trailer after all */ … … 400 463 /* Consume final NL */ 401 464 if((c=read_char(arg,ops_true)) < 0) 402 return OPS_R_E OF;465 return OPS_R_EARLY_EOF; 403 466 if(c != '\n') 404 467 /* wasn't a trailer line after all */ … … 408 471 { 409 472 if(!parse_headers(arg)) 410 return OPS_R_E OF;473 return OPS_R_EARLY_EOF; 411 474 content.content.armour_header.type=buf; 412 475 CB(OPS_PTAG_CT_ARMOUR_HEADER,&content); openpgpsdk/trunk/src/packet-parse.c
r221 r225 557 557 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 558 558 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 559 case OPS_PTAG_CT_UNARMOURED_TEXT: 560 case OPS_PTAG_CT_ARMOUR_TRAILER: 559 561 break; 560 562
