Changeset 307

Show
Ignore:
Timestamp:
11/25/05 14:44:20
Author:
ben
Message:

Start hiding things.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/Makefile.template

    r305 r307  
    77LIBDEPS=common.o ../src/libops.a 
    88LIBS=$(LIBDEPS) %CRYPTO_LIBS% %ZLIB% $(DM_LIB) %LIBS% 
     9EXES=packet-dump verify create-key create-signed-key verify2 sign-detached 
    910 
    10 all: Makefile .depend packet-dump verify create-key create-signed-key \ 
    11      verify2 sign-detached 
     11all: Makefile .depend $(EXES) 
    1212 
    1313test: test-dump test-verify test-verify-armoured test-create-key 
     
    3939 
    4040clean: 
    41         rm -f packet-dump verify create-key *.o 
     41        rm -f $(EXES) *.o 
    4242        rm -f TAGS 
    4343 
  • openpgpsdk/trunk/examples/create-key.c

    r301 r307  
    55int main(int argc,char **argv) 
    66    { 
    7     ops_writer_fd_arg_t arg; 
    8     ops_create_info_t info; 
     7    ops_create_info_t *info; 
    98    const unsigned char *id; 
    109    const char *nstr; 
     
    2625    BN_hex2bn(&e,estr); 
    2726 
    28     arg.fd=1; 
    29     info.writer=ops_writer_fd; 
    30     info.arg=&arg; 
     27    info=ops_create_info_new(); 
     28    ops_create_info_set_writer_fd(info,1); 
    3129 
    32     ops_write_rsa_public_key(time(NULL),n,e,&info); 
    33     ops_write_user_id(id,&info); 
     30    ops_write_rsa_public_key(time(NULL),n,e,info); 
     31    ops_write_user_id(id,info); 
     32 
     33    ops_create_info_delete(info); 
    3434 
    3535    return 0; 
  • openpgpsdk/trunk/examples/create-signed-key.c

    r304 r307  
    2020int main(int argc,char **argv) 
    2121    { 
    22     ops_writer_fd_arg_t arg; 
    23     ops_create_info_t info; 
    24     ops_create_signature_t sig; 
     22    ops_create_info_t *info; 
     23    ops_create_signature_t *sig; 
    2524    ops_user_id_t id; 
    2625    unsigned char keyid[OPS_KEY_ID_SIZE]; 
     
    3130    const char *pubfile; 
    3231    BIGNUM *f4; 
     32    int fd; 
    3333 
    3434    if(argc != 4) 
     
    5151    ops_init(); 
    5252 
     53    info=ops_create_info_new(); 
     54 
    5355    // OpenSSL has p and q reversed relative to OpenPGP 
    5456    ops_fast_create_rsa_secret_key(&skey,time(NULL),rsa->q,rsa->p,rsa->d, 
    5557                                   rsa->iqmp,rsa->n,rsa->e); 
    5658 
    57     skey.key.rsa.p=rsa->q; 
    58     skey.key.rsa.q=rsa->p; 
    59     skey.key.rsa.d=rsa->d; 
    60     skey.key.rsa.u=rsa->iqmp; 
    61  
    62     arg.fd=open(secfile,O_CREAT|O_TRUNC|O_WRONLY,0666); 
    63     if(arg.fd < 0) 
     59    fd=open(secfile,O_CREAT|O_TRUNC|O_WRONLY,0666); 
     60    if(fd < 0) 
    6461        { 
    6562        perror(secfile); 
    6663        exit(2); 
    6764        } 
     65    ops_create_info_set_writer_fd(info,fd); 
    6866 
    69     info.writer=ops_writer_fd; 
    70     info.arg=&arg; 
     67    ops_write_struct_secret_key(&skey,info); 
    7168 
    72     ops_write_struct_secret_key(&skey,&info); 
     69    ops_create_info_close_writer(info); 
    7370 
    74     close(arg.fd); 
     71    close(fd); 
    7572 
    76     arg.fd=open(pubfile,O_CREAT|O_TRUNC|O_WRONLY,0666); 
    77     if(arg.fd < 0) 
     73    fd=open(pubfile,O_CREAT|O_TRUNC|O_WRONLY,0666); 
     74    if(fd < 0) 
    7875        { 
    7976        perror(pubfile); 
    8077        exit(2); 
    8178        } 
     79    ops_create_info_set_writer_fd(info,fd); 
    8280 
    83     ops_write_struct_public_key(&skey.public_key,&info); 
     81    ops_write_struct_public_key(&skey.public_key,info); 
    8482 
    8583    ops_fast_create_user_id(&id,user_id); 
    86     ops_write_struct_user_id(&id,&info); 
     84    ops_write_struct_user_id(&id,info); 
    8785 
    88     ops_signature_start_key_signature(&sig,&skey.public_key,&id, 
     86    sig=ops_create_signature_new(); 
     87 
     88    ops_signature_start_key_signature(sig,&skey.public_key,&id, 
    8989                                      OPS_CERT_POSITIVE); 
    90     ops_signature_add_creation_time(&sig,time(NULL)); 
     90    ops_signature_add_creation_time(sig,time(NULL)); 
    9191 
    9292    ops_keyid(keyid,&skey.public_key); 
    93     ops_signature_add_issuer_key_id(&sig,keyid); 
     93    ops_signature_add_issuer_key_id(sig,keyid); 
    9494 
    95     ops_signature_add_primary_user_id(&sig,ops_true); 
     95    ops_signature_add_primary_user_id(sig,ops_true); 
    9696 
    97     ops_signature_hashed_subpackets_end(&sig); 
     97    ops_signature_hashed_subpackets_end(sig); 
    9898 
    99     ops_write_signature(&sig,&skey.public_key,&skey,&info); 
     99    ops_write_signature(sig,&skey.public_key,&skey,info); 
     100 
     101    ops_create_signature_delete(sig); 
     102    ops_create_info_delete(info); 
     103 
     104    close(fd); 
     105 
     106    RSA_free(rsa); 
     107    BN_free(f4); 
    100108 
    101109    ops_finish(); 
    102110 
    103     close(arg.fd); 
    104  
    105111    return 0; 
    106112    } 
  • openpgpsdk/trunk/examples/packet-dump.c

    r306 r307  
    231231static void print_string_and_value( char *name, char *str, unsigned char value) 
    232232    { 
    233  
    234233    print_name(name); 
    235234 
  • openpgpsdk/trunk/include/openpgpsdk/create.h

    r304 r307  
    2020    }; 
    2121 
    22 struct ops_create_info; 
    2322/** 
    2423 * \ingroup Create 
    2524 * the writer function prototype 
    2625 */ 
    27 typedef ops_writer_ret_t ops_packet_writer_t(const unsigned char *src, 
    28                                              unsigned length, 
    29                                              ops_writer_flags_t flags, 
    30                                              struct ops_create_info *create_info); 
     26typedef ops_writer_ret_t ops_writer_t(const unsigned char *src, 
     27                                      unsigned length, 
     28                                      ops_writer_flags_t flags, 
     29                                      ops_error_t **errors, 
     30                                      void *arg); 
    3131 
    32 /** 
    33  * \ingroup Create 
    34  * This struct contains the required information about how to write 
    35  */ 
    36 struct ops_create_info 
    37     { 
    38     ops_packet_writer_t *writer; /*!< the writer function */ 
    39     void *arg;                  /*!< arguments for the writer function */ 
    40     ops_error_t * errors;       /*!< an error stack */ 
    41     }; 
    42 /** 
    43  * \ingroup Create 
    44  * Contains the required information about how to write 
    45  */ 
    46 typedef struct ops_create_info ops_create_info_t; 
     32typedef void ops_writer_destroyer_t(void *arg); 
     33 
     34void ops_create_info_set_writer(ops_create_info_t *info, 
     35                                ops_writer_t *writer, 
     36                                ops_writer_destroyer_t *destroyer, 
     37                                void *arg); 
     38 
     39ops_create_info_t *ops_create_info_new(void); 
     40void ops_create_info_delete(ops_create_info_t *info); 
     41void ops_create_info_set_writer_fd(ops_create_info_t *info,int fd); 
     42void ops_create_info_close_writer(ops_create_info_t *info); 
    4743 
    4844ops_boolean_t ops_write(const void *src,unsigned length, 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r301 r307  
    66 
    77#include "openpgpsdk/types.h" 
     8#include <errno.h>  
    89 
    910/** error codes */ 
     
    3940    { 
    4041    ops_errcode_t errcode; 
    41     int errno; /*!< irrelevent unless errcode == OPS_E_SYSTEM_ERROR */ 
     42    int sys_errno; /*!< irrelevent unless errcode == OPS_E_SYSTEM_ERROR */ 
    4243    char *comment; 
    4344    const char *file; 
     
    4849char *ops_errcode(const ops_errcode_t errcode); 
    4950 
    50 void push_error(ops_error_t **errstack,ops_errcode_t errcode,int errno, 
     51void push_error(ops_error_t **errstack,ops_errcode_t errcode,int sys_errno, 
    5152                const char *file,int line,const char *comment,...); 
    5253void print_error(ops_error_t *err); 
  • openpgpsdk/trunk/include/openpgpsdk/memory.h

    r301 r307  
    2626void ops_memory_release(ops_memory_t *mem); 
    2727 
    28 struct ops_create_info; 
    29 ops_writer_ret_t ops_writer_memory(const unsigned char *src,unsigned length, 
    30                                    ops_writer_flags_t flags, 
    31                                    struct ops_create_info *create_info); 
    32  
     28void ops_create_info_set_writer_memory(ops_create_info_t *info, 
     29                                       ops_memory_t *mem); 
    3330#endif 
  • openpgpsdk/trunk/include/openpgpsdk/packet.h

    r287 r307  
    299299    } ops_public_key_union_t; 
    300300 
     301/** Version. 
     302 * OpenPGP has two different protocol versions: version 3 and version 4. 
     303 * 
     304 * \see RFC2440bis-12 5.2 
     305 */ 
     306typedef enum 
     307    { 
     308    OPS_V3=3,   /*<! Version 3 */ 
     309    OPS_V4=4,   /*<! Version 4 */ 
     310    } ops_version_t; 
     311 
    301312/** Structure to hold one pgp public key */ 
    302313typedef struct 
    303314    { 
    304     unsigned                  version;        /*!< version of the key (v3, v4...) */ 
     315    ops_version_t             version;        /*!< version of the key (v3, v4...) */ 
    305316    time_t                      creation_time;  /*!< when the key was created.  Note that interpretation varies with key 
    306317                                                  version. */ 
     
    386397    } ops_user_attribute_t; 
    387398 
    388 /** Signature Version. 
    389  * OpenPGP has two different signature versions: version 3 and version 4. 
    390  * 
    391  * \see RFC2440bis-12 5.2 
    392  */ 
    393 typedef enum 
    394     { 
    395     OPS_SIG_V3=3,       /*<! Version 3 Signature */ 
    396     OPS_SIG_V4=4,       /*<! Version 4 Signature */ 
    397     } ops_sig_version_t; 
    398  
    399399/** Signature Type. 
    400400 * OpenPGP defines different signature types that allow giving different meanings to signatures.  Signature types 
     
    485485    } ops_signature_union_t; 
    486486 
     487#define OPS_KEY_ID_SIZE         8 
     488 
    487489/** Struct to hold a signature packet. 
    488490 * 
     
    490492 * \see RFC2440bis-12 5.2.3 
    491493 */ 
    492 #define OPS_KEY_ID_SIZE         8 
    493 /** signature */ 
    494 typedef struct 
    495     { 
    496     ops_sig_version_t           version;        /*!< signature version number */ 
     494typedef struct 
     495    { 
     496    ops_version_t               version;        /*!< signature version number */ 
    497497    ops_sig_type_t              type;           /*!< signature type value */ 
    498498    time_t                      creation_time;  /*!< creation time of the signature */ 
  • openpgpsdk/trunk/include/openpgpsdk/signature.h

    r304 r307  
    66#include "create.h" 
    77 
    8 /** \ingroup Create 
    9  * needed for signature creation 
    10  */ 
    11 typedef struct 
    12     { 
    13     ops_packet_writer_t *writer; /*!< The writer function */ 
    14     void *arg;  /*!< Arguments for the writer function */ 
    15     ops_hash_t hash;  
    16     ops_signature_t sig;  
    17     ops_memory_t mem;  
    18     ops_create_info_t info; /*!< how to do the writing */ 
    19     unsigned hashed_count_offset; 
    20     unsigned hashed_data_length; 
    21     unsigned unhashed_count_offset; 
    22     } ops_create_signature_t; 
     8typedef struct ops_create_signature ops_create_signature_t; 
     9 
     10ops_create_signature_t *ops_create_signature_new(void); 
     11void ops_create_signature_delete(ops_create_signature_t *sig); 
    2312 
    2413ops_boolean_t 
     
    4332                                       ops_sig_type_t type); 
    4433void ops_signature_start_plaintext_signature(ops_create_signature_t *sig, 
     34                                             ops_secret_key_t *key, 
    4535                                             ops_hash_algorithm_t hash, 
    4636                                             ops_sig_type_t type); 
  • openpgpsdk/trunk/include/openpgpsdk/types.h

    r304 r307  
    6464typedef enum ops_writer_ret_t ops_writer_ret_t; 
    6565 
     66/** 
     67 * \ingroup Create 
     68 * Contains the required information about how to write 
     69 */ 
     70typedef struct ops_create_info ops_create_info_t; 
    6671 
    6772#endif 
  • openpgpsdk/trunk/include/openpgpsdk/util.h

    r301 r307  
    2020    } ops_reader_fd_arg_t; 
    2121 
    22 /** Arguments for writer_fd 
    23  */ 
    24 typedef struct 
    25     { 
    26     int fd; /*!< file descriptor */ 
    27     } ops_writer_fd_arg_t; 
    28  
    2922void hexdump(const unsigned char *src,size_t length); 
    3023ops_reader_ret_t ops_reader_fd(unsigned char *dest,unsigned *plength, 
    3124                               ops_reader_flags_t flags,ops_parse_info_t *parse_info); 
    32 struct ops_create_info; 
    33 ops_writer_ret_t ops_writer_fd(const unsigned char *src,unsigned length, 
    34                                ops_writer_flags_t flags,struct ops_create_info *create_info); 
    3525 
    3626/* typesafe deconstification */ 
     
    4434#define OPS_ARRAY_SIZE(a)       (sizeof(a)/sizeof(*(a))) 
    4535 
     36/** Allocate zeroed memory */ 
     37void *ops_mallocz(size_t n); 
     38 
    4639#endif 
  • openpgpsdk/trunk/src/armour.c

    r296 r307  
    687687    dearmour_arg_t *arg; 
    688688 
    689     arg=malloc(sizeof *arg); 
    690     memset(arg,'\0',sizeof *arg); 
     689    arg=ops_mallocz(sizeof *arg); 
    691690 
    692691    arg->reader_arg=parse_info->reader_arg; 
  • openpgpsdk/trunk/src/create.c

    r304 r307  
    66#include <string.h> 
    77#include <assert.h> 
     8#include <unistd.h> 
     9 
     10/** 
     11 * \ingroup Create 
     12 * This struct contains the required information about how to write 
     13 */ 
     14struct ops_create_info 
     15    { 
     16    ops_writer_t *writer; /*!< the writer function */ 
     17    void *arg;                  /*!< arguments for the writer function */ 
     18    ops_writer_destroyer_t *destroyer; 
     19    ops_error_t *errors;        /*!< an error stack */ 
     20    }; 
    821 
    922/* 
     
    1326                                ops_create_info_t *info) 
    1427    { 
    15     return info->writer(src,length,0,info) == OPS_W_OK; 
     28    return info->writer(src,length,0,&info->errors,info->arg) == OPS_W_OK; 
    1629    } 
    1730 
     
    401414                          ops_boolean_t make_packet) 
    402415    { 
    403     ops_create_info_t info; 
     416    ops_create_info_t *info; 
     417 
     418    info=ops_create_info_new(); 
    404419 
    405420    ops_memory_init(out,128); 
    406     info.writer=ops_writer_memory; 
    407     info.arg=out; 
    408  
    409     write_public_key_body(key,&info); 
     421    ops_create_info_set_writer_memory(info,out); 
     422 
     423    write_public_key_body(key,info); 
    410424 
    411425    if(make_packet) 
    412426        ops_memory_make_packet(out,OPS_PTAG_CT_PUBLIC_KEY); 
     427 
     428    ops_create_info_delete(info); 
    413429    } 
    414430 
     
    466482        && write_secret_key_body(key,info); 
    467483    } 
     484 
     485/** 
     486 * \ingroup Create 
     487 * 
     488 * Create a new ops_create_info_t structure. 
     489 * 
     490 * \return the new structure. 
     491 */ 
     492ops_create_info_t *ops_create_info_new(void) 
     493    { return ops_mallocz(sizeof(ops_create_info_t)); } 
     494 
     495/** 
     496 * \ingroup Create 
     497 * 
     498 * Delete an ops_create_info_t structure. If a writer is active, then 
     499 * that is also deleted. 
     500 * 
     501 * \param info the structure to be deleted. 
     502 */ 
     503void ops_create_info_delete(ops_create_info_t *info) 
     504    { 
     505    if(info->destroyer) 
     506        { 
     507        info->destroyer(info->arg); 
     508        info->destroyer=NULL; 
     509        } 
     510 
     511    free(info); 
     512    } 
     513 
     514typedef struct 
     515    { 
     516    int fd; 
     517    } writer_fd_arg_t; 
     518 
     519static ops_writer_ret_t fd_writer(const unsigned char *src,unsigned length, 
     520                                  ops_writer_flags_t flags, 
     521                                  ops_error_t **errors,void *arg_) 
     522    { 
     523    writer_fd_arg_t *arg=arg_; 
     524    int n=write(arg->fd,src,length); 
     525 
     526    OPS_USED(flags); 
     527 
     528    if(n == -1) 
     529        { 
     530        ops_system_error_1(errors,OPS_E_W_WRITE_FAILED,"write", 
     531                           "file descriptor %d",arg->fd); 
     532        return OPS_W_ERROR; 
     533        } 
     534 
     535    if((unsigned)n != length) 
     536        { 
     537        ops_error_1(errors,OPS_E_W_WRITE_TOO_SHORT, 
     538                    "file descriptor %d",arg->fd); 
     539        return OPS_W_ERROR; 
     540        } 
     541 
     542    return OPS_W_OK; 
     543    } 
     544 
     545static void fd_destroyer(void *arg) 
     546    { 
     547    free(arg); 
     548    } 
     549 
     550/** 
     551 * \ingroup Create 
     552 * 
     553 * Set the writer in info to be a stock writer that writes to a file 
     554 * descriptor. If another writer has already been set, then that is 
     555 * first destroyed. 
     556 *  
     557 * \param info The info structure 
     558 * \param fd The file descriptor 
     559 * 
     560 */ 
     561 
     562void ops_create_info_set_writer_fd(ops_create_info_t *info,int fd) 
     563    { 
     564    writer_fd_arg_t *arg=malloc(sizeof *arg); 
     565 
     566    arg->fd=fd; 
     567    ops_create_info_set_writer(info,fd_writer,fd_destroyer,arg); 
     568    } 
     569 
     570/** 
     571 * \ingroup Create 
     572 * 
     573 * Set a writer in info. If another writer has already been set, then 
     574 * that is first destroyed. 
     575 * 
     576 * \param info The info structure 
     577 * \param writer The writer 
     578 * \param destroyer The destroyer 
     579 * \param arg The argument for the writer and destroyer 
     580 */ 
     581void ops_create_info_set_writer(ops_create_info_t *info, 
     582                                ops_writer_t *writer, 
     583                                ops_writer_destroyer_t *destroyer, 
     584                                void *arg) 
     585    { 
     586    ops_create_info_close_writer(info); 
     587    info->writer=writer; 
     588    info->destroyer=destroyer; 
     589    info->arg=arg; 
     590    } 
     591 
     592/** 
     593 * \ingroup Create 
     594 * 
     595 * Close the writer currently set in info. 
     596 * 
     597 * \param info The info structure 
     598 */ 
     599void ops_create_info_close_writer(ops_create_info_t *info) 
     600    { 
     601    if(info->destroyer) 
     602        info->destroyer(info->arg); 
     603 
     604    info->writer=NULL; 
     605    info->destroyer=NULL; 
     606    info->arg=NULL; 
     607    } 
  • openpgpsdk/trunk/src/errors.c

    r301 r307  
    5858 */ 
    5959 
    60 void push_error(ops_error_t **errstack,ops_errcode_t errcode,int errno, 
     60void push_error(ops_error_t **errstack,ops_errcode_t errcode,int sys_errno, 
    6161                const char *file,int line,const char *fmt,...) 
    6262    { 
     
    8484    // fill in the details 
    8585    err->errcode=errcode; 
    86     err->errno=errno; 
     86    err->sys_errno=sys_errno; 
    8787    err->file=file; 
    8888    err->line=line; 
     
    9595    printf("%s:%d: ",err->file,err->line); 
    9696    if (err->errcode==OPS_E_SYSTEM_ERROR) 
    97         printf("system error %d returned from %s()\n",err->errno, err->comment); 
     97        printf("system error %d returned from %s()\n",err->sys_errno, 
     98               err->comment); 
    9899    else 
    99         printf("%s, %s\n", 
    100                ops_errcode(err->errcode), 
    101                err->comment); 
     100        printf("%s, %s\n",ops_errcode(err->errcode),err->comment); 
    102101    } 
    103102 
  • openpgpsdk/trunk/src/memory.c

    r301 r307  
    5858    } 
    5959 
    60 ops_writer_ret_t ops_writer_memory(const unsigned char *src,unsigned length, 
    61                                    ops_writer_flags_t flags, 
    62                                    ops_create_info_t *create_info) 
     60static ops_writer_ret_t memory_writer(const unsigned char *src,unsigned length, 
     61                                      ops_writer_flags_t flags, 
     62                                      ops_error_t **errors, 
     63                                      void *arg) 
    6364    { 
    64     ops_memory_t *mem=create_info->arg; 
     65    ops_memory_t *mem=arg; 
    6566 
    6667    OPS_USED(flags); 
     68    OPS_USED(errors); 
    6769    ops_memory_add(mem,src,length); 
    6870    return OPS_W_OK; 
     71    } 
     72 
     73/** 
     74 * \ingroup Create 
     75 * 
     76 * Set a memory writer. Note that it is the caller's resposibility to 
     77 * release mem. 
     78 * 
     79 * \param info The info structure 
     80 * \param mem The memory structure 
     81 */ 
     82 
     83void ops_create_info_set_writer_memory(ops_create_info_t *info, 
     84                                       ops_memory_t *mem) 
     85    { 
     86    ops_create_info_set_writer(info,memory_writer,NULL,mem); 
    6987    } 
    7088 
  • openpgpsdk/trunk/src/packet-parse.c

    r304 r307  
    990990    ops_parser_content_t content; 
    991991 
    992     C.signature.version=OPS_SIG_V3; 
     992    C.signature.version=OPS_V3; 
    993993 
    994994    /* hash info length */ 
     
    13961396 
    13971397    memset(&C.signature,'\0',sizeof C.signature); 
    1398     C.signature.version=OPS_SIG_V4; 
     1398    C.signature.version=OPS_V4; 
    13991399    C.signature.v4_hashed_data_start=v4_hashed_data_start; 
    14001400 
  • openpgpsdk/trunk/src/signature.c

    r304 r307  
    77#include <assert.h> 
    88#include <string.h> 
     9 
     10/** \ingroup Create 
     11 * needed for signature creation 
     12 */ 
     13struct ops_create_signature 
     14    { 
     15    ops_hash_t hash;  
     16    ops_signature_t sig;  
     17    ops_memory_t mem;  
     18    ops_create_info_t *info; /*!< how to do the writing */ 
     19    unsigned hashed_count_offset; 
     20    unsigned hashed_data_length; 
     21    unsigned unhashed_count_offset; 
     22    }; 
     23 
     24ops_create_signature_t *ops_create_signature_new() 
     25    { return ops_mallocz(sizeof(ops_create_signature_t)); } 
     26 
     27void ops_create_signature_delete(ops_create_signature_t *sig) 
     28    { 
     29    ops_create_info_delete(sig->info); 
     30    sig->info=NULL; 
     31    free(sig); 
     32    } 
    933 
    1034static unsigned char prefix_md5[]={ 0x30,0x20,0x30,0x0C,0x06,0x08,0x2A,0x86, 
     
    143167                             const unsigned char *raw_packet) 
    144168    { 
    145     if(sig->version == OPS_SIG_V4) 
     169    if(sig->version == OPS_V4) 
    146170        { 
    147171        if(raw_packet) 
     
    231255    init_signature(&hash,sig,key); 
    232256 
    233     if(sig->version == OPS_SIG_V4) 
     257    if(sig->version == OPS_V4) 
    234258        { 
    235259        ops_hash_add_int(&hash,0xb4,1); 
     
    308332                                       ops_sig_type_t type) 
    309333    { 
    310     memset(sig,'\0',sizeof *sig); 
     334    sig->info=ops_create_info_new(); 
     335 
    311336    // XXX: refactor with check (in several ways - check should probably 
    312337    // use the buffered writer to construct packets (done), and also should 
    313338    // share code for hash calculation) 
    314     sig->sig.version=OPS_SIG_V4; 
     339    sig->sig.version=OPS_V4; 
    315340    sig->sig.hash_algorithm=OPS_HASH_SHA1; 
    316341    sig->sig.key_algorithm=key->algorithm; 
     
    328353    // thing to get counts before writing. 
    329354    ops_memory_init(&sig->mem,100); 
    330     sig->info.writer=ops_writer_memory; 
    331     sig->info.arg=&sig->mem; 
     355    ops_create_info_set_writer_memory(sig->info,&sig->mem); 
    332356 
    333357    // write nearly up to the first subpacket 
    334     ops_write_scalar(sig->sig.version,1,&sig->info); 
    335     ops_write_scalar(sig->sig.type,1,&sig->info); 
    336     ops_write_scalar(sig->sig.key_algorithm,1,&sig->info); 
    337     ops_write_scalar(sig->sig.hash_algorithm,1,&sig->info); 
     358    ops_write_scalar(sig->sig.version,1,sig->info); 
     359    ops_write_scalar(sig->sig.type,1,sig->info); 
     360    ops_write_scalar(sig->sig.key_algorithm,1,sig->info); 
     361    ops_write_scalar(sig->sig.hash_algorithm,1,sig->info); 
    338362 
    339363    // dummy hashed subpacket count 
    340364    sig->hashed_count_offset=sig->mem.length; 
    341     ops_write_scalar(0,2,&sig->info); 
     365    ops_write_scalar(0,2,sig->info); 
    342366    } 
    343367 
     
    353377 */ 
    354378void ops_signature_start_plaintext_signature(ops_create_signature_t *sig, 
     379                                             ops_secret_key_t *key, 
    355380                                             ops_hash_algorithm_t hash, 
    356381                                             ops_sig_type_t type) 
    357382    { 
    358     memset(sig,'\0',sizeof *sig); 
     383    sig->info=ops_create_info_new(); 
     384 
    359385    // XXX: refactor with check (in several ways - check should probably 
    360386    // use the buffered writer to construct packets (done), and also should 
    361387    // share code for hash calculation) 
    362     sig->sig.version=OPS_SIG_V4; 
     388    sig->sig.version=OPS_V4; 
     389    sig->sig.key_algorithm=key->public_key.algorithm; 
    363390    sig->sig.hash_algorithm=hash; 
    364391    sig->sig.type=type; 
     
    371398    // thing to get counts before writing. 
    372399    ops_memory_init(&sig->mem,100); 
    373     sig->info.writer=ops_writer_memory; 
    374     sig->info.arg=&sig->mem; 
     400    ops_create_info_set_writer_memory(sig->info,&sig->mem); 
    375401 
    376402    // write nearly up to the first subpacket 
    377     ops_write_scalar(sig->sig.version,1,&sig->info); 
    378     ops_write_scalar(sig->sig.type,1,&sig->info); 
    379     ops_write_scalar(sig->sig.key_algorithm,1,&sig->info); 
    380     ops_write_scalar(sig->sig.hash_algorithm,1,&sig->info); 
     403    ops_write_scalar(sig->sig.version,1,sig->info); 
     404    ops_write_scalar(sig->sig.type,1,sig->info); 
     405    ops_write_scalar(sig->sig.key_algorithm,1,sig->info); 
     406    ops_write_scalar(sig->sig.hash_algorithm,1,sig->info); 
    381407 
    382408    // dummy hashed subpacket count 
    383409    sig->hashed_count_offset=sig->mem.length; 
    384     ops_write_scalar(0,2,&sig->info); 
     410    ops_write_scalar(0,2,sig->info); 
    385411    } 
    386412 
     
    415441    // dummy unhashed subpacket count 
    416442    sig->unhashed_count_offset=sig->mem.length; 
    417     ops_write_scalar(0,2,&sig->info); 
     443    ops_write_scalar(0,2,sig->info); 
    418444    } 
    419445 
     
    448474    // and write it directly to the output instead of via memory. 
    449475    assert(key->algorithm == OPS_PKA_RSA); 
    450     rsa_sign(&sig->hash,&key->key.rsa,&skey->key.rsa,&sig->info); 
     476    rsa_sign(&sig->hash,&key->key.rsa,&skey->key.rsa,sig->info); 
    451477 
    452478    ops_write_ptag(OPS_PTAG_CT_SIGNATURE,info); 
     
    467493void ops_signature_add_creation_time(ops_create_signature_t *sig,time_t when) 
    468494    { 
    469     ops_write_ss_header(5,OPS_PTAG_SS_CREATION_TIME,&sig->info); 
    470     ops_write_scalar(when,4,&sig->info); 
     495    ops_write_ss_header(5,OPS_PTAG_SS_CREATION_TIME,sig->info); 
     496    ops_write_scalar(when,4,sig->info); 
    471497    } 
    472498 
     
    483509                                     const unsigned char keyid[OPS_KEY_ID_SIZE]) 
    484510    { 
    485     ops_write_ss_header(OPS_KEY_ID_SIZE+1,OPS_PTAG_SS_ISSUER_KEY_ID,&sig->info); 
    486     ops_write(keyid,OPS_KEY_ID_SIZE,&sig->info); 
     511    ops_write_ss_header(OPS_KEY_ID_SIZE+1,OPS_PTAG_SS_ISSUER_KEY_ID,sig->info); 
     512    ops_write(keyid,OPS_KEY_ID_SIZE,sig->info); 
    487513    } 
    488514 
     
    498524                                       ops_boolean_t primary) 
    499525    { 
    500     ops_write_ss_header(2,OPS_PTAG_SS_PRIMARY_USER_ID,&sig->info); 
    501     ops_write_scalar(primary,1,&sig->info); 
    502     } 
     526    ops_write_ss_header(2,OPS_PTAG_SS_PRIMARY_USER_ID,sig->info); 
     527    ops_write_scalar(primary,1,sig->info); 
     528    } 
  • openpgpsdk/trunk/src/util.c

    r301 r307  
    1010#include <assert.h> 
    1111#include <unistd.h> 
    12 #include <errno.h>  
     12#include <string.h> 
    1313 
    1414/** 
     
    141141    } 
    142142 
    143 /** 
    144  * \ingroup Create 
    145  * 
    146  * ops_writer_fd() attempts to write up to #length bytes  
    147  * to the file descriptor in #arg_ from the buffer #src  
    148  * using the rules contained in #flags 
    149  *  
    150  * \param       src 
    151  * \param       length Number of bytes to try to write 
    152  * \param       flags   Rules to use 
    153  * \param       arg_    Gets cast to #ops_writer_fd_arg_t 
    154  * 
    155  * \return      OPS_W_ERROR     if not enough bytes written 
    156  * \return      OPS_W_OK if all bytes written 
    157  * \todo change arg_ to typesafe?  
    158  */ 
    159 ops_writer_ret_t ops_writer_fd(const unsigned char *src,unsigned length, 
    160                                ops_writer_flags_t flags, 
    161                                ops_create_info_t *create_info) 
     143void *ops_mallocz(size_t n) 
    162144    { 
    163     ops_writer_fd_arg_t *arg=create_info->arg; 
    164     int n=write(arg->fd,src,length); 
     145    void *m=malloc(n); 
    165146 
    166     OPS_USED(flags); 
     147    memset(m,'\0',n); 
    167148 
    168     if(n == -1) 
    169         { 
    170         ops_system_error_1(&create_info->errors,OPS_E_W_WRITE_FAILED,"write", 
    171                            "file descriptor %d",arg->fd); 
    172         return OPS_W_ERROR; 
    173         } 
    174  
    175     if((unsigned)n != length) 
    176         { 
    177         ops_error_1(&create_info->errors,OPS_E_W_WRITE_TOO_SHORT, 
    178                            "file descriptor %d",arg->fd); 
    179         return OPS_W_ERROR; 
    180         } 
    181  
    182     return OPS_W_OK; 
     149    return m; 
    183150    }