Changeset 514

Show
Ignore:
Timestamp:
10/15/07 12:11:28
Author:
rachel
Message:

WIN32 changes provided by Alexey Simak

Files:

Legend:

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

    r485 r514  
    3333    snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); 
    3434 
    35     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 
     35    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
    3636        { 
    3737        fprintf(stderr,"Can't create key details\n"); 
  • openpgpsdk/trunk/tests/test_packet_types.c

    r511 r514  
    238238        char* plaintext="Text to be hashed in test_ops_mdc"; 
    239239        int rtn=0; 
     240    size_t sz_preamble; 
    240241 
    241242    ops_crypt_t crypt; 
     
    245246    ops_encrypt_init(&crypt); 
    246247 
    247     size_t sz_preamble=crypt.blocksize+2; 
     248    sz_preamble=crypt.blocksize+2; 
    248249    preamble=ops_mallocz(sz_preamble); 
    249250    ops_random(preamble, crypt.blocksize); 
     
    302303    char* ldt_text="Test Data string for test_se_ip"; 
    303304 
    304     ops_setup_memory_write(&cinfo_ldt,&mem_ldt,strlen(ldt_text)); 
    305     ops_write_literal_data((unsigned char *)ldt_text, strlen(ldt_text), 
    306                            OPS_LDT_TEXT, cinfo_ldt); 
    307  
    308     /* 
    309      * write out the encrypted packet 
    310      */ 
    311305    int rtn=0; 
    312306    ops_create_info_t *cinfo; 
    313307    ops_parse_info_t *pinfo; 
    314308    ops_memory_t *mem; 
     309 
     310    ops_setup_memory_write(&cinfo_ldt,&mem_ldt,strlen(ldt_text)); 
     311    ops_write_literal_data((unsigned char *)ldt_text, strlen(ldt_text), 
     312                           OPS_LDT_TEXT, cinfo_ldt); 
     313 
     314    /* 
     315     * write out the encrypted packet 
     316     */ 
    315317    ops_setup_memory_write(&cinfo,&mem,MAXBUF); 
    316318 
     
    364366    ops_memory_t *mem; 
    365367    int rtn=0; 
     368    const ops_key_data_t *pub_key=NULL; 
    366369 
    367370    // setup for write 
     
    369372 
    370373    // write 
    371     const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id); 
     374    pub_key=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id); 
    372375    assert(pub_key); 
    373376 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r511 r514  
    214214             protocol==NULL ? "" : "_", 
    215215             filename,suffix); 
     216#ifdef WIN32 
     217    fd=open(encfile,O_RDONLY | O_BINARY); 
     218#else 
    216219    fd=open(encfile,O_RDONLY); 
     220#endif 
    217221    if(fd < 0) 
    218222        { 
  • openpgpsdk/trunk/tests/test_rsa_encrypt.c

    r511 r514  
    133133 
    134134    // open encrypted file 
     135#ifdef WIN32 
     136    fd=open(encfile,O_RDONLY | O_BINARY); 
     137#else 
    135138    fd=open(encfile,O_RDONLY); 
     139#endif 
    136140    if(fd < 0) 
    137141        { 
     
    177181    int fd_out=0; 
    178182    int rtn=0; 
     183    ops_create_info_t *cinfo; 
     184    ops_pk_session_key_t* encrypted_pk_session_key; 
     185    ops_crypt_t encrypt; 
     186    unsigned char *iv=NULL; 
    179187     
    180188    /* 
     
    186194    // open file to encrypt 
    187195    snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 
     196#ifdef WIN32 
     197    fd_in=open(myfile,O_RDONLY | O_BINARY); 
     198#else 
    188199    fd_in=open(myfile,O_RDONLY); 
     200#endif 
    189201    if(fd_in < 0) 
    190202        { 
     
    194206     
    195207    snprintf(encrypted_file,MAXBUF,"%s/%s.%s",dir,filename,suffix); 
     208#ifdef WIN32 
     209    fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 
     210#else 
    196211    fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 
     212#endif 
    197213    if(fd_out < 0) 
    198214        { 
     
    226242    // Set encryption writer and handling options 
    227243 
    228     ops_create_info_t *cinfo; 
    229244    cinfo=ops_create_info_new(); 
    230245    ops_writer_set_fd(cinfo,fd_out);  
     
    232247    // Create and write encrypted PK session key 
    233248 
    234     ops_pk_session_key_t* encrypted_pk_session_key; 
    235249    encrypted_pk_session_key=ops_create_pk_session_key(pub_key); 
    236250    ops_write_pk_session_key(cinfo,encrypted_pk_session_key); 
    237251 
    238     ops_crypt_t encrypt; 
    239252    ops_crypt_any(&encrypt, encrypted_pk_session_key->symmetric_algorithm); 
    240     unsigned char *iv=NULL; 
    241253    iv=ops_mallocz(encrypt.blocksize); 
    242254    encrypt.set_iv(&encrypt, iv); 
     
    295307    int rtn=0; 
    296308     
     309    ops_create_info_t *cinfo; 
     310    char* testtext=NULL; 
     311    char pp[MAXBUF]; 
     312 
    297313    /* 
    298314     * Read from test file and write plaintext to memory 
     
    302318    // open file to encrypt 
    303319    snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 
     320#ifdef WIN32 
     321    fd_in=open(myfile,O_RDONLY | O_BINARY); 
     322#else 
    304323    fd_in=open(myfile,O_RDONLY); 
     324#endif 
    305325    if(fd_in < 0) 
    306326        { 
     
    310330     
    311331    snprintf(encrypted_file,MAXBUF,"%s/%s%s.%s",dir,gpgtest,filename,suffix); 
     332#ifdef WIN32 
     333    fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 
     334#else 
    312335    fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 
     336#endif 
    313337    if(fd_out < 0) 
    314338        { 
     
    324348    // This example shows output to a file 
    325349 
    326     ops_create_info_t *cinfo; 
    327350    cinfo=ops_create_info_new(); 
    328351    ops_writer_set_fd(cinfo,fd_out);  
     
    367390        // File contents should match - check with GPG 
    368391         
    369         char pp[MAXBUF]; 
    370392        if (pub_key==alpha_pub_keydata) 
    371393            pp[0]='\0'; 
     
    383405        // File contents should match - checking with OPS 
    384406         
    385         char* testtext=NULL; 
    386407        testtext=create_testtext(filename); 
    387408        test_rsa_decrypt(encrypted_file,testtext); 
  • openpgpsdk/trunk/tests/test_rsa_signature.c

    r506 r514  
    5757    int fd_out=0; 
    5858    int rtn=0; 
     59    ops_create_info_t *cinfo=NULL; 
    5960     
    6061    // open file to sign 
    6162    snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 
     63#ifdef WIN32 
     64    fd_in=open(myfile,O_RDONLY | O_BINARY); 
     65#else 
    6266    fd_in=open(myfile,O_RDONLY); 
     67#endif 
    6368    if(fd_in < 0) 
    6469        { 
     
    6873     
    6974    snprintf(signed_file,MAXBUF,"%s/%s_%s.%s",dir,filename,ops_show_hash_algorithm(hash_alg),suffix); 
     75#ifdef WIN32 
     76    fd_out=open(signed_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 
     77#else 
    7078    fd_out=open(signed_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 
     79#endif 
    7180    if(fd_out < 0) 
    7281        { 
     
    8594 
    8695    // set up output file 
    87     ops_create_info_t *cinfo; 
    8896    cinfo=ops_create_info_new(); 
    8997    ops_writer_set_fd(cinfo,fd_out);  
     
    114122    ops_write_signature(sig,(ops_public_key_t *)&skey->public_key,(ops_secret_key_t *)skey,cinfo); 
    115123    ops_writer_close(cinfo); 
     124    close(fd_out); 
    116125 
    117126#ifdef TODO 
  • openpgpsdk/trunk/tests/test_rsa_verify.c

    r507 r514  
    1212 
    1313#include "tests.h" 
     14 
     15#ifndef ATTRIBUTE_UNUSED 
     16 
     17#ifndef WIN32 
     18#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 
     19#else 
     20#define ATTRIBUTE_UNUSED  
     21#endif // #ifndef WIN32 
     22 
     23#endif /* ATTRIBUTE_UNUSED */ 
    1424 
    1525typedef struct 
     
    162172    } 
    163173 
    164 static void test_rsa_verify(const int has_armour, const int has_passphrase __attribute__((__unused__)), const char *filename, const char* protocol) 
     174static void test_rsa_verify(const int has_armour, const int has_passphrase ATTRIBUTE_UNUSED, const char *filename, const char* protocol) 
    165175    { 
    166176    char signedfile[MAXBUF+1]; 
     
    178188             protocol==NULL ? "" : "_", 
    179189             filename,suffix); 
     190#ifdef WIN32 
     191    fd=open(signedfile,O_RDONLY | O_BINARY); 
     192#else 
    180193    fd=open(signedfile,O_RDONLY); 
     194#endif 
    181195    if(fd < 0) 
    182196        { 
  • openpgpsdk/trunk/tests/tests.c

    r511 r514  
    33#include <string.h> 
    44#include <stdlib.h> 
     5#ifndef WIN32 
    56#include <unistd.h> 
     7#endif 
    68#include <sys/stat.h> 
    79 
     
    5759    snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); 
    5860 
     61#ifdef WIN32 
     62    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
     63#else 
    5964    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 
     65#endif 
    6066        { 
    6167        fprintf(stderr,"Can't create Alpha key details\n"); 
     
    7581    snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.bravo"); 
    7682 
     83#ifdef WIN32 
     84    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
     85#else 
    7786    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 
     87#endif 
    7888        { 
    7989        fprintf(stderr,"Can't create Bravo key details\n"); 
     
    206216    int limit=10; // don't try indefinitely 
    207217    long int rnd=0; 
     218 
     219#ifdef WIN32 
     220    srand( (unsigned)time( NULL ) ); 
     221#endif 
    208222    while (limit--)  
    209223        { 
     
    212226         
    213227        // Try to create directory 
     228#ifndef WIN32 
    214229        if (!mkdir(dir,0700)) 
     230#else 
     231        if (!_mkdir(dir)) 
     232#endif 
    215233            { 
    216234            // success 
     
    234252    const unsigned int maxbuf=1024; 
    235253    char buf[maxbuf+1]; 
     254    unsigned int sz_one=0; 
     255    unsigned int sz_big=0; 
     256    char* bigbuf=NULL;  
     257 
    236258    buf[maxbuf]='\0'; 
    237259    snprintf(buf,maxbuf,"%s : Test Text\n", text); 
    238260 
    239     const unsigned int sz_one=strlen(buf); 
    240     const unsigned int sz_big=sz_one*repeats+1; 
    241  
    242     char* bigbuf=ops_mallocz(sz_big);  
     261    sz_one=strlen(buf); 
     262    sz_big=sz_one*repeats+1; 
     263 
     264    bigbuf=ops_mallocz(sz_big);  
     265 
    243266   for (i=0; i<repeats; i++) 
    244267        { 
     
    257280    snprintf((char *)buf,maxlen,"%s%s", text, preamble); 
    258281 
     282#ifdef WIN32 
     283    srand( (unsigned)time( NULL ) ); 
     284#endif 
    259285    for (i=strlen(text)+strlen(preamble); i<maxlen; i++) 
    260286        { 
     
    270296    int fd=0; 
    271297    snprintf(filename,MAXBUF,"%s/%s",dir,name); 
     298#ifdef WIN32 
     299    if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL | O_BINARY, 0600))<0) 
     300#else 
    272301    if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL, 0600))<0) 
     302#endif 
    273303        return; 
    274304 
     
    318348    const ops_key_data_t *keydata=NULL; 
    319349    const ops_secret_key_t *secret; 
     350    char *passphrase=NULL; 
    320351 
    321352    OPS_USED(cbinfo); 
     
    331362 
    332363        // Do we need the passphrase and not have it? If so, get it 
    333         char *passphrase=NULL; 
    334364        passphrase=NULL; 
    335365 
  • openpgpsdk/trunk/tests/tests.h

    r511 r514  
    66#include <string.h> 
    77#include <stdlib.h> 
     8#ifndef WIN32 
    89#include <unistd.h> 
     10#else 
     11#include <direct.h> 
     12#define snprintf _snprintf 
     13#define random   rand 
     14#endif 
    915#include <fcntl.h> 
    1016#include <sys/stat.h>