Changeset 317
- Timestamp:
- 11/30/05 15:23:25
- Files:
-
- openpgpsdk/trunk/examples/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/memory.h (modified) (2 diffs)
- openpgpsdk/trunk/src/accumulate.c (modified) (1 diff)
- openpgpsdk/trunk/src/armour.c (modified) (7 diffs)
- openpgpsdk/trunk/src/fingerprint.c (modified) (1 diff)
- openpgpsdk/trunk/src/memory.c (modified) (4 diffs)
- openpgpsdk/trunk/src/signature.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/Makefile.template
r314 r317 89 89 echo "Sign this!" > $(SCRATCH)/to-be-signed-inline 90 90 echo "- test dash-escaping" >> $(SCRATCH)/to-be-signed-inline 91 echo "and test trailing whitespace " >> $(SCRATCH)/to-be-signed-inline 91 92 ./sign-inline $(SCRATCH)/key.sec "Why a user ID?" SHA1 $(SCRATCH)/to-be-signed-inline $(SCRATCH)/to-be-signed-inline.sig 92 93 openpgpsdk/trunk/include/openpgpsdk/memory.h
r307 r317 11 11 /** ops_memory_t 12 12 */ 13 typedef struct 14 { 15 unsigned char *buf; 16 size_t length; 17 size_t allocated; 18 } ops_memory_t; 13 typedef struct ops_memory ops_memory_t; 19 14 15 ops_memory_t *ops_memory_new(void); 16 void ops_memory_free(ops_memory_t *mem); 20 17 void ops_memory_init(ops_memory_t *mem,size_t initial_size); 21 18 void ops_memory_pad(ops_memory_t *mem,size_t length); … … 24 21 size_t length); 25 22 void ops_memory_make_packet(ops_memory_t *out,ops_content_tag_t tag); 23 void ops_memory_clear(ops_memory_t *mem); 26 24 void ops_memory_release(ops_memory_t *mem); 27 25 28 26 void ops_create_info_set_writer_memory(ops_create_info_t *info, 29 27 ops_memory_t *mem); 28 29 size_t ops_memory_get_length(const ops_memory_t *mem); 30 void *ops_memory_get_data(ops_memory_t *mem); 31 30 32 #endif openpgpsdk/trunk/src/accumulate.c
r271 r317 76 76 * \ingroup Parse 77 77 * 78 * ops_parse_and_accumulate() parsespackets from an input stream until EOF or error.78 * Parse packets from an input stream until EOF or error. 79 79 * 80 * The parsed data is added to "keyring".80 * Key data found in the parsed data is added to #keyring. 81 81 * 82 * Once all the input data has been parsed: 83 * - the keyring is printed to stdout 84 * - each signature on the keyring is validated, with the result printed to stdout 85 * 86 * \sa See Detailed Description for usage. 87 * 88 * \param *keyring Pointer to an existing keyring 89 * \param *opt Options to use when parsing 82 * \param keyring Pointer to an existing keyring 83 * \param opt Options to use when parsing 90 84 */ 91 85 openpgpsdk/trunk/src/armour.c
r316 r317 719 719 ops_boolean_t seen_cr:1; 720 720 ops_create_signature_t *sig; 721 ops_memory_t *trailing; 721 722 } dash_escaped_arg_t; 722 723 … … 732 733 for(n=0 ; n < length ; ++n) 733 734 { 735 unsigned l; 736 734 737 if(arg->seen_nl) 735 738 { … … 738 741 arg->seen_nl=ops_false; 739 742 } 743 740 744 arg->seen_nl=src[n] == '\n'; 745 741 746 if(arg->seen_nl && !arg->seen_cr) 742 747 { … … 745 750 ops_signature_add_data(arg->sig,"\r",1); 746 751 } 752 747 753 arg->seen_cr=src[n] == '\r'; 754 748 755 if(!ops_stacked_write(&src[n],1,errors,winfo)) 749 756 return ops_false; 750 ops_signature_add_data(arg->sig,&src[n],1); 757 758 /* trailing whitespace isn't included in the signature */ 759 if(src[n] == ' ' || src[n] == '\t') 760 ops_memory_add(arg->trailing,&src[n],1); 761 else 762 { 763 if((l=ops_memory_get_length(arg->trailing))) 764 { 765 if(!arg->seen_nl && !arg->seen_cr) 766 ops_signature_add_data(arg->sig, 767 ops_memory_get_data(arg->trailing), 768 l); 769 ops_memory_clear(arg->trailing); 770 } 771 ops_signature_add_data(arg->sig,&src[n],1); 772 } 751 773 } 752 774 … … 758 780 dash_escaped_arg_t *arg=ops_writer_get_arg(winfo); 759 781 782 ops_memory_free(arg->trailing); 760 783 free(arg); 761 784 } … … 774 797 arg->seen_nl=ops_true; 775 798 arg->sig=sig; 799 arg->trailing=ops_memory_new(); 776 800 ops_writer_push(info,dash_escaped_writer,NULL,dash_escaped_destroyer,arg); 777 801 } … … 913 937 ops_mallocz(sizeof(linebreak_arg_t))); 914 938 915 916 939 base64=ops_mallocz(sizeof *base64); 917 940 base64->checksum=CRC24_INIT; openpgpsdk/trunk/src/fingerprint.c
r312 r317 52 52 else 53 53 { 54 ops_memory_t mem;54 ops_memory_t *mem=ops_memory_new(); 55 55 ops_hash_t sha1; 56 size_t l; 56 57 57 memset(&mem,'\0',sizeof mem); 58 59 ops_build_public_key(&mem,key,ops_false); 58 ops_build_public_key(mem,key,ops_false); 60 59 61 60 ops_hash_sha1(&sha1); 62 61 sha1.init(&sha1); 63 62 63 l=ops_memory_get_length(mem); 64 64 65 ops_hash_add_int(&sha1,0x99,1); 65 ops_hash_add_int(&sha1, mem.length,2);66 sha1.add(&sha1, mem.buf,mem.length);66 ops_hash_add_int(&sha1,l,2); 67 sha1.add(&sha1,ops_memory_get_data(mem),l); 67 68 sha1.finish(&sha1,fp->fingerprint); 69 68 70 fp->length=20; 69 71 70 ops_memory_ release(&mem);72 ops_memory_free(mem); 71 73 } 72 74 } openpgpsdk/trunk/src/memory.c
r314 r317 6 6 #include <string.h> 7 7 #include <assert.h> 8 9 struct ops_memory 10 { 11 unsigned char *buf; 12 size_t length; 13 size_t allocated; 14 }; 8 15 9 16 void ops_memory_init(ops_memory_t *mem,size_t initial_size) … … 52 59 } 53 60 61 /** 62 * Unlike ops_memory_release(), this retains the allocated memory but 63 * sets the length of stored data to zero. 64 */ 65 void ops_memory_clear(ops_memory_t *mem) 66 { mem->length=0; } 67 54 68 void ops_memory_release(ops_memory_t *mem) 55 69 { 56 70 free(mem->buf); 57 71 mem->buf=NULL; 72 mem->length=0; 58 73 } 59 74 … … 76 91 * 77 92 * \param info The info structure 78 * \param mem The memory structure 79 */ 93 * \param mem The memory structure */ 80 94 81 95 void ops_create_info_set_writer_memory(ops_create_info_t *info, … … 119 133 out->length+=extra+1; 120 134 } 135 136 ops_memory_t *ops_memory_new() 137 { return ops_mallocz(sizeof(ops_memory_t)); } 138 139 void ops_memory_free(ops_memory_t *mem) 140 { 141 ops_memory_release(mem); 142 free(mem); 143 } 144 145 size_t ops_memory_get_length(const ops_memory_t *mem) 146 { return mem->length; } 147 148 void *ops_memory_get_data(ops_memory_t *mem) 149 { return mem->buf; } openpgpsdk/trunk/src/signature.c
r314 r317 15 15 ops_hash_t hash; 16 16 ops_signature_t sig; 17 ops_memory_t mem;17 ops_memory_t *mem; 18 18 ops_create_info_t *info; /*!< how to do the writing */ 19 19 unsigned hashed_count_offset; … … 140 140 static void hash_add_key(ops_hash_t *hash,const ops_public_key_t *key) 141 141 { 142 ops_memory_t mem; 143 144 memset(&mem,'\0',sizeof mem); 145 ops_build_public_key(&mem,key,ops_false); 146 142 ops_memory_t *mem=ops_memory_new(); 143 size_t l; 144 145 ops_build_public_key(mem,key,ops_false); 146 147 l=ops_memory_get_length(mem); 147 148 ops_hash_add_int(hash,0x99,1); 148 ops_hash_add_int(hash, mem.length,2);149 hash->add(hash, mem.buf,mem.length);150 151 ops_memory_ release(&mem);149 ops_hash_add_int(hash,l,2); 150 hash->add(hash,ops_memory_get_data(mem),l); 151 152 ops_memory_free(mem); 152 153 } 153 154 … … 315 316 return finalise_signature(hash,sig,signer,NULL); 316 317 } 317 318 319 static void start_signature(ops_create_signature_t *sig) 320 { 321 // since this has subpackets and stuff, we have to buffer the whole 322 // thing to get counts before writing. 323 sig->mem=ops_memory_new(); 324 ops_memory_init(sig->mem,100); 325 ops_create_info_set_writer_memory(sig->info,sig->mem); 326 327 // write nearly up to the first subpacket 328 ops_write_scalar(sig->sig.version,1,sig->info); 329 ops_write_scalar(sig->sig.type,1,sig->info); 330 ops_write_scalar(sig->sig.key_algorithm,1,sig->info); 331 ops_write_scalar(sig->sig.hash_algorithm,1,sig->info); 332 333 // dummy hashed subpacket count 334 sig->hashed_count_offset=ops_memory_get_length(sig->mem); 335 ops_write_scalar(0,2,sig->info); 336 } 318 337 319 338 /** … … 351 370 sig->hash.add(&sig->hash,id->user_id,strlen((char *)id->user_id)); 352 371 353 // since this has subpackets and stuff, we have to buffer the whole 354 // thing to get counts before writing. 355 ops_memory_init(&sig->mem,100); 356 ops_create_info_set_writer_memory(sig->info,&sig->mem); 357 358 // write nearly up to the first subpacket 359 ops_write_scalar(sig->sig.version,1,sig->info); 360 ops_write_scalar(sig->sig.type,1,sig->info); 361 ops_write_scalar(sig->sig.key_algorithm,1,sig->info); 362 ops_write_scalar(sig->sig.hash_algorithm,1,sig->info); 363 364 // dummy hashed subpacket count 365 sig->hashed_count_offset=sig->mem.length; 366 ops_write_scalar(0,2,sig->info); 372 start_signature(sig); 367 373 } 368 374 … … 395 401 396 402 common_init_signature(&sig->hash,&sig->sig); 397 398 // since this has subpackets and stuff, we have to buffer the whole 399 // thing to get counts before writing. 400 ops_memory_init(&sig->mem,100); 401 ops_create_info_set_writer_memory(sig->info,&sig->mem); 402 403 // write nearly up to the first subpacket 404 ops_write_scalar(sig->sig.version,1,sig->info); 405 ops_write_scalar(sig->sig.type,1,sig->info); 406 ops_write_scalar(sig->sig.key_algorithm,1,sig->info); 407 ops_write_scalar(sig->sig.hash_algorithm,1,sig->info); 408 409 // dummy hashed subpacket count 410 sig->hashed_count_offset=sig->mem.length; 411 ops_write_scalar(0,2,sig->info); 403 start_signature(sig); 412 404 } 413 405 … … 437 429 void ops_signature_hashed_subpackets_end(ops_create_signature_t *sig) 438 430 { 439 sig->hashed_data_length=sig->mem.length-sig->hashed_count_offset-2; 440 ops_memory_place_int(&sig->mem,sig->hashed_count_offset, 431 sig->hashed_data_length=ops_memory_get_length(sig->mem) 432 -sig->hashed_count_offset-2; 433 ops_memory_place_int(sig->mem,sig->hashed_count_offset, 441 434 sig->hashed_data_length,2); 442 435 // dummy unhashed subpacket count 443 sig->unhashed_count_offset= sig->mem.length;436 sig->unhashed_count_offset=ops_memory_get_length(sig->mem); 444 437 ops_write_scalar(0,2,sig->info); 445 438 } … … 461 454 ops_secret_key_t *skey,ops_create_info_t *info) 462 455 { 456 size_t l=ops_memory_get_length(sig->mem); 457 463 458 assert(sig->hashed_data_length != (unsigned)-1); 464 459 465 ops_memory_place_int( &sig->mem,sig->unhashed_count_offset,466 sig->mem.length-sig->unhashed_count_offset-2,2);460 ops_memory_place_int(sig->mem,sig->unhashed_count_offset, 461 l-sig->unhashed_count_offset-2,2); 467 462 468 463 // add the packet from version number to end of hashed subpackets 469 sig->hash.add(&sig->hash,sig->mem.buf,sig->unhashed_count_offset); 464 sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem), 465 sig->unhashed_count_offset); 470 466 ops_hash_add_int(&sig->hash,sig->sig.version,1); 471 467 ops_hash_add_int(&sig->hash,0xff,1); … … 479 475 480 476 ops_write_ptag(OPS_PTAG_CT_SIGNATURE,info); 481 ops_write_length(sig->mem.length,info); 482 ops_write(sig->mem.buf,sig->mem.length,info); 483 484 ops_memory_release(&sig->mem); 477 l=ops_memory_get_length(sig->mem); 478 ops_write_length(l,info); 479 ops_write(ops_memory_get_data(sig->mem),l,info); 480 481 ops_memory_free(sig->mem); 485 482 } 486 483
