diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index 9efe2f84..713b8da5 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -2075,3 +2075,62 @@ int sc_pkcs15_allocate_object_content(struct sc_pkcs15_object *obj, return SC_SUCCESS; } + +struct sc_supported_algo_info * +sc_pkcs15_get_supported_algo(struct sc_pkcs15_card *p15card, + unsigned operation, unsigned mechanism) +{ + struct sc_context *ctx = p15card->card->ctx; + struct sc_supported_algo_info *info = NULL; + int ii; + + for (ii=0;iitokeninfo->supported_algos[ii].reference; ii++) + if ((p15card->tokeninfo->supported_algos[ii].operations & operation) + && (p15card->tokeninfo->supported_algos[ii].mechanism == mechanism)) + break; + + if (ii < SC_MAX_SUPPORTED_ALGORITHMS && p15card->tokeninfo->supported_algos[ii].reference) { + info = &p15card->tokeninfo->supported_algos[ii]; + sc_log(ctx, "found supported algorithm (ref:%X,mech:%X,ops:%X,algo_ref:%X)", + info->reference, info->mechanism, info->operations, info->algo_ref); + } + + return info; +} + + +int +sc_pkcs15_add_supported_algo_ref(struct sc_pkcs15_object *obj, + struct sc_supported_algo_info *algo) +{ + int *algo_refs = NULL; + int ii; + + if (!algo) + return SC_SUCCESS; + + switch (obj->type) { + case SC_PKCS15_TYPE_PRKEY_RSA: + algo_refs = ((struct sc_pkcs15_prkey_info *)obj->data)->algo_refs; + break; + case SC_PKCS15_TYPE_PUBKEY_RSA: + algo_refs = ((struct sc_pkcs15_pubkey_info *)obj->data)->algo_refs; + break; + } + if (!algo_refs) + return SC_ERROR_NOT_SUPPORTED; + + for (ii=0;iireference) + return SC_SUCCESS; + + for (ii=0;iireference; + return SC_SUCCESS; + } + } + + return SC_ERROR_TOO_MANY_OBJECTS; +} + diff --git a/src/libopensc/pkcs15.h b/src/libopensc/pkcs15.h index 2b77e8f2..fc93f4bd 100644 --- a/src/libopensc/pkcs15.h +++ b/src/libopensc/pkcs15.h @@ -319,6 +319,8 @@ struct sc_pkcs15_prkey_info { size_t modulus_length; /* RSA */ size_t field_length; /* EC in bits */ + int algo_refs[SC_MAX_SUPPORTED_ALGORITHMS]; + struct sc_pkcs15_der subject; void *params; @@ -336,6 +338,8 @@ struct sc_pkcs15_pubkey_info { size_t modulus_length; /* RSA */ size_t field_length; /* EC in bits */ + int algo_refs[SC_MAX_SUPPORTED_ALGORITHMS]; + struct sc_pkcs15_der subject; void *params; @@ -781,6 +785,11 @@ void sc_pkcs15_free_object_content(struct sc_pkcs15_object *); int sc_pkcs15_allocate_object_content(struct sc_pkcs15_object *, const unsigned char *, size_t); +struct sc_supported_algo_info *sc_pkcs15_get_supported_algo(struct sc_pkcs15_card *, + unsigned, unsigned); +int sc_pkcs15_add_supported_algo_ref(struct sc_pkcs15_object *, + struct sc_supported_algo_info *); + /* New object search API. * More complex, but also more powerful. */