Changeset 422

Show
Ignore:
Timestamp:
07/26/06 04:18:10
Author:
ben
Message:

Propagate armour errors.

Files:

Legend:

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

    r418 r422  
    44#include "keyring.h" 
    55 
    6 int ops_parse_and_accumulate(ops_keyring_t *keyring,ops_parse_info_t *parse_info); 
     6int ops_parse_and_accumulate(ops_keyring_t *keyring, 
     7                             ops_parse_info_t *parse_info); 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r336 r422  
    1919    OPS_E_R_READ_FAILED =OPS_E_R+1, 
    2020    OPS_E_R_EARLY_EOF   =OPS_E_R+2, 
     21    OPS_E_R_BAD_FORMAT  =OPS_E_R+3, // For example, malformed armour 
    2122 
    2223    /* writer errors */ 
  • openpgpsdk/trunk/src/armour.c

    r417 r422  
    6464// FIXME: move these to a common header 
    6565#define CB(cbinfo,t,pc) do { (pc)->tag=(t); if(ops_parse_cb((pc),(cbinfo)) == OPS_RELEASE_MEMORY) ops_parser_content_free(pc); } while(0) 
    66 #define ERR(cbinfo,err)        do { content.content.error.error=err; content.tag=OPS_PARSER_ERROR; ops_parse_cb(&content,(cbinfo)); return -1; } while(0) 
     66#define ERR(cbinfo,err,code)   do { content.content.error.error=err; content.tag=OPS_PARSER_ERROR; ops_parse_cb(&content,(cbinfo)); OPS_ERROR(errors,code,err); return -1; } while(0) 
    6767 
    6868static void push_back(dearmour_arg_t *arg,const unsigned char *buf, 
     
    230230            { 
    231231            free(hash); 
    232             ERR(cbinfo,"Unknown hash algorithm"); 
     232            ERR(cbinfo,"Unknown hash algorithm",OPS_E_R_BAD_FORMAT); 
    233233            } 
    234234        ops_hash_any(hash,alg); 
     
    256256                /* then this had better be a trailer! */ 
    257257                if(c != '-') 
    258                     ERR(cbinfo,"Bad dash-escaping"); 
     258                    ERR(cbinfo,"Bad dash-escaping",OPS_E_R_BAD_FORMAT); 
    259259                for(count=2 ; count < 5 ; ++count) 
    260260                    { 
     
    262262                        return -1; 
    263263                    if(c != '-') 
    264                         ERR(cbinfo,"Bad dash-escaping (2)"); 
     264                        ERR(cbinfo,"Bad dash-escaping (2)",OPS_E_R_BAD_FORMAT); 
    265265                    } 
    266266                arg->state=AT_TRAILER_NAME; 
     
    344344                if(!first && !arg->allow_headers_without_gap) 
    345345                    // then we have seriously malformed armour 
    346                     ERR(cbinfo,"No colon in armour header"); 
     346                    ERR(cbinfo,"No colon in armour header",OPS_E_R_BAD_FORMAT); 
    347347                else 
    348348                    { 
    349349                    if(first && 
    350350                       !(arg->allow_headers_without_gap || arg->allow_no_gap)) 
    351                         ERR(cbinfo,"No colon in armour header (2)"); 
     351                        ERR(cbinfo,"No colon in armour header (2)", 
     352                            OPS_E_R_BAD_FORMAT); 
    352353                    // then we have a nasty armoured block with no 
    353354                    // headers, not even a blank line. 
     
    360361                *s='\0'; 
    361362                if(s[1] != ' ') 
    362                     ERR(cbinfo,"No space in armour header"); 
     363                    ERR(cbinfo,"No space in armour header",OPS_E_R_BAD_FORMAT); 
    363364                add_header(arg,buf,s+2); 
    364365                nbuf=0; 
     
    454455    ret=read4(arg,errors,rinfo,cbinfo,&c,&n,&l); 
    455456    if(ret < 0) 
    456         ERR(cbinfo,"Badly formed base64"); 
     457        ERR(cbinfo,"Badly formed base64",OPS_E_R_BAD_FORMAT); 
    457458 
    458459    if(n == 3) 
     
    471472        c=read_char(arg,errors,rinfo,cbinfo,ops_false); 
    472473        if(c != '=') 
    473             ERR(cbinfo,"Badly terminated base64"); 
     474            ERR(cbinfo,"Badly terminated base64",OPS_E_R_BAD_FORMAT); 
    474475        } 
    475476    else if(n == 0) 
     
    491492        c=read_and_eat_whitespace(arg,errors,rinfo,cbinfo,ops_true); 
    492493        if(c != '\n') 
    493             ERR(cbinfo,"No newline at base64 end"); 
     494            ERR(cbinfo,"No newline at base64 end",OPS_E_R_BAD_FORMAT); 
    494495        c=read_char(arg,errors,rinfo,cbinfo,ops_false); 
    495496        if(c != '=') 
    496             ERR(cbinfo,"No checksum at base64 end"); 
     497            ERR(cbinfo,"No checksum at base64 end",OPS_E_R_BAD_FORMAT); 
    497498        } 
    498499 
     
    502503        ret=read4(arg,errors,rinfo,cbinfo,&c,&n,&arg->read_checksum); 
    503504        if(ret < 0 || n != 4) 
    504             ERR(cbinfo,"Error in checksum"); 
     505            ERR(cbinfo,"Error in checksum",OPS_E_R_BAD_FORMAT); 
    505506        c=read_char(arg,errors,rinfo,cbinfo,ops_true); 
    506507        if(arg->allow_trailing_whitespace) 
    507508            c=eat_whitespace(c,arg,errors,rinfo,cbinfo,ops_true); 
    508509        if(c != '\n') 
    509             ERR(cbinfo,"Badly terminated checksum"); 
     510            ERR(cbinfo,"Badly terminated checksum",OPS_E_R_BAD_FORMAT); 
    510511        c=read_char(arg,errors,rinfo,cbinfo,ops_false); 
    511512        if(c != '-') 
    512             ERR(cbinfo,"Bad base64 trailer (2)"); 
     513            ERR(cbinfo,"Bad base64 trailer (2)",OPS_E_R_BAD_FORMAT); 
    513514        } 
    514515 
     
    517518        for(n=0 ; n < 4 ; ++n) 
    518519            if(read_char(arg,errors,rinfo,cbinfo,ops_false) != '-') 
    519                 ERR(cbinfo,"Bad base64 trailer"); 
     520                ERR(cbinfo,"Bad base64 trailer",OPS_E_R_BAD_FORMAT); 
    520521        arg->eof64=ops_true; 
    521522        } 
     
    533534 
    534535    if(arg->eof64 && arg->read_checksum != arg->checksum) 
    535         ERR(cbinfo,"Checksum mismatch"); 
     536        ERR(cbinfo,"Checksum mismatch",OPS_E_R_BAD_FORMAT); 
    536537 
    537538    return 1; 
     
    701702                 } 
    702703             /* then I guess this wasn't a proper trailer */ 
    703              ERR(cbinfo,"Bad ASCII armour trailer"); 
     704             ERR(cbinfo,"Bad ASCII armour trailer",OPS_E_R_BAD_FORMAT); 
    704705             break; 
    705706 
     
    714715                 if(c != '-') 
    715716                     /* wasn't a trailer after all */ 
    716                      ERR(cbinfo,"Bad ASCII armour trailer (2)"); 
     717                     ERR(cbinfo,"Bad ASCII armour trailer (2)", 
     718                         OPS_E_R_BAD_FORMAT); 
    717719                 } 
    718720 
     
    726728             if(c != '\n') 
    727729                 /* wasn't a trailer line after all */ 
    728                  ERR(cbinfo,"Bad ASCII armour trailer (3)"); 
     730                 ERR(cbinfo,"Bad ASCII armour trailer (3)",OPS_E_R_BAD_FORMAT); 
    729731 
    730732             if(!strncmp(buf,"BEGIN ",6))