Changeset 508

Show
Ignore:
Timestamp:
09/20/07 11:12:43
Author:
rachel
Message:

Tidy up code and comments

Files:

Legend:

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

    r507 r508  
    2121    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
    2222    static ops_boolean_t skipping; 
    23     //    static const ops_key_data_t *decrypter; 
    24     //    const ops_key_data_t *keydata=NULL; 
    25     //    const ops_secret_key_t *secret; 
    2623 
    2724    OPS_USED(cbinfo); 
     
    5956    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
    6057        return callback_literal_data(content_,cbinfo); 
    61         //      text=ops_mallocz(content->literal_data_body.length+1); 
    62         //      memcpy(text,content->literal_data_body.data,content->literal_data_body.length); 
    63         //              break; 
    6458 
    6559    case OPS_PARSER_PTAG: 
     
    7771 
    7872    default: 
    79         fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 
    80                 content_->tag); 
    81         assert(0); 
     73        return callback_general(content_,cbinfo); 
    8274        } 
    8375 
     
    125117    fd=open(encfile,O_RDONLY); 
    126118    if(fd < 0) 
    127        
    128        perror(encfile); 
    129        exit(2); 
    130        
     119       
     120        perror(encfile); 
     121        exit(2); 
     122       
    131123     
    132124    // Set decryption reader and handling options 
     
    136128    ops_parse_cb_set(pinfo,callback_ops_decrypt,NULL); 
    137129 
    138     //    current_passphrase=nopassphrase; 
    139      
    140130    // Do the decryption 
    141131 
     
    165155    int rtn=0; 
    166156     
     157    /* 
     158     * Read from test file and write plaintext to memory 
     159     * in set of Literal Data packets 
     160     * \todo optimise using stacked writers 
     161     */ 
     162 
    167163    // open file to encrypt 
    168164    snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 
     
    182178        } 
    183179     
    184     // ops_parse_cb_set(pinfo,callback,NULL); 
    185  
    186     // key in this instance is the public key of the recipient 
    187  
    188     // setup encrypt struct 
    189     //  unsigned char key[OPS_MAX_KEY_SIZE]; 
    190     /* 
    191     encrypt.set_iv(&encrypt,key.iv); 
    192     encrypt.set_key(&encrypt,??); 
    193 */ 
    194     //    ops_crypt_any(&encrypt,key.algorithm); 
    195     //    ops_encrypt_init(&encrypt); 
    196  
    197     //    ops_writer_push_encrypt(cinfo,key); 
    198  
    199     // Set up armour/passphrase options 
    200  
    201     /* 
    202     if (has_armour) 
    203         ops_writer_push_armour(cinfo,ops_false,ops_false,ops_false); 
    204         */ 
    205     // current_passphrase=has_passphrase ? passphrase : nopassphrase; 
    206      
    207     // Do the encryption 
     180    // write plaintext to memory 
    208181 
    209182    for (;;) 
    210    
     183       
    211184            unsigned char buf[MAXBUF]; 
    212185            int n=0; 
     
    216189                    break; 
    217190            assert(n>=0); 
    218 #ifdef USING_PUSH 
    219             ops_write(buf,n,cinfo); 
    220 #else 
     191 
    221192        // create a simple literal data packet as the encrypted payload 
    222193        ops_setup_memory_write(&cinfo_ldt,&mem_ldt,n); 
    223194        ops_write_literal_data((unsigned char *)buf, n, 
    224195                           OPS_LDT_BINARY, cinfo_ldt); 
    225 #endif 
    226     } 
    227  
    228     // write to file 
     196        } 
     197    close(fd_in); 
     198 
     199    /* 
     200     * Encrypt and write to file 
     201     */ 
    229202 
    230203    // Set encryption writer and handling options 
     
    235208 
    236209    // Create and write encrypted PK session key 
    237  
    238     //    char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 
    239     //    const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id); 
    240     //    ops_print_public_key_verbose(pub_key); 
    241210 
    242211    ops_pk_session_key_t* encrypted_pk_session_key; 
     
    249218    iv=ops_mallocz(encrypt.blocksize); 
    250219    encrypt.set_iv(&encrypt, iv); 
    251     //key=ops_mallocz(encrypt.keysize);  
    252220    encrypt.set_key(&encrypt, &encrypted_pk_session_key->key[0]); 
    253221    ops_encrypt_init(&encrypt); 
    254222 
    255223    /* 
    256      * write out the encrypted packet 
     224     * write out encrypted packets 
    257225     */ 
    258226 
     
    260228                          ops_memory_get_length(mem_ldt), 
    261229                          &encrypt, cinfo); 
    262  
    263      
    264     // Tidy up 
    265  
    266     close(fd_in); 
    267230    close(fd_out); 
    268231 
    269      // File contents should match - check with OPS 
     232    /* 
     233     * Test results 
     234     */ 
     235 
     236    // File contents should match - checking with OPS 
     237 
    270238    char buffer[MAXBUF+1]; 
    271239    create_testtext(filename,&buffer[0],MAXBUF);