Changeset 689

Show
Ignore:
Timestamp:
08/02/09 15:02:37
Author:
ben
Message:

Layout. Avoid casts.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/src/lib/create.c

    r686 r689  
    205205 
    206206    default: 
     207        fprintf(stderr, "Unknown algorithm %d\n", key->algorithm); 
    207208        assert(0); 
    208209        break; 
  • openpgpsdk/trunk/tests/test_rsa_keys.c

    r688 r689  
    4747    { 
    4848    ops_keydata_t* keydata=ops_keydata_new(); 
    49     CU_ASSERT(ops_rsa_generate_keypair(1024,65537,keydata)==ops_true); 
     49    CU_ASSERT(ops_rsa_generate_keypair(1024, 65537, keydata)); 
    5050    ops_keydata_free(keydata); 
    5151    } 
     
    5858    ops_keydata_t* keydata=NULL; 
    5959 
    60     keydata=ops_rsa_create_selfsigned_keypair(1024,17,&uid); 
     60    keydata=ops_rsa_create_selfsigned_keypair(1024, 17, &uid); 
    6161 
    6262    CU_ASSERT(keydata != NULL); 
     
    6666 
    6767static ops_parse_cb_return_t 
    68 cb_get_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo __attribute__((unused))) 
     68cb_get_passphrase(const ops_parser_content_t *content_, 
     69                  ops_parse_cb_info_t *cbinfo __attribute__((unused))) 
    6970    { 
    7071    const ops_parser_content_union_t *content=&content_->content; 
     
    7879          Doing this so the test can be automated. 
    7980        */ 
    80         *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase("hello"); 
     81        *(content->secret_key_passphrase.passphrase) 
     82            =ops_malloc_passphrase("hello"); 
    8183        return OPS_KEEP_MEMORY; 
    8284        break; 
     
    99101    const ops_public_key_t* pub_key=NULL; 
    100102    const ops_secret_key_t* sec_key=NULL; 
    101     const char* pp="hello"; 
    102     const unsigned char *passphrase=(unsigned char *)pp; 
    103     const size_t pplen=strlen(pp); 
     103    static const unsigned char pp[]="hello"; 
    104104    char filename[MAXBUF+1]; 
    105105    int fd=0; 
     
    117117    uid.user_id=(unsigned char *) userid; 
    118118 
    119     keydata=ops_rsa_create_selfsigned_keypair(1024,65537,&uid); 
     119    keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid); 
    120120    CU_ASSERT(keydata != NULL); 
    121121    pub_key=ops_get_public_key_from_data(keydata); 
     
    127127     */ 
    128128 
    129     snprintf(filename,MAXBUF,"%s/%s.%s",dir,"ops_transferable_public_key",suffix); 
    130     fd=ops_setup_file_write(&cinfo, filename,overwrite); 
    131     ops_write_transferable_public_key(keydata,armoured,cinfo); 
    132     ops_teardown_file_write(cinfo,fd); 
     129    snprintf(filename, MAXBUF, "%s/%s.%s", dir, "ops_transferable_public_key", 
     130             suffix); 
     131    fd=ops_setup_file_write(&cinfo, filename, overwrite); 
     132    ops_write_transferable_public_key(keydata, armoured, cinfo); 
     133    ops_teardown_file_write(cinfo, fd); 
    133134 
    134135    /* 
     
    143144    result=ops_mallocz(sizeof(*result)); 
    144145 
    145     CU_ASSERT(ops_validate_all_signatures(result, &pub_keyring, NULL)==ops_true); 
    146     CU_ASSERT(result->valid_count==1); 
    147  
    148     CU_ASSERT(memcmp(result->valid_sigs[0].signer_id,keyid,OPS_KEY_ID_SIZE)==0); 
    149     CU_ASSERT(result->invalid_count==0); 
    150     CU_ASSERT(result->unknown_signer_count==0); 
     146    CU_ASSERT(ops_validate_all_signatures(result, &pub_keyring, NULL)); 
     147    CU_ASSERT(result->valid_count == 1); 
     148 
     149    CU_ASSERT(memcmp(result->valid_sigs[0].signer_id, keyid, OPS_KEY_ID_SIZE) 
     150              == 0); 
     151    CU_ASSERT(result->invalid_count == 0); 
     152    CU_ASSERT(result->unknown_signer_count == 0); 
    151153 
    152154    ops_validate_result_free(result); 
     
    154156    // Validate public key with GPG 
    155157 
    156     snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 
     158    snprintf(cmd, sizeof cmd, 
     159             "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 
     160             gpgcmd); 
    157161    rtn=run(cmd); 
    158162    CU_ASSERT(rtn==0);  
     
    164168    result=ops_mallocz(sizeof(*result)); 
    165169 
    166     snprintf(filename,MAXBUF,"%s/%s.%s",dir,"ops_transferable_secret_key",suffix); 
    167     fd=ops_setup_file_write(&cinfo, filename,overwrite); 
    168     ops_write_transferable_secret_key(keydata,passphrase,pplen,armoured,cinfo); 
    169     ops_teardown_file_write(cinfo,fd); 
     170    snprintf(filename, MAXBUF, "%s/%s.%s", dir, "ops_transferable_secret_key", 
     171             suffix); 
     172    fd=ops_setup_file_write(&cinfo, filename, overwrite); 
     173    ops_write_transferable_secret_key(keydata, pp, sizeof pp-1, armoured, 
     174                                      cinfo); 
     175    ops_teardown_file_write(cinfo, fd); 
    170176 
    171177    // generate keyring from this file 
     
    176182    result=ops_mallocz(sizeof(*result)); 
    177183 
    178     CU_ASSERT(ops_validate_all_signatures(result, &sec_keyring, cb_get_passphrase)==ops_true); 
    179     CU_ASSERT(result->valid_count==1); 
    180     CU_ASSERT(result->invalid_count==0); 
    181     CU_ASSERT(result->unknown_signer_count==0); 
     184    CU_ASSERT(ops_validate_all_signatures(result, &sec_keyring, 
     185                                          cb_get_passphrase)); 
     186    CU_ASSERT(result->valid_count == 1); 
     187    CU_ASSERT(result->invalid_count == 0); 
     188    CU_ASSERT(result->unknown_signer_count == 0); 
    182189 
    183190    ops_validate_result_free(result); 
    184191 
    185192    // validate with GPG 
    186     snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 
     193    snprintf(cmd, sizeof cmd, 
     194             "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 
     195             gpgcmd); 
    187196    rtn=run(cmd); 
    188197    CU_ASSERT(rtn==0);  
     
    201210    ops_keyring_t keyring; 
    202211    char filename[MAXBUF+1]; 
    203     snprintf(filename,MAXBUF,"%s/%s", dir, "pubring.gpg"); 
     212 
     213    snprintf(filename, MAXBUF, "%s/%s", dir, "pubring.gpg"); 
    204214 
    205215    memset(&keyring, '\0', sizeof keyring); 
     
    249259 
    250260    // Keyring 1 
    251     keydata=ops_rsa_create_selfsigned_keypair(1024,65537,&uid1); 
     261    keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid1); 
    252262    CU_ASSERT(keydata != NULL); 
    253     snprintf(filename,MAXBUF,"%s/%s",dir,"transferable_public_key_1"); 
    254     fd=ops_setup_file_write(&cinfo, filename,overwrite); 
    255     ops_write_transferable_public_key(keydata,OPS_ARMOURED,cinfo); 
    256     ops_teardown_file_write(cinfo,fd); 
     263    snprintf(filename, MAXBUF, "%s/%s", dir, "transferable_public_key_1"); 
     264    fd=ops_setup_file_write(&cinfo, filename, overwrite); 
     265    ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 
     266    ops_teardown_file_write(cinfo, fd); 
    257267    ops_keyring_read_from_file(&keyring1, OPS_ARMOURED, filename); 
    258268 
    259269    // Keyring 2 
    260     keydata=ops_rsa_create_selfsigned_keypair(1024,65537,&uid2); 
     270    keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid2); 
    261271    CU_ASSERT(keydata != NULL); 
    262     snprintf(filename,MAXBUF,"%s/%s",dir,"transferable_public_key_2"); 
    263     fd=ops_setup_file_write(&cinfo, filename,overwrite); 
    264     ops_write_transferable_public_key(keydata,OPS_ARMOURED,cinfo); 
    265     ops_teardown_file_write(cinfo,fd); 
     272    snprintf(filename, MAXBUF, "%s/%s", dir, "transferable_public_key_2"); 
     273    fd=ops_setup_file_write(&cinfo, filename, overwrite); 
     274    ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 
     275    ops_teardown_file_write(cinfo, fd); 
    266276    ops_keyring_read_from_file(&keyring2, OPS_ARMOURED, filename); 
    267277 
     
    277287    snprintf(filename,MAXBUF,"%s/%s",dir,"transferable_public_key_3_bad"); 
    278288    fd=ops_setup_file_write(&cinfo, filename, overwrite); 
    279     ops_write_transferable_public_key(keydata,OPS_ARMOURED,cinfo); 
    280     ops_teardown_file_write(cinfo,fd); 
     289    ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 
     290    ops_teardown_file_write(cinfo, fd); 
    281291    ops_keyring_read_from_file(&keyring3, OPS_ARMOURED, filename); 
    282292 
     
    289299    assert(keydata1); 
    290300 
    291     CU_ASSERT(ops_validate_key_signatures(result, keydata1, &keyring2, NULL)==ops_false); 
     301    CU_ASSERT(!ops_validate_key_signatures(result, keydata1, &keyring2, NULL)); 
    292302 
    293303    CU_ASSERT(result->valid_count==0); 
     
    307317    assert(keydata3); 
    308318 
    309     CU_ASSERT(ops_validate_key_signatures(result, keydata3, &keyring3, NULL)==ops_false); 
    310  
    311     CU_ASSERT(result->valid_count==0); 
    312     CU_ASSERT(result->invalid_count==1); 
    313     CU_ASSERT(result->unknown_signer_count==0); 
     319    CU_ASSERT(!ops_validate_key_signatures(result, keydata3, &keyring3, NULL)); 
     320 
     321    CU_ASSERT(result->valid_count == 0); 
     322    CU_ASSERT(result->invalid_count == 1); 
     323    CU_ASSERT(result->unknown_signer_count == 0); 
    314324    ops_validate_result_free(result); 
    315325 
    316326    // validate with GPG - should fail 
    317     snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 
     327    snprintf(cmd, sizeof cmd, 
     328             "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 
     329             gpgcmd); 
    318330    rtn=run(cmd); 
    319331    CU_ASSERT(rtn!=0);  
     
    351363 
    352364    // add suite 
    353     suite=CU_add_suite("RSA Keys Suite", init_suite_rsa_keys, clean_suite_rsa_keys); 
     365    suite=CU_add_suite("RSA Keys Suite", init_suite_rsa_keys, 
     366                       clean_suite_rsa_keys); 
    354367    if (!suite) 
    355368        return NULL; 
     
    357370    // add tests to suite 
    358371 
    359     if (NULL == CU_add_test(suite, "Generate key pair", test_rsa_keys_generate_keypair)) 
    360         return NULL; 
    361  
    362     if (NULL == CU_add_test(suite, "Self-sign key pair", test_rsa_keys_selfsign_keypair)) 
    363         return NULL; 
    364  
    365     if (NULL == CU_add_test(suite, "Verify self-signed key pair", test_rsa_keys_verify_keypair)) 
    366         return NULL; 
    367  
    368     if (NULL == CU_add_test(suite, "Verify self-signed key pair (armoured)", test_rsa_keys_verify_armoured_keypair)) 
    369         return NULL; 
    370  
    371     if (NULL == CU_add_test(suite, "Verify self-signed key pair fails", test_rsa_keys_verify_keypair_fail)) 
    372         return NULL; 
    373  
    374     if (NULL == CU_add_test(suite, "Read keyring from file", test_rsa_keys_read_from_file)) 
     372    if (NULL == CU_add_test(suite, "Generate key pair", 
     373                            test_rsa_keys_generate_keypair)) 
     374        return NULL; 
     375 
     376    if (NULL == CU_add_test(suite, "Self-sign key pair", 
     377                            test_rsa_keys_selfsign_keypair)) 
     378        return NULL; 
     379 
     380    if (NULL == CU_add_test(suite, "Verify self-signed key pair", 
     381                            test_rsa_keys_verify_keypair)) 
     382        return NULL; 
     383 
     384    if (NULL == CU_add_test(suite, "Verify self-signed key pair (armoured)", 
     385                            test_rsa_keys_verify_armoured_keypair)) 
     386        return NULL; 
     387 
     388    if (NULL == CU_add_test(suite, "Verify self-signed key pair fails", 
     389                            test_rsa_keys_verify_keypair_fail)) 
     390        return NULL; 
     391 
     392    if (NULL == CU_add_test(suite, "Read keyring from file", 
     393                            test_rsa_keys_read_from_file)) 
    375394        return NULL; 
    376395