Changeset 476
- Timestamp:
- 06/11/07 13:13:19
- Files:
-
- openpgpsdk/trunk/tests/test_packet_types.c (modified) (7 diffs)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_packet_types.c
r475 r476 7 7 #include "openpgpsdk/std_print.h" 8 8 #include "openpgpsdk/util.h" 9 #include "openpgpsdk/crypto.h" 10 #include "../src/advanced/parse_local.h" 9 11 10 12 #include "tests.h" … … 37 39 38 40 static ops_parse_cb_return_t 39 callback (const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)41 callback_literal_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 40 42 { 41 43 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; … … 67 69 } 68 70 71 static ops_parse_cb_return_t 72 callback_symmetrically_encrypted_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 73 { 74 //ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 75 76 OPS_USED(cbinfo); 77 78 ops_print_packet(content_); 79 80 switch(content_->tag) 81 { 82 // ignore 83 // break; 84 85 // case OPS_PTAG_CT_SE_DATA_BODY: 86 // data=ops_mallocz(content->literal_data_body.length+1); 87 // memcpy(data,content->literal_data_body.data,content->literal_data_body.length); 88 // break; 89 90 case OPS_PARSER_PTAG: 91 case OPS_PTAG_CT_SE_DATA_HEADER: 92 // ignore 93 break; 94 95 default: 96 fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 97 content_->tag); 98 assert(0); 99 } 100 101 return OPS_RELEASE_MEMORY; 102 } 103 69 104 // \todo temp place to this. need to work out best place for this struct 70 105 // this is a copy of the original definition in adv_memory.c … … 130 165 */ 131 166 132 init_for_memory_read(&pinfo,mem,callback );167 init_for_memory_read(&pinfo,mem,callback_literal_data); 133 168 134 169 // and parse it … … 175 210 */ 176 211 177 init_for_memory_read(&pinfo,mem,callback );212 init_for_memory_read(&pinfo,mem,callback_literal_data); 178 213 179 214 // and parse it … … 193 228 } 194 229 230 static void test_symmetrically_encrypted_data_packet() 231 { 232 ops_create_info_t *cinfo; 233 ops_parse_info_t *pinfo; 234 ops_memory_t *mem; 235 236 unsigned char *in=ops_mallocz(MAXBUF); 237 int rtn=0; 238 239 // create test data buffer 240 create_testdata("symmetrically encrypted data packet", &in[0], MAXBUF); 241 242 /* 243 * initialise needed structures for writing into memory 244 */ 245 246 init_for_memory_write(&cinfo,&mem); 247 248 /* 249 * create literal data packet 250 */ 251 ops_write_symmetrically_encrypted_data(in,MAXBUF,cinfo); 252 253 /* 254 * initialise needed structures for reading from memory 255 */ 256 257 init_for_memory_read(&pinfo,mem,callback_symmetrically_encrypted_data); 258 259 // and parse it 260 261 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 262 // \todo hardcode for now 263 // note: also hardcoded in ops_write_symmetrically_encrypted_data 264 ops_crypt_any(&(pinfo->decrypt), OPS_SA_AES_256); 265 ops_encrypt_init(&pinfo->decrypt); 266 rtn=ops_parse(pinfo); 267 268 /* 269 * test it's the same 270 */ 271 272 CU_ASSERT(memcmp(data,in,MAXBUF)==0); 273 274 // cleanup 275 ops_memory_free(mem); 276 free (in); 277 } 278 195 279 CU_pSuite suite_packet_types() 196 280 { … … 209 293 return NULL; 210 294 295 if (NULL == CU_add_test(suite, "Symmetrically Encrypted Data packet (Tag 9)", test_symmetrically_encrypted_data_packet)) 296 return NULL; 297 211 298 return suite; 212 299 } openpgpsdk/trunk/tests/test_rsa_decrypt.c
r471 r476 33 33 static char* text; 34 34 35 static char *create_testtext(const char *filename)36 {37 static char buffer[MAXBUF+1];38 snprintf(buffer,MAXBUF,"Hello world : %s/%s\n", dir, filename);39 return &buffer[0];40 }41 42 35 static int create_testfile(const char *name) 43 36 { … … 50 43 return 0; 51 44 52 snprintf(buffer,MAXBUF,create_testtext(name));45 create_testtext(name,&buffer[0],MAXBUF); 53 46 write(fd,buffer,strlen(buffer)); 54 47 close(fd); … … 290 283 { 291 284 char encfile[MAXBUF+1]; 285 char testtext[MAXBUF+1]; 292 286 char *suffix= has_armour ? "asc" : "gpg"; 293 287 int fd=0; … … 326 320 327 321 // File contents should match 328 CU_ASSERT(strcmp(text,create_testtext(filename))==0); 322 create_testtext(filename,&testtext[0],MAXBUF); 323 CU_ASSERT(strcmp(text,testtext)==0); 329 324 } 330 325
