Changeset 496

Show
Ignore:
Timestamp:
08/27/07 16:18:35
Author:
rachel
Message:

Removed use of old macro ERR1P and replaced with new stacked errors OPS_ERROR_1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r495 r496  
    1717    /* reader errors */ 
    1818    OPS_E_R=0x1000,     /* general reader error */ 
    19     OPS_E_R_READ_FAILED =OPS_E_R+1, 
    20     OPS_E_R_EARLY_EOF   =OPS_E_R+2, 
    21     OPS_E_R_BAD_FORMAT  =OPS_E_R+3, // For example, malformed armour 
     19    OPS_E_R_READ_FAILED         =OPS_E_R+1, 
     20    OPS_E_R_EARLY_EOF           =OPS_E_R+2, 
     21    OPS_E_R_BAD_FORMAT          =OPS_E_R+3, // For example, malformed armour 
     22    OPS_E_R_UNCONSUMED_DATA     =OPS_E_R+4, 
    2223 
    2324    /* writer errors */ 
     
    3940    /* Algorithm support errors */ 
    4041    OPS_E_ALG=0x5000,                   /* general algorithm error */ 
    41     OPS_E_ALG_UNSUPPORTED_SYMMETRIC     =OPS_E_ALG+1, 
     42    OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG         =OPS_E_ALG+1, 
     43    OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG        =OPS_E_ALG+2, 
     44    OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG     =OPS_E_ALG+3, 
     45    OPS_E_ALG_UNSUPPORTED_HASH_ALG              =OPS_E_ALG+4, 
    4246 
    4347    /* Protocol errors */ 
    4448    OPS_E_PROTO=0x6000, /* general protocol error */ 
    45     OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT           =OPS_E_PROTO+2, 
    46  
     49    OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT   =OPS_E_PROTO+2, 
     50    OPS_E_PROTO_UNKNOWN_SS              =OPS_E_PROTO+3, 
     51    OPS_E_PROTO_CRITICAL_SS_IGNORED     =OPS_E_PROTO+4, 
     52    OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN     =OPS_E_PROTO+5, 
     53    OPS_E_PROTO_BAD_SIGNATURE_VRSN      =OPS_E_PROTO+6, 
     54    OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN   =OPS_E_PROTO+7, 
     55    OPS_E_PROTO_BAD_PKSK_VRSN           =OPS_E_PROTO+8, 
     56    OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN =OPS_E_PROTO+9, 
     57    OPS_E_PROTO_BAD_SK_CHECKSUM         =OPS_E_PROTO+10, 
    4758    } ops_errcode_t; 
    4859 
     
    7182#define OPS_ERROR(err,code,fmt) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt); } while(0) 
    7283#define OPS_ERROR_1(err,code,fmt,arg)   do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg); } while(0) 
     84#define OPS_ERROR_2(err,code,fmt,arg,arg2)      do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2); } while(0) 
     85#define OPS_ERROR_3(err,code,fmt,arg,arg2,arg3) do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2,arg3); } while(0) 
     86#define OPS_ERROR_4(err,code,fmt,arg,arg2,arg3,arg4)    do { ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg,arg2,arg3,arg4); } while(0) 
    7387 
    7488#endif /* OPS_ERRORS */ 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r495 r496  
    131131/*! macro to save typing */ 
    132132#define C               content.content 
     133 
    133134/*! set error code in content and run CallBack to handle error */ 
    134135#define ERRCODE(cbinfo,err)     do { C.errcode.errcode=err; CB(cbinfo,OPS_PARSER_ERRCODE,&content); } while(0) 
     
    140141#define WARN(warn)      do { C.error.error=warn; CB(OPS_PARSER_ERROR,&content);; } while(0) 
    141142#define WARNP(info,warn)        do { C.error.error=warn; CBP(info,OPS_PARSER_ERROR,&content); } while(0) 
     143#ifdef XXX 
    142144/*! \todo descr ERR1 macro */ 
    143145#define ERR1P(info,fmt,x)       do { format_error(&content,(fmt),(x)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 
    144146#define ERR2P(info,fmt,x,y)     do { format_error(&content,(fmt),(x),(y)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 
    145147#define ERR4P(info,fmt,x,y,z,a) do { format_error(&content,(fmt),(x),(y),(z),(a)); CBP(info,OPS_PARSER_ERROR,&content); return ops_false; } while(0) 
     148#endif 
    146149 
    147150/* XXX: replace ops_ptag_t with something more appropriate for limiting 
    148151   reads */ 
    149152 
     153#ifdef OLD 
    150154/* Note that this makes the parser non-reentrant, in a limited way */ 
    151155/* It is the caller's responsibility to avoid overflow in the buffer */ 
     
    161165    content->content.error.error=buf; 
    162166    } 
     167#endif 
    163168 
    164169/** 
     
    918923                                 ops_parse_info_t *pinfo) 
    919924    { 
    920     ops_parser_content_t content; 
     925    //    ops_parser_content_t content; 
    921926    unsigned char c[1]; 
    922927 
     
    927932    key->version=c[0]; 
    928933    if(key->version < 2 || key->version > 4) 
    929         ERR1P(pinfo,"Bad public key version (0x%02x)",key->version); 
     934        { 
     935        OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN, 
     936                    "Bad public key version (0x%02x)",key->version); 
     937        return 0; 
     938        } 
    930939 
    931940    if(!limited_read_time(&key->creation_time,region,pinfo)) 
     
    969978 
    970979    default: 
    971         ERR1P(pinfo,"Unknown public key algorithm (%d)",key->algorithm); 
     980        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG,"Unsupported Public Key algorithm (%s)",ops_show_pka(key->algorithm)); 
     981        return 0; 
    972982        } 
    973983 
     
    9991009    // XXX: this test should be done for all packets, surely? 
    10001010    if(region->length_read != region->length) 
    1001         ERR1P(pinfo,"Unconsumed data (%d)", 
    1002               region->length-region->length_read); 
     1011        { 
     1012        OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 
     1013                    "Unconsumed data (%d)", region->length-region->length_read); 
     1014        return 0; 
     1015        } 
    10031016 
    10041017    CBP(pinfo,tag,&content); 
     
    12301243 
    12311244    default: 
    1232         ERR1P(pinfo,"Bad signature key algorithm (%d)",C.signature.key_algorithm); 
     1245        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 
     1246                    "Unsupported signature key algorithm (%s)", 
     1247                    ops_show_pka(C.signature.key_algorithm)); 
     1248        return 0; 
    12331249        } 
    12341250 
    12351251    if(region->length_read != region->length) 
    1236         ERR1P(pinfo,"Unconsumed data (%d)",region->length-region->length_read); 
     1252        { 
     1253        OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA,"Unconsumed data (%d)",region->length-region->length_read); 
     1254        return 0; 
     1255        } 
    12371256 
    12381257    if(C.signature.signer_id_set) 
     
    14591478    default: 
    14601479        if(pinfo->ss_parsed[t8]&t7) 
    1461             ERR1P(pinfo,"Unknown signature subpacket type (%d)"
    1462                 c[0]&0x7f); 
     1480            OPS_ERROR_1(&pinfo->errors, OPS_E_PROTO_UNKNOWN_SS
     1481                        "Unknown signature subpacket type (%d)", c[0]&0x7f); 
    14631482        read=ops_false; 
    14641483        break; 
     
    14691488        { 
    14701489        if(content.critical) 
    1471             ERR1P(pinfo,"Critical signature subpacket ignored (%d)", 
    1472                   c[0]&0x7f); 
     1490            OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_CRITICAL_SS_IGNORED, 
     1491                        "Critical signature subpacket ignored (%d)", 
     1492                        c[0]&0x7f); 
    14731493        if(!read && !limited_skip(subregion.length-1,&subregion,pinfo)) 
    14741494            return 0; 
     
    14801500 
    14811501    if(read && subregion.length_read != subregion.length) 
    1482         ERR1P(pinfo,"Unconsumed data (%d)", subregion.length-subregion.length_read); 
     1502        { 
     1503        OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 
     1504                    "Unconsumed data (%d)",  
     1505                    subregion.length-subregion.length_read); 
     1506        return 0; 
     1507        } 
    14831508  
    14841509    CBP(pinfo,content.tag,&content); 
     
    16541679 
    16551680    default: 
    1656         ERR1P(pinfo,"Bad v4 signature key algorithm (%d)", 
    1657               C.signature.key_algorithm); 
     1681        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_KEY_ALG, 
     1682                    "Bad v4 signature key algorithm (%s)", 
     1683                    ops_show_pka(C.signature.key_algorithm)); 
     1684        return 0; 
    16581685        } 
    16591686 
    16601687    if(region->length_read != region->length) 
    1661         ERR1P(pinfo,"Unconsumed data (%d)", 
    1662               region->length-region->length_read); 
     1688        { 
     1689        OPS_ERROR_1(&pinfo->errors,OPS_E_R_UNCONSUMED_DATA, 
     1690                    "Unconsumed data (%d)", 
     1691                    region->length-region->length_read); 
     1692        return 0; 
     1693        } 
    16631694 
    16641695    CBP(pinfo,OPS_PTAG_CT_SIGNATURE_FOOTER,&content); 
     
    16961727    else if(c[0] == 4) 
    16971728        return parse_v4_signature(region,pinfo,v4_hashed_data_start); 
    1698     ERR1P(pinfo,"Bad signature version (%d)",c[0]); 
     1729 
     1730    OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_SIGNATURE_VRSN, 
     1731                "Bad signature version (%d)",c[0]); 
     1732    return 0; 
    16991733    } 
    17001734 
     
    17251759        return 0; 
    17261760    if(C.one_pass_signature.version != 3) 
    1727         ERR1P(pinfo,"Bad one-pass signature version (%d)", 
    1728              C.one_pass_signature.version); 
     1761        { 
     1762        OPS_ERROR_1(&pinfo->errors,OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN, 
     1763                    "Bad one-pass signature version (%d)", 
     1764                    C.one_pass_signature.version); 
     1765        return 0; 
     1766        } 
    17291767 
    17301768    if(!limited_read(c,1,region,pinfo)) 
     
    21902228    C.pk_session_key.version=c[0]; 
    21912229    if(C.pk_session_key.version != OPS_PKSK_V3) 
    2192         ERR1P(pinfo, 
     2230        { 
     2231        OPS_ERROR_1(&pinfo->errors, OPS_E_PROTO_BAD_PKSK_VRSN, 
    21932232              "Bad public-key encrypted session key version (%d)", 
    21942233              C.pk_session_key.version); 
     2234        return 0; 
     2235        } 
    21952236 
    21962237    if(!limited_read(C.pk_session_key.key_id, 
     
    22292270 
    22302271    default: 
    2231         ERR1P(pinfo
    2232              "Unknown public key algorithm in session key (%d)", 
    2233              C.pk_session_key.algorithm); 
     2272        OPS_ERROR_1(&pinfo->errors, OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG
     2273                    "Unknown public key algorithm in session key (%s)", 
     2274                    ops_show_pka(C.pk_session_key.algorithm)); 
    22342275        return 0; 
    22352276        } 
     
    22642305        { 
    22652306        // ERR1P 
    2266         OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SYMMETRIC,"Symmetric algorithm %s not supported", ops_show_symmetric_algorithm(C.pk_session_key.symmetric_algorithm)); 
     2307        OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG, 
     2308                    "Symmetric algorithm %s not supported",  
     2309                    ops_show_symmetric_algorithm(C.pk_session_key.symmetric_algorithm)); 
    22672310        return 0; 
    22682311        } 
     
    22822325    if((unsigned)n != k+3) 
    22832326        { 
    2284         ERR2P(pinfo,"decrypted message wrong length (got %d expected %d)", 
    2285               n,k+3); 
     2327        OPS_ERROR_2(&pinfo->errors,OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN, 
     2328                    "decrypted message wrong length (got %d expected %d)", 
     2329                    n,k+3); 
    22862330        return 0; 
    22872331        } 
     
    23082352    if (unencoded_m_buf[k+1]!=cs[0] || unencoded_m_buf[k+2]!=cs[1]) 
    23092353        { 
    2310         ERR4P(pinfo, "Session key checksum wrong: expected %2x %2x, got %2x %2x", 
     2354        OPS_ERROR_4(&pinfo->errors, OPS_E_PROTO_BAD_SK_CHECKSUM, 
     2355                    "Session key checksum wrong: expected %2x %2x, got %2x %2x", 
    23112356              cs[0], cs[1], unencoded_m_buf[k+1], unencoded_m_buf[k+2]); 
    23122357        return 0; 
     
    24632508        unsigned char buf[OPS_MAX_BLOCK_SIZE+2]; 
    24642509        size_t b=decrypt->blocksize; 
    2465       ops_parser_content_t content; 
     2510        //    ops_parser_content_t content; 
    24662511        ops_region_t encregion; 
    24672512 
     
    24782523            { 
    24792524            ops_reader_pop_decrypt(pinfo); 
    2480             ERR4P(pinfo,"Bad symmetric decrypt (%02x%02x vs %02x%02x)", 
    2481                   buf[b-2],buf[b-1],buf[b],buf[b+1]); 
     2525            OPS_ERROR_4(&pinfo->errors, OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT, 
     2526                        "Bad symmetric decrypt (%02x%02x vs %02x%02x)", 
     2527                        buf[b-2],buf[b-1],buf[b],buf[b+1]); 
     2528            return 0; 
    24822529            } 
    24832530 
     
    27342781 
    27352782    default: 
    2736         ERR1P(pinfo,"Unknown content tag 0x%x", C.ptag.content_tag); 
     2783        OPS_ERROR_1(&pinfo->errors,OPS_E_P_UNKNOWN_TAG, 
     2784                    "Unknown content tag 0x%x", C.ptag.content_tag); 
    27372785        r=0; 
    27382786        }