declare some functions static plus some type fixes

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2137 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
nils 2005-02-04 22:52:13 +00:00
parent e0c1b6e8f1
commit 235abe1ffd
2 changed files with 39 additions and 44 deletions

View File

@ -87,7 +87,7 @@ struct sc_context *ctx = NULL;
struct sc_card *card = NULL; struct sc_card *card = NULL;
struct sc_pkcs15_card *p15card = NULL; struct sc_pkcs15_card *p15card = NULL;
char * get_pin(struct sc_pkcs15_object *obj) static char * get_pin(struct sc_pkcs15_object *obj)
{ {
char buf[80]; char buf[80];
char *pincode; char *pincode;
@ -107,7 +107,7 @@ char * get_pin(struct sc_pkcs15_object *obj)
} }
} }
int read_input(u8 *buf, int buflen) static int read_input(u8 *buf, int buflen)
{ {
FILE *inf; FILE *inf;
int c; int c;
@ -126,7 +126,7 @@ int read_input(u8 *buf, int buflen)
return c; return c;
} }
int write_output(const u8 *buf, int len) static int write_output(const u8 *buf, int len)
{ {
FILE *outf; FILE *outf;
int output_binary = (opt_output == NULL && opt_raw == 0 ? 0 : 1); int output_binary = (opt_output == NULL && opt_raw == 0 ? 0 : 1);
@ -151,7 +151,7 @@ int write_output(const u8 *buf, int len)
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
#define GETBN(bn) ((bn)->len? BN_bin2bn((bn)->data, (bn)->len, NULL) : NULL) #define GETBN(bn) ((bn)->len? BN_bin2bn((bn)->data, (bn)->len, NULL) : NULL)
int extract_key(struct sc_pkcs15_object *obj, EVP_PKEY **pk) static int extract_key(struct sc_pkcs15_object *obj, EVP_PKEY **pk)
{ {
struct sc_pkcs15_prkey *key; struct sc_pkcs15_prkey *key;
const char *pass = NULL; const char *pass = NULL;
@ -228,7 +228,7 @@ done: if (r < 0)
return r; return r;
} }
int sign_ext(struct sc_pkcs15_object *obj, static int sign_ext(struct sc_pkcs15_object *obj,
u8 *data, size_t len, u8 *out, size_t out_len) u8 *data, size_t len, u8 *out, size_t out_len)
{ {
EVP_PKEY *pkey = NULL; EVP_PKEY *pkey = NULL;
@ -275,7 +275,7 @@ int sign_ext(struct sc_pkcs15_object *obj,
} }
#endif #endif
int sign(struct sc_pkcs15_object *obj) static int sign(struct sc_pkcs15_object *obj)
{ {
u8 buf[1024], out[1024]; u8 buf[1024], out[1024];
struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data; struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data;
@ -285,19 +285,14 @@ int sign(struct sc_pkcs15_object *obj)
fprintf(stderr, "No input file specified.\n"); fprintf(stderr, "No input file specified.\n");
return 2; return 2;
} }
#if 0
if (opt_output == NULL) {
fprintf(stderr, "No output file specified.\n");
return 2;
}
#endif
c = read_input(buf, sizeof(buf)); c = read_input(buf, sizeof(buf));
if (c < 0) if (c < 0)
return 2; return 2;
len = sizeof(out); len = sizeof(out);
if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA
&& !(opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1) && !(opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1)
&& c != key->modulus_length/8) { && (size_t)c != key->modulus_length/8) {
fprintf(stderr, "Input has to be exactly %d bytes, when using no padding.\n", fprintf(stderr, "Input has to be exactly %d bytes, when using no padding.\n",
key->modulus_length/8); key->modulus_length/8);
return 2; return 2;
@ -351,7 +346,7 @@ static int decipher_ext(struct sc_pkcs15_object *obj,
} }
#endif #endif
int decipher(struct sc_pkcs15_object *obj) static int decipher(struct sc_pkcs15_object *obj)
{ {
u8 buf[1024], out[1024]; u8 buf[1024], out[1024];
int r, c, len; int r, c, len;

View File

@ -110,7 +110,7 @@ struct sc_context *ctx = NULL;
struct sc_card *card = NULL; struct sc_card *card = NULL;
struct sc_pkcs15_card *p15card = NULL; struct sc_pkcs15_card *p15card = NULL;
void print_cert_info(const struct sc_pkcs15_object *obj) static void print_cert_info(const struct sc_pkcs15_object *obj)
{ {
unsigned int i; unsigned int i;
struct sc_pkcs15_cert_info *cert = (struct sc_pkcs15_cert_info *) obj->data; struct sc_pkcs15_cert_info *cert = (struct sc_pkcs15_cert_info *) obj->data;
@ -126,7 +126,7 @@ void print_cert_info(const struct sc_pkcs15_object *obj)
} }
int list_certificates(void) static int list_certificates(void)
{ {
int r, i; int r, i;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -145,7 +145,7 @@ int list_certificates(void)
return 0; return 0;
} }
int static int
print_pem_object(const char *kind, const u8*data, size_t data_len) print_pem_object(const char *kind, const u8*data, size_t data_len)
{ {
FILE *outf; FILE *outf;
@ -193,10 +193,10 @@ print_pem_object(const char *kind, const u8*data, size_t data_len)
return 0; return 0;
} }
int static int
list_data_object(const char *kind, const u8*data, size_t data_len) list_data_object(const char *kind, const u8*data, size_t data_len)
{ {
int i; size_t i;
printf("%s (%i bytes): <", kind, data_len); printf("%s (%i bytes): <", kind, data_len);
for (i = 0; i < data_len; i++) for (i = 0; i < data_len; i++)
@ -206,10 +206,10 @@ list_data_object(const char *kind, const u8*data, size_t data_len)
return 0; return 0;
} }
int static int
print_data_object(const char *kind, const u8*data, size_t data_len) print_data_object(const char *kind, const u8*data, size_t data_len)
{ {
int i; size_t i;
if (opt_outfile != NULL) { if (opt_outfile != NULL) {
FILE *outf; FILE *outf;
@ -235,7 +235,7 @@ print_data_object(const char *kind, const u8*data, size_t data_len)
return 0; return 0;
} }
int read_certificate(void) static int read_certificate(void)
{ {
int r, i, count; int r, i, count;
struct sc_pkcs15_id id; struct sc_pkcs15_id id;
@ -272,7 +272,7 @@ int read_certificate(void)
return 2; return 2;
} }
int read_data_object(void) static int read_data_object(void)
{ {
int r, i, count, oid_len = 0; int r, i, count, oid_len = 0;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -317,7 +317,7 @@ int read_data_object(void)
return 2; return 2;
} }
int list_data_objects(void) static int list_data_objects(void)
{ {
int r, i, count; int r, i, count;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -359,7 +359,7 @@ int list_data_objects(void)
return 0; return 0;
} }
void print_prkey_info(const struct sc_pkcs15_object *obj) static void print_prkey_info(const struct sc_pkcs15_object *obj)
{ {
unsigned int i; unsigned int i;
struct sc_pkcs15_prkey_info *prkey = (struct sc_pkcs15_prkey_info *) obj->data; struct sc_pkcs15_prkey_info *prkey = (struct sc_pkcs15_prkey_info *) obj->data;
@ -368,7 +368,7 @@ void print_prkey_info(const struct sc_pkcs15_object *obj)
"wrap", "unwrap", "verify", "verifyRecover", "wrap", "unwrap", "verify", "verifyRecover",
"derive", "nonRepudiation" "derive", "nonRepudiation"
}; };
const int usage_count = sizeof(usages)/sizeof(usages[0]); const size_t usage_count = sizeof(usages)/sizeof(usages[0]);
const char *access_flags[] = { const char *access_flags[] = {
"sensitive", "extract", "alwaysSensitive", "sensitive", "extract", "alwaysSensitive",
"neverExtract", "local" "neverExtract", "local"
@ -401,7 +401,7 @@ void print_prkey_info(const struct sc_pkcs15_object *obj)
} }
int list_private_keys(void) static int list_private_keys(void)
{ {
int r, i; int r, i;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -420,7 +420,7 @@ int list_private_keys(void)
return 0; return 0;
} }
void print_pubkey_info(const struct sc_pkcs15_object *obj) static void print_pubkey_info(const struct sc_pkcs15_object *obj)
{ {
unsigned int i; unsigned int i;
const struct sc_pkcs15_pubkey_info *pubkey = (const struct sc_pkcs15_pubkey_info *) obj->data; const struct sc_pkcs15_pubkey_info *pubkey = (const struct sc_pkcs15_pubkey_info *) obj->data;
@ -461,7 +461,7 @@ void print_pubkey_info(const struct sc_pkcs15_object *obj)
printf("\tID : %s\n", sc_pkcs15_print_id(&pubkey->id)); printf("\tID : %s\n", sc_pkcs15_print_id(&pubkey->id));
} }
int list_public_keys(void) static int list_public_keys(void)
{ {
int r, i; int r, i;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -480,7 +480,7 @@ int list_public_keys(void)
return 0; return 0;
} }
int read_public_key(void) static int read_public_key(void)
{ {
int r; int r;
struct sc_pkcs15_id id; struct sc_pkcs15_id id;
@ -572,7 +572,7 @@ get_pin_info(void)
return obj; return obj;
} }
u8 * get_pin(const char *prompt, sc_pkcs15_object_t *pin_obj) static u8 * get_pin(const char *prompt, sc_pkcs15_object_t *pin_obj)
{ {
sc_pkcs15_pin_info_t *pinfo = (sc_pkcs15_pin_info_t *) pin_obj->data; sc_pkcs15_pin_info_t *pinfo = (sc_pkcs15_pin_info_t *) pin_obj->data;
char buf[80]; char buf[80];
@ -616,7 +616,7 @@ authenticate(sc_pkcs15_object_t *obj)
pin, pin? strlen((char *) pin) : 0); pin, pin? strlen((char *) pin) : 0);
} }
void print_pin_info(const struct sc_pkcs15_object *obj) static void print_pin_info(const struct sc_pkcs15_object *obj)
{ {
const char *pin_flags[] = { const char *pin_flags[] = {
"case-sensitive", "local", "change-disabled", "case-sensitive", "local", "change-disabled",
@ -628,9 +628,9 @@ void print_pin_info(const struct sc_pkcs15_object *obj)
const char *pin_types[] = {"bcd", "ascii-numeric", "UTF-8", const char *pin_types[] = {"bcd", "ascii-numeric", "UTF-8",
"halfnibble bcd", "iso 9664-1"}; "halfnibble bcd", "iso 9664-1"};
const struct sc_pkcs15_pin_info *pin = (const struct sc_pkcs15_pin_info *) obj->data; const struct sc_pkcs15_pin_info *pin = (const struct sc_pkcs15_pin_info *) obj->data;
const int pf_count = sizeof(pin_flags)/sizeof(pin_flags[0]); const size_t pf_count = sizeof(pin_flags)/sizeof(pin_flags[0]);
char path[SC_MAX_PATH_SIZE * 2 + 1]; char path[SC_MAX_PATH_SIZE * 2 + 1];
int i; size_t i;
char *p; char *p;
p = path; p = path;
@ -658,7 +658,7 @@ void print_pin_info(const struct sc_pkcs15_object *obj)
printf("\tTries left: %d\n", pin->tries_left); printf("\tTries left: %d\n", pin->tries_left);
} }
int list_pins(void) static int list_pins(void)
{ {
int r, i; int r, i;
struct sc_pkcs15_object *objs[32]; struct sc_pkcs15_object *objs[32];
@ -677,7 +677,7 @@ int list_pins(void)
return 0; return 0;
} }
int unblock_pin(void) static int unblock_pin(void)
{ {
struct sc_pkcs15_pin_info *pinfo = NULL; struct sc_pkcs15_pin_info *pinfo = NULL;
sc_pkcs15_object_t *pin_obj; sc_pkcs15_object_t *pin_obj;
@ -727,7 +727,7 @@ int unblock_pin(void)
return 0; return 0;
} }
int change_pin(void) static int change_pin(void)
{ {
sc_pkcs15_object_t *pin_obj; sc_pkcs15_object_t *pin_obj;
sc_pkcs15_pin_info_t *pinfo = NULL; sc_pkcs15_pin_info_t *pinfo = NULL;
@ -781,9 +781,9 @@ int change_pin(void)
return 0; return 0;
} }
int read_and_cache_file(const struct sc_path *path) static int read_and_cache_file(const struct sc_path *path)
{ {
struct sc_file *tmpfile; struct sc_file *tfile;
const struct sc_acl_entry *e; const struct sc_acl_entry *e;
u8 buf[16384]; u8 buf[16384];
int r; int r;
@ -793,18 +793,18 @@ int read_and_cache_file(const struct sc_path *path)
hex_dump(stdout, path->value, path->len, ""); hex_dump(stdout, path->value, path->len, "");
printf("...\n"); printf("...\n");
} }
r = sc_select_file(card, path, &tmpfile); r = sc_select_file(card, path, &tfile);
if (r != 0) { if (r != 0) {
fprintf(stderr, "sc_select_file() failed: %s\n", sc_strerror(r)); fprintf(stderr, "sc_select_file() failed: %s\n", sc_strerror(r));
return -1; return -1;
} }
e = sc_file_get_acl_entry(tmpfile, SC_AC_OP_READ); e = sc_file_get_acl_entry(tfile, SC_AC_OP_READ);
if (e != NULL && e->method != SC_AC_NONE) { if (e != NULL && e->method != SC_AC_NONE) {
if (verbose) if (verbose)
printf("Skipping; ACL for read operation is not NONE.\n"); printf("Skipping; ACL for read operation is not NONE.\n");
return -1; return -1;
} }
r = sc_read_binary(card, 0, buf, tmpfile->size, 0); r = sc_read_binary(card, 0, buf, tfile->size, 0);
if (r < 0) { if (r < 0) {
fprintf(stderr, "sc_read_binary() failed: %s\n", sc_strerror(r)); fprintf(stderr, "sc_read_binary() failed: %s\n", sc_strerror(r));
return -1; return -1;
@ -814,11 +814,11 @@ int read_and_cache_file(const struct sc_path *path)
fprintf(stderr, "Unable to cache file: %s\n", sc_strerror(r)); fprintf(stderr, "Unable to cache file: %s\n", sc_strerror(r));
return -1; return -1;
} }
sc_file_free(tmpfile); sc_file_free(tfile);
return 0; return 0;
} }
int learn_card(void) static int learn_card(void)
{ {
char dir[PATH_MAX]; char dir[PATH_MAX];
int r, i, cert_count; int r, i, cert_count;