as every card structure has an own copy of the card ops struc, allocating a new one shouldn't be necessary

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2147 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
nils 2005-02-06 20:46:15 +00:00
parent bd0cb300f8
commit 8a9646cc1b
2 changed files with 11 additions and 32 deletions

View File

@ -20,8 +20,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "internal.h" #include <opensc/pkcs15.h>
#include "pkcs15.h" #include <opensc/log.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -29,7 +29,6 @@
int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *); int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
static int (*set_security_env)(sc_card_t *, const struct sc_security_env *, int); static int (*set_security_env)(sc_card_t *, const struct sc_security_env *, int);
static int (*compute_signature)(sc_card_t *, const u8 *, size_t, u8 *, size_t);
static int set_sec_env(sc_card_t *card, const struct sc_security_env *env, int se_num) static int set_sec_env(sc_card_t *card, const struct sc_security_env *env, int se_num)
{ {
@ -327,20 +326,11 @@ sc_pkcs15emu_infocamere_init(sc_pkcs15_card_t *p15card)
r = sc_select_file(card, &path, NULL); r = sc_select_file(card, &path, NULL);
if (change_sign) { if (change_sign) {
struct sc_card_operations *new_ops;
new_ops = (struct sc_card_operations *) calloc(1, sizeof(*new_ops));
if (!new_ops)
return SC_ERROR_OUT_OF_MEMORY;
/* copy normal cardos card ops */
*new_ops = *card->ops;
/* save old signature funcs */ /* save old signature funcs */
set_security_env = new_ops->set_security_env; set_security_env = card->ops->set_security_env;
compute_signature = new_ops->compute_signature; /* set new one */
/* set new one */ card->ops->set_security_env = set_sec_env;
new_ops->set_security_env = set_sec_env; card->ops->compute_signature = do_sign;
new_ops->compute_signature = do_sign;
/* use new ops */
card->ops = new_ops;
} }
return 0; return 0;
@ -348,7 +338,6 @@ sc_pkcs15emu_infocamere_init(sc_pkcs15_card_t *p15card)
failed: sc_error(card->ctx, "Failed to initialize Infocamere emulation: %s\n", failed: sc_error(card->ctx, "Failed to initialize Infocamere emulation: %s\n",
sc_strerror(r)); sc_strerror(r));
return r; return r;
} }
static int infocamere_detect_card(sc_pkcs15_card_t *p15card) static int infocamere_detect_card(sc_pkcs15_card_t *p15card)

View File

@ -20,8 +20,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "internal.h" #include <opensc/pkcs15.h>
#include "pkcs15.h" #include <opensc/log.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -29,7 +29,6 @@
int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *); int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
static int (*set_security_env) (sc_card_t *, const struct sc_security_env *, int); static int (*set_security_env) (sc_card_t *, const struct sc_security_env *, int);
static int (*compute_signature) (sc_card_t *, const u8 *, size_t, u8 *, size_t);
static int set_sec_env(sc_card_t * card, const struct sc_security_env *env, static int set_sec_env(sc_card_t * card, const struct sc_security_env *env,
int se_num) int se_num)
@ -222,20 +221,11 @@ static int sc_pkcs15emu_postecert_init(sc_pkcs15_card_t * p15card)
sc_format_path("3F00", &path); sc_format_path("3F00", &path);
sc_select_file(card, &path, NULL); sc_select_file(card, &path, NULL);
{ {
struct sc_card_operations *new_ops;
new_ops = (struct sc_card_operations *) calloc(1, sizeof(*new_ops));
if (!new_ops)
return SC_ERROR_OUT_OF_MEMORY;
/* copy normal cardos card ops */
*new_ops = *card->ops;
/* save old signature funcs */ /* save old signature funcs */
set_security_env = new_ops->set_security_env; set_security_env = card->ops->set_security_env;
compute_signature = new_ops->compute_signature;
/* set new one */ /* set new one */
new_ops->set_security_env = set_sec_env; card->ops->set_security_env = set_sec_env;
new_ops->compute_signature = do_sign; card->ops->compute_signature = do_sign;
/* use new ops */
card->ops = new_ops;
} }
return 0; return 0;