Previously debugging information seems to have been output by editing a

static variable and recompiling. Make this a bit more dynamic, adding a
--debug "filename" argument to the application, and by using a filename-
based debug framework to replicate previous behavior. Multiple filenames
can be provided.

In addition, add more debugging information by printing out the human
values of signature type and key algorithm when parsing packets.
This commit is contained in:
agc 2009-01-21 01:32:54 +00:00
parent 84ce5f6759
commit 2626a640dd
18 changed files with 147 additions and 106 deletions

View File

@ -53,4 +53,7 @@ void *ops_mallocz(size_t n);
char *ops_str_from_map(int, ops_map_t *);
int ops_set_debug_level(const char *);
int ops_get_debug_level(const char *);
#endif

View File

@ -44,8 +44,6 @@
#include <openpgpsdk/writer.h>
#include <openpgpsdk/final.h>
static int debug=0;
/**
* \ingroup Core_Create
* \param length
@ -340,7 +338,7 @@ static ops_boolean_t write_secret_key_body(const ops_secret_key_t *key,
crypt.set_key(&crypt, session_key);
ops_encrypt_init(&crypt);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\nWRITING:\niv=");
@ -378,7 +376,7 @@ static ops_boolean_t write_secret_key_body(const ops_secret_key_t *key,
|| !ops_write_mpi(key->key.rsa.q,info)
|| !ops_write_mpi(key->key.rsa.u,info))
{
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"4 x mpi not written - problem\n"); }
return ops_false;
}
@ -878,7 +876,7 @@ ops_boolean_t encode_m_buf(const unsigned char *M, size_t mLen,
memcpy(EM+i, M, mLen);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"Encoded Message: \n");
@ -924,7 +922,7 @@ ops_pk_session_key_t *ops_create_pk_session_key(const ops_keydata_t *key)
session_key->version=OPS_PKSK_V3;
memcpy(session_key->key_id, key->key_id, sizeof session_key->key_id);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"Encrypting for RSA key id : ");
@ -940,7 +938,7 @@ ops_pk_session_key_t *ops_create_pk_session_key(const ops_keydata_t *key)
session_key->symmetric_algorithm=OPS_SA_CAST5;
ops_random(session_key->key, CAST_KEY_LENGTH);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"CAST5 session key created (len=%d):\n ", CAST_KEY_LENGTH);
@ -955,7 +953,7 @@ ops_pk_session_key_t *ops_create_pk_session_key(const ops_keydata_t *key)
return NULL;
}
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
printf("unencoded m buf:\n");
@ -1242,7 +1240,7 @@ ops_boolean_t ops_write_one_pass_sig(const ops_secret_key_t* skey,
ops_create_info_t* info)
{
unsigned char keyid[OPS_KEY_ID_SIZE];
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"calling ops_keyid in write_one_pass_sig: this calls sha1_init\n"); }
ops_keyid(keyid,&skey->public_key);

View File

@ -38,8 +38,7 @@
#endif
#include <openpgpsdk/final.h>
static int debug=0;
#include <openpgpsdk/util.h>
/**
* \ingroup Core_Keys
@ -84,7 +83,7 @@ void ops_fingerprint(ops_fingerprint_t *fp,const ops_public_key_t *key)
ops_build_public_key(mem,key,ops_false);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"--- creating key fingerprint\n"); }
ops_hash_sha1(&sha1);
@ -97,7 +96,7 @@ void ops_fingerprint(ops_fingerprint_t *fp,const ops_public_key_t *key)
sha1.add(&sha1,ops_memory_get_data(mem),l);
sha1.finish(&sha1,fp->fingerprint);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"--- finished creating key fingerprint\n"); }
fp->length=20;

View File

@ -28,8 +28,7 @@
#include <openpgpsdk/hash.h>
#include <openpgpsdk/final.h>
static int debug=0;
#include <openpgpsdk/util.h>
/**
\ingroup Core_Hashes
@ -183,7 +182,7 @@ void ops_calc_mdc_hash(const unsigned char* preamble, const size_t sz_preamble,
ops_hash_t hash;
unsigned char c[1];
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"ops_calc_mdc_hash():\n");
@ -217,7 +216,7 @@ void ops_calc_mdc_hash(const unsigned char* preamble, const size_t sz_preamble,
//finish
hash.finish(&hash,hashed);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\nhashed (len=%d): ",OPS_SHA1_HASH_SIZE);

View File

@ -38,8 +38,7 @@
#include <openpgpsdk/std_print.h>
#include <openpgpsdk/final.h>
static int debug=0;
#include <openpgpsdk/util.h>
static void test_secret_key(const ops_secret_key_t *skey)
{
@ -91,7 +90,7 @@ void ops_hash_md5(ops_hash_t *hash)
static void sha1_init(ops_hash_t *hash)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"***\n***\nsha1_init\n***\n");
}
@ -103,7 +102,7 @@ static void sha1_init(ops_hash_t *hash)
static void sha1_add(ops_hash_t *hash,const unsigned char *data,
unsigned length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"adding %d to hash:\n ", length);
@ -123,7 +122,7 @@ static void sha1_add(ops_hash_t *hash,const unsigned char *data,
static unsigned sha1_finish(ops_hash_t *hash,unsigned char *out)
{
SHA1_Final(out,hash->data);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i=0;
fprintf(stderr,"***\n***\nsha1_finish\n***\n");
@ -151,7 +150,7 @@ void ops_hash_sha1(ops_hash_t *hash)
static void sha256_init(ops_hash_t *hash)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"***\n***\nsha256_init\n***\n");
}
@ -163,7 +162,7 @@ static void sha256_init(ops_hash_t *hash)
static void sha256_add(ops_hash_t *hash,const unsigned char *data,
unsigned length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"adding %d to hash:\n ", length);
@ -183,7 +182,7 @@ static void sha256_add(ops_hash_t *hash,const unsigned char *data,
static unsigned sha256_finish(ops_hash_t *hash,unsigned char *out)
{
SHA256_Final(out,hash->data);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i=0;
fprintf(stderr,"***\n***\nsha1_finish\n***\n");
@ -210,7 +209,7 @@ void ops_hash_sha256(ops_hash_t *hash)
static void sha384_init(ops_hash_t *hash)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"***\n***\nsha384_init\n***\n");
}
@ -222,7 +221,7 @@ static void sha384_init(ops_hash_t *hash)
static void sha384_add(ops_hash_t *hash,const unsigned char *data,
unsigned length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"adding %d to hash:\n ", length);
@ -242,7 +241,7 @@ static void sha384_add(ops_hash_t *hash,const unsigned char *data,
static unsigned sha384_finish(ops_hash_t *hash,unsigned char *out)
{
SHA384_Final(out,hash->data);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i=0;
fprintf(stderr,"***\n***\nsha1_finish\n***\n");
@ -269,7 +268,7 @@ void ops_hash_sha384(ops_hash_t *hash)
static void sha512_init(ops_hash_t *hash)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"***\n***\nsha512_init\n***\n");
}
@ -281,7 +280,7 @@ static void sha512_init(ops_hash_t *hash)
static void sha512_add(ops_hash_t *hash,const unsigned char *data,
unsigned length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"adding %d to hash:\n ", length);
@ -301,7 +300,7 @@ static void sha512_add(ops_hash_t *hash,const unsigned char *data,
static unsigned sha512_finish(ops_hash_t *hash,unsigned char *out)
{
SHA512_Final(out,hash->data);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i=0;
fprintf(stderr,"***\n***\nsha1_finish\n***\n");
@ -328,7 +327,7 @@ void ops_hash_sha512(ops_hash_t *hash)
static void sha224_init(ops_hash_t *hash)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"***\n***\nsha1_init\n***\n");
}
@ -340,7 +339,7 @@ static void sha224_init(ops_hash_t *hash)
static void sha224_add(ops_hash_t *hash,const unsigned char *data,
unsigned length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"adding %d to hash:\n ", length);
@ -360,7 +359,7 @@ static void sha224_add(ops_hash_t *hash,const unsigned char *data,
static unsigned sha224_finish(ops_hash_t *hash,unsigned char *out)
{
SHA224_Final(out,hash->data);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i=0;
fprintf(stderr,"***\n***\nsha1_finish\n***\n");
@ -400,7 +399,7 @@ ops_boolean_t ops_dsa_verify(const unsigned char *hash,size_t hash_length,
odsa->g=dsa->g;
odsa->pub_key=dsa->y;
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned i;
fprintf(stderr,"hash passed in:\n");
@ -417,7 +416,7 @@ ops_boolean_t ops_dsa_verify(const unsigned char *hash,size_t hash_length,
hash_length=qlen;
// ret=DSA_do_verify(hash,hash_length,osig,odsa);
ret=DSA_do_verify(hash,hash_length,osig,odsa);
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"ret=%d\n",ret);
}
@ -717,7 +716,7 @@ ops_boolean_t ops_rsa_generate_keypair(const int numbits, const unsigned long e,
// should now have checksum in skey struct
// test
if (debug)
if (ops_get_debug_level(__FILE__))
test_secret_key(skey);
return ops_true;

View File

@ -52,8 +52,6 @@
#include <openpgpsdk/final.h>
static int debug=0;
/**
* limited_read_data reads the specified amount of the subregion's data
* into a data_t structure
@ -1751,7 +1749,7 @@ static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo)
ops_parser_content_t content;
//debug=1;
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "\nparse_v4_signature\n"); }
// clear signature
@ -1768,8 +1766,8 @@ static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo)
if(!limited_read(c,1,region,pinfo))
return 0;
C.signature.info.type=c[0];
if (debug)
{ fprintf(stderr, "signature type=%d\n", C.signature.info.type); }
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "signature type=%d (%s)\n", C.signature.info.type, ops_show_sig_type(C.signature.info.type)); }
/* XXX: check signature type */
@ -1777,14 +1775,14 @@ static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo)
return 0;
C.signature.info.key_algorithm=c[0];
/* XXX: check algorithm */
if (debug)
{ fprintf(stderr, "key_algorithm=%d\n", C.signature.info.key_algorithm); }
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "key_algorithm=%d (%s)\n", C.signature.info.key_algorithm, ops_show_pka(C.signature.info.key_algorithm)); }
if(!limited_read(c,1,region,pinfo))
return 0;
C.signature.info.hash_algorithm=c[0];
/* XXX: check algorithm */
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "hash_algorithm=%d %s\n", C.signature.info.hash_algorithm, ops_show_hash_algorithm(C.signature.info.hash_algorithm)); }
CBP(pinfo,OPS_PTAG_CT_SIGNATURE_HEADER,&content);
@ -2168,7 +2166,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
int blocksize;
ops_boolean_t crypted;
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"\n---------\nparse_secret_key:\n");
fprintf(stderr,"region length=%d, length_read=%d, remainder=%d\n", region->length, region->length_read, region->length-region->length_read);
}
@ -2177,7 +2175,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
if(!parse_public_key_data(&C.secret_key.public_key,region,pinfo))
return 0;
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"parse_secret_key: public key parsed\n");
ops_print_public_key(&C.secret_key.public_key);
@ -2259,7 +2257,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
CBP(pinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);
if(!passphrase)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{
// \todo make into proper error
fprintf(stderr,"parse_secret_key: can't get passphrase\n");
@ -2331,7 +2329,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
free(passphrase);
ops_crypt_any(&decrypt,C.secret_key.algorithm);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\nREADING:\niv=");
@ -2402,7 +2400,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
// assert(0);
}
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"4 MPIs read\n");
// ops_print_secret_key_verbose(OPS_PTAG_CT_SECRET_KEY, &C.secret_key);
@ -2467,7 +2465,7 @@ static int parse_secret_key(ops_region_t *region,ops_parse_info_t *pinfo)
CBP(pinfo,OPS_PTAG_CT_SECRET_KEY,&content);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "--- end of parse_secret_key\n\n"); }
return 1;
@ -2512,7 +2510,7 @@ static int parse_pk_session_key(ops_region_t *region,
sizeof C.pk_session_key.key_id,region,pinfo))
return 0;
if (debug)
if (ops_get_debug_level(__FILE__))
{
int i;
int x=sizeof C.pk_session_key.key_id;
@ -2599,7 +2597,7 @@ static int parse_pk_session_key(ops_region_t *region,
memcpy(C.pk_session_key.key,unencoded_m_buf+1,k);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int j;
printf("session key recovered (len=%d):\n",k);
@ -2609,7 +2607,7 @@ static int parse_pk_session_key(ops_region_t *region,
}
C.pk_session_key.checksum=unencoded_m_buf[k+1]+(unencoded_m_buf[k+2] << 8);
if (debug)
if (ops_get_debug_level(__FILE__))
{
printf("session key checksum: %2x %2x\n", unencoded_m_buf[k+1], unencoded_m_buf[k+2]);
}

View File

@ -42,8 +42,6 @@
#include <openpgpsdk/final.h>
static int debug=0;
#define CRC24_POLY 0x1864cfbL
/**
@ -173,7 +171,7 @@ static int set_lastseen_headerline(dearmour_arg_t* arg, char* buf, ops_error_t *
return 0;
}
if (debug)
if (ops_get_debug_level(__FILE__))
printf("set header: buf=%s, arg->lastseen=%d, prev=%d\n", buf, arg->lastseen, prev);
switch (arg->lastseen)
@ -425,7 +423,7 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
if(body->data[0] == '\n')
hash->add(hash,(unsigned char *)"\r",1);
hash->add(hash,body->data,body->length);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"Got body:\n%s\n",body->data); }
CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY,&content);
body->length=0;
@ -435,7 +433,7 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
++total;
if(body->length == sizeof body->data)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"Got body (2):\n%s\n",body->data); }
CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY,&content);
body->length=0;

View File

@ -32,8 +32,7 @@
#include <openpgpsdk/packet-show.h>
#include <openpgpsdk/final.h>
static int debug=0;
#include <openpgpsdk/util.h>
#ifndef ATTRIBUTE_UNUSED
@ -155,7 +154,7 @@ static int encrypted_data_reader(void *dest,size_t length,ops_error_t **errors,
arg->decrypted,
buffer,n);
if (debug)
if (ops_get_debug_level(__FILE__))
{
int i=0;
fprintf(stderr,"READING:\nencrypted: ");

View File

@ -52,8 +52,6 @@
#include <openpgpsdk/final.h>
static int debug=0;
typedef struct
{
// boolean: false once we've done the preamble/MDC checks
@ -117,7 +115,7 @@ static int se_ip_data_reader(void *dest_, size_t len, ops_error_t **errors,
return -1;
}
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\n\nentire SE IP packet (len=%d):\n",decrypted_region.length);
@ -133,7 +131,7 @@ static int se_ip_data_reader(void *dest_, size_t len, ops_error_t **errors,
// verify leading preamble
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\npreamble: ");
@ -165,7 +163,7 @@ static int se_ip_data_reader(void *dest_, size_t len, ops_error_t **errors,
mdc_hash=mdc+2;
#ifdef DEBUG
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;

View File

@ -35,10 +35,10 @@
#include <unistd.h>
#include <openpgpsdk/final.h>
#include <openpgpsdk/util.h>
#include <openssl/dsa.h>
static int debug=0;
#define MAXBUF 1024 /*<! Standard buffer size to use */
/** \ingroup Core_Create
@ -170,7 +170,7 @@ static ops_boolean_t encode_hash_buf(const unsigned char *M, size_t mLen,
// \todo test n for OK response?
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"Encoded Message: \n");
for (i=0; i<encoded_msg_sz; i++)
@ -205,7 +205,7 @@ static void rsa_sign(ops_hash_t *hash,const ops_rsa_public_key_t *rsa,
hashbuf[0]=0;
hashbuf[1]=1;
if (debug)
if (ops_get_debug_level(__FILE__))
{ printf("rsa_sign: PS is %d\n", keysize-hashsize-1-2); }
for(n=2 ; n < keysize-hashsize-1 ; ++n)
hashbuf[n]=0xff;
@ -309,7 +309,7 @@ static ops_boolean_t rsa_verify(ops_hash_algorithm_t type,
if(hashbuf_from_sig[n++] != 0)
return ops_false;
if (debug)
if (ops_get_debug_level(__FILE__))
{
int zz;
unsigned uu;
@ -672,7 +672,7 @@ static void ops_signature_start_signature(ops_create_signature_t *sig,
sig->hashed_data_length=-1;
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"initialising hash for sig in mem\n"); }
initialise_hash(&sig->hash,&sig->sig);
start_signature_in_mem(sig);
@ -714,7 +714,7 @@ void ops_signature_start_message_signature(ops_create_signature_t *sig,
void ops_signature_add_data(ops_create_signature_t *sig,const void *buf,
size_t length)
{
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"ops_signature_add_data adds to hash\n"); }
sig->hash.add(&sig->hash,buf,length);
}
@ -781,7 +781,7 @@ ops_boolean_t ops_write_signature(ops_create_signature_t *sig, const ops_public_
// add the packet from version number to end of hashed subpackets
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "--- Adding packet to hash from version number to hashed subpkts\n"); }
sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem),
@ -793,7 +793,7 @@ ops_boolean_t ops_write_signature(ops_create_signature_t *sig, const ops_public_
// +6 for version, type, pk alg, hash alg, hashed subpacket length
ops_hash_add_int(&sig->hash,sig->hashed_data_length+6,4);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "--- Finished adding packet to hash from version number to hashed subpkts\n"); }
// XXX: technically, we could figure out how big the signature is
@ -1176,7 +1176,7 @@ ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filen
if (use_armour)
ops_writer_push_armoured_message(cinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "** Writing out one pass sig\n"); }
// write one_pass_sig
@ -1188,12 +1188,12 @@ ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filen
// output file contents as Literal Data packet
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"** Writing out data now\n"); }
ops_write_literal_data_from_buf(ops_memory_get_data(mem_buf), ops_memory_get_length(mem_buf), OPS_LDT_BINARY, cinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"** After Writing out data now\n");}
// add subpackets to signature
@ -1285,7 +1285,7 @@ ops_memory_t* ops_sign_buf(const void* input, const size_t input_len, const ops_
if (use_armour)
ops_writer_push_armoured_message(cinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "** Writing out one pass sig\n"); }
// write one_pass_sig
@ -1297,12 +1297,12 @@ ops_memory_t* ops_sign_buf(const void* input, const size_t input_len, const ops_
// output file contents as Literal Data packet
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"** Writing out data now\n"); }
ops_write_literal_data_from_buf(input, input_len, ld_type, cinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr,"** After Writing out data now\n");}
// add subpackets to signature

View File

@ -32,8 +32,7 @@
#include <openpgpsdk/packet-show.h>
#include <openpgpsdk/final.h>
//static int debug=0;
#include <openpgpsdk/util.h>
#ifndef ATTRIBUTE_UNUSED

View File

@ -183,3 +183,62 @@ unsigned short ops_reader_pop_sum16(ops_parse_info_t *pinfo)
return sum;
}
/* small useful functions for setting the file-level debugging levels */
/* saves editing the static variable for every source file */
/* if the debugv list contains the filename in question, we're debugging it */
enum {
MAX_DEBUG_NAMES = 32
};
static int debugc;
static char *debugv[MAX_DEBUG_NAMES];
/* set the debugging level per filename */
int
ops_set_debug_level(const char *f)
{
const char *name;
int i;
if (f == NULL) {
f = "all";
}
if ((name = strrchr(f, '/')) == NULL) {
name = f;
} else {
name += 1;
}
for (i = 0 ; i < debugc && i < MAX_DEBUG_NAMES ; i++) {
if (strcmp(debugv[i], name) == 0) {
return 1;
}
}
if (i == MAX_DEBUG_NAMES) {
return 0;
}
debugv[debugc++] = strdup(name);
return 1;
}
/* get the debugging level per filename */
int
ops_get_debug_level(const char *f)
{
const char *name;
int i;
if ((name = strrchr(f, '/')) == NULL) {
name = f;
} else {
name += 1;
}
for (i = 0 ; i < debugc ; i++) {
if (strcmp(debugv[i], "all") == 0 ||
strcmp(debugv[i], name) == 0) {
return 1;
}
}
return 0;
}

View File

@ -35,8 +35,6 @@
#include <openpgpsdk/final.h>
static int debug=0;
static ops_boolean_t check_binary_signature(const unsigned len,
const unsigned char *data,
const ops_signature_t *sig,
@ -198,7 +196,7 @@ ops_validate_key_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cb
const ops_keydata_t *signer;
ops_boolean_t valid=ops_false;
if (debug)
if (ops_get_debug_level(__FILE__))
printf("%s\n",ops_show_packet_tag(content_->tag));
switch(content_->tag)
@ -348,7 +346,7 @@ validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinf
ops_boolean_t valid=ops_false;
ops_memory_t* mem=NULL;
if (debug)
if (ops_get_debug_level(__FILE__))
printf("%s\n",ops_show_packet_tag(content_->tag));
switch(content_->tag)
@ -380,7 +378,7 @@ validate_data_cb(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinf
case OPS_PTAG_CT_SIGNATURE: // V3 sigs
case OPS_PTAG_CT_SIGNATURE_FOOTER: // V4 sigs
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int zzz=0;
printf("\n*** hashed data:\n");
@ -674,7 +672,7 @@ ops_boolean_t ops_validate_file(ops_validate_result_t *result, const char* filen
ops_parse(pinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{
printf("valid=%d, invalid=%d, unknown=%d\n",
result->valid_count,
@ -727,7 +725,7 @@ ops_boolean_t ops_validate_mem(ops_validate_result_t *result, ops_memory_t* mem,
ops_parse(pinfo);
if (debug)
if (ops_get_debug_level(__FILE__))
{
printf("valid=%d, invalid=%d, unknown=%d\n",
result->valid_count,

View File

@ -44,8 +44,6 @@
#include <openpgpsdk/final.h>
//static int debug=0;
/*
* return true if OK, otherwise false
*/

View File

@ -31,8 +31,7 @@
#include <openpgpsdk/version.h>
#include <openpgpsdk/final.h>
static int debug=0;
#include <openpgpsdk/util.h>
/**
* \struct dash_escaped_arg_t
@ -53,7 +52,7 @@ static ops_boolean_t dash_escaped_writer(const unsigned char *src,
dash_escaped_arg_t *arg=ops_writer_get_arg(winfo);
unsigned n;
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"dash_escaped_writer writing %d:\n", length);

View File

@ -25,8 +25,7 @@
#include <assert.h>
#include <string.h>
#include <openpgpsdk/readerwriter.h>
static int debug=0;
#include <openpgpsdk/util.h>
typedef struct
{
@ -62,7 +61,7 @@ static ops_boolean_t encrypt_writer(const unsigned char *src,
arg->crypt->cfb_encrypt(arg->crypt, encbuf, src+done, len);
if (debug)
if (ops_get_debug_level(__FILE__))
{
int i=0;
fprintf(stderr,"WRITING:\nunencrypted: ");
@ -77,7 +76,7 @@ static ops_boolean_t encrypt_writer(const unsigned char *src,
if (!ops_stacked_write(encbuf,len,errors,winfo))
{
if (debug)
if (ops_get_debug_level(__FILE__))
{ fprintf(stderr, "encrypted_writer got error from stacked write, returning\n"); }
return ops_false;
}

View File

@ -38,8 +38,7 @@
#include <openpgpsdk/keyring.h>
#include <openpgpsdk/random.h>
#include <openpgpsdk/readerwriter.h>
static int debug=0;
#include <openpgpsdk/util.h>
typedef struct
{
@ -177,7 +176,7 @@ ops_boolean_t ops_write_se_ip_pktset(const unsigned char *data,
preamble[crypt->blocksize]=preamble[crypt->blocksize-2];
preamble[crypt->blocksize+1]=preamble[crypt->blocksize-1];
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
fprintf(stderr,"\npreamble: ");
@ -194,7 +193,7 @@ ops_boolean_t ops_write_se_ip_pktset(const unsigned char *data,
ops_write_mdc(hashed, cinfo_mdc);
if (debug)
if (ops_get_debug_level(__FILE__))
{
unsigned int i=0;
size_t sz_plaintext=len;
@ -218,7 +217,7 @@ ops_boolean_t ops_write_se_ip_pktset(const unsigned char *data,
ops_writer_push_encrypt_crypt(cinfo, crypt);
#ifdef DEBUG
if (debug)
if (ops_get_debug_level(__FILE__))
{
fprintf(stderr,"writing %ld + %d + %ld\n", sz_preamble, len, ops_memory_get_length(mem_mdc));
}

View File

@ -26,8 +26,7 @@
#include <openpgpsdk/readerwriter.h>
#include <openpgpsdk/final.h>
//static int debug=0;
#include <openpgpsdk/util.h>
typedef struct
{