Changeset 476

Show
Ignore:
Timestamp:
06/11/07 13:13:19
Author:
rachel
Message:

New test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/tests/test_packet_types.c

    r475 r476  
    77#include "openpgpsdk/std_print.h" 
    88#include "openpgpsdk/util.h" 
     9#include "openpgpsdk/crypto.h" 
     10#include "../src/advanced/parse_local.h" 
    911 
    1012#include "tests.h" 
     
    3739 
    3840static ops_parse_cb_return_t 
    39 callback(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     41callback_literal_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
    4042    { 
    4143    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
     
    6769    } 
    6870  
     71static ops_parse_cb_return_t 
     72callback_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  
    69104// \todo temp place to this. need to work out best place for this struct 
    70105// this is a copy of the original definition in adv_memory.c 
     
    130165     */ 
    131166 
    132     init_for_memory_read(&pinfo,mem,callback); 
     167    init_for_memory_read(&pinfo,mem,callback_literal_data); 
    133168 
    134169    // and parse it 
     
    175210     */ 
    176211 
    177     init_for_memory_read(&pinfo,mem,callback); 
     212    init_for_memory_read(&pinfo,mem,callback_literal_data); 
    178213 
    179214    // and parse it 
     
    193228    } 
    194229 
     230static 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 
    195279CU_pSuite suite_packet_types() 
    196280{ 
     
    209293            return NULL; 
    210294     
     295    if (NULL == CU_add_test(suite, "Symmetrically Encrypted Data packet (Tag 9)", test_symmetrically_encrypted_data_packet)) 
     296            return NULL; 
     297     
    211298    return suite; 
    212299} 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r471 r476  
    3333static char* text; 
    3434 
    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  
    4235static int create_testfile(const char *name) 
    4336    { 
     
    5043        return 0; 
    5144 
    52     snprintf(buffer,MAXBUF,create_testtext(name)); 
     45    create_testtext(name,&buffer[0],MAXBUF); 
    5346    write(fd,buffer,strlen(buffer)); 
    5447    close(fd); 
     
    290283    { 
    291284    char encfile[MAXBUF+1]; 
     285    char testtext[MAXBUF+1]; 
    292286    char *suffix= has_armour ? "asc" : "gpg"; 
    293287    int fd=0; 
     
    326320     
    327321    // 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); 
    329324    } 
    330325