cleanup: -index shadows a variable in /usr/include/string.h

-some signed vs. unsigned issues
         -and some const cleanup


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2039 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
nils 2004-12-22 09:48:27 +00:00
parent 4ddfe862e5
commit 5847b646f9
8 changed files with 60 additions and 57 deletions

View File

@ -203,7 +203,7 @@ int
sc_keycache_put_pin(const sc_path_t *path, int ref, const u8 *pin)
{
return sc_keycache_put_key(path, SC_AC_CHV, ref, pin,
pin? strlen((char *) pin) : 0);
pin? strlen((const char *) pin) : 0);
}
/*

View File

@ -134,7 +134,7 @@ struct sc_pkcs15init_operations {
* pin file index.
*/
int (*new_pin)(struct sc_profile *, struct sc_card *,
struct sc_pkcs15_pin_info *, unsigned int index,
struct sc_pkcs15_pin_info *, unsigned int idx,
const u8 *pin, size_t pin_len,
const u8 *puk, size_t puk_len);
@ -142,7 +142,7 @@ struct sc_pkcs15init_operations {
* Store a key on the card
*/
int (*new_key)(struct sc_profile *, struct sc_card *,
struct sc_pkcs15_prkey *key, unsigned int index,
struct sc_pkcs15_prkey *key, unsigned int idx,
struct sc_pkcs15_prkey_info *);
/*
@ -155,7 +155,7 @@ struct sc_pkcs15init_operations {
* Generate a new key pair
*/
int (*old_generate_key)(struct sc_profile *, struct sc_card *,
unsigned int index, unsigned int keybits,
unsigned int idx, unsigned int keybits,
sc_pkcs15_pubkey_t *pubkey_res,
struct sc_pkcs15_prkey_info *);
@ -340,6 +340,8 @@ extern int sc_pkcs15init_get_label(struct sc_profile *, const char **);
extern void sc_pkcs15init_set_secret(struct sc_profile *,
int, int, u8 *, size_t);
extern int sc_pkcs15init_set_pin_data(struct sc_profile *, int,
const u8 *, size_t);
extern int sc_pkcs15init_verify_key(struct sc_profile *, struct sc_card *,
sc_file_t *, unsigned int, unsigned int);

View File

@ -132,7 +132,7 @@ static int sc_pkcs15init_write_info(sc_card_t *card, sc_profile_t *,
sc_pkcs15_object_t *pin_obj);
static struct profile_operations {
char *name;
const char *name;
void *func;
} profile_operations[] = {
{ "gpk", (void *) sc_pkcs15init_get_gpk_ops },
@ -307,8 +307,8 @@ sc_pkcs15init_bind(struct sc_card *card, const char *name,
profile->name = strdup(name);
if (strchr(profile->name, '+') != NULL) {
char *s;
int i = 0;
i = 0;
(void) strtok(profile->name, "+");
while ((s = strtok(NULL, "+")) != NULL) {
if (i < SC_PKCS15INIT_MAX_OPTIONS-1)
@ -696,7 +696,7 @@ sc_pkcs15init_store_pin(struct sc_pkcs15_card *p15card,
sc_card_t *card = p15card->card;
sc_pkcs15_object_t *pin_obj;
sc_pkcs15_pin_info_t *pin_info;
int r, index;
int r, idx;
/* No auth_id given: select one */
if (args->auth_id.len == 0) {
@ -745,10 +745,10 @@ sc_pkcs15init_store_pin(struct sc_pkcs15_card *p15card,
r = sc_pkcs15init_create_pin(p15card, profile, pin_obj, args);
} else {
/* Get the number of PINs we already have */
index = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH,
idx = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH,
NULL, 0);
r = profile->ops->new_pin(profile, card, pin_info, index,
r = profile->ops->new_pin(profile, card, pin_info, idx,
args->pin, args->pin_len,
args->puk, args->puk_len);
}
@ -1069,10 +1069,10 @@ sc_pkcs15init_generate_key(struct sc_pkcs15_card *p15card,
if (r < 0)
return r;
} else {
int index;
int idx;
index = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PRKEY, NULL, 0);
r = profile->ops->old_generate_key(profile, p15card->card, index, keybits,
idx = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PRKEY, NULL, 0);
r = profile->ops->old_generate_key(profile, p15card->card, idx, keybits,
&pubkey_args.key, key_info);
}
@ -1110,7 +1110,7 @@ sc_pkcs15init_store_private_key(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_prkey_info *key_info;
sc_card_t *card = p15card->card;
sc_pkcs15_prkey_t key;
int keybits, index, r = 0;
int keybits, idx, r = 0;
/* Create a copy of the key first */
key = keyargs->key;
@ -1153,7 +1153,7 @@ sc_pkcs15init_store_private_key(struct sc_pkcs15_card *p15card,
key_info = (struct sc_pkcs15_prkey_info *) object->data;
/* Get the number of private keys already on this card */
index = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PRKEY, NULL, 0);
idx = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PRKEY, NULL, 0);
if (!(keyargs->flags & SC_PKCS15INIT_EXTRACTABLE)) {
if (profile->ops->create_key) {
/* New API */
@ -1166,7 +1166,7 @@ sc_pkcs15init_store_private_key(struct sc_pkcs15_card *p15card,
return r;
} else {
r = profile->ops->new_key(profile, p15card->card,
&key, index, key_info);
&key, idx, key_info);
if (r < 0)
return r;
}
@ -1538,7 +1538,7 @@ sc_pkcs15init_store_data(struct sc_pkcs15_card *p15card,
{
struct sc_file *file = NULL;
int r;
unsigned int index = -1;
unsigned int idx = -1;
/* Set the SO PIN reference from card */
if ((r = set_so_pin_from_card(p15card, profile)) < 0)
@ -1558,13 +1558,13 @@ sc_pkcs15init_store_data(struct sc_pkcs15_card *p15card,
} else {
/* Get the number of objects of this type already on this card */
index = sc_pkcs15_get_objects(p15card,
idx = sc_pkcs15_get_objects(p15card,
object->type & SC_PKCS15_TYPE_CLASS_MASK,
NULL, 0);
/* Allocate data file */
r = profile->ops->new_file(profile, p15card->card,
object->type, index, &file);
object->type, idx, &file);
if (r < 0) {
sc_error(p15card->card->ctx, "Unable to allocate file");
goto done;
@ -1745,7 +1745,7 @@ sc_pkcs15init_requires_restrictive_usage(struct sc_pkcs15_card *p15card,
* Check RSA key for consistency, and compute missing
* CRT elements
*/
int
static int
prkey_fixup_rsa(sc_pkcs15_card_t *p15card, struct sc_pkcs15_prkey_rsa *key)
{
if (!key->modulus.len || !key->exponent.len
@ -2885,7 +2885,7 @@ sc_pkcs15init_fixup_acls(struct sc_profile *profile, struct sc_file *file,
/* If we weren't given a replacement ACL,
* leave the original ACL untouched */
if (acl == NULL || acl->key_ref == -1) {
if (acl == NULL || acl->key_ref == (unsigned int)-1) {
sc_error(card->ctx,
"ACL references %s, which is not defined",
what);

View File

@ -48,7 +48,7 @@ static int miocos_init_app(struct sc_profile *profile, struct sc_card *card,
*/
static int
miocos_new_pin(struct sc_profile *profile, struct sc_card *card,
struct sc_pkcs15_pin_info *info, unsigned int index,
struct sc_pkcs15_pin_info *info, unsigned int idx,
const u8 *pin, size_t pin_len,
const u8 *puk, size_t puk_len)
{
@ -61,8 +61,8 @@ miocos_new_pin(struct sc_profile *profile, struct sc_card *card,
if (r)
return r;
memset(&ac_info, 0, sizeof(ac_info));
info->reference = index + 1;
ac_info.ref = index + 1;
info->reference = idx + 1;
ac_info.ref = idx + 1;
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PIN, &tmpinfo);
ac_info.max_tries = tmpinfo.tries_left;
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PUK, &tmpinfo);
@ -89,9 +89,9 @@ miocos_new_file(struct sc_profile *profile, struct sc_card *card,
{
struct sc_file *file;
struct sc_path *p;
char name[64], *tag, *desc;
char name[64];
const char *tag = NULL, *desc = NULL;
desc = tag = NULL;
while (1) {
switch (type) {
case SC_PKCS15_TYPE_PRKEY_RSA:
@ -169,7 +169,7 @@ miocos_update_private_key(struct sc_profile *profile, struct sc_card *card,
*/
static int
miocos_new_key(struct sc_profile *profile, struct sc_card *card,
struct sc_pkcs15_prkey *key, unsigned int index,
struct sc_pkcs15_prkey *key, unsigned int idx,
struct sc_pkcs15_prkey_info *info)
{
sc_file_t *keyfile;
@ -185,7 +185,7 @@ miocos_new_key(struct sc_profile *profile, struct sc_card *card,
sc_error(card->ctx, "MioCOS supports only 1024-bit RSA keys.");
return SC_ERROR_NOT_SUPPORTED;
}
r = miocos_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, index,
r = miocos_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, idx,
&keyfile);
if (r < 0)
return r;

View File

@ -262,7 +262,7 @@ static int cosm_create_reference_data(struct sc_profile *profile, struct sc_card
if (puk) {
int ii, jj;
unsigned char *ptr = (unsigned char *)puk;
const unsigned char *ptr = puk;
puk_buff = (unsigned char *) malloc(0x100);
if (!puk_buff)
@ -272,7 +272,7 @@ static int cosm_create_reference_data(struct sc_profile *profile, struct sc_card
if (profile_puk.max_length > 0x100)
return SC_ERROR_INCONSISTENT_PROFILE;
memset(puk_buff, profile_puk.pad_char, 0x100);
for (ii=0; ii<8 && (ptr-puk) < puk_len && (*ptr); ii++) {
for (ii=0; ii<8 && (size_t)(ptr-puk) < puk_len && (*ptr); ii++) {
jj = 0;
while (isalnum(*ptr) && jj<16) {
*(puk_buff + ii*0x10 + jj++) = *ptr;
@ -288,10 +288,10 @@ static int cosm_create_reference_data(struct sc_profile *profile, struct sc_card
sc_debug(card->ctx, "pinfo->reference %i; tries %i\n",
pinfo->reference, profile_pin.tries_left);
sc_debug(card->ctx, "sc_card_ctl %s\n","SC_CARDCTL_OBERTHUR_CREATE_PIN");
sc_debug(card->ctx, "sc_card_ctl %s\n","SC_CARDCTL_OBERTHUR_CREATE_PIN");
args.type = SC_AC_CHV;
args.ref = pinfo->reference;
args.pin = (u8 *)pin;
args.pin = pin;
args.pin_len = pin_len;
args.pin_tries = profile_pin.tries_left;
args.puk = puk_buff;
@ -432,7 +432,7 @@ cosm_new_file(struct sc_profile *profile, struct sc_card *card,
unsigned int type, unsigned int num, struct sc_file **out)
{
struct sc_file *file;
char *_template = NULL, *desc = NULL;
const char *_template = NULL, *desc = NULL;
unsigned int structure = 0xFFFFFFFF;
sc_debug(card->ctx, "type %X; num %i\n",type, num);
@ -506,7 +506,7 @@ cosm_new_file(struct sc_profile *profile, struct sc_card *card,
*/
static int
cosm_old_generate_key(struct sc_profile *profile, struct sc_card *card,
unsigned int index, unsigned int keybits,
unsigned int idx, unsigned int keybits,
sc_pkcs15_pubkey_t *pubkey,
struct sc_pkcs15_prkey_info *info)
{
@ -515,14 +515,14 @@ cosm_old_generate_key(struct sc_profile *profile, struct sc_card *card,
sc_path_t path;
int rv;
sc_debug(card->ctx, "index %i; nn %i\n",index,keybits);
sc_debug(card->ctx, "index %i; nn %i\n",idx,keybits);
if (keybits < 512 || keybits > 2048 || (keybits%0x20)) {
sc_error(card->ctx, "Unsupported key size %u\n", keybits);
return SC_ERROR_INVALID_ARGUMENTS;
}
/* Get private key file from profile. */
if ((rv = cosm_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, index,
if ((rv = cosm_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, idx,
&prkf)) < 0)
goto failed;
sc_debug(card->ctx, "prv ef type %i\n",prkf->ef_structure);
@ -611,7 +611,7 @@ failed:
*/
static int
cosm_new_key(struct sc_profile *profile, struct sc_card *card,
struct sc_pkcs15_prkey *key, unsigned int index,
struct sc_pkcs15_prkey *key, unsigned int idx,
struct sc_pkcs15_prkey_info *info)
{
struct sc_file *prvfile = NULL, *pubfile = NULL;
@ -620,14 +620,14 @@ cosm_new_key(struct sc_profile *profile, struct sc_card *card,
u8 *buff;
int rv, ii;
sc_debug(card->ctx, " index %i\n", index);
sc_debug(card->ctx, " index %i\n", idx);
if (key->algorithm != SC_ALGORITHM_RSA) {
sc_error(card->ctx, "For a while supports only RSA keys.");
return SC_ERROR_NOT_SUPPORTED;
}
/* Create and populate the private part. */
rv = cosm_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, index,
rv = cosm_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA, idx,
&prvfile);
if (rv < 0)
return SC_ERROR_SYNTAX_ERROR;

View File

@ -583,10 +583,11 @@ static size_t starcos_ipf_get_lastpos(u8 *ipf, size_t ipf_len)
if (!num_keys)
return 1;
while (num_keys--) {
size_t offset = p - ipf; /* note: p > ipf */
/* get offset to the next key header */
tmp = 12 + (p[1] << 8) + p[2];
if (p + tmp - ipf > ipf_len)
return SC_ERROR_INTERNAL; /* FIXME */
if (tmp + offset > ipf_len)
return SC_ERROR_INTERNAL;
p += tmp;
}
@ -667,7 +668,7 @@ static int starcos_write_pukey(sc_profile_t *profile, sc_card_t *card,
return SC_ERROR_OUT_OF_MEMORY;
/* read the complete IPF */
r = sc_read_binary(card, 0, buf, len, 0);
if (r < 0 || r != len)
if (r < 0 || r != (int)len)
return r;
/* get/fix number of keys */
num_keys = buf[0];

View File

@ -464,7 +464,7 @@ sc_profile_get_pin_id(struct sc_profile *profile,
struct pin_info *pi;
for (pi = profile->pin_list; pi; pi = pi->next) {
if (pi->pin.reference == reference) {
if (pi->pin.reference == (int)reference) {
*id = pi->id;
return 0;
}
@ -549,7 +549,7 @@ sc_profile_instantiate_template(sc_profile_t *profile,
sc_card_t *card = profile->card;
sc_profile_t *tmpl;
sc_template_t *info;
unsigned int index;
unsigned int idx;
struct file_info *fi, *base_file, *match = NULL;
for (info = profile->template_list; info; info = info->next) {
@ -560,10 +560,10 @@ sc_profile_instantiate_template(sc_profile_t *profile,
return SC_ERROR_TEMPLATE_NOT_FOUND;
tmpl = info->data;
index = id->value[id->len-1];
idx = id->value[id->len-1];
for (fi = profile->ef_list; fi; fi = fi->next) {
if (fi->base_template == tmpl
&& fi->inst_index == index
&& fi->inst_index == idx
&& sc_compare_path(&fi->inst_path, base_path)
&& !strcmp(fi->ident, file_name)) {
sc_file_dup(ret, fi->file);
@ -595,13 +595,13 @@ sc_profile_instantiate_template(sc_profile_t *profile,
fi->instance = NULL;
if ((parent = fi->parent) == NULL) {
parent = base_file;
skew = index;
skew = idx;
}
parent = parent->instance;
instance = sc_profile_instantiate_file(profile, fi, parent, skew);
instance->base_template = tmpl;
instance->inst_index = index;
instance->inst_index = idx;
instance->inst_path = *base_path;
if (!strcmp(instance->ident, file_name))
@ -793,7 +793,7 @@ new_key(struct sc_profile *profile, unsigned int type, unsigned int ref)
return ai;
}
int
static int
do_key_value(struct state *cur, int argc, char **argv)
{
struct auth_info *ai = cur->key;
@ -890,14 +890,14 @@ process_tmpl(struct state *cur, struct block *info,
* This is crucial; the profile instantiation code relies on it
*/
void
append_file(sc_profile_t *profile, struct file_info *new_file)
append_file(sc_profile_t *profile, struct file_info *nfile)
{
struct file_info **list, *fi;
list = &profile->ef_list;
while ((fi = *list) != NULL)
list = &fi->next;
*list = new_file;
*list = nfile;
}
/*
@ -974,7 +974,7 @@ new_file(struct state *cur, const char *name, unsigned int type)
profile->df[df_type] = file;
}
assert(file);
if (file->type != type) {
if (file->type != (int)type) {
parse_error(cur, "inconsistent file type (should be %s)",
(file->type == SC_FILE_TYPE_DF)? "DF" : "EF");
return NULL;
@ -1195,7 +1195,7 @@ new_pin(struct sc_profile *profile, unsigned int id)
*/
pi = (struct pin_info *) calloc(1, sizeof(*pi));
pi->id = id;
pi->pin.type = -1;
pi->pin.type = (unsigned int)-1;
pi->pin.flags = 0x32;
pi->pin.max_length = 0;
pi->pin.min_length = 0;
@ -1214,7 +1214,7 @@ set_pin_defaults(struct sc_profile *profile, struct pin_info *pi)
{
struct sc_pkcs15_pin_info *info = &pi->pin;
if (info->type < 0)
if (info->type == (unsigned int) -1)
info->type = profile->pin_encoding;
if (info->max_length == 0)
info->max_length = profile->pin_maxlen;
@ -1702,9 +1702,9 @@ get_authid(struct state *cur, const char *value,
static int
get_uint(struct state *cur, const char *value, unsigned int *vp)
{
const char *ep;
char *ep;
*vp = strtoul(value, (char **) &ep, 0);
*vp = strtoul(value, &ep, 0);
if (*ep != '\0') {
parse_error(cur,
"invalid integer argument \"%s\"\n", value);
@ -1799,7 +1799,7 @@ expr_fail(struct num_exp_ctx *ctx)
static void
expr_put(struct num_exp_ctx *ctx, char c)
{
if (ctx->j >= sizeof(ctx->word))
if (ctx->j >= (int)sizeof(ctx->word))
expr_fail(ctx);
ctx->word[ctx->j++] = c;
}

View File

@ -120,7 +120,7 @@ struct sc_profile {
sc_pkcs15_card_t * p15_data; /* as found on card */
};
struct sc_profile *sc_profile_new();
struct sc_profile *sc_profile_new(void);
int sc_profile_load(struct sc_profile *, const char *);
int sc_profile_finish(struct sc_profile *);
void sc_profile_free(struct sc_profile *);