Changeset 508
- Timestamp:
- 09/20/07 11:12:43
- Files:
-
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_rsa_encrypt.c
r507 r508 21 21 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 22 22 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;26 23 27 24 OPS_USED(cbinfo); … … 59 56 case OPS_PTAG_CT_LITERAL_DATA_BODY: 60 57 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;64 58 65 59 case OPS_PARSER_PTAG: … … 77 71 78 72 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); 82 74 } 83 75 … … 125 117 fd=open(encfile,O_RDONLY); 126 118 if(fd < 0) 127 {128 perror(encfile);129 exit(2);130 }119 { 120 perror(encfile); 121 exit(2); 122 } 131 123 132 124 // Set decryption reader and handling options … … 136 128 ops_parse_cb_set(pinfo,callback_ops_decrypt,NULL); 137 129 138 // current_passphrase=nopassphrase;139 140 130 // Do the decryption 141 131 … … 165 155 int rtn=0; 166 156 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 167 163 // open file to encrypt 168 164 snprintf(myfile,MAXBUF,"%s/%s",dir,filename); … … 182 178 } 183 179 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 208 181 209 182 for (;;) 210 {183 { 211 184 unsigned char buf[MAXBUF]; 212 185 int n=0; … … 216 189 break; 217 190 assert(n>=0); 218 #ifdef USING_PUSH 219 ops_write(buf,n,cinfo); 220 #else 191 221 192 // create a simple literal data packet as the encrypted payload 222 193 ops_setup_memory_write(&cinfo_ldt,&mem_ldt,n); 223 194 ops_write_literal_data((unsigned char *)buf, n, 224 195 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 */ 229 202 230 203 // Set encryption writer and handling options … … 235 208 236 209 // 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);241 210 242 211 ops_pk_session_key_t* encrypted_pk_session_key; … … 249 218 iv=ops_mallocz(encrypt.blocksize); 250 219 encrypt.set_iv(&encrypt, iv); 251 //key=ops_mallocz(encrypt.keysize);252 220 encrypt.set_key(&encrypt, &encrypted_pk_session_key->key[0]); 253 221 ops_encrypt_init(&encrypt); 254 222 255 223 /* 256 * write out the encrypted packet224 * write out encrypted packets 257 225 */ 258 226 … … 260 228 ops_memory_get_length(mem_ldt), 261 229 &encrypt, cinfo); 262 263 264 // Tidy up265 266 close(fd_in);267 230 close(fd_out); 268 231 269 // File contents should match - check with OPS 232 /* 233 * Test results 234 */ 235 236 // File contents should match - checking with OPS 237 270 238 char buffer[MAXBUF+1]; 271 239 create_testtext(filename,&buffer[0],MAXBUF);
