EAC_set_cvc_default_dir:
   64|    238|{
   65|    238|    if (default_dir) {
  ------------------
  |  Branch (65:9): [True: 238, False: 0]
  ------------------
   66|    238|        strncpy(cvc_default_dir, default_dir, (sizeof cvc_default_dir) - 1);
   67|    238|        cvc_default_dir[(sizeof cvc_default_dir) - 1] = '\0';
   68|    238|    }
   69|    238|}

EAC_init:
   71|    119|{
   72|       |    OpenSSL_add_all_algorithms();
   73|    119|    EAC_add_all_objects();
   74|    119|    EAC_set_x509_default_dir(X509DIR);
   75|    119|    EAC_set_cvc_default_dir(CVCDIR);
   76|    119|}
EAC_CTX_clear_free:
  277|      8|{
  278|      8|    if (ctx) {
  ------------------
  |  Branch (278:9): [True: 0, False: 8]
  ------------------
  279|      0|        if (ctx->bn_ctx)
  ------------------
  |  Branch (279:13): [True: 0, False: 0]
  ------------------
  280|      0|            BN_CTX_free(ctx->bn_ctx);
  281|      0|        if (ctx->md_ctx)
  ------------------
  |  Branch (281:13): [True: 0, False: 0]
  ------------------
  282|      0|            EVP_MD_CTX_destroy(ctx->md_ctx);
  283|      0|        if (ctx->cipher_ctx)
  ------------------
  |  Branch (283:13): [True: 0, False: 0]
  ------------------
  284|      0|            EVP_CIPHER_CTX_free(ctx->cipher_ctx);
  285|      0|        sk_pop_free((_STACK *) ctx->pace_ctxs, wrap_pace_ctx_clear_free);
  286|      0|        sk_pop_free((_STACK *) ctx->ca_ctxs, wrap_ca_ctx_clear_free);
  287|      0|        sk_pop_free((_STACK *) ctx->ri_ctxs, wrap_ri_ctx_clear_free);
  288|      0|        TA_CTX_clear_free(ctx->ta_ctx);
  289|      0|        KA_CTX_clear_free(ctx->key_ctx);
  290|      0|        if (ctx->ssc)
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  ------------------
  291|      0|            BN_clear_free(ctx->ssc);
  292|       |        OPENSSL_free(ctx);
  293|      0|    }
  294|      8|}

EAC_add_all_objects:
  174|    119|{
  175|    119|    int obj;
  176|       |
  177|    119|    if (objects_initialized)
  ------------------
  |  Branch (177:9): [True: 118, False: 1]
  ------------------
  178|    118|        return;
  179|       |
  180|       |    /* derived from a patched obj_mac.h with the power of regex */
  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  182|       |
  183|      1|#define ASC_standardizedDomainParameters		ASC_bsi_de".1.2"
  184|      1|    obj = OBJ_txt2nid(ASC_standardizedDomainParameters);
  ------------------
  |  |  183|      1|#define ASC_standardizedDomainParameters		ASC_bsi_de".1.2"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
  185|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (185:9): [True: 1, False: 0]
  ------------------
  186|      1|        obj = OBJ_create(ASC_standardizedDomainParameters	, SN_standardizedDomainParameters	, SN_standardizedDomainParameters	);
  ------------------
  |  |  183|      1|#define ASC_standardizedDomainParameters		ASC_bsi_de".1.2"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_standardizedDomainParameters	, SN_standardizedDomainParameters	, SN_standardizedDomainParameters	);
  ------------------
  |  |   81|      1|#define SN_standardizedDomainParameters		"standardizedDomainParameters"
  ------------------
                      obj = OBJ_create(ASC_standardizedDomainParameters	, SN_standardizedDomainParameters	, SN_standardizedDomainParameters	);
  ------------------
  |  |   81|      1|#define SN_standardizedDomainParameters		"standardizedDomainParameters"
  ------------------
  187|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (187:9): [True: 1, False: 0]
  ------------------
  188|      1|        NID_standardizedDomainParameters = obj;
  189|       |
  190|      1|#define ASC_id_PK		ASC_bsi_de".2.2.1"
  191|       |
  192|      1|#define ASC_id_PK_DH		ASC_id_PK".1"
  193|      1|    obj = OBJ_txt2nid(ASC_id_PK_DH);
  ------------------
  |  |  192|      1|#define ASC_id_PK_DH		ASC_id_PK".1"
  |  |  ------------------
  |  |  |  |  190|      1|#define ASC_id_PK		ASC_bsi_de".2.2.1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (194:9): [True: 1, False: 0]
  ------------------
  195|      1|        obj = OBJ_create(ASC_id_PK_DH	, SN_id_PK_DH	, SN_id_PK_DH	);
  ------------------
  |  |  192|      1|#define ASC_id_PK_DH		ASC_id_PK".1"
  |  |  ------------------
  |  |  |  |  190|      1|#define ASC_id_PK		ASC_bsi_de".2.2.1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PK_DH	, SN_id_PK_DH	, SN_id_PK_DH	);
  ------------------
  |  |   87|      1|#define SN_id_PK_DH		"id-PK-DH"
  ------------------
                      obj = OBJ_create(ASC_id_PK_DH	, SN_id_PK_DH	, SN_id_PK_DH	);
  ------------------
  |  |   87|      1|#define SN_id_PK_DH		"id-PK-DH"
  ------------------
  196|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (196:9): [True: 1, False: 0]
  ------------------
  197|      1|        NID_id_PK_DH = obj;
  198|       |
  199|      1|#define ASC_id_PK_ECDH		ASC_id_PK".2"
  200|      1|    obj = OBJ_txt2nid(ASC_id_PK_ECDH);
  ------------------
  |  |  199|      1|#define ASC_id_PK_ECDH		ASC_id_PK".2"
  |  |  ------------------
  |  |  |  |  190|      1|#define ASC_id_PK		ASC_bsi_de".2.2.1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (201:9): [True: 1, False: 0]
  ------------------
  202|      1|        obj = OBJ_create(ASC_id_PK_ECDH	, SN_id_PK_ECDH	, SN_id_PK_ECDH	);
  ------------------
  |  |  199|      1|#define ASC_id_PK_ECDH		ASC_id_PK".2"
  |  |  ------------------
  |  |  |  |  190|      1|#define ASC_id_PK		ASC_bsi_de".2.2.1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PK_ECDH	, SN_id_PK_ECDH	, SN_id_PK_ECDH	);
  ------------------
  |  |   91|      1|#define SN_id_PK_ECDH		"id-PK-ECDH"
  ------------------
                      obj = OBJ_create(ASC_id_PK_ECDH	, SN_id_PK_ECDH	, SN_id_PK_ECDH	);
  ------------------
  |  |   91|      1|#define SN_id_PK_ECDH		"id-PK-ECDH"
  ------------------
  203|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (203:9): [True: 1, False: 0]
  ------------------
  204|      1|        NID_id_PK_ECDH = obj;
  205|       |
  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  207|      1|    obj = OBJ_txt2nid(ASC_id_TA);
  ------------------
  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
  208|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (208:9): [True: 1, False: 0]
  ------------------
  209|      1|        obj = OBJ_create(ASC_id_TA	, SN_id_TA	, SN_id_TA	);
  ------------------
  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA	, SN_id_TA	, SN_id_TA	);
  ------------------
  |  |   95|      1|#define SN_id_TA		"id-TA"
  ------------------
                      obj = OBJ_create(ASC_id_TA	, SN_id_TA	, SN_id_TA	);
  ------------------
  |  |   95|      1|#define SN_id_TA		"id-TA"
  ------------------
  210|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (210:9): [True: 1, False: 0]
  ------------------
  211|      1|        NID_id_TA = obj;
  212|       |
  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  214|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA);
  ------------------
  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  ------------------
  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (215:9): [True: 1, False: 0]
  ------------------
  216|      1|        obj = OBJ_create(ASC_id_TA_RSA	, SN_id_TA_RSA	, SN_id_TA_RSA	);
  ------------------
  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  ------------------
  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA	, SN_id_TA_RSA	, SN_id_TA_RSA	);
  ------------------
  |  |   99|      1|#define SN_id_TA_RSA		"id-TA-RSA"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA	, SN_id_TA_RSA	, SN_id_TA_RSA	);
  ------------------
  |  |   99|      1|#define SN_id_TA_RSA		"id-TA-RSA"
  ------------------
  217|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (217:9): [True: 1, False: 0]
  ------------------
  218|      1|        NID_id_TA_RSA = obj;
  219|       |
  220|      1|#define ASC_id_TA_RSA_v1_5_SHA_1		ASC_id_TA_RSA".1"
  221|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_v1_5_SHA_1);
  ------------------
  |  |  220|      1|#define ASC_id_TA_RSA_v1_5_SHA_1		ASC_id_TA_RSA".1"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (222:9): [True: 1, False: 0]
  ------------------
  223|      1|        obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	);
  ------------------
  |  |  220|      1|#define ASC_id_TA_RSA_v1_5_SHA_1		ASC_id_TA_RSA".1"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	);
  ------------------
  |  |  103|      1|#define SN_id_TA_RSA_v1_5_SHA_1		"id-TA-RSA-v1-5-SHA-1"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	, SN_id_TA_RSA_v1_5_SHA_1	);
  ------------------
  |  |  103|      1|#define SN_id_TA_RSA_v1_5_SHA_1		"id-TA-RSA-v1-5-SHA-1"
  ------------------
  224|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (224:9): [True: 1, False: 0]
  ------------------
  225|      1|        NID_id_TA_RSA_v1_5_SHA_1 = obj;
  226|       |
  227|      1|#define ASC_id_TA_RSA_v1_5_SHA_256		ASC_id_TA_RSA".2"
  228|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_v1_5_SHA_256);
  ------------------
  |  |  227|      1|#define ASC_id_TA_RSA_v1_5_SHA_256		ASC_id_TA_RSA".2"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  229|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (229:9): [True: 1, False: 0]
  ------------------
  230|      1|        obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	);
  ------------------
  |  |  227|      1|#define ASC_id_TA_RSA_v1_5_SHA_256		ASC_id_TA_RSA".2"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	);
  ------------------
  |  |  107|      1|#define SN_id_TA_RSA_v1_5_SHA_256		"id-TA-RSA-v1-5-SHA-256"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	, SN_id_TA_RSA_v1_5_SHA_256	);
  ------------------
  |  |  107|      1|#define SN_id_TA_RSA_v1_5_SHA_256		"id-TA-RSA-v1-5-SHA-256"
  ------------------
  231|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (231:9): [True: 1, False: 0]
  ------------------
  232|      1|        NID_id_TA_RSA_v1_5_SHA_256 = obj;
  233|       |
  234|      1|#define ASC_id_TA_RSA_PSS_SHA_1		ASC_id_TA_RSA".3"
  235|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_PSS_SHA_1);
  ------------------
  |  |  234|      1|#define ASC_id_TA_RSA_PSS_SHA_1		ASC_id_TA_RSA".3"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (236:9): [True: 1, False: 0]
  ------------------
  237|      1|        obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	);
  ------------------
  |  |  234|      1|#define ASC_id_TA_RSA_PSS_SHA_1		ASC_id_TA_RSA".3"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	);
  ------------------
  |  |  111|      1|#define SN_id_TA_RSA_PSS_SHA_1		"id-TA-RSA-PSS-SHA-1"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	, SN_id_TA_RSA_PSS_SHA_1	);
  ------------------
  |  |  111|      1|#define SN_id_TA_RSA_PSS_SHA_1		"id-TA-RSA-PSS-SHA-1"
  ------------------
  238|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (238:9): [True: 1, False: 0]
  ------------------
  239|      1|        NID_id_TA_RSA_PSS_SHA_1 = obj;
  240|       |
  241|      1|#define ASC_id_TA_RSA_PSS_SHA_256		ASC_id_TA_RSA".4"
  242|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_PSS_SHA_256);
  ------------------
  |  |  241|      1|#define ASC_id_TA_RSA_PSS_SHA_256		ASC_id_TA_RSA".4"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (243:9): [True: 1, False: 0]
  ------------------
  244|      1|        obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	);
  ------------------
  |  |  241|      1|#define ASC_id_TA_RSA_PSS_SHA_256		ASC_id_TA_RSA".4"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	);
  ------------------
  |  |  115|      1|#define SN_id_TA_RSA_PSS_SHA_256		"id-TA-RSA-PSS-SHA-256"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	, SN_id_TA_RSA_PSS_SHA_256	);
  ------------------
  |  |  115|      1|#define SN_id_TA_RSA_PSS_SHA_256		"id-TA-RSA-PSS-SHA-256"
  ------------------
  245|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (245:9): [True: 1, False: 0]
  ------------------
  246|      1|        NID_id_TA_RSA_PSS_SHA_256 = obj;
  247|       |
  248|      1|#define ASC_id_TA_RSA_v1_5_SHA_512		ASC_id_TA_RSA".5"
  249|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_v1_5_SHA_512);
  ------------------
  |  |  248|      1|#define ASC_id_TA_RSA_v1_5_SHA_512		ASC_id_TA_RSA".5"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  250|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (250:9): [True: 1, False: 0]
  ------------------
  251|      1|        obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	);
  ------------------
  |  |  248|      1|#define ASC_id_TA_RSA_v1_5_SHA_512		ASC_id_TA_RSA".5"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	);
  ------------------
  |  |  119|      1|#define SN_id_TA_RSA_v1_5_SHA_512		"id-TA-RSA-v1-5-SHA-512"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	, SN_id_TA_RSA_v1_5_SHA_512	);
  ------------------
  |  |  119|      1|#define SN_id_TA_RSA_v1_5_SHA_512		"id-TA-RSA-v1-5-SHA-512"
  ------------------
  252|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (252:9): [True: 1, False: 0]
  ------------------
  253|      1|        NID_id_TA_RSA_v1_5_SHA_512 = obj;
  254|       |
  255|      1|#define ASC_id_TA_RSA_PSS_SHA_512		ASC_id_TA_RSA".6"
  256|      1|    obj = OBJ_txt2nid(ASC_id_TA_RSA_PSS_SHA_512);
  ------------------
  |  |  255|      1|#define ASC_id_TA_RSA_PSS_SHA_512		ASC_id_TA_RSA".6"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (257:9): [True: 1, False: 0]
  ------------------
  258|      1|        obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	);
  ------------------
  |  |  255|      1|#define ASC_id_TA_RSA_PSS_SHA_512		ASC_id_TA_RSA".6"
  |  |  ------------------
  |  |  |  |  213|      1|#define ASC_id_TA_RSA		ASC_id_TA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	);
  ------------------
  |  |  123|      1|#define SN_id_TA_RSA_PSS_SHA_512		"id-TA-RSA-PSS-SHA-512"
  ------------------
                      obj = OBJ_create(ASC_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	, SN_id_TA_RSA_PSS_SHA_512	);
  ------------------
  |  |  123|      1|#define SN_id_TA_RSA_PSS_SHA_512		"id-TA-RSA-PSS-SHA-512"
  ------------------
  259|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (259:9): [True: 1, False: 0]
  ------------------
  260|      1|        NID_id_TA_RSA_PSS_SHA_512 = obj;
  261|       |
  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  263|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA);
  ------------------
  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  ------------------
  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  264|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (264:9): [True: 1, False: 0]
  ------------------
  265|      1|        obj = OBJ_create(ASC_id_TA_ECDSA	, SN_id_TA_ECDSA	, SN_id_TA_ECDSA	);
  ------------------
  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  ------------------
  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA	, SN_id_TA_ECDSA	, SN_id_TA_ECDSA	);
  ------------------
  |  |  127|      1|#define SN_id_TA_ECDSA		"id-TA-ECDSA"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA	, SN_id_TA_ECDSA	, SN_id_TA_ECDSA	);
  ------------------
  |  |  127|      1|#define SN_id_TA_ECDSA		"id-TA-ECDSA"
  ------------------
  266|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (266:9): [True: 1, False: 0]
  ------------------
  267|      1|        NID_id_TA_ECDSA = obj;
  268|       |
  269|      1|#define ASC_id_TA_ECDSA_SHA_1		ASC_id_TA_ECDSA".1"
  270|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA_SHA_1);
  ------------------
  |  |  269|      1|#define ASC_id_TA_ECDSA_SHA_1		ASC_id_TA_ECDSA".1"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (271:9): [True: 1, False: 0]
  ------------------
  272|      1|        obj = OBJ_create(ASC_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	);
  ------------------
  |  |  269|      1|#define ASC_id_TA_ECDSA_SHA_1		ASC_id_TA_ECDSA".1"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	);
  ------------------
  |  |  131|      1|#define SN_id_TA_ECDSA_SHA_1		"id-TA-ECDSA-SHA-1"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	, SN_id_TA_ECDSA_SHA_1	);
  ------------------
  |  |  131|      1|#define SN_id_TA_ECDSA_SHA_1		"id-TA-ECDSA-SHA-1"
  ------------------
  273|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (273:9): [True: 1, False: 0]
  ------------------
  274|      1|        NID_id_TA_ECDSA_SHA_1 = obj;
  275|       |
  276|      1|#define ASC_id_TA_ECDSA_SHA_224		ASC_id_TA_ECDSA".2"
  277|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA_SHA_224);
  ------------------
  |  |  276|      1|#define ASC_id_TA_ECDSA_SHA_224		ASC_id_TA_ECDSA".2"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (278:9): [True: 1, False: 0]
  ------------------
  279|      1|        obj = OBJ_create(ASC_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	);
  ------------------
  |  |  276|      1|#define ASC_id_TA_ECDSA_SHA_224		ASC_id_TA_ECDSA".2"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	);
  ------------------
  |  |  135|      1|#define SN_id_TA_ECDSA_SHA_224		"id-TA-ECDSA-SHA-224"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	, SN_id_TA_ECDSA_SHA_224	);
  ------------------
  |  |  135|      1|#define SN_id_TA_ECDSA_SHA_224		"id-TA-ECDSA-SHA-224"
  ------------------
  280|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (280:9): [True: 1, False: 0]
  ------------------
  281|      1|        NID_id_TA_ECDSA_SHA_224 = obj;
  282|       |
  283|      1|#define ASC_id_TA_ECDSA_SHA_256		ASC_id_TA_ECDSA".3"
  284|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA_SHA_256);
  ------------------
  |  |  283|      1|#define ASC_id_TA_ECDSA_SHA_256		ASC_id_TA_ECDSA".3"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (285:9): [True: 1, False: 0]
  ------------------
  286|      1|        obj = OBJ_create(ASC_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	);
  ------------------
  |  |  283|      1|#define ASC_id_TA_ECDSA_SHA_256		ASC_id_TA_ECDSA".3"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	);
  ------------------
  |  |  139|      1|#define SN_id_TA_ECDSA_SHA_256		"id-TA-ECDSA-SHA-256"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	, SN_id_TA_ECDSA_SHA_256	);
  ------------------
  |  |  139|      1|#define SN_id_TA_ECDSA_SHA_256		"id-TA-ECDSA-SHA-256"
  ------------------
  287|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (287:9): [True: 1, False: 0]
  ------------------
  288|      1|        NID_id_TA_ECDSA_SHA_256 = obj;
  289|       |
  290|      1|#define ASC_id_TA_ECDSA_SHA_384		ASC_id_TA_ECDSA".4"
  291|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA_SHA_384);
  ------------------
  |  |  290|      1|#define ASC_id_TA_ECDSA_SHA_384		ASC_id_TA_ECDSA".4"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (292:9): [True: 1, False: 0]
  ------------------
  293|      1|        obj = OBJ_create(ASC_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	);
  ------------------
  |  |  290|      1|#define ASC_id_TA_ECDSA_SHA_384		ASC_id_TA_ECDSA".4"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	);
  ------------------
  |  |  143|      1|#define SN_id_TA_ECDSA_SHA_384		"id-TA-ECDSA-SHA-384"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	, SN_id_TA_ECDSA_SHA_384	);
  ------------------
  |  |  143|      1|#define SN_id_TA_ECDSA_SHA_384		"id-TA-ECDSA-SHA-384"
  ------------------
  294|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (294:9): [True: 1, False: 0]
  ------------------
  295|      1|        NID_id_TA_ECDSA_SHA_384 = obj;
  296|       |
  297|      1|#define ASC_id_TA_ECDSA_SHA_512		ASC_id_TA_ECDSA".5"
  298|      1|    obj = OBJ_txt2nid(ASC_id_TA_ECDSA_SHA_512);
  ------------------
  |  |  297|      1|#define ASC_id_TA_ECDSA_SHA_512		ASC_id_TA_ECDSA".5"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (299:9): [True: 1, False: 0]
  ------------------
  300|      1|        obj = OBJ_create(ASC_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	);
  ------------------
  |  |  297|      1|#define ASC_id_TA_ECDSA_SHA_512		ASC_id_TA_ECDSA".5"
  |  |  ------------------
  |  |  |  |  262|      1|#define ASC_id_TA_ECDSA		ASC_id_TA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  206|      1|#define ASC_id_TA		ASC_bsi_de".2.2.2"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	);
  ------------------
  |  |  147|      1|#define SN_id_TA_ECDSA_SHA_512		"id-TA-ECDSA-SHA-512"
  ------------------
                      obj = OBJ_create(ASC_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	, SN_id_TA_ECDSA_SHA_512	);
  ------------------
  |  |  147|      1|#define SN_id_TA_ECDSA_SHA_512		"id-TA-ECDSA-SHA-512"
  ------------------
  301|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (301:9): [True: 1, False: 0]
  ------------------
  302|      1|        NID_id_TA_ECDSA_SHA_512 = obj;
  303|       |
  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  305|       |
  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  307|      1|    obj = OBJ_txt2nid(ASC_id_CA_DH);
  ------------------
  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  ------------------
  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (308:9): [True: 1, False: 0]
  ------------------
  309|      1|        obj = OBJ_create(ASC_id_CA_DH	, SN_id_CA_DH	, SN_id_CA_DH	);
  ------------------
  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  ------------------
  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH	, SN_id_CA_DH	, SN_id_CA_DH	);
  ------------------
  |  |  153|      1|#define SN_id_CA_DH		"id-CA-DH"
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH	, SN_id_CA_DH	, SN_id_CA_DH	);
  ------------------
  |  |  153|      1|#define SN_id_CA_DH		"id-CA-DH"
  ------------------
  310|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (310:9): [True: 1, False: 0]
  ------------------
  311|      1|        NID_id_CA_DH = obj;
  312|       |
  313|      1|#define ASC_id_CA_DH_3DES_CBC_CBC		ASC_id_CA_DH".1"
  314|      1|    obj = OBJ_txt2nid(ASC_id_CA_DH_3DES_CBC_CBC);
  ------------------
  |  |  313|      1|#define ASC_id_CA_DH_3DES_CBC_CBC		ASC_id_CA_DH".1"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (315:9): [True: 1, False: 0]
  ------------------
  316|      1|        obj = OBJ_create(ASC_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	);
  ------------------
  |  |  313|      1|#define ASC_id_CA_DH_3DES_CBC_CBC		ASC_id_CA_DH".1"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	);
  ------------------
  |  |  157|      1|#define SN_id_CA_DH_3DES_CBC_CBC		"id-CA-DH-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	, SN_id_CA_DH_3DES_CBC_CBC	);
  ------------------
  |  |  157|      1|#define SN_id_CA_DH_3DES_CBC_CBC		"id-CA-DH-3DES-CBC-CBC"
  ------------------
  317|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (317:9): [True: 1, False: 0]
  ------------------
  318|      1|        NID_id_CA_DH_3DES_CBC_CBC = obj;
  319|       |
  320|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_128		ASC_id_CA_DH".2"
  321|      1|    obj = OBJ_txt2nid(ASC_id_CA_DH_AES_CBC_CMAC_128);
  ------------------
  |  |  320|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_128		ASC_id_CA_DH".2"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (322:9): [True: 1, False: 0]
  ------------------
  323|      1|        obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	);
  ------------------
  |  |  320|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_128		ASC_id_CA_DH".2"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	);
  ------------------
  |  |  161|      1|#define SN_id_CA_DH_AES_CBC_CMAC_128		"id-CA-DH-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	, SN_id_CA_DH_AES_CBC_CMAC_128	);
  ------------------
  |  |  161|      1|#define SN_id_CA_DH_AES_CBC_CMAC_128		"id-CA-DH-AES-CBC-CMAC-128"
  ------------------
  324|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (324:9): [True: 1, False: 0]
  ------------------
  325|      1|        NID_id_CA_DH_AES_CBC_CMAC_128 = obj;
  326|       |
  327|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_192		ASC_id_CA_DH".3"
  328|      1|    obj = OBJ_txt2nid(ASC_id_CA_DH_AES_CBC_CMAC_192);
  ------------------
  |  |  327|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_192		ASC_id_CA_DH".3"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  329|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (329:9): [True: 1, False: 0]
  ------------------
  330|      1|        obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	);
  ------------------
  |  |  327|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_192		ASC_id_CA_DH".3"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	);
  ------------------
  |  |  165|      1|#define SN_id_CA_DH_AES_CBC_CMAC_192		"id-CA-DH-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	, SN_id_CA_DH_AES_CBC_CMAC_192	);
  ------------------
  |  |  165|      1|#define SN_id_CA_DH_AES_CBC_CMAC_192		"id-CA-DH-AES-CBC-CMAC-192"
  ------------------
  331|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (331:9): [True: 1, False: 0]
  ------------------
  332|      1|        NID_id_CA_DH_AES_CBC_CMAC_192 = obj;
  333|       |
  334|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_256		ASC_id_CA_DH".4"
  335|      1|    obj = OBJ_txt2nid(ASC_id_CA_DH_AES_CBC_CMAC_256);
  ------------------
  |  |  334|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_256		ASC_id_CA_DH".4"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (336:9): [True: 1, False: 0]
  ------------------
  337|      1|        obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	);
  ------------------
  |  |  334|      1|#define ASC_id_CA_DH_AES_CBC_CMAC_256		ASC_id_CA_DH".4"
  |  |  ------------------
  |  |  |  |  306|      1|#define ASC_id_CA_DH		ASC_id_CA".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	);
  ------------------
  |  |  169|      1|#define SN_id_CA_DH_AES_CBC_CMAC_256		"id-CA-DH-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	, SN_id_CA_DH_AES_CBC_CMAC_256	);
  ------------------
  |  |  169|      1|#define SN_id_CA_DH_AES_CBC_CMAC_256		"id-CA-DH-AES-CBC-CMAC-256"
  ------------------
  338|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (338:9): [True: 1, False: 0]
  ------------------
  339|      1|        NID_id_CA_DH_AES_CBC_CMAC_256 = obj;
  340|       |
  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  342|      1|    obj = OBJ_txt2nid(ASC_id_CA_ECDH);
  ------------------
  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  ------------------
  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  343|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (343:9): [True: 1, False: 0]
  ------------------
  344|      1|        obj = OBJ_create(ASC_id_CA_ECDH	, SN_id_CA_ECDH	, SN_id_CA_ECDH	);
  ------------------
  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  ------------------
  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH	, SN_id_CA_ECDH	, SN_id_CA_ECDH	);
  ------------------
  |  |  173|      1|#define SN_id_CA_ECDH		"id-CA-ECDH"
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH	, SN_id_CA_ECDH	, SN_id_CA_ECDH	);
  ------------------
  |  |  173|      1|#define SN_id_CA_ECDH		"id-CA-ECDH"
  ------------------
  345|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (345:9): [True: 1, False: 0]
  ------------------
  346|      1|        NID_id_CA_ECDH = obj;
  347|       |
  348|      1|#define ASC_id_CA_ECDH_3DES_CBC_CBC		ASC_id_CA_ECDH".1"
  349|      1|    obj = OBJ_txt2nid(ASC_id_CA_ECDH_3DES_CBC_CBC);
  ------------------
  |  |  348|      1|#define ASC_id_CA_ECDH_3DES_CBC_CBC		ASC_id_CA_ECDH".1"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  350|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (350:9): [True: 1, False: 0]
  ------------------
  351|      1|        obj = OBJ_create(ASC_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	);
  ------------------
  |  |  348|      1|#define ASC_id_CA_ECDH_3DES_CBC_CBC		ASC_id_CA_ECDH".1"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	);
  ------------------
  |  |  177|      1|#define SN_id_CA_ECDH_3DES_CBC_CBC		"id-CA-ECDH-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	, SN_id_CA_ECDH_3DES_CBC_CBC	);
  ------------------
  |  |  177|      1|#define SN_id_CA_ECDH_3DES_CBC_CBC		"id-CA-ECDH-3DES-CBC-CBC"
  ------------------
  352|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (352:9): [True: 1, False: 0]
  ------------------
  353|      1|        NID_id_CA_ECDH_3DES_CBC_CBC = obj;
  354|       |
  355|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_128		ASC_id_CA_ECDH".2"
  356|      1|    obj = OBJ_txt2nid(ASC_id_CA_ECDH_AES_CBC_CMAC_128);
  ------------------
  |  |  355|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_128		ASC_id_CA_ECDH".2"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (357:9): [True: 1, False: 0]
  ------------------
  358|      1|        obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	);
  ------------------
  |  |  355|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_128		ASC_id_CA_ECDH".2"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	);
  ------------------
  |  |  181|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_128		"id-CA-ECDH-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	, SN_id_CA_ECDH_AES_CBC_CMAC_128	);
  ------------------
  |  |  181|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_128		"id-CA-ECDH-AES-CBC-CMAC-128"
  ------------------
  359|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (359:9): [True: 1, False: 0]
  ------------------
  360|      1|        NID_id_CA_ECDH_AES_CBC_CMAC_128 = obj;
  361|       |
  362|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_192		ASC_id_CA_ECDH".3"
  363|      1|    obj = OBJ_txt2nid(ASC_id_CA_ECDH_AES_CBC_CMAC_192);
  ------------------
  |  |  362|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_192		ASC_id_CA_ECDH".3"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (364:9): [True: 1, False: 0]
  ------------------
  365|      1|        obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	);
  ------------------
  |  |  362|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_192		ASC_id_CA_ECDH".3"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	);
  ------------------
  |  |  185|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_192		"id-CA-ECDH-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	, SN_id_CA_ECDH_AES_CBC_CMAC_192	);
  ------------------
  |  |  185|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_192		"id-CA-ECDH-AES-CBC-CMAC-192"
  ------------------
  366|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (366:9): [True: 1, False: 0]
  ------------------
  367|      1|        NID_id_CA_ECDH_AES_CBC_CMAC_192 = obj;
  368|       |
  369|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_256		ASC_id_CA_ECDH".4"
  370|      1|    obj = OBJ_txt2nid(ASC_id_CA_ECDH_AES_CBC_CMAC_256);
  ------------------
  |  |  369|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_256		ASC_id_CA_ECDH".4"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  371|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (371:9): [True: 1, False: 0]
  ------------------
  372|      1|        obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	);
  ------------------
  |  |  369|      1|#define ASC_id_CA_ECDH_AES_CBC_CMAC_256		ASC_id_CA_ECDH".4"
  |  |  ------------------
  |  |  |  |  341|      1|#define ASC_id_CA_ECDH		ASC_id_CA".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  304|      1|#define ASC_id_CA		ASC_bsi_de".2.2.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	);
  ------------------
  |  |  189|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_256		"id-CA-ECDH-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	, SN_id_CA_ECDH_AES_CBC_CMAC_256	);
  ------------------
  |  |  189|      1|#define SN_id_CA_ECDH_AES_CBC_CMAC_256		"id-CA-ECDH-AES-CBC-CMAC-256"
  ------------------
  373|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (373:9): [True: 1, False: 0]
  ------------------
  374|      1|        NID_id_CA_ECDH_AES_CBC_CMAC_256 = obj;
  375|       |
  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  377|       |
  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  379|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_GM);
  ------------------
  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  380|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (380:9): [True: 1, False: 0]
  ------------------
  381|      1|        obj = OBJ_create(ASC_id_PACE_DH_GM	, SN_id_PACE_DH_GM	, SN_id_PACE_DH_GM	);
  ------------------
  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM	, SN_id_PACE_DH_GM	, SN_id_PACE_DH_GM	);
  ------------------
  |  |  195|      1|#define SN_id_PACE_DH_GM		"id-PACE-DH-GM"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM	, SN_id_PACE_DH_GM	, SN_id_PACE_DH_GM	);
  ------------------
  |  |  195|      1|#define SN_id_PACE_DH_GM		"id-PACE-DH-GM"
  ------------------
  382|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (382:9): [True: 1, False: 0]
  ------------------
  383|      1|        NID_id_PACE_DH_GM = obj;
  384|       |
  385|      1|#define ASC_id_PACE_DH_GM_3DES_CBC_CBC		ASC_id_PACE_DH_GM".1"
  386|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_GM_3DES_CBC_CBC);
  ------------------
  |  |  385|      1|#define ASC_id_PACE_DH_GM_3DES_CBC_CBC		ASC_id_PACE_DH_GM".1"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  387|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (387:9): [True: 1, False: 0]
  ------------------
  388|      1|        obj = OBJ_create(ASC_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  385|      1|#define ASC_id_PACE_DH_GM_3DES_CBC_CBC		ASC_id_PACE_DH_GM".1"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  199|      1|#define SN_id_PACE_DH_GM_3DES_CBC_CBC		"id-PACE-DH-GM-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	, SN_id_PACE_DH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  199|      1|#define SN_id_PACE_DH_GM_3DES_CBC_CBC		"id-PACE-DH-GM-3DES-CBC-CBC"
  ------------------
  389|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (389:9): [True: 1, False: 0]
  ------------------
  390|      1|        NID_id_PACE_DH_GM_3DES_CBC_CBC = obj;
  391|       |
  392|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_128		ASC_id_PACE_DH_GM".2"
  393|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_GM_AES_CBC_CMAC_128);
  ------------------
  |  |  392|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_128		ASC_id_PACE_DH_GM".2"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (394:9): [True: 1, False: 0]
  ------------------
  395|      1|        obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  392|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_128		ASC_id_PACE_DH_GM".2"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  203|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_128		"id-PACE-DH-GM-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	, SN_id_PACE_DH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  203|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_128		"id-PACE-DH-GM-AES-CBC-CMAC-128"
  ------------------
  396|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (396:9): [True: 1, False: 0]
  ------------------
  397|      1|        NID_id_PACE_DH_GM_AES_CBC_CMAC_128 = obj;
  398|       |
  399|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_192		ASC_id_PACE_DH_GM".3"
  400|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_GM_AES_CBC_CMAC_192);
  ------------------
  |  |  399|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_192		ASC_id_PACE_DH_GM".3"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  401|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (401:9): [True: 1, False: 0]
  ------------------
  402|      1|        obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  399|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_192		ASC_id_PACE_DH_GM".3"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  207|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_192		"id-PACE-DH-GM-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	, SN_id_PACE_DH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  207|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_192		"id-PACE-DH-GM-AES-CBC-CMAC-192"
  ------------------
  403|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (403:9): [True: 1, False: 0]
  ------------------
  404|      1|        NID_id_PACE_DH_GM_AES_CBC_CMAC_192 = obj;
  405|       |
  406|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_256		ASC_id_PACE_DH_GM".4"
  407|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_GM_AES_CBC_CMAC_256);
  ------------------
  |  |  406|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_256		ASC_id_PACE_DH_GM".4"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  408|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (408:9): [True: 1, False: 0]
  ------------------
  409|      1|        obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  406|      1|#define ASC_id_PACE_DH_GM_AES_CBC_CMAC_256		ASC_id_PACE_DH_GM".4"
  |  |  ------------------
  |  |  |  |  378|      1|#define ASC_id_PACE_DH_GM		ASC_id_PACE".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  211|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_256		"id-PACE-DH-GM-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	, SN_id_PACE_DH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  211|      1|#define SN_id_PACE_DH_GM_AES_CBC_CMAC_256		"id-PACE-DH-GM-AES-CBC-CMAC-256"
  ------------------
  410|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (410:9): [True: 1, False: 0]
  ------------------
  411|      1|        NID_id_PACE_DH_GM_AES_CBC_CMAC_256 = obj;
  412|       |
  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  414|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_GM);
  ------------------
  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (415:9): [True: 1, False: 0]
  ------------------
  416|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	);
  ------------------
  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	);
  ------------------
  |  |  215|      1|#define SN_id_PACE_ECDH_GM		"id-PACE-ECDH-GM"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	, SN_id_PACE_ECDH_GM	);
  ------------------
  |  |  215|      1|#define SN_id_PACE_ECDH_GM		"id-PACE-ECDH-GM"
  ------------------
  417|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (417:9): [True: 1, False: 0]
  ------------------
  418|      1|        NID_id_PACE_ECDH_GM = obj;
  419|       |
  420|      1|#define ASC_id_PACE_ECDH_GM_3DES_CBC_CBC		ASC_id_PACE_ECDH_GM".1"
  421|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_GM_3DES_CBC_CBC);
  ------------------
  |  |  420|      1|#define ASC_id_PACE_ECDH_GM_3DES_CBC_CBC		ASC_id_PACE_ECDH_GM".1"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  422|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (422:9): [True: 1, False: 0]
  ------------------
  423|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  420|      1|#define ASC_id_PACE_ECDH_GM_3DES_CBC_CBC		ASC_id_PACE_ECDH_GM".1"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  219|      1|#define SN_id_PACE_ECDH_GM_3DES_CBC_CBC		"id-PACE-ECDH-GM-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	, SN_id_PACE_ECDH_GM_3DES_CBC_CBC	);
  ------------------
  |  |  219|      1|#define SN_id_PACE_ECDH_GM_3DES_CBC_CBC		"id-PACE-ECDH-GM-3DES-CBC-CBC"
  ------------------
  424|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (424:9): [True: 1, False: 0]
  ------------------
  425|      1|        NID_id_PACE_ECDH_GM_3DES_CBC_CBC = obj;
  426|       |
  427|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_GM".2"
  428|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128);
  ------------------
  |  |  427|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_GM".2"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (429:9): [True: 1, False: 0]
  ------------------
  430|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  427|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_GM".2"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  223|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128		"id-PACE-ECDH-GM-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128	);
  ------------------
  |  |  223|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_128		"id-PACE-ECDH-GM-AES-CBC-CMAC-128"
  ------------------
  431|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (431:9): [True: 1, False: 0]
  ------------------
  432|      1|        NID_id_PACE_ECDH_GM_AES_CBC_CMAC_128 = obj;
  433|       |
  434|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_GM".3"
  435|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192);
  ------------------
  |  |  434|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_GM".3"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (436:9): [True: 1, False: 0]
  ------------------
  437|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  434|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_GM".3"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  227|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192		"id-PACE-ECDH-GM-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192	);
  ------------------
  |  |  227|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_192		"id-PACE-ECDH-GM-AES-CBC-CMAC-192"
  ------------------
  438|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (438:9): [True: 1, False: 0]
  ------------------
  439|      1|        NID_id_PACE_ECDH_GM_AES_CBC_CMAC_192 = obj;
  440|       |
  441|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_GM".4"
  442|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256);
  ------------------
  |  |  441|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_GM".4"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (443:9): [True: 1, False: 0]
  ------------------
  444|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  441|      1|#define ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_GM".4"
  |  |  ------------------
  |  |  |  |  413|      1|#define ASC_id_PACE_ECDH_GM		ASC_id_PACE".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  231|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256		"id-PACE-ECDH-GM-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256	);
  ------------------
  |  |  231|      1|#define SN_id_PACE_ECDH_GM_AES_CBC_CMAC_256		"id-PACE-ECDH-GM-AES-CBC-CMAC-256"
  ------------------
  445|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (445:9): [True: 1, False: 0]
  ------------------
  446|      1|        NID_id_PACE_ECDH_GM_AES_CBC_CMAC_256 = obj;
  447|       |
  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  449|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_IM);
  ------------------
  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (450:9): [True: 1, False: 0]
  ------------------
  451|      1|        obj = OBJ_create(ASC_id_PACE_DH_IM	, SN_id_PACE_DH_IM	, SN_id_PACE_DH_IM	);
  ------------------
  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM	, SN_id_PACE_DH_IM	, SN_id_PACE_DH_IM	);
  ------------------
  |  |  235|      1|#define SN_id_PACE_DH_IM		"id-PACE-DH-IM"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM	, SN_id_PACE_DH_IM	, SN_id_PACE_DH_IM	);
  ------------------
  |  |  235|      1|#define SN_id_PACE_DH_IM		"id-PACE-DH-IM"
  ------------------
  452|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (452:9): [True: 1, False: 0]
  ------------------
  453|      1|        NID_id_PACE_DH_IM = obj;
  454|       |
  455|      1|#define ASC_id_PACE_DH_IM_3DES_CBC_CBC		ASC_id_PACE_DH_IM".1"
  456|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_IM_3DES_CBC_CBC);
  ------------------
  |  |  455|      1|#define ASC_id_PACE_DH_IM_3DES_CBC_CBC		ASC_id_PACE_DH_IM".1"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  457|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (457:9): [True: 1, False: 0]
  ------------------
  458|      1|        obj = OBJ_create(ASC_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  455|      1|#define ASC_id_PACE_DH_IM_3DES_CBC_CBC		ASC_id_PACE_DH_IM".1"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  239|      1|#define SN_id_PACE_DH_IM_3DES_CBC_CBC		"id-PACE-DH-IM-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	, SN_id_PACE_DH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  239|      1|#define SN_id_PACE_DH_IM_3DES_CBC_CBC		"id-PACE-DH-IM-3DES-CBC-CBC"
  ------------------
  459|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (459:9): [True: 1, False: 0]
  ------------------
  460|      1|        NID_id_PACE_DH_IM_3DES_CBC_CBC = obj;
  461|       |
  462|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_128		ASC_id_PACE_DH_IM".2"
  463|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_IM_AES_CBC_CMAC_128);
  ------------------
  |  |  462|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_128		ASC_id_PACE_DH_IM".2"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (464:9): [True: 1, False: 0]
  ------------------
  465|      1|        obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  462|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_128		ASC_id_PACE_DH_IM".2"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  243|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_128		"id-PACE-DH-IM-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	, SN_id_PACE_DH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  243|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_128		"id-PACE-DH-IM-AES-CBC-CMAC-128"
  ------------------
  466|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (466:9): [True: 1, False: 0]
  ------------------
  467|      1|        NID_id_PACE_DH_IM_AES_CBC_CMAC_128 = obj;
  468|       |
  469|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_192		ASC_id_PACE_DH_IM".3"
  470|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_IM_AES_CBC_CMAC_192);
  ------------------
  |  |  469|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_192		ASC_id_PACE_DH_IM".3"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  471|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (471:9): [True: 1, False: 0]
  ------------------
  472|      1|        obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  469|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_192		ASC_id_PACE_DH_IM".3"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  247|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_192		"id-PACE-DH-IM-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	, SN_id_PACE_DH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  247|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_192		"id-PACE-DH-IM-AES-CBC-CMAC-192"
  ------------------
  473|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (473:9): [True: 1, False: 0]
  ------------------
  474|      1|        NID_id_PACE_DH_IM_AES_CBC_CMAC_192 = obj;
  475|       |
  476|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_256		ASC_id_PACE_DH_IM".4"
  477|      1|    obj = OBJ_txt2nid(ASC_id_PACE_DH_IM_AES_CBC_CMAC_256);
  ------------------
  |  |  476|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_256		ASC_id_PACE_DH_IM".4"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (478:9): [True: 1, False: 0]
  ------------------
  479|      1|        obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  476|      1|#define ASC_id_PACE_DH_IM_AES_CBC_CMAC_256		ASC_id_PACE_DH_IM".4"
  |  |  ------------------
  |  |  |  |  448|      1|#define ASC_id_PACE_DH_IM		ASC_id_PACE".3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  251|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_256		"id-PACE-DH-IM-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	, SN_id_PACE_DH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  251|      1|#define SN_id_PACE_DH_IM_AES_CBC_CMAC_256		"id-PACE-DH-IM-AES-CBC-CMAC-256"
  ------------------
  480|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (480:9): [True: 1, False: 0]
  ------------------
  481|      1|        NID_id_PACE_DH_IM_AES_CBC_CMAC_256 = obj;
  482|       |
  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  484|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_IM);
  ------------------
  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  485|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (485:9): [True: 1, False: 0]
  ------------------
  486|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	);
  ------------------
  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  ------------------
  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	);
  ------------------
  |  |  255|      1|#define SN_id_PACE_ECDH_IM		"id-PACE-ECDH-IM"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	, SN_id_PACE_ECDH_IM	);
  ------------------
  |  |  255|      1|#define SN_id_PACE_ECDH_IM		"id-PACE-ECDH-IM"
  ------------------
  487|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (487:9): [True: 1, False: 0]
  ------------------
  488|      1|        NID_id_PACE_ECDH_IM = obj;
  489|       |
  490|      1|#define ASC_id_PACE_ECDH_IM_3DES_CBC_CBC		ASC_id_PACE_ECDH_IM".1"
  491|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_IM_3DES_CBC_CBC);
  ------------------
  |  |  490|      1|#define ASC_id_PACE_ECDH_IM_3DES_CBC_CBC		ASC_id_PACE_ECDH_IM".1"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  492|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (492:9): [True: 1, False: 0]
  ------------------
  493|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  490|      1|#define ASC_id_PACE_ECDH_IM_3DES_CBC_CBC		ASC_id_PACE_ECDH_IM".1"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  259|      1|#define SN_id_PACE_ECDH_IM_3DES_CBC_CBC		"id-PACE-ECDH-IM-3DES-CBC-CBC"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	, SN_id_PACE_ECDH_IM_3DES_CBC_CBC	);
  ------------------
  |  |  259|      1|#define SN_id_PACE_ECDH_IM_3DES_CBC_CBC		"id-PACE-ECDH-IM-3DES-CBC-CBC"
  ------------------
  494|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (494:9): [True: 1, False: 0]
  ------------------
  495|      1|        NID_id_PACE_ECDH_IM_3DES_CBC_CBC = obj;
  496|       |
  497|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_IM".2"
  498|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128);
  ------------------
  |  |  497|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_IM".2"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  499|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (499:9): [True: 1, False: 0]
  ------------------
  500|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  497|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128		ASC_id_PACE_ECDH_IM".2"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  263|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128		"id-PACE-ECDH-IM-AES-CBC-CMAC-128"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128	);
  ------------------
  |  |  263|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_128		"id-PACE-ECDH-IM-AES-CBC-CMAC-128"
  ------------------
  501|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (501:9): [True: 1, False: 0]
  ------------------
  502|      1|        NID_id_PACE_ECDH_IM_AES_CBC_CMAC_128 = obj;
  503|       |
  504|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_IM".3"
  505|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192);
  ------------------
  |  |  504|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_IM".3"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  506|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (506:9): [True: 1, False: 0]
  ------------------
  507|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  504|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192		ASC_id_PACE_ECDH_IM".3"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  267|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192		"id-PACE-ECDH-IM-AES-CBC-CMAC-192"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192	);
  ------------------
  |  |  267|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_192		"id-PACE-ECDH-IM-AES-CBC-CMAC-192"
  ------------------
  508|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (508:9): [True: 1, False: 0]
  ------------------
  509|      1|        NID_id_PACE_ECDH_IM_AES_CBC_CMAC_192 = obj;
  510|       |
  511|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_IM".4"
  512|      1|    obj = OBJ_txt2nid(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256);
  ------------------
  |  |  511|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_IM".4"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (513:9): [True: 1, False: 0]
  ------------------
  514|      1|        obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  511|      1|#define ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256		ASC_id_PACE_ECDH_IM".4"
  |  |  ------------------
  |  |  |  |  483|      1|#define ASC_id_PACE_ECDH_IM		ASC_id_PACE".4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  376|      1|#define ASC_id_PACE		ASC_bsi_de".2.2.4"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  271|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256		"id-PACE-ECDH-IM-AES-CBC-CMAC-256"
  ------------------
                      obj = OBJ_create(ASC_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	, SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256	);
  ------------------
  |  |  271|      1|#define SN_id_PACE_ECDH_IM_AES_CBC_CMAC_256		"id-PACE-ECDH-IM-AES-CBC-CMAC-256"
  ------------------
  515|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (515:9): [True: 1, False: 0]
  ------------------
  516|      1|        NID_id_PACE_ECDH_IM_AES_CBC_CMAC_256 = obj;
  517|       |
  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  519|       |
  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  521|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH);
  ------------------
  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  ------------------
  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  522|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (522:9): [True: 1, False: 0]
  ------------------
  523|      1|        obj = OBJ_create(ASC_id_RI_DH	, SN_id_RI_DH	, SN_id_RI_DH	);
  ------------------
  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  ------------------
  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH	, SN_id_RI_DH	, SN_id_RI_DH	);
  ------------------
  |  |  277|      1|#define SN_id_RI_DH		"id-RI-DH"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH	, SN_id_RI_DH	, SN_id_RI_DH	);
  ------------------
  |  |  277|      1|#define SN_id_RI_DH		"id-RI-DH"
  ------------------
  524|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (524:9): [True: 1, False: 0]
  ------------------
  525|      1|        NID_id_RI_DH = obj;
  526|       |
  527|      1|#define ASC_id_RI_DH_SHA_1		ASC_id_RI_DH".1"
  528|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH_SHA_1);
  ------------------
  |  |  527|      1|#define ASC_id_RI_DH_SHA_1		ASC_id_RI_DH".1"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  529|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (529:9): [True: 1, False: 0]
  ------------------
  530|      1|        obj = OBJ_create(ASC_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	);
  ------------------
  |  |  527|      1|#define ASC_id_RI_DH_SHA_1		ASC_id_RI_DH".1"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	);
  ------------------
  |  |  281|      1|#define SN_id_RI_DH_SHA_1		"id-RI-DH-SHA-1"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	, SN_id_RI_DH_SHA_1	);
  ------------------
  |  |  281|      1|#define SN_id_RI_DH_SHA_1		"id-RI-DH-SHA-1"
  ------------------
  531|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (531:9): [True: 1, False: 0]
  ------------------
  532|      1|        NID_id_RI_DH_SHA_1 = obj;
  533|       |
  534|      1|#define ASC_id_RI_DH_SHA_224		ASC_id_RI_DH".2"
  535|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH_SHA_224);
  ------------------
  |  |  534|      1|#define ASC_id_RI_DH_SHA_224		ASC_id_RI_DH".2"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (536:9): [True: 1, False: 0]
  ------------------
  537|      1|        obj = OBJ_create(ASC_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	);
  ------------------
  |  |  534|      1|#define ASC_id_RI_DH_SHA_224		ASC_id_RI_DH".2"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	);
  ------------------
  |  |  285|      1|#define SN_id_RI_DH_SHA_224		"id-RI-DH-SHA-224"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	, SN_id_RI_DH_SHA_224	);
  ------------------
  |  |  285|      1|#define SN_id_RI_DH_SHA_224		"id-RI-DH-SHA-224"
  ------------------
  538|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (538:9): [True: 1, False: 0]
  ------------------
  539|      1|        NID_id_RI_DH_SHA_224 = obj;
  540|       |
  541|      1|#define ASC_id_RI_DH_SHA_256		ASC_id_RI_DH".3"
  542|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH_SHA_256);
  ------------------
  |  |  541|      1|#define ASC_id_RI_DH_SHA_256		ASC_id_RI_DH".3"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  543|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (543:9): [True: 1, False: 0]
  ------------------
  544|      1|        obj = OBJ_create(ASC_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	);
  ------------------
  |  |  541|      1|#define ASC_id_RI_DH_SHA_256		ASC_id_RI_DH".3"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	);
  ------------------
  |  |  289|      1|#define SN_id_RI_DH_SHA_256		"id-RI-DH-SHA-256"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	, SN_id_RI_DH_SHA_256	);
  ------------------
  |  |  289|      1|#define SN_id_RI_DH_SHA_256		"id-RI-DH-SHA-256"
  ------------------
  545|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (545:9): [True: 1, False: 0]
  ------------------
  546|      1|        NID_id_RI_DH_SHA_256 = obj;
  547|       |
  548|      1|#define ASC_id_RI_DH_SHA_384		ASC_id_RI_DH".4"
  549|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH_SHA_384);
  ------------------
  |  |  548|      1|#define ASC_id_RI_DH_SHA_384		ASC_id_RI_DH".4"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  550|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (550:9): [True: 1, False: 0]
  ------------------
  551|      1|        obj = OBJ_create(ASC_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	);
  ------------------
  |  |  548|      1|#define ASC_id_RI_DH_SHA_384		ASC_id_RI_DH".4"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	);
  ------------------
  |  |  293|      1|#define SN_id_RI_DH_SHA_384		"id-RI-DH-SHA-384"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	, SN_id_RI_DH_SHA_384	);
  ------------------
  |  |  293|      1|#define SN_id_RI_DH_SHA_384		"id-RI-DH-SHA-384"
  ------------------
  552|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (552:9): [True: 1, False: 0]
  ------------------
  553|      1|        NID_id_RI_DH_SHA_384 = obj;
  554|       |
  555|      1|#define ASC_id_RI_DH_SHA_512		ASC_id_RI_DH".5"
  556|      1|    obj = OBJ_txt2nid(ASC_id_RI_DH_SHA_512);
  ------------------
  |  |  555|      1|#define ASC_id_RI_DH_SHA_512		ASC_id_RI_DH".5"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  557|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (557:9): [True: 1, False: 0]
  ------------------
  558|      1|        obj = OBJ_create(ASC_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	);
  ------------------
  |  |  555|      1|#define ASC_id_RI_DH_SHA_512		ASC_id_RI_DH".5"
  |  |  ------------------
  |  |  |  |  520|      1|#define ASC_id_RI_DH		ASC_id_RI".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	);
  ------------------
  |  |  297|      1|#define SN_id_RI_DH_SHA_512		"id-RI-DH-SHA-512"
  ------------------
                      obj = OBJ_create(ASC_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	, SN_id_RI_DH_SHA_512	);
  ------------------
  |  |  297|      1|#define SN_id_RI_DH_SHA_512		"id-RI-DH-SHA-512"
  ------------------
  559|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (559:9): [True: 1, False: 0]
  ------------------
  560|      1|        NID_id_RI_DH_SHA_512 = obj;
  561|       |
  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  563|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH);
  ------------------
  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  ------------------
  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  564|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (564:9): [True: 1, False: 0]
  ------------------
  565|      1|        obj = OBJ_create(ASC_id_RI_ECDH	, SN_id_RI_ECDH	, SN_id_RI_ECDH	);
  ------------------
  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  ------------------
  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH	, SN_id_RI_ECDH	, SN_id_RI_ECDH	);
  ------------------
  |  |  301|      1|#define SN_id_RI_ECDH		"id-RI-ECDH"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH	, SN_id_RI_ECDH	, SN_id_RI_ECDH	);
  ------------------
  |  |  301|      1|#define SN_id_RI_ECDH		"id-RI-ECDH"
  ------------------
  566|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (566:9): [True: 1, False: 0]
  ------------------
  567|      1|        NID_id_RI_ECDH = obj;
  568|       |
  569|      1|#define ASC_id_RI_ECDH_SHA_1		ASC_id_RI_ECDH".1"
  570|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH_SHA_1);
  ------------------
  |  |  569|      1|#define ASC_id_RI_ECDH_SHA_1		ASC_id_RI_ECDH".1"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (571:9): [True: 1, False: 0]
  ------------------
  572|      1|        obj = OBJ_create(ASC_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	);
  ------------------
  |  |  569|      1|#define ASC_id_RI_ECDH_SHA_1		ASC_id_RI_ECDH".1"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	);
  ------------------
  |  |  305|      1|#define SN_id_RI_ECDH_SHA_1		"id-RI-ECDH-SHA-1"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	, SN_id_RI_ECDH_SHA_1	);
  ------------------
  |  |  305|      1|#define SN_id_RI_ECDH_SHA_1		"id-RI-ECDH-SHA-1"
  ------------------
  573|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (573:9): [True: 1, False: 0]
  ------------------
  574|      1|        NID_id_RI_ECDH_SHA_1 = obj;
  575|       |
  576|      1|#define ASC_id_RI_ECDH_SHA_224		ASC_id_RI_ECDH".2"
  577|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH_SHA_224);
  ------------------
  |  |  576|      1|#define ASC_id_RI_ECDH_SHA_224		ASC_id_RI_ECDH".2"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (578:9): [True: 1, False: 0]
  ------------------
  579|      1|        obj = OBJ_create(ASC_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	);
  ------------------
  |  |  576|      1|#define ASC_id_RI_ECDH_SHA_224		ASC_id_RI_ECDH".2"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	);
  ------------------
  |  |  309|      1|#define SN_id_RI_ECDH_SHA_224		"id-RI-ECDH-SHA-224"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	, SN_id_RI_ECDH_SHA_224	);
  ------------------
  |  |  309|      1|#define SN_id_RI_ECDH_SHA_224		"id-RI-ECDH-SHA-224"
  ------------------
  580|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (580:9): [True: 1, False: 0]
  ------------------
  581|      1|        NID_id_RI_ECDH_SHA_224 = obj;
  582|       |
  583|      1|#define ASC_id_RI_ECDH_SHA_256		ASC_id_RI_ECDH".3"
  584|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH_SHA_256);
  ------------------
  |  |  583|      1|#define ASC_id_RI_ECDH_SHA_256		ASC_id_RI_ECDH".3"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (585:9): [True: 1, False: 0]
  ------------------
  586|      1|        obj = OBJ_create(ASC_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	);
  ------------------
  |  |  583|      1|#define ASC_id_RI_ECDH_SHA_256		ASC_id_RI_ECDH".3"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	);
  ------------------
  |  |  313|      1|#define SN_id_RI_ECDH_SHA_256		"id-RI-ECDH-SHA-256"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	, SN_id_RI_ECDH_SHA_256	);
  ------------------
  |  |  313|      1|#define SN_id_RI_ECDH_SHA_256		"id-RI-ECDH-SHA-256"
  ------------------
  587|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (587:9): [True: 1, False: 0]
  ------------------
  588|      1|        NID_id_RI_ECDH_SHA_256 = obj;
  589|       |
  590|      1|#define ASC_id_RI_ECDH_SHA_384		ASC_id_RI_ECDH".4"
  591|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH_SHA_384);
  ------------------
  |  |  590|      1|#define ASC_id_RI_ECDH_SHA_384		ASC_id_RI_ECDH".4"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (592:9): [True: 1, False: 0]
  ------------------
  593|      1|        obj = OBJ_create(ASC_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	);
  ------------------
  |  |  590|      1|#define ASC_id_RI_ECDH_SHA_384		ASC_id_RI_ECDH".4"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	);
  ------------------
  |  |  317|      1|#define SN_id_RI_ECDH_SHA_384		"id-RI-ECDH-SHA-384"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	, SN_id_RI_ECDH_SHA_384	);
  ------------------
  |  |  317|      1|#define SN_id_RI_ECDH_SHA_384		"id-RI-ECDH-SHA-384"
  ------------------
  594|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (594:9): [True: 1, False: 0]
  ------------------
  595|      1|        NID_id_RI_ECDH_SHA_384 = obj;
  596|       |
  597|      1|#define ASC_id_RI_ECDH_SHA_512		ASC_id_RI_ECDH".5"
  598|      1|    obj = OBJ_txt2nid(ASC_id_RI_ECDH_SHA_512);
  ------------------
  |  |  597|      1|#define ASC_id_RI_ECDH_SHA_512		ASC_id_RI_ECDH".5"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  599|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (599:9): [True: 1, False: 0]
  ------------------
  600|      1|        obj = OBJ_create(ASC_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	);
  ------------------
  |  |  597|      1|#define ASC_id_RI_ECDH_SHA_512		ASC_id_RI_ECDH".5"
  |  |  ------------------
  |  |  |  |  562|      1|#define ASC_id_RI_ECDH		ASC_id_RI".2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  518|      1|#define ASC_id_RI		ASC_bsi_de".2.2.5"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	);
  ------------------
  |  |  321|      1|#define SN_id_RI_ECDH_SHA_512		"id-RI-ECDH-SHA-512"
  ------------------
                      obj = OBJ_create(ASC_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	, SN_id_RI_ECDH_SHA_512	);
  ------------------
  |  |  321|      1|#define SN_id_RI_ECDH_SHA_512		"id-RI-ECDH-SHA-512"
  ------------------
  601|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (601:9): [True: 1, False: 0]
  ------------------
  602|      1|        NID_id_RI_ECDH_SHA_512 = obj;
  603|       |
  604|      1|#define ASC_id_CI		ASC_bsi_de".2.2.6"
  605|      1|    obj = OBJ_txt2nid(ASC_id_CI);
  ------------------
  |  |  604|      1|#define ASC_id_CI		ASC_bsi_de".2.2.6"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
  606|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (606:9): [True: 1, False: 0]
  ------------------
  607|      1|        obj = OBJ_create(ASC_id_CI	, SN_id_CI	, SN_id_CI	);
  ------------------
  |  |  604|      1|#define ASC_id_CI		ASC_bsi_de".2.2.6"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CI	, SN_id_CI	, SN_id_CI	);
  ------------------
  |  |  325|      1|#define SN_id_CI		"id-CI"
  ------------------
                      obj = OBJ_create(ASC_id_CI	, SN_id_CI	, SN_id_CI	);
  ------------------
  |  |  325|      1|#define SN_id_CI		"id-CI"
  ------------------
  608|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (608:9): [True: 1, False: 0]
  ------------------
  609|      1|        NID_id_CI = obj;
  610|       |
  611|      1|#define ASC_id_eIDSecurity		ASC_bsi_de".2.2.7"
  612|      1|    obj = OBJ_txt2nid(ASC_id_eIDSecurity);
  ------------------
  |  |  611|      1|#define ASC_id_eIDSecurity		ASC_bsi_de".2.2.7"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
  613|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (613:9): [True: 1, False: 0]
  ------------------
  614|      1|        obj = OBJ_create(ASC_id_eIDSecurity	, SN_id_eIDSecurity	, SN_id_eIDSecurity	);
  ------------------
  |  |  611|      1|#define ASC_id_eIDSecurity		ASC_bsi_de".2.2.7"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_eIDSecurity	, SN_id_eIDSecurity	, SN_id_eIDSecurity	);
  ------------------
  |  |  329|      1|#define SN_id_eIDSecurity		"id-eIDSecurity"
  ------------------
                      obj = OBJ_create(ASC_id_eIDSecurity	, SN_id_eIDSecurity	, SN_id_eIDSecurity	);
  ------------------
  |  |  329|      1|#define SN_id_eIDSecurity		"id-eIDSecurity"
  ------------------
  615|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (615:9): [True: 1, False: 0]
  ------------------
  616|      1|        NID_id_eIDSecurity = obj;
  617|       |
  618|      1|#define ASC_id_PT		ASC_bsi_de".2.2.8"
  619|      1|    obj = OBJ_txt2nid(ASC_id_PT);
  ------------------
  |  |  618|      1|#define ASC_id_PT		ASC_bsi_de".2.2.8"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
  620|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (620:9): [True: 1, False: 0]
  ------------------
  621|      1|        obj = OBJ_create(ASC_id_PT	, SN_id_PT	, SN_id_PT	);
  ------------------
  |  |  618|      1|#define ASC_id_PT		ASC_bsi_de".2.2.8"
  |  |  ------------------
  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_PT	, SN_id_PT	, SN_id_PT	);
  ------------------
  |  |  333|      1|#define SN_id_PT		"id-PT"
  ------------------
                      obj = OBJ_create(ASC_id_PT	, SN_id_PT	, SN_id_PT	);
  ------------------
  |  |  333|      1|#define SN_id_PT		"id-PT"
  ------------------
  622|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (622:9): [True: 1, False: 0]
  ------------------
  623|      1|        NID_id_PT = obj;
  624|       |
  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  626|       |
  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  628|       |
  629|      1|#define ASC_ecka_dh_SessionKDF		ASC_ecka_dh".2"
  630|      1|    obj = OBJ_txt2nid(ASC_ecka_dh_SessionKDF);
  ------------------
  |  |  629|      1|#define ASC_ecka_dh_SessionKDF		ASC_ecka_dh".2"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (631:9): [True: 1, False: 0]
  ------------------
  632|      1|        obj = OBJ_create(ASC_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	);
  ------------------
  |  |  629|      1|#define ASC_ecka_dh_SessionKDF		ASC_ecka_dh".2"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	);
  ------------------
  |  |  341|      1|#define SN_ecka_dh_SessionKDF		"ecka-dh-SessionKDF"
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	, SN_ecka_dh_SessionKDF	);
  ------------------
  |  |  341|      1|#define SN_ecka_dh_SessionKDF		"ecka-dh-SessionKDF"
  ------------------
  633|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (633:9): [True: 1, False: 0]
  ------------------
  634|      1|        NID_ecka_dh_SessionKDF = obj;
  635|       |
  636|      1|#define ASC_ecka_dh_SessionKDF_DES3		ASC_ecka_dh".2.1"
  637|      1|    obj = OBJ_txt2nid(ASC_ecka_dh_SessionKDF_DES3);
  ------------------
  |  |  636|      1|#define ASC_ecka_dh_SessionKDF_DES3		ASC_ecka_dh".2.1"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (638:9): [True: 1, False: 0]
  ------------------
  639|      1|        obj = OBJ_create(ASC_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	);
  ------------------
  |  |  636|      1|#define ASC_ecka_dh_SessionKDF_DES3		ASC_ecka_dh".2.1"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	);
  ------------------
  |  |  345|      1|#define SN_ecka_dh_SessionKDF_DES3		"ecka-dh-SessionKDF-DES3"
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	, SN_ecka_dh_SessionKDF_DES3	);
  ------------------
  |  |  345|      1|#define SN_ecka_dh_SessionKDF_DES3		"ecka-dh-SessionKDF-DES3"
  ------------------
  640|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (640:9): [True: 1, False: 0]
  ------------------
  641|      1|        NID_ecka_dh_SessionKDF_DES3 = obj;
  642|       |
  643|      1|#define ASC_ecka_dh_SessionKDF_AES128		ASC_ecka_dh".2.2"
  644|      1|    obj = OBJ_txt2nid(ASC_ecka_dh_SessionKDF_AES128);
  ------------------
  |  |  643|      1|#define ASC_ecka_dh_SessionKDF_AES128		ASC_ecka_dh".2.2"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (645:9): [True: 1, False: 0]
  ------------------
  646|      1|        obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	);
  ------------------
  |  |  643|      1|#define ASC_ecka_dh_SessionKDF_AES128		ASC_ecka_dh".2.2"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	);
  ------------------
  |  |  349|      1|#define SN_ecka_dh_SessionKDF_AES128		"ecka-dh-SessionKDF-AES128"
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	, SN_ecka_dh_SessionKDF_AES128	);
  ------------------
  |  |  349|      1|#define SN_ecka_dh_SessionKDF_AES128		"ecka-dh-SessionKDF-AES128"
  ------------------
  647|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (647:9): [True: 1, False: 0]
  ------------------
  648|      1|        NID_ecka_dh_SessionKDF_AES128 = obj;
  649|       |
  650|      1|#define ASC_ecka_dh_SessionKDF_AES192		ASC_ecka_dh".2.3"
  651|      1|    obj = OBJ_txt2nid(ASC_ecka_dh_SessionKDF_AES192);
  ------------------
  |  |  650|      1|#define ASC_ecka_dh_SessionKDF_AES192		ASC_ecka_dh".2.3"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (652:9): [True: 1, False: 0]
  ------------------
  653|      1|        obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	);
  ------------------
  |  |  650|      1|#define ASC_ecka_dh_SessionKDF_AES192		ASC_ecka_dh".2.3"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	);
  ------------------
  |  |  353|      1|#define SN_ecka_dh_SessionKDF_AES192		"ecka-dh-SessionKDF-AES192"
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	, SN_ecka_dh_SessionKDF_AES192	);
  ------------------
  |  |  353|      1|#define SN_ecka_dh_SessionKDF_AES192		"ecka-dh-SessionKDF-AES192"
  ------------------
  654|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (654:9): [True: 1, False: 0]
  ------------------
  655|      1|        NID_ecka_dh_SessionKDF_AES192 = obj;
  656|       |
  657|      1|#define ASC_ecka_dh_SessionKDF_AES256		ASC_ecka_dh".2.4"
  658|      1|    obj = OBJ_txt2nid(ASC_ecka_dh_SessionKDF_AES256);
  ------------------
  |  |  657|      1|#define ASC_ecka_dh_SessionKDF_AES256		ASC_ecka_dh".2.4"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  659|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (659:9): [True: 1, False: 0]
  ------------------
  660|      1|        obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	);
  ------------------
  |  |  657|      1|#define ASC_ecka_dh_SessionKDF_AES256		ASC_ecka_dh".2.4"
  |  |  ------------------
  |  |  |  |  627|      1|#define ASC_ecka_dh		ASC_id_ecc".5.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  625|      1|#define ASC_id_ecc		ASC_bsi_de".1.1"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	);
  ------------------
  |  |  357|      1|#define SN_ecka_dh_SessionKDF_AES256		"ecka-dh-SessionKDF-AES256"
  ------------------
                      obj = OBJ_create(ASC_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	, SN_ecka_dh_SessionKDF_AES256	);
  ------------------
  |  |  357|      1|#define SN_ecka_dh_SessionKDF_AES256		"ecka-dh-SessionKDF-AES256"
  ------------------
  661|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (661:9): [True: 1, False: 0]
  ------------------
  662|      1|        NID_ecka_dh_SessionKDF_AES256 = obj;
  663|       |
  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  665|       |
  666|      1|#define ASC_id_IS		ASC_id_roles".1"
  667|      1|    obj = OBJ_txt2nid(ASC_id_IS);
  ------------------
  |  |  666|      1|#define ASC_id_IS		ASC_id_roles".1"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  668|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (668:9): [True: 1, False: 0]
  ------------------
  669|      1|        obj = OBJ_create(ASC_id_IS	, SN_id_IS	, SN_id_IS	);
  ------------------
  |  |  666|      1|#define ASC_id_IS		ASC_id_roles".1"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_IS	, SN_id_IS	, SN_id_IS	);
  ------------------
  |  |  363|      1|#define SN_id_IS		"id-IS"
  ------------------
                      obj = OBJ_create(ASC_id_IS	, SN_id_IS	, SN_id_IS	);
  ------------------
  |  |  363|      1|#define SN_id_IS		"id-IS"
  ------------------
  670|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (670:9): [True: 1, False: 0]
  ------------------
  671|      1|        NID_id_IS = obj;
  672|       |
  673|      1|#define ASC_id_AT		ASC_id_roles".2"
  674|      1|    obj = OBJ_txt2nid(ASC_id_AT);
  ------------------
  |  |  673|      1|#define ASC_id_AT		ASC_id_roles".2"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  675|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (675:9): [True: 1, False: 0]
  ------------------
  676|      1|        obj = OBJ_create(ASC_id_AT	, SN_id_AT	, SN_id_AT	);
  ------------------
  |  |  673|      1|#define ASC_id_AT		ASC_id_roles".2"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_AT	, SN_id_AT	, SN_id_AT	);
  ------------------
  |  |  367|      1|#define SN_id_AT		"id-AT"
  ------------------
                      obj = OBJ_create(ASC_id_AT	, SN_id_AT	, SN_id_AT	);
  ------------------
  |  |  367|      1|#define SN_id_AT		"id-AT"
  ------------------
  677|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (677:9): [True: 1, False: 0]
  ------------------
  678|      1|        NID_id_AT = obj;
  679|       |
  680|      1|#define ASC_id_ST		ASC_id_roles".3"
  681|      1|    obj = OBJ_txt2nid(ASC_id_ST);
  ------------------
  |  |  680|      1|#define ASC_id_ST		ASC_id_roles".3"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (682:9): [True: 1, False: 0]
  ------------------
  683|      1|        obj = OBJ_create(ASC_id_ST	, SN_id_ST	, SN_id_ST	);
  ------------------
  |  |  680|      1|#define ASC_id_ST		ASC_id_roles".3"
  |  |  ------------------
  |  |  |  |  664|      1|#define ASC_id_roles		ASC_bsi_de".3.1.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_ST	, SN_id_ST	, SN_id_ST	);
  ------------------
  |  |  371|      1|#define SN_id_ST		"id-ST"
  ------------------
                      obj = OBJ_create(ASC_id_ST	, SN_id_ST	, SN_id_ST	);
  ------------------
  |  |  371|      1|#define SN_id_ST		"id-ST"
  ------------------
  684|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (684:9): [True: 1, False: 0]
  ------------------
  685|      1|        NID_id_ST = obj;
  686|       |
  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  688|       |
  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  690|      1|    obj = OBJ_txt2nid(ASC_id_description);
  ------------------
  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  ------------------
  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (691:9): [True: 1, False: 0]
  ------------------
  692|      1|        obj = OBJ_create(ASC_id_description	, SN_id_description	, SN_id_description	);
  ------------------
  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  ------------------
  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_description	, SN_id_description	, SN_id_description	);
  ------------------
  |  |  377|      1|#define SN_id_description		"id-description"
  ------------------
                      obj = OBJ_create(ASC_id_description	, SN_id_description	, SN_id_description	);
  ------------------
  |  |  377|      1|#define SN_id_description		"id-description"
  ------------------
  693|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (693:9): [True: 1, False: 0]
  ------------------
  694|      1|        NID_id_description = obj;
  695|       |
  696|      1|#define ASC_id_plainFormat		ASC_id_description".1"
  697|      1|    obj = OBJ_txt2nid(ASC_id_plainFormat);
  ------------------
  |  |  696|      1|#define ASC_id_plainFormat		ASC_id_description".1"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  698|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (698:9): [True: 1, False: 0]
  ------------------
  699|      1|        obj = OBJ_create(ASC_id_plainFormat	, SN_id_plainFormat	, SN_id_plainFormat	);
  ------------------
  |  |  696|      1|#define ASC_id_plainFormat		ASC_id_description".1"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_plainFormat	, SN_id_plainFormat	, SN_id_plainFormat	);
  ------------------
  |  |  381|      1|#define SN_id_plainFormat		"id-plainFormat"
  ------------------
                      obj = OBJ_create(ASC_id_plainFormat	, SN_id_plainFormat	, SN_id_plainFormat	);
  ------------------
  |  |  381|      1|#define SN_id_plainFormat		"id-plainFormat"
  ------------------
  700|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (700:9): [True: 1, False: 0]
  ------------------
  701|      1|        NID_id_plainFormat = obj;
  702|       |
  703|      1|#define ASC_id_htmlFormat		ASC_id_description".2"
  704|      1|    obj = OBJ_txt2nid(ASC_id_htmlFormat);
  ------------------
  |  |  703|      1|#define ASC_id_htmlFormat		ASC_id_description".2"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (705:9): [True: 1, False: 0]
  ------------------
  706|      1|        obj = OBJ_create(ASC_id_htmlFormat	, SN_id_htmlFormat	, SN_id_htmlFormat	);
  ------------------
  |  |  703|      1|#define ASC_id_htmlFormat		ASC_id_description".2"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_htmlFormat	, SN_id_htmlFormat	, SN_id_htmlFormat	);
  ------------------
  |  |  385|      1|#define SN_id_htmlFormat		"id-htmlFormat"
  ------------------
                      obj = OBJ_create(ASC_id_htmlFormat	, SN_id_htmlFormat	, SN_id_htmlFormat	);
  ------------------
  |  |  385|      1|#define SN_id_htmlFormat		"id-htmlFormat"
  ------------------
  707|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (707:9): [True: 1, False: 0]
  ------------------
  708|      1|        NID_id_htmlFormat = obj;
  709|       |
  710|      1|#define ASC_id_pdfFormat		ASC_id_description".3"
  711|      1|    obj = OBJ_txt2nid(ASC_id_pdfFormat);
  ------------------
  |  |  710|      1|#define ASC_id_pdfFormat		ASC_id_description".3"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (712:9): [True: 1, False: 0]
  ------------------
  713|      1|        obj = OBJ_create(ASC_id_pdfFormat	, SN_id_pdfFormat	, SN_id_pdfFormat	);
  ------------------
  |  |  710|      1|#define ASC_id_pdfFormat		ASC_id_description".3"
  |  |  ------------------
  |  |  |  |  689|      1|#define ASC_id_description		ASC_id_extensions".1"
  |  |  |  |  ------------------
  |  |  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_pdfFormat	, SN_id_pdfFormat	, SN_id_pdfFormat	);
  ------------------
  |  |  389|      1|#define SN_id_pdfFormat		"id-pdfFormat"
  ------------------
                      obj = OBJ_create(ASC_id_pdfFormat	, SN_id_pdfFormat	, SN_id_pdfFormat	);
  ------------------
  |  |  389|      1|#define SN_id_pdfFormat		"id-pdfFormat"
  ------------------
  714|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (714:9): [True: 1, False: 0]
  ------------------
  715|      1|        NID_id_pdfFormat = obj;
  716|       |
  717|      1|#define ASC_id_sector		ASC_id_extensions".2"
  718|      1|    obj = OBJ_txt2nid(ASC_id_sector);
  ------------------
  |  |  717|      1|#define ASC_id_sector		ASC_id_extensions".2"
  |  |  ------------------
  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  719|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (719:9): [True: 1, False: 0]
  ------------------
  720|      1|        obj = OBJ_create(ASC_id_sector	, SN_id_sector	, SN_id_sector	);
  ------------------
  |  |  717|      1|#define ASC_id_sector		ASC_id_extensions".2"
  |  |  ------------------
  |  |  |  |  687|      1|#define ASC_id_extensions		ASC_bsi_de".3.1.3"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_sector	, SN_id_sector	, SN_id_sector	);
  ------------------
  |  |  393|      1|#define SN_id_sector		"id-sector"
  ------------------
                      obj = OBJ_create(ASC_id_sector	, SN_id_sector	, SN_id_sector	);
  ------------------
  |  |  393|      1|#define SN_id_sector		"id-sector"
  ------------------
  721|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (721:9): [True: 1, False: 0]
  ------------------
  722|      1|        NID_id_sector = obj;
  723|       |
  724|      1|#define ASC_id_eID		ASC_bsi_de".3.2"
  725|       |
  726|      1|#define ASC_id_SecurityObject		ASC_id_eID".1"
  727|      1|    obj = OBJ_txt2nid(ASC_id_SecurityObject);
  ------------------
  |  |  726|      1|#define ASC_id_SecurityObject		ASC_id_eID".1"
  |  |  ------------------
  |  |  |  |  724|      1|#define ASC_id_eID		ASC_bsi_de".3.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  728|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (728:9): [True: 1, False: 0]
  ------------------
  729|      1|        obj = OBJ_create(ASC_id_SecurityObject	, SN_id_SecurityObject	, SN_id_SecurityObject	);
  ------------------
  |  |  726|      1|#define ASC_id_SecurityObject		ASC_id_eID".1"
  |  |  ------------------
  |  |  |  |  724|      1|#define ASC_id_eID		ASC_bsi_de".3.2"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_SecurityObject	, SN_id_SecurityObject	, SN_id_SecurityObject	);
  ------------------
  |  |  399|      1|#define SN_id_SecurityObject		"id-SecurityObject"
  ------------------
                      obj = OBJ_create(ASC_id_SecurityObject	, SN_id_SecurityObject	, SN_id_SecurityObject	);
  ------------------
  |  |  399|      1|#define SN_id_SecurityObject		"id-SecurityObject"
  ------------------
  730|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (730:9): [True: 1, False: 0]
  ------------------
  731|      1|        NID_id_SecurityObject = obj;
  732|       |
  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  734|       |
  735|      1|#define ASC_id_DateOfBirth		ASC_id_AuxiliaryData".1"
  736|      1|    obj = OBJ_txt2nid(ASC_id_DateOfBirth);
  ------------------
  |  |  735|      1|#define ASC_id_DateOfBirth		ASC_id_AuxiliaryData".1"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (737:9): [True: 1, False: 0]
  ------------------
  738|      1|        obj = OBJ_create(ASC_id_DateOfBirth	, SN_id_DateOfBirth	, SN_id_DateOfBirth	);
  ------------------
  |  |  735|      1|#define ASC_id_DateOfBirth		ASC_id_AuxiliaryData".1"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_DateOfBirth	, SN_id_DateOfBirth	, SN_id_DateOfBirth	);
  ------------------
  |  |  405|      1|#define SN_id_DateOfBirth		"id-DateOfBirth"
  ------------------
                      obj = OBJ_create(ASC_id_DateOfBirth	, SN_id_DateOfBirth	, SN_id_DateOfBirth	);
  ------------------
  |  |  405|      1|#define SN_id_DateOfBirth		"id-DateOfBirth"
  ------------------
  739|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (739:9): [True: 1, False: 0]
  ------------------
  740|      1|        NID_id_DateOfBirth = obj;
  741|       |
  742|      1|#define ASC_id_DateOfExpiry		ASC_id_AuxiliaryData".2"
  743|      1|    obj = OBJ_txt2nid(ASC_id_DateOfExpiry);
  ------------------
  |  |  742|      1|#define ASC_id_DateOfExpiry		ASC_id_AuxiliaryData".2"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  744|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (744:9): [True: 1, False: 0]
  ------------------
  745|      1|        obj = OBJ_create(ASC_id_DateOfExpiry	, SN_id_DateOfExpiry	, SN_id_DateOfExpiry	);
  ------------------
  |  |  742|      1|#define ASC_id_DateOfExpiry		ASC_id_AuxiliaryData".2"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_DateOfExpiry	, SN_id_DateOfExpiry	, SN_id_DateOfExpiry	);
  ------------------
  |  |  409|      1|#define SN_id_DateOfExpiry		"id-DateOfExpiry"
  ------------------
                      obj = OBJ_create(ASC_id_DateOfExpiry	, SN_id_DateOfExpiry	, SN_id_DateOfExpiry	);
  ------------------
  |  |  409|      1|#define SN_id_DateOfExpiry		"id-DateOfExpiry"
  ------------------
  746|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (746:9): [True: 1, False: 0]
  ------------------
  747|      1|        NID_id_DateOfExpiry = obj;
  748|       |
  749|      1|#define ASC_id_CommunityID		ASC_id_AuxiliaryData".3"
  750|      1|    obj = OBJ_txt2nid(ASC_id_CommunityID);
  ------------------
  |  |  749|      1|#define ASC_id_CommunityID		ASC_id_AuxiliaryData".3"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  751|      1|    if (obj == NID_undef)
  ------------------
  |  Branch (751:9): [True: 1, False: 0]
  ------------------
  752|      1|        obj = OBJ_create(ASC_id_CommunityID	, SN_id_CommunityID	, SN_id_CommunityID	);
  ------------------
  |  |  749|      1|#define ASC_id_CommunityID		ASC_id_AuxiliaryData".3"
  |  |  ------------------
  |  |  |  |  733|      1|#define ASC_id_AuxiliaryData		ASC_bsi_de".3.1.4"
  |  |  |  |  ------------------
  |  |  |  |  |  |  181|      1|#define ASC_bsi_de		"0.4.0.127.0.7"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      obj = OBJ_create(ASC_id_CommunityID	, SN_id_CommunityID	, SN_id_CommunityID	);
  ------------------
  |  |  413|      1|#define SN_id_CommunityID		"id-CommunityID"
  ------------------
                      obj = OBJ_create(ASC_id_CommunityID	, SN_id_CommunityID	, SN_id_CommunityID	);
  ------------------
  |  |  413|      1|#define SN_id_CommunityID		"id-CommunityID"
  ------------------
  753|      1|    if (obj != NID_undef)
  ------------------
  |  Branch (753:9): [True: 1, False: 0]
  ------------------
  754|      1|        NID_id_CommunityID = obj;
  755|       |
  756|      1|    if (NID_undef == NID_standardizedDomainParameters
  ------------------
  |  Branch (756:9): [True: 0, False: 1]
  ------------------
  757|      1|            || NID_undef == NID_id_PK_DH
  ------------------
  |  Branch (757:16): [True: 0, False: 1]
  ------------------
  758|      1|            || NID_undef == NID_id_PK_ECDH
  ------------------
  |  Branch (758:16): [True: 0, False: 1]
  ------------------
  759|      1|            || NID_undef == NID_id_TA
  ------------------
  |  Branch (759:16): [True: 0, False: 1]
  ------------------
  760|      1|            || NID_undef == NID_id_TA_RSA
  ------------------
  |  Branch (760:16): [True: 0, False: 1]
  ------------------
  761|      1|            || NID_undef == NID_id_TA_RSA_v1_5_SHA_1
  ------------------
  |  Branch (761:16): [True: 0, False: 1]
  ------------------
  762|      1|            || NID_undef == NID_id_TA_RSA_v1_5_SHA_256
  ------------------
  |  Branch (762:16): [True: 0, False: 1]
  ------------------
  763|      1|            || NID_undef == NID_id_TA_RSA_PSS_SHA_1
  ------------------
  |  Branch (763:16): [True: 0, False: 1]
  ------------------
  764|      1|            || NID_undef == NID_id_TA_RSA_PSS_SHA_256
  ------------------
  |  Branch (764:16): [True: 0, False: 1]
  ------------------
  765|      1|            || NID_undef == NID_id_TA_RSA_v1_5_SHA_512
  ------------------
  |  Branch (765:16): [True: 0, False: 1]
  ------------------
  766|      1|            || NID_undef == NID_id_TA_RSA_PSS_SHA_512
  ------------------
  |  Branch (766:16): [True: 0, False: 1]
  ------------------
  767|      1|            || NID_undef == NID_id_TA_ECDSA
  ------------------
  |  Branch (767:16): [True: 0, False: 1]
  ------------------
  768|      1|            || NID_undef == NID_id_TA_ECDSA_SHA_1
  ------------------
  |  Branch (768:16): [True: 0, False: 1]
  ------------------
  769|      1|            || NID_undef == NID_id_TA_ECDSA_SHA_224
  ------------------
  |  Branch (769:16): [True: 0, False: 1]
  ------------------
  770|      1|            || NID_undef == NID_id_TA_ECDSA_SHA_256
  ------------------
  |  Branch (770:16): [True: 0, False: 1]
  ------------------
  771|      1|            || NID_undef == NID_id_TA_ECDSA_SHA_384
  ------------------
  |  Branch (771:16): [True: 0, False: 1]
  ------------------
  772|      1|            || NID_undef == NID_id_TA_ECDSA_SHA_512
  ------------------
  |  Branch (772:16): [True: 0, False: 1]
  ------------------
  773|      1|            || NID_undef == NID_id_CA_DH
  ------------------
  |  Branch (773:16): [True: 0, False: 1]
  ------------------
  774|      1|            || NID_undef == NID_id_CA_DH_3DES_CBC_CBC
  ------------------
  |  Branch (774:16): [True: 0, False: 1]
  ------------------
  775|      1|            || NID_undef == NID_id_CA_DH_AES_CBC_CMAC_128
  ------------------
  |  Branch (775:16): [True: 0, False: 1]
  ------------------
  776|      1|            || NID_undef == NID_id_CA_DH_AES_CBC_CMAC_192
  ------------------
  |  Branch (776:16): [True: 0, False: 1]
  ------------------
  777|      1|            || NID_undef == NID_id_CA_DH_AES_CBC_CMAC_256
  ------------------
  |  Branch (777:16): [True: 0, False: 1]
  ------------------
  778|      1|            || NID_undef == NID_id_CA_ECDH
  ------------------
  |  Branch (778:16): [True: 0, False: 1]
  ------------------
  779|      1|            || NID_undef == NID_id_CA_ECDH_3DES_CBC_CBC
  ------------------
  |  Branch (779:16): [True: 0, False: 1]
  ------------------
  780|      1|            || NID_undef == NID_id_CA_ECDH_AES_CBC_CMAC_128
  ------------------
  |  Branch (780:16): [True: 0, False: 1]
  ------------------
  781|      1|            || NID_undef == NID_id_CA_ECDH_AES_CBC_CMAC_192
  ------------------
  |  Branch (781:16): [True: 0, False: 1]
  ------------------
  782|      1|            || NID_undef == NID_id_CA_ECDH_AES_CBC_CMAC_256
  ------------------
  |  Branch (782:16): [True: 0, False: 1]
  ------------------
  783|      1|            || NID_undef == NID_id_PACE_DH_GM
  ------------------
  |  Branch (783:16): [True: 0, False: 1]
  ------------------
  784|      1|            || NID_undef == NID_id_PACE_DH_GM_3DES_CBC_CBC
  ------------------
  |  Branch (784:16): [True: 0, False: 1]
  ------------------
  785|      1|            || NID_undef == NID_id_PACE_DH_GM_AES_CBC_CMAC_128
  ------------------
  |  Branch (785:16): [True: 0, False: 1]
  ------------------
  786|      1|            || NID_undef == NID_id_PACE_DH_GM_AES_CBC_CMAC_192
  ------------------
  |  Branch (786:16): [True: 0, False: 1]
  ------------------
  787|      1|            || NID_undef == NID_id_PACE_DH_GM_AES_CBC_CMAC_256
  ------------------
  |  Branch (787:16): [True: 0, False: 1]
  ------------------
  788|      1|            || NID_undef == NID_id_PACE_ECDH_GM
  ------------------
  |  Branch (788:16): [True: 0, False: 1]
  ------------------
  789|      1|            || NID_undef == NID_id_PACE_ECDH_GM_3DES_CBC_CBC
  ------------------
  |  Branch (789:16): [True: 0, False: 1]
  ------------------
  790|      1|            || NID_undef == NID_id_PACE_ECDH_GM_AES_CBC_CMAC_128
  ------------------
  |  Branch (790:16): [True: 0, False: 1]
  ------------------
  791|      1|            || NID_undef == NID_id_PACE_ECDH_GM_AES_CBC_CMAC_192
  ------------------
  |  Branch (791:16): [True: 0, False: 1]
  ------------------
  792|      1|            || NID_undef == NID_id_PACE_ECDH_GM_AES_CBC_CMAC_256
  ------------------
  |  Branch (792:16): [True: 0, False: 1]
  ------------------
  793|      1|            || NID_undef == NID_id_PACE_DH_IM
  ------------------
  |  Branch (793:16): [True: 0, False: 1]
  ------------------
  794|      1|            || NID_undef == NID_id_PACE_DH_IM_3DES_CBC_CBC
  ------------------
  |  Branch (794:16): [True: 0, False: 1]
  ------------------
  795|      1|            || NID_undef == NID_id_PACE_DH_IM_AES_CBC_CMAC_128
  ------------------
  |  Branch (795:16): [True: 0, False: 1]
  ------------------
  796|      1|            || NID_undef == NID_id_PACE_DH_IM_AES_CBC_CMAC_192
  ------------------
  |  Branch (796:16): [True: 0, False: 1]
  ------------------
  797|      1|            || NID_undef == NID_id_PACE_DH_IM_AES_CBC_CMAC_256
  ------------------
  |  Branch (797:16): [True: 0, False: 1]
  ------------------
  798|      1|            || NID_undef == NID_id_PACE_ECDH_IM
  ------------------
  |  Branch (798:16): [True: 0, False: 1]
  ------------------
  799|      1|            || NID_undef == NID_id_PACE_ECDH_IM_3DES_CBC_CBC
  ------------------
  |  Branch (799:16): [True: 0, False: 1]
  ------------------
  800|      1|            || NID_undef == NID_id_PACE_ECDH_IM_AES_CBC_CMAC_128
  ------------------
  |  Branch (800:16): [True: 0, False: 1]
  ------------------
  801|      1|            || NID_undef == NID_id_PACE_ECDH_IM_AES_CBC_CMAC_192
  ------------------
  |  Branch (801:16): [True: 0, False: 1]
  ------------------
  802|      1|            || NID_undef == NID_id_PACE_ECDH_IM_AES_CBC_CMAC_256
  ------------------
  |  Branch (802:16): [True: 0, False: 1]
  ------------------
  803|      1|            || NID_undef == NID_id_RI_DH
  ------------------
  |  Branch (803:16): [True: 0, False: 1]
  ------------------
  804|      1|            || NID_undef == NID_id_RI_DH_SHA_1
  ------------------
  |  Branch (804:16): [True: 0, False: 1]
  ------------------
  805|      1|            || NID_undef == NID_id_RI_DH_SHA_224
  ------------------
  |  Branch (805:16): [True: 0, False: 1]
  ------------------
  806|      1|            || NID_undef == NID_id_RI_DH_SHA_256
  ------------------
  |  Branch (806:16): [True: 0, False: 1]
  ------------------
  807|      1|            || NID_undef == NID_id_RI_DH_SHA_384
  ------------------
  |  Branch (807:16): [True: 0, False: 1]
  ------------------
  808|      1|            || NID_undef == NID_id_RI_DH_SHA_512
  ------------------
  |  Branch (808:16): [True: 0, False: 1]
  ------------------
  809|      1|            || NID_undef == NID_id_RI_ECDH
  ------------------
  |  Branch (809:16): [True: 0, False: 1]
  ------------------
  810|      1|            || NID_undef == NID_id_RI_ECDH_SHA_1
  ------------------
  |  Branch (810:16): [True: 0, False: 1]
  ------------------
  811|      1|            || NID_undef == NID_id_RI_ECDH_SHA_224
  ------------------
  |  Branch (811:16): [True: 0, False: 1]
  ------------------
  812|      1|            || NID_undef == NID_id_RI_ECDH_SHA_256
  ------------------
  |  Branch (812:16): [True: 0, False: 1]
  ------------------
  813|      1|            || NID_undef == NID_id_RI_ECDH_SHA_384
  ------------------
  |  Branch (813:16): [True: 0, False: 1]
  ------------------
  814|      1|            || NID_undef == NID_id_RI_ECDH_SHA_512
  ------------------
  |  Branch (814:16): [True: 0, False: 1]
  ------------------
  815|      1|            || NID_undef == NID_id_CI
  ------------------
  |  Branch (815:16): [True: 0, False: 1]
  ------------------
  816|      1|            || NID_undef == NID_id_eIDSecurity
  ------------------
  |  Branch (816:16): [True: 0, False: 1]
  ------------------
  817|      1|            || NID_undef == NID_id_PT
  ------------------
  |  Branch (817:16): [True: 0, False: 1]
  ------------------
  818|      1|            || NID_undef == NID_ecka_dh_SessionKDF
  ------------------
  |  Branch (818:16): [True: 0, False: 1]
  ------------------
  819|      1|            || NID_undef == NID_ecka_dh_SessionKDF_DES3
  ------------------
  |  Branch (819:16): [True: 0, False: 1]
  ------------------
  820|      1|            || NID_undef == NID_ecka_dh_SessionKDF_AES128
  ------------------
  |  Branch (820:16): [True: 0, False: 1]
  ------------------
  821|      1|            || NID_undef == NID_ecka_dh_SessionKDF_AES192
  ------------------
  |  Branch (821:16): [True: 0, False: 1]
  ------------------
  822|      1|            || NID_undef == NID_ecka_dh_SessionKDF_AES256
  ------------------
  |  Branch (822:16): [True: 0, False: 1]
  ------------------
  823|      1|            || NID_undef == NID_id_IS
  ------------------
  |  Branch (823:16): [True: 0, False: 1]
  ------------------
  824|      1|            || NID_undef == NID_id_AT
  ------------------
  |  Branch (824:16): [True: 0, False: 1]
  ------------------
  825|      1|            || NID_undef == NID_id_ST
  ------------------
  |  Branch (825:16): [True: 0, False: 1]
  ------------------
  826|      1|            || NID_undef == NID_id_description
  ------------------
  |  Branch (826:16): [True: 0, False: 1]
  ------------------
  827|      1|            || NID_undef == NID_id_plainFormat
  ------------------
  |  Branch (827:16): [True: 0, False: 1]
  ------------------
  828|      1|            || NID_undef == NID_id_htmlFormat
  ------------------
  |  Branch (828:16): [True: 0, False: 1]
  ------------------
  829|      1|            || NID_undef == NID_id_pdfFormat
  ------------------
  |  Branch (829:16): [True: 0, False: 1]
  ------------------
  830|      1|            || NID_undef == NID_id_sector
  ------------------
  |  Branch (830:16): [True: 0, False: 1]
  ------------------
  831|      1|            || NID_undef == NID_id_SecurityObject
  ------------------
  |  Branch (831:16): [True: 0, False: 1]
  ------------------
  832|      1|            || NID_undef == NID_id_DateOfBirth
  ------------------
  |  Branch (832:16): [True: 0, False: 1]
  ------------------
  833|      1|            || NID_undef == NID_id_DateOfExpiry
  ------------------
  |  Branch (833:16): [True: 0, False: 1]
  ------------------
  834|      1|            || NID_undef == NID_id_CommunityID) {
  ------------------
  |  Branch (834:16): [True: 0, False: 1]
  ------------------
  835|      0|        log_err("Error adding objects");
  ------------------
  |  |   61|      0|#define log_err(M, ...) {fprintf(stderr, "[ERROR] (%s:%d ) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__); ossl_errors();}
  |  |  ------------------
  |  |  |  |   60|      0|#define ossl_errors() ERR_print_errors_fp(stderr)
  |  |  ------------------
  ------------------
  836|      0|    }
  837|       |
  838|      1|    objects_initialized = 1;
  839|      1|}

EAC_set_x509_default_dir:
   63|    119|{
   64|    119|    if (default_dir) {
  ------------------
  |  Branch (64:9): [True: 119, False: 0]
  ------------------
   65|    119|        strncpy(x509_default_dir, default_dir, (sizeof x509_default_dir) - 1);
   66|    119|        x509_default_dir[(sizeof x509_default_dir) - 1] = '\0';
   67|    119|    }
   68|    119|}

strlcat:
   49|   946k|{
   50|   946k|	char *d = dst;
   51|   946k|	const char *s = src;
   52|   946k|	size_t n = siz;
   53|   946k|	size_t dlen;
   54|       |
   55|       |	/* Find the end of dst and adjust bytes left but don't go past end */
   56|   950k|	while (n-- != 0 && *d != '\0')
  ------------------
  |  Branch (56:9): [True: 950k, False: 0]
  |  Branch (56:21): [True: 4.13k, False: 946k]
  ------------------
   57|  4.13k|		d++;
   58|   946k|	dlen = d - dst;
   59|   946k|	n = siz - dlen;
   60|       |
   61|   946k|	if (n == 0)
  ------------------
  |  Branch (61:6): [True: 0, False: 946k]
  ------------------
   62|      0|		return(dlen + strlen(s));
   63|  3.78M|	while (*s != '\0') {
  ------------------
  |  Branch (63:9): [True: 2.84M, False: 946k]
  ------------------
   64|  2.84M|		if (n != 1) {
  ------------------
  |  Branch (64:7): [True: 2.84M, False: 0]
  ------------------
   65|  2.84M|			*d++ = *s;
   66|  2.84M|			n--;
   67|  2.84M|		}
   68|  2.84M|		s++;
   69|  2.84M|	}
   70|   946k|	*d = '\0';
   71|       |
   72|   946k|	return(dlen + (s - src));	/* count does not include NUL */
   73|   946k|}

_strlcpy:
   36|  12.4k|{
   37|  12.4k|	char *d = dst;
   38|  12.4k|	const char *s = src;
   39|  12.4k|	size_t n = siz;
   40|       |
   41|       |	/* Copy as many bytes as will fit */
   42|  12.4k|	if (n != 0) {
  ------------------
  |  Branch (42:6): [True: 12.4k, False: 0]
  ------------------
   43|   173k|		while (--n != 0) {
  ------------------
  |  Branch (43:10): [True: 173k, False: 0]
  ------------------
   44|   173k|			if ((*d++ = *s++) == '\0')
  ------------------
  |  Branch (44:8): [True: 12.4k, False: 160k]
  ------------------
   45|  12.4k|				break;
   46|   173k|		}
   47|  12.4k|	}
   48|       |
   49|       |	/* Not enough room in dst, add NUL and traverse rest of src */
   50|  12.4k|	if (n == 0) {
  ------------------
  |  Branch (50:6): [True: 0, False: 12.4k]
  ------------------
   51|      0|		if (siz != 0)
  ------------------
  |  Branch (51:7): [True: 0, False: 0]
  ------------------
   52|      0|			*d = '\0';		/* NUL-terminate dst */
   53|      0|		while (*s++)
  ------------------
  |  Branch (53:10): [True: 0, False: 0]
  ------------------
   54|      0|			;
   55|      0|	}
   56|       |
   57|  12.4k|	return(s - src - 1);	/* count does not include NUL */
   58|  12.4k|}

padding.c:constant_time_is_zero:
   85|  17.4k|{
   86|  17.4k|	return constant_time_msb(~a & (a - 1));
   87|  17.4k|}
padding.c:constant_time_msb:
   59|  19.4k|{
   60|  19.4k|	return 0 - (a >> (sizeof(a) * 8 - 1));
   61|  19.4k|}
padding.c:constant_time_eq:
  118|    312|{
  119|    312|	return constant_time_is_zero(a ^ b);
  120|    312|}
padding.c:constant_time_select:
   66|  69.1k|{
   67|  69.1k|	return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
   68|  69.1k|}
padding.c:value_barrier:
   38|   138k|{
   39|   138k|	volatile unsigned int r = a;
   40|   138k|	return r;
   41|   138k|}
padding.c:constant_time_ge:
  110|     70|{
  111|     70|	return ~constant_time_lt(a, b);
  112|     70|}
padding.c:constant_time_lt:
  104|  2.06k|{
  105|  2.06k|	return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
  106|  2.06k|}
padding.c:constant_time_select_8:
   72|  58.5k|{
   73|  58.5k|	return (unsigned char)constant_time_select(mask, a, b);
   74|  58.5k|}

list_init:
  240|  20.3k|int list_init(list_t *simclist_restrict l) {
  241|  20.3k|    if (l == NULL) {
  ------------------
  |  Branch (241:9): [True: 0, False: 20.3k]
  ------------------
  242|      0|        return -1;
  243|      0|    }
  244|       |
  245|  20.3k|    memset(l, 0, sizeof *l);
  246|       |
  247|  20.3k|    seed_random();
  248|       |
  249|  20.3k|    l->numels = 0;
  250|       |
  251|       |    /* head/tail sentinels and mid pointer */
  252|  20.3k|    l->head_sentinel = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  253|  20.3k|    l->tail_sentinel = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  254|  20.3k|    if (l->tail_sentinel == NULL || l->head_sentinel == NULL) {
  ------------------
  |  Branch (254:9): [True: 0, False: 20.3k]
  |  Branch (254:37): [True: 0, False: 20.3k]
  ------------------
  255|      0|        return -1;
  256|      0|    }
  257|  20.3k|    l->head_sentinel->next = l->tail_sentinel;
  258|  20.3k|    l->tail_sentinel->prev = l->head_sentinel;
  259|  20.3k|    l->head_sentinel->prev = l->tail_sentinel->next = l->mid = NULL;
  260|  20.3k|    l->head_sentinel->data = l->tail_sentinel->data = NULL;
  261|       |
  262|       |    /* iteration attributes */
  263|  20.3k|    l->iter_active = 0;
  264|  20.3k|    l->iter_pos = 0;
  265|  20.3k|    l->iter_curentry = NULL;
  266|       |
  267|       |    /* free-list attributes */
  268|  20.3k|    l->spareelsnum = 0;
  269|  20.3k|    l->spareels = (struct list_entry_s **)malloc(SIMCLIST_MAX_SPARE_ELEMS * sizeof(struct list_entry_s *));
  ------------------
  |  |  115|  20.3k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  270|  20.3k|    if (l->spareels == NULL) {
  ------------------
  |  Branch (270:9): [True: 0, False: 20.3k]
  ------------------
  271|      0|        return -1;
  272|      0|    }
  273|       |
  274|       |#ifdef SIMCLIST_WITH_THREADS
  275|       |    l->threadcount = 0;
  276|       |#endif
  277|       |
  278|  20.3k|    if (0 != list_attributes_setdefaults(l)) {
  ------------------
  |  Branch (278:9): [True: 0, False: 20.3k]
  ------------------
  279|      0|        return -1;
  280|      0|    }
  281|       |
  282|  20.3k|    assert(list_repOk(l));
  283|  20.3k|    assert(list_attrOk(l));
  284|       |
  285|  20.3k|    return 0;
  286|  20.3k|}
list_destroy:
  288|  20.3k|void list_destroy(list_t *simclist_restrict l) {
  289|  20.3k|    unsigned int i;
  290|       |
  291|  20.3k|    list_clear(l);
  292|  41.1k|    for (i = 0; i < l->spareelsnum; i++) {
  ------------------
  |  Branch (292:17): [True: 20.7k, False: 20.3k]
  ------------------
  293|  20.7k|        free(l->spareels[i]);
  294|  20.7k|    }
  295|  20.3k|    free(l->spareels);
  296|  20.3k|    free(l->head_sentinel);
  297|  20.3k|    free(l->tail_sentinel);
  298|  20.3k|}
list_attributes_comparator:
  320|  3.46k|int list_attributes_comparator(list_t *simclist_restrict l, element_comparator comparator_fun) {
  321|  3.46k|    if (l == NULL) return -1;
  ------------------
  |  Branch (321:9): [True: 0, False: 3.46k]
  ------------------
  322|       |
  323|  3.46k|    l->attrs.comparator = comparator_fun;
  324|       |
  325|  3.46k|    assert(list_attrOk(l));
  326|       |
  327|  3.46k|    return 0;
  328|  3.46k|}
list_attributes_seeker:
  330|  16.3k|int list_attributes_seeker(list_t *simclist_restrict l, element_seeker seeker_fun) {
  331|  16.3k|    if (l == NULL) return -1;
  ------------------
  |  Branch (331:9): [True: 0, False: 16.3k]
  ------------------
  332|       |
  333|  16.3k|    l->attrs.seeker = seeker_fun;
  334|  16.3k|    assert(list_attrOk(l));
  335|       |
  336|  16.3k|    return 0;
  337|  16.3k|}
list_attributes_copy:
  339|  5.07k|int list_attributes_copy(list_t *simclist_restrict l, element_meter metric_fun, int copy_data) {
  340|  5.07k|    if (l == NULL || (metric_fun == NULL && copy_data != 0)) return -1;
  ------------------
  |  Branch (340:9): [True: 0, False: 5.07k]
  |  Branch (340:23): [True: 0, False: 5.07k]
  |  Branch (340:45): [True: 0, False: 0]
  ------------------
  341|       |
  342|  5.07k|    l->attrs.meter = metric_fun;
  343|  5.07k|    l->attrs.copy_data = copy_data;
  344|       |
  345|  5.07k|    assert(list_attrOk(l));
  346|       |
  347|  5.07k|    return 0;
  348|  5.07k|}
list_append:
  374|  38.0k|int list_append(list_t *simclist_restrict l, const void *data) {
  375|  38.0k|    return list_insert_at(l, data, l->numels);
  376|  38.0k|}
list_get_at:
  386|  35.6k|void *list_get_at(const list_t *simclist_restrict l, unsigned int pos) {
  387|  35.6k|    struct list_entry_s *tmp;
  388|       |
  389|  35.6k|    tmp = list_findpos(l, pos);
  390|       |
  391|  35.6k|    return (tmp != NULL ? tmp->data : NULL);
  ------------------
  |  Branch (391:13): [True: 35.6k, False: 0]
  ------------------
  392|  35.6k|}
list_insert_at:
  470|  38.0k|int list_insert_at(list_t *simclist_restrict l, const void *data, unsigned int pos) {
  471|  38.0k|    struct list_entry_s *lent, *succ, *prec;
  472|       |
  473|  38.0k|    if (l->iter_active || pos > l->numels) return -1;
  ------------------
  |  Branch (473:9): [True: 0, False: 38.0k]
  |  Branch (473:27): [True: 0, False: 38.0k]
  ------------------
  474|       |
  475|       |    /* this code optimizes malloc() with a free-list */
  476|  38.0k|    if (l->spareelsnum > 0) {
  ------------------
  |  Branch (476:9): [True: 0, False: 38.0k]
  ------------------
  477|      0|        lent = l->spareels[l->spareelsnum-1];
  478|      0|        l->spareelsnum--;
  479|  38.0k|    } else {
  480|  38.0k|        lent = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  481|  38.0k|        if (lent == NULL) {
  ------------------
  |  Branch (481:13): [True: 0, False: 38.0k]
  ------------------
  482|      0|            return -1;
  483|      0|        }
  484|  38.0k|    }
  485|       |
  486|  38.0k|    if (l->attrs.copy_data) {
  ------------------
  |  Branch (486:9): [True: 22.7k, False: 15.2k]
  ------------------
  487|       |        /* make room for user' data (has to be copied) */
  488|  22.7k|        size_t datalen = l->attrs.meter(data);
  489|  22.7k|        lent->data = (struct list_entry_s *)malloc(datalen);
  490|  22.7k|        if (lent->data == NULL) {
  ------------------
  |  Branch (490:13): [True: 0, False: 22.7k]
  ------------------
  491|      0|            if (!(l->spareelsnum > 0)) {
  ------------------
  |  Branch (491:17): [True: 0, False: 0]
  ------------------
  492|      0|                free(lent);
  493|      0|            }
  494|      0|            return -1;
  495|      0|        }
  496|  22.7k|        memcpy(lent->data, data, datalen);
  497|  22.7k|    } else {
  498|  15.2k|        lent->data = (void*)data;
  499|  15.2k|    }
  500|       |
  501|       |    /* actually append element */
  502|  38.0k|    prec = list_findpos(l, pos-1);
  503|  38.0k|    if (prec == NULL) {
  ------------------
  |  Branch (503:9): [True: 0, False: 38.0k]
  ------------------
  504|      0|        if (l->attrs.copy_data) {
  ------------------
  |  Branch (504:13): [True: 0, False: 0]
  ------------------
  505|      0|            free(lent->data);
  506|      0|        }
  507|      0|        if (!(l->spareelsnum > 0)) {
  ------------------
  |  Branch (507:13): [True: 0, False: 0]
  ------------------
  508|      0|            free(lent);
  509|      0|        }
  510|      0|        return -1;
  511|      0|    }
  512|  38.0k|    succ = prec->next;
  513|       |
  514|  38.0k|    prec->next = lent;
  515|  38.0k|    lent->prev = prec;
  516|  38.0k|    lent->next = succ;
  517|  38.0k|    succ->prev = lent;
  518|       |
  519|  38.0k|    l->numels++;
  520|       |
  521|       |    /* fix mid pointer */
  522|  38.0k|    if (l->numels == 1) { /* first element, set pointer */
  ------------------
  |  Branch (522:9): [True: 17.1k, False: 20.8k]
  ------------------
  523|  17.1k|        l->mid = lent;
  524|  20.8k|    } else if (l->numels % 2) {    /* now odd */
  ------------------
  |  Branch (524:16): [True: 10.0k, False: 10.7k]
  ------------------
  525|  10.0k|        if (pos >= (l->numels-1)/2) l->mid = l->mid->next;
  ------------------
  |  Branch (525:13): [True: 10.0k, False: 0]
  ------------------
  526|  10.7k|    } else {                /* now even */
  527|  10.7k|        if (pos <= (l->numels-1)/2) l->mid = l->mid->prev;
  ------------------
  |  Branch (527:13): [True: 0, False: 10.7k]
  ------------------
  528|  10.7k|    }
  529|       |
  530|  38.0k|    assert(list_repOk(l));
  531|       |
  532|  38.0k|    return 1;
  533|  38.0k|}
list_delete:
  535|  15.2k|int list_delete(list_t *simclist_restrict l, const void *data) {
  536|  15.2k|	int pos, r;
  537|       |
  538|  15.2k|	pos = list_locate(l, data);
  539|  15.2k|	if (pos < 0)
  ------------------
  |  Branch (539:6): [True: 0, False: 15.2k]
  ------------------
  540|      0|		return -1;
  541|       |
  542|  15.2k|	r = list_delete_at(l, pos);
  543|  15.2k|	if (r < 0)
  ------------------
  |  Branch (543:6): [True: 0, False: 15.2k]
  ------------------
  544|      0|		return -1;
  545|       |
  546|  15.2k|    assert(list_repOk(l));
  547|       |
  548|  15.2k|	return 0;
  549|  15.2k|}
list_delete_at:
  551|  15.2k|int list_delete_at(list_t *simclist_restrict l, unsigned int pos) {
  552|  15.2k|    struct list_entry_s *delendo;
  553|       |
  554|       |
  555|  15.2k|    if (l->iter_active || pos >= l->numels) return -1;
  ------------------
  |  Branch (555:9): [True: 0, False: 15.2k]
  |  Branch (555:27): [True: 0, False: 15.2k]
  ------------------
  556|       |
  557|  15.2k|    delendo = list_findpos(l, pos);
  558|       |
  559|  15.2k|    list_drop_elem(l, delendo, pos);
  560|       |
  561|  15.2k|    l->numels--;
  562|       |
  563|       |
  564|  15.2k|    assert(list_repOk(l));
  565|       |
  566|  15.2k|    return  0;
  567|  15.2k|}
list_clear:
  634|  20.3k|int list_clear(list_t *simclist_restrict l) {
  635|  20.3k|    struct list_entry_s *s;
  636|       |
  637|  20.3k|    if (l->iter_active) return -1;
  ------------------
  |  Branch (637:9): [True: 0, False: 20.3k]
  ------------------
  638|       |
  639|  20.3k|    if (l->head_sentinel && l->tail_sentinel) {
  ------------------
  |  Branch (639:9): [True: 20.3k, False: 0]
  |  Branch (639:29): [True: 20.3k, False: 0]
  ------------------
  640|  20.3k|        if (l->attrs.copy_data) {        /* also free user data */
  ------------------
  |  Branch (640:13): [True: 5.07k, False: 15.2k]
  ------------------
  641|       |            /* spare a loop conditional with two loops: spareing elems and freeing elems */
  642|  10.6k|            for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
  ------------------
  |  |  115|  21.2k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (642:46): [True: 9.96k, False: 641]
  |  Branch (642:91): [True: 5.53k, False: 4.43k]
  ------------------
  643|       |                /* move elements as spares as long as there is room */
  644|  5.53k|                if (s->data != NULL) free(s->data);
  ------------------
  |  Branch (644:21): [True: 5.53k, False: 0]
  ------------------
  645|  5.53k|                l->spareels[l->spareelsnum++] = s;
  646|  5.53k|            }
  647|  22.2k|            while (s != l->tail_sentinel) {
  ------------------
  |  Branch (647:20): [True: 17.2k, False: 5.07k]
  ------------------
  648|       |                /* free the remaining elems */
  649|  17.2k|                if (s->data != NULL) free(s->data);
  ------------------
  |  Branch (649:21): [True: 17.2k, False: 0]
  ------------------
  650|  17.2k|                s = s->next;
  651|  17.2k|                free(s->prev);
  652|  17.2k|            }
  653|  5.07k|            l->head_sentinel->next = l->tail_sentinel;
  654|  5.07k|            l->tail_sentinel->prev = l->head_sentinel;
  655|  15.2k|        } else { /* only free element containers */
  656|       |            /* spare a loop conditional with two loops: spareing elems and freeing elems */
  657|  15.2k|            for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
  ------------------
  |  |  115|  30.5k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (657:46): [True: 15.2k, False: 0]
  |  Branch (657:91): [True: 0, False: 15.2k]
  ------------------
  658|       |                /* move elements as spares as long as there is room */
  659|      0|                l->spareels[l->spareelsnum++] = s;
  660|      0|            }
  661|  15.2k|            while (s != l->tail_sentinel) {
  ------------------
  |  Branch (661:20): [True: 0, False: 15.2k]
  ------------------
  662|       |                /* free the remaining elems */
  663|      0|                s = s->next;
  664|      0|                free(s->prev);
  665|      0|            }
  666|  15.2k|            l->head_sentinel->next = l->tail_sentinel;
  667|  15.2k|            l->tail_sentinel->prev = l->head_sentinel;
  668|  15.2k|        }
  669|  20.3k|    }
  670|  20.3k|    l->numels = 0;
  671|  20.3k|    l->mid = NULL;
  672|       |
  673|  20.3k|    assert(list_repOk(l));
  674|       |
  675|  20.3k|    return 0;
  676|  20.3k|}
list_size:
  678|  48.5k|unsigned int list_size(const list_t *simclist_restrict l) {
  679|  48.5k|    return l->numels;
  680|  48.5k|}
list_locate:
  686|  35.0k|int list_locate(const list_t *simclist_restrict l, const void *data) {
  687|  35.0k|    struct list_entry_s *el;
  688|  35.0k|    int pos = 0;
  689|       |
  690|  35.0k|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return -1;
  ------------------
  |  Branch (690:9): [True: 0, False: 35.0k]
  |  Branch (690:37): [True: 0, False: 35.0k]
  ------------------
  691|       |
  692|  35.0k|    if (l->attrs.comparator != NULL) {
  ------------------
  |  Branch (692:9): [True: 19.8k, False: 15.2k]
  ------------------
  693|       |        /* use comparator */
  694|   145k|        for (el = l->head_sentinel->next; el != l->tail_sentinel; el = el->next, pos++) {
  ------------------
  |  Branch (694:43): [True: 132k, False: 12.3k]
  ------------------
  695|   132k|            if (l->attrs.comparator(data, el->data) == 0) break;
  ------------------
  |  Branch (695:17): [True: 7.47k, False: 125k]
  ------------------
  696|   132k|        }
  697|  19.8k|    } else {
  698|       |        /* compare references */
  699|  15.2k|        for (el = l->head_sentinel->next; el != l->tail_sentinel; el = el->next, pos++) {
  ------------------
  |  Branch (699:43): [True: 15.2k, False: 0]
  ------------------
  700|  15.2k|            if (el->data == data) break;
  ------------------
  |  Branch (700:17): [True: 15.2k, False: 0]
  ------------------
  701|  15.2k|        }
  702|  15.2k|    }
  703|  35.0k|    if (el == l->tail_sentinel) return -1;
  ------------------
  |  Branch (703:9): [True: 12.3k, False: 22.7k]
  ------------------
  704|       |
  705|  22.7k|    return pos;
  706|  35.0k|}
list_seek:
  708|  2.36k|void *list_seek(list_t *simclist_restrict l, const void *indicator) {
  709|  2.36k|    const struct list_entry_s *iter;
  710|       |
  711|  2.36k|    if (l->attrs.seeker == NULL) return NULL;
  ------------------
  |  Branch (711:9): [True: 0, False: 2.36k]
  ------------------
  712|       |
  713|  2.36k|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return NULL;
  ------------------
  |  Branch (713:9): [True: 0, False: 2.36k]
  |  Branch (713:37): [True: 0, False: 2.36k]
  ------------------
  714|       |
  715|  3.63k|    for (iter = l->head_sentinel->next; iter != l->tail_sentinel; iter = iter->next) {
  ------------------
  |  Branch (715:41): [True: 2.47k, False: 1.16k]
  ------------------
  716|  2.47k|        if (l->attrs.seeker(iter->data, indicator) != 0) return iter->data;
  ------------------
  |  Branch (716:13): [True: 1.20k, False: 1.26k]
  ------------------
  717|  2.47k|    }
  718|       |
  719|  1.16k|    return NULL;
  720|  2.36k|}
list_contains:
  722|  9.25k|int list_contains(const list_t *simclist_restrict l, const void *data) {
  723|  9.25k|    return (list_locate(l, data) >= 0);
  724|  9.25k|}
list_iterator_start:
  967|  6.48k|int list_iterator_start(list_t *simclist_restrict l) {
  968|  6.48k|    if (l->iter_active) return 0;
  ------------------
  |  Branch (968:9): [True: 0, False: 6.48k]
  ------------------
  969|  6.48k|    if (l->head_sentinel == NULL) return -1;
  ------------------
  |  Branch (969:9): [True: 0, False: 6.48k]
  ------------------
  970|  6.48k|    l->iter_pos = 0;
  971|  6.48k|    l->iter_active = 1;
  972|  6.48k|    l->iter_curentry = l->head_sentinel->next;
  973|  6.48k|    return 1;
  974|  6.48k|}
list_iterator_next:
  976|  53.1k|void *list_iterator_next(list_t *simclist_restrict l) {
  977|  53.1k|    void *toret;
  978|       |
  979|  53.1k|    if (! l->iter_active) return NULL;
  ------------------
  |  Branch (979:9): [True: 0, False: 53.1k]
  ------------------
  980|       |
  981|  53.1k|    toret = l->iter_curentry->data;
  982|  53.1k|    l->iter_curentry = l->iter_curentry->next;
  983|  53.1k|    l->iter_pos++;
  984|       |
  985|  53.1k|    return toret;
  986|  53.1k|}
list_iterator_hasnext:
  988|  48.3k|int list_iterator_hasnext(const list_t *simclist_restrict l) {
  989|  48.3k|    if (! l->iter_active) return 0;
  ------------------
  |  Branch (989:9): [True: 0, False: 48.3k]
  ------------------
  990|  48.3k|    return (l->iter_pos < l->numels);
  991|  48.3k|}
list_iterator_stop:
  993|  6.48k|int list_iterator_stop(list_t *simclist_restrict l) {
  994|  6.48k|    if (! l->iter_active) return 0;
  ------------------
  |  Branch (994:9): [True: 0, False: 6.48k]
  ------------------
  995|  6.48k|    l->iter_pos = 0;
  996|  6.48k|    l->iter_active = 0;
  997|  6.48k|    return 1;
  998|  6.48k|}
simclist.c:seed_random:
  217|  20.3k|static simclist_inline void seed_random() {
  218|  20.3k|    if (random_seed == 0) {
  ------------------
  |  Branch (218:9): [True: 1, False: 20.3k]
  ------------------
  219|      1|#ifndef _WIN32
  220|      1|        random_seed = (unsigned)getpid() ^ (unsigned)time(NULL);
  221|       |#else
  222|       |        random_seed = (unsigned)GetCurrentProcessId() ^ (unsigned)time(NULL);
  223|       |#endif
  224|      1|    }
  225|  20.3k|}
simclist.c:list_attributes_setdefaults:
  300|  20.3k|int list_attributes_setdefaults(list_t *simclist_restrict l) {
  301|  20.3k|    l->attrs.comparator = NULL;
  302|  20.3k|    l->attrs.seeker = NULL;
  303|       |
  304|       |    /* also free() element data when removing and element from the list */
  305|  20.3k|    l->attrs.meter = NULL;
  306|  20.3k|    l->attrs.copy_data = 0;
  307|       |
  308|  20.3k|    l->attrs.hasher = NULL;
  309|       |
  310|       |    /* serializer/unserializer */
  311|  20.3k|    l->attrs.serializer = NULL;
  312|  20.3k|    l->attrs.unserializer = NULL;
  313|       |
  314|  20.3k|    assert(list_attrOk(l));
  315|       |
  316|  20.3k|    return 0;
  317|  20.3k|}
simclist.c:list_findpos:
  421|  88.8k|static simclist_inline struct list_entry_s *list_findpos(const list_t *simclist_restrict l, int posstart) {
  422|  88.8k|    struct list_entry_s *ptr;
  423|  88.8k|    float x;
  424|  88.8k|    int i;
  425|       |
  426|  88.8k|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return NULL;
  ------------------
  |  Branch (426:9): [True: 0, False: 88.8k]
  |  Branch (426:37): [True: 0, False: 88.8k]
  ------------------
  427|       |
  428|       |    /* accept 1 slot overflow for fetching head and tail sentinels */
  429|  88.8k|    if (posstart < -1 || posstart > (int)l->numels) return NULL;
  ------------------
  |  Branch (429:9): [True: 0, False: 88.8k]
  |  Branch (429:26): [True: 0, False: 88.8k]
  ------------------
  430|       |
  431|  88.8k|    x = l->numels ? (float)(posstart+1) / l->numels : 0;
  ------------------
  |  Branch (431:9): [True: 71.7k, False: 17.1k]
  ------------------
  432|  88.8k|    if (x <= 0.25) {
  ------------------
  |  Branch (432:9): [True: 18.1k, False: 70.7k]
  ------------------
  433|       |        /* first quarter: get to posstart from head */
  434|  20.5k|        for (i = -1, ptr = l->head_sentinel; i < posstart; ptr = ptr->next, i++);
  ------------------
  |  Branch (434:46): [True: 2.34k, False: 18.1k]
  ------------------
  435|  70.7k|    } else if (x < 0.5) {
  ------------------
  |  Branch (435:16): [True: 989, False: 69.7k]
  ------------------
  436|       |        /* second quarter: get to posstart from mid */
  437|  3.21k|        for (i = (l->numels-1)/2, ptr = l->mid; i > posstart; ptr = ptr->prev, i--);
  ------------------
  |  Branch (437:49): [True: 2.22k, False: 989]
  ------------------
  438|  69.7k|    } else if (x <= 0.75) {
  ------------------
  |  Branch (438:16): [True: 1.99k, False: 67.7k]
  ------------------
  439|       |        /* third quarter: get to posstart from mid */
  440|  4.82k|        for (i = (l->numels-1)/2, ptr = l->mid; i < posstart; ptr = ptr->next, i++);
  ------------------
  |  Branch (440:49): [True: 2.83k, False: 1.99k]
  ------------------
  441|  67.7k|    } else {
  442|       |        /* fourth quarter: get to posstart from tail */
  443|   136k|        for (i = l->numels, ptr = l->tail_sentinel; i > posstart; ptr = ptr->prev, i--);
  ------------------
  |  Branch (443:53): [True: 69.0k, False: 67.7k]
  ------------------
  444|  67.7k|    }
  445|       |
  446|  88.8k|    return ptr;
  447|  88.8k|}
simclist.c:list_drop_elem:
 1432|  15.2k|static int list_drop_elem(list_t *simclist_restrict l, struct list_entry_s *tmp, unsigned int pos) {
 1433|  15.2k|    if (tmp == NULL) return -1;
  ------------------
  |  Branch (1433:9): [True: 0, False: 15.2k]
  ------------------
 1434|       |
 1435|       |    /* fix mid pointer. This is wrt the PRE situation */
 1436|  15.2k|    if (l->numels % 2) {    /* now odd */
  ------------------
  |  Branch (1436:9): [True: 15.2k, False: 0]
  ------------------
 1437|       |        /* sort out the base case by hand */
 1438|  15.2k|        if (l->numels == 1) l->mid = NULL;
  ------------------
  |  Branch (1438:13): [True: 15.2k, False: 0]
  ------------------
 1439|      0|        else if (pos >= l->numels/2) l->mid = l->mid->prev;
  ------------------
  |  Branch (1439:18): [True: 0, False: 0]
  ------------------
 1440|  15.2k|    } else {                /* now even */
 1441|      0|        if (pos < l->numels/2) l->mid = l->mid->next;
  ------------------
  |  Branch (1441:13): [True: 0, False: 0]
  ------------------
 1442|      0|    }
 1443|       |
 1444|  15.2k|    tmp->prev->next = tmp->next;
 1445|  15.2k|    tmp->next->prev = tmp->prev;
 1446|       |
 1447|       |    /* free what's to be freed */
 1448|  15.2k|    if (l->attrs.copy_data && tmp->data != NULL)
  ------------------
  |  Branch (1448:9): [True: 0, False: 15.2k]
  |  Branch (1448:31): [True: 0, False: 0]
  ------------------
 1449|      0|        free(tmp->data);
 1450|       |
 1451|  15.2k|    if (l->spareels != NULL && l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS) {
  ------------------
  |  |  115|  15.2k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (1451:9): [True: 15.2k, False: 0]
  |  Branch (1451:32): [True: 15.2k, False: 0]
  ------------------
 1452|  15.2k|        l->spareels[l->spareelsnum++] = tmp;
 1453|  15.2k|    } else {
 1454|      0|        free(tmp);
 1455|      0|    }
 1456|       |
 1457|  15.2k|    return 0;
 1458|  15.2k|}

sc_apdu_get_length:
   42|  5.18k|{
   43|  5.18k|	size_t ret = 4;
   44|       |
   45|  5.18k|	switch (apdu->cse) {
   46|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (46:2): [True: 0, False: 5.18k]
  ------------------
   47|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (47:7): [True: 0, False: 0]
  ------------------
   48|      0|			ret++;
   49|      0|		break;
   50|  5.18k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  5.18k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (50:2): [True: 5.18k, False: 0]
  ------------------
   51|  5.18k|		ret++;
   52|  5.18k|		break;
   53|      0|	case SC_APDU_CASE_2_EXT:
  ------------------
  |  |  297|      0|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (53:2): [True: 0, False: 5.18k]
  ------------------
   54|      0|		ret += (proto == SC_PROTO_T0 ? 1 : 3);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (54:11): [True: 0, False: 0]
  ------------------
   55|      0|		break;
   56|      0|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (56:2): [True: 0, False: 5.18k]
  ------------------
   57|      0|		ret += 1 + apdu->lc;
   58|      0|		break;
   59|      0|	case SC_APDU_CASE_3_EXT:
  ------------------
  |  |  298|      0|#define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  |  |  ------------------
  |  |               #define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (59:2): [True: 0, False: 5.18k]
  ------------------
   60|      0|		ret += apdu->lc + (proto == SC_PROTO_T0 ? 1 : 3);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (60:22): [True: 0, False: 0]
  ------------------
   61|      0|		break;
   62|      0|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (62:2): [True: 0, False: 5.18k]
  ------------------
   63|      0|		ret += apdu->lc + (proto != SC_PROTO_T0 ? 2 : 1);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (63:22): [True: 0, False: 0]
  ------------------
   64|      0|		break;
   65|      0|	case SC_APDU_CASE_4_EXT:
  ------------------
  |  |  299|      0|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (65:2): [True: 0, False: 5.18k]
  ------------------
   66|      0|		ret += apdu->lc + (proto == SC_PROTO_T0 ? 1 : 5);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (66:22): [True: 0, False: 0]
  ------------------
   67|      0|		break;
   68|      0|	default:
  ------------------
  |  Branch (68:2): [True: 0, False: 5.18k]
  ------------------
   69|      0|		return 0;
   70|  5.18k|	}
   71|  5.18k|	return ret;
   72|  5.18k|}
sc_apdu2bytes:
   84|  2.59k|{
   85|  2.59k|	u8     *p = out;
   86|       |
   87|  2.59k|	size_t len = sc_apdu_get_length(apdu, proto);
   88|       |
   89|  2.59k|	if (out == NULL || outlen < len)
  ------------------
  |  Branch (89:6): [True: 0, False: 2.59k]
  |  Branch (89:21): [True: 0, False: 2.59k]
  ------------------
   90|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   91|       |	/* CLA, INS, P1 and P2 */
   92|  2.59k|	*p++ = apdu->cla;
   93|  2.59k|	*p++ = apdu->ins;
   94|  2.59k|	*p++ = apdu->p1;
   95|  2.59k|	*p++ = apdu->p2;
   96|       |	/* case depend part */
   97|  2.59k|	switch (apdu->cse) {
  ------------------
  |  Branch (97:10): [True: 2.59k, False: 0]
  ------------------
   98|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (98:2): [True: 0, False: 2.59k]
  ------------------
   99|       |		/* T0 needs an additional 0x00 byte */
  100|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (100:7): [True: 0, False: 0]
  ------------------
  101|      0|			*p = (u8)0x00;
  102|      0|		break;
  103|  2.59k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  2.59k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (103:2): [True: 2.59k, False: 0]
  ------------------
  104|  2.59k|		*p = (u8)apdu->le;
  105|  2.59k|		break;
  106|      0|	case SC_APDU_CASE_2_EXT:
  ------------------
  |  |  297|      0|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (106:2): [True: 0, False: 2.59k]
  ------------------
  107|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (107:7): [True: 0, False: 0]
  ------------------
  108|       |			/* T0 extended APDUs look just like short APDUs */
  109|      0|			*p = (u8)apdu->le;
  110|      0|		else {
  111|       |			/* in case of T1 always use 3 bytes for length */
  112|      0|			*p++ = (u8)0x00;
  113|      0|			*p++ = (u8)(apdu->le >> 8);
  114|      0|			*p = (u8)apdu->le;
  115|      0|		}
  116|      0|		break;
  117|      0|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (117:2): [True: 0, False: 2.59k]
  ------------------
  118|      0|		*p++ = (u8)apdu->lc;
  119|      0|		memcpy(p, apdu->data, apdu->lc);
  120|      0|		break;
  121|      0|	case SC_APDU_CASE_3_EXT:
  ------------------
  |  |  298|      0|#define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  |  |  ------------------
  |  |               #define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (121:2): [True: 0, False: 2.59k]
  ------------------
  122|      0|		if (proto == SC_PROTO_T0) {
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (122:7): [True: 0, False: 0]
  ------------------
  123|       |			/* in case of T0 the command is transmitted in chunks
  124|       |			 * < 255 using the ENVELOPE command ... */
  125|      0|			if (apdu->lc > 255) {
  ------------------
  |  Branch (125:8): [True: 0, False: 0]
  ------------------
  126|       |				/* ... so if Lc is greater than 255 bytes
  127|       |				 * an error has occurred on a higher level */
  128|      0|				sc_log(ctx, "invalid Lc length for CASE 3 extended APDU (need ENVELOPE)");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  130|      0|			}
  131|      0|		}
  132|      0|		else {
  133|       |			/* in case of T1 always use 3 bytes for length */
  134|      0|			*p++ = (u8)0x00;
  135|      0|			*p++ = (u8)(apdu->lc >> 8);
  136|      0|			*p++ = (u8)apdu->lc;
  137|      0|		}
  138|      0|		memcpy(p, apdu->data, apdu->lc);
  139|      0|		break;
  140|      0|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (140:2): [True: 0, False: 2.59k]
  ------------------
  141|      0|		*p++ = (u8)apdu->lc;
  142|      0|		memcpy(p, apdu->data, apdu->lc);
  143|      0|		p += apdu->lc;
  144|       |		/* in case of T0 no Le byte is added */
  145|      0|		if (proto != SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (145:7): [True: 0, False: 0]
  ------------------
  146|      0|			*p = (u8)apdu->le;
  147|      0|		break;
  148|      0|	case SC_APDU_CASE_4_EXT:
  ------------------
  |  |  299|      0|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  |  Branch (148:2): [True: 0, False: 2.59k]
  ------------------
  149|      0|		if (proto == SC_PROTO_T0) {
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (149:7): [True: 0, False: 0]
  ------------------
  150|       |			/* again a T0 extended case 4 APDU looks just
  151|       |			 * like a short APDU, the additional data is
  152|       |			 * transferred using ENVELOPE and GET RESPONSE */
  153|      0|			*p++ = (u8)apdu->lc;
  154|      0|			memcpy(p, apdu->data, apdu->lc);
  155|      0|		}
  156|      0|		else {
  157|      0|			*p++ = (u8)0x00;
  158|      0|			*p++ = (u8)(apdu->lc >> 8);
  159|      0|			*p++ = (u8)apdu->lc;
  160|      0|			memcpy(p, apdu->data, apdu->lc);
  161|      0|			p += apdu->lc;
  162|       |			/* only 2 bytes are use to specify the length of the
  163|       |			 * expected data */
  164|      0|			*p++ = (u8)(apdu->le >> 8);
  165|      0|			*p = (u8)apdu->le;
  166|      0|		}
  167|      0|		break;
  168|  2.59k|	}
  169|       |
  170|  2.59k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  171|  2.59k|}
sc_apdu_get_octets:
  175|  2.59k|{
  176|  2.59k|	size_t	nlen;
  177|  2.59k|	u8	*nbuf;
  178|       |
  179|  2.59k|	if (apdu == NULL || buf == NULL || len == NULL)
  ------------------
  |  Branch (179:6): [True: 0, False: 2.59k]
  |  Branch (179:22): [True: 0, False: 2.59k]
  |  Branch (179:37): [True: 0, False: 2.59k]
  ------------------
  180|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  181|       |
  182|       |	/* get the estimated length of encoded APDU */
  183|  2.59k|	nlen = sc_apdu_get_length(apdu, proto);
  184|  2.59k|	if (nlen == 0)
  ------------------
  |  Branch (184:6): [True: 0, False: 2.59k]
  ------------------
  185|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  186|  2.59k|	nbuf = malloc(nlen);
  187|  2.59k|	if (nbuf == NULL)
  ------------------
  |  Branch (187:6): [True: 0, False: 2.59k]
  ------------------
  188|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  189|       |	/* encode the APDU in the buffer */
  190|  2.59k|	if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) {
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (190:6): [True: 0, False: 2.59k]
  ------------------
  191|      0|		free(nbuf);
  192|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  193|      0|	}
  194|  2.59k|	*buf = nbuf;
  195|  2.59k|	*len = nlen;
  196|       |
  197|  2.59k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  198|  2.59k|}
sc_check_apdu:
  256|   448k|{
  257|   448k|	if ((apdu->cse & ~SC_APDU_SHORT_MASK) == 0) {
  ------------------
  |  |  295|   448k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  |  Branch (257:6): [True: 447k, False: 775]
  ------------------
  258|       |		/* length check for short APDU */
  259|   447k|		if (apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0))   {
  ------------------
  |  |  306|     17|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (259:7): [True: 35, False: 447k]
  |  Branch (259:26): [True: 17, False: 447k]
  |  Branch (259:44): [True: 1, False: 16]
  ------------------
  260|     36|			sc_log(card->ctx, "failed length check for short APDU");
  ------------------
  |  |   71|     36|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  261|     36|			goto error;
  262|     36|		}
  263|   447k|	}
  264|    775|	else if ((apdu->cse & SC_APDU_EXT) != 0) {
  ------------------
  |  |  296|    775|#define SC_APDU_EXT			0x10
  ------------------
  |  Branch (264:11): [True: 775, False: 0]
  ------------------
  265|       |		/* check if the card supports extended APDUs */
  266|    775|		if ((card->caps & SC_CARD_CAP_APDU_EXT) == 0) {
  ------------------
  |  |  547|    775|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (266:7): [True: 0, False: 775]
  ------------------
  267|      0|			sc_log(card->ctx, "card doesn't support extended APDUs");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  268|      0|			goto error;
  269|      0|		}
  270|       |		/* length check for extended APDU */
  271|    775|		if (apdu->le > 65536 || apdu->lc > 65535)   {
  ------------------
  |  Branch (271:7): [True: 0, False: 775]
  |  Branch (271:27): [True: 0, False: 775]
  ------------------
  272|      0|			sc_log(card->ctx, "failed length check for extended APDU");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  273|      0|			goto error;
  274|      0|		}
  275|    775|	}
  276|      0|	else   {
  277|      0|		goto error;
  278|      0|	}
  279|       |
  280|   448k|	switch (apdu->cse & SC_APDU_SHORT_MASK) {
  ------------------
  |  |  295|   448k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  281|  2.58k|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|  2.58k|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (281:2): [True: 2.58k, False: 446k]
  ------------------
  282|       |		/* no data is sent or received */
  283|  2.58k|		if (apdu->datalen != 0 || apdu->lc != 0 || apdu->le != 0)
  ------------------
  |  Branch (283:7): [True: 0, False: 2.58k]
  |  Branch (283:29): [True: 0, False: 2.58k]
  |  Branch (283:46): [True: 0, False: 2.58k]
  ------------------
  284|      0|			goto error;
  285|  2.58k|		break;
  286|   131k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|   131k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (286:2): [True: 131k, False: 317k]
  ------------------
  287|       |		/* no data is sent */
  288|   131k|		if (apdu->datalen != 0 || apdu->lc != 0)
  ------------------
  |  Branch (288:7): [True: 0, False: 131k]
  |  Branch (288:29): [True: 0, False: 131k]
  ------------------
  289|      0|			goto error;
  290|       |		/* data is expected       */
  291|   131k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (291:7): [True: 3, False: 131k]
  |  Branch (291:29): [True: 0, False: 131k]
  ------------------
  292|      3|			goto error;
  293|   131k|		break;
  294|   131k|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|  59.4k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (294:2): [True: 59.4k, False: 389k]
  ------------------
  295|       |		/* data is sent */
  296|  59.4k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (296:7): [True: 1, False: 59.4k]
  |  Branch (296:29): [True: 0, False: 59.4k]
  |  Branch (296:51): [True: 0, False: 59.4k]
  ------------------
  297|      1|			goto error;
  298|       |		/* no data is expected    */
  299|  59.4k|		if (apdu->le != 0)
  ------------------
  |  Branch (299:7): [True: 0, False: 59.4k]
  ------------------
  300|      0|			goto error;
  301|       |		/* inconsistent datalen   */
  302|  59.4k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (302:7): [True: 0, False: 59.4k]
  ------------------
  303|      0|			goto error;
  304|  59.4k|		break;
  305|   255k|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|   255k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (305:2): [True: 255k, False: 193k]
  ------------------
  306|       |		/* data is sent */
  307|   255k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (307:7): [True: 45, False: 255k]
  |  Branch (307:29): [True: 0, False: 255k]
  |  Branch (307:51): [True: 0, False: 255k]
  ------------------
  308|     45|			goto error;
  309|       |		/* data is expected       */
  310|   255k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (310:7): [True: 0, False: 255k]
  |  Branch (310:29): [True: 0, False: 255k]
  ------------------
  311|      0|			goto error;
  312|       |		/* inconsistent datalen   */
  313|   255k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (313:7): [True: 0, False: 255k]
  ------------------
  314|      0|			goto error;
  315|   255k|		break;
  316|   255k|	default:
  ------------------
  |  Branch (316:2): [True: 0, False: 448k]
  ------------------
  317|      0|		sc_log(card->ctx, "Invalid APDU case %d", apdu->cse);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  319|   448k|	}
  320|   448k|	return SC_SUCCESS;
  ------------------
  |  |   28|   448k|#define SC_SUCCESS				0
  ------------------
  321|     85|error:
  322|     85|	sc_log(card->ctx, "Invalid Case %d %s APDU:\n"
  ------------------
  |  |   71|     85|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  325|    170|		apdu->cse & SC_APDU_SHORT_MASK,
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     85|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |  326|    170|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     85|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  327|    170|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  |  |  |  |  328|    170|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  |  |  |  |  329|    170|		apdu->resp, (unsigned long) apdu->resplen,
  |  |  |  |  330|    170|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  |  |  ------------------
  ------------------
  323|     85|		"cse=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%lu le=%lu\n"
  324|     85|		"resp=%p resplen=%lu data=%p datalen=%lu flags=0x%8.8lx",
  325|     85|		apdu->cse & SC_APDU_SHORT_MASK,
  326|     85|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  327|     85|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  328|     85|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  329|     85|		apdu->resp, (unsigned long) apdu->resplen,
  330|     85|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  331|     85|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     85|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  332|   448k|}
sc_transmit_apdu:
  541|   445k|{
  542|   445k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   445k|#define SC_SUCCESS				0
  ------------------
  543|       |
  544|   445k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (544:6): [True: 0, False: 445k]
  |  Branch (544:22): [True: 0, False: 445k]
  ------------------
  545|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  546|       |
  547|   445k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   445k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   445k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   445k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   445k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 445k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  548|       |
  549|       |	/* determine the APDU type if necessary, i.e. to use
  550|       |	 * short or extended APDUs  */
  551|   445k|	sc_detect_apdu_cse(card, apdu);
  552|       |	/* basic APDU consistency check */
  553|   445k|	r = sc_check_apdu(card, apdu);
  554|   445k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   445k|#define SC_SUCCESS				0
  ------------------
  |  Branch (554:6): [True: 85, False: 445k]
  ------------------
  555|     85|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     85|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  556|       |
  557|   445k|	r = sc_lock(card);	/* acquire card lock*/
  558|   445k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|   445k|#define SC_SUCCESS				0
  ------------------
  |  Branch (558:6): [True: 0, False: 445k]
  ------------------
  559|      0|		sc_log(card->ctx, "unable to acquire lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  560|      0|		return r;
  561|      0|	}
  562|       |
  563|   445k|#if ENABLE_SM
  564|   445k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|   890k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (564:6): [True: 4.35k, False: 440k]
  ------------------
  565|  4.35k|			&& (apdu->flags & SC_APDU_FLAGS_CHAINING) != 0
  ------------------
  |  |  306|  4.35k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (565:7): [True: 0, False: 4.35k]
  ------------------
  566|      0|			&& (apdu->flags & SC_APDU_FLAGS_SM_CHAINING) != 0) {
  ------------------
  |  |  316|      0|#define SC_APDU_FLAGS_SM_CHAINING	0x00000010UL
  ------------------
  |  Branch (566:7): [True: 0, False: 0]
  ------------------
  567|      0|		sc_log(card->ctx,"Let SM do the chaining");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  568|      0|		r = sc_transmit(card, apdu);
  569|      0|	} else
  570|   445k|#endif
  571|   445k|	if ((apdu->flags & SC_APDU_FLAGS_CHAINING) != 0) {
  ------------------
  |  |  306|   445k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (571:6): [True: 421, False: 444k]
  ------------------
  572|       |		/* divide et impera: transmit APDU in chunks with Lc <= max_send_size
  573|       |		 * bytes using command chaining */
  574|    421|		size_t    len  = apdu->datalen;
  575|    421|		const u8  *buf = apdu->data;
  576|    421|		size_t    max_send_size = sc_get_max_send_size(card);
  577|       |
  578|  1.42k|		while (len != 0) {
  ------------------
  |  Branch (578:10): [True: 1.13k, False: 294]
  ------------------
  579|  1.13k|			size_t    plen;
  580|  1.13k|			sc_apdu_t tapdu;
  581|  1.13k|			int       last = 0;
  582|       |
  583|  1.13k|			tapdu = *apdu;
  584|       |			/* clear chaining flag */
  585|  1.13k|			tapdu.flags &= ~SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  1.13k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  586|  1.13k|			if (len > max_send_size) {
  ------------------
  |  Branch (586:8): [True: 836, False: 298]
  ------------------
  587|       |				/* adjust APDU case: in case of CASE 4 APDU
  588|       |				 * the intermediate APDU are of CASE 3 */
  589|    836|				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  295|    836|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
              				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  294|    836|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (589:9): [True: 836, False: 0]
  ------------------
  590|    836|					tapdu.cse--;
  591|       |				/* XXX: the chunk size must be adjusted when
  592|       |				 *      secure messaging is used */
  593|    836|				plen          = max_send_size;
  594|    836|				tapdu.cla    |= 0x10;
  595|       |				/* the intermediate APDU don't expect response data */
  596|    836|				tapdu.le      = 0;
  597|    836|				tapdu.resplen = 0;
  598|    836|				tapdu.resp    = NULL;
  599|    836|			} else {
  600|    298|				plen = len;
  601|    298|				last = 1;
  602|    298|			}
  603|  1.13k|			tapdu.data    = buf;
  604|  1.13k|			tapdu.datalen = tapdu.lc = plen;
  605|       |
  606|  1.13k|			r = sc_check_apdu(card, &tapdu);
  607|  1.13k|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.13k|#define SC_SUCCESS				0
  ------------------
  |  Branch (607:8): [True: 0, False: 1.13k]
  ------------------
  608|      0|				sc_log(card->ctx, "inconsistent APDU while chaining");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  609|      0|				break;
  610|      0|			}
  611|       |
  612|  1.13k|			r = sc_transmit(card, &tapdu);
  613|  1.13k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.13k|#define SC_SUCCESS				0
  ------------------
  |  Branch (613:8): [True: 22, False: 1.11k]
  ------------------
  614|     22|				break;
  615|  1.11k|			if (last != 0) {
  ------------------
  |  Branch (615:8): [True: 294, False: 818]
  ------------------
  616|       |				/* in case of the last APDU set the SW1
  617|       |				 * and SW2 bytes in the original APDU */
  618|    294|				apdu->sw1 = tapdu.sw1;
  619|    294|				apdu->sw2 = tapdu.sw2;
  620|    294|				apdu->resplen = tapdu.resplen;
  621|    818|			} else {
  622|       |				/* otherwise check the status bytes */
  623|    818|				r = sc_check_sw(card, tapdu.sw1, tapdu.sw2);
  624|    818|				if (r != SC_SUCCESS)
  ------------------
  |  |   28|    818|#define SC_SUCCESS				0
  ------------------
  |  Branch (624:9): [True: 105, False: 713]
  ------------------
  625|    105|					break;
  626|    818|			}
  627|  1.00k|			len -= plen;
  628|  1.00k|			buf += plen;
  629|  1.00k|		}
  630|   444k|	} else {
  631|       |		/* transmit single APDU */
  632|   444k|		r = sc_transmit(card, apdu);
  633|   444k|	}
  634|       |
  635|   445k|	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   890k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   445k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (635:6): [True: 0, False: 445k]
  |  Branch (635:34): [True: 0, False: 445k]
  ------------------
  636|       |		/* give card driver a chance to react on resets */
  637|      0|		if (card->ops->card_reader_lock_obtained)
  ------------------
  |  Branch (637:7): [True: 0, False: 0]
  ------------------
  638|      0|			card->ops->card_reader_lock_obtained(card, 1);
  639|      0|	}
  640|       |
  641|       |	/* all done => release lock */
  642|   445k|	if (sc_unlock(card) != SC_SUCCESS)
  ------------------
  |  |   28|   445k|#define SC_SUCCESS				0
  ------------------
  |  Branch (642:6): [True: 0, False: 445k]
  ------------------
  643|      0|		sc_log(card->ctx, "sc_unlock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  644|       |
  645|   445k|	return r;
  646|   445k|}
sc_bytes2apdu:
  651|     94|{
  652|     94|	const unsigned char *p;
  653|     94|	size_t len0;
  654|       |
  655|     94|	if (!buf || !apdu)
  ------------------
  |  Branch (655:6): [True: 0, False: 94]
  |  Branch (655:14): [True: 0, False: 94]
  ------------------
  656|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  657|       |
  658|     94|	len0 = len;
  659|     94|	if (len < 4) {
  ------------------
  |  Branch (659:6): [True: 0, False: 94]
  ------------------
  660|      0|		sc_log(ctx, "APDU too short (must be at least 4 bytes)");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  661|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  662|      0|	}
  663|       |
  664|     94|	memset(apdu, 0, sizeof *apdu);
  665|     94|	p = buf;
  666|     94|	apdu->cla = *p++;
  667|     94|	apdu->ins = *p++;
  668|     94|	apdu->p1 = *p++;
  669|     94|	apdu->p2 = *p++;
  670|     94|	len -= 4;
  671|       |
  672|     94|	if (!len) {
  ------------------
  |  Branch (672:6): [True: 0, False: 94]
  ------------------
  673|      0|		apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  674|      0|		sc_log(ctx, "CASE_1 APDU: %zu bytes:\tins=%02x p1=%02x p2=%02x lc=%04zx le=%04zx",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  675|      0|				len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
  676|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  677|      0|	}
  678|       |
  679|     94|	if (*p == 0 && len >= 3) {
  ------------------
  |  Branch (679:6): [True: 0, False: 94]
  |  Branch (679:17): [True: 0, False: 0]
  ------------------
  680|       |		/* ...must be an extended APDU */
  681|      0|		p++;
  682|      0|		if (len == 3) {
  ------------------
  |  Branch (682:7): [True: 0, False: 0]
  ------------------
  683|      0|			apdu->le = (*p++)<<8;
  684|      0|			apdu->le += *p++;
  685|      0|			if (apdu->le == 0)
  ------------------
  |  Branch (685:8): [True: 0, False: 0]
  ------------------
  686|      0|				apdu->le = 0xffff+1;
  687|      0|			len -= 3;
  688|      0|			apdu->cse = SC_APDU_CASE_2_EXT;
  ------------------
  |  |  297|      0|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  689|      0|		}
  690|      0|		else {
  691|       |			/* len > 3 */
  692|      0|			apdu->lc = (*p++)<<8;
  693|      0|			apdu->lc += *p++;
  694|      0|			len -= 3;
  695|      0|			if (len < apdu->lc) {
  ------------------
  |  Branch (695:8): [True: 0, False: 0]
  ------------------
  696|      0|				sc_log(ctx, "APDU too short (need %zu more bytes)", apdu->lc - len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  697|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  698|      0|			}
  699|      0|			apdu->data = p;
  700|      0|			apdu->datalen = apdu->lc;
  701|      0|			len -= apdu->lc;
  702|      0|			p += apdu->lc;
  703|      0|			if (!len) {
  ------------------
  |  Branch (703:8): [True: 0, False: 0]
  ------------------
  704|      0|				apdu->cse = SC_APDU_CASE_3_EXT;
  ------------------
  |  |  298|      0|#define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  |  |  ------------------
  |  |               #define SC_APDU_CASE_3_EXT		SC_APDU_CASE_3_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  705|      0|			}
  706|      0|			else {
  707|       |				/* at this point the apdu has a Lc, so Le is on 2 bytes */
  708|      0|				if (len < 2) {
  ------------------
  |  Branch (708:9): [True: 0, False: 0]
  ------------------
  709|      0|					sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too short (need 2 more bytes)\n");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  710|      0|					return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  711|      0|				}
  712|      0|				apdu->le = (*p++)<<8;
  713|      0|				apdu->le += *p++;
  714|      0|				if (apdu->le == 0)
  ------------------
  |  Branch (714:9): [True: 0, False: 0]
  ------------------
  715|      0|					apdu->le = 0xffff+1;
  716|      0|				len -= 2;
  717|      0|				apdu->cse = SC_APDU_CASE_4_EXT;
  ------------------
  |  |  299|      0|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  718|      0|			}
  719|      0|		}
  720|      0|	}
  721|     94|	else {
  722|       |		/* ...must be a short APDU */
  723|     94|		if (len == 1) {
  ------------------
  |  Branch (723:7): [True: 94, False: 0]
  ------------------
  724|     94|			apdu->le = *p++;
  725|     94|			if (apdu->le == 0)
  ------------------
  |  Branch (725:8): [True: 0, False: 94]
  ------------------
  726|      0|				apdu->le = 0xff+1;
  727|     94|			len--;
  728|     94|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|     94|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  729|     94|		}
  730|      0|		else {
  731|      0|			apdu->lc = *p++;
  732|      0|			len--;
  733|      0|			if (len < apdu->lc) {
  ------------------
  |  Branch (733:8): [True: 0, False: 0]
  ------------------
  734|      0|				sc_log(ctx, "APDU too short (need %zu more bytes)", apdu->lc - len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  735|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  736|      0|			}
  737|      0|			apdu->data = p;
  738|      0|			apdu->datalen = apdu->lc;
  739|      0|			len -= apdu->lc;
  740|      0|			p += apdu->lc;
  741|      0|			if (!len) {
  ------------------
  |  Branch (741:8): [True: 0, False: 0]
  ------------------
  742|      0|				apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  743|      0|			}
  744|      0|			else {
  745|      0|				apdu->le = *p++;
  746|      0|				if (apdu->le == 0)
  ------------------
  |  Branch (746:9): [True: 0, False: 0]
  ------------------
  747|      0|					apdu->le = 0xff+1;
  748|      0|				len--;
  749|      0|				apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  750|      0|			}
  751|      0|		}
  752|     94|	}
  753|     94|	if (len) {
  ------------------
  |  Branch (753:6): [True: 0, False: 94]
  ------------------
  754|      0|		sc_log(ctx, "APDU too long (%lu bytes extra)",(unsigned long) len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  755|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  756|      0|	}
  757|       |
  758|     94|	sc_log(ctx, "Case %d %s APDU, %zu bytes:\tins=%02x p1=%02x p2=%02x lc=%04zx le=%04zx",
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  759|    188|			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     94|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |               			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     94|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  760|    188|			len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
  |  |  ------------------
  ------------------
  759|     94|			apdu->cse & SC_APDU_SHORT_MASK, (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  760|     94|			len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
  761|       |
  762|     94|	return SC_SUCCESS;
  ------------------
  |  |   28|     94|#define SC_SUCCESS				0
  ------------------
  763|     94|}
apdu.c:sc_detect_apdu_cse:
  340|   445k|{
  341|   445k|	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  301|   890k|#define SC_APDU_CASE_2			0x22
  ------------------
              	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  302|   804k|#define SC_APDU_CASE_3			0x23
  ------------------
  |  Branch (341:6): [True: 86.3k, False: 359k]
  |  Branch (341:37): [True: 12, False: 359k]
  ------------------
  342|   359k|	    apdu->cse == SC_APDU_CASE_4) {
  ------------------
  |  |  303|   359k|#define SC_APDU_CASE_4			0x24
  ------------------
  |  Branch (342:6): [True: 7.26k, False: 351k]
  ------------------
  343|  93.5k|		int btype = apdu->cse & SC_APDU_SHORT_MASK;
  ------------------
  |  |  295|  93.5k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  344|       |		/* if either Lc or Le is bigger than the maximum for
  345|       |		 * short APDUs and the card supports extended APDUs
  346|       |		 * use extended APDUs (unless Lc is greater than
  347|       |		 * 255 and command chaining is activated) */
  348|  93.5k|		if ((apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
  ------------------
  |  |  306|      0|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (348:8): [True: 768, False: 92.8k]
  |  Branch (348:27): [True: 0, False: 92.8k]
  |  Branch (348:45): [True: 0, False: 0]
  ------------------
  349|    768|		    (card->caps & SC_CARD_CAP_APDU_EXT) != 0)
  ------------------
  |  |  547|    768|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (349:7): [True: 733, False: 35]
  ------------------
  350|    733|			btype |= SC_APDU_EXT;
  ------------------
  |  |  296|    733|#define SC_APDU_EXT			0x10
  ------------------
  351|  93.5k|		apdu->cse = btype;
  352|  93.5k|	}
  353|   445k|}
apdu.c:sc_transmit:
  507|   445k|{
  508|   445k|	struct sc_context *ctx  = card->ctx;
  509|   445k|	size_t       olen  = apdu->resplen;
  510|   445k|	int          r;
  511|       |
  512|   445k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   445k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   445k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   445k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   445k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 445k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|       |
  514|   445k|	r = sc_single_transmit(card, apdu);
  515|   445k|	LOG_TEST_RET(ctx, r, "transmit APDU failed");
  ------------------
  |  |  174|   445k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   445k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   445k|	int _ret = (r); \
  |  |  |  |  168|   445k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 617, False: 445k]
  |  |  |  |  ------------------
  |  |  |  |  169|    617|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    617|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    617|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    617|		return _ret; \
  |  |  |  |  172|    617|	} \
  |  |  |  |  173|   445k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 445k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|       |	/* ok, the APDU was successfully transmitted. Now we have two special cases:
  518|       |	 * 1. the card returned 0x6Cxx: in this case APDU will be re-transmitted with Le set to SW2
  519|       |	 * (possible only if response buffer size is larger than new Le = SW2)
  520|       |	 */
  521|   445k|	if (apdu->sw1 == 0x6C && (apdu->flags & SC_APDU_FLAGS_NO_RETRY_WL) == 0) {
  ------------------
  |  |  312|  3.18k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  |  Branch (521:6): [True: 3.18k, False: 442k]
  |  Branch (521:27): [True: 3.09k, False: 94]
  ------------------
  522|  3.09k|		r = sc_set_le_and_transmit(card, apdu, olen);
  523|  3.09k|		LOG_TEST_RET(ctx, r, "cannot re-transmit APDU ");
  ------------------
  |  |  174|  3.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.09k|	int _ret = (r); \
  |  |  |  |  168|  3.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.23k, False: 858]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.23k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.23k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.23k|		return _ret; \
  |  |  |  |  172|  2.23k|	} \
  |  |  |  |  173|  3.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 858]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|  3.09k|	}
  525|       |
  526|       |	/* 2. the card returned 0x61xx: more data can be read from the card
  527|       |	 *    using the GET RESPONSE command (mostly used in the T0 protocol).
  528|       |	 *    Unless the SC_APDU_FLAGS_NO_GET_RESP is set we try to read as
  529|       |	 *    much data as possible using GET RESPONSE.
  530|       |	 */
  531|   443k|	if (apdu->sw1 == 0x61 && (apdu->flags & SC_APDU_FLAGS_NO_GET_RESP) == 0) {
  ------------------
  |  |  308|  36.8k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  |  Branch (531:6): [True: 36.8k, False: 406k]
  |  Branch (531:27): [True: 31.4k, False: 5.36k]
  ------------------
  532|  31.4k|		r = sc_get_response(card, apdu, olen);
  533|  31.4k|		LOG_TEST_RET(ctx, r, "cannot get all data with 'GET RESPONSE'");
  ------------------
  |  |  174|  31.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  31.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  31.4k|	int _ret = (r); \
  |  |  |  |  168|  31.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.54k, False: 26.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.54k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.54k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.54k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.54k|		return _ret; \
  |  |  |  |  172|  4.54k|	} \
  |  |  |  |  173|  31.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|  31.4k|	}
  535|       |
  536|   438k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|   438k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   438k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   438k|	int _ret = r; \
  |  |  |  |  155|   438k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 438k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   438k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 438k]
  |  |  |  |  ------------------
  |  |  |  |  157|   438k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   438k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   438k|	return _ret; \
  |  |  |  |  163|   438k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  537|   438k|}
apdu.c:sc_single_transmit:
  358|   446k|{
  359|   446k|	struct sc_context *ctx  = card->ctx;
  360|   446k|	int rv;
  361|       |
  362|   446k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   446k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   446k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   446k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   446k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 446k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|   446k|	if (card->reader->ops->transmit == NULL)
  ------------------
  |  Branch (363:6): [True: 0, False: 446k]
  ------------------
  364|   446k|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "cannot transmit APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|       |
  366|   446k|	sc_log(ctx, "CLA:%X, INS:%X, P1:%X, P2:%X, data(%zu) %p",
  ------------------
  |  |   71|   446k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  367|   446k|			apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen, apdu->data);
  368|   446k|#ifdef ENABLE_SM
  369|   446k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|   893k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (369:6): [True: 4.36k, False: 442k]
  ------------------
  370|  4.36k|		   	&& (apdu->flags & SC_APDU_FLAGS_NO_SM) == 0) {
  ------------------
  |  |  314|  4.36k|#define SC_APDU_FLAGS_NO_SM		0x00000008UL
  ------------------
  |  Branch (370:10): [True: 2.18k, False: 2.18k]
  ------------------
  371|  2.18k|		LOG_FUNC_RETURN(ctx, sc_sm_single_transmit(card, apdu));
  ------------------
  |  |  164|  2.18k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.18k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.18k|	int _ret = r; \
  |  |  |  |  155|  2.18k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    620|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 620, False: 1.56k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.18k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.18k|	return _ret; \
  |  |  |  |  163|  2.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|  2.18k|	}
  373|   444k|#endif
  374|       |
  375|       |	/* send APDU to the reader driver */
  376|   444k|	rv = card->reader->ops->transmit(card->reader, apdu);
  377|   444k|	LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  174|   444k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   444k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   444k|	int _ret = (r); \
  |  |  |  |  168|   444k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 444k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|   444k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 444k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  378|       |
  379|   444k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|   444k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   444k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   444k|	int _ret = r; \
  |  |  |  |  155|   444k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 444k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   444k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 444k]
  |  |  |  |  ------------------
  |  |  |  |  157|   444k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   444k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   444k|	return _ret; \
  |  |  |  |  163|   444k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  380|   444k|}
apdu.c:sc_set_le_and_transmit:
  385|  3.09k|{
  386|  3.09k|	struct sc_context *ctx  = card->ctx;
  387|  3.09k|	size_t nlen = apdu->sw2 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (387:16): [True: 1.67k, False: 1.41k]
  ------------------
  388|  3.09k|	int rv;
  389|       |
  390|  3.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|       |	/* we cannot re-transmit the APDU with the demanded Le value
  392|       |	 * as the buffer is too small => error */
  393|  3.09k|	if (olen < nlen)
  ------------------
  |  Branch (393:6): [True: 2.23k, False: 861]
  ------------------
  394|  3.09k|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_LENGTH, "wrong length: required length exceeds resplen");
  ------------------
  |  |  174|  2.23k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.23k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.23k|	int _ret = (r); \
  |  |  |  |  168|  2.23k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.23k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.23k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.23k|		return _ret; \
  |  |  |  |  172|  2.23k|	} \
  |  |  |  |  173|  2.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|       |
  396|       |	/* don't try again if it doesn't work this time */
  397|    861|	apdu->flags  |= SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|    861|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  398|       |	/* set the new expected length */
  399|    861|	apdu->resplen = olen;
  400|    861|	apdu->le      = nlen;
  401|       |#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  402|       |	/* Belpic V1 applets have a problem: if the card sends a 6C XX (only XX bytes available),
  403|       |	 * and we resend the command too soon (i.e. the reader is too fast), the card doesn't respond.
  404|       |	 * So we build in a delay. */
  405|       |	if (card->type == SC_CARD_TYPE_BELPIC_EID)
  406|       |		msleep(40);
  407|       |#endif
  408|       |
  409|       |	/* re-transmit the APDU with new Le length */
  410|    861|	rv = sc_single_transmit(card, apdu);
  411|    861|	LOG_TEST_RET(ctx, rv, "cannot re-transmit APDU");
  ------------------
  |  |  174|    861|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    861|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    861|	int _ret = (r); \
  |  |  |  |  168|    861|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 858]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|    861|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 858]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|       |
  413|    858|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    858|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    858|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    858|	int _ret = r; \
  |  |  |  |  155|    858|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 858, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    858|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 858]
  |  |  |  |  ------------------
  |  |  |  |  157|    858|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    858|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    858|	return _ret; \
  |  |  |  |  163|    858|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|    858|}
apdu.c:sc_get_response:
  419|  31.4k|{
  420|  31.4k|	struct sc_context *ctx  = card->ctx;
  421|  31.4k|	size_t le, minlen, buflen;
  422|  31.4k|	unsigned char *buf;
  423|  31.4k|	int rv;
  424|       |
  425|  31.4k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  31.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  31.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  31.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  31.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 31.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|  31.4k|	if (apdu->le == 0) {
  ------------------
  |  Branch (426:6): [True: 9.50k, False: 21.9k]
  ------------------
  427|       |		/* no data is requested => change return value to 0x9000 and ignore the remaining data */
  428|  9.50k|		apdu->sw1 = 0x90;
  429|  9.50k|		apdu->sw2 = 0x00;
  430|  9.50k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.50k|#define SC_SUCCESS				0
  ------------------
  431|  9.50k|	}
  432|       |
  433|       |	/* this should _never_ happen */
  434|  21.9k|	if (!card->ops->get_response)
  ------------------
  |  Branch (434:6): [True: 78, False: 21.8k]
  ------------------
  435|  21.9k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "no GET RESPONSE command");
  ------------------
  |  |  174|     78|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     78|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     78|	int _ret = (r); \
  |  |  |  |  168|     78|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 78, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     78|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     78|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     78|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     78|		return _ret; \
  |  |  |  |  172|     78|	} \
  |  |  |  |  173|     78|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|       |
  437|       |	/* call GET RESPONSE until we have read all data requested or until the card returns 0x9000,
  438|       |	 * whatever happens first. */
  439|       |
  440|       |	/* if there are already data in response append a new data to the end of the buffer */
  441|  21.8k|	buf = apdu->resp + apdu->resplen;
  442|       |
  443|       |	/* read as much data as fits in apdu->resp (i.e. min(apdu->resplen, amount of data available)). */
  444|  21.8k|	buflen = olen - apdu->resplen;
  445|       |
  446|       |	/* 0x6100 means at least 256 more bytes to read */
  447|  21.8k|	le = apdu->sw2 != 0 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (447:7): [True: 17.8k, False: 3.98k]
  ------------------
  448|       |	/* we try to read at least as much as bytes as promised in the response bytes */
  449|  21.8k|	minlen = le;
  450|       |
  451|  26.9k|	do {
  452|  26.9k|		unsigned char resp[256];
  453|  26.9k|		size_t resp_len = le;
  454|       |
  455|       |		/* we have all the data the caller requested even if the card has more data */
  456|  26.9k|		if (buflen == 0)
  ------------------
  |  Branch (456:7): [True: 6.33k, False: 20.5k]
  ------------------
  457|  6.33k|			break;
  458|       |
  459|       |		/* call GET RESPONSE to get more date from the card;
  460|       |		 * note: GET RESPONSE returns the left amount of data (== SW2) */
  461|  20.5k|		memset(resp, 0, sizeof(resp));
  462|  20.5k|		rv = card->ops->get_response(card, &resp_len, resp);
  463|  20.5k|		if (rv < 0)   {
  ------------------
  |  Branch (463:7): [True: 4.46k, False: 16.1k]
  ------------------
  464|  4.46k|#ifdef ENABLE_SM
  465|  4.46k|			if (resp_len)   {
  ------------------
  |  Branch (465:8): [True: 2.15k, False: 2.30k]
  ------------------
  466|  2.15k|				sc_log_hex(ctx, "SM response data", resp, resp_len);
  ------------------
  |  |  129|  2.15k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  2.15k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|  2.15k|				sc_sm_update_apdu_response(card, resp, resp_len, rv, apdu);
  468|  2.15k|			}
  469|  4.46k|#endif
  470|  4.46k|			LOG_TEST_RET(ctx, rv, "GET RESPONSE error");
  ------------------
  |  |  174|  4.46k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.46k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.46k|	int _ret = (r); \
  |  |  |  |  168|  4.46k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.46k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.46k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.46k|		return _ret; \
  |  |  |  |  172|  4.46k|	} \
  |  |  |  |  173|  4.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  471|  4.46k|		}
  472|       |
  473|  16.1k|		le = resp_len;
  474|       |		/* copy as much as will fit in requested buffer */
  475|  16.1k|		if (buflen < le)
  ------------------
  |  Branch (475:7): [True: 755, False: 15.3k]
  ------------------
  476|    755|			le = buflen;
  477|       |
  478|  16.1k|		memcpy(buf, resp, le);
  479|  16.1k|		buf    += le;
  480|  16.1k|		buflen -= le;
  481|       |
  482|  16.1k|		minlen -= le;
  483|  16.1k|		if (rv != 0)
  ------------------
  |  Branch (483:7): [True: 5.06k, False: 11.0k]
  ------------------
  484|  5.06k|			le = minlen = (size_t)rv;
  485|  11.0k|		else
  486|       |			/* if the card has returned 0x9000 but we still expect data ask for more
  487|       |			 * until we have read enough bytes */
  488|  11.0k|			le = minlen;
  489|  16.1k|	} while (rv != 0 && minlen != 0);
  ------------------
  |  Branch (489:11): [True: 5.06k, False: 11.0k]
  |  Branch (489:22): [True: 5.06k, False: 0]
  ------------------
  490|       |
  491|       |	/* we've read all data, let's return 0x9000 */
  492|  17.3k|	apdu->resplen = buf - apdu->resp;
  493|  17.3k|	apdu->sw1 = 0x90;
  494|  17.3k|	apdu->sw2 = 0x00;
  495|       |
  496|  17.3k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  17.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.3k|	int _ret = r; \
  |  |  |  |  155|  17.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 17.3k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.3k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  17.3k|	return _ret; \
  |  |  |  |  163|  17.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|  17.3k|}

sc_asn1_read_tag:
   63|   207k|{
   64|   207k|	const u8 *p = *buf;
   65|   207k|	size_t left = buflen, len;
   66|   207k|	unsigned int cla, tag, i;
   67|       |
   68|   207k|	*buf = NULL;
   69|       |
   70|   207k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (70:6): [True: 5.06k, False: 202k]
  |  Branch (70:19): [True: 0, False: 202k]
  |  Branch (70:25): [True: 0, False: 202k]
  ------------------
   71|  5.06k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  5.06k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   72|   202k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (72:6): [True: 2.34k, False: 200k]
  |  Branch (72:20): [True: 9.15k, False: 191k]
  ------------------
   73|       |		/* end of data reached */
   74|  11.5k|		*taglen = 0;
   75|  11.5k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  11.5k|#define SC_ASN1_TAG_EOC			0
  ------------------
   76|  11.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
   77|  11.5k|	}
   78|       |
   79|       |	/* parse tag byte(s)
   80|       |	 * Resulted tag is presented by integer that has not to be
   81|       |	 * confused with the 'tag number' part of ASN.1 tag.
   82|       |	 */
   83|   191k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   191k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   191k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   84|   191k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   191k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   85|   191k|	p++;
   86|   191k|	left--;
   87|   191k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   191k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (87:6): [True: 2.31k, False: 188k]
  ------------------
   88|       |		/* high tag number */
   89|  2.31k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  2.31k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   90|       |		/* search the last tag octet */
   91|  3.50k|		do {
   92|  3.50k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (92:8): [True: 209, False: 3.29k]
  |  Branch (92:21): [True: 129, False: 3.16k]
  ------------------
   93|       |				/* either an invalid tag or it doesn't fit in
   94|       |				 * unsigned int */
   95|    338|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    338|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   96|  3.16k|			tag <<= 8;
   97|  3.16k|			tag |= *p;
   98|  3.16k|			p++;
   99|  3.16k|			left--;
  100|  3.16k|			n--;
  101|  3.16k|		} while (tag & 0x80);
  ------------------
  |  Branch (101:12): [True: 1.19k, False: 1.97k]
  ------------------
  102|  2.31k|	}
  103|       |
  104|       |	/* parse length byte(s) */
  105|   190k|	if (left == 0)
  ------------------
  |  Branch (105:6): [True: 1.25k, False: 189k]
  ------------------
  106|  1.25k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.25k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  107|   189k|	len = *p;
  108|   189k|	p++;
  109|   189k|	left--;
  110|   189k|	if (len & 0x80) {
  ------------------
  |  Branch (110:6): [True: 35.9k, False: 153k]
  ------------------
  111|  35.9k|		len &= 0x7f;
  112|  35.9k|		unsigned int a = 0;
  113|  35.9k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (113:7): [True: 6.86k, False: 29.1k]
  |  Branch (113:25): [True: 232, False: 28.8k]
  ------------------
  114|  7.09k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  7.09k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  115|  45.6k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (115:15): [True: 16.7k, False: 28.8k]
  ------------------
  116|  16.7k|			a <<= 8;
  117|  16.7k|			a |= *p;
  118|  16.7k|			p++;
  119|  16.7k|			left--;
  120|  16.7k|		}
  121|  28.8k|		len = a;
  122|  28.8k|	}
  123|       |
  124|   182k|	*cla_out = cla;
  125|   182k|	*tag_out = tag;
  126|   182k|	*taglen = len;
  127|   182k|	*buf = p;
  128|       |
  129|   182k|	if (len > left)
  ------------------
  |  Branch (129:6): [True: 9.25k, False: 173k]
  ------------------
  130|  9.25k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  9.25k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  131|       |
  132|   173k|	return SC_SUCCESS;
  ------------------
  |  |   28|   173k|#define SC_SUCCESS				0
  ------------------
  133|   182k|}
sc_format_asn1_entry:
  137|   211k|{
  138|   211k|	entry->parm = parm;
  139|   211k|	entry->arg  = arg;
  140|   211k|	if (set_present)
  ------------------
  |  Branch (140:6): [True: 28.9k, False: 182k]
  ------------------
  141|  28.9k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  28.9k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  142|   211k|}
sc_copy_asn1_entry:
  146|  65.7k|{
  147|   278k|	while (src->name != NULL) {
  ------------------
  |  Branch (147:9): [True: 212k, False: 65.7k]
  ------------------
  148|   212k|		*dest = *src;
  149|   212k|		dest++;
  150|   212k|		src++;
  151|   212k|	}
  152|       |	dest->name = NULL;
  153|  65.7k|}
sc_asn1_find_tag:
  481|  39.4k|{
  482|  39.4k|	size_t left = buflen, taglen;
  483|  39.4k|	const u8 *p = buf;
  484|       |
  485|  39.4k|	*taglen_in = 0;
  486|  92.9k|	while (left >= 2) {
  ------------------
  |  Branch (486:9): [True: 85.8k, False: 7.02k]
  ------------------
  487|  85.8k|		unsigned int cla = 0, tag, mask = 0xff00;
  488|       |
  489|  85.8k|		buf = p;
  490|       |		/* read a tag */
  491|  85.8k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   171k|#define SC_SUCCESS				0
  ------------------
  |  Branch (491:7): [True: 7.65k, False: 78.2k]
  ------------------
  492|  78.2k|				|| p == NULL)
  ------------------
  |  Branch (492:8): [True: 7.56k, False: 70.6k]
  ------------------
  493|  15.2k|			return NULL;
  494|       |
  495|  70.6k|		left -= (p - buf);
  496|       |		/* we need to shift the class byte to the leftmost
  497|       |		 * byte of the tag */
  498|  71.9k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (498:10): [True: 1.30k, False: 70.6k]
  ------------------
  499|  1.30k|			cla  <<= 8;
  500|  1.30k|			mask <<= 8;
  501|  1.30k|		}
  502|       |		/* compare the read tag with the given tag */
  503|  70.6k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (503:7): [True: 17.2k, False: 53.4k]
  ------------------
  504|       |			/* we have a match => return length and value part */
  505|  17.2k|			if (taglen > left)
  ------------------
  |  Branch (505:8): [True: 0, False: 17.2k]
  ------------------
  506|      0|				return NULL;
  507|  17.2k|			*taglen_in = taglen;
  508|  17.2k|			return p;
  509|  17.2k|		}
  510|       |		/* otherwise continue reading tags */
  511|  53.4k|		left -= taglen;
  512|  53.4k|		p += taglen;
  513|  53.4k|	}
  514|  7.02k|	return NULL;
  515|  39.4k|}
sc_asn1_skip_tag:
  519|  53.7k|{
  520|  53.7k|	const u8 *p = *buf;
  521|  53.7k|	size_t len = *buflen, taglen;
  522|  53.7k|	unsigned int cla = 0, tag;
  523|       |
  524|  53.7k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   107k|#define SC_SUCCESS				0
  ------------------
  |  Branch (524:6): [True: 9.01k, False: 44.7k]
  ------------------
  525|  44.7k|			|| p == NULL)
  ------------------
  |  Branch (525:7): [True: 1.62k, False: 43.1k]
  ------------------
  526|  10.6k|		return NULL;
  527|  43.1k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (527:10): [True: 43.1k, False: 0]
  ------------------
  528|  23.9k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  23.9k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (528:2): [True: 23.9k, False: 19.1k]
  ------------------
  529|  23.9k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  23.9k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  23.9k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (529:7): [True: 2.14k, False: 21.8k]
  ------------------
  530|  2.14k|			return NULL;
  531|  21.8k|		break;
  532|  21.8k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  7.40k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (532:2): [True: 7.40k, False: 35.7k]
  ------------------
  533|  7.40k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  7.40k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  7.40k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (533:7): [True: 838, False: 6.56k]
  ------------------
  534|    838|			return NULL;
  535|  6.56k|		break;
  536|  10.7k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  10.7k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (536:2): [True: 10.7k, False: 32.3k]
  ------------------
  537|  10.7k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  10.7k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  10.7k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (537:7): [True: 2.06k, False: 8.68k]
  ------------------
  538|  2.06k|			return NULL;
  539|  8.68k|		break;
  540|  8.68k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|    987|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (540:2): [True: 987, False: 42.1k]
  ------------------
  541|    987|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|    987|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|    987|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (541:7): [True: 987, False: 0]
  ------------------
  542|    987|			return NULL;
  543|      0|		break;
  544|  43.1k|	}
  545|  37.0k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|  37.0k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (545:6): [True: 18.1k, False: 18.9k]
  ------------------
  546|  18.1k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  18.1k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (546:7): [True: 811, False: 17.3k]
  ------------------
  547|    811|			return NULL;
  548|  18.1k|	} else
  549|  18.9k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  18.9k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (549:7): [True: 1.00k, False: 17.9k]
  ------------------
  550|  1.00k|			return NULL;
  551|  35.2k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  35.2k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (551:6): [True: 9.48k, False: 25.7k]
  ------------------
  552|  9.48k|		return NULL;
  553|  25.7k|	len -= (p - *buf);	/* header size */
  554|  25.7k|	if (taglen > len) {
  ------------------
  |  Branch (554:6): [True: 0, False: 25.7k]
  ------------------
  555|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "too long ASN.1 object (size %zu while only %zu available)",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  556|      0|				taglen, len);
  557|      0|		return NULL;
  558|      0|	}
  559|  25.7k|	*buflen -= (p - *buf) + taglen;
  560|  25.7k|	*buf = p + taglen;	/* point to next tag */
  561|  25.7k|	*taglen_out = taglen;
  562|  25.7k|	return p;
  563|  25.7k|}
sc_asn1_verify_tag:
  567|  1.09k|{
  568|  1.09k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  569|  1.09k|}
sc_asn1_decode_integer:
  728|  1.76k|{
  729|  1.76k|	int    a = 0, is_negative = 0;
  730|  1.76k|	size_t i = 0;
  731|       |
  732|  1.76k|	if (inlen == 0) {
  ------------------
  |  Branch (732:6): [True: 12, False: 1.75k]
  ------------------
  733|     12|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     12|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  734|     12|	}
  735|  1.75k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (735:6): [True: 24, False: 1.72k]
  ------------------
  736|     24|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     24|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  737|     24|	}
  738|  1.72k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (738:6): [True: 198, False: 1.52k]
  ------------------
  739|    198|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (739:7): [True: 0, False: 198]
  |  Branch (739:17): [True: 0, False: 0]
  |  Branch (739:30): [True: 0, False: 0]
  |  Branch (739:50): [True: 0, False: 0]
  ------------------
  740|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  741|      0|		}
  742|    198|		is_negative = 1;
  743|    198|		a |= 0xff^(*inbuf++);
  744|    198|		i = 1;
  745|  1.52k|	} else {
  746|  1.52k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (746:7): [True: 0, False: 1.52k]
  |  Branch (746:17): [True: 0, False: 0]
  |  Branch (746:30): [True: 0, False: 0]
  |  Branch (746:50): [True: 0, False: 0]
  ------------------
  747|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  748|      0|		}
  749|  1.52k|	}
  750|  4.39k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (750:9): [True: 2.66k, False: 1.72k]
  ------------------
  751|  2.66k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (751:7): [True: 0, False: 2.66k]
  |  Branch (751:29): [True: 0, False: 2.66k]
  ------------------
  752|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  753|      0|		}
  754|  2.66k|		a <<= 8;
  755|  2.66k|		if (is_negative) {
  ------------------
  |  Branch (755:7): [True: 211, False: 2.45k]
  ------------------
  756|    211|			a |= 0xff^(*inbuf++);
  757|  2.45k|		} else {
  758|  2.45k|			a |= *inbuf++;
  759|  2.45k|		}
  760|  2.66k|	}
  761|  1.72k|	if (is_negative) {
  ------------------
  |  Branch (761:6): [True: 198, False: 1.52k]
  ------------------
  762|       |		/* Calculate Two's complement from previously positive number */
  763|    198|		a = (-1 * a) - 1;
  764|    198|	}
  765|  1.72k|	*out = a;
  766|  1.72k|	return 0;
  767|  1.72k|}
sc_asn1_decode_object_id:
  828|  8.81k|{
  829|  8.81k|	int large_second_octet = 0;
  830|  8.81k|	unsigned int a = 0;
  831|  8.81k|	const u8 *p = inbuf;
  832|  8.81k|	int *octet;
  833|       |
  834|  8.81k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (834:6): [True: 468, False: 8.34k]
  |  Branch (834:20): [True: 3, False: 8.34k]
  |  Branch (834:37): [True: 0, False: 8.34k]
  ------------------
  835|    471|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    471|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  836|       |
  837|  8.34k|	sc_init_oid(id);
  838|  8.34k|	octet = id->value;
  839|       |
  840|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  841|  8.34k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   69|  8.34k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 4.99k, False: 3.34k]
  |  |  ------------------
  ------------------
  842|  8.34k|	*octet++ = a;
  843|       |
  844|       |	/* The second octet fits here if the previous was 0 or 1 and second one is smaller than 40.
  845|       |	 * for the value 2 we can go up to 47. Otherwise the first bit needs to be set
  846|       |	 * and we continue reading further */
  847|  8.34k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (847:6): [True: 6.52k, False: 1.82k]
  ------------------
  848|  6.52k|		*octet++ = *p - (a * 40);
  849|  6.52k|		inlen--;
  850|  6.52k|	} else {
  851|  1.82k|		large_second_octet = 1;
  852|  1.82k|	}
  853|       |
  854|  26.6k|	while (inlen) {
  ------------------
  |  Branch (854:9): [True: 20.3k, False: 6.36k]
  ------------------
  855|  20.3k|		if (!large_second_octet)
  ------------------
  |  Branch (855:7): [True: 18.4k, False: 1.82k]
  ------------------
  856|  18.4k|			p++;
  857|       |		/* This signalizes empty most significant bits, which means
  858|       |		 * the unsigned integer encoding is not minimal */
  859|  20.3k|		if (*p == 0x80) {
  ------------------
  |  Branch (859:7): [True: 506, False: 19.8k]
  ------------------
  860|    506|			sc_init_oid(id);
  861|    506|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    506|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  862|    506|		}
  863|       |		/* Use unsigned type here so we can process the whole INT range.
  864|       |		 * Values can not be negative */
  865|  19.8k|		a = *p & 0x7F;
  866|  19.8k|		inlen--;
  867|  29.0k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (867:10): [True: 22.9k, False: 6.11k]
  |  Branch (867:19): [True: 9.64k, False: 13.2k]
  ------------------
  868|       |			/* Limit the OID values to int size and do not overflow */
  869|  9.64k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (869:8): [True: 434, False: 9.20k]
  ------------------
  870|    434|				sc_init_oid(id);
  871|    434|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    434|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  872|    434|			}
  873|  9.20k|			p++;
  874|  9.20k|			a <<= 7;
  875|  9.20k|			a |= *p & 0x7F;
  876|  9.20k|			inlen--;
  877|  9.20k|		}
  878|  19.3k|		if (*p & 0x80) {
  ------------------
  |  Branch (878:7): [True: 645, False: 18.7k]
  ------------------
  879|       |			/* We dropped out from previous cycle on the end of
  880|       |			 * data while still expecting continuation of value */
  881|    645|			sc_init_oid(id);
  882|    645|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    645|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  883|    645|		}
  884|  18.7k|		if (large_second_octet) {
  ------------------
  |  Branch (884:7): [True: 1.57k, False: 17.1k]
  ------------------
  885|  1.57k|			a -= (2 * 40);
  886|  1.57k|		}
  887|  18.7k|		if (a > INT_MAX) {
  ------------------
  |  Branch (887:7): [True: 268, False: 18.4k]
  ------------------
  888|    268|			sc_init_oid(id);
  889|    268|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    268|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  890|    268|		}
  891|  18.4k|		*octet++ = a;
  892|  18.4k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  18.4k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (892:7): [True: 124, False: 18.3k]
  ------------------
  893|    124|			sc_init_oid(id);
  894|    124|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    124|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  895|    124|		}
  896|  18.3k|		large_second_octet = 0;
  897|  18.3k|	}
  898|       |
  899|  6.36k|	return 0;
  900|  8.34k|}
sc_asn1_encode_object_id:
  904|  5.47k|{
  905|  5.47k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  906|  5.47k|	int	i;
  907|       |
  908|  5.47k|	if (!buflen || !id)
  ------------------
  |  Branch (908:6): [True: 0, False: 5.47k]
  |  Branch (908:17): [True: 0, False: 5.47k]
  ------------------
  909|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  910|       |
  911|       |	/* an OID must have at least two components */
  912|  5.47k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (912:6): [True: 0, False: 5.47k]
  |  Branch (912:28): [True: 0, False: 5.47k]
  ------------------
  913|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  914|       |
  915|  34.1k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  34.1k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (915:14): [True: 34.1k, False: 0]
  ------------------
  916|  34.1k|		unsigned int k, shift;
  917|       |
  918|  34.1k|		if (id->value[i] == -1)
  ------------------
  |  Branch (918:7): [True: 5.47k, False: 28.6k]
  ------------------
  919|  5.47k|			break;
  920|       |
  921|  28.6k|		k = id->value[i];
  922|  28.6k|		switch (i) {
  923|  5.47k|		case 0:
  ------------------
  |  Branch (923:3): [True: 5.47k, False: 23.1k]
  ------------------
  924|  5.47k|			if (k > 2)
  ------------------
  |  Branch (924:8): [True: 0, False: 5.47k]
  ------------------
  925|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  926|  5.47k|			*p = k * 40;
  927|  5.47k|			break;
  928|  5.47k|		case 1:
  ------------------
  |  Branch (928:3): [True: 5.47k, False: 23.1k]
  ------------------
  929|  5.47k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (929:8): [True: 0, False: 5.47k]
  |  Branch (929:18): [True: 0, False: 0]
  ------------------
  930|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  931|      0|			}
  932|       |			/* We can encode larger IDs to multiple bytes
  933|       |			 * similarly as the following IDs */
  934|  5.47k|			k += *p;
  935|       |			/* fall through */
  936|  23.1k|		default:
  ------------------
  |  Branch (936:3): [True: 17.6k, False: 10.9k]
  ------------------
  937|  23.1k|			shift = 28;
  938|   111k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (938:11): [True: 92.4k, False: 19.0k]
  |  Branch (938:20): [True: 88.2k, False: 4.13k]
  ------------------
  939|  88.2k|				shift -= 7;
  940|  27.5k|			while (shift) {
  ------------------
  |  Branch (940:11): [True: 4.38k, False: 23.1k]
  ------------------
  941|  4.38k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  942|  4.38k|				shift -= 7;
  943|  4.38k|			}
  944|  23.1k|			*p++ = k & 0x7F;
  945|  23.1k|			break;
  946|  28.6k|		}
  947|  28.6k|	}
  948|       |
  949|  5.47k|	*buflen = p - temp;
  950|       |
  951|  5.47k|	if (buf)   {
  ------------------
  |  Branch (951:6): [True: 5.47k, False: 0]
  ------------------
  952|  5.47k|		*buf = malloc(*buflen);
  953|  5.47k|		if (!*buf)
  ------------------
  |  Branch (953:7): [True: 0, False: 5.47k]
  ------------------
  954|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  955|  5.47k|		memcpy(*buf, temp, *buflen);
  956|  5.47k|	}
  957|  5.47k|	return 0;
  958|  5.47k|}
sc_asn1_put_tag:
  975|  9.78k|{
  976|  9.78k|	size_t c = 0;
  977|  9.78k|	unsigned int tag_len, ii;
  978|  9.78k|	u8 *p = out;
  979|  9.78k|	u8 tag_char[4] = {0, 0, 0, 0};
  980|       |
  981|       |	/* Check tag */
  982|  9.78k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (982:6): [True: 0, False: 9.78k]
  |  Branch (982:18): [True: 0, False: 9.78k]
  ------------------
  983|       |		/* A tag of 0x00 is not valid and at most 4-byte tag names are supported. */
  984|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  985|      0|	}
  986|  19.5k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (986:20): [True: 9.78k, False: 9.78k]
  ------------------
  987|       |		/* Note: tag char will be reversed order. */
  988|  9.78k|		tag_char[tag_len++] = tag & 0xFF;
  989|  9.78k|	}
  990|       |
  991|  9.78k|	if (tag_len > 1)   {
  ------------------
  |  Branch (991:6): [True: 0, False: 9.78k]
  ------------------
  992|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (992:7): [True: 0, False: 0]
  ------------------
  993|       |			/* First byte is not escape marker. */
  994|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  995|      0|		}
  996|      0|		for (ii = 1; ii < tag_len - 1; ii++) {
  ------------------
  |  Branch (996:16): [True: 0, False: 0]
  ------------------
  997|      0|			if ((tag_char[ii] & 0x80) != 0x80) {
  ------------------
  |  Branch (997:8): [True: 0, False: 0]
  ------------------
  998|       |				/* MS bit is not 'one'. */
  999|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1000|      0|			}
 1001|      0|		}
 1002|      0|		if ((tag_char[0] & 0x80) != 0x00) {
  ------------------
  |  Branch (1002:7): [True: 0, False: 0]
  ------------------
 1003|       |			/* MS bit of the last byte is not 'zero'. */
 1004|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1005|      0|		}
 1006|      0|	}
 1007|       |
 1008|       |	/* Calculate the number of additional bytes necessary to encode the length. */
 1009|       |	/* c+1 is the size of the length field. */
 1010|  9.78k|	if (datalen > 127) {
  ------------------
  |  Branch (1010:6): [True: 18, False: 9.76k]
  ------------------
 1011|     18|		c = 1;
 1012|     33|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1012:10): [True: 15, False: 18]
  ------------------
 1013|     15|			c++;
 1014|     18|	}
 1015|  9.78k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1015:6): [True: 102, False: 9.67k]
  |  Branch (1015:21): [True: 0, False: 9.67k]
  ------------------
 1016|       |		/* Caller only asks for the length that would be written. */
 1017|    102|		return (int)(tag_len + (c + 1) + datalen);
 1018|    102|	}
 1019|       |	/* We will write the tag, so check the length. */
 1020|  9.67k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1020:6): [True: 0, False: 9.67k]
  ------------------
 1021|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1022|  19.3k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1022:12): [True: 9.67k, False: 9.67k]
  ------------------
 1023|  9.67k|		*p++ = tag_char[tag_len - ii - 1];
 1024|       |
 1025|  9.67k|	if (c > 0) {
  ------------------
  |  Branch (1025:6): [True: 12, False: 9.66k]
  ------------------
 1026|     12|		*p++ = 0x80 | c;
 1027|     34|		while (c--)
  ------------------
  |  Branch (1027:10): [True: 22, False: 12]
  ------------------
 1028|     22|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1029|     12|	}
 1030|  9.66k|	else {
 1031|  9.66k|		*p++ = datalen & 0x7F;
 1032|  9.66k|	}
 1033|  9.67k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1033:5): [True: 9.57k, False: 102]
  |  Branch (1033:13): [True: 9.57k, False: 0]
  ------------------
 1034|  9.57k|		memcpy(p, data, datalen);
 1035|  9.57k|		p += datalen;
 1036|  9.57k|	}
 1037|  9.67k|	if (ptr != NULL)
  ------------------
  |  Branch (1037:6): [True: 9.67k, False: 0]
  ------------------
 1038|  9.67k|		*ptr = p;
 1039|  9.67k|	return 0;
 1040|  9.67k|}
sc_asn1_decode:
 1813|  12.0k|{
 1814|  12.0k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1815|  12.0k|}
sc_asn1_decode_choice:
 1819|  1.37k|{
 1820|  1.37k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1821|  1.37k|}
sc_asn1_encode:
 2081|  8.52k|{
 2082|  8.52k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2083|  8.52k|}
_sc_asn1_encode:
 2087|  5.47k|{
 2088|  5.47k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2089|  5.47k|}
_sc_asn1_decode:
 2095|    934|{
 2096|    934|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2097|    934|}
sc_der_copy:
 2101|  1.02k|{
 2102|  1.02k|	if (!dst || !src)
  ------------------
  |  Branch (2102:6): [True: 0, False: 1.02k]
  |  Branch (2102:14): [True: 0, False: 1.02k]
  ------------------
 2103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2104|  1.02k|	memset(dst, 0, sizeof(*dst));
 2105|  1.02k|	if (src->len) {
  ------------------
  |  Branch (2105:6): [True: 1.01k, False: 5]
  ------------------
 2106|  1.01k|		if (!src->value)
  ------------------
  |  Branch (2106:7): [True: 0, False: 1.01k]
  ------------------
 2107|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2108|  1.01k|		dst->value = malloc(src->len);
 2109|  1.01k|		if (!dst->value)
  ------------------
  |  Branch (2109:7): [True: 0, False: 1.01k]
  ------------------
 2110|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2111|  1.01k|		dst->len = src->len;
 2112|  1.01k|		memcpy(dst->value, src->value, src->len);
 2113|  1.01k|	}
 2114|  1.02k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.02k|#define SC_SUCCESS				0
  ------------------
 2115|  1.02k|}
sc_encode_oid:
 2120|  5.10k|{
 2121|  5.10k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2122|  5.10k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  5.10k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  5.10k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  5.10k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2123|  5.10k|		{ NULL, 0, 0, 0, NULL, NULL }
 2124|  5.10k|	};
 2125|  5.10k|	struct sc_asn1_entry asn1_object_id[2];
 2126|  5.10k|	int rv;
 2127|       |
 2128|  5.10k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2129|  5.10k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2130|       |
 2131|  5.10k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2132|  5.10k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|  5.10k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.10k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.10k|	int _ret = (r); \
  |  |  |  |  168|  5.10k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 5.10k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  5.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2133|       |
 2134|  5.10k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.10k|#define SC_SUCCESS				0
  ------------------
 2135|  5.10k|}
sc_asn1_sig_value_rs_to_sequence:
 2155|      3|{
 2156|      3|	struct sc_asn1_entry asn1_sig_value[C_ASN1_SIG_VALUE_SIZE];
 2157|      3|	struct sc_asn1_entry asn1_sig_value_coefficients[C_ASN1_SIG_VALUE_COEFFICIENTS_SIZE];
 2158|      3|	unsigned char *r = in, *s = in + inlen/2;
 2159|      3|	size_t r_len = inlen/2, s_len = inlen/2;
 2160|      3|	int rv;
 2161|       |
 2162|      3|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      3|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      3|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      3|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      3|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2163|       |
 2164|       |	/* R/S are filled up with zeroes, we do not want that in sequence format */
 2165|     95|	while(r_len > 1 && *r == 0x00) {
  ------------------
  |  Branch (2165:8): [True: 93, False: 2]
  |  Branch (2165:21): [True: 92, False: 1]
  ------------------
 2166|     92|		r++;
 2167|     92|		r_len--;
 2168|     92|	}
 2169|     94|	while(s_len > 1 && *s == 0x00) {
  ------------------
  |  Branch (2169:8): [True: 93, False: 1]
  |  Branch (2169:21): [True: 91, False: 2]
  ------------------
 2170|     91|		s++;
 2171|     91|		s_len--;
 2172|     91|	}
 2173|       |
 2174|      3|	sc_copy_asn1_entry(c_asn1_sig_value, asn1_sig_value);
 2175|      3|	sc_format_asn1_entry(asn1_sig_value + 0, asn1_sig_value_coefficients, NULL, 1);
 2176|       |
 2177|      3|	sc_copy_asn1_entry(c_asn1_sig_value_coefficients, asn1_sig_value_coefficients);
 2178|      3|	sc_format_asn1_entry(asn1_sig_value_coefficients + 0, r, &r_len, 1);
 2179|      3|	sc_format_asn1_entry(asn1_sig_value_coefficients + 1, s, &s_len, 1);
 2180|       |
 2181|      3|	rv = sc_asn1_encode(ctx, asn1_sig_value, buf, buflen);
 2182|      3|	LOG_TEST_RET(ctx, rv, "ASN.1 encoding ECDSA-SIg-Value failed");
  ------------------
  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2183|       |
 2184|      3|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2185|      3|}
sc_asn1_decode_ecdsa_signature:
 2234|     17|int sc_asn1_decode_ecdsa_signature(sc_context_t *ctx, const u8 *data, size_t datalen, size_t fieldsize, u8 **out, size_t outlen) {
 2235|     17|	int i, r;
 2236|     17|	const unsigned char *pseq, *pint, *pend;
 2237|     17|	unsigned int cla, tag;
 2238|     17|	size_t seqlen, intlen;
 2239|       |
 2240|     17|	if (!ctx || !data || !out || !(*out)) {
  ------------------
  |  Branch (2240:6): [True: 0, False: 17]
  |  Branch (2240:14): [True: 0, False: 17]
  |  Branch (2240:23): [True: 0, False: 17]
  |  Branch (2240:31): [True: 0, False: 17]
  ------------------
 2241|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2242|      0|	}
 2243|     17|	if (outlen < 2 * fieldsize) {
  ------------------
  |  Branch (2243:6): [True: 0, False: 17]
  ------------------
 2244|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Output too small for EC signature");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2245|      0|	}
 2246|       |
 2247|     17|	memset(*out, 0, outlen);
 2248|       |
 2249|     17|	pseq = data;
 2250|     17|	r = sc_asn1_read_tag(&pseq, datalen, &cla, &tag, &seqlen);
 2251|     17|	if (pseq == NULL || r < 0 || seqlen == 0 || (cla | tag) != 0x30)
  ------------------
  |  Branch (2251:6): [True: 5, False: 12]
  |  Branch (2251:22): [True: 1, False: 11]
  |  Branch (2251:31): [True: 1, False: 10]
  |  Branch (2251:46): [True: 1, False: 9]
  ------------------
 2252|     17|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x30 tag");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2253|       |
 2254|      9|	pint = pseq;
 2255|      9|	pend = pseq + seqlen;
 2256|     20|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (2256:14): [True: 16, False: 4]
  ------------------
 2257|     16|		r = sc_asn1_read_tag(&pint, (pend - pint), &cla, &tag, &intlen);
 2258|     16|		if (pint == NULL || r < 0 || intlen == 0 || (cla | tag) != 0x02) {
  ------------------
  |  Branch (2258:7): [True: 1, False: 15]
  |  Branch (2258:23): [True: 1, False: 14]
  |  Branch (2258:32): [True: 2, False: 12]
  |  Branch (2258:47): [True: 1, False: 11]
  ------------------
 2259|      5|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      5|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2260|      5|			LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x02");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2261|      5|		}
 2262|       |
 2263|     11|		if (intlen == fieldsize + 1) { /* drop leading 00 if present */
  ------------------
  |  Branch (2263:7): [True: 0, False: 11]
  ------------------
 2264|      0|			if (*pint != 0x00) {
  ------------------
  |  Branch (2264:8): [True: 0, False: 0]
  ------------------
 2265|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2266|      0|				LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Signature too long");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2267|      0|			}
 2268|      0|			pint++;
 2269|      0|			intlen--;
 2270|      0|		}
 2271|     11|		if (intlen > fieldsize) {
  ------------------
  |  Branch (2271:7): [True: 0, False: 11]
  ------------------
 2272|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2273|      0|			LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Signature too long");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2274|      0|		}
 2275|     11|		memcpy(*out + fieldsize * i + fieldsize - intlen , pint, intlen);
 2276|     11|		pint += intlen; /* next integer */
 2277|     11|	}
 2278|      4|	r = (int)(2 * fieldsize);
 2279|      9|err:
 2280|      9|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      4|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      4|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      4|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2281|      9|}
asn1.c:decode_bit_string:
  573|  1.26k|{
  574|  1.26k|	const u8 *in = inbuf;
  575|  1.26k|	u8 *out = (u8 *) outbuf;
  576|  1.26k|	int i, count = 0;
  577|  1.26k|	int zero_bits;
  578|  1.26k|	size_t octets_left;
  579|       |
  580|  1.26k|	if (inlen < 1)
  ------------------
  |  Branch (580:6): [True: 4, False: 1.26k]
  ------------------
  581|      4|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  582|       |
  583|       |	/* The formatting is only enforced by SHALL keyword so we should accept
  584|       |	 * by default also non-strict values. */
  585|  1.26k|	if (strict) {
  ------------------
  |  Branch (585:6): [True: 0, False: 1.26k]
  ------------------
  586|       |		/* 8.6.2.3 If the bitstring is empty, there shall be no
  587|       |		 * subsequent octets,and the initial octet shall be zero. */
  588|      0|		if (inlen == 1 && *in != 0)
  ------------------
  |  Branch (588:7): [True: 0, False: 0]
  |  Branch (588:21): [True: 0, False: 0]
  ------------------
  589|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  590|       |		/* ITU-T Rec. X.690 8.6.2.2: The number shall be in the range zero to seven. */
  591|      0|		if ((*in & ~0x07) != 0)
  ------------------
  |  Branch (591:7): [True: 0, False: 0]
  ------------------
  592|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  593|      0|	}
  594|       |
  595|  1.26k|	memset(outbuf, 0, outlen);
  596|  1.26k|	zero_bits = *in & 0x07;
  597|  1.26k|	in++;
  598|  1.26k|	octets_left = inlen - 1;
  599|  1.26k|	if (outlen < octets_left)
  ------------------
  |  Branch (599:6): [True: 8, False: 1.25k]
  ------------------
  600|      8|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      8|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  601|       |
  602|  49.9k|	while (octets_left) {
  ------------------
  |  Branch (602:9): [True: 48.7k, False: 1.24k]
  ------------------
  603|       |		/* 1st octet of input:  ABCDEFGH, where A is the MSB */
  604|       |		/* 1st octet of output: HGFEDCBA, where A is the LSB */
  605|       |		/* first bit in bit string is the LSB in first resulting octet */
  606|  48.7k|		int bits_to_go;
  607|       |
  608|  48.7k|		*out = 0;
  609|  48.7k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (609:7): [True: 1.20k, False: 47.5k]
  |  Branch (609:27): [True: 641, False: 565]
  ------------------
  610|    641|			bits_to_go = 8 - zero_bits;
  611|       |			/* Verify the padding is zero bits */
  612|    641|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (612:8): [True: 15, False: 626]
  ------------------
  613|     15|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     15|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  614|     15|			}
  615|    641|		} else
  616|  48.0k|			bits_to_go = 8;
  617|  48.7k|		if (invert)
  ------------------
  |  Branch (617:7): [True: 1.64k, False: 47.0k]
  ------------------
  618|  13.6k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (618:16): [True: 12.0k, False: 1.64k]
  ------------------
  619|  12.0k|				*out |= ((*in >> (7 - i)) & 1) << i;
  620|  12.0k|			}
  621|  47.0k|		else {
  622|  47.0k|			*out = *in;
  623|  47.0k|		}
  624|  48.7k|		out++;
  625|  48.7k|		in++;
  626|  48.7k|		octets_left--;
  627|  48.7k|		count++;
  628|  48.7k|	}
  629|  1.24k|	return (count * 8) - zero_bits;
  630|  1.25k|}
asn1.c:asn1_write_element:
 1050|  15.7k|{
 1051|  15.7k|	unsigned char t;
 1052|  15.7k|	unsigned char *buf, *p;
 1053|  15.7k|	int c = 0;
 1054|  15.7k|	unsigned short_tag;
 1055|  15.7k|	unsigned char tag_char[3] = {0, 0, 0};
 1056|  15.7k|	size_t tag_len, ii;
 1057|       |
 1058|  15.7k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|  15.7k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1059|  31.4k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1059:20): [True: 15.7k, False: 15.7k]
  ------------------
 1060|  15.7k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1061|  15.7k|	if (!tag_len)
  ------------------
  |  Branch (1061:6): [True: 0, False: 15.7k]
  ------------------
 1062|      0|		tag_len = 1;
 1063|       |
 1064|  15.7k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1064:6): [True: 0, False: 15.7k]
  ------------------
 1065|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (1065:7): [True: 0, False: 0]
  ------------------
 1066|      0|			SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "First byte of the long tag is not 'escape marker'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1067|       |
 1068|      0|		for (ii = 1; ii < tag_len - 1; ii++)
  ------------------
  |  Branch (1068:16): [True: 0, False: 0]
  ------------------
 1069|      0|			if (!(tag_char[ii] & 0x80))
  ------------------
  |  Branch (1069:8): [True: 0, False: 0]
  ------------------
 1070|      0|				SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "MS bit expected to be 'one'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1071|       |
 1072|      0|		if (tag_char[0] & 0x80)
  ------------------
  |  Branch (1072:7): [True: 0, False: 0]
  ------------------
 1073|      0|			SC_TEST_RET(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_INVALID_DATA, "MS bit of the last byte expected to be 'zero'");
  ------------------
  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  167|      0|	int _ret = (r); \
  |  |  168|      0|	if (_ret < 0) { \
  |  |  ------------------
  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  171|      0|		return _ret; \
  |  |  172|      0|	} \
  |  |  173|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1074|      0|	}
 1075|       |
 1076|  15.7k|	t = tag_char[tag_len - 1] & 0x1F;
 1077|       |
 1078|  15.7k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|  15.7k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1078:10): [True: 15.7k, False: 0]
  ------------------
 1079|  9.00k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|  9.00k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1079:2): [True: 9.00k, False: 6.69k]
  ------------------
 1080|  9.00k|		break;
 1081|  6.69k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  6.69k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1081:2): [True: 6.69k, False: 9.00k]
  ------------------
 1082|  6.69k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  6.69k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1083|  6.69k|		break;
 1084|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  139|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1084:2): [True: 0, False: 15.7k]
  ------------------
 1085|      0|		t |= SC_ASN1_TAG_CONTEXT;
  ------------------
  |  |  187|      0|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
 1086|      0|		break;
 1087|      0|	case SC_ASN1_PRV:
  ------------------
  |  |  140|      0|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (1087:2): [True: 0, False: 15.7k]
  ------------------
 1088|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1089|      0|		break;
 1090|  15.7k|	}
 1091|  15.7k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|  15.7k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1091:6): [True: 1.80k, False: 13.8k]
  ------------------
 1092|  1.80k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|  1.80k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1093|  15.7k|	if (datalen > 127) {
  ------------------
  |  Branch (1093:6): [True: 1.05k, False: 14.6k]
  ------------------
 1094|  1.05k|		c = 1;
 1095|  1.13k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1095:10): [True: 80, False: 1.05k]
  ------------------
 1096|     80|			c++;
 1097|  1.05k|	}
 1098|       |
 1099|  15.7k|	*outlen = tag_len + 1 + c + datalen;
 1100|  15.7k|	buf = malloc(*outlen);
 1101|  15.7k|	if (buf == NULL)
  ------------------
  |  Branch (1101:6): [True: 0, False: 15.7k]
  ------------------
 1102|      0|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1103|       |
 1104|  15.7k|	*out = p = buf;
 1105|  15.7k|	*p++ = t;
 1106|  15.7k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1106:12): [True: 0, False: 15.7k]
  ------------------
 1107|      0|		*p++ = tag_char[tag_len - ii - 1];
 1108|       |
 1109|  15.7k|	if (c) {
  ------------------
  |  Branch (1109:6): [True: 1.05k, False: 14.6k]
  ------------------
 1110|  1.05k|		*p++ = 0x80 | c;
 1111|  2.19k|		while (c--)
  ------------------
  |  Branch (1111:10): [True: 1.13k, False: 1.05k]
  ------------------
 1112|  1.13k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1113|  1.05k|	}
 1114|  14.6k|	else   {
 1115|  14.6k|		*p++ = datalen & 0x7F;
 1116|  14.6k|	}
 1117|  15.7k|	if (datalen && data) {
  ------------------
  |  Branch (1117:6): [True: 15.4k, False: 265]
  |  Branch (1117:17): [True: 15.4k, False: 0]
  ------------------
 1118|  15.4k|		memcpy(p, data, datalen);
 1119|  15.4k|	}
 1120|       |
 1121|  15.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.7k|#define SC_SUCCESS				0
  ------------------
 1122|  15.7k|}
asn1.c:asn1_decode:
 1722|  20.2k|{
 1723|  20.2k|	int r, idx = 0;
 1724|  20.2k|	const u8 *p = in, *obj;
 1725|  20.2k|	struct sc_asn1_entry *entry = asn1;
 1726|  20.2k|	size_t left = len, objlen;
 1727|       |
 1728|  20.2k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*s""called, left=%zu, depth %d%s",
  ------------------
  |  |   70|  40.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 1.60k, False: 18.6k]
  |  |  ------------------
  ------------------
 1729|  20.2k|			depth, depth, "", left, depth, choice ? ", choice" : "");
 1730|       |
 1731|  20.2k|	if (!p)
  ------------------
  |  Branch (1731:6): [True: 6, False: 20.2k]
  ------------------
 1732|      6|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      6|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1733|  20.2k|	if (left < 2) {
  ------------------
  |  Branch (1733:6): [True: 1.34k, False: 18.9k]
  ------------------
 1734|  3.08k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|  2.29k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1734:10): [True: 2.29k, False: 789]
  |  Branch (1734:24): [True: 1.73k, False: 560]
  ------------------
 1735|  1.73k|			asn1++;
 1736|       |		/* If all elements were optional, there's nothing
 1737|       |		 * to complain about */
 1738|  1.34k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1738:7): [True: 789, False: 560]
  ------------------
 1739|    789|			return 0;
 1740|    560|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    560|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1741|    560|			      "non-optional field \"%s\" not found\n",
 1742|    560|			      asn1->name);
 1743|    560|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    560|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1744|  1.34k|	}
 1745|  18.9k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1745:6): [True: 800, False: 18.1k]
  |  Branch (1745:19): [True: 227, False: 17.9k]
  |  Branch (1745:35): [True: 0, False: 17.9k]
  ------------------
 1746|  1.02k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.02k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1747|       |
 1748|  62.7k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1748:16): [True: 49.4k, False: 13.3k]
  ------------------
 1749|  49.4k|		entry = &asn1[idx];
 1750|       |
 1751|  49.4k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|  49.4k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  | 1752|  49.4k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1753|  49.4k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  49.4k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1752|  49.4k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1753|  49.4k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1754|       |
 1755|       |		/* Special case CHOICE has no tag */
 1756|  49.4k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  49.4k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1756:7): [True: 232, False: 49.2k]
  ------------------
 1757|    232|			r = asn1_decode(ctx,
 1758|    232|				(struct sc_asn1_entry *) entry->parm,
 1759|    232|				p, left, &p, &left, 1, depth + 1);
 1760|       |			/* When the inner call fails it returns before writing
 1761|       |			 * back to *newp and *len_left, so the caller's p/left are
 1762|       |			 * unchanged.  Swallowing the error for an optional
 1763|       |			 * CHOICE is therefore safe: the next field will be
 1764|       |			 * attempted at the same position. */
 1765|    232|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|    104|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1765:8): [True: 128, False: 104]
  |  Branch (1765:18): [True: 1, False: 103]
  ------------------
 1766|    129|				r = 0;
 1767|    232|			goto decode_ok;
 1768|    232|		}
 1769|       |
 1770|  49.2k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1771|  49.2k|		if (obj == NULL) {
  ------------------
  |  Branch (1771:7): [True: 27.2k, False: 21.9k]
  ------------------
 1772|  27.2k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  27.2k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1773|  27.2k|			if (choice)
  ------------------
  |  Branch (1773:8): [True: 4.99k, False: 22.2k]
  ------------------
 1774|  4.99k|				continue;
 1775|  22.2k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  22.2k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1775:8): [True: 19.7k, False: 2.48k]
  ------------------
 1776|  19.7k|				continue;
 1777|  2.48k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  2.48k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1778|  2.48k|			if (left) {
  ------------------
  |  Branch (1778:8): [True: 2.43k, False: 53]
  ------------------
 1779|  2.43k|				u8 line[128], *linep = line;
 1780|  2.43k|				size_t i;
 1781|       |
 1782|  2.43k|				line[0] = 0;
 1783|  18.9k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1783:17): [True: 17.6k, False: 1.31k]
  |  Branch (1783:27): [True: 16.4k, False: 1.11k]
  ------------------
 1784|  16.4k|					sprintf((char *) linep, "%02X ", p[i]);
 1785|  16.4k|					linep += 3;
 1786|  16.4k|				}
 1787|  2.43k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  2.43k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1788|  2.43k|			}
 1789|  2.48k|			sc_free_entry(asn1);
 1790|  2.48k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  2.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.48k|	int _ret = r; \
  |  |  155|  2.48k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.48k, False: 0]
  |  |  ------------------
  |  |  156|  2.48k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  2.48k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.48k, False: 0]
  |  |  ------------------
  |  |  157|  2.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.48k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.48k|	return _ret; \
  |  |  163|  2.48k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1791|  2.48k|		}
 1792|  21.9k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1793|       |
 1794|  22.1k|decode_ok:
 1795|  22.1k|		if (r)
  ------------------
  |  Branch (1795:7): [True: 944, False: 21.2k]
  ------------------
 1796|    944|			return r;
 1797|  21.2k|		if (choice)
  ------------------
  |  Branch (1797:7): [True: 1.14k, False: 20.0k]
  ------------------
 1798|  1.14k|			break;
 1799|  21.2k| 	}
 1800|  14.4k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1800:7): [True: 1.29k, False: 13.1k]
  |  Branch (1800:17): [True: 151, False: 1.14k]
  ------------------
 1801|    151|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|    151|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    151|	int _ret = r; \
  |  |  155|    151|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 151, False: 0]
  |  |  ------------------
  |  |  156|    151|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    151|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 151, False: 0]
  |  |  ------------------
  |  |  157|    151|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    151|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    151|	return _ret; \
  |  |  163|    151|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1802|  14.3k| 	if (newp != NULL)
  ------------------
  |  Branch (1802:7): [True: 2.68k, False: 11.6k]
  ------------------
 1803|  2.68k|		*newp = p;
 1804|  14.3k| 	if (len_left != NULL)
  ------------------
  |  Branch (1804:7): [True: 2.68k, False: 11.6k]
  ------------------
 1805|  2.68k|		*len_left = left;
 1806|  14.3k|	if (choice)
  ------------------
  |  Branch (1806:6): [True: 1.14k, False: 13.1k]
  ------------------
 1807|  1.14k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|  1.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.14k|	int _ret = r; \
  |  |  155|  1.14k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 337, False: 810]
  |  |  ------------------
  |  |  156|    337|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 337]
  |  |  ------------------
  |  |  157|    337|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    810|	} else { \
  |  |  159|    810|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    810|			"returning with: %d\n", _ret); \
  |  |  161|    810|	} \
  |  |  162|  1.14k|	return _ret; \
  |  |  163|  1.14k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1808|  13.1k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  13.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  13.1k|	int _ret = r; \
  |  |  155|  13.1k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 13.1k, False: 0]
  |  |  ------------------
  |  |  156|  13.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 13.1k]
  |  |  ------------------
  |  |  157|  13.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  13.1k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  13.1k|	return _ret; \
  |  |  163|  13.1k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1809|  13.1k|}
asn1.c:sc_free_entry:
 1687|  11.2k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1688|  11.2k|	int idx = 0;
 1689|  11.2k|	struct sc_asn1_entry *entry = asn1;
 1690|       |
 1691|  11.2k|	if (!asn1)
  ------------------
  |  Branch (1691:6): [True: 424, False: 10.7k]
  ------------------
 1692|    424|		return;
 1693|       |
 1694|  52.0k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1694:16): [True: 41.2k, False: 10.7k]
  ------------------
 1695|  41.2k|		entry = &asn1[idx];
 1696|  41.2k|		switch (entry->type) {
 1697|  3.03k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  3.03k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1697:3): [True: 3.03k, False: 38.1k]
  ------------------
 1698|  8.73k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  8.73k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1698:3): [True: 5.69k, False: 35.5k]
  ------------------
 1699|  8.73k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1700|  8.73k|			break;
 1701|  7.08k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  7.08k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1701:3): [True: 7.08k, False: 34.1k]
  ------------------
 1702|  7.11k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  7.11k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1702:3): [True: 31, False: 41.2k]
  ------------------
 1703|  7.15k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  7.15k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1703:3): [True: 42, False: 41.1k]
  ------------------
 1704|  7.35k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  7.35k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1704:3): [True: 191, False: 41.0k]
  ------------------
 1705|  7.59k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  7.59k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1705:3): [True: 241, False: 40.9k]
  ------------------
 1706|  9.54k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  9.54k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1706:3): [True: 1.94k, False: 39.2k]
  ------------------
 1707|  9.54k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  9.54k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    738|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1707:8): [True: 738, False: 8.80k]
  |  Branch (1707:42): [True: 159, False: 579]
  ------------------
 1708|    159|				u8 **buf = (u8 **)entry->parm;
 1709|    159|				free(*buf);
 1710|    159|				*buf = NULL;
 1711|    159|			}
 1712|  9.54k|			break;
 1713|  22.9k|		default:
  ------------------
  |  Branch (1713:3): [True: 22.9k, False: 18.2k]
  ------------------
 1714|  22.9k|			break;
 1715|  41.2k|		}
 1716|  41.2k|	}
 1717|  10.7k|}
asn1.c:asn1_decode_entry:
 1485|  21.9k|{
 1486|  21.9k|	void *parm = entry->parm;
 1487|  21.9k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1488|  21.9k|			     size_t nobjlen, int ndepth);
 1489|  21.9k|	size_t *len = (size_t *) entry->arg;
 1490|  21.9k|	int r = 0;
 1491|       |
 1492|  21.9k|	callback_func = parm;
 1493|       |
 1494|  21.9k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|  87.8k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 6.03k, False: 15.9k]
  |  |  |  Branch (70:115): [True: 6.03k, False: 15.9k]
  |  |  ------------------
  ------------------
 1495|  21.9k|		depth, depth, "", entry->name,
 1496|  21.9k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1497|  21.9k|		objlen > 16 ? "..." : "");
 1498|       |
 1499|  21.9k|	switch (entry->type) {
 1500|  5.59k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  5.59k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1500:2): [True: 5.59k, False: 16.3k]
  ------------------
 1501|  5.59k|		if (parm != NULL)
  ------------------
  |  Branch (1501:7): [True: 4.45k, False: 1.14k]
  ------------------
 1502|  4.45k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1503|  4.45k|				       objlen, NULL, NULL, 0, depth + 1);
 1504|  5.59k|		break;
 1505|    545|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    545|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1505:2): [True: 545, False: 21.4k]
  ------------------
 1506|    545|		break;
 1507|    115|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|    115|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1507:2): [True: 115, False: 21.8k]
  ------------------
 1508|    115|		if (parm != NULL) {
  ------------------
  |  Branch (1508:7): [True: 115, False: 0]
  ------------------
 1509|    115|			if (objlen != 1) {
  ------------------
  |  Branch (1509:8): [True: 1, False: 114]
  ------------------
 1510|      1|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 object length: %zu", objlen);
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1511|      1|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1512|      1|			} else
 1513|    114|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1513:23): [True: 111, False: 3]
  ------------------
 1514|    115|		}
 1515|    115|		break;
 1516|  1.64k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  1.64k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1516:2): [True: 1.64k, False: 20.3k]
  ------------------
 1517|  1.76k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  1.76k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1517:2): [True: 122, False: 21.8k]
  ------------------
 1518|  1.76k|		if (parm != NULL) {
  ------------------
  |  Branch (1518:7): [True: 1.76k, False: 1]
  ------------------
 1519|  1.76k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1520|  1.76k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.76k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1520:8): [True: 1.72k, False: 36]
  ------------------
 1521|  1.72k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  1.72k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1522|  1.72k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1523|  1.72k|			}
 1524|  1.76k|		}
 1525|  1.76k|		break;
 1526|    492|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    492|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1526:2): [True: 492, False: 21.4k]
  ------------------
 1527|    858|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    858|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1527:2): [True: 366, False: 21.5k]
  ------------------
 1528|    858|		if (parm != NULL) {
  ------------------
  |  Branch (1528:7): [True: 492, False: 366]
  ------------------
 1529|    492|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|    492|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1529:17): [True: 0, False: 492]
  ------------------
 1530|    492|			if (len == NULL)
  ------------------
  |  Branch (1530:8): [True: 0, False: 492]
  ------------------
 1531|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1532|    492|			if (objlen < 1) {
  ------------------
  |  Branch (1532:8): [True: 11, False: 481]
  ------------------
 1533|     11|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     11|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1534|     11|				break;
 1535|     11|			}
 1536|    481|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    481|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1536:8): [True: 481, False: 0]
  ------------------
 1537|    481|				u8 **buf = (u8 **) parm;
 1538|    481|				if (objlen > 1) {
  ------------------
  |  Branch (1538:9): [True: 458, False: 23]
  ------------------
 1539|    458|					*buf = malloc(objlen-1);
 1540|    458|					if (*buf == NULL) {
  ------------------
  |  Branch (1540:10): [True: 0, False: 458]
  ------------------
 1541|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1542|      0|						break;
 1543|      0|					}
 1544|    458|				} else {
 1545|     23|					*buf = NULL;
 1546|     23|				}
 1547|    481|				*len = objlen-1;
 1548|    481|				parm = *buf;
 1549|    481|			}
 1550|    481|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1551|    481|			if (r >= 0) {
  ------------------
  |  Branch (1551:8): [True: 462, False: 19]
  ------------------
 1552|    462|				*len = r;
 1553|    462|				r = 0;
 1554|    462|			}
 1555|    481|		}
 1556|    847|		break;
 1557|    847|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|    786|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1557:2): [True: 786, False: 21.1k]
  ------------------
 1558|    786|		if (parm != NULL)
  ------------------
  |  Branch (1558:7): [True: 786, False: 0]
  ------------------
 1559|    786|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1560|    786|		break;
 1561|  7.80k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  7.80k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1561:2): [True: 7.80k, False: 14.1k]
  ------------------
 1562|  7.80k|		if (parm != NULL) {
  ------------------
  |  Branch (1562:7): [True: 6.91k, False: 891]
  ------------------
 1563|  6.91k|			size_t c;
 1564|  6.91k|			if (len == NULL)
  ------------------
  |  Branch (1564:8): [True: 0, False: 6.91k]
  ------------------
 1565|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1566|       |
 1567|       |			/* Strip off padding zero */
 1568|  6.91k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  6.91k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1568:8): [True: 1.67k, False: 5.23k]
  ------------------
 1569|  1.67k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1569:9): [True: 1.60k, False: 68]
  |  Branch (1569:23): [True: 825, False: 779]
  ------------------
 1570|    825|				objlen--;
 1571|    825|				obj++;
 1572|    825|			}
 1573|       |
 1574|       |			/* Allocate buffer if needed */
 1575|  6.91k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  6.91k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1575:8): [True: 3.89k, False: 3.01k]
  ------------------
 1576|  3.89k|				u8 **buf = (u8 **) parm;
 1577|  3.89k|				if (objlen > 0) {
  ------------------
  |  Branch (1577:9): [True: 3.73k, False: 164]
  ------------------
 1578|  3.73k|					*buf = malloc(objlen);
 1579|  3.73k|					if (*buf == NULL) {
  ------------------
  |  Branch (1579:10): [True: 0, False: 3.73k]
  ------------------
 1580|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1581|      0|						break;
 1582|      0|					}
 1583|  3.73k|				} else {
 1584|    164|					*buf = NULL;
 1585|    164|				}
 1586|  3.89k|				c = *len = objlen;
 1587|  3.89k|				parm = *buf;
 1588|  3.89k|			} else
 1589|  3.01k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1589:9): [True: 137, False: 2.87k]
  ------------------
 1590|       |
 1591|  6.91k|			memcpy(parm, obj, c);
 1592|  6.91k|			*len = c;
 1593|  6.91k|		}
 1594|  7.80k|		break;
 1595|  7.80k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      2|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1595:2): [True: 2, False: 21.9k]
  ------------------
 1596|      2|		if (parm != NULL) {
  ------------------
  |  Branch (1596:7): [True: 1, False: 1]
  ------------------
 1597|      1|			size_t c;
 1598|      1|			if (len == NULL)
  ------------------
  |  Branch (1598:8): [True: 0, False: 1]
  ------------------
 1599|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1600|      1|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|      1|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1600:8): [True: 0, False: 1]
  ------------------
 1601|      0|				u8 **buf = (u8 **) parm;
 1602|      0|				if (objlen > 0) {
  ------------------
  |  Branch (1602:9): [True: 0, False: 0]
  ------------------
 1603|      0|					*buf = malloc(objlen);
 1604|      0|					if (*buf == NULL) {
  ------------------
  |  Branch (1604:10): [True: 0, False: 0]
  ------------------
 1605|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1606|      0|						break;
 1607|      0|					}
 1608|      0|				} else {
 1609|      0|					*buf = NULL;
 1610|      0|				}
 1611|      0|				c = *len = objlen;
 1612|      0|				parm = *buf;
 1613|      0|			} else
 1614|      1|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1614:9): [True: 0, False: 1]
  ------------------
 1615|       |
 1616|      1|			memcpy(parm, obj, c);
 1617|      1|			*len = c;
 1618|      1|		}
 1619|      2|		break;
 1620|  1.47k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  1.47k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1620:2): [True: 1.47k, False: 20.4k]
  ------------------
 1621|  1.47k|		if (parm != NULL)
  ------------------
  |  Branch (1621:7): [True: 1.47k, False: 5]
  ------------------
 1622|  1.47k|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1623|  1.47k|		break;
 1624|      3|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      3|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1624:2): [True: 3, False: 21.9k]
  ------------------
 1625|    172|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|    172|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1625:2): [True: 169, False: 21.7k]
  ------------------
 1626|    172|		if (parm != NULL) {
  ------------------
  |  Branch (1626:7): [True: 171, False: 1]
  ------------------
 1627|    171|			if (len == NULL)
  ------------------
  |  Branch (1627:8): [True: 0, False: 171]
  ------------------
 1628|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1629|    171|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    171|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1629:8): [True: 0, False: 171]
  ------------------
 1630|      0|				u8 **buf = (u8 **) parm;
 1631|      0|				*buf = malloc(objlen+1);
 1632|      0|				if (*buf == NULL) {
  ------------------
  |  Branch (1632:9): [True: 0, False: 0]
  ------------------
 1633|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1634|      0|					break;
 1635|      0|				}
 1636|      0|				*len = objlen+1;
 1637|      0|				parm = *buf;
 1638|      0|			}
 1639|    171|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1640|    171|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    171|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1640:8): [True: 0, False: 171]
  ------------------
 1641|      0|				*len -= 1;
 1642|      0|			}
 1643|    171|		}
 1644|    172|		break;
 1645|    947|	case SC_ASN1_PATH:
  ------------------
  |  |  174|    947|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1645:2): [True: 947, False: 21.0k]
  ------------------
 1646|    947|		if (entry->parm != NULL)
  ------------------
  |  Branch (1646:7): [True: 947, False: 0]
  ------------------
 1647|    947|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1648|    947|		break;
 1649|    160|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|    160|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1649:2): [True: 160, False: 21.7k]
  ------------------
 1650|    160|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1650:7): [True: 160, False: 0]
  ------------------
 1651|    160|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1652|    160|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1652:15): [True: 0, False: 160]
  ------------------
 1653|       |
 1654|    160|			memcpy(id->value, obj, c);
 1655|    160|			id->len = c;
 1656|    160|		}
 1657|    160|		break;
 1658|    180|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|    180|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1658:2): [True: 180, False: 21.7k]
  ------------------
 1659|    180|		if (entry->parm != NULL)
  ------------------
  |  Branch (1659:7): [True: 178, False: 2]
  ------------------
 1660|    178|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1661|    180|		break;
 1662|    934|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    934|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1662:2): [True: 934, False: 21.0k]
  ------------------
 1663|    934|		if (entry->parm != NULL)
  ------------------
  |  Branch (1663:7): [True: 934, False: 0]
  ------------------
 1664|    934|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1665|    934|		break;
 1666|     36|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|     36|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1666:2): [True: 36, False: 21.9k]
  ------------------
 1667|     36|		if (entry->parm != NULL)
  ------------------
  |  Branch (1667:7): [True: 36, False: 0]
  ------------------
 1668|     36|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1669|     36|		break;
 1670|    579|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|    579|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1670:2): [True: 579, False: 21.3k]
  ------------------
 1671|    579|		if (entry->parm != NULL)
  ------------------
  |  Branch (1671:7): [True: 579, False: 0]
  ------------------
 1672|    579|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1673|    579|		break;
 1674|      0|	default:
  ------------------
  |  Branch (1674:2): [True: 0, False: 21.9k]
  ------------------
 1675|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 type: %d\n", entry->type);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1676|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1677|  21.9k|	}
 1678|  21.9k|	if (r) {
  ------------------
  |  Branch (1678:6): [True: 841, False: 21.1k]
  ------------------
 1679|    841|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|    841|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1680|    841|		      sc_strerror(r));
 1681|    841|		return r;
 1682|    841|	}
 1683|  21.1k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  21.1k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1684|  21.1k|	return 0;
 1685|  21.9k|}
asn1.c:decode_bit_field:
  686|    786|{
  687|    786|	u8		data[sizeof(unsigned int)];
  688|    786|	unsigned int	field = 0;
  689|    786|	int		i, n;
  690|       |
  691|    786|	if (outlen != sizeof(data))
  ------------------
  |  Branch (691:6): [True: 0, False: 786]
  ------------------
  692|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  693|       |
  694|    786|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  695|    786|	if (n < 0)
  ------------------
  |  Branch (695:6): [True: 41, False: 745]
  ------------------
  696|     41|		return n;
  697|       |
  698|  2.38k|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (698:14): [True: 1.63k, False: 745]
  ------------------
  699|  1.63k|		field |= ((unsigned int) data[i/8] << i);
  700|  1.63k|	}
  701|    745|	memcpy(outbuf, &field, outlen);
  702|    745|	return 0;
  703|    786|}
asn1.c:sc_asn1_decode_utf8string:
  962|    171|{
  963|    171|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (963:6): [True: 0, False: 171]
  ------------------
  964|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  965|    171|	*outlen = inlen+1;
  966|    171|	memcpy(out, inbuf, inlen);
  967|    171|	out[inlen] = 0;
  968|    171|	return 0;
  969|    171|}
asn1.c:asn1_decode_path:
 1144|    947|{
 1145|    947|	int idx, count, r;
 1146|    947|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1147|    947|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1148|    947|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1149|       |
 1150|    947|	memset(path, 0, sizeof(struct sc_path));
 1151|       |
 1152|    947|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1153|    947|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1154|       |
 1155|    947|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1156|    947|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1157|       |
 1158|    947|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1159|    947|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1160|    947|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1161|    947|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1162|       |
 1163|    947|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1164|    947|	if (r)
  ------------------
  |  Branch (1164:6): [True: 21, False: 926]
  ------------------
 1165|     21|		return r;
 1166|       |
 1167|    926|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    926|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1167:6): [True: 0, False: 926]
  ------------------
 1168|       |		/* extended path present: set 'path' and 'aid' */
 1169|      0|		memcpy(path->aid.value, aid_value, aid_len);
 1170|      0|		path->aid.len = aid_len;
 1171|       |
 1172|      0|		memcpy(path->value, path_value, path_len);
 1173|      0|		path->len = path_len;
 1174|      0|	}
 1175|    926|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    926|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1175:11): [True: 886, False: 40]
  ------------------
 1176|       |		/* path present: set 'path' */
 1177|    886|		memcpy(path->value, path_value, path_len);
 1178|    886|		path->len = path_len;
 1179|    886|	}
 1180|     40|	else   {
 1181|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1182|     40|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     40|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1183|     40|	}
 1184|       |
 1185|    886|	if (path->len == 2)
  ------------------
  |  Branch (1185:6): [True: 81, False: 805]
  ------------------
 1186|     81|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     81|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1187|    805|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1187:13): [True: 0, False: 805]
  |  Branch (1187:30): [True: 0, False: 0]
  ------------------
 1188|      0|		path->type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 1189|    805|	else
 1190|    805|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    805|#define SC_PATH_TYPE_PATH		2
  ------------------
 1191|       |
 1192|    886|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    886|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      8|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1192:6): [True: 8, False: 878]
  |  Branch (1192:48): [True: 1, False: 7]
  ------------------
 1193|      1|		path->index = idx;
 1194|      1|		path->count = count;
 1195|      1|	}
 1196|    885|	else {
 1197|    885|		path->index = 0;
 1198|    885|		path->count = -1;
 1199|    885|	}
 1200|       |
 1201|    886|	return SC_SUCCESS;
  ------------------
  |  |   28|    886|#define SC_SUCCESS				0
  ------------------
 1202|    926|}
asn1.c:asn1_decode_p15_object:
 1390|    178|{
 1391|    178|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1392|    178|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1393|    178|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1394|    178|	size_t flags_len = sizeof(p15_obj->flags);
 1395|    178|	size_t label_len = sizeof(p15_obj->label);
 1396|    178|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1397|    178|	int r, ii;
 1398|       |
 1399|  1.60k|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|  1.60k|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1399:13): [True: 1.42k, False: 178]
  ------------------
 1400|  1.42k|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1401|    178|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1402|       |
 1403|       |
 1404|    178|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1405|    178|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1406|    178|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1407|    178|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1408|    178|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1409|    178|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1410|       |
 1411|  1.60k|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|  1.60k|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1411:13): [True: 1.42k, False: 178]
  ------------------
 1412|  1.42k|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1413|  1.42k|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1414|  1.42k|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1415|  1.42k|	}
 1416|    178|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1417|       |
 1418|    178|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1419|    178|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1420|    178|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1421|    178|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1422|       |
 1423|    178|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1424|    178|	return r;
 1425|    178|}
asn1.c:asn1_decode_se_info:
 1238|     36|{
 1239|     36|	struct sc_pkcs15_sec_env_info **ses;
 1240|     36|	const unsigned char *ptr = obj;
 1241|     36|	size_t idx, ptrlen = objlen;
 1242|     36|	int ret;
 1243|       |
 1244|     36|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     36|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     36|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     36|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     36|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1245|       |
 1246|     36|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     36|#define SC_MAX_SE_NUM			8
  ------------------
 1247|     36|	if (ses == NULL) {
  ------------------
  |  Branch (1247:6): [True: 0, False: 36]
  ------------------
 1248|      0|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1249|      0|	}
 1250|       |
 1251|     89|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|    178|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1251:14): [True: 89, False: 0]
  |  Branch (1251:37): [True: 70, False: 19]
  ------------------
 1252|     70|		struct sc_asn1_entry asn1_se[2];
 1253|     70|		struct sc_asn1_entry asn1_se_info[4];
 1254|     70|		struct sc_pkcs15_sec_env_info si;
 1255|       |
 1256|     70|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1257|     70|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1258|       |
 1259|     70|		si.aid.len = sizeof(si.aid.value);
 1260|     70|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1261|     70|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1262|     70|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1263|     70|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1264|       |
 1265|     70|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1266|     70|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     70|#define SC_SUCCESS				0
  ------------------
  |  Branch (1266:7): [True: 17, False: 53]
  ------------------
 1267|     17|			goto err;
 1268|     53|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|     53|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1268:7): [True: 43, False: 10]
  ------------------
 1269|     43|			sc_init_oid(&si.owner);
 1270|       |
 1271|     53|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1272|     53|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1272:7): [True: 0, False: 53]
  ------------------
 1273|      0|			ret = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1274|      0|			goto err;
 1275|      0|		}
 1276|       |
 1277|     53|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1278|     53|		idx++;
 1279|     53|	}
 1280|       |
 1281|     19|	*se  = ses;
 1282|     19|	*num = idx;
 1283|     19|	ret = SC_SUCCESS;
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
 1284|     36|err:
 1285|     36|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     36|#define SC_SUCCESS				0
  ------------------
  |  Branch (1285:6): [True: 17, False: 19]
  ------------------
 1286|     17|		size_t i;
 1287|     41|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1287:15): [True: 24, False: 17]
  ------------------
 1288|     24|			if (ses[i])
  ------------------
  |  Branch (1288:8): [True: 24, False: 0]
  ------------------
 1289|     24|				free(ses[i]);
 1290|     17|		free(ses);
 1291|     17|	}
 1292|       |
 1293|     36|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  153|     36|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     36|	int _ret = r; \
  |  |  155|     36|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 36, False: 0]
  |  |  ------------------
  |  |  156|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 17, False: 19]
  |  |  ------------------
  |  |  157|     36|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     36|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     36|	return _ret; \
  |  |  163|     36|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1294|     36|}
asn1.c:asn1_encode:
 2038|  14.7k|{
 2039|  14.7k|	int r, idx = 0;
 2040|  14.7k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2041|  14.7k|	size_t total = 0, objsize;
 2042|       |
 2043|  14.7k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2043:6): [True: 0, False: 14.7k]
  ------------------
 2044|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2045|      0|	}
 2046|       |
 2047|  37.2k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2047:16): [True: 22.5k, False: 14.6k]
  ------------------
 2048|  22.5k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2049|  22.5k|		if (r) {
  ------------------
  |  Branch (2049:7): [True: 54, False: 22.4k]
  ------------------
 2050|     54|			if (obj)
  ------------------
  |  Branch (2050:8): [True: 0, False: 54]
  ------------------
 2051|      0|				free(obj);
 2052|     54|			if (buf)
  ------------------
  |  Branch (2052:8): [True: 17, False: 37]
  ------------------
 2053|     17|				free(buf);
 2054|     54|			return r;
 2055|     54|		}
 2056|       |		/* in case of an empty (optional) element continue with
 2057|       |		 * the next asn1 element */
 2058|  22.4k|		if (!objsize)
  ------------------
  |  Branch (2058:7): [True: 6.79k, False: 15.7k]
  ------------------
 2059|  6.79k|			continue;
 2060|  15.7k|		tmp = (u8 *) realloc(buf, total + objsize);
 2061|  15.7k|		if (!tmp) {
  ------------------
  |  Branch (2061:7): [True: 0, False: 15.7k]
  ------------------
 2062|      0|			if (obj)
  ------------------
  |  Branch (2062:8): [True: 0, False: 0]
  ------------------
 2063|      0|				free(obj);
 2064|      0|			if (buf)
  ------------------
  |  Branch (2064:8): [True: 0, False: 0]
  ------------------
 2065|      0|				free(buf);
 2066|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2067|      0|		}
 2068|  15.7k|		buf = tmp;
 2069|  15.7k|		memcpy(buf + total, obj, objsize);
 2070|  15.7k|		free(obj);
 2071|  15.7k|		obj = NULL;
 2072|  15.7k|		total += objsize;
 2073|  15.7k|	}
 2074|  14.6k|	*ptr = buf;
 2075|  14.6k|	*size = total;
 2076|  14.6k|	return 0;
 2077|  14.7k|}
asn1.c:asn1_encode_entry:
 1825|  22.5k|{
 1826|  22.5k|	void *parm = entry->parm;
 1827|  22.5k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1828|  22.5k|			     size_t *nobjlen, int ndepth);
 1829|  22.5k|	const size_t *len = (const size_t *) entry->arg;
 1830|  22.5k|	int r = 0;
 1831|  22.5k|	u8 * buf = NULL;
 1832|  22.5k|	size_t buflen = 0;
 1833|       |
 1834|  22.5k|	callback_func = parm;
 1835|       |
 1836|  22.5k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  22.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  | 1837|  22.5k|	       	depth, depth, "", entry->name,
  |  |  |  | 1838|  22.5k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  22.5k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1837|  22.5k|	       	depth, depth, "", entry->name,
 1838|  22.5k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1839|  22.5k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  22.5k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1839:6): [True: 6.79k, False: 15.7k]
  ------------------
 1840|  6.79k|		goto no_object;
 1841|  15.7k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*stype=%d, tag=0x%02x, parm=%p, len=%zu",
  ------------------
  |  |   70|  31.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 8.90k, False: 6.85k]
  |  |  ------------------
  ------------------
 1842|  15.7k|			depth, depth, "", entry->type, entry->tag, parm, len ? *len : 0);
 1843|       |
 1844|  15.7k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  15.7k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1844:6): [True: 0, False: 15.7k]
  ------------------
 1845|      0|		const struct sc_asn1_entry *list, *choice = NULL;
 1846|       |
 1847|      0|		list = (const struct sc_asn1_entry *) parm;
 1848|      0|		while (list->name != NULL) {
  ------------------
  |  Branch (1848:10): [True: 0, False: 0]
  ------------------
 1849|      0|			if (list->flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1849:8): [True: 0, False: 0]
  ------------------
 1850|      0|				if (choice) {
  ------------------
  |  Branch (1850:9): [True: 0, False: 0]
  ------------------
 1851|      0|					sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1852|      0|						"ASN.1 problem: more than "
 1853|      0|						"one CHOICE when encoding %s: "
 1854|      0|						"%s and %s both present\n",
 1855|      0|						entry->name,
 1856|      0|						choice->name,
 1857|      0|						list->name);
 1858|      0|					return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1859|      0|				}
 1860|      0|				choice = list;
 1861|      0|			}
 1862|      0|			list++;
 1863|      0|		}
 1864|      0|		if (choice == NULL)
  ------------------
  |  Branch (1864:7): [True: 0, False: 0]
  ------------------
 1865|      0|			goto no_object;
 1866|      0|		return asn1_encode_entry(ctx, choice, obj, objlen, depth + 1);
 1867|      0|	}
 1868|       |
 1869|  15.7k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|  31.5k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1869:6): [True: 15.4k, False: 265]
  |  Branch (1869:37): [True: 23, False: 15.4k]
  ------------------
 1870|     23|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|     23|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1871|     23|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     23|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1872|     23|	}
 1873|       |
 1874|  15.7k|	switch (entry->type) {
 1875|    753|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|    753|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1875:2): [True: 753, False: 14.9k]
  ------------------
 1876|    753|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1877|    753|				&buflen, depth + 1);
 1878|    753|		break;
 1879|    265|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    265|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1879:2): [True: 265, False: 15.4k]
  ------------------
 1880|    265|		buf = NULL;
 1881|    265|		buflen = 0;
 1882|    265|		break;
 1883|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1883:2): [True: 0, False: 15.7k]
  ------------------
 1884|      0|		buf = malloc(1);
 1885|      0|		if (buf == NULL) {
  ------------------
  |  Branch (1885:7): [True: 0, False: 0]
  ------------------
 1886|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1887|      0|			break;
 1888|      0|		}
 1889|      0|		buf[0] = *((int *) parm) ? 0xFF : 0;
  ------------------
  |  Branch (1889:12): [True: 0, False: 0]
  ------------------
 1890|      0|		buflen = 1;
 1891|      0|		break;
 1892|      0|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|      0|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1892:2): [True: 0, False: 15.7k]
  ------------------
 1893|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1893:2): [True: 0, False: 15.7k]
  ------------------
 1894|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1895|      0|		break;
 1896|    363|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    363|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1896:2): [True: 363, False: 15.3k]
  ------------------
 1897|    363|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    363|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1897:2): [True: 0, False: 15.7k]
  ------------------
 1898|    363|		if (len != NULL) {
  ------------------
  |  Branch (1898:7): [True: 363, False: 0]
  ------------------
 1899|    363|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|    363|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1899:8): [True: 0, False: 363]
  ------------------
 1900|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1901|    363|			else
 1902|    363|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1903|    363|		} else {
 1904|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1905|      0|		}
 1906|    363|		break;
 1907|      0|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|      0|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1907:2): [True: 0, False: 15.7k]
  ------------------
 1908|      0|		if (len != NULL) {
  ------------------
  |  Branch (1908:7): [True: 0, False: 0]
  ------------------
 1909|      0|			r = encode_bit_field((const u8 *) parm, *len, &buf, &buflen);
 1910|      0|		} else {
 1911|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1912|      0|		}
 1913|      0|		break;
 1914|      0|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      0|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1914:2): [True: 0, False: 15.7k]
  ------------------
 1915|  8.51k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  8.51k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1915:2): [True: 8.51k, False: 7.21k]
  ------------------
 1916|  8.51k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  8.51k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1916:2): [True: 0, False: 15.7k]
  ------------------
 1917|  8.51k|		if (len != NULL) {
  ------------------
  |  Branch (1917:7): [True: 8.51k, False: 0]
  ------------------
 1918|  8.51k|			buf = malloc(*len + 1);
 1919|  8.51k|			if (buf == NULL) {
  ------------------
  |  Branch (1919:8): [True: 0, False: 8.51k]
  ------------------
 1920|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1921|      0|				break;
 1922|      0|			}
 1923|  8.51k|			buflen = 0;
 1924|       |			/* If the integer is supposed to be unsigned, insert
 1925|       |			 * a padding byte if the MSB is one */
 1926|  8.51k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  8.51k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1926:8): [True: 747, False: 7.77k]
  ------------------
 1927|    747|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1927:9): [True: 167, False: 580]
  ------------------
 1928|    167|				buf[buflen++] = 0x00;
 1929|    167|			}
 1930|  8.51k|			memcpy(buf + buflen, parm, *len);
 1931|  8.51k|			buflen += *len;
 1932|  8.51k|		} else {
 1933|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1934|      0|		}
 1935|  8.51k|		break;
 1936|  8.51k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1936:2): [True: 0, False: 15.7k]
  ------------------
 1937|      0|		if (len != NULL) {
  ------------------
  |  Branch (1937:7): [True: 0, False: 0]
  ------------------
 1938|      0|			buf = malloc(*len);
 1939|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1939:8): [True: 0, False: 0]
  ------------------
 1940|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1941|      0|				break;
 1942|      0|			}
 1943|      0|			memcpy(buf, parm, *len);
 1944|      0|			buflen = *len;
 1945|      0|		} else {
 1946|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1947|      0|		}
 1948|      0|		break;
 1949|  5.47k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  5.47k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1949:2): [True: 5.47k, False: 10.2k]
  ------------------
 1950|  5.47k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1951|  5.47k|		break;
 1952|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  174|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1952:2): [True: 0, False: 15.7k]
  ------------------
 1953|      0|		r = asn1_encode_path(ctx, (const sc_path_t *) parm, &buf, &buflen, depth, entry->flags);
 1954|      0|		break;
 1955|      0|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|      0|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1955:2): [True: 0, False: 15.7k]
  ------------------
 1956|      0|		{
 1957|      0|			const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm;
 1958|       |
 1959|      0|			buf = malloc(id->len);
 1960|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1960:8): [True: 0, False: 0]
  ------------------
 1961|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1962|      0|				break;
 1963|      0|			}
 1964|      0|			memcpy(buf, id->value, id->len);
 1965|      0|			buflen = id->len;
 1966|      0|		}
 1967|      0|		break;
 1968|      0|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|      0|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1968:2): [True: 0, False: 15.7k]
  ------------------
 1969|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1970|      0|		break;
 1971|    363|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    363|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1971:2): [True: 363, False: 15.3k]
  ------------------
 1972|    363|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1973|    363|		break;
 1974|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1974:2): [True: 0, False: 15.7k]
  ------------------
 1975|      0|		if (!len)
  ------------------
  |  Branch (1975:7): [True: 0, False: 0]
  ------------------
 1976|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1977|      0|		r = asn1_encode_se_info(ctx, (struct sc_pkcs15_sec_env_info **)parm, *len, &buf, &buflen, depth);
 1978|      0|		break;
 1979|      0|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|      0|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1979:2): [True: 0, False: 15.7k]
  ------------------
 1980|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1981|      0|		break;
 1982|      0|	default:
  ------------------
  |  Branch (1982:2): [True: 0, False: 15.7k]
  ------------------
 1983|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 type: %d\n", entry->type);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1984|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1985|  15.7k|	}
 1986|  15.7k|	if (r) {
  ------------------
  |  Branch (1986:6): [True: 27, False: 15.7k]
  ------------------
 1987|     27|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|     27|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1988|     27|		      sc_strerror(r));
 1989|     27|		if (buf)
  ------------------
  |  Branch (1989:7): [True: 0, False: 27]
  ------------------
 1990|      0|			free(buf);
 1991|     27|		return r;
 1992|     27|	}
 1993|       |
 1994|       |	/* Treatment of OPTIONAL elements:
 1995|       |	 *  -	if the encoding has 0 length, and the element is OPTIONAL,
 1996|       |	 *	we don't write anything (unless it's an ASN1 NULL and the
 1997|       |	 *      SC_ASN1_PRESENT flag is set).
 1998|       |	 *  -	if the encoding has 0 length, but the element is non-OPTIONAL,
 1999|       |	 *	constructed, we write a empty element (e.g. a SEQUENCE of
 2000|       |	 *      length 0). In case of an ASN1 NULL just write the tag and
 2001|       |	 *      length (i.e. 0x05,0x00).
 2002|       |	 *  -	any other empty objects are considered bogus
 2003|       |	 */
 2004|  22.5k|no_object:
 2005|  22.5k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|  29.5k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  7.06k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2005:6): [True: 7.06k, False: 15.4k]
  |  Branch (2005:17): [True: 7.06k, False: 4]
  |  Branch (2005:52): [True: 6.79k, False: 265]
  ------------------
 2006|       |		/* This happens when we try to encode e.g. the
 2007|       |		 * subClassAttributes, which may be empty */
 2008|  6.79k|		*obj = NULL;
 2009|  6.79k|		*objlen = 0;
 2010|  6.79k|		r = 0;
 2011|  15.7k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|    269|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2011:13): [True: 269, False: 15.4k]
  |  Branch (2011:24): [True: 0, False: 269]
  ------------------
 2012|      0|		*obj = NULL;
 2013|      0|		*objlen = 0;
 2014|      0|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2015|      0|		if (r)
  ------------------
  |  Branch (2015:7): [True: 0, False: 0]
  ------------------
 2016|      0|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "error writing ASN.1 tag and length: %s\n", sc_strerror(r));
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2017|  15.7k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|  15.9k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|      4|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2017:13): [True: 15.4k, False: 269]
  |  Branch (2017:23): [True: 265, False: 4]
  |  Branch (2017:54): [True: 0, False: 4]
  ------------------
 2018|  15.7k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2019|  15.7k|		if (r)
  ------------------
  |  Branch (2019:7): [True: 0, False: 15.7k]
  ------------------
 2020|      0|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "error writing ASN.1 tag and length: %s\n",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2021|  15.7k|					sc_strerror(r));
 2022|  15.7k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      4|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2022:13): [True: 0, False: 4]
  ------------------
 2023|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode non-optional ASN.1 object: not given by caller\n");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2024|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2025|      4|	} else {
 2026|      4|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\n");
  ------------------
  |  |   70|      4|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2027|      4|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2028|      4|	}
 2029|  22.5k|	if (buf)
  ------------------
  |  Branch (2029:6): [True: 15.4k, False: 7.06k]
  ------------------
 2030|  15.4k|		free(buf);
 2031|  22.5k|	if (r >= 0)
  ------------------
  |  Branch (2031:6): [True: 22.4k, False: 4]
  ------------------
 2032|  22.4k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*slength of encoded item=%zu", depth, depth, "", *objlen);
  ------------------
  |  |   70|  22.4k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2033|  22.5k|	return r;
 2034|  15.7k|}
asn1.c:encode_bit_string:
  646|    363|{
  647|    363|	const u8 *in = inbuf;
  648|    363|	u8 *out;
  649|    363|	size_t bytes, skipped = 0;
  650|       |
  651|    363|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  145|    363|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  652|    363|	*outbuf = out = malloc(bytes);
  653|    363|	if (out == NULL)
  ------------------
  |  Branch (653:6): [True: 0, False: 363]
  ------------------
  654|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  655|    363|	*outlen = bytes;
  656|    363|	out += 1;
  657|  38.6k|	while (bits_left) {
  ------------------
  |  Branch (657:9): [True: 38.2k, False: 363]
  ------------------
  658|  38.2k|		size_t i, bits_to_go = 8;
  659|       |
  660|  38.2k|		*out = 0;
  661|  38.2k|		if (bits_left < 8) {
  ------------------
  |  Branch (661:7): [True: 0, False: 38.2k]
  ------------------
  662|      0|			bits_to_go = bits_left;
  663|      0|			skipped = 8 - bits_left;
  664|      0|		}
  665|  38.2k|		if (invert) {
  ------------------
  |  Branch (665:7): [True: 0, False: 38.2k]
  ------------------
  666|      0|			for (i = 0; i < bits_to_go; i++)
  ------------------
  |  Branch (666:16): [True: 0, False: 0]
  ------------------
  667|      0|				*out |= ((*in >> i) & 1) << (7 - i);
  668|  38.2k|		} else {
  669|  38.2k|			*out = *in;
  670|  38.2k|			if (bits_left < 8)
  ------------------
  |  Branch (670:8): [True: 0, False: 38.2k]
  ------------------
  671|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|  38.2k|		}
  673|  38.2k|		bits_left -= bits_to_go;
  674|  38.2k|		out++, in++;
  675|  38.2k|	}
  676|    363|	out = *outbuf;
  677|    363|	out[0] = skipped;
  678|    363|	return 0;
  679|    363|}

sc_aux_data_free:
  193|  2.03k|{
  194|  2.03k|	if (data == NULL || *data == NULL)
  ------------------
  |  Branch (194:6): [True: 0, False: 2.03k]
  |  Branch (194:22): [True: 2.03k, False: 0]
  ------------------
  195|  2.03k|		return;
  196|       |
  197|      0|	switch((*data)->type) {
  198|      0|	case SC_AUX_DATA_TYPE_MD_CMAP_RECORD:
  ------------------
  |  |   36|      0|#define SC_AUX_DATA_TYPE_MD_CMAP_RECORD	    0x01
  ------------------
  |  Branch (198:2): [True: 0, False: 0]
  ------------------
  199|      0|		free(*data);
  200|      0|		break;
  201|      0|	default:
  ------------------
  |  Branch (201:2): [True: 0, False: 0]
  ------------------
  202|      0|		break;
  203|      0|	}
  204|       |
  205|      0|	*data = NULL;
  206|      0|}

sc_get_asepcos_driver:
 1086|  15.2k|{
 1087|  15.2k|	return sc_get_driver();
 1088|  15.2k|}
card-asepcos.c:sc_get_driver:
 1064|  15.2k|{
 1065|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1065:6): [True: 1, False: 15.2k]
  ------------------
 1066|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1067|  15.2k|	asepcos_ops = *iso_ops;
 1068|  15.2k|	asepcos_ops.match_card        = asepcos_match_card;
 1069|  15.2k|	asepcos_ops.init              = asepcos_init;
 1070|  15.2k|	asepcos_ops.select_file       = asepcos_select_file;
 1071|  15.2k|	asepcos_ops.set_security_env  = asepcos_set_security_env;
 1072|  15.2k|	asepcos_ops.decipher          = asepcos_decipher;
 1073|  15.2k|	asepcos_ops.compute_signature = asepcos_compute_signature;
 1074|  15.2k|	asepcos_ops.create_file       = asepcos_create_file;
 1075|  15.2k|	asepcos_ops.delete_file       = asepcos_delete_file;
 1076|  15.2k|	asepcos_ops.list_files        = asepcos_list_files;
 1077|  15.2k|	asepcos_ops.card_ctl          = asepcos_card_ctl;
 1078|  15.2k|	asepcos_ops.pin_cmd           = asepcos_pin_cmd;
 1079|  15.2k|	asepcos_ops.logout            = asepcos_logout;
 1080|  15.2k|	asepcos_ops.card_reader_lock_obtained = asepcos_card_reader_lock_obtained;
 1081|       |
 1082|  15.2k|	return &asepcos_drv;
 1083|  15.2k|}
card-asepcos.c:asepcos_match_card:
   47|  15.2k|{
   48|  15.2k|	int i = _sc_match_atr(card, asepcos_atrs, &card->type);
   49|  15.2k|	if (i < 0)
  ------------------
  |  Branch (49:6): [True: 15.2k, False: 0]
  ------------------
   50|  15.2k|		return 0;
   51|      0|	return 1;
   52|  15.2k|}

sc_get_atrust_acos_driver:
  814|  15.2k|{
  815|  15.2k|	return sc_get_driver();
  816|  15.2k|}
card-atrust-acos.c:sc_get_driver:
  789|  15.2k|{
  790|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  791|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (791:6): [True: 1, False: 15.2k]
  ------------------
  792|      1|		iso_ops = iso_drv->ops;
  793|       |
  794|  15.2k|	atrust_acos_ops = *iso_drv->ops;
  795|  15.2k|	atrust_acos_ops.match_card = atrust_acos_match_card;
  796|  15.2k|	atrust_acos_ops.init   = atrust_acos_init;
  797|  15.2k|	atrust_acos_ops.finish = atrust_acos_finish;
  798|  15.2k|	atrust_acos_ops.select_file = atrust_acos_select_file;
  799|  15.2k|	atrust_acos_ops.check_sw    = atrust_acos_check_sw;
  800|  15.2k|	atrust_acos_ops.create_file = NULL;
  801|  15.2k|	atrust_acos_ops.delete_file = NULL;
  802|  15.2k|	atrust_acos_ops.set_security_env  = atrust_acos_set_security_env;
  803|  15.2k|	atrust_acos_ops.compute_signature = atrust_acos_compute_signature;
  804|  15.2k|	atrust_acos_ops.decipher    = atrust_acos_decipher;
  805|  15.2k|	atrust_acos_ops.card_ctl    = atrust_acos_card_ctl;
  806|  15.2k|	atrust_acos_ops.logout      = atrust_acos_logout;
  807|       |
  808|  15.2k|	return &atrust_acos_drv;
  809|  15.2k|}
card-atrust-acos.c:atrust_acos_match_card:
   76|  15.2k|{
   77|  15.2k|	int		i, match = 0;
   78|       |
   79|       |
   80|  75.6k|	for (i = 0; atrust_acos_atrs[i] != NULL; i++)
  ------------------
  |  Branch (80:14): [True: 60.6k, False: 14.9k]
  ------------------
   81|  60.6k|	{
   82|  60.6k|		u8 defatr[SC_MAX_ATR_SIZE];
   83|  60.6k|		size_t len = sizeof(defatr);
   84|  60.6k|		const char *atrp = atrust_acos_atrs[i];
   85|       |
   86|  60.6k|		if (sc_hex_to_bin(atrp, defatr, &len))
  ------------------
  |  Branch (86:7): [True: 0, False: 60.6k]
  ------------------
   87|      0|			continue;
   88|       |		/* we may only verify part of ATR since */
   89|       |		/* part of the hist chars is variable */
   90|  60.6k|		if (len > card->atr.len)
  ------------------
  |  Branch (90:7): [True: 25.6k, False: 35.0k]
  ------------------
   91|  25.6k|			continue;
   92|  35.0k|		if (memcmp(card->atr.value, defatr, len) != 0)
  ------------------
  |  Branch (92:7): [True: 34.8k, False: 274]
  ------------------
   93|  34.8k|			continue;
   94|       |
   95|    274|		match = 1;
   96|    274|		card->name = atrust_acos_names[i];
   97|       |
   98|    274|		break;
   99|  35.0k|    }
  100|  15.2k|	return match;
  101|  15.2k|}
card-atrust-acos.c:atrust_acos_init:
  106|    274|{
  107|    274|	unsigned int flags;
  108|    274|	atrust_acos_ex_data *ex_data;
  109|       |
  110|    274|	ex_data = calloc(1, sizeof(atrust_acos_ex_data));
  111|    274|	if (ex_data == NULL)
  ------------------
  |  Branch (111:6): [True: 0, False: 274]
  ------------------
  112|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  113|       |
  114|    274|	card->cla  = 0x00;
  115|    274|	card->drv_data = (void *)ex_data;
  116|       |
  117|       |	/* set the supported algorithm */
  118|       |
  119|    274|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    274|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    274|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    274|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  120|    274|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|    274|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  121|    274|		| SC_ALGORITHM_RSA_HASH_SHA1
  ------------------
  |  |  134|    274|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  122|    274|		| SC_ALGORITHM_RSA_HASH_MD5
  ------------------
  |  |  135|    274|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  123|    274|		| SC_ALGORITHM_RSA_HASH_RIPEMD160
  ------------------
  |  |  137|    274|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  124|    274|		| SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  136|    274|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  125|       |
  126|    274|	if (card->name != NULL && !strcmp(card->name, ACOS_EMV_A05))
  ------------------
  |  |   37|    274|#define ACOS_EMV_A05		"A-TRUST ACOS A05"
  ------------------
  |  Branch (126:6): [True: 274, False: 0]
  |  Branch (126:28): [True: 182, False: 92]
  ------------------
  127|    182|		flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|    182|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  128|       |
  129|    274|	_sc_card_add_rsa_alg(card, 1536, flags, 0x10001);
  130|       |
  131|       |	/* we need read_binary&friends with max 128 bytes per read */
  132|    274|	card->max_send_size = 128;
  133|    274|	card->max_recv_size = 128;
  134|       |
  135|    274|	return 0;
  136|    274|}
card-atrust-acos.c:atrust_acos_finish:
  141|    274|{
  142|    274|	if (card->drv_data)
  ------------------
  |  Branch (142:6): [True: 274, False: 0]
  ------------------
  143|    274|		free((atrust_acos_ex_data *)card->drv_data);
  144|    274|	return 0;
  145|    274|}
card-atrust-acos.c:atrust_acos_select_file:
  364|  1.34k|{
  365|  1.34k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  366|  1.34k|	int    r;
  367|  1.34k|	size_t i, pathlen;
  368|       |
  369|  1.34k|	memcpy(path, in_path->value, in_path->len);
  370|  1.34k|	pathlen = in_path->len;
  371|       |
  372|  1.34k|	if (in_path->type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  1.34k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (372:6): [True: 0, False: 1.34k]
  ------------------
  373|       |		/* SELECT EF/DF with ID */
  374|       |		/* Select with 2byte File-ID */
  375|      0|		if (pathlen != 2)
  ------------------
  |  Branch (375:7): [True: 0, False: 0]
  ------------------
  376|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  377|      0|		return atrust_acos_select_fid(card, path[0], path[1], file_out);
  378|  1.34k|	} else if (in_path->type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  1.34k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (378:13): [True: 524, False: 824]
  ------------------
  379|       |		/* SELECT DF with AID */
  380|       |		/* Select with 1-16byte Application-ID */
  381|    524|		return atrust_acos_select_aid(card, pathbuf, pathlen, file_out);
  382|    824|	} else if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|    824|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (382:13): [True: 824, False: 0]
  ------------------
  383|    824|		u8 n_pathbuf[SC_MAX_PATH_SIZE];
  384|       |
  385|       |		/* Select with path (sequence of File-IDs) */
  386|       |		/* ACOS only supports one
  387|       |		 * level of subdirectories, therefore a path is
  388|       |		 * at most 3 FID long (the last one being the FID
  389|       |		 * of a EF) => pathlen must be even and less than 6
  390|       |		 */
  391|    824|		if (pathlen%2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (391:7): [True: 0, False: 824]
  |  Branch (391:25): [True: 1, False: 823]
  |  Branch (391:40): [True: 0, False: 823]
  ------------------
  392|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  393|       |		/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  394|    823|		if (pathlen == 6 && ( path[0] != 0x3f || path[1] != 0x00 ))
  ------------------
  |  Branch (394:7): [True: 19, False: 804]
  |  Branch (394:25): [True: 1, False: 18]
  |  Branch (394:44): [True: 1, False: 17]
  ------------------
  395|      2|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      2|	int _ret = r; \
  |  |  155|      2|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  ------------------
  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  ------------------
  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      2|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      2|	return _ret; \
  |  |  163|      2|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  396|       |
  397|       |		/* unify path (the first FID should be MF) */
  398|    821|		if (path[0] != 0x3f || path[1] != 0x00)
  ------------------
  |  Branch (398:7): [True: 26, False: 795]
  |  Branch (398:26): [True: 3, False: 792]
  ------------------
  399|     29|		{
  400|     29|			n_pathbuf[0] = 0x3f;
  401|     29|			n_pathbuf[1] = 0x00;
  402|     29|			memcpy(n_pathbuf+2, path, pathlen);
  403|     29|			path = n_pathbuf;
  404|     29|			pathlen += 2;
  405|     29|		}
  406|       |
  407|  1.05k|		for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (407:15): [True: 834, False: 220]
  ------------------
  408|    834|			r = atrust_acos_select_fid(card, path[i], path[i + 1], NULL);
  409|    834|			LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    834|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    834|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    834|	int _ret = (r); \
  |  |  |  |  168|    834|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 601, False: 233]
  |  |  |  |  ------------------
  |  |  |  |  169|    601|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    601|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    601|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    601|		return _ret; \
  |  |  |  |  172|    601|	} \
  |  |  |  |  173|    834|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 233]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  410|    834|		}
  411|    220|		return atrust_acos_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  412|    821|	} else
  413|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  414|  1.34k|}
card-atrust-acos.c:atrust_acos_select_fid:
  282|  1.05k|{
  283|  1.05k|	sc_apdu_t apdu;
  284|  1.05k|	u8 data[] = {id_hi & 0xff, id_lo & 0xff};
  285|  1.05k|	u8 resp[SC_MAX_APDU_BUFFER_SIZE];
  286|  1.05k|	int bIsDF = 0, r;
  287|       |
  288|       |	/* request FCI to distinguish between EFs and DFs */
  289|  1.05k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.05k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  290|  1.05k|	apdu.resp = (u8*)resp;
  291|  1.05k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  1.05k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  292|  1.05k|	apdu.le = 256;
  293|  1.05k|	apdu.lc = 2;
  294|  1.05k|	apdu.data = (u8*)data;
  295|  1.05k|	apdu.datalen = 2;
  296|       |
  297|  1.05k|	r = sc_transmit_apdu(card, &apdu);
  298|  1.05k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.05k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.05k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.05k|	int _ret = (r); \
  |  |  |  |  168|  1.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|  1.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|       |
  300|  1.03k|	if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
  ------------------
  |  Branch (300:6): [True: 1.03k, False: 0]
  |  Branch (300:25): [True: 33, False: 1.00k]
  |  Branch (300:45): [True: 12, False: 21]
  ------------------
  301|       |		/* no FCI => we have a DF (see comment in process_fci()) */
  302|     12|		bIsDF = 1;
  303|     12|		apdu.p2 = 0x0C;
  304|     12|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     12|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|     12|		apdu.resplen = 0;
  306|     12|		apdu.le = 0;
  307|     12|		r = sc_transmit_apdu(card, &apdu);
  308|     12|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|  1.02k|    	} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)) {
  ------------------
  |  Branch (309:17): [True: 0, False: 1.02k]
  |  Branch (309:38): [True: 463, False: 563]
  |  Branch (309:58): [True: 432, False: 31]
  ------------------
  310|       |		/* SELECT returned some data (possible FCI) =>
  311|       |		 * try a READ BINARY to see if a EF is selected */
  312|    432|		sc_apdu_t apdu2;
  313|    432|		u8 resp2[2];
  314|    432|		sc_format_apdu(card, &apdu2, SC_APDU_CASE_2_SHORT, 0xB0, 0, 0);
  ------------------
  |  |  292|    432|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  315|    432|		apdu2.resp = (u8*)resp2;
  316|    432|		apdu2.resplen = 2;
  317|    432|		apdu2.le = 1;
  318|    432|		apdu2.lc = 0;
  319|    432|		r = sc_transmit_apdu(card, &apdu2);
  320|    432|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    432|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    432|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    432|	int _ret = (r); \
  |  |  |  |  168|    432|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 416]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|    432|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 416]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  321|    416|		if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86)
  ------------------
  |  Branch (321:7): [True: 59, False: 357]
  |  Branch (321:28): [True: 32, False: 27]
  ------------------
  322|       |			/* no current EF is selected => we have a DF */
  323|     32|			bIsDF = 1;
  324|    416|	}
  325|       |
  326|  1.01k|	if (apdu.sw1 != 0x61 && (apdu.sw1 != 0x90 || apdu.sw2 != 0x00))
  ------------------
  |  Branch (326:6): [True: 1.01k, False: 0]
  |  Branch (326:27): [True: 569, False: 447]
  |  Branch (326:47): [True: 31, False: 416]
  ------------------
  327|    600|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    600|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    600|	int _ret = r; \
  |  |  155|    600|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 600, False: 0]
  |  |  ------------------
  |  |  156|    600|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    600|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 600, False: 0]
  |  |  ------------------
  |  |  157|    600|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    600|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    600|	return _ret; \
  |  |  163|    600|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  328|       |
  329|    416|	if (file_out) {
  ------------------
  |  Branch (329:6): [True: 169, False: 247]
  ------------------
  330|    169|		sc_file_t *file = sc_file_new();
  331|    169|		if (!file)
  ------------------
  |  Branch (331:7): [True: 0, False: 169]
  ------------------
  332|    169|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  333|    169|		file->id = (id_hi << 8) + id_lo;
  334|       |
  335|    169|		if (bIsDF) {
  ------------------
  |  Branch (335:7): [True: 12, False: 157]
  ------------------
  336|       |			/* we have a DF */
  337|     12|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     12|#define SC_FILE_TYPE_DF			0x04
  ------------------
  338|     12|			file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     12|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  339|     12|			file->size = 0;
  340|     12|			file->namelen = 0;
  341|     12|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|     12|#define SC_FILE_MAGIC			0x14426950
  ------------------
  342|     12|			*file_out = file;
  343|    157|		} else {
  344|       |			/* ok, assume we have a EF */
  345|    157|			r = process_fci(card->ctx, file, apdu.resp,
  346|    157|					apdu.resplen);
  347|    157|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    157|#define SC_SUCCESS				0
  ------------------
  |  Branch (347:8): [True: 38, False: 119]
  ------------------
  348|     38|				sc_file_free(file);
  349|     38|				return r;
  350|     38|			}
  351|       |
  352|    119|			*file_out = file;
  353|    119|		}
  354|    169|	}
  355|       |
  356|    378|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    378|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    378|	int _ret = r; \
  |  |  155|    378|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 378, False: 0]
  |  |  ------------------
  |  |  156|    378|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 378]
  |  |  ------------------
  |  |  157|    378|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    378|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    378|	return _ret; \
  |  |  163|    378|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  357|    378|}
card-atrust-acos.c:process_fci:
  151|    157|{
  152|       |
  153|    157|	size_t taglen, len = buflen;
  154|    157|	const u8 *tag = NULL, *p;
  155|       |
  156|    157|	sc_log(ctx,  "processing FCI bytes\n");
  ------------------
  |  |   71|    157|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  157|       |
  158|    157|	if (buflen < 2)
  ------------------
  |  Branch (158:6): [True: 22, False: 135]
  ------------------
  159|     22|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     22|#define SC_ERROR_INTERNAL			-1400
  ------------------
  160|    135|	if (buf[0] != 0x6f)					/* FCI template */
  ------------------
  |  Branch (160:6): [True: 9, False: 126]
  ------------------
  161|      9|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      9|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  162|    126|	len = (size_t)buf[1];
  163|    126|	if (buflen - 2 < len)
  ------------------
  |  Branch (163:6): [True: 7, False: 119]
  ------------------
  164|      7|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      7|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  165|    119|	p = buf + 2;
  166|       |
  167|       |	/* defaults */
  168|    119|	file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    119|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  169|    119|	file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    119|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  170|    119|	file->shareable = 0;
  171|    119|	file->record_length = 0;
  172|    119|	file->size = 0;
  173|       |
  174|       |	/* get file size */
  175|    119|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  176|    119|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (176:6): [True: 21, False: 98]
  |  Branch (176:21): [True: 12, False: 9]
  ------------------
  177|     12|		int bytes = (tag[0] << 8) + tag[1];
  178|     12|		sc_log(ctx,  "  bytes in file: %d\n", bytes);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  179|     12|		file->size = bytes;
  180|     12|	}
  181|       |
  182|       |	/* get file type */
  183|    119|  	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  184|    119|	if (tag != NULL) {
  ------------------
  |  Branch (184:6): [True: 60, False: 59]
  ------------------
  185|     60|		const char *type = "unknown";
  186|     60|		const char *structure = "unknown";
  187|       |
  188|     60|		if (taglen == 1 && tag[0] == 0x01) {
  ------------------
  |  Branch (188:7): [True: 31, False: 29]
  |  Branch (188:22): [True: 6, False: 25]
  ------------------
  189|       |			/* transparent EF */
  190|      6|			type = "working EF";
  191|      6|			structure = "transparent";
  192|      6|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  193|      6|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|      6|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  194|     54|		} else if (taglen == 1 && tag[0] == 0x11) {
  ------------------
  |  Branch (194:14): [True: 25, False: 29]
  |  Branch (194:29): [True: 8, False: 17]
  ------------------
  195|       |			/* object EF */
  196|      8|			type = "working EF";
  197|      8|			structure = "object";
  198|      8|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      8|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  199|      8|			file->ef_structure = SC_FILE_EF_TRANSPARENT; /* TODO */
  ------------------
  |  |  221|      8|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  200|     46|		} else if (taglen == 3 && tag[1] == 0x21) {
  ------------------
  |  Branch (200:14): [True: 15, False: 31]
  |  Branch (200:29): [True: 12, False: 3]
  ------------------
  201|     12|			type = "working EF";
  202|     12|			file->record_length = tag[2];
  203|     12|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     12|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  204|       |			/* linear fixed, cyclic or compute */
  205|     12|			switch ( tag[0] )
  206|     12|			{
  207|      3|				case 0x02:
  ------------------
  |  Branch (207:5): [True: 3, False: 9]
  ------------------
  208|      3|					structure = "linear fixed";
  209|      3|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|      3|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  210|      3|					break;
  211|      3|				case 0x07:
  ------------------
  |  Branch (211:5): [True: 3, False: 9]
  ------------------
  212|      3|					structure = "cyclic";
  213|      3|					file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|      3|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  214|      3|					break;
  215|      3|				case 0x17:
  ------------------
  |  Branch (215:5): [True: 3, False: 9]
  ------------------
  216|      3|					structure = "compute";
  217|      3|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      3|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  218|      3|					break;
  219|      3|				default:
  ------------------
  |  Branch (219:5): [True: 3, False: 9]
  ------------------
  220|      3|					structure = "unknown";
  221|      3|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      3|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  222|      3|					file->record_length = 0;
  223|      3|					break;
  224|     12|			}
  225|     12|		}
  226|       |
  227|     60|	 	sc_log(ctx,  "  type: %s\n", type);
  ------------------
  |  |   71|     60|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  228|     60|		sc_log(ctx,  "  EF structure: %s\n", structure);
  ------------------
  |  |   71|     60|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  229|     60|	}
  230|    119|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    119|#define SC_FILE_MAGIC			0x14426950
  ------------------
  231|       |
  232|    119|	return SC_SUCCESS;
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
  233|    119|}
card-atrust-acos.c:atrust_acos_select_aid:
  240|    524|{
  241|    524|	sc_apdu_t apdu;
  242|    524|	int r;
  243|    524|	size_t i = 0;
  244|       |
  245|    524|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x04, 0x0C);
  ------------------
  |  |  293|    524|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  246|    524|	apdu.lc = len;
  247|    524|	apdu.data = (u8*)aid;
  248|    524|	apdu.datalen = len;
  249|    524|	apdu.resplen = 0;
  250|    524|	apdu.le = 0;
  251|    524|	r = sc_transmit_apdu(card, &apdu);
  252|    524|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    524|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    524|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    524|	int _ret = (r); \
  |  |  |  |  168|    524|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 518]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 518]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  253|       |
  254|       |	/* check return value */
  255|    518|	if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61)
  ------------------
  |  Branch (255:8): [True: 78, False: 440]
  |  Branch (255:28): [True: 65, False: 13]
  |  Branch (255:49): [True: 453, False: 0]
  ------------------
  256|    453|    		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    453|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    453|	int _ret = r; \
  |  |  155|    453|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 453, False: 0]
  |  |  ------------------
  |  |  156|    453|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    453|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 453, False: 0]
  |  |  ------------------
  |  |  157|    453|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    453|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    453|	return _ret; \
  |  |  163|    453|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  257|       |
  258|     65|	if (file_out) {
  ------------------
  |  Branch (258:6): [True: 0, False: 65]
  ------------------
  259|      0|		sc_file_t *file = sc_file_new();
  260|      0|		if (!file)
  ------------------
  |  Branch (260:7): [True: 0, False: 0]
  ------------------
  261|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  263|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  264|      0|		file->path.len = 0;
  265|      0|		file->size = 0;
  266|       |		/* AID */
  267|      0|		for (i = 0; i < len; i++)
  ------------------
  |  Branch (267:15): [True: 0, False: 0]
  ------------------
  268|      0|			file->name[i] = aid[i];
  269|      0|		file->namelen = len;
  270|      0|		file->id = 0x0000;
  271|      0|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  272|      0|		*file_out = file;
  273|      0|	}
  274|     65|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|     65|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     65|	int _ret = r; \
  |  |  155|     65|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 65, False: 0]
  |  |  ------------------
  |  |  156|     65|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 65]
  |  |  ------------------
  |  |  157|     65|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     65|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     65|	return _ret; \
  |  |  163|     65|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  275|     65|}
card-atrust-acos.c:atrust_acos_check_sw:
  693|  1.91k|{
  694|       |
  695|  1.91k|	sc_log(card->ctx,  "sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  ------------------
  |  |   71|  1.91k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  696|       |
  697|  1.91k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (697:6): [True: 739, False: 1.17k]
  |  Branch (697:21): [True: 675, False: 64]
  ------------------
  698|    675|		return SC_SUCCESS;
  ------------------
  |  |   28|    675|#define SC_SUCCESS				0
  ------------------
  699|  1.24k|	if (sw1 == 0x63 && (sw2 & ~0x0fU) == 0xc0 )
  ------------------
  |  Branch (699:6): [True: 35, False: 1.20k]
  |  Branch (699:21): [True: 10, False: 25]
  ------------------
  700|     10|	{
  701|     10|		sc_log(card->ctx,  "Verification failed (remaining tries: %d)\n",
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  702|     10|		(sw2 & 0x0f));
  703|     10|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     10|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  704|     10|	}
  705|       |
  706|       |	/* iso error */
  707|  1.23k|	return iso_ops->check_sw(card, sw1, sw2);
  708|  1.24k|}
card-atrust-acos.c:atrust_acos_card_ctl:
  748|     19|{
  749|       |
  750|     19|	switch (cmd)
  751|     19|	{
  752|     19|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (752:2): [True: 19, False: 0]
  ------------------
  753|     19|		return acos_get_serialnr(card, (sc_serial_number_t *)ptr);
  754|      0|	default:
  ------------------
  |  Branch (754:2): [True: 0, False: 19]
  ------------------
  755|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  756|     19|	}
  757|     19|}
card-atrust-acos.c:acos_get_serialnr:
  713|     19|{
  714|     19|	int r;
  715|     19|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
  716|     19|	sc_apdu_t apdu;
  717|       |
  718|     19|	if (!serial)
  ------------------
  |  Branch (718:6): [True: 0, False: 19]
  ------------------
  719|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  720|       |	/* see if we have cached serial number */
  721|     19|	if (card->serialnr.len) {
  ------------------
  |  Branch (721:6): [True: 0, False: 19]
  ------------------
  722|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  723|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  724|      0|	}
  725|       |	/* get serial number via GET CARD DATA */
  726|     19|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xf6, 0x00, 0x00);
  ------------------
  |  |  292|     19|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  727|     19|	apdu.cla |= 0x80;
  728|     19|	apdu.resp = rbuf;
  729|     19|	apdu.resplen = sizeof(rbuf);
  730|     19|	apdu.le   = 256;
  731|     19|	apdu.lc   = 0;
  732|     19|	apdu.datalen = 0;
  733|     19|        r = sc_transmit_apdu(card, &apdu);
  734|     19|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  735|     18|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (735:6): [True: 7, False: 11]
  |  Branch (735:26): [True: 1, False: 10]
  ------------------
  736|      8|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      8|#define SC_ERROR_INTERNAL			-1400
  ------------------
  737|       |	/* cache serial number */
  738|     10|	memcpy(card->serialnr.value, apdu.resp, MIN(apdu.resplen, SC_MAX_SERIALNR));
  ------------------
  |  |   69|     10|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 8, False: 2]
  |  |  ------------------
  ------------------
  739|     10|	card->serialnr.len = MIN(apdu.resplen, SC_MAX_SERIALNR);
  ------------------
  |  |   69|     10|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 8, False: 2]
  |  |  ------------------
  ------------------
  740|       |	/* copy and return serial number */
  741|     10|	memcpy(serial, &card->serialnr, sizeof(*serial));
  742|     10|	return SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  743|     18|}

sc_get_authentic_driver:
 2155|  15.2k|{
 2156|  15.2k|	return sc_get_driver();
 2157|  15.2k|}
card-authentic.c:sc_get_driver:
 2120|  15.2k|{
 2121|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2122|       |
 2123|  15.2k|	if (!iso_ops)
  ------------------
  |  Branch (2123:6): [True: 1, False: 15.2k]
  ------------------
 2124|      1|		iso_ops = iso_drv->ops;
 2125|       |
 2126|  15.2k|	authentic_ops = *iso_ops;
 2127|       |
 2128|  15.2k|	authentic_ops.match_card = authentic_match_card;
 2129|  15.2k|	authentic_ops.init = authentic_init;
 2130|  15.2k|	authentic_ops.finish = authentic_finish;
 2131|  15.2k|	authentic_ops.read_binary = authentic_read_binary;
 2132|  15.2k|	authentic_ops.write_binary = authentic_write_binary;
 2133|  15.2k|	authentic_ops.update_binary = authentic_update_binary;
 2134|  15.2k|	authentic_ops.erase_binary = authentic_erase_binary;
 2135|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2136|  15.2k|	authentic_ops.select_file = authentic_select_file;
 2137|       |	/* get_response: Untested */
 2138|  15.2k|	authentic_ops.get_challenge = authentic_get_challenge;
 2139|  15.2k|	authentic_ops.set_security_env = authentic_set_security_env;
 2140|       |	/* decipher: Untested */
 2141|  15.2k|	authentic_ops.decipher = authentic_decipher;
 2142|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2143|  15.2k|	authentic_ops.create_file = authentic_create_file;
 2144|  15.2k|	authentic_ops.delete_file = authentic_delete_file;
 2145|  15.2k|	authentic_ops.card_ctl = authentic_card_ctl;
 2146|  15.2k|	authentic_ops.process_fci = authentic_process_fci;
 2147|  15.2k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2148|  15.2k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2149|       |
 2150|  15.2k|	return &authentic_drv;
 2151|  15.2k|}
card-authentic.c:authentic_match_card:
  396|  11.2k|{
  397|  11.2k|	struct sc_context *ctx = card->ctx;
  398|  11.2k|	int i;
  399|       |
  400|  11.2k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  11.2k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  11.2k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  401|  11.2k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  402|  11.2k|	if (i < 0)   {
  ------------------
  |  Branch (402:6): [True: 11.0k, False: 248]
  ------------------
  403|  11.0k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  11.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  404|  11.0k|		return 0;
  405|  11.0k|	}
  406|       |
  407|    248|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   71|    248|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  408|    248|	return 1;
  409|  11.2k|}
card-authentic.c:authentic_init:
  448|    248|{
  449|    248|	struct sc_context *ctx = card->ctx;
  450|    248|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    248|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  451|       |
  452|    248|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    248|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    248|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    248|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    248|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 248]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|    248|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (453:11): [True: 248, False: 0]
  ------------------
  454|    248|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (454:7): [True: 248, False: 0]
  ------------------
  455|    248|			card->name = authentic_known_atrs[ii].name;
  456|    248|			card->flags = authentic_known_atrs[ii].flags;
  457|    248|			break;
  458|    248|		}
  459|    248|	}
  460|       |
  461|    248|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (461:6): [True: 0, False: 248]
  ------------------
  462|    248|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|       |
  464|    248|	card->cla  = 0x00;
  465|    248|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  466|    248|	if (!card->drv_data)
  ------------------
  |  Branch (466:6): [True: 0, False: 248]
  ------------------
  467|    248|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|       |
  469|    248|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (469:6): [True: 248, False: 0]
  ------------------
  470|    248|		rv = authentic_init_oberthur_authentic_3_2(card);
  471|       |
  472|    248|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    248|#define SC_SUCCESS				0
  ------------------
  |  Branch (472:6): [True: 139, False: 109]
  ------------------
  473|    139|		rv = authentic_get_serialnr(card, NULL);
  474|       |
  475|    248|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    248|#define SC_SUCCESS				0
  ------------------
  |  Branch (475:6): [True: 26, False: 222]
  ------------------
  476|     26|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     26|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  477|       |
  478|       |	/* Free private data on error */
  479|    248|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    248|#define SC_SUCCESS				0
  ------------------
  |  Branch (479:6): [True: 26, False: 222]
  ------------------
  480|     26|		free(card->drv_data);
  481|     26|		card->drv_data = NULL;
  482|     26|	}
  483|    248|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    248|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    248|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    248|	int _ret = r; \
  |  |  |  |  155|    248|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 248, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    248|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26, False: 222]
  |  |  |  |  ------------------
  |  |  |  |  157|    248|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    248|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    248|	return _ret; \
  |  |  |  |  163|    248|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|    248|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  414|    248|{
  415|    248|	struct sc_context *ctx = card->ctx;
  416|    248|	unsigned int flags;
  417|    248|	int rv = 0;
  418|       |
  419|    248|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    248|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    248|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    248|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    248|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 248]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|       |
  421|    248|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    248|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    248|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    248|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    248|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    248|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    248|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    248|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|    248|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    248|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    248|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    248|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    248|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    248|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    248|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    248|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  422|       |
  423|    248|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    248|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  424|    248|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    248|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  425|    248|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    248|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  426|       |
  427|    248|#ifdef ENABLE_SM
  428|    248|	card->sm_ctx.ops.open = authentic_sm_open;
  429|    248|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  430|    248|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  431|    248|#endif
  432|       |
  433|    248|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  434|    248|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    248|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    248|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    248|	int _ret = (r); \
  |  |  |  |  168|    248|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 126, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  169|    126|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    126|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    126|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    126|		return _ret; \
  |  |  |  |  172|    126|	} \
  |  |  |  |  173|    248|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  435|       |
  436|    122|	rv = authentic_select_mf(card, NULL);
  437|    122|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 109]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|       |
  439|    109|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  440|    109|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  441|       |
  442|    109|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    109|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    109|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    109|	int _ret = r; \
  |  |  |  |  155|    109|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 109, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    109|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  157|    109|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    109|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    109|	return _ret; \
  |  |  |  |  163|    109|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|    109|}
card-authentic.c:authentic_select_mf:
  550|    122|{
  551|    122|	struct sc_context *ctx = card->ctx;
  552|    122|	struct sc_path mfpath;
  553|    122|	int rv;
  554|       |
  555|    122|	struct sc_apdu apdu;
  556|    122|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  557|       |
  558|    122|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    122|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    122|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    122|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    122|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|       |
  560|    122|	sc_format_path("3F00", &mfpath);
  561|    122|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    122|#define SC_PATH_TYPE_PATH		2
  ------------------
  562|       |
  563|    122|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    122|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  564|       |
  565|    122|	apdu.resp = rbuf;
  566|    122|	apdu.resplen = sizeof(rbuf);
  567|       |
  568|    122|	rv = sc_transmit_apdu(card, &apdu);
  569|    122|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 121]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 121]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|    121|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  571|    121|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|    121|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    121|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    121|	int _ret = (r); \
  |  |  |  |  168|    121|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 115]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 115]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  572|       |
  573|    115|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  574|    115|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    115|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    115|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    115|	int _ret = (r); \
  |  |  |  |  168|    115|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    115|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 109]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  575|       |
  576|    109|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    109|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    109|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    109|	int _ret = r; \
  |  |  |  |  155|    109|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 109, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    109|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  157|    109|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    109|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    109|	return _ret; \
  |  |  |  |  163|    109|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  577|    109|}
card-authentic.c:authentic_set_current_files:
  511|    490|{
  512|    490|	struct sc_context *ctx = card->ctx;
  513|    490|	struct sc_file *file = NULL;
  514|    490|	int rv;
  515|       |
  516|    490|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    490|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    490|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    490|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    490|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 490]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|    490|	if (resplen)   {
  ------------------
  |  Branch (517:6): [True: 222, False: 268]
  ------------------
  518|    222|		switch (resp[0]) {
  519|     40|		case 0x62:
  ------------------
  |  Branch (519:3): [True: 40, False: 182]
  ------------------
  520|    204|		case 0x6F:
  ------------------
  |  Branch (520:3): [True: 164, False: 58]
  ------------------
  521|    204|			file = sc_file_new();
  522|    204|			if (file == NULL)
  ------------------
  |  Branch (522:8): [True: 0, False: 204]
  ------------------
  523|    204|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|    204|			if (path)
  ------------------
  |  Branch (524:8): [True: 204, False: 0]
  ------------------
  525|    204|				file->path = *path;
  526|       |
  527|    204|			rv = authentic_process_fci(card, file, resp, resplen);
  528|    204|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    204|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:8): [True: 23, False: 181]
  ------------------
  529|     23|				sc_file_free(file);
  530|     23|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process error");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     23|		return _ret; \
  |  |  |  |  172|     23|	} \
  |  |  |  |  173|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  531|     23|			}
  532|       |
  533|    181|			break;
  534|    181|		default:
  ------------------
  |  Branch (534:3): [True: 18, False: 204]
  ------------------
  535|     18|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    222|		}
  537|       |
  538|    181|		if (file_out)
  ------------------
  |  Branch (538:7): [True: 87, False: 94]
  ------------------
  539|     87|			*file_out = file;
  540|     94|		else
  541|     94|			sc_file_free(file);
  542|    181|	}
  543|       |
  544|    449|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    449|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    449|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    449|	int _ret = r; \
  |  |  |  |  155|    449|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 449, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    449|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 449]
  |  |  |  |  ------------------
  |  |  |  |  157|    449|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    449|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    449|	return _ret; \
  |  |  |  |  163|    449|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  545|    449|}
card-authentic.c:authentic_get_serialnr:
 1470|    241|{
 1471|    241|	struct sc_context *ctx = card->ctx;
 1472|    241|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1473|    241|	int rv;
 1474|       |
 1475|    241|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    241|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    241|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    241|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    241|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 241]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1476|    241|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1476:6): [True: 155, False: 86]
  ------------------
 1477|    155|		rv = authentic_get_cplc(card);
 1478|    155|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    155|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    155|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    155|	int _ret = (r); \
  |  |  |  |  168|    155|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  169|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     41|		return _ret; \
  |  |  |  |  172|     41|	} \
  |  |  |  |  173|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 114]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1479|       |
 1480|    114|		card->serialnr.len = 4;
 1481|    114|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1482|       |
 1483|    114|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   71|    114|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1484|    114|				card->serialnr.value[0], card->serialnr.value[1],
 1485|    114|				card->serialnr.value[2], card->serialnr.value[3]);
 1486|    114|	}
 1487|       |
 1488|    200|	if (serial)
  ------------------
  |  Branch (1488:6): [True: 87, False: 113]
  ------------------
 1489|     87|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1490|       |
 1491|    200|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    200|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    200|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    200|	int _ret = r; \
  |  |  |  |  155|    200|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 200]
  |  |  |  |  ------------------
  |  |  |  |  157|    200|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    200|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    200|	return _ret; \
  |  |  |  |  163|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|    200|}
card-authentic.c:authentic_get_cplc:
  366|    155|{
  367|    155|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  368|    155|	struct sc_apdu apdu;
  369|    155|	int rv, ii;
  370|    155|	unsigned char p1, p2;
  371|       |
  372|    155|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    155|#define SC_CPLC_TAG		0x9F7F
  ------------------
  373|    155|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    155|#define SC_CPLC_TAG		0x9F7F
  ------------------
  374|    155|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    155|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  375|    158|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (375:12): [True: 157, False: 1]
  ------------------
  376|    157|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    157|#define SC_CPLC_DER_SIZE	45
  ------------------
  377|    157|		apdu.resplen = sizeof(prv_data->cplc.value);
  378|    157|		apdu.resp = prv_data->cplc.value;
  379|       |
  380|    157|		rv = sc_transmit_apdu(card, &apdu);
  381|    157|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    157|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    157|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    157|	int _ret = (r); \
  |  |  |  |  168|    157|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 155]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|    157|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 155]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|    155|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  383|    155|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    155|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (383:7): [True: 152, False: 3]
  ------------------
  384|    152|			break;
  385|       |
  386|      3|		apdu.cla = 0x80;
  387|      3|	}
  388|    153|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    153|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    153|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    153|	int _ret = (r); \
  |  |  |  |  168|    153|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|    153|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 114]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  389|       |
  390|    114|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    114|#define SC_CPLC_DER_SIZE	45
  ------------------
  391|    114|	return SC_SUCCESS;
  ------------------
  |  |   28|    114|#define SC_SUCCESS				0
  ------------------
  392|    153|}
card-authentic.c:authentic_finish:
 1853|    222|{
 1854|    222|	struct sc_context *ctx = card->ctx;
 1855|       |
 1856|    222|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    222|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    222|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    222|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    222|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 222]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1857|       |
 1858|    222|#ifdef ENABLE_SM
 1859|    222|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1859:6): [True: 0, False: 222]
  ------------------
 1860|      0|		card->sm_ctx.ops.close(card);
 1861|    222|#endif
 1862|       |
 1863|    222|	if (card->drv_data)
  ------------------
  |  Branch (1863:6): [True: 222, False: 0]
  ------------------
 1864|    222|		free(card->drv_data);
 1865|    222|	card->drv_data = NULL;
 1866|    222|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    222|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    222|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    222|	int _ret = r; \
  |  |  |  |  155|    222|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    222|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 222]
  |  |  |  |  ------------------
  |  |  |  |  157|    222|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    222|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    222|	return _ret; \
  |  |  |  |  163|    222|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1867|    222|}
card-authentic.c:authentic_read_binary:
  649|    407|{
  650|    407|	struct sc_context *ctx = card->ctx;
  651|    407|	struct sc_apdu apdu;
  652|    407|	size_t sz, rest, ret_count = 0;
  653|    407|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    407|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  654|       |
  655|    407|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    407|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    407|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    407|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    407|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 407]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|    407|	sc_log(ctx, "offs:%i,count:%zu,max_recv_size:%zu", idx, count, card->max_recv_size);
  ------------------
  |  |   71|    407|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  657|       |
  658|    407|	rest = count;
  659|  1.29k|	while(rest)   {
  ------------------
  |  Branch (659:8): [True: 897, False: 401]
  ------------------
  660|    897|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (660:8): [True: 490, False: 407]
  ------------------
  661|    897|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|    897|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  662|    897|		apdu.le = sz;
  663|    897|		apdu.resplen = sz;
  664|    897|		apdu.resp = (buf + ret_count);
  665|       |
  666|    897|		rv = sc_transmit_apdu(card, &apdu);
  667|    897|		if(!rv)
  ------------------
  |  Branch (667:6): [True: 891, False: 6]
  ------------------
  668|    891|			ret_count += apdu.resplen;
  669|      6|		else
  670|      6|			break;
  671|       |
  672|    891|		idx += sz;
  673|    891|		rest -= sz;
  674|    891|	}
  675|       |
  676|    407|	if (rv)   {
  ------------------
  |  Branch (676:6): [True: 6, False: 401]
  ------------------
  677|      6|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  678|      0|		LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  679|      0|	}
  680|       |
  681|    401|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  682|    401|	if (!rv)
  ------------------
  |  Branch (682:6): [True: 371, False: 30]
  ------------------
  683|    371|		count = ret_count;
  684|       |
  685|    401|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    401|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    401|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    401|	int _ret = (r); \
  |  |  |  |  168|    401|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 371]
  |  |  |  |  ------------------
  |  |  |  |  169|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     30|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     30|		return _ret; \
  |  |  |  |  172|     30|	} \
  |  |  |  |  173|    401|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 371]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  686|    371|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|    371|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    371|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    371|	int _ret = r; \
  |  |  |  |  155|    371|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 364]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    364|	} else { \
  |  |  |  |  159|    364|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    364|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    364|	} \
  |  |  |  |  162|    371|	return _ret; \
  |  |  |  |  163|    371|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|    371|}
card-authentic.c:authentic_select_file:
  582|  1.21k|{
  583|  1.21k|	struct sc_context *ctx = card->ctx;
  584|  1.21k|	struct sc_apdu apdu;
  585|  1.21k|	struct sc_path lpath;
  586|  1.21k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  587|  1.21k|	size_t pathlen;
  588|  1.21k|	int rv;
  589|       |
  590|  1.21k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.21k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.21k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.21k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.21k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|       |
  592|  1.21k|	memcpy(&lpath, path, sizeof(struct sc_path));
  593|       |
  594|  1.21k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  2.43k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (594:6): [True: 683, False: 536]
  |  Branch (594:41): [True: 18, False: 665]
  ------------------
  595|     18|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     18|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  596|       |
  597|  1.21k|	pathlen = lpath.len;
  598|  1.21k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.21k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  599|       |
  600|  1.21k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (600:6): [True: 0, False: 1.21k]
  ------------------
  601|  1.21k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported card");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|       |
  603|  1.21k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.21k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (603:6): [True: 18, False: 1.20k]
  ------------------
  604|     18|		apdu.p1 = 0x00;
  605|     18|	}
  606|  1.20k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.20k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (606:11): [True: 665, False: 536]
  ------------------
  607|    665|		apdu.p1 = 0x08;
  608|    665|	}
  609|    536|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    536|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (609:11): [True: 0, False: 536]
  ------------------
  610|      0|		apdu.p1 = 0x09;
  611|      0|	}
  612|    536|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    536|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (612:11): [True: 536, False: 0]
  ------------------
  613|    536|		apdu.p1 = 4;
  614|    536|	}
  615|      0|	else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (615:11): [True: 0, False: 0]
  ------------------
  616|      0|		apdu.p1 = 0x03;
  617|      0|		pathlen = 0;
  618|      0|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  619|      0|	}
  620|      0|	else   {
  621|      0|		sc_log(ctx, "Invalid PATH type: 0x%X", lpath.type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  622|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "authentic_select_file() invalid PATH type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  623|      0|	}
  624|       |
  625|  1.21k|	apdu.lc = pathlen;
  626|  1.21k|	apdu.data = lpath.value;
  627|  1.21k|	apdu.datalen = pathlen;
  628|       |
  629|  1.21k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  2.43k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (629:6): [True: 1.21k, False: 0]
  |  Branch (629:42): [True: 0, False: 0]
  ------------------
  630|  1.21k|		apdu.resp = rbuf;
  631|  1.21k|		apdu.resplen = sizeof(rbuf);
  632|  1.21k|		apdu.le = 256;
  633|  1.21k|	}
  634|       |
  635|  1.21k|	rv = sc_transmit_apdu(card, &apdu);
  636|  1.21k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.21k|	int _ret = (r); \
  |  |  |  |  168|  1.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 1.20k]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|  1.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  637|  1.20k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  638|  1.20k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.20k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.20k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.20k|	int _ret = (r); \
  |  |  |  |  168|  1.20k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 833, False: 375]
  |  |  |  |  ------------------
  |  |  |  |  169|    833|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    833|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    833|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    833|		return _ret; \
  |  |  |  |  172|    833|	} \
  |  |  |  |  173|  1.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 375]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  639|       |
  640|    375|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  641|    375|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    375|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    375|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    375|	int _ret = (r); \
  |  |  |  |  168|    375|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 340]
  |  |  |  |  ------------------
  |  |  |  |  169|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     35|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     35|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     35|		return _ret; \
  |  |  |  |  172|     35|	} \
  |  |  |  |  173|    375|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 340]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|       |
  643|    340|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    340|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    340|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    340|	int _ret = r; \
  |  |  |  |  155|    340|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 340, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    340|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 340]
  |  |  |  |  ------------------
  |  |  |  |  157|    340|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    340|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    340|	return _ret; \
  |  |  |  |  163|    340|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|    340|}
card-authentic.c:authentic_card_ctl:
 1744|    102|{
 1745|    102|	struct sc_context *ctx = card->ctx;
 1746|    102|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1747|       |
 1748|    102|	switch (cmd) {
  ------------------
  |  Branch (1748:10): [True: 102, False: 0]
  ------------------
 1749|    102|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1749:2): [True: 102, False: 0]
  ------------------
 1750|    102|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1751|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1751:2): [True: 0, False: 102]
  ------------------
 1752|      0|		sc_log(ctx, "CARDCTL SDO_CREATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1753|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1754|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1754:2): [True: 0, False: 102]
  ------------------
 1755|      0|		sc_log(ctx, "CARDCTL SDO_DELETE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1756|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1757|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1757:2): [True: 0, False: 102]
  ------------------
 1758|      0|		sc_log(ctx, "CARDCTL SDO_STORE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1759|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1760|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1760:2): [True: 0, False: 102]
  ------------------
 1761|      0|		sc_log(ctx, "CARDCTL SDO_GENERATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1762|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1763|    102|	}
 1764|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1765|    102|}
card-authentic.c:authentic_get_tagged_data:
  177|    120|{
  178|    120|	size_t size_len, tag_len, offs, size;
  179|    120|	int rv;
  180|    120|	unsigned tag;
  181|       |
  182|    120|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 120]
  |  Branch (182:14): [True: 0, False: 120]
  ------------------
  183|    120|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|    941|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 896, False: 45]
  ------------------
  186|    896|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 84, False: 812]
  |  Branch (186:33): [True: 91, False: 721]
  ------------------
  187|    175|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 7, False: 168]
  ------------------
  188|    175|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    168|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|    168|			tag_len = 2;
  191|    168|		}
  192|    721|		else   {
  193|    721|			tag = *(in + offs);
  194|    721|			tag_len = 1;
  195|    721|		}
  196|       |
  197|    889|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 19, False: 870]
  ------------------
  198|    889|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    870|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|    870|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|    870|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    870|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    870|	int _ret = (r); \
  |  |  |  |  168|    870|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 858]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|    870|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 858]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|    858|		size_len = rv;
  203|       |
  204|    858|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 37, False: 821]
  ------------------
  205|     37|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 2, False: 35]
  ------------------
  206|     37|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|     35|			*out = in + offs + tag_len + size_len;
  209|     35|			*out_len = size;
  210|       |
  211|     35|			return SC_SUCCESS;
  ------------------
  |  |   28|     35|#define SC_SUCCESS				0
  ------------------
  212|     37|		}
  213|       |
  214|    821|		offs += tag_len + size_len + size;
  215|    821|	}
  216|       |
  217|     45|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     45|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    120|}
card-authentic.c:authentic_parse_size:
  149|    870|{
  150|    870|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 870]
  |  Branch (150:13): [True: 0, False: 870]
  |  Branch (150:21): [True: 0, False: 870]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|    870|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 652, False: 218]
  ------------------
  154|    652|		*out = *in;
  155|    652|		return 1;
  156|    652|	}
  157|    218|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 80, False: 138]
  ------------------
  158|     80|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 2, False: 78]
  ------------------
  159|      2|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|     78|		*out = *(in + 1);
  161|     78|		return 2;
  162|     80|	}
  163|    138|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 130, False: 8]
  ------------------
  164|    130|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 2, False: 128]
  ------------------
  165|      2|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|    128|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|    128|		return 3;
  168|    130|	}
  169|       |
  170|      8|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      8|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|    870|}
card-authentic.c:authentic_process_fci:
  775|    204|{
  776|    204|	struct sc_context *ctx = card->ctx;
  777|    204|	size_t taglen;
  778|    204|	int rv;
  779|    204|	unsigned ii;
  780|    204|	const unsigned char *tag = NULL;
  781|    204|	unsigned char ops_DF[8] = {
  782|    204|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    204|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    204|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    204|#define SC_AC_OP_CRYPTO			7
  ------------------
  783|    204|	};
  784|    204|	unsigned char ops_EF[8] = {
  785|    204|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    204|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    204|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  189|    204|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  191|    204|#define SC_AC_OP_RESIZE			25
  ------------------
  786|    204|	};
  787|       |
  788|    204|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    204|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    204|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    204|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    204|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 204]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|       |
  790|    204|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  791|    204|	if (tag != NULL) {
  ------------------
  |  Branch (791:6): [True: 154, False: 50]
  ------------------
  792|    154|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    154|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  793|    154|		buf = tag;
  794|    154|		buflen = taglen;
  795|    154|	}
  796|       |
  797|    204|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  798|    204|	if (tag != NULL) {
  ------------------
  |  Branch (798:6): [True: 38, False: 166]
  ------------------
  799|     38|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|     38|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  800|     38|		buf = tag;
  801|     38|		buflen = taglen;
  802|     38|	}
  803|       |
  804|    204|	rv = iso_ops->process_fci(card, file, buf, buflen);
  805|    204|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    204|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    204|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    204|	int _ret = (r); \
  |  |  |  |  168|    204|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 204]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    204|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 204]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|       |
  807|    204|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (807:6): [True: 71, False: 133]
  ------------------
  808|     71|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|     71|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     71|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|     71|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   71|     71|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  810|     71|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    142|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     48|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (810:7): [True: 23, False: 48]
  |  Branch (810:50): [True: 25, False: 23]
  ------------------
  811|     48|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     48|#define SC_FILE_TYPE_DF			0x04
  ------------------
  812|     48|		}
  813|     23|		else   {
  814|     23|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     23|		return _ret; \
  |  |  |  |  172|     23|	} \
  |  |  |  |  173|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|     23|		}
  816|     71|	}
  817|       |
  818|    181|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    181|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    181|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  819|    658|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (819:15): [True: 484, False: 174]
  |  Branch (819:46): [True: 477, False: 7]
  ------------------
  820|    477|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    477|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (820:22): [True: 67, False: 410]
  ------------------
  821|    477|		unsigned char acl = *(file->sec_attr + ii*2);
  822|    477|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  823|    477|		unsigned sc = acl * 0x100 + cred_id;
  824|       |
  825|    477|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    477|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  826|    477|		if (op == 0xFF)
  ------------------
  |  Branch (826:7): [True: 71, False: 406]
  ------------------
  827|     71|			;
  828|    406|		else if (!acl && !cred_id)
  ------------------
  |  Branch (828:12): [True: 109, False: 297]
  |  Branch (828:20): [True: 43, False: 66]
  ------------------
  829|     43|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     43|#define SC_AC_NONE			0x00000000
  ------------------
  830|    363|		else if (acl == 0xFF)
  ------------------
  |  Branch (830:12): [True: 55, False: 308]
  ------------------
  831|     55|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     55|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    308|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    308|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (832:12): [True: 130, False: 178]
  ------------------
  833|    130|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    130|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  834|    178|		else if (cred_id)
  ------------------
  |  Branch (834:12): [True: 121, False: 57]
  ------------------
  835|    121|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    121|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  836|     57|		else
  837|     57|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     57|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  838|    477|	}
  839|       |
  840|    181|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    181|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    181|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    181|	int _ret = r; \
  |  |  |  |  155|    181|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 181, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    181|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    181|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    181|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    181|	return _ret; \
  |  |  |  |  163|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|    181|}
card-authentic.c:authentic_pin_cmd:
 1438|    102|{
 1439|    102|	struct sc_context *ctx = card->ctx;
 1440|    102|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    102|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1441|       |
 1442|    102|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    102|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    102|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    102|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    102|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1443|    102|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1444|    102|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1445|    102|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1446|       |
 1447|    102|	switch (data->cmd)   {
 1448|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1448:2): [True: 0, False: 102]
  ------------------
 1449|      0|		rv = authentic_pin_verify(card, data);
 1450|      0|		break;
 1451|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1451:2): [True: 0, False: 102]
  ------------------
 1452|      0|		rv = authentic_pin_change(card, data);
 1453|      0|		break;
 1454|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1454:2): [True: 0, False: 102]
  ------------------
 1455|      0|		rv = authentic_pin_reset(card, data);
 1456|      0|		break;
 1457|    102|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    102|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1457:2): [True: 102, False: 0]
  ------------------
 1458|    102|		rv = authentic_pin_get_policy(card, data, NULL);
 1459|    102|		break;
 1460|      0|	default:
  ------------------
  |  Branch (1460:2): [True: 0, False: 102]
  ------------------
 1461|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN command");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1462|    102|	}
 1463|       |
 1464|    102|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    102|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    102|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    102|	int _ret = r; \
  |  |  |  |  155|    102|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    101|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 101, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|    102|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    102|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    102|	return _ret; \
  |  |  |  |  163|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1465|    102|}
card-authentic.c:authentic_pin_get_policy:
 1299|    102|{
 1300|    102|	struct sc_context *ctx = card->ctx;
 1301|    102|	struct sc_apdu apdu;
 1302|    102|	unsigned char rbuf[0x100];
 1303|    102|	int ii, rv;
 1304|       |
 1305|    102|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    102|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    102|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    102|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    102|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1306|    102|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|       |
 1308|    102|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    102|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1309|    105|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1309:12): [True: 104, False: 1]
  ------------------
 1310|    104|		apdu.le = sizeof(rbuf);
 1311|    104|		apdu.resp = rbuf;
 1312|    104|		apdu.resplen = sizeof(rbuf);
 1313|       |
 1314|    104|		rv = sc_transmit_apdu(card, &apdu);
 1315|    104|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    104|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    104|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    104|	int _ret = (r); \
  |  |  |  |  168|    104|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 103]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 103]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1316|    103|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1317|       |
 1318|    103|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    103|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1318:7): [True: 100, False: 3]
  ------------------
 1319|    100|			break;
 1320|       |
 1321|      3|		apdu.cla = 0x80;
 1322|      3|	}
 1323|    101|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  174|    101|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    101|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    101|	int _ret = (r); \
  |  |  |  |  168|    101|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 92]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|    101|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 92]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1324|       |
 1325|     92|	data->pin1.tries_left = -1;
 1326|       |
 1327|     92|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1328|     92|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  174|     92|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     92|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     92|	int _ret = (r); \
  |  |  |  |  168|     92|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 91, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     91|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     91|		return _ret; \
  |  |  |  |  172|     91|	} \
  |  |  |  |  173|     92|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1329|       |
 1330|      1|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      1|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1331|      1|	data->pin1.offset = 5;
 1332|      1|	data->pin1.pad_char = 0xFF;
 1333|      1|	data->pin1.pad_length = data->pin1.max_length;
 1334|      1|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      1|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1335|       |
 1336|      1|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      1|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1337|       |
 1338|      1|	sc_log(ctx, "PIN policy: size max/min/pad %zu/%zu/%zu, tries max/left %i/%i",
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1339|      1|			data->pin1.max_length, data->pin1.min_length, data->pin1.pad_length,
 1340|      1|			data->pin1.max_tries, data->pin1.tries_left);
 1341|       |
 1342|      1|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1343|      1|}
card-authentic.c:authentic_parse_credential_data:
  286|     92|{
  287|     92|	unsigned char *data;
  288|     92|	size_t data_len;
  289|     92|	int rv, ii;
  290|     92|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|     92|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|     92|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|     92|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  174|     92|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     92|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     92|	int _ret = (r); \
  |  |  |  |  168|     92|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 76, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  169|     76|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     76|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     76|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     76|		return _ret; \
  |  |  |  |  172|     76|	} \
  |  |  |  |  173|     92|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|     16|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|     16|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|     16|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  174|     16|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     16|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     16|	int _ret = (r); \
  |  |  |  |  168|     16|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|     10|	if (data_len < 1)
  ------------------
  |  Branch (297:6): [True: 1, False: 9]
  ------------------
  298|     10|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid try limit");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      9|	pin_cmd->pin1.max_tries = *data;
  300|       |
  301|      9|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|      9|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  302|      9|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|      8|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (303:6): [True: 7, False: 1]
  |  Branch (303:22): [True: 1, False: 6]
  ------------------
  304|      1|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      1|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  305|      7|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (305:11): [True: 6, False: 1]
  |  Branch (305:27): [True: 5, False: 1]
  |  Branch (305:41): [True: 1, False: 4]
  ------------------
  306|      1|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|      1|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  307|      6|	else
  308|      6|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|       |
  310|       |	/* Parse optional ACLs when requested */
  311|      2|	if (acls) {
  ------------------
  |  Branch (311:6): [True: 0, False: 2]
  ------------------
  312|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_ACLS, &data, &data_len);
  ------------------
  |  |   75|      0|#define AUTHENTIC_TAG_DOCP_ACLS			0x86
  ------------------
  313|      0|		LOG_TEST_RET(ctx, rv, "failed to get ACLs");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|      0|		sc_log(ctx, "data_len:%zu", data_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|		if (data_len == 10)   {
  ------------------
  |  Branch (315:7): [True: 0, False: 0]
  ------------------
  316|      0|			for (ii=0; ii<5; ii++)   {
  ------------------
  |  Branch (316:15): [True: 0, False: 0]
  ------------------
  317|      0|				unsigned char acl = *(data + ii*2);
  318|      0|				unsigned char cred_id = *(data + ii*2 + 1);
  319|      0|				unsigned sc = acl * 0x100 + cred_id;
  320|       |
  321|      0|				sc_log(ctx, "%i: SC:%X", ii, sc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  322|      0|				if (!sc)
  ------------------
  |  Branch (322:9): [True: 0, False: 0]
  ------------------
  323|      0|					continue;
  324|       |
  325|      0|				if (acl & AUTHENTIC_AC_SM_MASK)   {
  ------------------
  |  |  119|      0|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (325:9): [True: 0, False: 0]
  ------------------
  326|      0|					acls[ii].method = SC_AC_SCB;
  ------------------
  |  |  157|      0|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  327|      0|					acls[ii].key_ref = sc;
  328|      0|				}
  329|      0|				else if (acl!=0xFF && cred_id)   {
  ------------------
  |  Branch (329:14): [True: 0, False: 0]
  |  Branch (329:27): [True: 0, False: 0]
  ------------------
  330|      0|					sc_log(ctx, "%i: ACL(method:SC_AC_CHV,id:%i)", ii, cred_id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  331|      0|					acls[ii].method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  332|      0|					acls[ii].key_ref = cred_id;
  333|      0|				}
  334|      0|				else   {
  335|      0|					acls[ii].method = SC_AC_NEVER;
  ------------------
  |  |  163|      0|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  336|      0|					acls[ii].key_ref = 0;
  337|      0|				}
  338|      0|			}
  339|      0|		}
  340|      0|	}
  341|       |
  342|      2|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|      2|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  343|      2|	if (!rv)   {
  ------------------
  |  Branch (343:6): [True: 1, False: 1]
  ------------------
  344|      1|		blob = data;
  345|      1|		blob_len = data_len;
  346|       |
  347|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  348|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|      0|		if (data_len < 1)
  ------------------
  |  Branch (349:7): [True: 0, False: 0]
  ------------------
  350|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid PIN max.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		pin_cmd->pin1.max_length = *data;
  352|       |
  353|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      0|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  354|      0|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  355|      0|		if (data_len < 1)
  ------------------
  |  Branch (355:7): [True: 0, False: 0]
  ------------------
  356|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|      0|		pin_cmd->pin1.min_length = *data;
  358|      0|	}
  359|       |
  360|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  361|      2|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1871|    997|{
 1872|    997|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    997|#define SC_SUCCESS				0
  ------------------
 1873|       |
 1874|    997|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    997|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    997|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    997|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 997]
  |  |  ------------------
  ------------------
 1875|       |
 1876|    997|	if (was_reset > 0
  ------------------
  |  Branch (1876:6): [True: 0, False: 997]
  ------------------
 1877|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1877:7): [True: 0, False: 0]
  ------------------
 1878|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1879|      0|	}
 1880|       |
 1881|    997|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    997|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    997|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    997|	int _ret = r; \
  |  |  |  |  155|    997|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 997, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    997|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 997]
  |  |  |  |  ------------------
  |  |  |  |  157|    997|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    997|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    997|	return _ret; \
  |  |  |  |  163|    997|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1882|    997|}

sc_get_belpic_driver:
  437|  15.2k|{
  438|  15.2k|	return sc_get_driver();
  439|  15.2k|}
card-belpic.c:sc_get_driver:
  414|  15.2k|{
  415|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (415:6): [True: 1, False: 15.2k]
  ------------------
  416|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  417|       |
  418|  15.2k|	belpic_ops.match_card = belpic_match_card;
  419|  15.2k|	belpic_ops.init = belpic_init;
  420|       |
  421|  15.2k|	belpic_ops.update_binary = iso_ops->update_binary;
  422|  15.2k|	belpic_ops.select_file = belpic_select_file;
  423|  15.2k|	belpic_ops.read_binary = belpic_read_binary;
  424|  15.2k|	belpic_ops.pin_cmd = belpic_pin_cmd;
  425|  15.2k|	belpic_ops.set_security_env = belpic_set_security_env;
  426|       |
  427|  15.2k|	belpic_ops.compute_signature = iso_ops->compute_signature;
  428|  15.2k|	belpic_ops.get_challenge = iso_ops->get_challenge;
  429|  15.2k|	belpic_ops.get_response = iso_ops->get_response;
  430|  15.2k|	belpic_ops.check_sw = iso_ops->check_sw;
  431|       |
  432|  15.2k|	return &belpic_drv;
  433|  15.2k|}
card-belpic.c:belpic_match_card:
  204|  10.0k|{
  205|  10.0k|	int i;
  206|       |
  207|  10.0k|	i = _sc_match_atr(card, belpic_atrs, &card->type);
  208|  10.0k|	if (i < 0)
  ------------------
  |  Branch (208:6): [True: 9.95k, False: 94]
  ------------------
  209|  9.95k|		return 0;
  210|     94|	return 1;
  211|  10.0k|}
card-belpic.c:belpic_init:
  214|     94|{
  215|     94|	int key_size = 1024;
  216|     94|	unsigned long flags = 0;
  217|       |
  218|     94|	sc_log(card->ctx,  "Belpic V%s\n", BELPIC_VERSION);
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  218|     94|	sc_log(card->ctx,  "Belpic V%s\n", BELPIC_VERSION);
  |  |  |  |  ------------------
  |  |  |  |  |  |   93|     94|#define BELPIC_VERSION			"1.4"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  219|       |
  220|     94|	if (card->type < 0)
  ------------------
  |  Branch (220:6): [True: 0, False: 94]
  ------------------
  221|      0|		card->type = SC_CARD_TYPE_BELPIC_EID;	/* Unknown card: assume it's the Belpic Card */
  222|       |
  223|     94|	card->cla = 0x00;
  224|     94|	if (card->type == SC_CARD_TYPE_BELPIC_EID) {
  ------------------
  |  Branch (224:6): [True: 94, False: 0]
  ------------------
  225|     94|		u8 carddata[BELPIC_CARDDATA_RESP_LEN];
  226|     94|		memset(carddata, 0, sizeof(carddata));
  227|       |
  228|     94|		if(get_carddata(card, carddata, sizeof(carddata)) < 0) {
  ------------------
  |  Branch (228:6): [True: 16, False: 78]
  ------------------
  229|     16|			return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     16|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  230|     16|		}
  231|     78|		if (carddata[BELPIC_CARDDATA_OFF_APPLETVERS] >= 0x18) {
  ------------------
  |  |  127|     78|#define BELPIC_CARDDATA_OFF_APPLETVERS 21
  ------------------
  |  Branch (231:7): [True: 39, False: 39]
  ------------------
  232|     39|			flags = SC_ALGORITHM_ECDSA_HASH_NONE | SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  175|     39|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     39|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
              			flags = SC_ALGORITHM_ECDSA_HASH_NONE | SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|     39|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  233|     39|			_sc_card_add_ec_alg(card, 256, flags, 0, NULL);
  234|     39|			_sc_card_add_ec_alg(card, 384, flags, 0, NULL);
  235|     39|			_sc_card_add_ec_alg(card, 512, flags, 0, NULL);
  236|     39|			_sc_card_add_ec_alg(card, 521, flags, 0, NULL);
  237|     39|		} else {
  238|     39|			if (carddata[BELPIC_CARDDATA_OFF_APPLETVERS] >= 0x17) {
  ------------------
  |  |  127|     39|#define BELPIC_CARDDATA_OFF_APPLETVERS 21
  ------------------
  |  Branch (238:8): [True: 4, False: 35]
  ------------------
  239|      4|				key_size = 2048;
  240|      4|			}
  241|     39|			_sc_card_add_rsa_alg(card, key_size,
  242|     39|					SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE, 0);
  ------------------
  |  |  111|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              					SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE, 0);
  ------------------
  |  |  133|     39|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|     39|		}
  244|     78|	}
  245|       |
  246|       |	/* State that we have an RNG */
  247|     78|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     78|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  248|       |
  249|     78|	card->max_pin_len = BELPIC_MAX_USER_PIN_LEN;
  ------------------
  |  |  102|     78|#define BELPIC_MAX_USER_PIN_LEN		12
  ------------------
  250|       |
  251|     78|	return 0;
  252|     94|}
card-belpic.c:get_carddata:
  166|     94|{
  167|     94|	sc_apdu_t apdu;
  168|     94|	u8 carddata_cmd[] = { 0x80, 0xE4, 0x00, 0x00, 0x1C };
  169|     94|	int r;
  170|       |
  171|     94|	if (carddataloc_len != BELPIC_CARDDATA_RESP_LEN)
  ------------------
  |  |  139|     94|#define BELPIC_CARDDATA_RESP_LEN 28
  ------------------
  |  Branch (171:6): [True: 0, False: 94]
  ------------------
  172|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  173|       |
  174|     94|	r = sc_bytes2apdu(card->ctx, carddata_cmd, sizeof(carddata_cmd), &apdu);
  175|     94|	if(r) {
  ------------------
  |  Branch (175:5): [True: 0, False: 94]
  ------------------
  176|      0|		sc_log(card->ctx,  "bytes to APDU conversion failed: %d\n", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  177|      0|		return r;
  178|      0|	}
  179|       |
  180|     94|	apdu.resp = carddata_loc;
  181|     94|	apdu.resplen = carddataloc_len;
  182|       |
  183|     94|	r = sc_transmit_apdu(card, &apdu);
  184|     94|	if(r) {
  ------------------
  |  Branch (184:5): [True: 1, False: 93]
  ------------------
  185|      1|		sc_log(card->ctx,  "GetCardData command failed: %d\n", r);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  186|      1|		return r;
  187|      1|	}
  188|       |
  189|     93|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  190|     93|	if(r) {
  ------------------
  |  Branch (190:5): [True: 12, False: 81]
  ------------------
  191|     12|		sc_log(card->ctx,  "GetCardData: card returned %d\n", r);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  192|     12|		return r;
  193|     12|	}
  194|     81|	if(apdu.resplen < carddataloc_len) {
  ------------------
  |  Branch (194:5): [True: 3, False: 78]
  ------------------
  195|      3|		sc_log(card->ctx, "GetCardData: card returned %zu bytes rather than expected %d",
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  196|      3|				apdu.resplen, carddataloc_len);
  197|      3|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      3|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  198|      3|	}
  199|       |
  200|     78|	return 0;
  201|     81|}
card-belpic.c:belpic_select_file:
  256|    390|{
  257|    390|	sc_apdu_t apdu;
  258|    390|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  259|    390|	int r;
  260|    390|	size_t pathlen;
  261|    390|	sc_file_t *file = NULL;
  262|       |
  263|    390|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (263:6): [True: 0, False: 390]
  |  Branch (263:22): [True: 0, False: 390]
  ------------------
  264|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  265|    390|	memcpy(path, in_path->value, in_path->len);
  266|    390|	pathlen = in_path->len;
  267|       |
  268|    390|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x08, 0x0C);
  ------------------
  |  |  293|    390|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  269|       |
  270|    390|	apdu.lc = pathlen;
  271|    390|	apdu.data = path;
  272|    390|	apdu.datalen = pathlen;
  273|       |
  274|    390|	apdu.resplen = 0;
  275|    390|	apdu.le = 0;
  276|       |
  277|    390|	r = sc_transmit_apdu(card, &apdu);
  278|       |
  279|    390|	LOG_TEST_RET(card->ctx, r, "Select File APDU transmit failed");
  ------------------
  |  |  174|    390|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    390|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    390|	int _ret = (r); \
  |  |  |  |  168|    390|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 379]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|    390|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 379]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|       |
  281|    379|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  282|    379|	if (r)
  ------------------
  |  Branch (282:6): [True: 236, False: 143]
  ------------------
  283|    236|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    236|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    236|	int _ret = r; \
  |  |  155|    236|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 236, False: 0]
  |  |  ------------------
  |  |  156|    236|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    236|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 236, False: 0]
  |  |  ------------------
  |  |  157|    236|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    236|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    236|	return _ret; \
  |  |  163|    236|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  284|       |
  285|    143|	next_idx = (size_t)-1;		/* reset */
  286|       |
  287|    143|	if (file_out != NULL) {
  ------------------
  |  Branch (287:6): [True: 108, False: 35]
  ------------------
  288|    108|		file = sc_file_new();
  289|    108|		file->path = *in_path;
  290|    108|		if (pathlen >= 2)
  ------------------
  |  Branch (290:7): [True: 108, False: 0]
  ------------------
  291|    108|			file->id = (in_path->value[pathlen - 2] << 8) | in_path->value[pathlen - 1];
  292|    108|		file->size = BELPIC_MAX_FILE_SIZE;
  ------------------
  |  |   99|    108|#define BELPIC_MAX_FILE_SIZE		65535
  ------------------
  293|    108|		file->shareable = 1;
  294|    108|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    108|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  295|    108|		if (pathlen == 2 && memcmp("\x3F\x00", in_path->value, 2) == 0)
  ------------------
  |  Branch (295:7): [True: 20, False: 88]
  |  Branch (295:23): [True: 0, False: 20]
  ------------------
  296|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  297|    108|		else
  298|    108|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    108|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  299|    108|		*file_out = file;
  300|    108|	}
  301|       |
  302|    143|	return 0;
  303|    379|}
card-belpic.c:belpic_read_binary:
  307|    369|{
  308|    369|	int r;
  309|       |
  310|    369|	if (next_idx == idx)
  ------------------
  |  Branch (310:6): [True: 43, False: 326]
  ------------------
  311|     43|		return 0;	/* File was already read entirely */
  312|       |
  313|    326|	r = iso_ops->read_binary(card, idx, buf, count, flags);
  314|       |
  315|       |	/* If the 'next_idx trick' shouldn't work, we hope this error
  316|       |	 * means that an attempt was made to read beyond the file's
  317|       |	 * contents, so we'll return 0 to end the loop in sc_read_binary()*/
  318|    326|	if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    326|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (318:6): [True: 6, False: 320]
  ------------------
  319|      6|		return 0;
  320|       |
  321|    320|	if (r >= 0 && (size_t)r < count)
  ------------------
  |  Branch (321:6): [True: 283, False: 37]
  |  Branch (321:16): [True: 65, False: 218]
  ------------------
  322|     65|		next_idx = idx + (size_t)r;
  323|       |
  324|    320|	return r;
  325|    326|}
card-belpic.c:belpic_pin_cmd:
  328|      1|{
  329|      1|	data->pin1.encoding = data->pin2.encoding = BELPIC_PIN_ENCODING;
  ------------------
  |  |  103|      1|#define BELPIC_PIN_ENCODING		SC_PIN_ENCODING_GLP
  |  |  ------------------
  |  |  |  |  427|      1|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  |  |  ------------------
  ------------------
  330|      1|	data->pin1.pad_char = data->pin2.pad_char = BELPIC_PAD_CHAR;
  ------------------
  |  |  104|      1|#define BELPIC_PAD_CHAR			0xFF
  ------------------
  331|      1|	data->pin1.min_length = data->pin2.min_length = BELPIC_MIN_USER_PIN_LEN;
  ------------------
  |  |  101|      1|#define BELPIC_MIN_USER_PIN_LEN		4
  ------------------
  332|      1|	data->pin1.max_length = data->pin2.max_length = BELPIC_MAX_USER_PIN_LEN;
  ------------------
  |  |  102|      1|#define BELPIC_MAX_USER_PIN_LEN		12
  ------------------
  333|      1|	data->apdu = NULL;
  334|       |
  335|      1|	return iso_ops->pin_cmd(card, data);
  336|      1|}

get_cac_label:
   62|  3.55k|{
   63|  3.55k|	if (index < 0 || index >= MAX_CAC_SLOTS)
  ------------------
  |  |   70|  3.55k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (63:6): [True: 0, False: 3.55k]
  |  Branch (63:19): [True: 0, False: 3.55k]
  ------------------
   64|      0|		return NULL;
   65|       |
   66|  3.55k|	return cac_labels[index];
   67|  3.55k|}
cac_new_private_data:
   83|  1.21k|{
   84|  1.21k|	cac_private_data_t *priv;
   85|       |
   86|  1.21k|	priv = calloc(1, sizeof(cac_private_data_t));
   87|  1.21k|	if (priv == NULL)
  ------------------
  |  Branch (87:6): [True: 0, False: 1.21k]
  ------------------
   88|      0|		return NULL;
   89|       |
   90|       |	/* Initialize PKI Applets list */
   91|  1.21k|	if (list_init(&priv->pki_list) != 0 ||
  ------------------
  |  Branch (91:6): [True: 0, False: 1.21k]
  ------------------
   92|  1.21k|	    list_attributes_comparator(&priv->pki_list, cac_list_compare_path) != 0 ||
  ------------------
  |  Branch (92:6): [True: 0, False: 1.21k]
  ------------------
   93|  1.21k|	    list_attributes_copy(&priv->pki_list, cac_list_meter, 1) != 0) {
  ------------------
  |  Branch (93:6): [True: 0, False: 1.21k]
  ------------------
   94|      0|		cac_free_private_data(priv);
   95|      0|		return NULL;
   96|      0|	}
   97|       |
   98|       |	/* Initialize General Applets List */
   99|  1.21k|	if (list_init(&priv->general_list) != 0 ||
  ------------------
  |  Branch (99:6): [True: 0, False: 1.21k]
  ------------------
  100|  1.21k|	    list_attributes_comparator(&priv->general_list, cac_list_compare_path) != 0 ||
  ------------------
  |  Branch (100:6): [True: 0, False: 1.21k]
  ------------------
  101|  1.21k|	    list_attributes_copy(&priv->general_list, cac_list_meter, 1) != 0) {
  ------------------
  |  Branch (101:6): [True: 0, False: 1.21k]
  ------------------
  102|      0|		cac_free_private_data(priv);
  103|      0|		return NULL;
  104|      0|	}
  105|       |
  106|  1.21k|	return priv;
  107|  1.21k|}
cac_free_private_data:
  110|  1.21k|{
  111|  1.21k|	free(priv->cac_id);
  112|  1.21k|	free(priv->cache_buf);
  113|  1.21k|	free(priv->aca_path);
  114|  1.21k|	list_destroy(&priv->pki_list);
  115|  1.21k|	list_destroy(&priv->general_list);
  116|  1.21k|	free(priv);
  117|  1.21k|	return;
  118|  1.21k|}
cac_add_object_to_list:
  121|  4.28k|{
  122|  4.28k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (122:6): [True: 0, False: 4.28k]
  ------------------
  123|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  124|  4.28k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.28k|#define SC_SUCCESS				0
  ------------------
  125|  4.28k|}
card-cac-common.c:cac_list_compare_path:
   70|  44.8k|{
   71|  44.8k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (71:6): [True: 0, False: 44.8k]
  |  Branch (71:19): [True: 0, False: 44.8k]
  ------------------
   72|      0|		return 1;
   73|  44.8k|	return memcmp( &((cac_object_t *) a)->path,
   74|  44.8k|		&((cac_object_t *) b)->path, sizeof(sc_path_t));
   75|  44.8k|}
card-cac-common.c:cac_list_meter:
   78|  4.28k|static size_t cac_list_meter(const void *el) {
   79|  4.28k|	return sizeof(cac_object_t);
   80|  4.28k|}

sc_get_cac_driver:
 1911|  30.5k|{
 1912|  30.5k|	return sc_get_driver();
 1913|  30.5k|}
card-cac.c:sc_get_driver:
 1885|  30.5k|{
 1886|  30.5k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1887|       |
 1888|  30.5k|	cac_ops = *iso_drv->ops;
 1889|  30.5k|	cac_ops.match_card = cac_match_card;
 1890|  30.5k|	cac_ops.init = cac_init;
 1891|  30.5k|	cac_ops.finish = cac_finish;
 1892|       |
 1893|  30.5k|	cac_ops.select_file =  cac_select_file; /* need to record object type */
 1894|  30.5k|	cac_ops.get_challenge = cac_get_challenge;
 1895|  30.5k|	cac_ops.read_binary = cac_read_binary;
 1896|       |	/* CAC driver is read only */
 1897|  30.5k|	cac_ops.write_binary = NULL;
 1898|  30.5k|	cac_ops.set_security_env = cac_set_security_env;
 1899|  30.5k|	cac_ops.restore_security_env = cac_restore_security_env;
 1900|  30.5k|	cac_ops.compute_signature = cac_compute_signature;
 1901|  30.5k|	cac_ops.decipher =  cac_decipher;
 1902|  30.5k|	cac_ops.card_ctl = cac_card_ctl;
 1903|  30.5k|	cac_ops.pin_cmd = cac_pin_cmd;
 1904|  30.5k|	cac_ops.logout = cac_logout;
 1905|       |
 1906|  30.5k|	return &cac_drv;
 1907|  30.5k|}
card-cac.c:cac_match_card:
 1796|  4.79k|{
 1797|  4.79k|	int r;
 1798|  4.79k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.79k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.79k]
  |  |  ------------------
  ------------------
 1799|       |
 1800|  4.79k|	r = cac_find_and_initialize(card, 0);
 1801|  4.79k|	return (r == SC_SUCCESS); /* never match */
  ------------------
  |  |   28|  4.79k|#define SC_SUCCESS				0
  ------------------
 1802|  4.79k|}
card-cac.c:cac_find_and_initialize:
 1719|  5.81k|{
 1720|  5.81k|	int r, index;
 1721|  5.81k|	cac_private_data_t *priv = NULL;
 1722|       |
 1723|       |	/* already initialized? */
 1724|  5.81k|	if (card->drv_data) {
  ------------------
  |  Branch (1724:6): [True: 0, False: 5.81k]
  ------------------
 1725|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1726|      0|	}
 1727|       |
 1728|       |	/* is this a CAC-2 specified in NIST Interagency Report 6887 -
 1729|       |	 * "Government Smart Card Interoperability Specification v2.1 July 2003" */
 1730|  5.81k|	r = cac_select_CCC(card);
 1731|  5.81k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  5.81k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1731:6): [True: 1.38k, False: 4.43k]
  ------------------
 1732|  1.38k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "CCC found, is CAC-2");
  ------------------
  |  |   70|  1.38k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1733|  1.38k|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1733:7): [True: 903, False: 479]
  ------------------
 1734|    903|			return r;
 1735|       |
 1736|    479|		priv = cac_new_private_data();
 1737|    479|		if (!priv)
  ------------------
  |  Branch (1737:7): [True: 0, False: 479]
  ------------------
 1738|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1739|    479|		r = cac_process_CCC(card, priv, 0);
 1740|    479|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    479|#define SC_SUCCESS				0
  ------------------
  |  Branch (1740:7): [True: 232, False: 247]
  ------------------
 1741|    232|			card->type = SC_CARD_TYPE_CAC_II;
 1742|    232|			card->drv_data = priv;
 1743|    232|			return r;
 1744|    232|		}
 1745|    479|	}
 1746|       |
 1747|       |	/* Even some ALT tokens can be missing CCC so we should try with ACA */
 1748|  4.67k|	r = cac_select_ACA(card);
 1749|  4.67k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  4.67k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1749:6): [True: 492, False: 4.18k]
  ------------------
 1750|    492|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "ACA found, is CAC-2 without CCC");
  ------------------
  |  |   70|    492|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1751|    492|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1751:7): [True: 96, False: 396]
  ------------------
 1752|     96|			return r;
 1753|       |
 1754|    396|		if (!priv) {
  ------------------
  |  Branch (1754:7): [True: 361, False: 35]
  ------------------
 1755|    361|			priv = cac_new_private_data();
 1756|    361|			if (!priv)
  ------------------
  |  Branch (1756:8): [True: 0, False: 361]
  ------------------
 1757|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1758|    361|		}
 1759|    396|		r = cac_process_ACA(card, priv);
 1760|    396|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    396|#define SC_SUCCESS				0
  ------------------
  |  Branch (1760:7): [True: 342, False: 54]
  ------------------
 1761|    342|			card->type = SC_CARD_TYPE_CAC_ALT_HID;
 1762|    342|			card->drv_data = priv;
 1763|    342|			return r;
 1764|    342|		}
 1765|    396|	}
 1766|       |
 1767|       |	/* is this a CAC Alt token without any accompanying structures */
 1768|  4.24k|	r = cac_find_first_pki_applet(card, &index);
 1769|  4.24k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  4.24k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1769:6): [True: 288, False: 3.95k]
  ------------------
 1770|    288|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "PKI applet found, is bare CAC Alt");
  ------------------
  |  |   70|    288|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1771|    288|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1771:7): [True: 23, False: 265]
  ------------------
 1772|     23|			return r;
 1773|       |
 1774|    265|		if (!priv) {
  ------------------
  |  Branch (1774:7): [True: 164, False: 101]
  ------------------
 1775|    164|			priv = cac_new_private_data();
 1776|    164|			if (!priv)
  ------------------
  |  Branch (1776:8): [True: 0, False: 164]
  ------------------
 1777|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1778|    164|		}
 1779|    265|		card->drv_data = priv; /* needed for the read_binary() */
 1780|    265|		r = cac_populate_cac_alt(card, index, priv);
 1781|    265|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    265|#define SC_SUCCESS				0
  ------------------
  |  Branch (1781:7): [True: 208, False: 57]
  ------------------
 1782|    208|			card->type = SC_CARD_TYPE_CAC_II;
 1783|    208|			return r;
 1784|    208|		}
 1785|     57|		card->drv_data = NULL; /* reset on failure */
 1786|     57|	}
 1787|  4.00k|	if (priv) {
  ------------------
  |  Branch (1787:6): [True: 222, False: 3.78k]
  ------------------
 1788|    222|		cac_free_private_data(priv);
 1789|    222|	}
 1790|  4.00k|	return r;
 1791|  4.24k|}
card-cac.c:cac_select_CCC:
 1218|  5.81k|{
 1219|       |	return cac_select_file_by_type(card, &cac_CCC_Path, NULL);
 1220|  5.81k|}
card-cac.c:cac_select_file_by_type:
 1023|  85.7k|{
 1024|  85.7k|	struct sc_context *ctx;
 1025|  85.7k|	struct sc_apdu apdu;
 1026|  85.7k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
 1027|  85.7k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
 1028|  85.7k|	int r, pathtype;
 1029|  85.7k|	size_t pathlen;
 1030|  85.7k|	struct sc_file *file = NULL;
 1031|  85.7k|	cac_private_data_t *priv;
 1032|       |
 1033|  85.7k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1033:6): [True: 0, False: 85.7k]
  |  Branch (1033:22): [True: 0, False: 85.7k]
  ------------------
 1034|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1035|       |
 1036|  85.7k|	priv = CAC_DATA(card);
  ------------------
  |  |   61|  85.7k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
 1037|  85.7k|	ctx = card->ctx;
 1038|       |
 1039|  85.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  85.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  85.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  85.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 85.7k]
  |  |  ------------------
  ------------------
 1040|       |
 1041|  85.7k|	memcpy(path, in_path->value, in_path->len);
 1042|  85.7k|	pathlen = in_path->len;
 1043|  85.7k|	pathtype = in_path->type;
 1044|       |
 1045|  85.7k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  85.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1046|  85.7k|	    "path=%s, path->value=%s path->type=%d (%x)",
 1047|  85.7k|	    sc_print_path(in_path),
 1048|  85.7k|	    sc_dump_hex(in_path->value, in_path->len),
 1049|  85.7k|	    in_path->type, in_path->type);
 1050|  85.7k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "file_out=%p index=%d count=%d\n",
  ------------------
  |  |   70|  85.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1051|  85.7k|	    file_out, in_path->index, in_path->count);
 1052|       |
 1053|       |	/* Sigh, iso7816_select_file expects paths to keys to have specific
 1054|       |	 * formats. There is no override. We have to add some bytes to the
 1055|       |	 * path to make it happy.
 1056|       |	 * We only need to do this for private keys.
 1057|       |	 */
 1058|  85.7k|	if ((pathlen > 2) && (pathlen <= 4) && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (1058:6): [True: 2.31k, False: 83.3k]
  |  Branch (1058:23): [True: 2.31k, False: 0]
  |  Branch (1058:41): [True: 2.31k, False: 0]
  ------------------
 1059|  2.31k|		path += 2;
 1060|  2.31k|		pathlen -= 2;
 1061|  2.31k|	}
 1062|       |
 1063|       |
 1064|       |	/* CAC has multiple different type of objects that aren't PKCS #15. When we read
 1065|       |	 * them we need convert them to something PKCS #15 would understand. Find the object
 1066|       |	 * and object type here:
 1067|       |	 */
 1068|  85.7k|	if (priv) { /* don't record anything if we haven't been initialized yet */
  ------------------
  |  Branch (1068:6): [True: 9.25k, False: 76.4k]
  ------------------
 1069|  9.25k|		priv->object_type = CAC_OBJECT_TYPE_GENERIC;
  ------------------
  |  |  172|  9.25k|#define CAC_OBJECT_TYPE_GENERIC		5
  ------------------
 1070|  9.25k|		if (cac_is_cert(priv, in_path)) {
  ------------------
  |  Branch (1070:7): [True: 2.37k, False: 6.87k]
  ------------------
 1071|  2.37k|			priv->object_type = CAC_OBJECT_TYPE_CERT;
  ------------------
  |  |  170|  2.37k|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
 1072|  2.37k|		}
 1073|       |
 1074|       |		/* forget any old cached values */
 1075|  9.25k|		if (priv->cache_buf) {
  ------------------
  |  Branch (1075:7): [True: 115, False: 9.13k]
  ------------------
 1076|    115|			free(priv->cache_buf);
 1077|    115|			priv->cache_buf = NULL;
 1078|    115|		}
 1079|  9.25k|		priv->cache_buf_len = 0;
 1080|  9.25k|		priv->cached = 0;
 1081|  9.25k|	}
 1082|       |
 1083|  85.7k|	if (in_path->aid.len) {
  ------------------
  |  Branch (1083:6): [True: 83.3k, False: 2.31k]
  ------------------
 1084|  83.3k|		if (!pathlen) {
  ------------------
  |  Branch (1084:7): [True: 81.6k, False: 1.74k]
  ------------------
 1085|  81.6k|			memcpy(path, in_path->aid.value, in_path->aid.len);
 1086|  81.6k|			pathlen = in_path->aid.len;
 1087|  81.6k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  81.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1088|  81.6k|		} else {
 1089|       |			/* First, select the application */
 1090|  1.74k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"select application" );
  ------------------
  |  |   70|  1.74k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1091|  1.74k|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  1.74k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1092|  1.74k|			apdu.data = in_path->aid.value;
 1093|  1.74k|			apdu.datalen = in_path->aid.len;
 1094|  1.74k|			apdu.lc = in_path->aid.len;
 1095|       |
 1096|  1.74k|			r = sc_transmit_apdu(card, &apdu);
 1097|  1.74k|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.74k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.74k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.74k|	int _ret = (r); \
  |  |  |  |  168|  1.74k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 34, False: 1.71k]
  |  |  |  |  ------------------
  |  |  |  |  169|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     34|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     34|		return _ret; \
  |  |  |  |  172|     34|	} \
  |  |  |  |  173|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.71k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1098|  1.71k|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1099|  1.71k|			if (r)
  ------------------
  |  Branch (1099:8): [True: 437, False: 1.27k]
  ------------------
 1100|  1.71k|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    437|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    437|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    437|	int _ret = r; \
  |  |  |  |  155|    437|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 437, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    437|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    437|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 437, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    437|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    437|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    437|	return _ret; \
  |  |  |  |  163|    437|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|       |
 1102|  1.71k|		}
 1103|  83.3k|	}
 1104|       |
 1105|  85.2k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  85.2k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1106|       |
 1107|  85.2k|	switch (pathtype) {
 1108|       |	/* ideally we would had SC_PATH_TYPE_OBJECT_ID and add code to the iso7816 select.
 1109|       |	 * Unfortunately we'd also need to update the caching code as well. For now just
 1110|       |	 * use FILE_ID and change p1 here */
 1111|  1.27k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  1.27k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1111:2): [True: 1.27k, False: 83.9k]
  ------------------
 1112|  1.27k|		apdu.p1 = 2;
 1113|  1.27k|		if (pathlen != 2)
  ------------------
  |  Branch (1113:7): [True: 0, False: 1.27k]
  ------------------
 1114|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1115|  1.27k|		break;
 1116|  81.6k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  81.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1116:2): [True: 81.6k, False: 3.59k]
  ------------------
 1117|  81.6k|		apdu.p1 = 4;
 1118|  81.6k|		break;
 1119|  2.31k|	default:
  ------------------
  |  Branch (1119:2): [True: 2.31k, False: 82.9k]
  ------------------
 1120|  2.31k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|  2.31k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.31k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.31k|	int _ret = r; \
  |  |  |  |  155|  2.31k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.31k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.31k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.31k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.31k|	return _ret; \
  |  |  |  |  163|  2.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1121|  85.2k|	}
 1122|  82.9k|	apdu.lc = pathlen;
 1123|  82.9k|	apdu.data = path;
 1124|  82.9k|	apdu.datalen = pathlen;
 1125|  82.9k|	apdu.resp = buf;
 1126|  82.9k|	apdu.resplen = sizeof(buf);
 1127|  82.9k|	apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (1127:12): [True: 0, False: 82.9k]
  ------------------
 1128|       |
 1129|  82.9k|	if (file_out != NULL) {
  ------------------
  |  Branch (1129:6): [True: 1.67k, False: 81.2k]
  ------------------
 1130|  1.67k|		apdu.p2 = 0;		/* first record, return FCI */
 1131|  1.67k|	}
 1132|  81.2k|	else {
 1133|  81.2k|		apdu.p2 = 0x0C;
 1134|  81.2k|	}
 1135|       |
 1136|  82.9k|	r = sc_transmit_apdu(card, &apdu);
 1137|  82.9k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  82.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  82.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  82.9k|	int _ret = (r); \
  |  |  |  |  168|  82.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 921, False: 82.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|    921|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    921|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    921|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    921|		return _ret; \
  |  |  |  |  172|    921|	} \
  |  |  |  |  173|  82.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1138|       |
 1139|  82.0k|	if (file_out == NULL) {
  ------------------
  |  Branch (1139:6): [True: 80.3k, False: 1.66k]
  ------------------
 1140|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
 1141|  80.3k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1142|  80.3k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (1142:7): [True: 178, False: 80.1k]
  |  Branch (1142:27): [True: 105, False: 73]
  ------------------
 1143|    105|			apdu.p2 = 0x00;
 1144|    105|			apdu.resplen = sizeof(buf);
 1145|    105|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|    105|#define SC_SUCCESS				0
  ------------------
  |  Branch (1145:8): [True: 38, False: 67]
  ------------------
 1146|     38|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1147|    105|		}
 1148|  80.3k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1148:7): [True: 67, False: 80.2k]
  ------------------
 1149|  80.3k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     67|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     67|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     67|	int _ret = r; \
  |  |  |  |  155|     67|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 67, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  157|     67|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     67|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     67|	return _ret; \
  |  |  |  |  163|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|  80.2k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  80.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  80.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  80.2k|	int _ret = r; \
  |  |  |  |  155|  80.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 80.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  80.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  74.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 74.6k, False: 5.59k]
  |  |  |  |  ------------------
  |  |  |  |  157|  80.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  80.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  80.2k|	return _ret; \
  |  |  |  |  163|  80.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|  80.2k|	}
 1152|       |
 1153|  1.66k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1154|  1.66k|	if (r)
  ------------------
  |  Branch (1154:6): [True: 684, False: 979]
  ------------------
 1155|  1.66k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    684|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    684|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    684|	int _ret = r; \
  |  |  |  |  155|    684|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 684, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    684|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    684|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 684, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    684|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    684|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    684|	return _ret; \
  |  |  |  |  163|    684|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1156|       |
 1157|       |	/* This needs to come after the applet selection */
 1158|    979|	if (priv && in_path->len >= 2) {
  ------------------
  |  Branch (1158:6): [True: 979, False: 0]
  |  Branch (1158:14): [True: 457, False: 522]
  ------------------
 1159|       |		/* get applet properties to know if we can treat the
 1160|       |		 * buffer as SimpleLTV and if we have PKI applet.
 1161|       |		 *
 1162|       |		 * Do this only if we select applets for reading
 1163|       |		 * (not during driver initialization)
 1164|       |		 */
 1165|    457|		cac_properties_t prop = {0};
 1166|    457|		size_t i = -1;
 1167|       |
 1168|    457|		r = cac_get_properties(card, &prop);
 1169|    457|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    457|#define SC_SUCCESS				0
  ------------------
  |  Branch (1169:7): [True: 380, False: 77]
  ------------------
 1170|    439|			for (i = 0; i < prop.num_objects; i++) {
  ------------------
  |  Branch (1170:16): [True: 115, False: 324]
  ------------------
 1171|    115|				sc_log(card->ctx, "Searching for our OID: 0x%02x 0x%02x = 0x%02x 0x%02x",
  ------------------
  |  |   71|    115|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1172|    115|				    prop.objects[i].oid[0], prop.objects[i].oid[1],
 1173|    115|					in_path->value[0], in_path->value[1]);
 1174|    115|				if (memcmp(prop.objects[i].oid,
  ------------------
  |  Branch (1174:9): [True: 56, False: 59]
  ------------------
 1175|    115|				    in_path->value, 2) == 0)
 1176|     56|					break;
 1177|    115|			}
 1178|    380|		}
 1179|    457|		if (i < prop.num_objects) {
  ------------------
  |  Branch (1179:7): [True: 56, False: 401]
  ------------------
 1180|     56|			if (prop.objects[i].privatekey)
  ------------------
  |  Branch (1180:8): [True: 9, False: 47]
  ------------------
 1181|      9|				priv->object_type = CAC_OBJECT_TYPE_CERT;
  ------------------
  |  |  170|      9|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
 1182|     47|			else if (prop.objects[i].simpletlv == 0)
  ------------------
  |  Branch (1182:13): [True: 44, False: 3]
  ------------------
 1183|     44|				priv->object_type = CAC_OBJECT_TYPE_TLV_FILE;
  ------------------
  |  |  171|     44|#define CAC_OBJECT_TYPE_TLV_FILE	4
  ------------------
 1184|     56|		}
 1185|    457|	}
 1186|       |
 1187|       |	/* CAC cards never return FCI, fake one */
 1188|    979|	file = sc_file_new();
 1189|    979|	if (file == NULL)
  ------------------
  |  Branch (1189:6): [True: 0, False: 979]
  ------------------
 1190|    979|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1191|    979|	file->path = *in_path;
 1192|    979|	file->size = CAC_MAX_SIZE; /* we don't know how big, just give a large size until we can read the file */
  ------------------
  |  |   26|    979|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
 1193|       |
 1194|    979|	*file_out = file;
 1195|    979|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    979|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    979|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    979|	int _ret = r; \
  |  |  |  |  155|    979|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 979, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    979|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 979]
  |  |  |  |  ------------------
  |  |  |  |  157|    979|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    979|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    979|	return _ret; \
  |  |  |  |  163|    979|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1196|       |
 1197|    979|}
card-cac.c:cac_is_cert:
  231|  9.25k|{
  232|  9.25k|	cac_object_t test_obj = {0};
  233|  9.25k|	test_obj.path = *in_path;
  234|  9.25k|	test_obj.path.index = 0;
  235|  9.25k|	test_obj.path.count = 0;
  236|       |
  237|  9.25k|	return (list_contains(&priv->pki_list, &test_obj) != 0);
  238|  9.25k|}
card-cac.c:cac_get_properties:
  919|    676|{
  920|    676|	u8 *rbuf = NULL;
  921|    676|	size_t rbuflen = 0, len;
  922|    676|	const u8 *val, *val_end;
  923|    676|	u8 tag;
  924|    676|	size_t i = 0;
  925|    676|	int r;
  926|    676|	prop->num_objects = 0;
  927|       |
  928|    676|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    676|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    676|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    676|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 676]
  |  |  ------------------
  ------------------
  929|       |
  930|    676|	r = cac_apdu_io(card, CAC_INS_GET_PROPERTIES, 0x01, 0x00, NULL, 0,
  ------------------
  |  |   63|    676|#define CAC_INS_GET_PROPERTIES        0x56
  ------------------
  931|    676|		&rbuf, &rbuflen);
  932|    676|	if (r < 0)
  ------------------
  |  Branch (932:6): [True: 85, False: 591]
  ------------------
  933|     85|		return r;
  934|       |
  935|    591|	val = rbuf;
  936|    591|	val_end = val + rbuflen;
  937|  8.71k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (937:9): [True: 8.44k, False: 278]
  ------------------
  938|       |		/* get the tag and the length */
  939|  8.44k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  8.44k|#define SC_SUCCESS				0
  ------------------
  |  Branch (939:7): [True: 311, False: 8.13k]
  ------------------
  940|    311|			break;
  941|       |
  942|  8.13k|		switch (tag) {
  943|    679|		case CAC_TAG_APPLET_INFORMATION:
  ------------------
  |  |   89|    679|#define CAC_TAG_APPLET_INFORMATION    0x01
  ------------------
  |  Branch (943:3): [True: 679, False: 7.45k]
  ------------------
  944|    679|			if (len != 5) {
  ------------------
  |  Branch (944:8): [True: 466, False: 213]
  ------------------
  945|    466|				sc_log(card->ctx, "TAG: Applet Information: Invalid length %zu", len);
  ------------------
  |  |   71|    466|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  946|    466|				break;
  947|    466|			}
  948|    213|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    213|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  949|    213|			    "TAG: Applet Information: Family: 0x%0x", val[0]);
  950|    213|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    213|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  951|    213|			    "     Applet Version: 0x%02x 0x%02x 0x%02x 0x%02x",
  952|    213|			    val[1], val[2], val[3], val[4]);
  953|    213|			break;
  954|       |
  955|  1.02k|		case CAC_TAG_NUMBER_OF_OBJECTS:
  ------------------
  |  |   90|  1.02k|#define CAC_TAG_NUMBER_OF_OBJECTS     0x40
  ------------------
  |  Branch (955:3): [True: 1.02k, False: 7.10k]
  ------------------
  956|  1.02k|			if (len != 1) {
  ------------------
  |  Branch (956:8): [True: 306, False: 716]
  ------------------
  957|    306|				sc_log(card->ctx, "TAG: Num objects: Invalid length %zu", len);
  ------------------
  |  |   71|    306|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  958|    306|				break;
  959|    306|			}
  960|    716|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    716|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  961|    716|			    "TAG: Num objects = %hhd", *val);
  962|       |			/* make sure we do not overrun buffer */
  963|    716|			prop->num_objects = MIN(val[0], CAC_MAX_OBJECTS);
  ------------------
  |  |   69|    716|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 465, False: 251]
  |  |  ------------------
  ------------------
  964|    716|			break;
  965|       |
  966|  1.13k|		case CAC_TAG_TV_BUFFER:
  ------------------
  |  |   91|  1.13k|#define CAC_TAG_TV_BUFFER             0x50
  ------------------
  |  Branch (966:3): [True: 1.13k, False: 6.99k]
  ------------------
  967|  1.13k|			if (len != 17) {
  ------------------
  |  Branch (967:8): [True: 282, False: 851]
  ------------------
  968|    282|				sc_log(card->ctx, "TAG: TV Object: Invalid length %zu", len);
  ------------------
  |  |   71|    282|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  969|    282|				break;
  970|    282|			}
  971|    851|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "TAG: TV Object nr. %zu", i);
  ------------------
  |  |   70|    851|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  972|    851|			if (i >= CAC_MAX_OBJECTS) {
  ------------------
  |  |  145|    851|#define CAC_MAX_OBJECTS 16
  ------------------
  |  Branch (972:8): [True: 1, False: 850]
  ------------------
  973|      1|				free(rbuf);
  974|      1|				return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  975|      1|			}
  976|       |
  977|    850|			if (cac_parse_properties_object(card, tag, val, len,
  ------------------
  |  Branch (977:8): [True: 68, False: 782]
  ------------------
  978|    850|			    &prop->objects[i]) == SC_SUCCESS)
  ------------------
  |  |   28|    850|#define SC_SUCCESS				0
  ------------------
  979|     68|				i++;
  980|    850|			break;
  981|       |
  982|  1.80k|		case CAC_TAG_PKI_OBJECT:
  ------------------
  |  |   92|  1.80k|#define CAC_TAG_PKI_OBJECT            0x51
  ------------------
  |  Branch (982:3): [True: 1.80k, False: 6.33k]
  ------------------
  983|  1.80k|			if (len != 17) {
  ------------------
  |  Branch (983:8): [True: 223, False: 1.57k]
  ------------------
  984|    223|				sc_log(card->ctx, "TAG: PKI Object: Invalid length %zu", len);
  ------------------
  |  |   71|    223|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  985|    223|				break;
  986|    223|			}
  987|  1.57k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "TAG: PKI Object nr. %zu", i);
  ------------------
  |  |   70|  1.57k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  988|  1.57k|			if (i >= CAC_MAX_OBJECTS) {
  ------------------
  |  |  145|  1.57k|#define CAC_MAX_OBJECTS 16
  ------------------
  |  Branch (988:8): [True: 1, False: 1.57k]
  ------------------
  989|      1|				free(rbuf);
  990|      1|				return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  991|      1|			}
  992|       |
  993|  1.57k|			if (cac_parse_properties_object(card, tag, val, len,
  ------------------
  |  Branch (993:8): [True: 332, False: 1.24k]
  ------------------
  994|  1.57k|			    &prop->objects[i]) == SC_SUCCESS)
  ------------------
  |  |   28|  1.57k|#define SC_SUCCESS				0
  ------------------
  995|    332|				i++;
  996|  1.57k|			break;
  997|       |
  998|  3.49k|		default:
  ------------------
  |  Branch (998:3): [True: 3.49k, False: 4.63k]
  ------------------
  999|       |			/* ignore tags we don't understand */
 1000|  3.49k|			sc_log(card->ctx, "TAG: Unknown (0x%02x), len=%zu", tag, len);
  ------------------
  |  |   71|  3.49k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1001|  3.49k|			break;
 1002|  8.13k|		}
 1003|  8.13k|	}
 1004|    589|	free(rbuf);
 1005|       |	/* sanity */
 1006|    589|	if (i != prop->num_objects)
  ------------------
  |  Branch (1006:6): [True: 140, False: 449]
  ------------------
 1007|    140|		sc_log(card->ctx, "The announced number of objects (%zu) did not match reality (%zu)",
  ------------------
  |  |   71|    140|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1008|    589|				prop->num_objects, i);
 1009|    589|	prop->num_objects = i;
 1010|       |
 1011|    589|	return SC_SUCCESS;
  ------------------
  |  |   28|    589|#define SC_SUCCESS				0
  ------------------
 1012|    591|}
card-cac.c:cac_apdu_io:
  253|  18.0k|{
  254|  18.0k|	int r;
  255|  18.0k|	sc_apdu_t apdu = {0};
  256|  18.0k|	u8 rbufinitbuf[CAC_MAX_SIZE];
  257|  18.0k|	u8 *rbuf;
  258|  18.0k|	size_t rbuflen;
  259|  18.0k|	unsigned int apdu_case = SC_APDU_CASE_1;
  ------------------
  |  |  291|  18.0k|#define SC_APDU_CASE_1			0x01
  ------------------
  260|       |
  261|       |
  262|  18.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  18.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  18.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  18.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 18.0k]
  |  |  ------------------
  ------------------
  263|       |
  264|  18.0k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  18.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  265|  18.0k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  266|       |
  267|  18.0k|	rbuf = rbufinitbuf;
  268|  18.0k|	rbuflen = sizeof(rbufinitbuf);
  269|       |
  270|       |	/* if caller provided a buffer and length */
  271|  18.0k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (271:6): [True: 18.0k, False: 0]
  |  Branch (271:17): [True: 16.8k, False: 1.19k]
  |  Branch (271:29): [True: 16.8k, False: 0]
  |  Branch (271:43): [True: 16.8k, False: 0]
  ------------------
  272|  16.8k|		rbuf = *recvbuf;
  273|  16.8k|		rbuflen = *recvbuflen;
  274|  16.8k|	}
  275|       |
  276|  18.0k|	if (recvbuf) {
  ------------------
  |  Branch (276:6): [True: 18.0k, False: 0]
  ------------------
  277|  18.0k|		if (sendbuf)
  ------------------
  |  Branch (277:7): [True: 16.9k, False: 1.07k]
  ------------------
  278|  16.9k|			apdu_case = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  16.9k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  279|  1.07k|		else
  280|  1.07k|			apdu_case = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  1.07k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  281|  18.0k|	} else if (sendbuf)
  ------------------
  |  Branch (281:13): [True: 0, False: 0]
  ------------------
  282|      0|		apdu_case = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  283|       |
  284|       |
  285|  18.0k|	sc_format_apdu(card, &apdu, apdu_case, ins, p1, p2);
  286|       |
  287|  18.0k|	apdu.lc = sendbuflen;
  288|  18.0k|	apdu.datalen = sendbuflen;
  289|  18.0k|	apdu.data = sendbuf;
  290|       |
  291|  18.0k|	if (recvbuf) {
  ------------------
  |  Branch (291:6): [True: 18.0k, False: 0]
  ------------------
  292|  18.0k|		apdu.resp = rbuf;
  293|  18.0k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (293:13): [True: 1.19k, False: 16.8k]
  ------------------
  294|  18.0k|		apdu.resplen = rbuflen;
  295|  18.0k|	} else {
  296|      0|		 apdu.resp =  rbuf;
  297|      0|		 apdu.le = 0;
  298|      0|		 apdu.resplen = 0;
  299|      0|	}
  300|       |
  301|  18.0k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  18.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  302|  18.0k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  303|       |
  304|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  305|  18.0k|	r = sc_transmit_apdu(card, &apdu);
  306|       |
  307|  18.0k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  18.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  308|  18.0k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  309|  18.0k|	if (r < 0) {
  ------------------
  |  Branch (309:6): [True: 239, False: 17.8k]
  ------------------
  310|    239|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    239|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  311|    239|		goto err;
  312|    239|	}
  313|       |
  314|  17.8k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  315|       |
  316|  17.8k|	if (r < 0) {
  ------------------
  |  Branch (316:6): [True: 567, False: 17.2k]
  ------------------
  317|    567|		sc_log(card->ctx,  "Card returned error ");
  ------------------
  |  |   71|    567|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|    567|		goto err;
  319|    567|	}
  320|       |
  321|  17.2k|	if (recvbuflen) {
  ------------------
  |  Branch (321:6): [True: 17.2k, False: 0]
  ------------------
  322|  17.2k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (322:7): [True: 17.2k, False: 0]
  |  Branch (322:18): [True: 1.04k, False: 16.1k]
  ------------------
  323|  1.04k|			*recvbuf =  malloc(apdu.resplen);
  324|  1.04k|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (324:8): [True: 0, False: 1.04k]
  ------------------
  325|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  326|      0|				goto err;
  327|      0|			}
  328|  1.04k|			memcpy(*recvbuf, rbuf, apdu.resplen);
  329|  1.04k|		}
  330|  17.2k|		*recvbuflen =  apdu.resplen;
  331|  17.2k|		r = (int)*recvbuflen;
  332|  17.2k|	}
  333|       |
  334|  18.0k|err:
  335|  18.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  18.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.0k|	int _ret = r; \
  |  |  |  |  155|  18.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.33k, False: 16.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.33k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    806|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 806, False: 527]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.33k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.7k|	} else { \
  |  |  |  |  159|  16.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.7k|	} \
  |  |  |  |  162|  18.0k|	return _ret; \
  |  |  |  |  163|  18.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|  18.0k|}
card-cac.c:cac_parse_properties_object:
  844|  2.42k|{
  845|  2.42k|	size_t len;
  846|  2.42k|	const u8 *val, *val_end;
  847|  2.42k|	u8 tag;
  848|  2.42k|	int parsed = 0;
  849|       |
  850|  2.42k|	if (data_len < 11)
  ------------------
  |  Branch (850:6): [True: 0, False: 2.42k]
  ------------------
  851|      0|		return -1;
  852|       |
  853|       |	/* Initialize: non-PKI applet */
  854|  2.42k|	object->privatekey = 0;
  855|       |
  856|  2.42k|	val = data;
  857|  2.42k|	val_end = data + data_len;
  858|  12.1k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (858:9): [True: 11.7k, False: 381]
  ------------------
  859|       |		/* get the tag and the length */
  860|  11.7k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  11.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (860:7): [True: 2.04k, False: 9.73k]
  ------------------
  861|  2.04k|			break;
  862|       |
  863|  9.73k|		switch (tag) {
  864|    949|		case CAC_TAG_OBJECT_ID:
  ------------------
  |  |   93|    949|#define CAC_TAG_OBJECT_ID             0x41
  ------------------
  |  Branch (864:3): [True: 949, False: 8.79k]
  ------------------
  865|    949|			if (len != 2) {
  ------------------
  |  Branch (865:8): [True: 576, False: 373]
  ------------------
  866|    576|				sc_log(card->ctx, "TAG: Object ID: Invalid length %zu", len);
  ------------------
  |  |   71|    576|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  867|    576|				break;
  868|    576|			}
  869|    373|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    373|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  870|    373|			    "TAG: Object ID = 0x%02x 0x%02x", val[0], val[1]);
  871|    373|			memcpy(&object->oid, val, 2);
  872|    373|			parsed++;
  873|    373|			break;
  874|       |
  875|  1.37k|		case CAC_TAG_BUFFER_PROPERTIES:
  ------------------
  |  |   94|  1.37k|#define CAC_TAG_BUFFER_PROPERTIES     0x42
  ------------------
  |  Branch (875:3): [True: 1.37k, False: 8.36k]
  ------------------
  876|  1.37k|			if (len != 5) {
  ------------------
  |  Branch (876:8): [True: 526, False: 851]
  ------------------
  877|    526|				sc_log(card->ctx, "TAG: Buffer Properties: Invalid length %zu", len);
  ------------------
  |  |   71|    526|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  878|    526|				break;
  879|    526|			}
  880|       |			/* First byte is "Type of Tag Supported" */
  881|    851|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    851|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  882|    851|			    "TAG: Buffer Properties: Type of Tag Supported = 0x%02x",
  883|    851|			    val[0]);
  884|    851|			object->simpletlv = val[0];
  885|    851|			parsed++;
  886|    851|			break;
  887|       |
  888|  1.56k|		case CAC_TAG_PKI_PROPERTIES:
  ------------------
  |  |   95|  1.56k|#define CAC_TAG_PKI_PROPERTIES        0x43
  ------------------
  |  Branch (888:3): [True: 1.56k, False: 8.17k]
  ------------------
  889|       |			/* 4th byte is "Private Key Initialized" */
  890|  1.56k|			if (len != 4) {
  ------------------
  |  Branch (890:8): [True: 659, False: 909]
  ------------------
  891|    659|				sc_log(card->ctx, "TAG: PKI Properties: Invalid length %zu", len);
  ------------------
  |  |   71|    659|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  892|    659|				break;
  893|    659|			}
  894|    909|			if (type != CAC_TAG_PKI_OBJECT) {
  ------------------
  |  |   92|    909|#define CAC_TAG_PKI_OBJECT            0x51
  ------------------
  |  Branch (894:8): [True: 233, False: 676]
  ------------------
  895|    233|				sc_log(card->ctx, "TAG: PKI Properties outside of PKI Object");
  ------------------
  |  |   71|    233|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  896|    233|				break;
  897|    233|			}
  898|    676|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    676|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  899|    676|			    "TAG: PKI Properties: Private Key Initialized = 0x%02x",
  900|    676|			    val[2]);
  901|    676|			object->privatekey = val[2];
  902|    676|			parsed++;
  903|    676|			break;
  904|       |
  905|  5.84k|		default:
  ------------------
  |  Branch (905:3): [True: 5.84k, False: 3.89k]
  ------------------
  906|       |			/* ignore tags we don't understand */
  907|  5.84k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  5.84k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  908|  5.84k|			    "TAG: Unknown (0x%02x)",tag );
  909|  5.84k|			break;
  910|  9.73k|		}
  911|  9.73k|	}
  912|  2.42k|	if (parsed < 2)
  ------------------
  |  Branch (912:6): [True: 2.02k, False: 400]
  ------------------
  913|  2.02k|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|  2.02k|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  914|       |
  915|    400|	return SC_SUCCESS;
  ------------------
  |  |   28|    400|#define SC_SUCCESS				0
  ------------------
  916|  2.42k|}
card-cac.c:cac_process_CCC:
 1498|  1.23k|{
 1499|  1.23k|	u8 *tl = NULL, *val = NULL;
 1500|  1.23k|	size_t tl_len = 0, val_len = 0;
 1501|  1.23k|	int r;
 1502|       |
 1503|  1.23k|	if (depth > CAC_MAX_CCC_DEPTH) {
  ------------------
  |  |  106|  1.23k|#define CAC_MAX_CCC_DEPTH             16
  ------------------
  |  Branch (1503:6): [True: 3, False: 1.23k]
  ------------------
 1504|      3|		sc_log(card->ctx, "Too much recursive CCC found. Exiting");
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1505|      3|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      3|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1506|      3|	}
 1507|       |
 1508|  1.23k|	r = cac_read_file(card, CAC_FILE_TAG, &tl, &tl_len);
  ------------------
  |  |   66|  1.23k|#define CAC_FILE_TAG    1
  ------------------
 1509|  1.23k|	if (r < 0)
  ------------------
  |  Branch (1509:6): [True: 171, False: 1.06k]
  ------------------
 1510|    171|		goto done;
 1511|       |
 1512|  1.06k|	r = cac_read_file(card, CAC_FILE_VALUE, &val, &val_len);
  ------------------
  |  |   67|  1.06k|#define CAC_FILE_VALUE  2
  ------------------
 1513|  1.06k|	if (r < 0)
  ------------------
  |  Branch (1513:6): [True: 13, False: 1.05k]
  ------------------
 1514|     13|		goto done;
 1515|       |
 1516|  1.05k|	r = cac_parse_CCC(card, priv, tl, tl_len, val, val_len, depth);
 1517|  1.23k|done:
 1518|  1.23k|	if (tl)
  ------------------
  |  Branch (1518:6): [True: 1.06k, False: 171]
  ------------------
 1519|  1.06k|		free(tl);
 1520|  1.23k|	if (val)
  ------------------
  |  Branch (1520:6): [True: 1.05k, False: 184]
  ------------------
 1521|  1.05k|		free(val);
 1522|  1.23k|	return r;
 1523|  1.05k|}
card-cac.c:cac_read_file:
  385|  3.95k|{
  386|  3.95k|	u8 params[2];
  387|  3.95k|	u8 count[2] = {0};
  388|  3.95k|	u8 *out = NULL;
  389|  3.95k|	u8 *out_ptr = NULL;
  390|  3.95k|	size_t offset = 0;
  391|  3.95k|	size_t size = 0;
  392|  3.95k|	size_t left = 0;
  393|  3.95k|	size_t len = 0;
  394|  3.95k|	int r;
  395|       |
  396|  3.95k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.95k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.95k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.95k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.95k]
  |  |  ------------------
  ------------------
  397|       |
  398|  3.95k|	params[0] = file_type;
  399|  3.95k|	params[1] = 2;
  400|       |
  401|       |	/* get the size */
  402|  3.95k|	len = sizeof(count);
  403|  3.95k|	out_ptr = count;
  404|  3.95k|	r = cac_apdu_io(card, CAC_INS_READ_FILE, 0, 0, &params[0], sizeof(params), &out_ptr, &len);
  ------------------
  |  |   61|  3.95k|#define CAC_INS_READ_FILE             0x52  /* read a TL or V file */
  ------------------
  405|  3.95k|	if (len == 0) {
  ------------------
  |  Branch (405:6): [True: 258, False: 3.70k]
  ------------------
  406|    258|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    258|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  407|    258|	}
  408|  3.95k|	if (r < 0)
  ------------------
  |  Branch (408:6): [True: 635, False: 3.32k]
  ------------------
  409|    635|		goto fail;
  410|       |
  411|  3.32k|	left = size = lebytes2ushort(count);
  412|  3.32k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  3.32k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  413|  3.32k|			"got %zu bytes out_ptr=%p count&=%p count[0]=0x%02x count[1]=0x%02x, len=0x%04zx (%zu)",
  414|  3.32k|			len, out_ptr, &count, count[0], count[1], size, size);
  415|  3.32k|	out = out_ptr = malloc(size);
  416|  3.32k|	if (out == NULL) {
  ------------------
  |  Branch (416:6): [True: 0, False: 3.32k]
  ------------------
  417|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  418|      0|		goto fail;
  419|      0|	}
  420|  15.5k|	for (offset += 2; left > 0; offset += len, left -= len, out_ptr += len) {
  ------------------
  |  Branch (420:20): [True: 12.3k, False: 3.11k]
  ------------------
  421|  12.3k|		len = MIN(left, CAC_MAX_CHUNK_SIZE);
  ------------------
  |  |   69|  12.3k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 4.27k, False: 8.12k]
  |  |  ------------------
  ------------------
  422|  12.3k|		params[1] = len;
  423|  12.3k|		r = cac_apdu_io(card, CAC_INS_READ_FILE, HIGH_BYTE_OF_SHORT(offset), LOW_BYTE_OF_SHORT(offset),
  ------------------
  |  |   61|  12.3k|#define CAC_INS_READ_FILE             0x52  /* read a TL or V file */
  ------------------
              		r = cac_apdu_io(card, CAC_INS_READ_FILE, HIGH_BYTE_OF_SHORT(offset), LOW_BYTE_OF_SHORT(offset),
  ------------------
  |  |  382|  12.3k|#define HIGH_BYTE_OF_SHORT(x) (((x)>> 8) & 0xff)
  ------------------
              		r = cac_apdu_io(card, CAC_INS_READ_FILE, HIGH_BYTE_OF_SHORT(offset), LOW_BYTE_OF_SHORT(offset),
  ------------------
  |  |  383|  12.3k|#define LOW_BYTE_OF_SHORT(x) ((x) & 0xff)
  ------------------
  424|  12.3k|						&params[0], sizeof(params), &out_ptr, &len);
  425|       |		/* if there is no data, assume there is no file */
  426|  12.3k|		if (len == 0) {
  ------------------
  |  Branch (426:7): [True: 74, False: 12.3k]
  ------------------
  427|     74|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     74|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  428|     74|		}
  429|  12.3k|		if (r < 0) {
  ------------------
  |  Branch (429:7): [True: 209, False: 12.1k]
  ------------------
  430|    209|			goto fail;
  431|    209|		}
  432|  12.3k|	}
  433|  3.11k|	*out_len = size;
  434|  3.11k|	*out_buf = out;
  435|  3.11k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.11k|	int _ret = r; \
  |  |  |  |  155|  3.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.11k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.11k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.11k|	return _ret; \
  |  |  |  |  163|  3.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|    844|fail:
  437|    844|	if (out)
  ------------------
  |  Branch (437:6): [True: 209, False: 635]
  ------------------
  438|    209|		free(out);
  439|    844|	*out_len = 0;
  440|    844|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    844|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    844|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    844|	int _ret = r; \
  |  |  |  |  155|    844|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 844, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    844|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    844|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 844, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    844|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    844|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    844|	return _ret; \
  |  |  |  |  163|    844|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  441|    844|}
card-cac.c:cac_parse_CCC:
 1391|  1.05k|{
 1392|  1.05k|	size_t len = 0;
 1393|  1.05k|	const u8 *tl_end = tl + tl_len;
 1394|  1.05k|	const u8 *val_end = val + val_len;
 1395|  1.05k|	sc_path_t new_path;
 1396|  1.05k|	int r;
 1397|       |
 1398|       |
 1399|  14.2k|	for (; (tl < tl_end) && (val< val_end); val += len) {
  ------------------
  |  Branch (1399:9): [True: 14.0k, False: 176]
  |  Branch (1399:26): [True: 13.9k, False: 68]
  ------------------
 1400|       |		/* get the tag and the length */
 1401|  13.9k|		u8 tag;
 1402|  13.9k|		r = sc_simpletlv_read_tag(&tl, tl_end - tl, &tag, &len);
 1403|  13.9k|		if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) {
  ------------------
  |  |   28|  27.9k|#define SC_SUCCESS				0
  ------------------
              		if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) {
  ------------------
  |  |   99|  1.07k|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (1403:7): [True: 1.07k, False: 12.9k]
  |  Branch (1403:26): [True: 37, False: 1.03k]
  ------------------
 1404|     37|			sc_log(card->ctx, "Failed to parse tag from buffer");
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1405|     37|			break;
 1406|     37|		}
 1407|  13.9k|		if (val + len > val_end) {
  ------------------
  |  Branch (1407:7): [True: 393, False: 13.5k]
  ------------------
 1408|    393|			sc_log(card->ctx, "Invalid length %zu", len);
  ------------------
  |  |   71|    393|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1409|    393|			break;
 1410|    393|		}
 1411|  13.5k|		switch (tag) {
 1412|    591|		case CAC_TAG_CUID:
  ------------------
  |  |   72|    591|#define CAC_TAG_CUID                  0xF0
  ------------------
  |  Branch (1412:3): [True: 591, False: 12.9k]
  ------------------
 1413|    591|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:CUID");
  ------------------
  |  |   70|    591|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1414|    591|			r = cac_parse_cuid(card, priv, (cac_cuid_t *)val, len);
 1415|    591|			if (r < 0)
  ------------------
  |  Branch (1415:8): [True: 2, False: 589]
  ------------------
 1416|      2|				return r;
 1417|    589|			break;
 1418|    782|		case CAC_TAG_CC_VERSION_NUMBER:
  ------------------
  |  |   73|    782|#define CAC_TAG_CC_VERSION_NUMBER     0xF1
  ------------------
  |  Branch (1418:3): [True: 782, False: 12.7k]
  ------------------
 1419|    782|			if (len != 1) {
  ------------------
  |  Branch (1419:8): [True: 342, False: 440]
  ------------------
 1420|    342|				sc_log(card->ctx, "TAG: CC Version: Invalid length %zu", len);
  ------------------
  |  |   71|    342|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1421|    342|				break;
 1422|    342|			}
 1423|       |			/* ignore the version numbers for now */
 1424|    440|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    440|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1425|    440|				"TAG: CC Version = 0x%02x", *val);
 1426|    440|			break;
 1427|    365|		case CAC_TAG_GRAMMAR_VERION_NUMBER:
  ------------------
  |  |   74|    365|#define CAC_TAG_GRAMMAR_VERION_NUMBER 0xF2
  ------------------
  |  Branch (1427:3): [True: 365, False: 13.2k]
  ------------------
 1428|    365|			if (len != 1) {
  ------------------
  |  Branch (1428:8): [True: 82, False: 283]
  ------------------
 1429|     82|				sc_log(card->ctx, "TAG: Grammar Version: Invalid length %zu", len);
  ------------------
  |  |   71|     82|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1430|     82|				break;
 1431|     82|			}
 1432|       |			/* ignore the version numbers for now */
 1433|    283|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    283|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1434|    283|				"TAG: Grammar Version = 0x%02x", *val);
 1435|    283|			break;
 1436|  4.22k|		case CAC_TAG_CARDURL:
  ------------------
  |  |   75|  4.22k|#define CAC_TAG_CARDURL               0xF3
  ------------------
  |  Branch (1436:3): [True: 4.22k, False: 9.34k]
  ------------------
 1437|  4.22k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:CARDURL");
  ------------------
  |  |   70|  4.22k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1438|  4.22k|			r = cac_parse_cardurl(card, priv, (cac_card_url_t *)val, len);
 1439|  4.22k|			if (r < 0)
  ------------------
  |  Branch (1439:8): [True: 7, False: 4.22k]
  ------------------
 1440|      7|				return r;
 1441|  4.22k|			break;
 1442|       |		/*
 1443|       |		 * The following are really for file systems cards. This code only cares about CAC VM cards
 1444|       |		 */
 1445|  4.22k|		case CAC_TAG_PKCS15:
  ------------------
  |  |   76|    568|#define CAC_TAG_PKCS15                0xF4
  ------------------
  |  Branch (1445:3): [True: 568, False: 13.0k]
  ------------------
 1446|    568|			if (len != 1) {
  ------------------
  |  Branch (1446:8): [True: 104, False: 464]
  ------------------
 1447|    104|				sc_log(card->ctx, "TAG: PKCS15: Invalid length %zu", len);
  ------------------
  |  |   71|    104|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1448|    104|				break;
 1449|    104|			}
 1450|       |			/* TODO should verify that this is '0'. If it's not
 1451|       |			 * zero, we should drop out of here and let the PKCS 15
 1452|       |			 * code handle this card */
 1453|    464|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: PKCS15 = 0x%02x", *val);
  ------------------
  |  |   70|    464|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1454|    464|			break;
 1455|    150|		case CAC_TAG_DATA_MODEL:
  ------------------
  |  |   78|    150|#define CAC_TAG_DATA_MODEL            0xF5
  ------------------
  |  Branch (1455:3): [True: 150, False: 13.4k]
  ------------------
 1456|    150|			if (len != 1) {
  ------------------
  |  Branch (1456:8): [True: 55, False: 95]
  ------------------
 1457|     55|				sc_log(card->ctx, "TAG: Registered Data Model Number: Invalid length %zu", len);
  ------------------
  |  |   71|     55|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1458|     55|				break;
 1459|     55|			}
 1460|     95|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: Registered Data Model Number (0x%02x)", *val);
  ------------------
  |  |   70|     95|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1461|     95|			break;
 1462|    250|		case CAC_TAG_CARD_APDU:
  ------------------
  |  |   79|    250|#define CAC_TAG_CARD_APDU             0xF7
  ------------------
  |  Branch (1462:3): [True: 250, False: 13.3k]
  ------------------
 1463|    649|		case CAC_TAG_CAPABILITY_TUPLES:
  ------------------
  |  |   81|    649|#define CAC_TAG_CAPABILITY_TUPLES     0xFB
  ------------------
  |  Branch (1463:3): [True: 399, False: 13.1k]
  ------------------
 1464|    783|		case CAC_TAG_STATUS_TUPLES:
  ------------------
  |  |   82|    783|#define CAC_TAG_STATUS_TUPLES         0xFC
  ------------------
  |  Branch (1464:3): [True: 134, False: 13.4k]
  ------------------
 1465|  1.40k|		case CAC_TAG_REDIRECTION:
  ------------------
  |  |   80|  1.40k|#define CAC_TAG_REDIRECTION           0xFA
  ------------------
  |  Branch (1465:3): [True: 621, False: 12.9k]
  ------------------
 1466|  1.43k|		case CAC_TAG_ERROR_CODES:
  ------------------
  |  |   84|  1.43k|#define CAC_TAG_ERROR_CODES           0xFE
  ------------------
  |  Branch (1466:3): [True: 32, False: 13.5k]
  ------------------
 1467|  1.43k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: FSSpecific(0x%02x)", tag);
  ------------------
  |  |   70|  1.43k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1468|  1.43k|			break;
 1469|    241|		case CAC_TAG_ACCESS_CONTROL:
  ------------------
  |  |   77|    241|#define CAC_TAG_ACCESS_CONTROL        0xF6
  ------------------
  |  Branch (1469:3): [True: 241, False: 13.3k]
  ------------------
 1470|       |			/* TODO handle access control later */
 1471|    241|			sc_log_hex(card->ctx, "TAG:ACCESS Control", val, len);
  ------------------
  |  |  129|    241|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    241|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1472|    241|			break;
 1473|    810|		case CAC_TAG_NEXT_CCC:
  ------------------
  |  |   83|    810|#define CAC_TAG_NEXT_CCC              0xFD
  ------------------
  |  Branch (1473:3): [True: 810, False: 12.7k]
  ------------------
 1474|    810|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:NEXT CCC");
  ------------------
  |  |   70|    810|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1475|    810|			r = cac_path_from_cardurl(card, &new_path, (cac_card_url_t *)val, len);
 1476|    810|			if (r < 0)
  ------------------
  |  Branch (1476:8): [True: 7, False: 803]
  ------------------
 1477|      7|				return r;
 1478|       |
 1479|    803|			r = cac_select_file_by_type(card, &new_path, NULL);
 1480|    803|			if (r < 0)
  ------------------
  |  Branch (1480:8): [True: 44, False: 759]
  ------------------
 1481|     44|				return r;
 1482|       |
 1483|       |			/* Increase depth to avoid infinite recursion */
 1484|    759|			r = cac_process_CCC(card, priv, depth + 1);
 1485|    759|			if (r < 0)
  ------------------
  |  Branch (1485:8): [True: 317, False: 442]
  ------------------
 1486|    317|				return r;
 1487|    442|			break;
 1488|  4.39k|		default:
  ------------------
  |  Branch (1488:3): [True: 4.39k, False: 9.17k]
  ------------------
 1489|       |			/* ignore tags we don't understand */
 1490|  4.39k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:Unknown (0x%02x)",tag );
  ------------------
  |  |   70|  4.39k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1491|  4.39k|			break;
 1492|  13.5k|		}
 1493|  13.5k|	}
 1494|    674|	return SC_SUCCESS;
  ------------------
  |  |   28|    674|#define SC_SUCCESS				0
  ------------------
 1495|  1.05k|}
card-cac.c:cac_parse_cuid:
 1364|    591|{
 1365|    591|	size_t card_id_len;
 1366|       |
 1367|    591|	if (len < sizeof(cac_cuid_t) || len > 256) {
  ------------------
  |  Branch (1367:6): [True: 2, False: 589]
  |  Branch (1367:34): [True: 0, False: 589]
  ------------------
 1368|      2|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1369|      2|	}
 1370|       |
 1371|    589|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "gsc_rid=%s", sc_dump_hex(val->gsc_rid, sizeof(val->gsc_rid)));
  ------------------
  |  |   70|    589|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1372|    589|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "manufacture id=%x", val->manufacturer_id);
  ------------------
  |  |   70|    589|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1373|    589|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "cac_type=%d", val->card_type);
  ------------------
  |  |   70|    589|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1374|    589|	card_id_len = len - (&val->card_id - (u8 *)val);
 1375|    589|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "card_id=%s (%zu)",
  ------------------
  |  |   70|    589|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1376|    589|			sc_dump_hex(&val->card_id, card_id_len), card_id_len);
 1377|    589|	priv->cuid = *val;
 1378|    589|	free(priv->cac_id);
 1379|    589|	priv->cac_id = malloc(card_id_len);
 1380|    589|	if (priv->cac_id == NULL) {
  ------------------
  |  Branch (1380:6): [True: 0, False: 589]
  ------------------
 1381|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1382|      0|	}
 1383|    589|	memcpy(priv->cac_id, &val->card_id, card_id_len);
 1384|    589|	priv->cac_id_len = card_id_len;
 1385|    589|	return SC_SUCCESS;
  ------------------
  |  |   28|    589|#define SC_SUCCESS				0
  ------------------
 1386|    589|}
card-cac.c:cac_parse_cardurl:
 1318|  4.22k|{
 1319|  4.22k|	cac_object_t new_object;
 1320|  4.22k|	const cac_object_t *obj;
 1321|  4.22k|	unsigned short object_id;
 1322|  4.22k|	int r;
 1323|       |
 1324|  4.22k|	r = cac_path_from_cardurl(card, &new_object.path, val, len);
 1325|  4.22k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  4.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1325:6): [True: 7, False: 4.22k]
  ------------------
 1326|      7|		return r;
 1327|      7|	}
 1328|  4.22k|	switch (val->cardApplicationType) {
 1329|  1.25k|	case CAC_APP_TYPE_PKI:
  ------------------
  |  |   99|  1.25k|#define CAC_APP_TYPE_PKI              0x04
  ------------------
  |  Branch (1329:2): [True: 1.25k, False: 2.96k]
  ------------------
 1330|       |		/* we don't want to overflow the cac_label array. This test could
 1331|       |		 * go way if we create a label function that will create a unique label
 1332|       |		 * from a cert index.
 1333|       |		 */
 1334|  1.25k|		if (priv->cert_next >= MAX_CAC_SLOTS)
  ------------------
  |  |   70|  1.25k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1334:7): [True: 310, False: 947]
  ------------------
 1335|    310|			break; /* don't fail just because we have more certs than we can support */
 1336|    947|		new_object.name = get_cac_label(priv->cert_next);
 1337|    947|		new_object.fd = priv->cert_next+1;
 1338|    947|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: pki_object found, cert_next=%d (%s),", priv->cert_next, new_object.name);
  ------------------
  |  |   70|    947|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1339|    947|		cac_add_object_to_list(&priv->pki_list, &new_object);
 1340|    947|		priv->cert_next++;
 1341|    947|		break;
 1342|    546|	case CAC_APP_TYPE_GENERAL:
  ------------------
  |  |   97|    546|#define CAC_APP_TYPE_GENERAL          0x01
  ------------------
  |  Branch (1342:2): [True: 546, False: 3.67k]
  ------------------
 1343|    546|		object_id = bebytes2ushort(val->objectID);
 1344|    546|		obj = cac_find_obj_by_id(object_id);
 1345|    546|		if (obj == NULL)
  ------------------
  |  Branch (1345:7): [True: 188, False: 358]
  ------------------
 1346|    188|			break; /* don't fail just because we don't recognize the object */
 1347|    358|		new_object.name = obj->name;
 1348|    358|		new_object.fd = 0;
 1349|    358|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: gen_object found, objectID=%x (%s),", object_id, new_object.name);
  ------------------
  |  |   70|    358|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1350|    358|		cac_add_object_to_list(&priv->general_list, &new_object);
 1351|    358|		break;
 1352|     75|	case CAC_APP_TYPE_SKI:
  ------------------
  |  |   98|     75|#define CAC_APP_TYPE_SKI              0x02
  ------------------
  |  Branch (1352:2): [True: 75, False: 4.14k]
  ------------------
 1353|     75|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: ski_object found");
  ------------------
  |  |   70|     75|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1354|     75|	break;
 1355|  2.34k|	default:
  ------------------
  |  Branch (1355:2): [True: 2.34k, False: 1.87k]
  ------------------
 1356|  2.34k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: unknown object_object found (type=0x%02x)", val->cardApplicationType);
  ------------------
  |  |   70|  2.34k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1357|       |		/* don't fail just because there is an unknown object in the CCC */
 1358|  2.34k|		break;
 1359|  4.22k|	}
 1360|  4.22k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.22k|#define SC_SUCCESS				0
  ------------------
 1361|  4.22k|}
card-cac.c:cac_find_obj_by_id:
  216|    546|{
  217|    546|	int i;
  218|       |
  219|  2.92k|	for (i = 0; i < cac_object_count; i++) {
  ------------------
  |  Branch (219:14): [True: 2.74k, False: 188]
  ------------------
  220|  2.74k|		if (cac_objects[i].fd == object_id) {
  ------------------
  |  Branch (220:7): [True: 358, False: 2.38k]
  ------------------
  221|    358|			return &cac_objects[i];
  222|    358|		}
  223|  2.74k|	}
  224|    188|	return NULL;
  225|    546|}
card-cac.c:cac_path_from_cardurl:
 1229|  5.03k|{
 1230|  5.03k|	if (len < 10) {
  ------------------
  |  Branch (1230:6): [True: 14, False: 5.02k]
  ------------------
 1231|     14|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     14|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1232|     14|	}
 1233|  5.02k|	sc_mem_clear(path, sizeof(sc_path_t));
 1234|  5.02k|	memcpy(path->aid.value, &val->rid, sizeof(val->rid));
 1235|  5.02k|	memcpy(&path->aid.value[5], val->applicationID, sizeof(val->applicationID));
 1236|  5.02k|	path->aid.len = sizeof(val->rid) + sizeof(val->applicationID);
 1237|  5.02k|	memcpy(path->value, val->objectID, sizeof(val->objectID));
 1238|  5.02k|	path->len = sizeof(val->objectID);
 1239|  5.02k|	path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  5.02k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1240|  5.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1241|  5.02k|			"path->aid=%x %x %x %x %x %x %x  len=%zu, path->value = %x %x len=%zu path->type=%d (%x)",
 1242|  5.02k|			path->aid.value[0], path->aid.value[1], path->aid.value[2], path->aid.value[3],
 1243|  5.02k|			path->aid.value[4], path->aid.value[5], path->aid.value[6], path->aid.len,
 1244|  5.02k|			path->value[0], path->value[1], path->len, path->type, path->type);
 1245|  5.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1246|  5.02k|			"rid=%x %x %x %x %x  len=%zu appid= %x %x len=%zu objid= %x %x len=%zu",
 1247|  5.02k|			val->rid[0], val->rid[1], val->rid[2], val->rid[3], val->rid[4],
 1248|  5.02k|			sizeof(val->rid), val->applicationID[0], val->applicationID[1],
 1249|  5.02k|			sizeof(val->applicationID), val->objectID[0], val->objectID[1], sizeof(val->objectID));
 1250|       |
 1251|  5.02k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.02k|#define SC_SUCCESS				0
  ------------------
 1252|  5.03k|}
card-cac.c:cac_select_ACA:
 1224|  4.67k|{
 1225|       |	return cac_select_file_by_type(card, &cac_ACA_Path, NULL);
 1226|  4.67k|}
card-cac.c:cac_process_ACA:
 1688|    396|{
 1689|    396|	int r;
 1690|    396|	u8 *val = NULL;
 1691|    396|	size_t val_len;
 1692|       |
 1693|    396|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    396|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    396|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    396|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 396]
  |  |  ------------------
  ------------------
 1694|       |
 1695|       |	/* Assuming ACA is already selected */
 1696|    396|	r = cac_get_acr(card, CAC_ACR_SERVICE, &val, &val_len);
  ------------------
  |  |  104|    396|#define CAC_ACR_SERVICE               0x21
  ------------------
 1697|    396|	if (r < 0)
  ------------------
  |  Branch (1697:6): [True: 33, False: 363]
  ------------------
 1698|     33|		goto done;
 1699|       |
 1700|    363|	r = cac_parse_ACA_service(card, priv, val, val_len);
 1701|    363|        if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
  |  Branch (1701:13): [True: 342, False: 21]
  ------------------
 1702|    342|		priv->aca_path = malloc(sizeof(sc_path_t));
 1703|    342|		if (!priv->aca_path) {
  ------------------
  |  Branch (1703:7): [True: 0, False: 342]
  ------------------
 1704|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1705|      0|			goto done;
 1706|      0|		}
 1707|    342|		memcpy(priv->aca_path, &cac_ACA_Path, sizeof(sc_path_t));
 1708|    342|	}
 1709|    396|done:
 1710|    396|	if (val)
  ------------------
  |  Branch (1710:6): [True: 363, False: 33]
  ------------------
 1711|    363|		free(val);
 1712|    396|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    396|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    396|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    396|	int _ret = r; \
  |  |  |  |  155|    396|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 396, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    396|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 54, False: 342]
  |  |  |  |  ------------------
  |  |  |  |  157|    396|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    396|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    396|	return _ret; \
  |  |  |  |  163|    396|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1713|    396|}
card-cac.c:cac_get_acr:
  344|    396|{
  345|    396|	u8 *out = NULL;
  346|       |	/* XXX assuming it will not be longer than 255 B */
  347|    396|	size_t len = 256;
  348|    396|	int r;
  349|       |
  350|    396|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    396|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    396|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    396|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 396]
  |  |  ------------------
  ------------------
  351|       |
  352|       |	/* for simplicity we support only ACR without arguments now */
  353|    396|	if (acr_type != 0x00 && acr_type != 0x10
  ------------------
  |  Branch (353:6): [True: 396, False: 0]
  |  Branch (353:26): [True: 396, False: 0]
  ------------------
  354|    396|	    && acr_type != 0x20 && acr_type != 0x21) {
  ------------------
  |  Branch (354:9): [True: 396, False: 0]
  |  Branch (354:29): [True: 0, False: 396]
  ------------------
  355|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  356|      0|	}
  357|       |
  358|    396|	r = cac_apdu_io(card, CAC_INS_GET_ACR, acr_type, 0, NULL, 0, &out, &len);
  ------------------
  |  |   62|    396|#define CAC_INS_GET_ACR               0x4c
  ------------------
  359|    396|	if (len == 0) {
  ------------------
  |  Branch (359:6): [True: 9, False: 387]
  ------------------
  360|      9|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      9|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  361|      9|	}
  362|    396|	if (r < 0)
  ------------------
  |  Branch (362:6): [True: 33, False: 363]
  ------------------
  363|     33|		goto fail;
  364|       |
  365|    363|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "got %zu bytes out=%p", len, out);
  ------------------
  |  |   70|    363|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  366|       |
  367|    363|	*out_len = len;
  368|    363|	*out_buf = out;
  369|    363|	return SC_SUCCESS;
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
  370|       |
  371|     33|fail:
  372|     33|	if (out)
  ------------------
  |  Branch (372:6): [True: 9, False: 24]
  ------------------
  373|      9|		free(out);
  374|       |	*out_buf = NULL;
  375|     33|	*out_len = 0;
  376|     33|	return r;
  377|    396|}
card-cac.c:cac_parse_ACA_service:
 1530|    363|{
 1531|    363|	size_t len = 0;
 1532|    363|	const u8 *val_end = val + val_len;
 1533|    363|	int r;
 1534|       |
 1535|    363|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    363|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  ------------------
  ------------------
 1536|       |
 1537|  4.84k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (1537:9): [True: 4.76k, False: 77]
  ------------------
 1538|       |		/* get the tag and the length */
 1539|  4.76k|		u8 tag;
 1540|  4.76k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  4.76k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1540:7): [True: 265, False: 4.49k]
  ------------------
 1541|    265|			break;
 1542|       |
 1543|  4.49k|		switch (tag) {
 1544|    723|		case CAC_TAG_APPLET_FAMILY:
  ------------------
  |  |   85|    723|#define CAC_TAG_APPLET_FAMILY         0x01
  ------------------
  |  Branch (1544:3): [True: 723, False: 3.77k]
  ------------------
 1545|    723|			if (len != 5) {
  ------------------
  |  Branch (1545:8): [True: 521, False: 202]
  ------------------
 1546|    521|				sc_log(card->ctx, "TAG: Applet Information: bad length %zu", len);
  ------------------
  |  |   71|    521|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1547|    521|				break;
 1548|    521|			}
 1549|    202|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    202|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1550|    202|			    "TAG: Applet Information: Family: 0x%02x", val[0]);
 1551|    202|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    202|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1552|    202|			    "     Applet Version: 0x%02x 0x%02x 0x%02x 0x%02x",
 1553|    202|			    val[1], val[2], val[3], val[4]);
 1554|    202|			break;
 1555|    435|		case CAC_TAG_NUMBER_APPLETS:
  ------------------
  |  |   86|    435|#define CAC_TAG_NUMBER_APPLETS        0x94
  ------------------
  |  Branch (1555:3): [True: 435, False: 4.06k]
  ------------------
 1556|    435|			if (len != 1) {
  ------------------
  |  Branch (1556:8): [True: 202, False: 233]
  ------------------
 1557|    202|				sc_log(card->ctx, "TAG: Num applets: bad length %zu", len);
  ------------------
  |  |   71|    202|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1558|    202|				break;
 1559|    202|			}
 1560|    233|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    233|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1561|    233|			    "TAG: Num applets = %hhd", *val);
 1562|    233|			break;
 1563|  1.08k|		case CAC_TAG_APPLET_ENTRY:
  ------------------
  |  |   87|  1.08k|#define CAC_TAG_APPLET_ENTRY          0x93
  ------------------
  |  Branch (1563:3): [True: 1.08k, False: 3.41k]
  ------------------
 1564|       |			/* Make sure we match the outer length */
 1565|  1.08k|			if (len < 3 || val[2] != len - 3) {
  ------------------
  |  Branch (1565:8): [True: 220, False: 860]
  |  Branch (1565:19): [True: 218, False: 642]
  ------------------
 1566|    438|				sc_log(card->ctx, "TAG: Applet Entry: bad length (%zu) or length of internal buffer", len);
  ------------------
  |  |   71|    438|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1567|    438|				break;
 1568|    438|			}
 1569|    642|			sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|    642|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1570|    642|			    "TAG: Applet Entry: AID", val + 3, val[2]);
 1571|       |			/* This is SimpleTLV prefixed with applet ID (1B) */
 1572|    642|			r = cac_parse_aid(card, priv, val + 3, val[2]);
 1573|    642|			if (r < 0)
  ------------------
  |  Branch (1573:8): [True: 21, False: 621]
  ------------------
 1574|     21|				return r;
 1575|    621|			break;
 1576|  2.26k|		default:
  ------------------
  |  Branch (1576:3): [True: 2.26k, False: 2.23k]
  ------------------
 1577|       |			/* ignore tags we don't understand */
 1578|  2.26k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  2.26k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1579|  2.26k|			    "TAG: Unknown (0x%02x)", tag);
 1580|  2.26k|			break;
 1581|  4.49k|		}
 1582|  4.49k|	}
 1583|    342|	return SC_SUCCESS;
  ------------------
  |  |   28|    342|#define SC_SUCCESS				0
  ------------------
 1584|    363|}
card-cac.c:cac_parse_aid:
 1255|    642|{
 1256|    642|	cac_object_t new_object;
 1257|    642|	cac_properties_t prop = {0};
 1258|    642|	size_t i;
 1259|    642|	int r;
 1260|       |
 1261|    642|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    642|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    642|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    642|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 642]
  |  |  ------------------
  ------------------
 1262|       |
 1263|    642|	if (aid_len < 0 || aid_len > SC_MAX_AID_SIZE) {
  ------------------
  |  |   43|    642|#define SC_MAX_AID_SIZE			16
  ------------------
  |  Branch (1263:6): [True: 0, False: 642]
  |  Branch (1263:21): [True: 1, False: 641]
  ------------------
 1264|      1|		sc_log(card->ctx, "AID length too large (%d)", aid_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1265|      1|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1266|      1|	}
 1267|       |
 1268|       |	/* Search for PKI applets (7 B). Ignore generic objects for now */
 1269|    641|	if (aid_len != 7 || (memcmp(aid, CAC_1_RID "\x01", 6) != 0
  ------------------
  |  |   66|    445|#define CAC_1_RID "\xA0\x00\x00\x00\x79"
  ------------------
  |  Branch (1269:6): [True: 196, False: 445]
  |  Branch (1269:23): [True: 285, False: 160]
  ------------------
 1270|    285|	    && memcmp(aid, CAC_1_RID "\x00", 6) != 0))
  ------------------
  |  |   66|    285|#define CAC_1_RID "\xA0\x00\x00\x00\x79"
  ------------------
  |  Branch (1270:9): [True: 214, False: 71]
  ------------------
 1271|    410|		return SC_SUCCESS;
  ------------------
  |  |   28|    410|#define SC_SUCCESS				0
  ------------------
 1272|       |
 1273|    231|	sc_mem_clear(&new_object.path, sizeof(sc_path_t));
 1274|    231|	memcpy(new_object.path.aid.value, aid, aid_len);
 1275|    231|	new_object.path.aid.len = aid_len;
 1276|       |
 1277|       |	/* Call without OID set will just select the AID without subsequent
 1278|       |	 * OID selection, which we need to figure out just now
 1279|       |	 */
 1280|    231|	r = cac_select_file_by_type(card, &new_object.path, NULL);
 1281|    231|	LOG_TEST_RET(card->ctx, r, "Cannot select AID");
  ------------------
  |  |  174|    231|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    231|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    231|	int _ret = (r); \
  |  |  |  |  168|    231|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 219]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|    231|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 219]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1282|    219|	r = cac_get_properties(card, &prop);
 1283|    219|	LOG_TEST_RET(card->ctx, r, "Cannot get CAC properties");
  ------------------
  |  |  174|    219|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    219|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    219|	int _ret = (r); \
  |  |  |  |  168|    219|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 211]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|    219|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 211]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1284|       |
 1285|    463|	for (i = 0; i < prop.num_objects; i++) {
  ------------------
  |  Branch (1285:14): [True: 253, False: 210]
  ------------------
 1286|       |		/* don't fail just because we have more certs than we can support */
 1287|    253|		if (priv->cert_next >= MAX_CAC_SLOTS)
  ------------------
  |  |   70|    253|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1287:7): [True: 1, False: 252]
  ------------------
 1288|      1|			return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1289|       |
 1290|    252|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    252|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1291|    252|		    "ACA: pki_object found, cert_next=%d (%s), privkey=%d",
 1292|    252|		    priv->cert_next, get_cac_label(priv->cert_next),
 1293|    252|		    prop.objects[i].privatekey);
 1294|       |
 1295|       |		/* If the private key is not initialized, we can safely
 1296|       |		 * ignore this object here, but increase the pointer to follow
 1297|       |		 * the certificate labels
 1298|       |		 */
 1299|    252|		if (!prop.objects[i].privatekey) {
  ------------------
  |  Branch (1299:7): [True: 176, False: 76]
  ------------------
 1300|    176|			priv->cert_next++;
 1301|    176|			continue;
 1302|    176|		}
 1303|       |
 1304|       |		/* OID here has always 2B */
 1305|     76|		memcpy(new_object.path.value, &prop.objects[i].oid, 2);
 1306|     76|		new_object.path.len = 2;
 1307|     76|		new_object.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     76|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1308|     76|		new_object.name = get_cac_label(priv->cert_next);
 1309|     76|		new_object.fd = priv->cert_next+1;
 1310|     76|		cac_add_object_to_list(&priv->pki_list, &new_object);
 1311|     76|		priv->cert_next++;
 1312|     76|	}
 1313|       |
 1314|    210|	return SC_SUCCESS;
  ------------------
  |  |   28|    210|#define SC_SUCCESS				0
  ------------------
 1315|    211|}
card-cac.c:cac_find_first_pki_applet:
 1598|  4.24k|{
 1599|  4.24k|	int r, i;
 1600|  68.8k|	for (i = 0; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  68.8k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1600:14): [True: 64.9k, False: 3.95k]
  ------------------
 1601|  64.9k|		r = cac_select_pki_applet(card, i);
 1602|  64.9k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  64.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1602:7): [True: 503, False: 64.4k]
  ------------------
 1603|       |			/* Try to read first two bytes of the buffer to
 1604|       |			 * make sure it is not just malfunctioning card
 1605|       |			 */
 1606|    503|			u8 params[2] = {CAC_FILE_TAG, 2};
  ------------------
  |  |   66|    503|#define CAC_FILE_TAG    1
  ------------------
 1607|    503|			u8 data[2], *out_ptr = data;
 1608|    503|			size_t len = 2;
 1609|    503|			r = cac_apdu_io(card, CAC_INS_READ_FILE, 0, 0,
  ------------------
  |  |   61|    503|#define CAC_INS_READ_FILE             0x52  /* read a TL or V file */
  ------------------
 1610|    503|			    &params[0], sizeof(params), &out_ptr, &len);
 1611|    503|			if (r != 2)
  ------------------
  |  Branch (1611:8): [True: 215, False: 288]
  ------------------
 1612|    215|				continue;
 1613|       |
 1614|    288|			*index_out = i;
 1615|    288|			return SC_SUCCESS;
  ------------------
  |  |   28|    288|#define SC_SUCCESS				0
  ------------------
 1616|    503|		}
 1617|  64.9k|	}
 1618|  3.95k|	return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  3.95k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1619|  4.24k|}
card-cac.c:cac_select_pki_applet:
 1588|  68.1k|{
 1589|  68.1k|	sc_path_t applet_path = cac_cac_pki_obj.path;
 1590|  68.1k|	applet_path.aid.value[applet_path.aid.len-1] = index;
 1591|       |	return cac_select_file_by_type(card, &applet_path, NULL);
 1592|  68.1k|}
card-cac.c:cac_populate_cac_alt:
 1625|    265|{
 1626|    265|	int r, i;
 1627|    265|	cac_object_t pki_obj = cac_cac_pki_obj;
 1628|    265|	u8 buf[100];
 1629|    265|	u8 *val;
 1630|       |
 1631|       |	/* populate PKI objects */
 1632|  3.17k|	for (i = index; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  3.17k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1632:18): [True: 2.90k, False: 265]
  ------------------
 1633|  2.90k|		r = cac_select_pki_applet(card, i);
 1634|  2.90k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.90k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1634:7): [True: 1.41k, False: 1.49k]
  ------------------
 1635|  1.41k|			pki_obj.name = get_cac_label(i);
 1636|  1.41k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  1.41k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1637|  1.41k|			    "CAC: pki_object found, cert_next=%d (%s),", i, pki_obj.name);
 1638|  1.41k|			pki_obj.path.aid.value[pki_obj.path.aid.len-1] = i;
 1639|  1.41k|			pki_obj.fd = i+1; /* don't use id of zero */
 1640|  1.41k|			cac_add_object_to_list(&priv->pki_list, &pki_obj);
 1641|  1.41k|		}
 1642|  2.90k|	}
 1643|       |
 1644|       |	/* populate non-PKI objects */
 1645|  1.85k|	for (i=0; i < cac_object_count; i++) {
  ------------------
  |  Branch (1645:12): [True: 1.59k, False: 265]
  ------------------
 1646|  1.59k|		r = cac_select_file_by_type(card, &cac_objects[i].path, NULL);
 1647|  1.59k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1647:7): [True: 622, False: 968]
  ------------------
 1648|    622|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    622|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1649|    622|			    "CAC: obj_object found, cert_next=%d (%s),",
 1650|    622|			    i, cac_objects[i].name);
 1651|    622|			cac_add_object_to_list(&priv->general_list, &cac_objects[i]);
 1652|    622|		}
 1653|  1.59k|	}
 1654|       |
 1655|       |	/*
 1656|       |	 * create a cuid to simulate the cac 2 cuid.
 1657|       |	 */
 1658|    265|	priv->cuid = cac_cac_cuid;
 1659|       |	/* create a serial number by hashing the first 100 bytes of the
 1660|       |	 * first certificate on the card */
 1661|    265|	r = cac_select_pki_applet(card, index);
 1662|    265|	if (r < 0) {
  ------------------
  |  Branch (1662:6): [True: 57, False: 208]
  ------------------
 1663|     57|		return r; /* shouldn't happen unless the card has been removed or is malfunctioning */
 1664|     57|	}
 1665|    208|	val = buf;
 1666|    208|	r = cac_read_binary(card, 0, val, sizeof(buf), 0);
 1667|    208|	if (r > 0) {
  ------------------
  |  Branch (1667:6): [True: 9, False: 199]
  ------------------
 1668|      9|#ifdef ENABLE_OPENSSL
 1669|      9|		size_t val_len = r;
 1670|      9|		free(priv->cac_id);
 1671|      9|		priv->cac_id = malloc(20);
 1672|      9|		if (priv->cac_id == NULL) {
  ------------------
  |  Branch (1672:7): [True: 0, False: 9]
  ------------------
 1673|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1674|      0|		}
 1675|      9|		SHA1(val, val_len, priv->cac_id);
 1676|      9|		priv->cac_id_len = 20;
 1677|      9|		sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|      9|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1678|      9|		    "cuid", priv->cac_id, priv->cac_id_len);
 1679|       |#else
 1680|       |		sc_log(card->ctx, "OpenSSL Required");
 1681|       |		return SC_ERROR_NOT_SUPPORTED;
 1682|       |#endif /* ENABLE_OPENSSL */
 1683|      9|	}
 1684|    208|	return SC_SUCCESS;
  ------------------
  |  |   28|    208|#define SC_SUCCESS				0
  ------------------
 1685|    208|}
card-cac.c:cac_init:
 1806|  1.02k|{
 1807|  1.02k|	int r;
 1808|  1.02k|	unsigned long flags;
 1809|       |
 1810|  1.02k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.02k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.02k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.02k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.02k]
  |  |  ------------------
  ------------------
 1811|       |
 1812|  1.02k|	r = cac_find_and_initialize(card, 1);
 1813|  1.02k|	if (r < 0) {
  ------------------
  |  Branch (1813:6): [True: 240, False: 782]
  ------------------
 1814|    240|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    240|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    240|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    240|	int _ret = r; \
  |  |  |  |  155|    240|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    240|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    240|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    240|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    240|	return _ret; \
  |  |  |  |  163|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1815|    240|	}
 1816|    782|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    782|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 1817|       |
 1818|    782|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 1819|    782|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 1820|    782|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 1821|       |
 1822|    782|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    782|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    782|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1823|       |
 1824|    782|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    782|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    782|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    782|	int _ret = r; \
  |  |  |  |  155|    782|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 782, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    782|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 782]
  |  |  |  |  ------------------
  |  |  |  |  157|    782|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    782|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    782|	return _ret; \
  |  |  |  |  163|    782|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1825|    782|}
card-cac.c:cac_finish:
 1205|    782|{
 1206|    782|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    782|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
 1207|       |
 1208|    782|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    782|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    782|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    782|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 782]
  |  |  ------------------
  ------------------
 1209|    782|	if (priv) {
  ------------------
  |  Branch (1209:6): [True: 782, False: 0]
  ------------------
 1210|    782|		cac_free_private_data(priv);
 1211|    782|	}
 1212|    782|	return SC_SUCCESS;
  ------------------
  |  |   28|    782|#define SC_SUCCESS				0
  ------------------
 1213|    782|}
card-cac.c:cac_select_file:
 1200|  4.49k|{
 1201|  4.49k|	return cac_select_file_by_type(card, in_path, file_out);
 1202|  4.49k|}
card-cac.c:cac_read_binary:
  451|  1.53k|{
  452|  1.53k|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|  1.53k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  453|  1.53k|	int r = 0;
  454|  1.53k|	u8 *tl = NULL, *val = NULL;
  455|  1.53k|	const u8 *tl_ptr, *val_ptr, *tl_start;
  456|  1.53k|	u8 *tlv_ptr;
  457|  1.53k|	const u8 *cert_ptr;
  458|  1.53k|	size_t tl_len = 0, val_len = 0, tlv_len;
  459|  1.53k|	size_t len, tl_head_len, cert_len;
  460|  1.53k|	u8 cert_type, tag;
  461|       |
  462|  1.53k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.53k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.53k]
  |  |  ------------------
  ------------------
  463|       |
  464|       |	/* if we didn't return it all last time, return the remainder */
  465|  1.53k|	if (priv->cached) {
  ------------------
  |  Branch (465:6): [True: 414, False: 1.12k]
  ------------------
  466|    414|		sc_log(card->ctx, "returning cached value idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|    414|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  467|    414|		if (idx > priv->cache_buf_len) {
  ------------------
  |  Branch (467:7): [True: 0, False: 414]
  ------------------
  468|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_END_REACHED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  469|      0|		}
  470|    414|		len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   69|    414|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 176, False: 238]
  |  |  ------------------
  ------------------
  471|    414|		memcpy(buf, &priv->cache_buf[idx], len);
  472|    414|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|    414|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    414|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    414|	int _ret = r; \
  |  |  |  |  155|    414|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 148, False: 266]
  |  |  |  |  ------------------
  |  |  |  |  156|    148|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 148]
  |  |  |  |  ------------------
  |  |  |  |  157|    148|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    266|	} else { \
  |  |  |  |  159|    266|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    266|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    266|	} \
  |  |  |  |  162|    414|	return _ret; \
  |  |  |  |  163|    414|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|    414|	}
  474|       |
  475|  1.12k|	sc_log(card->ctx, "clearing cache idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|  1.12k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  476|  1.12k|	if (priv->cache_buf) {
  ------------------
  |  Branch (476:6): [True: 0, False: 1.12k]
  ------------------
  477|      0|		free(priv->cache_buf);
  478|      0|		priv->cache_buf = NULL;
  479|      0|		priv->cache_buf_len = 0;
  480|      0|	}
  481|       |
  482|       |
  483|  1.12k|	if (priv->object_type <= 0)
  ------------------
  |  Branch (483:6): [True: 0, False: 1.12k]
  ------------------
  484|  1.12k|		 LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  485|       |
  486|  1.12k|	r = cac_read_file(card, CAC_FILE_TAG, &tl, &tl_len);
  ------------------
  |  |   66|  1.12k|#define CAC_FILE_TAG    1
  ------------------
  487|  1.12k|	if (r < 0)  {
  ------------------
  |  Branch (487:6): [True: 588, False: 536]
  ------------------
  488|    588|		goto done;
  489|    588|	}
  490|       |
  491|    536|	r = cac_read_file(card, CAC_FILE_VALUE, &val, &val_len);
  ------------------
  |  |   67|    536|#define CAC_FILE_VALUE  2
  ------------------
  492|    536|	if (r < 0)
  ------------------
  |  Branch (492:6): [True: 72, False: 464]
  ------------------
  493|     72|		goto done;
  494|       |
  495|    464|	switch (priv->object_type) {
  496|     40|	case CAC_OBJECT_TYPE_TLV_FILE:
  ------------------
  |  |  171|     40|#define CAC_OBJECT_TYPE_TLV_FILE	4
  ------------------
  |  Branch (496:2): [True: 40, False: 424]
  ------------------
  497|     40|		tlv_len = tl_len + val_len;
  498|     40|		priv->cache_buf = malloc(tlv_len);
  499|     40|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (499:7): [True: 0, False: 40]
  ------------------
  500|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  501|      0|			goto done;
  502|      0|		}
  503|     40|		priv->cache_buf_len = tlv_len;
  504|       |
  505|     40|		for (tl_ptr = tl, val_ptr = val, tlv_ptr = priv->cache_buf;
  506|    293|				tl_len >= 2 && tlv_len > 0;
  ------------------
  |  Branch (506:5): [True: 259, False: 34]
  |  Branch (506:20): [True: 259, False: 0]
  ------------------
  507|    259|				val_len -= len, tlv_len -= len, val_ptr += len, tlv_ptr += len) {
  508|       |			/* get the tag and the length */
  509|    259|			tl_start = tl_ptr;
  510|    259|			r = sc_simpletlv_read_tag(&tl_ptr, tl_len, &tag, &len);
  511|    259|			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   28|    518|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   99|    170|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (511:8): [True: 170, False: 89]
  |  Branch (511:27): [True: 6, False: 164]
  ------------------
  512|      6|				break;
  513|    253|			tl_head_len = (tl_ptr - tl_start);
  514|    253|			sc_simpletlv_put_tag(tag, len, tlv_ptr, tlv_len, &tlv_ptr);
  515|    253|			tlv_len -= tl_head_len;
  516|    253|			tl_len -= tl_head_len;
  517|       |
  518|       |			/* don't crash on bad data */
  519|    253|			if (val_len < len) {
  ------------------
  |  Branch (519:8): [True: 174, False: 79]
  ------------------
  520|    174|				sc_log(card->ctx, "Received too long value %zu, while only %zu left. Truncating",
  ------------------
  |  |   71|    174|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  521|    174|						len, val_len);
  522|    174|				len = val_len;
  523|    174|			}
  524|       |			/* if we run out of return space, truncate */
  525|    253|			if (tlv_len < len) {
  ------------------
  |  Branch (525:8): [True: 0, False: 253]
  ------------------
  526|      0|				len = tlv_len;
  527|      0|			}
  528|    253|			memcpy(tlv_ptr, val_ptr, len);
  529|    253|		}
  530|       |		/* fixup the cache_buf_le to reflect for the bad data ignored above */
  531|     40|		priv->cache_buf_len = (tlv_ptr - priv->cache_buf);
  532|     40|		break;
  533|       |
  534|    422|	case CAC_OBJECT_TYPE_CERT:
  ------------------
  |  |  170|    422|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
  |  Branch (534:2): [True: 422, False: 42]
  ------------------
  535|       |		/* read file */
  536|    422|		sc_log(card->ctx, " obj= cert_file, val_len=%zu (0x%04zx)", val_len, val_len);
  ------------------
  |  |   71|    422|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  537|    422|		cert_len = 0;
  538|    422|		cert_ptr = NULL;
  539|    422|		cert_type = 0;
  540|  3.05k|		for (tl_ptr = tl, val_ptr = val; tl_len >= 2;
  ------------------
  |  Branch (540:36): [True: 2.86k, False: 189]
  ------------------
  541|  2.86k|		    val_len -= len, val_ptr += len, tl_len -= tl_head_len) {
  542|  2.86k|			tl_start = tl_ptr;
  543|  2.86k|			r = sc_simpletlv_read_tag(&tl_ptr, tl_len, &tag, &len);
  544|  2.86k|			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   28|  5.72k|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   99|    425|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (544:8): [True: 425, False: 2.43k]
  |  Branch (544:27): [True: 10, False: 415]
  ------------------
  545|     10|				break;
  546|  2.85k|			tl_head_len = tl_ptr - tl_start;
  547|       |
  548|       |			/* incomplete value */
  549|  2.85k|			if (val_len < len) {
  ------------------
  |  Branch (549:8): [True: 223, False: 2.62k]
  ------------------
  550|    223|				sc_log(card->ctx, "Read incomplete value %zu, while only %zu left",
  ------------------
  |  |   71|    223|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|    223|						len, val_len);
  552|    223|				break;
  553|    223|			}
  554|       |
  555|  2.62k|			if (tag == CAC_TAG_CERTIFICATE) {
  ------------------
  |  |   69|  2.62k|#define CAC_TAG_CERTIFICATE           0x70
  ------------------
  |  Branch (555:8): [True: 261, False: 2.36k]
  ------------------
  556|    261|				cert_len = len;
  557|    261|				cert_ptr = val_ptr;
  558|    261|			}
  559|  2.62k|			if (tag == CAC_TAG_CERTINFO) {
  ------------------
  |  |   70|  2.62k|#define CAC_TAG_CERTINFO              0x71
  ------------------
  |  Branch (559:8): [True: 173, False: 2.45k]
  ------------------
  560|    173|				if ((len >= 1) && (val_len >=1)) {
  ------------------
  |  Branch (560:9): [True: 134, False: 39]
  |  Branch (560:23): [True: 134, False: 0]
  ------------------
  561|    134|					cert_type = *val_ptr;
  562|    134|				}
  563|    173|			}
  564|  2.62k|			if (tag == CAC_TAG_MSCUID) {
  ------------------
  |  |   71|  2.62k|#define CAC_TAG_MSCUID                0x72
  ------------------
  |  Branch (564:8): [True: 37, False: 2.59k]
  ------------------
  565|     37|				sc_log_hex(card->ctx, "MSCUID", val_ptr, len);
  ------------------
  |  |  129|     37|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     37|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|     37|			}
  567|  2.62k|		}
  568|       |		/* if the info byte is 1, then the cert is compressed, decompress it */
  569|    422|		if ((cert_type & 0x3) == 1 && flags) {
  ------------------
  |  Branch (569:7): [True: 102, False: 320]
  |  Branch (569:33): [True: 98, False: 4]
  ------------------
  570|     98|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     98|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  571|     98|		}
  572|    422|		if (cert_len > 0) {
  ------------------
  |  Branch (572:7): [True: 119, False: 303]
  ------------------
  573|    119|			priv->cache_buf = malloc(cert_len);
  574|    119|			if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (574:8): [True: 0, False: 119]
  ------------------
  575|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  576|      0|				goto done;
  577|      0|			}
  578|    119|			priv->cache_buf_len = cert_len;
  579|    119|			memcpy(priv->cache_buf, cert_ptr, cert_len);
  580|    303|		} else {
  581|    303|			sc_log(card->ctx, "Can't read zero-length certificate");
  ------------------
  |  |   71|    303|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  582|    303|			goto done;
  583|    303|		}
  584|    119|		break;
  585|    119|	case CAC_OBJECT_TYPE_GENERIC:
  ------------------
  |  |  172|      2|#define CAC_OBJECT_TYPE_GENERIC		5
  ------------------
  |  Branch (585:2): [True: 2, False: 462]
  ------------------
  586|       |		/* TODO
  587|       |		 * We have some two buffers in unknown encoding that we
  588|       |		 * need to present in PKCS#15 layer.
  589|       |		 */
  590|      2|	default:
  ------------------
  |  Branch (590:2): [True: 0, False: 464]
  ------------------
  591|       |		/* Unknown object type */
  592|      2|		sc_log(card->ctx, "Unknown object type: %x", priv->object_type);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  593|      2|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  594|      2|		goto done;
  595|    464|	}
  596|       |
  597|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
  598|    159|	priv->cached = 1;
  599|    159|	len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   69|    159|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 91, False: 68]
  |  |  ------------------
  ------------------
  600|    159|	memcpy(buf, &priv->cache_buf[idx], len);
  601|    159|	r = (int)len;
  602|  1.12k|done:
  603|  1.12k|	if (tl)
  ------------------
  |  Branch (603:6): [True: 536, False: 588]
  ------------------
  604|    536|		free(tl);
  605|  1.12k|	if (val)
  ------------------
  |  Branch (605:6): [True: 464, False: 660]
  ------------------
  606|    464|		free(val);
  607|  1.12k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.12k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.12k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.12k|	int _ret = r; \
  |  |  |  |  155|  1.12k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 967, False: 157]
  |  |  |  |  ------------------
  |  |  |  |  156|    967|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    791|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 791, False: 176]
  |  |  |  |  ------------------
  |  |  |  |  157|    967|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    967|	} else { \
  |  |  |  |  159|    157|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    157|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    157|	} \
  |  |  |  |  162|  1.12k|	return _ret; \
  |  |  |  |  163|  1.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|  1.12k|}
card-cac.c:cac_set_security_env:
  726|     59|{
  727|     59|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     59|#define SC_SUCCESS				0
  ------------------
  728|       |
  729|     59|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     59|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     59|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     59|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 59]
  |  |  ------------------
  ------------------
  730|       |
  731|     59|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|     59|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  732|     59|			env->flags, env->operation, env->algorithm, env->algorithm_flags, env->algorithm_ref,
  733|     59|			env->key_ref[0], env->key_ref_len);
  734|       |
  735|     59|	if (env->algorithm != SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|     59|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (735:6): [True: 0, False: 59]
  ------------------
  736|      0|		 r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  737|      0|	}
  738|       |
  739|       |
  740|     59|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     59|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     59|	int _ret = r; \
  |  |  155|     59|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 59, False: 0]
  |  |  ------------------
  |  |  156|     59|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 59]
  |  |  ------------------
  |  |  157|     59|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     59|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     59|	return _ret; \
  |  |  163|     59|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  741|     59|}
card-cac.c:cac_compute_signature:
  827|      4|{
  828|      4|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      4|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      4|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      4|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4]
  |  |  ------------------
  ------------------
  829|       |
  830|      4|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, cac_rsa_op(card, data, datalen, out, outlen));
  ------------------
  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      4|	int _ret = r; \
  |  |  155|      4|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3, False: 1]
  |  |  ------------------
  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2, False: 1]
  |  |  ------------------
  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      3|	} else { \
  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  161|      1|	} \
  |  |  162|      4|	return _ret; \
  |  |  163|      4|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  831|      4|}
card-cac.c:cac_rsa_op:
  755|     59|{
  756|     59|	int r;
  757|     59|	u8 *outp, *rbuf;
  758|     59|	size_t rbuflen, outplen;
  759|       |
  760|     59|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     59|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     59|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     59|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 59]
  |  |  ------------------
  ------------------
  761|     59|	sc_log(card->ctx, "datalen=%zu outlen=%zu\n", datalen, outlen);
  ------------------
  |  |   71|     59|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  762|       |
  763|     59|	outp = out;
  764|     59|	outplen = outlen;
  765|       |
  766|       |	/* Not strictly necessary. This code requires the caller to have selected the correct PKI container
  767|       |	 * and authenticated to that container with the verifyPin command... All of this under the reader lock.
  768|       |	 * The PKCS #15 higher level driver code does all this correctly (it's the same for all cards, just
  769|       |	 * different sets of APDU's that need to be called), so this call is really a little bit of paranoia */
  770|     59|	r = sc_lock(card);
  771|     59|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     59|#define SC_SUCCESS				0
  ------------------
  |  Branch (771:6): [True: 0, False: 59]
  ------------------
  772|     59|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  773|       |
  774|       |
  775|     59|	rbuf = NULL;
  776|     59|	rbuflen = 0;
  777|    119|	for (; datalen > CAC_MAX_CHUNK_SIZE; data += CAC_MAX_CHUNK_SIZE, datalen -= CAC_MAX_CHUNK_SIZE) {
  ------------------
  |  |   59|    119|#define CAC_MAX_CHUNK_SIZE 240
  ------------------
              	for (; datalen > CAC_MAX_CHUNK_SIZE; data += CAC_MAX_CHUNK_SIZE, datalen -= CAC_MAX_CHUNK_SIZE) {
  ------------------
  |  |   59|     60|#define CAC_MAX_CHUNK_SIZE 240
  ------------------
              	for (; datalen > CAC_MAX_CHUNK_SIZE; data += CAC_MAX_CHUNK_SIZE, datalen -= CAC_MAX_CHUNK_SIZE) {
  ------------------
  |  |   59|     60|#define CAC_MAX_CHUNK_SIZE 240
  ------------------
  |  Branch (777:9): [True: 69, False: 50]
  ------------------
  778|     69|		r = cac_apdu_io(card, CAC_INS_SIGN_DECRYPT, CAC_P1_STEP,  0,
  ------------------
  |  |   60|     69|#define CAC_INS_SIGN_DECRYPT          0x42  /* A crypto operation */
  ------------------
              		r = cac_apdu_io(card, CAC_INS_SIGN_DECRYPT, CAC_P1_STEP,  0,
  ------------------
  |  |   64|     69|#define CAC_P1_STEP    0x80
  ------------------
  779|     69|			data, CAC_MAX_CHUNK_SIZE, &rbuf, &rbuflen);
  ------------------
  |  |   59|     69|#define CAC_MAX_CHUNK_SIZE 240
  ------------------
  780|     69|		if (r < 0) {
  ------------------
  |  Branch (780:7): [True: 9, False: 60]
  ------------------
  781|      9|			break;
  782|      9|		}
  783|     60|		if (rbuflen != 0) {
  ------------------
  |  Branch (783:7): [True: 36, False: 24]
  ------------------
  784|     36|			size_t n = MIN(rbuflen, outplen);
  ------------------
  |  |   69|     36|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 12, False: 24]
  |  |  ------------------
  ------------------
  785|     36|			memcpy(outp, rbuf, n);
  786|     36|			outp += n;
  787|     36|			outplen -= n;
  788|     36|		}
  789|     60|		free(rbuf);
  790|     60|		rbuf = NULL;
  791|     60|		rbuflen = 0;
  792|     60|	}
  793|     59|	if (r < 0) {
  ------------------
  |  Branch (793:6): [True: 9, False: 50]
  ------------------
  794|      9|		goto err;
  795|      9|	}
  796|     50|	rbuf = NULL;
  797|     50|	rbuflen = 0;
  798|     50|	r = cac_apdu_io(card, CAC_INS_SIGN_DECRYPT, CAC_P1_FINAL, 0, data, datalen, &rbuf, &rbuflen);
  ------------------
  |  |   60|     50|#define CAC_INS_SIGN_DECRYPT          0x42  /* A crypto operation */
  ------------------
              	r = cac_apdu_io(card, CAC_INS_SIGN_DECRYPT, CAC_P1_FINAL, 0, data, datalen, &rbuf, &rbuflen);
  ------------------
  |  |   65|     50|#define CAC_P1_FINAL   0x00
  ------------------
  799|     50|	if (r < 0) {
  ------------------
  |  Branch (799:6): [True: 25, False: 25]
  ------------------
  800|     25|		goto err;
  801|     25|	}
  802|     25|	if (rbuflen != 0) {
  ------------------
  |  Branch (802:6): [True: 22, False: 3]
  ------------------
  803|     22|		size_t n = MIN(rbuflen, outplen);
  ------------------
  |  |   69|     22|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 10, False: 12]
  |  |  ------------------
  ------------------
  804|     22|		memcpy(outp, rbuf, n);
  805|       |		/*outp += n;     unused */
  806|     22|		outplen -= n;
  807|     22|	}
  808|     25|	free(rbuf);
  809|     25|	rbuf = NULL;
  810|     25|	r = (int)(outlen - outplen);
  811|       |
  812|     59|err:
  813|     59|	sc_unlock(card);
  814|     59|	if (r < 0) {
  ------------------
  |  Branch (814:6): [True: 34, False: 25]
  ------------------
  815|     34|		sc_mem_clear(out, outlen);
  816|     34|	}
  817|     59|	if (rbuf) {
  ------------------
  |  Branch (817:6): [True: 0, False: 59]
  ------------------
  818|      0|		free(rbuf);
  819|      0|	}
  820|       |
  821|     59|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     59|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     59|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     59|	int _ret = r; \
  |  |  |  |  155|     59|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 37, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  156|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 34, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|     37|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     37|	} else { \
  |  |  |  |  159|     22|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     22|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     22|	} \
  |  |  |  |  162|     59|	return _ret; \
  |  |  |  |  163|     59|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  822|     59|}
card-cac.c:cac_decipher:
  836|     55|{
  837|     55|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     55|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     55|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     55|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 55]
  |  |  ------------------
  ------------------
  838|       |
  839|     55|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, cac_rsa_op(card, data, datalen, out, outlen));
  ------------------
  |  |  153|     55|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     55|	int _ret = r; \
  |  |  155|     55|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 34, False: 21]
  |  |  ------------------
  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 32, False: 2]
  |  |  ------------------
  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     34|	} else { \
  |  |  159|     21|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     21|			"returning with: %d\n", _ret); \
  |  |  161|     21|	} \
  |  |  162|     55|	return _ret; \
  |  |  163|     55|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  840|     55|}
card-cac.c:cac_card_ctl:
  673|  9.36k|{
  674|  9.36k|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|  9.36k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  675|       |
  676|  9.36k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.36k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.36k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.36k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.36k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.36k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|  9.36k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  9.36k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  678|       |
  679|  9.36k|	if (priv == NULL) {
  ------------------
  |  Branch (679:6): [True: 0, False: 9.36k]
  ------------------
  680|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  681|      0|	}
  682|  9.36k|	switch(cmd) {
  ------------------
  |  Branch (682:9): [True: 9.36k, False: 0]
  ------------------
  683|    952|		case SC_CARDCTL_CAC_GET_ACA_PATH:
  ------------------
  |  Branch (683:3): [True: 952, False: 8.41k]
  ------------------
  684|    952|			return cac_get_ACA_path(card, (sc_path_t *) ptr);
  685|    952|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (685:3): [True: 952, False: 8.41k]
  ------------------
  686|    952|			return cac_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
  687|    952|		case SC_CARDCTL_CAC_INIT_GET_GENERIC_OBJECTS:
  ------------------
  |  Branch (687:3): [True: 952, False: 8.41k]
  ------------------
  688|    952|			return cac_get_init_and_get_count(&priv->general_list, &priv->general_current, (int *)ptr);
  689|    952|		case SC_CARDCTL_CAC_INIT_GET_CERT_OBJECTS:
  ------------------
  |  Branch (689:3): [True: 952, False: 8.41k]
  ------------------
  690|    952|			return cac_get_init_and_get_count(&priv->pki_list, &priv->pki_current, (int *)ptr);
  691|    892|		case SC_CARDCTL_CAC_GET_NEXT_GENERIC_OBJECT:
  ------------------
  |  Branch (691:3): [True: 892, False: 8.47k]
  ------------------
  692|    892|			return cac_fill_object_info(&priv->general_list, &priv->general_current, (sc_pkcs15_data_info_t *)ptr);
  693|  2.76k|		case SC_CARDCTL_CAC_GET_NEXT_CERT_OBJECT:
  ------------------
  |  Branch (693:3): [True: 2.76k, False: 6.60k]
  ------------------
  694|  2.76k|			return cac_fill_object_info(&priv->pki_list, &priv->pki_current, (sc_pkcs15_data_info_t *)ptr);
  695|    952|		case SC_CARDCTL_CAC_FINAL_GET_GENERIC_OBJECTS:
  ------------------
  |  Branch (695:3): [True: 952, False: 8.41k]
  ------------------
  696|    952|			return cac_final_iterator(&priv->general_list);
  697|    952|		case SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS:
  ------------------
  |  Branch (697:3): [True: 952, False: 8.41k]
  ------------------
  698|    952|			return cac_final_iterator(&priv->pki_list);
  699|  9.36k|	}
  700|       |
  701|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|      0|}
card-cac.c:cac_get_ACA_path:
  662|    952|{
  663|    952|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    952|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  664|       |
  665|    952|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    952|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    952|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    952|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    952|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|    952|	if (priv->aca_path) {
  ------------------
  |  Branch (666:6): [True: 337, False: 615]
  ------------------
  667|    337|		*path = *priv->aca_path;
  668|    337|	}
  669|    952|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    952|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    952|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    952|	int _ret = r; \
  |  |  |  |  155|    952|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 952, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    952|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  157|    952|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    952|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    952|	return _ret; \
  |  |  |  |  163|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  670|    952|}
card-cac.c:cac_get_serial_nr_from_CUID:
  645|    952|{
  646|    952|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    952|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  647|       |
  648|    952|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    952|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    952|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    952|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    952|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  649|    952|        if (card->serialnr.len)   {
  ------------------
  |  Branch (649:13): [True: 0, False: 952]
  ------------------
  650|      0|                *serial = card->serialnr;
  651|      0|                LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|      0|        }
  653|    952|	if (priv->cac_id_len) {
  ------------------
  |  Branch (653:6): [True: 207, False: 745]
  ------------------
  654|    207|		serial->len = MIN(priv->cac_id_len, SC_MAX_SERIALNR);
  ------------------
  |  |   69|    207|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 204, False: 3]
  |  |  ------------------
  ------------------
  655|    207|		memcpy(serial->value, priv->cac_id, serial->len);
  656|    207|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    207|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    207|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    207|	int _ret = r; \
  |  |  |  |  155|    207|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    207|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 207]
  |  |  |  |  ------------------
  |  |  |  |  157|    207|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    207|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    207|	return _ret; \
  |  |  |  |  163|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  657|    207|	}
  658|    745|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|    745|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    745|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    745|	int _ret = r; \
  |  |  |  |  155|    745|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 745, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    745|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    745|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 745, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    745|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    745|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    745|	return _ret; \
  |  |  |  |  163|    745|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  659|    745|}
card-cac.c:cac_get_init_and_get_count:
  612|  1.90k|{
  613|  1.90k|	*countp = list_size(list);
  614|  1.90k|	list_iterator_start(list);
  615|  1.90k|	*entry = list_iterator_next(list);
  616|  1.90k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.90k|#define SC_SUCCESS				0
  ------------------
  617|  1.90k|}
card-cac.c:cac_fill_object_info:
  628|  3.65k|{
  629|  3.65k|	memset(obj_info, 0, sizeof(sc_pkcs15_data_info_t));
  630|  3.65k|	if (*entry == NULL) {
  ------------------
  |  Branch (630:6): [True: 0, False: 3.65k]
  ------------------
  631|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  632|      0|	}
  633|       |
  634|  3.65k|	obj_info->path = (*entry)->path;
  635|  3.65k|	obj_info->path.count = CAC_MAX_SIZE-1; /* read something from the object */
  ------------------
  |  |   26|  3.65k|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
  636|  3.65k|	obj_info->id.value[0] = ((*entry)->fd >> 8) & 0xff;
  637|  3.65k|	obj_info->id.value[1] = (*entry)->fd & 0xff;
  638|  3.65k|	obj_info->id.len = 2;
  639|  3.65k|	strncpy(obj_info->app_label, (*entry)->name, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|  3.65k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  640|  3.65k|	*entry = list_iterator_next(list);
  641|  3.65k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.65k|#define SC_SUCCESS				0
  ------------------
  642|  3.65k|}
card-cac.c:cac_final_iterator:
  621|  1.90k|{
  622|  1.90k|	list_iterator_stop(list);
  623|  1.90k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.90k|#define SC_SUCCESS				0
  ------------------
  624|  1.90k|}
card-cac.c:cac_pin_cmd:
 1834|     23|{
 1835|       |	/* CAC, like PIV needs Extra validation of (new) PIN during
 1836|       |	 * a PIN change request, to ensure it's not outside the
 1837|       |	 * FIPS 201 4.1.6.1 (numeric only) and * FIPS 140-2
 1838|       |	 * (6 character minimum) requirements.
 1839|       |	 */
 1840|     23|	sc_apdu_t apdu;
 1841|     23|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1842|     23|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1843|     23|	int rv;
 1844|       |
 1845|     23|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|     23|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1845:6): [True: 0, False: 23]
  ------------------
 1846|      0|		size_t i = 0;
 1847|      0|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (1847:7): [True: 0, False: 0]
  ------------------
 1848|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1849|      0|		}
 1850|      0|		for(i=0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (1850:12): [True: 0, False: 0]
  ------------------
 1851|      0|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (1851:8): [True: 0, False: 0]
  ------------------
 1852|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1853|      0|			}
 1854|      0|		}
 1855|       |
 1856|       |		/* We can change the PIN of Giesecke & Devrient CAC ALT tokens
 1857|       |		 * with a bit non-standard APDU */
 1858|      0|		if (card->type == SC_CARD_TYPE_CAC_ALT_HID) {
  ------------------
  |  Branch (1858:7): [True: 0, False: 0]
  ------------------
 1859|      0|			int r = 0;
 1860|      0|			r = iso7816_build_pin_apdu(card, &apdu, data, sbuf, sizeof(sbuf));
 1861|      0|			if (r < 0)
  ------------------
  |  Branch (1861:8): [True: 0, False: 0]
  ------------------
 1862|      0|				return r;
 1863|       |			/* it requires P1 = 0x01 completely against the ISO specs */
 1864|      0|			apdu.p1 = 0x01;
 1865|      0|			data->apdu = &apdu;
 1866|      0|		}
 1867|      0|	}
 1868|       |
 1869|     23|	rv = iso_drv->ops->pin_cmd(card, data);
 1870|       |
 1871|       |	data->apdu = NULL;
 1872|     23|	return rv;
 1873|     23|}

sc_get_cac1_driver:
  554|  15.2k|{
  555|  15.2k|	return sc_get_driver();
  556|  15.2k|}
card-cac1.c:sc_get_driver:
  536|  15.2k|{
  537|       |	/* Inherit most of the things from the CAC driver */
  538|  15.2k|	struct sc_card_driver *cac_drv = sc_get_cac_driver();
  539|       |
  540|  15.2k|	cac_ops = *cac_drv->ops;
  541|  15.2k|	cac_ops.match_card = cac_match_card;
  542|  15.2k|	cac_ops.init = cac_init;
  543|  15.2k|	cac_ops.finish = cac_finish;
  544|       |
  545|  15.2k|	cac_ops.select_file =  cac_select_file; /* need to record object type */
  546|  15.2k|	cac_ops.read_binary = cac_read_binary;
  547|  15.2k|	cac_ops.logout = cac_logout;
  548|       |
  549|  15.2k|	return &cac1_drv;
  550|  15.2k|}
card-cac1.c:cac_match_card:
  489|  2.64k|{
  490|  2.64k|	int r;
  491|  2.64k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.64k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.64k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.64k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.64k]
  |  |  ------------------
  ------------------
  492|       |
  493|  2.64k|	r = cac_find_and_initialize(card, 0);
  494|  2.64k|	return (r == SC_SUCCESS); /* never match */
  ------------------
  |  |   28|  2.64k|#define SC_SUCCESS				0
  ------------------
  495|  2.64k|}
card-cac1.c:cac_find_and_initialize:
  451|  2.85k|{
  452|  2.85k|	int r, index;
  453|  2.85k|	cac_private_data_t *priv = NULL;
  454|       |
  455|       |	/* already initialized? */
  456|  2.85k|	if (card->drv_data) {
  ------------------
  |  Branch (456:6): [True: 0, False: 2.85k]
  ------------------
  457|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  458|      0|	}
  459|       |
  460|       |	/* is this a CAC Alt token without any accompanying structures */
  461|  2.85k|	r = cac_find_first_pki_applet(card, &index);
  462|  2.85k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.85k|#define SC_SUCCESS				0
  ------------------
  |  Branch (462:6): [True: 424, False: 2.43k]
  ------------------
  463|    424|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "PKI applet found, is bare CAC-1");
  ------------------
  |  |   70|    424|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|    424|		if (!initialize) /* match card only */
  ------------------
  |  Branch (464:7): [True: 216, False: 208]
  ------------------
  465|    216|			return r;
  466|       |
  467|    208|		if (!priv) {
  ------------------
  |  Branch (467:7): [True: 208, False: 0]
  ------------------
  468|    208|			priv = cac_new_private_data();
  469|    208|			if (!priv)
  ------------------
  |  Branch (469:8): [True: 0, False: 208]
  ------------------
  470|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  471|    208|		}
  472|    208|		card->drv_data = priv; /* needed for the read_binary() */
  473|    208|		r = cac_populate_cac1(card, index, priv);
  474|    208|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    208|#define SC_SUCCESS				0
  ------------------
  |  Branch (474:7): [True: 176, False: 32]
  ------------------
  475|    176|			card->type = SC_CARD_TYPE_CAC_I;
  476|    176|			return r;
  477|    176|		}
  478|     32|		card->drv_data = NULL; /* reset on failure */
  479|     32|	}
  480|  2.46k|	if (priv) {
  ------------------
  |  Branch (480:6): [True: 32, False: 2.43k]
  ------------------
  481|     32|		cac_free_private_data(priv);
  482|     32|	}
  483|  2.46k|	return r;
  484|  2.85k|}
card-cac1.c:cac_find_first_pki_applet:
  365|  2.85k|{
  366|  2.85k|	int r, i;
  367|       |
  368|  42.0k|	for (i = 0; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  42.0k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (368:14): [True: 39.6k, False: 2.43k]
  ------------------
  369|  39.6k|		r = cac_select_pki_applet(card, i);
  370|  39.6k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  39.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (370:7): [True: 539, False: 39.1k]
  ------------------
  371|    539|			u8 data[2];
  372|    539|			sc_apdu_t apdu;
  373|       |
  374|       |			/* Try to read first two bytes of the buffer to
  375|       |			 * make sure it is not just malfunctioning card
  376|       |			 */
  377|    539|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2,
  ------------------
  |  |  301|    539|#define SC_APDU_CASE_2			0x22
  ------------------
  378|    539|				CAC_INS_GET_CERTIFICATE, 0x00, 0x00);
  ------------------
  |  |   59|    539|#define CAC_INS_GET_CERTIFICATE       0x36  /* CAC1 command to read a certificate */
  ------------------
  379|    539|			apdu.le = 0x02;
  380|    539|			apdu.resplen = 2;
  381|    539|			apdu.resp = data;
  382|    539|			r = sc_transmit_apdu(card, &apdu);
  383|       |			/* SW1 = 0x63 means more data in CAC1 */
  384|    539|			if (r == SC_SUCCESS && apdu.sw1 != 0x63)
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (384:8): [True: 147, False: 392]
  |  Branch (384:27): [True: 115, False: 32]
  ------------------
  385|    115|				continue;
  386|       |
  387|    424|			*index_out = i;
  388|    424|			return SC_SUCCESS;
  ------------------
  |  |   28|    424|#define SC_SUCCESS				0
  ------------------
  389|    539|		}
  390|  39.6k|	}
  391|  2.43k|	return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  2.43k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  392|  2.85k|}
card-cac1.c:cac_select_pki_applet:
  355|  43.0k|{
  356|  43.0k|	sc_path_t applet_path = cac_cac_pki_obj.path;
  357|  43.0k|	applet_path.aid.value[applet_path.aid.len-1] = index;
  358|       |	return cac_select_file_by_type(card, &applet_path, NULL);
  359|  43.0k|}
card-cac1.c:cac_select_file_by_type:
  201|  44.3k|{
  202|  44.3k|	struct sc_context *ctx;
  203|  44.3k|	struct sc_apdu apdu;
  204|  44.3k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  205|  44.3k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  206|  44.3k|	int r, pathtype;
  207|  44.3k|	size_t pathlen;
  208|  44.3k|	struct sc_file *file = NULL;
  209|  44.3k|	cac_private_data_t *priv;
  210|       |
  211|  44.3k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (211:6): [True: 0, False: 44.3k]
  |  Branch (211:22): [True: 0, False: 44.3k]
  ------------------
  212|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  213|       |
  214|  44.3k|	ctx = card->ctx;
  215|  44.3k|	priv = CAC_DATA(card);
  ------------------
  |  |   61|  44.3k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  216|       |
  217|  44.3k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  44.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  44.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  44.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 44.3k]
  |  |  ------------------
  ------------------
  218|       |
  219|  44.3k|	memcpy(path, in_path->value, in_path->len);
  220|  44.3k|	pathlen = in_path->len;
  221|  44.3k|	pathtype = in_path->type;
  222|       |
  223|  44.3k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  44.3k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  224|  44.3k|		"path=%s, path->value=%s path->type=%d (%x)",
  225|  44.3k|		sc_print_path(in_path),
  226|  44.3k|		sc_dump_hex(in_path->value, in_path->len),
  227|  44.3k|		in_path->type, in_path->type);
  228|  44.3k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "file_out=%p index=%d count=%d\n",
  ------------------
  |  |   70|  44.3k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  229|  44.3k|		file_out, in_path->index, in_path->count);
  230|       |
  231|       |	/* Sigh, iso7816_select_file expects paths to keys to have specific
  232|       |	 * formats. There is no override. We have to add some bytes to the
  233|       |	 * path to make it happy.
  234|       |	 * We only need to do this for private keys.
  235|       |	 */
  236|  44.3k|	if ((pathlen > 2) && (pathlen <= 4) && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (236:6): [True: 524, False: 43.7k]
  |  Branch (236:23): [True: 524, False: 0]
  |  Branch (236:41): [True: 524, False: 0]
  ------------------
  237|    524|		path += 2;
  238|    524|		pathlen -= 2;
  239|    524|	}
  240|       |
  241|       |
  242|       |	/* CAC has multiple different type of objects that aren't PKCS #15. When we read
  243|       |	 * them we need convert them to something PKCS #15 would understand. Find the object
  244|       |	 * and object type here:
  245|       |	 */
  246|  44.3k|	if (priv) { /* don't record anything if we haven't been initialized yet */
  ------------------
  |  Branch (246:6): [True: 4.65k, False: 39.6k]
  ------------------
  247|       |		/* forget any old cached values */
  248|  4.65k|		if (priv->cache_buf) {
  ------------------
  |  Branch (248:7): [True: 241, False: 4.41k]
  ------------------
  249|    241|			free(priv->cache_buf);
  250|    241|			priv->cache_buf = NULL;
  251|    241|		}
  252|  4.65k|		priv->cache_buf_len = 0;
  253|  4.65k|		priv->cached = 0;
  254|  4.65k|	}
  255|       |
  256|  44.3k|	if (in_path->aid.len) {
  ------------------
  |  Branch (256:6): [True: 43.7k, False: 524]
  ------------------
  257|  43.7k|		if (!pathlen) {
  ------------------
  |  Branch (257:7): [True: 43.7k, False: 0]
  ------------------
  258|  43.7k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  259|  43.7k|			pathlen = in_path->aid.len;
  260|  43.7k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  43.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  261|  43.7k|		} else {
  262|       |			/* First, select the application */
  263|      0|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"select application" );
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  264|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  265|      0|			apdu.data = in_path->aid.value;
  266|      0|			apdu.datalen = in_path->aid.len;
  267|      0|			apdu.lc = in_path->aid.len;
  268|       |
  269|      0|			r = sc_transmit_apdu(card, &apdu);
  270|      0|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|      0|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  272|      0|			if (r)
  ------------------
  |  Branch (272:8): [True: 0, False: 0]
  ------------------
  273|      0|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  274|       |
  275|      0|		}
  276|  43.7k|	}
  277|       |
  278|  44.3k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  44.3k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  279|       |
  280|  44.3k|	switch (pathtype) {
  281|       |	/* ideally we would had SC_PATH_TYPE_OBJECT_ID and add code to the iso7816 select.
  282|       |	 * Unfortunately we'd also need to update the caching code as well. For now just
  283|       |	 * use FILE_ID and change p1 here */
  284|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (284:2): [True: 0, False: 44.3k]
  ------------------
  285|      0|		apdu.p1 = 2;
  286|      0|		if (pathlen != 2)
  ------------------
  |  Branch (286:7): [True: 0, False: 0]
  ------------------
  287|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  288|      0|		break;
  289|  43.7k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  43.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (289:2): [True: 43.7k, False: 524]
  ------------------
  290|  43.7k|		apdu.p1 = 4;
  291|  43.7k|		break;
  292|    524|	default:
  ------------------
  |  Branch (292:2): [True: 524, False: 43.7k]
  ------------------
  293|    524|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    524|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    524|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    524|	int _ret = r; \
  |  |  |  |  155|    524|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    524|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    524|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    524|	return _ret; \
  |  |  |  |  163|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|  44.3k|	}
  295|  43.7k|	apdu.lc = pathlen;
  296|  43.7k|	apdu.data = path;
  297|  43.7k|	apdu.datalen = pathlen;
  298|  43.7k|	apdu.resp = buf;
  299|  43.7k|	apdu.resplen = sizeof(buf);
  300|  43.7k|	apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (300:12): [True: 0, False: 43.7k]
  ------------------
  301|  43.7k|	apdu.p2 = 0x00;
  302|       |
  303|  43.7k|	r = sc_transmit_apdu(card, &apdu);
  304|  43.7k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  43.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  43.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  43.7k|	int _ret = (r); \
  |  |  |  |  168|  43.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 186, False: 43.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    186|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    186|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    186|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    186|		return _ret; \
  |  |  |  |  172|    186|	} \
  |  |  |  |  173|  43.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|  43.6k|	if (file_out == NULL) {
  ------------------
  |  Branch (306:6): [True: 42.8k, False: 742]
  ------------------
  307|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  308|  42.8k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  309|  42.8k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (309:7): [True: 185, False: 42.6k]
  |  Branch (309:27): [True: 88, False: 97]
  ------------------
  310|     88|			apdu.p2 = 0x00;
  311|     88|			apdu.resplen = sizeof(buf);
  312|     88|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     88|#define SC_SUCCESS				0
  ------------------
  |  Branch (312:8): [True: 34, False: 54]
  ------------------
  313|     34|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  314|     88|		}
  315|  42.8k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (315:7): [True: 54, False: 42.8k]
  ------------------
  316|  42.8k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|  42.8k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  42.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  42.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  42.8k|	int _ret = r; \
  |  |  |  |  155|  42.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 42.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  42.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  41.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 41.2k, False: 1.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  42.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  42.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  42.8k|	return _ret; \
  |  |  |  |  163|  42.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|  42.8k|	}
  319|       |
  320|    742|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  321|    742|	if (r)
  ------------------
  |  Branch (321:6): [True: 280, False: 462]
  ------------------
  322|    742|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    280|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    280|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    280|	int _ret = r; \
  |  |  |  |  155|    280|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 280, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    280|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    280|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 280, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    280|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    280|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    280|	return _ret; \
  |  |  |  |  163|    280|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|       |	/* CAC cards never return FCI, fake one */
  325|    462|	file = sc_file_new();
  326|    462|	if (file == NULL)
  ------------------
  |  Branch (326:6): [True: 0, False: 462]
  ------------------
  327|    462|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  328|    462|	file->path = *in_path;
  329|    462|	file->size = CAC_MAX_SIZE; /* we don't know how big, just give a large size until we can read the file */
  ------------------
  |  |   26|    462|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
  330|       |
  331|    462|	*file_out = file;
  332|    462|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    462|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    462|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    462|	int _ret = r; \
  |  |  |  |  155|    462|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 462, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    462|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 462]
  |  |  |  |  ------------------
  |  |  |  |  157|    462|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    462|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    462|	return _ret; \
  |  |  |  |  163|    462|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  333|       |
  334|    462|}
card-cac1.c:cac_populate_cac1:
  395|    208|{
  396|    208|	int r, i;
  397|    208|	cac_object_t pki_obj = cac_cac_pki_obj;
  398|    208|	u8 buf[100];
  399|    208|	u8 *val;
  400|    208|	size_t val_len;
  401|       |
  402|       |	/* populate PKI objects */
  403|  3.38k|	for (i = index; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  3.38k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (403:18): [True: 3.18k, False: 208]
  ------------------
  404|  3.18k|		r = cac_select_pki_applet(card, i);
  405|  3.18k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.18k|#define SC_SUCCESS				0
  ------------------
  |  Branch (405:7): [True: 869, False: 2.31k]
  ------------------
  406|    869|			pki_obj.name = get_cac_label(i);
  407|    869|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    869|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  408|    869|				"CAC: pki_object found, cert_next=%d (%s)",
  409|    869|				i, pki_obj.name);
  410|    869|			pki_obj.path.aid.value[pki_obj.path.aid.len-1] = i;
  411|    869|			pki_obj.fd = i+1; /* don't use id of zero */
  412|    869|			cac_add_object_to_list(&priv->pki_list, &pki_obj);
  413|    869|		}
  414|  3.18k|	}
  415|       |
  416|       |	/*
  417|       |	 * create a cuid to simulate the cac 2 cuid.
  418|       |	 */
  419|    208|	priv->cuid = cac_cac_cuid;
  420|       |	/* create a serial number by hashing the first 100 bytes of the
  421|       |	 * first certificate on the card */
  422|    208|	r = cac_select_pki_applet(card, index);
  423|    208|	if (r < 0) {
  ------------------
  |  Branch (423:6): [True: 32, False: 176]
  ------------------
  424|     32|		return r; /* shouldn't happen unless the card has been removed or is malfunctioning */
  425|     32|	}
  426|    176|	val = buf;
  427|    176|	val_len = sizeof(buf);
  428|    176|	r = cac_cac1_get_certificate(card, &val, &val_len);
  429|    176|	if (r >= 0) {
  ------------------
  |  Branch (429:6): [True: 43, False: 133]
  ------------------
  430|     43|		priv->cac_id = malloc(20);
  431|     43|		if (priv->cac_id == NULL) {
  ------------------
  |  Branch (431:7): [True: 0, False: 43]
  ------------------
  432|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  433|      0|		}
  434|     43|#ifdef ENABLE_OPENSSL
  435|     43|		SHA1(val, val_len, priv->cac_id);
  436|     43|		priv->cac_id_len = 20;
  437|     43|		sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|     43|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  438|     43|			"cuid", priv->cac_id, priv->cac_id_len);
  439|       |#else
  440|       |		sc_log(card->ctx, "OpenSSL Required");
  441|       |		return SC_ERROR_NOT_SUPPORTED;
  442|       |#endif /* ENABLE_OPENSSL */
  443|     43|	}
  444|    176|	return SC_SUCCESS;
  ------------------
  |  |   28|    176|#define SC_SUCCESS				0
  ------------------
  445|    176|}
card-cac1.c:cac_cac1_get_certificate:
   65|    638|{
   66|    638|	u8 buf[CAC_MAX_SIZE];
   67|    638|	u8 *out_ptr;
   68|    638|	size_t size = 0;
   69|    638|	size_t left = 0;
   70|    638|	size_t len;
   71|    638|	sc_apdu_t apdu;
   72|    638|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    638|#define SC_SUCCESS				0
  ------------------
   73|    638|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    638|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    638|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    638|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 638]
  |  |  ------------------
  ------------------
   74|       |	/* get the size */
   75|    638|	size = left = *out_buf ? *out_len : sizeof(buf);
  ------------------
  |  Branch (75:16): [True: 176, False: 462]
  ------------------
   76|    638|	out_ptr = *out_buf ? *out_buf : buf;
  ------------------
  |  Branch (76:12): [True: 176, False: 462]
  ------------------
   77|    638|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, CAC_INS_GET_CERTIFICATE, 0, 0 );
  ------------------
  |  |  292|    638|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
              	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, CAC_INS_GET_CERTIFICATE, 0, 0 );
  ------------------
  |  |   59|    638|#define CAC_INS_GET_CERTIFICATE       0x36  /* CAC1 command to read a certificate */
  ------------------
   78|    638|	len = MIN(left, 100);
  ------------------
  |  |   69|    638|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 638]
  |  |  ------------------
  ------------------
   79|    679|	while (left > 0) {
  ------------------
  |  Branch (79:9): [True: 669, False: 10]
  ------------------
   80|    669|		apdu.resp = out_ptr;
   81|    669|		apdu.le = len;
   82|    669|		apdu.resplen = left;
   83|    669|		r = sc_transmit_apdu(card, &apdu);
   84|    669|		if (r < 0) {
  ------------------
  |  Branch (84:7): [True: 81, False: 588]
  ------------------
   85|     81|			break;
   86|     81|		}
   87|    588|		if (apdu.resplen == 0) {
  ------------------
  |  Branch (87:7): [True: 140, False: 448]
  ------------------
   88|    140|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    140|#define SC_ERROR_INTERNAL			-1400
  ------------------
   89|    140|			break;
   90|    140|		}
   91|       |		/* in the old CAC-1, 0x63 means 'more data' in addition to 'pin failed' */
   92|    448|		if (apdu.sw1 != 0x63 || apdu.sw2 < 1)  {
  ------------------
  |  Branch (92:7): [True: 388, False: 60]
  |  Branch (92:27): [True: 19, False: 41]
  ------------------
   93|       |			/* we've either finished reading, or hit an error, break */
   94|    407|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   95|    407|			left -= apdu.resplen;
   96|    407|			break;
   97|    407|		}
   98|       |		/* Adjust the lengths */
   99|     41|		left -= apdu.resplen;
  100|     41|		out_ptr += apdu.resplen;
  101|     41|		len = MIN(left, apdu.sw2);
  ------------------
  |  |   69|     41|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 20, False: 21]
  |  |  ------------------
  ------------------
  102|     41|	}
  103|    638|	if (r < 0) {
  ------------------
  |  Branch (103:6): [True: 258, False: 380]
  ------------------
  104|    258|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    258|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    258|	int _ret = r; \
  |  |  155|    258|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 258, False: 0]
  |  |  ------------------
  |  |  156|    258|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    258|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 258, False: 0]
  |  |  ------------------
  |  |  157|    258|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    258|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    258|	return _ret; \
  |  |  163|    258|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  105|    258|	}
  106|    380|	r = (int)(size - left);
  107|    380|	if (*out_buf == NULL) {
  ------------------
  |  Branch (107:6): [True: 337, False: 43]
  ------------------
  108|    337|		*out_buf = malloc(r);
  109|    337|		if (*out_buf == NULL) {
  ------------------
  |  Branch (109:7): [True: 0, False: 337]
  ------------------
  110|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  111|      0|				SC_ERROR_OUT_OF_MEMORY);
  112|      0|		}
  113|    337|		memcpy(*out_buf, buf, r);
  114|    337|	}
  115|    380|	*out_len = r;
  116|    380|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    380|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    380|	int _ret = r; \
  |  |  155|    380|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 380]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    380|	} else { \
  |  |  159|    380|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    380|			"returning with: %d\n", _ret); \
  |  |  161|    380|	} \
  |  |  162|    380|	return _ret; \
  |  |  163|    380|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  117|    380|}
card-cac1.c:cac_init:
  499|    216|{
  500|    216|	int r;
  501|    216|	unsigned long flags;
  502|       |
  503|    216|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    216|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    216|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    216|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 216]
  |  |  ------------------
  ------------------
  504|       |
  505|    216|	r = cac_find_and_initialize(card, 1);
  506|    216|	if (r < 0) {
  ------------------
  |  Branch (506:6): [True: 40, False: 176]
  ------------------
  507|     40|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     40|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     40|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     40|	int _ret = r; \
  |  |  |  |  155|     40|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 40, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 40, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     40|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     40|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     40|	return _ret; \
  |  |  |  |  163|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|     40|	}
  509|    176|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    176|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  510|       |
  511|    176|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
  512|    176|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
  513|    176|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
  514|       |
  515|    176|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    176|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    176|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  516|       |
  517|    176|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    176|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    176|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    176|	int _ret = r; \
  |  |  |  |  155|    176|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 176, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    176|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 176]
  |  |  |  |  ------------------
  |  |  |  |  157|    176|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    176|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    176|	return _ret; \
  |  |  |  |  163|    176|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  518|    176|}
card-cac1.c:cac_finish:
  342|    176|{
  343|    176|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    176|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  344|       |
  345|    176|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    176|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    176|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    176|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 176]
  |  |  ------------------
  ------------------
  346|    176|	if (priv) {
  ------------------
  |  Branch (346:6): [True: 176, False: 0]
  ------------------
  347|    176|		cac_free_private_data(priv);
  348|    176|	}
  349|    176|	return SC_SUCCESS;
  ------------------
  |  |   28|    176|#define SC_SUCCESS				0
  ------------------
  350|    176|}
card-cac1.c:cac_select_file:
  337|  1.26k|{
  338|  1.26k|	return cac_select_file_by_type(card, in_path, file_out);
  339|  1.26k|}
card-cac1.c:cac_read_binary:
  126|  1.76k|{
  127|  1.76k|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|  1.76k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  128|  1.76k|	int r = 0;
  129|  1.76k|	u8 *val = NULL;
  130|  1.76k|	u8 *cert_ptr;
  131|  1.76k|	size_t val_len = 0;
  132|  1.76k|	size_t len, cert_len;
  133|  1.76k|	u8 cert_type;
  134|       |
  135|  1.76k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.76k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.76k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.76k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.76k]
  |  |  ------------------
  ------------------
  136|       |
  137|       |	/* if we didn't return it all last time, return the remainder */
  138|  1.76k|	if (priv->cached) {
  ------------------
  |  Branch (138:6): [True: 1.30k, False: 462]
  ------------------
  139|  1.30k|		sc_log(card->ctx, "returning cached value idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|  1.30k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  140|  1.30k|		if (idx > priv->cache_buf_len) {
  ------------------
  |  Branch (140:7): [True: 0, False: 1.30k]
  ------------------
  141|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_END_REACHED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  142|      0|		}
  143|  1.30k|		len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   69|  1.30k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 928, False: 377]
  |  |  ------------------
  ------------------
  144|  1.30k|		memcpy(buf, &priv->cache_buf[idx], len);
  145|  1.30k|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|  1.30k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.30k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.30k|	int _ret = r; \
  |  |  |  |  155|  1.30k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 254, False: 1.05k]
  |  |  |  |  ------------------
  |  |  |  |  156|    254|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 254]
  |  |  |  |  ------------------
  |  |  |  |  157|    254|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.05k|	} else { \
  |  |  |  |  159|  1.05k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.05k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.05k|	} \
  |  |  |  |  162|  1.30k|	return _ret; \
  |  |  |  |  163|  1.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|  1.30k|	}
  147|       |
  148|    462|	sc_log(card->ctx, "clearing cache idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|    462|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  149|    462|	free(priv->cache_buf);
  150|    462|	priv->cache_buf = NULL;
  151|    462|	priv->cache_buf_len = 0;
  152|       |
  153|    462|	r = cac_cac1_get_certificate(card, &val, &val_len);
  154|    462|	if (r < 0)
  ------------------
  |  Branch (154:6): [True: 125, False: 337]
  ------------------
  155|    125|		goto done;
  156|    337|	if (val_len < 1) {
  ------------------
  |  Branch (156:6): [True: 0, False: 337]
  ------------------
  157|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  158|      0|		goto done;
  159|      0|	}
  160|       |
  161|    337|	cert_type = val[0];
  162|    337|	cert_ptr = val + 1;
  163|    337|	cert_len = val_len - 1;
  164|       |
  165|       |	/* if the info byte is 1, then the cert is compressed, decompress it */
  166|    337|	if ((cert_type & 0x3) == 1) {
  ------------------
  |  Branch (166:6): [True: 196, False: 141]
  ------------------
  167|    196|		if (flags)
  ------------------
  |  Branch (167:7): [True: 196, False: 0]
  ------------------
  168|    196|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|    196|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  169|    196|	}
  170|    337|	if (cert_len > 0) {
  ------------------
  |  Branch (170:6): [True: 301, False: 36]
  ------------------
  171|    301|		priv->cache_buf = malloc(cert_len);
  172|    301|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (172:7): [True: 0, False: 301]
  ------------------
  173|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  174|      0|			goto done;
  175|      0|		}
  176|    301|		priv->cache_buf_len = cert_len;
  177|    301|		memcpy(priv->cache_buf, cert_ptr, cert_len);
  178|    301|	}
  179|       |
  180|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
  181|    337|	priv->cached = 1;
  182|    337|	len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   69|    337|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 123, False: 214]
  |  |  ------------------
  ------------------
  183|    337|	if (len && priv->cache_buf)
  ------------------
  |  Branch (183:6): [True: 301, False: 36]
  |  Branch (183:13): [True: 301, False: 0]
  ------------------
  184|    301|		memcpy(buf, &priv->cache_buf[idx], len);
  185|    337|	r = (int)len;
  186|    462|done:
  187|    462|	if (val)
  ------------------
  |  Branch (187:6): [True: 337, False: 125]
  ------------------
  188|    337|		free(val);
  189|    462|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    462|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    462|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    462|	int _ret = r; \
  |  |  |  |  155|    462|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 161, False: 301]
  |  |  |  |  ------------------
  |  |  |  |  156|    161|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    125|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 125, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  157|    161|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    301|	} else { \
  |  |  |  |  159|    301|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    301|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    301|	} \
  |  |  |  |  162|    462|	return _ret; \
  |  |  |  |  163|    462|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  190|    462|}

sc_get_cardos_driver:
 1594|  15.2k|{
 1595|  15.2k|	return sc_get_driver();
 1596|  15.2k|}
card-cardos.c:sc_get_driver:
 1569|  15.2k|{
 1570|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1570:6): [True: 1, False: 15.2k]
  ------------------
 1571|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1572|  15.2k|	cardos_ops = *iso_ops;
 1573|  15.2k|	cardos_ops.match_card = cardos_match_card;
 1574|  15.2k|	cardos_ops.init = cardos_init;
 1575|  15.2k|	cardos_ops.finish = cardos_finish;
 1576|  15.2k|	cardos_ops.select_file = cardos_select_file;
 1577|  15.2k|	cardos_ops.create_file = cardos_create_file;
 1578|  15.2k|	cardos_ops.set_security_env = cardos_set_security_env;
 1579|  15.2k|	cardos_ops.restore_security_env = cardos_restore_security_env;
 1580|  15.2k|	cardos_ops.compute_signature = cardos_compute_signature;
 1581|  15.2k|	cardos_ops.decipher = cardos_decipher;
 1582|       |
 1583|  15.2k|	cardos_ops.list_files = cardos_list_files;
 1584|  15.2k|	cardos_ops.check_sw = cardos_check_sw;
 1585|  15.2k|	cardos_ops.card_ctl = cardos_card_ctl;
 1586|  15.2k|	cardos_ops.pin_cmd = cardos_pin_cmd;
 1587|  15.2k|	cardos_ops.logout  = cardos_logout;
 1588|       |
 1589|  15.2k|	return &cardos_drv;
 1590|  15.2k|}
card-cardos.c:cardos_match_card:
   82|  14.7k|{
   83|  14.7k|	unsigned char atr[SC_MAX_ATR_SIZE] = {0};
   84|  14.7k|	int i;
   85|       |
   86|  14.7k|	i = _sc_match_atr(card, cardos_atrs, &card->type);
   87|  14.7k|	if (i < 0)
  ------------------
  |  Branch (87:6): [True: 14.2k, False: 568]
  ------------------
   88|  14.2k|		return 0;
   89|       |
   90|    568|	memcpy(atr, card->atr.value, card->atr.len);
   91|       |
   92|       |	/* Do not change card type for CIE! */
   93|    568|	if (card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (93:6): [True: 0, False: 568]
  ------------------
   94|      0|		return 1;
   95|    568|	if (card->type == SC_CARD_TYPE_CARDOS_M4_4)
  ------------------
  |  Branch (95:6): [True: 0, False: 568]
  ------------------
   96|      0|		return 1;
   97|    568|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0)
  ------------------
  |  Branch (97:6): [True: 4, False: 564]
  ------------------
   98|      4|		return 1;
   99|    564|	if (card->type == SC_CARD_TYPE_CARDOS_V5_3)
  ------------------
  |  Branch (99:6): [True: 432, False: 132]
  ------------------
  100|    432|		return 1;
  101|    132|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (101:6): [True: 97, False: 35]
  ------------------
  102|     97|		int rv;
  103|     97|		sc_apdu_t apdu = {0};
  104|     97|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = {0};
  105|       |		/* first check some additional ATR bytes */
  106|     97|		if ((atr[4] != 0xff && atr[4] != 0x02) ||
  ------------------
  |  Branch (106:8): [True: 95, False: 2]
  |  Branch (106:26): [True: 6, False: 89]
  ------------------
  107|     91|		    (atr[6] != 0x10 && atr[6] != 0x0a) ||
  ------------------
  |  Branch (107:8): [True: 11, False: 80]
  |  Branch (107:26): [True: 9, False: 2]
  ------------------
  108|     82|		    (atr[9] != 0x55 && atr[9] != 0x58))
  ------------------
  |  Branch (108:8): [True: 81, False: 1]
  |  Branch (108:26): [True: 7, False: 74]
  ------------------
  109|     22|			return 0;
  110|       |		/* get the os version using GET DATA and compare it with
  111|       |		 * version in the ATR */
  112|     75|		sc_log(card->ctx,  "checking cardos version ...");
  ------------------
  |  |   71|     75|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  113|     75|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x82);
  ------------------
  |  |  292|     75|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  114|     75|		apdu.resp = rbuf;
  115|     75|		apdu.resplen = sizeof(rbuf);
  116|     75|		apdu.le = 256;
  117|     75|		apdu.lc = 0;
  118|     75|		rv = sc_transmit_apdu(card, &apdu);
  119|     75|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     75|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     75|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     75|	int _ret = (r); \
  |  |  |  |  168|     75|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 70]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 70]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  120|     70|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || apdu.resplen < 2)
  ------------------
  |  Branch (120:7): [True: 11, False: 59]
  |  Branch (120:27): [True: 4, False: 55]
  |  Branch (120:47): [True: 2, False: 53]
  ------------------
  121|     17|			return 0;
  122|     53|		if (apdu.resp[0] != atr[10] ||
  ------------------
  |  Branch (122:7): [True: 11, False: 42]
  ------------------
  123|     42|		    apdu.resp[1] != atr[11])
  ------------------
  |  Branch (123:7): [True: 11, False: 31]
  ------------------
  124|       |			/* version mismatch */
  125|     22|			return 0;
  126|     31|		if (atr[11] <= 0x04) {
  ------------------
  |  Branch (126:7): [True: 2, False: 29]
  ------------------
  127|      2|			sc_log(card->ctx,  "found cardos m4.01");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  128|      2|			card->type = SC_CARD_TYPE_CARDOS_M4_01;
  129|     29|		} else if (atr[11] == 0x08) {
  ------------------
  |  Branch (129:14): [True: 1, False: 28]
  ------------------
  130|      1|			sc_log(card->ctx,  "found cardos v4.3b");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  131|      1|			card->type = SC_CARD_TYPE_CARDOS_M4_3;
  132|     28|		} else if (atr[11] == 0x09) {
  ------------------
  |  Branch (132:14): [True: 2, False: 26]
  ------------------
  133|      2|			sc_log(card->ctx,  "found cardos v4.2b");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  134|      2|			card->type = SC_CARD_TYPE_CARDOS_M4_2B;
  135|     26|		} else if (atr[11] >= 0x0B) {
  ------------------
  |  Branch (135:14): [True: 9, False: 17]
  ------------------
  136|      9|			sc_log(card->ctx,  "found cardos v4.2c or higher");
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  137|      9|			card->type = SC_CARD_TYPE_CARDOS_M4_2C;
  138|     17|		} else {
  139|     17|			sc_log(card->ctx,  "found cardos m4.2");
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  140|     17|		}
  141|     31|	}
  142|     66|	return 1;
  143|    132|}
card-cardos.c:cardos_init:
  218|    502|{
  219|    502|	cardos_data_t * priv = NULL;
  220|    502|	unsigned long flags = 0;
  221|    502|	size_t data_field_length;
  222|    502|	sc_apdu_t apdu;
  223|    502|	u8 rbuf[2];
  224|    502|	int r;
  225|       |
  226|    502|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    502|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    502|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    502|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 502]
  |  |  ------------------
  ------------------
  227|       |
  228|    502|	priv = calloc(1, sizeof(cardos_data_t));
  229|    502|	if (!priv)
  ------------------
  |  Branch (229:6): [True: 0, False: 502]
  ------------------
  230|    502|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|    502|	card->drv_data = priv;
  232|       |
  233|    502|	card->name = "Atos CardOS";
  234|    502|	card->cla = 0x00;
  235|       |
  236|       |	/* let user override flags and type from opensc.conf */
  237|       |	/* user can override card->type too.*/
  238|    502|	if (card->flags) {
  ------------------
  |  Branch (238:6): [True: 0, False: 502]
  ------------------
  239|      0|	    flags = card->flags;
  240|    502|	} else {
  241|       |
  242|       |		/* Set up algorithm info. */
  243|    502|		flags = 0;
  244|    502|		if (card->type == SC_CARD_TYPE_CARDOS_V5_0) {
  ------------------
  |  Branch (244:7): [True: 4, False: 498]
  ------------------
  245|      4|			flags |= SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  111|      4|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      4|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      4|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              			flags |= SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|      4|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  246|    498|		} else if(card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (246:13): [True: 432, False: 66]
  ------------------
  247|    432|			flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PSS | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    432|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              			flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PSS | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  133|    432|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              			flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PSS | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  107|    432|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
              			flags |= SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PSS | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    432|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  248|    432|		} else {
  249|     66|			flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|     66|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  250|     66|				| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|     66|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  251|     66|				| SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|     66|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  252|     66|				| SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     66|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  253|     66|		}
  254|    502|	}
  255|       |
  256|    502|	priv->flags = flags;
  257|       |
  258|    502|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (258:6): [True: 17, False: 485]
  ------------------
  259|     17|		r = cardos_have_2048bit_package(card);
  260|     17|		if (r < 0) {
  ------------------
  |  Branch (260:7): [True: 1, False: 16]
  ------------------
  261|      1|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      1|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  262|      1|			goto err;
  263|      1|		}
  264|     16|		if (r == 1)
  ------------------
  |  Branch (264:7): [True: 1, False: 15]
  ------------------
  265|      1|			priv->rsa_2048 = 1;
  266|     16|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     16|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  267|    485|	} else if (card->type == SC_CARD_TYPE_CARDOS_M4_3
  ------------------
  |  Branch (267:13): [True: 1, False: 484]
  ------------------
  268|    484|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2B
  ------------------
  |  Branch (268:6): [True: 2, False: 482]
  ------------------
  269|    482|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2C
  ------------------
  |  Branch (269:6): [True: 9, False: 473]
  ------------------
  270|    473|		|| card->type == SC_CARD_TYPE_CARDOS_M4_4
  ------------------
  |  Branch (270:6): [True: 0, False: 473]
  ------------------
  271|    473|		|| card->type == SC_CARD_TYPE_CARDOS_V5_0
  ------------------
  |  Branch (271:6): [True: 4, False: 469]
  ------------------
  272|    469|		|| card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (272:6): [True: 432, False: 37]
  ------------------
  273|    448|		priv->rsa_2048 = 1;
  274|    448|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    448|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  275|       |		/* TODO check this. EC only if in supported_algo */
  276|    448|		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    448|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    448|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  277|    448|	}
  278|       |
  279|       |	/* probe DATA FIELD LENGTH with GET DATA */
  280|    501|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x8D);
  ------------------
  |  |  292|    501|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  281|    501|	apdu.le = sizeof rbuf;
  282|    501|	apdu.resp = rbuf;
  283|    501|	apdu.resplen = sizeof(rbuf);
  284|       |
  285|    501|	r = sc_transmit_apdu(card, &apdu);
  286|    501|	if (r < 0)
  ------------------
  |  Branch (286:6): [True: 6, False: 495]
  ------------------
  287|    501|		LOG_TEST_GOTO_ERR(card->ctx,
  ------------------
  |  |  184|      6|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      6|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      6|	int _ret = (r); \
  |  |  |  |  178|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      6|		goto err; \
  |  |  |  |  182|      6|	} \
  |  |  |  |  183|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|    495|				SC_ERROR_INVALID_CARD,
  289|    495|				"APDU transmit failed");
  290|    495|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  291|    495|	if (r < 0)
  ------------------
  |  Branch (291:6): [True: 107, False: 388]
  ------------------
  292|    495|		LOG_TEST_GOTO_ERR(card->ctx,
  ------------------
  |  |  184|    107|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    107|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    107|	int _ret = (r); \
  |  |  |  |  178|    107|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 107, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    107|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    107|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    107|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    107|		goto err; \
  |  |  |  |  182|    107|	} \
  |  |  |  |  183|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|    388|				SC_ERROR_INVALID_CARD,
  294|    388|				"GET DATA command returned error");
  295|    388|	if (apdu.resplen != 2) {
  ------------------
  |  Branch (295:6): [True: 7, False: 381]
  ------------------
  296|      7|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      7|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  297|      7|		goto err;
  298|      7|	}
  299|    381|	data_field_length = ((rbuf[0] << 8) | rbuf[1]);
  300|       |
  301|       |	/* TODO is this really needed? strip the length of possible Lc and Le bytes */
  302|       |
  303|       |	/* Use Min card sizes and reader too. for V5_3 at least*/
  304|       |
  305|    381|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (305:6): [True: 3, False: 378]
  |  Branch (305:48): [True: 340, False: 38]
  ------------------
  306|    343|		sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|    343|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  309|    343|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  |  |  |  |  310|    343|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  |  |  |  |  ------------------
  |  |  |  |  |  |  547|    343|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|    343|				"data_field_length:%zu card->reader->max_send_size:%zu "
  308|    343|				"card->reader->max_recv_size:%zu %s",
  309|    343|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  310|    343|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  311|       |
  312|    343|		if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  547|    343|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (312:7): [True: 343, False: 0]
  ------------------
  313|    343|			card->max_send_size  = data_field_length - 6;
  314|       |#ifdef _WIN32
  315|       |			/* Windows does not support PCSC PART_10 and may have forced reader to 255/256
  316|       |			 * https://github.com/OpenSC/OpenSC/commit/eddea6f3c2d3dafc2c09eba6695c745a61b5186f
  317|       |			 * may have reset this. if so, will override and force extended
  318|       |			 * Most, if not all, cardos cards do extended, but not chaining
  319|       |			 */
  320|       |			if (card->reader->max_send_size == 255 && card->reader->max_recv_size == 256) {
  321|       |				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "resetting reader to use data_field_length");
  322|       |				card->reader->max_send_size = data_field_length - 6;
  323|       |				card->reader->max_recv_size = data_field_length - 3;
  324|       |			}
  325|       |#endif
  326|    343|		} else
  327|      0|			card->max_send_size = data_field_length - 3;
  328|       |
  329|    343|		card->max_send_size = sc_get_max_send_size(card); /* include reader sizes and protocol */
  330|    343|		card->max_recv_size = data_field_length - 2;
  331|    343|		card->max_recv_size = sc_get_max_recv_size(card);
  332|    343|	} else {
  333|       |		/* old way, disregards reader capabilities */
  334|     38|		if (card->caps & SC_CARD_CAP_APDU_EXT)
  ------------------
  |  |  547|     38|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (334:7): [True: 3, False: 35]
  ------------------
  335|      3|			card->max_send_size = data_field_length - 6;
  336|     35|		else
  337|     35|			card->max_send_size = data_field_length - 3;
  338|       |		/* strip the length of SW bytes */
  339|     38|		card->max_recv_size = data_field_length - 2;
  340|     38|	}
  341|       |
  342|       |	/*for new cards, wait till after sc_pkcs15_bind_internal reads tokeninfo */
  343|    381|	if (card->type != SC_CARD_TYPE_CARDOS_V5_0 && card->type != SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (343:6): [True: 378, False: 3]
  |  Branch (343:48): [True: 38, False: 340]
  ------------------
  344|     38|		r = cardos_add_algs(card, flags, 0, 0);
  345|     38|	}
  346|       |
  347|    502|err:
  348|    502|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    502|#define SC_SUCCESS				0
  ------------------
  |  Branch (348:6): [True: 121, False: 381]
  ------------------
  349|    121|		free(priv);
  350|    121|		card->drv_data = NULL;
  351|    121|	}
  352|       |
  353|    502|	return r;
  354|    381|}
card-cardos.c:cardos_have_2048bit_package:
  146|     17|{
  147|     17|	sc_apdu_t apdu;
  148|     17|        u8        rbuf[SC_MAX_APDU_BUFFER_SIZE];
  149|     17|        int       r;
  150|     17|	const u8  *p = rbuf, *q, *pp;
  151|     17|	size_t    len, tlen = 0, ilen = 0;
  152|       |
  153|     17|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x88);
  ------------------
  |  |  292|     17|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  154|     17|	apdu.resp    = rbuf;
  155|     17|	apdu.resplen = sizeof(rbuf);
  156|     17|	apdu.lc = 0;
  157|     17|	apdu.le = 256;
  158|     17|	r = sc_transmit_apdu(card, &apdu);
  159|     17|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|     16|	if ((len = apdu.resplen) == 0)
  ------------------
  |  Branch (161:6): [True: 3, False: 13]
  ------------------
  162|       |		/* looks like no package has been installed  */
  163|      3|		return 0;
  164|       |
  165|     79|	while (len != 0) {
  ------------------
  |  Branch (165:9): [True: 72, False: 7]
  ------------------
  166|     72|		pp = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen);
  167|     72|		if (pp == NULL)
  ------------------
  |  Branch (167:7): [True: 1, False: 71]
  ------------------
  168|      1|			return 0;
  169|     71|		q = sc_asn1_find_tag(card->ctx, pp, tlen, 0x01, &ilen);
  170|     71|		if (q == NULL || ilen != 4)
  ------------------
  |  Branch (170:7): [True: 1, False: 70]
  |  Branch (170:20): [True: 3, False: 67]
  ------------------
  171|      4|			return 0;
  172|     67|		if (q[0] == 0x1c)
  ------------------
  |  Branch (172:7): [True: 1, False: 66]
  ------------------
  173|      1|			return 1;
  174|     66|		p   += tlen;
  175|     66|		len -= tlen + 2;
  176|     66|	}
  177|       |
  178|      7|	return 0;
  179|     13|}
card-cardos.c:cardos_add_algs:
  185|     42|{
  186|       |
  187|     42|	cardos_data_t * priv = (cardos_data_t *)card->drv_data;
  188|       |
  189|     42|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     42|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     42|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     42|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 42]
  |  |  ------------------
  ------------------
  190|       |
  191|     42|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  192|     42|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  193|     42|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  194|     42|	if (priv->rsa_2048 == 1) {
  ------------------
  |  Branch (194:6): [True: 6, False: 36]
  ------------------
  195|      6|		_sc_card_add_rsa_alg(card, 1280, flags, 0);
  196|      6|		_sc_card_add_rsa_alg(card, 1536, flags, 0);
  197|      6|		_sc_card_add_rsa_alg(card, 1792, flags, 0);
  198|      6|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  199|      6|	}
  200|       |
  201|     42|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (201:6): [True: 1, False: 41]
  |  Branch (201:48): [True: 3, False: 38]
  ------------------
  202|       |		/* Starting with CardOS 5, the card supports PIN query commands */
  203|      4|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|      4|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  204|      4|		_sc_card_add_rsa_alg(card, 3072, flags, 0);
  205|      4|		_sc_card_add_rsa_alg(card, 4096, flags, 0);
  206|      4|	}
  207|       |
  208|       |	/* TODO need to get sizes from supported_algos too */
  209|     42|	if (ec_flags != 0) {
  ------------------
  |  Branch (209:6): [True: 0, False: 42]
  ------------------
  210|      0|		 _sc_card_add_ec_alg(card, 256, ec_flags, priv->ext_flags, NULL);
  211|      0|		 _sc_card_add_ec_alg(card, 384, ec_flags, priv->ext_flags, NULL);
  212|      0|	}
  213|       |
  214|     42|	return 0;
  215|     42|}
card-cardos.c:cardos_finish:
  381|    381|{
  382|    381|	int r = 0;
  383|       |
  384|    381|	if (card == NULL )
  ------------------
  |  Branch (384:6): [True: 0, False: 381]
  ------------------
  385|      0|		return 0;
  386|       |
  387|    381|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    381|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    381|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    381|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 381]
  |  |  ------------------
  ------------------
  388|       |
  389|       |	/* free priv data */
  390|    381|	if (card->drv_data) { /* priv */
  ------------------
  |  Branch (390:6): [True: 381, False: 0]
  ------------------
  391|    381|		free(card->drv_data);
  392|    381|		card->drv_data = NULL;
  393|    381|	}
  394|       |
  395|    381|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    381|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    381|	int _ret = r; \
  |  |  155|    381|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 381, False: 0]
  |  |  ------------------
  |  |  156|    381|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 381]
  |  |  ------------------
  |  |  157|    381|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    381|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    381|	return _ret; \
  |  |  163|    381|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  396|    381|}
card-cardos.c:cardos_select_file:
  638|  2.22k|{
  639|  2.22k|	int r;
  640|       |
  641|  2.22k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.22k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.22k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.22k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.22k]
  |  |  ------------------
  ------------------
  642|  2.22k|	r = iso_ops->select_file(card, in_path, file);
  643|  2.22k|	if (r >= 0 && file)
  ------------------
  |  Branch (643:6): [True: 474, False: 1.74k]
  |  Branch (643:16): [True: 347, False: 127]
  ------------------
  644|    347|		parse_sec_attr((*file), (*file)->sec_attr, (*file)->sec_attr_len);
  645|  2.22k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.22k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.22k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.22k|	int _ret = r; \
  |  |  |  |  155|  2.22k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.22k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.74k, False: 474]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.22k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.22k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.22k|	return _ret; \
  |  |  |  |  163|  2.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  646|  2.22k|}
card-cardos.c:parse_sec_attr:
  623|    347|{
  624|    347|	size_t i;
  625|    347|	const int *idx;
  626|       |
  627|    347|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    347|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (627:8): [True: 1, False: 346]
  ------------------
  628|       |
  629|       |	/* acl defaults to 0xFF if unspecified */
  630|  3.47k|	for (i = 0; i < 9; i++)
  ------------------
  |  Branch (630:14): [True: 3.12k, False: 347]
  ------------------
  631|  3.12k|		if (idx[i] != -1)
  ------------------
  |  Branch (631:7): [True: 2.42k, False: 695]
  ------------------
  632|  2.42k|			add_acl_entry(file, idx[i], (u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (632:37): [True: 277, False: 2.15k]
  ------------------
  633|    347|}
card-cardos.c:add_acl_entry:
  550|  2.42k|{
  551|  2.42k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  2.42k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  552|       |
  553|  2.42k|	switch (byte) {
  554|     61|	case 0x00:
  ------------------
  |  Branch (554:2): [True: 61, False: 2.36k]
  ------------------
  555|     61|		method = SC_AC_NONE;
  ------------------
  |  |  150|     61|#define SC_AC_NONE			0x00000000
  ------------------
  556|     61|		break;
  557|  2.18k|	case 0xFF:
  ------------------
  |  Branch (557:2): [True: 2.18k, False: 244]
  ------------------
  558|  2.18k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  2.18k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  559|  2.18k|		break;
  560|    183|	default:
  ------------------
  |  Branch (560:2): [True: 183, False: 2.24k]
  ------------------
  561|    183|		if (byte > 0x7F) {
  ------------------
  |  Branch (561:7): [True: 80, False: 103]
  ------------------
  562|     80|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     80|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  563|    103|		} else {
  564|    103|			method = SC_AC_CHV;
  ------------------
  |  |  151|    103|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  565|    103|			key_ref = byte;
  566|    103|		}
  567|    183|		break;
  568|  2.42k|	}
  569|  2.42k|	sc_file_add_acl_entry(file, op, method, key_ref);
  570|  2.42k|}
card-cardos.c:cardos_check_sw:
  462|  4.90k|{
  463|  4.90k|	const int err_count = sizeof(cardos_errors)/sizeof(cardos_errors[0]);
  464|  4.90k|	int i;
  465|       |
  466|   117k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (466:14): [True: 116k, False: 211]
  ------------------
  467|   116k|		if (cardos_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (467:7): [True: 4.69k, False: 112k]
  ------------------
  468|  4.69k|			if ( cardos_errors[i].errorstr )
  ------------------
  |  Branch (468:9): [True: 2.13k, False: 2.56k]
  ------------------
  469|  2.13k|				sc_log(card->ctx,  "%s\n",
  ------------------
  |  |   71|  2.13k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  470|  4.69k|				 	cardos_errors[i].errorstr);
  471|  4.69k|			return cardos_errors[i].errorno;
  472|  4.69k|		}
  473|   116k|	}
  474|       |
  475|    211|        sc_log(card->ctx,  "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
  ------------------
  |  |   71|    211|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  476|    211|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    211|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  477|  4.90k|}
card-cardos.c:cardos_card_ctl:
 1475|     25|{
 1476|     25|	switch (cmd) {
  ------------------
  |  Branch (1476:10): [True: 25, False: 0]
  ------------------
 1477|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_FCI:
  ------------------
  |  Branch (1477:2): [True: 0, False: 25]
  ------------------
 1478|      0|		break;
 1479|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_OCI:
  ------------------
  |  Branch (1479:2): [True: 0, False: 25]
  ------------------
 1480|      0|		return cardos_put_data_oci(card,
 1481|      0|			(struct sc_cardctl_cardos_obj_info *) ptr);
 1482|      0|		break;
 1483|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_SECI:
  ------------------
  |  Branch (1483:2): [True: 0, False: 25]
  ------------------
 1484|      0|		return cardos_put_data_seci(card,
 1485|      0|			(struct sc_cardctl_cardos_obj_info *) ptr);
 1486|      0|		break;
 1487|      0|	case SC_CARDCTL_CARDOS_GENERATE_KEY:
  ------------------
  |  Branch (1487:2): [True: 0, False: 25]
  ------------------
 1488|      0|		return cardos_generate_key(card,
 1489|      0|			(struct sc_cardctl_cardos_genkey_info *) ptr);
 1490|      8|	case  SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS:
  ------------------
  |  Branch (1490:2): [True: 8, False: 17]
  ------------------
 1491|      8|		return cardos_pass_algo_flags(card,
 1492|      8|			(struct sc_cardctl_cardos_pass_algo_flags *) ptr);
 1493|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1493:2): [True: 0, False: 25]
  ------------------
 1494|      0|		return cardos_lifecycle_get(card, (int *) ptr);
 1495|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1495:2): [True: 0, False: 25]
  ------------------
 1496|      0|		return cardos_lifecycle_set(card, (int *) ptr);
 1497|     17|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1497:2): [True: 17, False: 8]
  ------------------
 1498|     17|		return cardos_get_serialnr(card, (sc_serial_number_t *)ptr);
 1499|     25|	}
 1500|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1501|     25|}
card-cardos.c:cardos_pass_algo_flags:
  357|      8|{
  358|      8|	cardos_data_t * priv = (cardos_data_t *)card->drv_data;
  359|      8|	int r = 0;
  360|       |
  361|      8|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      8|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  ------------------
  ------------------
  362|      8|	switch (ptr->pass) {
  363|      4|		case 1:
  ------------------
  |  Branch (363:3): [True: 4, False: 4]
  ------------------
  364|      4|			ptr->card_flags = card->flags;
  365|      4|			ptr->used_flags = priv->flags;
  366|      4|			ptr->ec_flags = priv->ec_flags;
  367|      4|			ptr->ext_flags = priv->ext_flags;
  368|      4|			break;
  369|      4|		case 2:
  ------------------
  |  Branch (369:3): [True: 4, False: 4]
  ------------------
  370|      4|			r = cardos_add_algs(card,ptr->new_flags, ptr->ec_flags, ptr->ext_flags);
  371|      4|			break;
  372|      0|		default:
  ------------------
  |  Branch (372:3): [True: 0, False: 8]
  ------------------
  373|      0|			sc_log(card->ctx, "ptr->pass: %ul invalid", ptr->pass);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  374|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  375|      8|	}
  376|      8|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  157|      8|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      8|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|      8|}
card-cardos.c:cardos_get_serialnr:
 1442|     17|{
 1443|     17|	int r;
 1444|     17|	sc_apdu_t apdu;
 1445|     17|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1446|       |
 1447|     17|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     17|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1448|     17|	apdu.resp = rbuf;
 1449|     17|	apdu.resplen = sizeof(rbuf);
 1450|     17|	apdu.le   = 256;
 1451|     17|	r = sc_transmit_apdu(card, &apdu);
 1452|     17|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1453|     15|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1453:6): [True: 4, False: 11]
  |  Branch (1453:26): [True: 1, False: 10]
  ------------------
 1454|      5|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1455|     10|	if ((apdu.resplen == 8) && (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3)) {
  ------------------
  |  Branch (1455:6): [True: 3, False: 7]
  |  Branch (1455:30): [True: 1, False: 2]
  |  Branch (1455:72): [True: 1, False: 1]
  ------------------
 1456|       |		/* cache serial number */
 1457|      2|		memcpy(card->serialnr.value, rbuf, 8);
 1458|      2|		card->serialnr.len = 8;
 1459|      8|	} else if (apdu.resplen == 32) {
  ------------------
  |  Branch (1459:13): [True: 1, False: 7]
  ------------------
 1460|       |		/* cache serial number */
 1461|      1|		memcpy(card->serialnr.value, &rbuf[10], 6);
 1462|      1|		card->serialnr.len = 6;
 1463|      7|	} else {
 1464|      7|		sc_log(card->ctx,  "unexpected response to GET DATA serial"
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1465|      7|				" number\n");
 1466|      7|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1467|      7|	}
 1468|       |	/* copy and return serial number */
 1469|      3|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1470|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1471|     10|}
card-cardos.c:cardos_pin_cmd:
 1510|     12|{
 1511|     12|	struct sc_context *ctx = card->ctx;
 1512|     12|	int rv;
 1513|       |
 1514|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1515|       |
 1516|     12|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     12|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1517|     12|	data->pin_reference |= 0x80;
 1518|       |
 1519|     12|	sc_log(ctx, "PIN_CMD(cmd:%i, ref:%i)", data->cmd, data->pin_reference);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1520|     12|	sc_log(ctx, "PIN1(max:%zu, min:%zu)", data->pin1.max_length, data->pin1.min_length);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1521|     12|	sc_log(ctx, "PIN2(max:%zu, min:%zu)", data->pin2.max_length, data->pin2.min_length);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1522|       |
 1523|       |	/* FIXME: the following values depend on what pin length was
 1524|       |	 * used when creating the BS objects */
 1525|     12|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (1525:6): [True: 12, False: 0]
  ------------------
 1526|     12|		data->pin1.max_length = 8;
 1527|     12|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (1527:6): [True: 12, False: 0]
  ------------------
 1528|     12|		data->pin2.max_length = 8;
 1529|       |
 1530|     12|	rv = iso_ops->pin_cmd(card, data);
 1531|     12|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|     12|}

sc_get_cedulauy_driver:
  292|  15.2k|{
  293|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  294|       |
  295|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (295:6): [True: 1, False: 15.2k]
  ------------------
  296|      1|		iso_ops = iso_drv->ops;
  297|       |
  298|  15.2k|	cedulauy_ops = *iso_ops;
  299|  15.2k|	cedulauy_ops.match_card = cedulauy_match_card;
  300|  15.2k|	cedulauy_ops.init = cedulauy_init;
  301|  15.2k|	cedulauy_ops.select_file = cedulauy_select_file;
  302|  15.2k|	cedulauy_ops.set_security_env = cedulauy_set_security_env;
  303|  15.2k|	cedulauy_ops.compute_signature = cedulauy_compute_signature;
  304|  15.2k|	cedulauy_ops.decipher = NULL; /* the signing key is sign-only */
  305|  15.2k|	cedulauy_ops.get_challenge = cedulauy_get_challenge;
  306|  15.2k|	cedulauy_ops.logout = cedulauy_logout;
  307|  15.2k|	cedulauy_ops.card_reader_lock_obtained = cedulauy_card_reader_lock_obtained;
  308|       |
  309|  15.2k|	return &cedulauy_drv;
  310|  15.2k|}
card-cedulauy.c:cedulauy_match_card:
  112|  7.54k|{
  113|  7.54k|	int i = _sc_match_atr(card, cedulauy_atrs, &card->type);
  114|       |
  115|  7.54k|	if (i < 0)
  ------------------
  |  Branch (115:6): [True: 7.44k, False: 94]
  ------------------
  116|  7.44k|		return 0;
  117|     94|	card->name = cedulauy_atrs[i].name;
  118|     94|	return 1;
  119|  7.54k|}
card-cedulauy.c:cedulauy_init:
  123|     94|{
  124|     94|	unsigned long flags;
  125|     94|	int r;
  126|       |
  127|     94|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     94|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     94|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     94|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     94|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|     94|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     94|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  130|       |
  131|     94|	r = cedulauy_select_app(card);
  132|     94|	LOG_TEST_RET(card->ctx, r, "Cannot select the eID application");
  ------------------
  |  |  174|     94|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     94|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     94|	int _ret = (r); \
  |  |  |  |  168|     94|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     94|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  133|       |
  134|       |	/* The card builds the DigestInfo on-card only for SHA-256 (algorithm
  135|       |	 * reference 0x42).  Everything else is signed as raw PKCS#1 v1.5 over
  136|       |	 * a DigestInfo built in software (algorithm reference 0x02). */
  137|     82|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  111|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  133|     82|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|     82|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  138|     82|	r = _sc_card_add_rsa_alg(card, 2048, flags, 0);
  139|       |
  140|     82|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     82|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     82|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     82|	int _ret = r; \
  |  |  |  |  155|     82|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 82, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     82|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  157|     82|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     82|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     82|	return _ret; \
  |  |  |  |  163|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|     82|}
card-cedulauy.c:cedulauy_select_app:
   97|     94|{
   98|     94|	struct sc_apdu apdu;
   99|     94|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  100|       |
  101|     94|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     94|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     94|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     94|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     94|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  102|       |
  103|     94|	sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x04, 0x00,
  104|     94|			cedulauy_aid, sizeof cedulauy_aid, resp, sizeof resp);
  105|     94|	SC_TRANSMIT_TEST_RET(card, apdu, "Cannot select the eID application");
  ------------------
  |  |   90|     94|	do { \
  |  |   91|     94|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|     94|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     94|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     94|	int _ret = (r); \
  |  |  |  |  |  |  168|     94|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 2, False: 92]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  |  |  172|      2|	} \
  |  |  |  |  |  |  173|     94|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 92]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|     94|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|     92|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     92|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     92|	int _ret = (r); \
  |  |  |  |  |  |  168|     92|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 10, False: 82]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  |  |  172|     10|	} \
  |  |  |  |  |  |  173|     92|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|     92|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 82]
  |  |  ------------------
  ------------------
  106|       |
  107|     82|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     82|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     82|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     82|	int _ret = r; \
  |  |  |  |  155|     82|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 82, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     82|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  157|     82|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     82|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     82|	return _ret; \
  |  |  |  |  163|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  108|     82|}
card-cedulauy.c:cedulauy_select_file:
  170|    151|{
  171|    151|	struct sc_path path = *in_path;
  172|       |
  173|    151|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    151|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    151|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    151|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    151|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 151]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|    151|	if (path.aid.len == sizeof cedulauy_aid && 0 == memcmp(path.aid.value, cedulauy_aid, sizeof cedulauy_aid)) {
  ------------------
  |  Branch (175:6): [True: 82, False: 69]
  |  Branch (175:45): [True: 82, False: 0]
  ------------------
  176|       |		/* swallow cedula AID, it is always selected via init() */
  177|     82|		path.aid.len = 0;
  178|     82|	}
  179|    151|	if (path.type == SC_PATH_TYPE_PATH && path.len >= 2 && path.value[0] == 0x3F && path.value[1] == 0x00) {
  ------------------
  |  |  119|    302|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (179:6): [True: 69, False: 82]
  |  Branch (179:40): [True: 69, False: 0]
  |  Branch (179:57): [True: 69, False: 0]
  |  Branch (179:82): [True: 69, False: 0]
  ------------------
  180|       |		/* swallow MF, everything resides within the Application DF */
  181|     69|		memmove(path.value, path.value + 2, path.len - 2);
  182|     69|		path.len -= 2;
  183|     69|	}
  184|    151|	if (path.type == SC_PATH_TYPE_PATH && path.len == 0) {
  ------------------
  |  |  119|    302|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:6): [True: 69, False: 82]
  |  Branch (184:40): [True: 0, False: 69]
  ------------------
  185|       |		/* Selection of MF was requested */
  186|      0|		sc_file_dup(file_out, cedulauy_get_mf());
  187|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|      0|	}
  189|       |
  190|    151|	LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, &path, file_out));
  ------------------
  |  |  164|    151|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    151|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    151|	int _ret = r; \
  |  |  |  |  155|    151|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 151, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    151|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    127|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 127, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|    151|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    151|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    151|	return _ret; \
  |  |  |  |  163|    151|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  191|    151|}
card-cedulauy.c:cedulauy_set_security_env:
  196|     29|{
  197|     29|	struct sc_apdu apdu;
  198|       |	/* MSE SET, Digital Signature Template: key reference and algorithm */
  199|     29|	unsigned char mse_data[] = {0x84, 0x01, 0xFF, 0x80, 0x01, CEDULAUY_ALGO_RSA_PKCS1};
  ------------------
  |  |   61|     29|#define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   57|     29|#define CEDULAUY_ALGO_HASH_NONE	  0x00 /* DigestInfo built in software */
  |  |  ------------------
  |  |               #define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   59|     29|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  200|       |
  201|     29|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     29|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     29|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     29|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     29|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|       |
  203|     29|	if (env == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 29]
  ------------------
  204|     29|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|     29|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|     29|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (205:6): [True: 0, False: 29]
  ------------------
  206|     29|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|     29|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   60|     29|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
              	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|     29|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (207:6): [True: 29, False: 0]
  |  Branch (207:47): [True: 0, False: 29]
  ------------------
  208|     29|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  209|     29|	if (env->key_ref_len != 1)
  ------------------
  |  Branch (209:6): [True: 0, False: 29]
  ------------------
  210|     29|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|       |
  212|     29|	mse_data[2] = env->key_ref[0];
  213|     29|	if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256)
  ------------------
  |  |  138|     29|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (213:6): [True: 27, False: 2]
  ------------------
  214|     27|		mse_data[5] = CEDULAUY_ALGO_RSA_PKCS1_SHA256;
  ------------------
  |  |   62|     27|#define CEDULAUY_ALGO_RSA_PKCS1_SHA256 (CEDULAUY_ALGO_HASH_SHA256 | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   58|     27|#define CEDULAUY_ALGO_HASH_SHA256 0x40 /* card builds the DigestInfo */
  |  |  ------------------
  |  |               #define CEDULAUY_ALGO_RSA_PKCS1_SHA256 (CEDULAUY_ALGO_HASH_SHA256 | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   59|     27|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  215|       |
  216|     29|	sc_format_apdu_ex(&apdu, card->cla, 0x22, 0x41, 0xB6,
  217|     29|			mse_data, sizeof mse_data, NULL, 0);
  218|     29|	SC_TRANSMIT_TEST_RET(card, apdu, "MSE SET DST failed");
  ------------------
  |  |   90|     29|	do { \
  |  |   91|     29|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 1, False: 28]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  |  |  172|      1|	} \
  |  |  |  |  |  |  173|     29|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|     29|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|     28|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     28|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     28|	int _ret = (r); \
  |  |  |  |  |  |  168|     28|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 10, False: 18]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  |  |  172|     10|	} \
  |  |  |  |  |  |  173|     28|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|     28|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 18]
  |  |  ------------------
  ------------------
  219|       |
  220|     18|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  221|     18|}
card-cedulauy.c:cedulauy_compute_signature:
  226|     18|{
  227|     18|	struct sc_apdu apdu;
  228|     18|	unsigned char sbuf[64];
  229|     18|	unsigned char rbuf[256]; /* RSA 2048 */
  230|     18|	size_t offs = 0;
  231|       |
  232|     18|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     18|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     18|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     18|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     18|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|       |
  234|     18|	if (data == NULL || out == NULL)
  ------------------
  |  Branch (234:6): [True: 0, False: 18]
  |  Branch (234:22): [True: 0, False: 18]
  ------------------
  235|     18|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|       |	/* What is loaded here matches the algorithm set in set_security_env:
  238|       |	 * for 0x42 'data' is the bare SHA-256 digest and the card builds the
  239|       |	 * DigestInfo; for 0x02 'data' is a complete DigestInfo built in
  240|       |	 * software, which the card pads (PKCS#1 v1.5) as-is. */
  241|     18|	if (datalen == 0 || datalen > sizeof(sbuf) - 2)
  ------------------
  |  Branch (241:6): [True: 0, False: 18]
  |  Branch (241:22): [True: 1, False: 17]
  ------------------
  242|     18|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|     17|				"Unsupported hash/DigestInfo length");
  244|       |
  245|       |	/* PSO HASH: load the digest */
  246|     17|	sbuf[offs++] = 0x90;
  247|     17|	sbuf[offs++] = (unsigned char)datalen;
  248|     17|	memcpy(sbuf + offs, data, datalen);
  249|     17|	offs += datalen;
  250|     17|	sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x90, 0xA0, sbuf, offs, NULL, 0);
  251|     17|	SC_TRANSMIT_TEST_RET(card, apdu, "PSO HASH failed");
  ------------------
  |  |   90|     17|	do { \
  |  |   91|     17|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 0, False: 17]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  |  |  172|      0|	} \
  |  |  |  |  |  |  173|     17|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|     17|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 8, False: 9]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  |  |  172|      8|	} \
  |  |  |  |  |  |  173|     17|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|     17|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 9]
  |  |  ------------------
  ------------------
  252|       |
  253|       |	/* PSO COMPUTE DIGITAL SIGNATURE */
  254|      9|	sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x9E, 0x9A, NULL, 0, rbuf, sizeof rbuf);
  255|      9|	SC_TRANSMIT_TEST_RET(card, apdu, "PSO COMPUTE DIGITAL SIGNATURE failed");
  ------------------
  |  |   90|      9|	do { \
  |  |   91|      9|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 2, False: 7]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  |  |  172|      2|	} \
  |  |  |  |  |  |  173|      9|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|      9|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 5, False: 2]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  |  |  172|      5|	} \
  |  |  |  |  |  |  173|      7|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|      7|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 2]
  |  |  ------------------
  ------------------
  256|       |
  257|      2|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (257:6): [True: 0, False: 2]
  ------------------
  258|      2|		LOG_TEST_RET(card->ctx, SC_ERROR_BUFFER_TOO_SMALL,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|      2|				"Signature buffer too small");
  260|      2|	memcpy(out, apdu.resp, apdu.resplen);
  261|      2|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|      2|}
card-cedulauy.c:cedulauy_card_reader_lock_obtained:
  145|    306|{
  146|    306|	if (was_reset)
  ------------------
  |  Branch (146:6): [True: 0, False: 306]
  ------------------
  147|    306|		LOG_FUNC_RETURN(card->ctx, cedulauy_select_app(card));
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|    306|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    306|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    306|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    306|	int _ret = r; \
  |  |  |  |  155|    306|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 306, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    306|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 306]
  |  |  |  |  ------------------
  |  |  |  |  157|    306|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    306|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    306|	return _ret; \
  |  |  |  |  163|    306|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  149|    306|}

sc_get_chipdocit_driver:
  486|  15.2k|{
  487|  15.2k|	struct sc_card_driver *iso = sc_get_iso7816_driver();
  488|  15.2k|	chipdocit_ops = *iso->ops;
  489|  15.2k|	chipdocit_ops.match_card = chipdocit_match_card;
  490|  15.2k|	chipdocit_ops.init = chipdocit_init;
  491|  15.2k|	chipdocit_ops.finish = chipdocit_finish;
  492|  15.2k|	chipdocit_ops.pin_cmd = chipdocit_pin_cmd;
  493|  15.2k|	chipdocit_ops.set_security_env = chipdocit_set_security_env;
  494|  15.2k|	chipdocit_ops.compute_signature = chipdocit_compute_signature;
  495|  15.2k|	return &chipdocit_drv;
  496|  15.2k|}
card-chipdocit.c:chipdocit_match_card:
  149|  4.00k|{
  150|  4.00k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.00k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.00k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  151|  4.00k|	if (_sc_match_atr(card, chipdocit_atrs, &card->type) < 0)
  ------------------
  |  Branch (151:6): [True: 4.00k, False: 0]
  ------------------
  152|  4.00k|		LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  4.00k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.00k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.00k|	int _ret = r; \
  |  |  |  |  155|  4.00k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.00k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.00k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.00k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.00k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.00k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.00k|	return _ret; \
  |  |  |  |  163|  4.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  153|       |	/* The ATR is shared with other Italian CNS cards; confirm this is the NXP
  154|       |	 * ChipDoc so the others fall through to the generic CNS driver. First select
  155|       |	 * the IAS-ECC application: this activates the card (its applets are otherwise
  156|       |	 * unreachable on a card not yet opened by other software). That AID is not a
  157|       |	 * discriminator on its own -- it is also the ICAO eMRTD application AID and
  158|       |	 * is present on other IAS-ECC cards, answering 90 00 on unrelated documents.
  159|       |	 * Then confirm the ChipDoc by selecting its Bit4id SSCD application, which is
  160|       |	 * absent elsewhere (6A 82 on an eMRTD), so the match does not become too
  161|       |	 * broad. */
  162|      0|	if (iso7816_select_aid(card, CHIPDOCIT_IAS_AID, sizeof CHIPDOCIT_IAS_AID, NULL, NULL) != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (162:6): [True: 0, False: 0]
  ------------------
  163|      0|		LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|      0|	if (iso7816_select_aid(card, CHIPDOCIT_SSCD_AID, sizeof CHIPDOCIT_SSCD_AID, NULL, NULL) != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (164:6): [True: 0, False: 0]
  ------------------
  165|      0|		LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  166|      0|	LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      0|}

coolkey_get_attribute_data:
  603|  1.70k|{
  604|       |	/* handle the V0 objects first */
  605|  1.70k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  1.70k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (605:6): [True: 971, False: 738]
  ------------------
  606|    971|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  607|    971|	}
  608|       |
  609|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  610|    738|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|    738|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (610:6): [True: 0, False: 738]
  ------------------
  611|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  612|      0|	}
  613|       |
  614|    738|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  615|       |
  616|    738|}
coolkey_compare_id:
  758|  88.0k|{
  759|  88.0k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (759:6): [True: 0, False: 88.0k]
  |  Branch (759:19): [True: 0, False: 88.0k]
  ------------------
  760|      0|		return 1;
  761|  88.0k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  762|  88.0k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  763|  88.0k|}
coolkey_list_meter:
  766|  4.83k|size_t coolkey_list_meter(const void *el) {
  767|  4.83k|	return sizeof(sc_cardctl_coolkey_object_t);
  768|  4.83k|}
coolkey_fill_object:
 1365|  22.4k|{
 1366|  22.4k|	int r;
 1367|  22.4k|	size_t buf_len = obj->length;
 1368|  22.4k|	u8 *new_obj_data = NULL;
 1369|  22.4k|	sc_cardctl_coolkey_object_t *obj_entry;
 1370|  22.4k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  22.4k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1371|       |
 1372|  22.4k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  22.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  22.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  22.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  22.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 22.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|       |
 1374|  22.4k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1374:6): [True: 0, False: 22.4k]
  ------------------
 1375|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1376|      0|	}
 1377|  22.4k|	new_obj_data = malloc(buf_len);
 1378|  22.4k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1378:6): [True: 0, False: 22.4k]
  ------------------
 1379|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1380|      0|	}
 1381|  22.4k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1382|  22.4k|				priv->nonce, sizeof(priv->nonce));
 1383|  22.4k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1383:6): [True: 20.5k, False: 1.96k]
  ------------------
 1384|  20.5k|		free(new_obj_data);
 1385|  20.5k|		if (r < 0) {
  ------------------
  |  Branch (1385:7): [True: 20.5k, False: 0]
  ------------------
 1386|  20.5k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  20.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  20.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  20.5k|	int _ret = r; \
  |  |  |  |  155|  20.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  20.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  20.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  20.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  20.5k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  20.5k|	return _ret; \
  |  |  |  |  163|  20.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1387|  20.5k|		}
 1388|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1389|      0|	}
 1390|  1.96k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1391|  1.96k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1391:6): [True: 0, False: 1.96k]
  ------------------
 1392|      0|		free(new_obj_data);
 1393|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1394|      0|	}
 1395|  1.96k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1395:6): [True: 0, False: 1.96k]
  ------------------
 1396|      0|		free(new_obj_data);
 1397|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1398|      0|	}
 1399|       |	/* Make sure we will not go over the allocated limits in the other
 1400|       |	 * objects if they somehow got different lengths in matching objects */
 1401|  1.96k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1401:6): [True: 0, False: 1.96k]
  ------------------
 1402|      0|		free(new_obj_data);
 1403|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1404|      0|	}
 1405|  1.96k|	obj_entry->data = new_obj_data;
 1406|  1.96k|	obj->data = new_obj_data;
 1407|  1.96k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.96k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.96k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.96k|	int _ret = r; \
  |  |  |  |  155|  1.96k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.96k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.96k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.96k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.96k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.96k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.96k|	return _ret; \
  |  |  |  |  163|  1.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1408|  1.96k|}
coolkey_find_object_by_template:
 1497|  1.31k|{
 1498|  1.31k|	list_t *list;
 1499|  1.31k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1500|  1.31k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  1.31k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1501|  1.31k|	int i, r;
 1502|  1.31k|	unsigned int tmp_pos = (unsigned int) -1;
 1503|       |
 1504|  1.31k|	list = &priv->objects_list;
 1505|  1.31k|	if (list->iter_active) {
  ------------------
  |  Branch (1505:6): [True: 1.31k, False: 0]
  ------------------
 1506|       |		/* workaround missing functionality of second iterator */
 1507|  1.31k|		tmp_pos = list->iter_pos;
 1508|  1.31k|		list_iterator_stop(list);
 1509|  1.31k|	}
 1510|       |
 1511|  1.31k|	list_iterator_start(list);
 1512|  22.9k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1512:9): [True: 22.1k, False: 802]
  ------------------
 1513|  22.1k|		sc_cardctl_coolkey_attribute_t attribute;
 1514|  22.1k|		current = list_iterator_next(list);
 1515|  22.1k|		attribute.object = current;
 1516|       |
 1517|  23.7k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1517:13): [True: 23.2k, False: 517]
  ------------------
 1518|  23.2k|			attribute.attribute_type = template[i].attribute_type;
 1519|  23.2k|			r = coolkey_find_attribute(card, &attribute);
 1520|  23.2k|			if (r < 0) {
  ------------------
  |  Branch (1520:8): [True: 12.9k, False: 10.2k]
  ------------------
 1521|  12.9k|				break;
 1522|  12.9k|			}
 1523|  10.2k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1523:8): [True: 141, False: 10.1k]
  ------------------
 1524|    141|				break;
 1525|    141|			}
 1526|  10.1k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1526:8): [True: 36, False: 10.1k]
  ------------------
 1527|     36|				break;
 1528|     36|			}
 1529|  10.1k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1529:8): [True: 8.54k, False: 1.58k]
  ------------------
 1530|  10.1k|							attribute.attribute_length) != 0) {
 1531|  8.54k|				break;
 1532|  8.54k|			}
 1533|  10.1k|		}
 1534|       |		/* just return the first one */
 1535|  22.1k|		if (i == count) {
  ------------------
  |  Branch (1535:7): [True: 517, False: 21.6k]
  ------------------
 1536|    517|			rv = current;
 1537|    517|			break;
 1538|    517|		}
 1539|  22.1k|	}
 1540|       |
 1541|  1.31k|	list_iterator_stop(list);
 1542|  1.31k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1542:6): [True: 1.31k, False: 0]
  ------------------
 1543|       |		/* workaround missing functionality of second iterator */
 1544|  1.31k|		list_iterator_start(list);
 1545|  15.3k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1545:10): [True: 15.2k, False: 165]
  |  Branch (1545:41): [True: 14.0k, False: 1.15k]
  ------------------
 1546|  14.0k|			(void) list_iterator_next(list);
 1547|  1.31k|	}
 1548|  1.31k|	return rv;
 1549|  1.31k|}
sc_get_coolkey_driver:
 2469|  15.2k|{
 2470|  15.2k|	return sc_get_driver();
 2471|  15.2k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  518|    971|{
  519|       |	/* we need to manually detect types CK_ULONG */
  520|    971|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|    971|#define COOLKEY_V0_OBJECT 0
  ------------------
  521|    971|	int r;
  522|    971|	size_t len;
  523|       |
  524|    971|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|    971|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  525|    971|	attr_out->attribute_length = 0;
  526|    971|	attr_out->attribute_value = NULL;
  527|       |
  528|    971|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  529|    971|	if (r < 0) {
  ------------------
  |  Branch (529:6): [True: 0, False: 971]
  ------------------
  530|      0|		return r;
  531|      0|	}
  532|    971|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (532:6): [True: 156, False: 815]
  ------------------
  533|    156|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    156|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  534|    156|	}
  535|    815|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    815|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     16|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (535:6): [True: 799, False: 16]
  |  Branch (535:34): [True: 0, False: 16]
  ------------------
  536|    800|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     16|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (536:14): [True: 1, False: 15]
  ------------------
  537|    800|		if (len != 4) {
  ------------------
  |  Branch (537:7): [True: 211, False: 589]
  ------------------
  538|    211|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    211|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  539|    211|		}
  540|    589|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|    589|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  541|    589|	}
  542|       |	/* return the length and the data */
  543|    604|	attr_out->attribute_length = len;
  544|    604|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  545|    604|	return SC_SUCCESS;
  ------------------
  |  |   28|    604|#define SC_SUCCESS				0
  ------------------
  546|    815|}
card-coolkey.c:coolkey_get_attribute_type:
  411|  13.5k|{
  412|  13.5k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  413|       |
  414|  13.5k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  415|  13.5k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  351|  8.03k|{
  352|  8.03k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  353|       |	/* don't reference beyond our buffer */
  354|  8.03k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (354:6): [True: 349, False: 7.68k]
  ------------------
  355|    349|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    349|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  356|    349|	}
  357|  7.68k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  358|  7.68k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.68k|#define SC_SUCCESS				0
  ------------------
  359|  8.03k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  553|    738|{
  554|    738|	int r;
  555|    738|	size_t len;
  556|    738|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  557|       |
  558|    738|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (558:6): [True: 35, False: 703]
  ------------------
  559|     35|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     35|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  560|     35|	}
  561|       |
  562|       |	/* we must have type V1. Process according to data type */
  563|    703|	switch (attribute_head->attribute_data_type) {
  564|       |	/* ULONG has implied length of 4 */
  565|    230|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|    230|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (565:2): [True: 230, False: 473]
  ------------------
  566|    230|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (566:7): [True: 18, False: 212]
  ------------------
  567|     18|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     18|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  568|     18|		}
  569|    212|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|    212|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  570|    212|		attr_out->attribute_length = 4;
  571|    212|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  572|    212|		return SC_SUCCESS;
  ------------------
  |  |   28|    212|#define SC_SUCCESS				0
  ------------------
  573|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  574|       |	/* return type STRING for BOOLS */
  575|     49|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|     49|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (575:2): [True: 49, False: 654]
  ------------------
  576|     49|		attr_out->attribute_length = 1;
  577|     49|		attr_out->attribute_value =  &coolkey_static_false;
  578|     49|		return SC_SUCCESS;
  ------------------
  |  |   28|     49|#define SC_SUCCESS				0
  ------------------
  579|     42|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|     42|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (579:2): [True: 42, False: 661]
  ------------------
  580|     42|		attr_out->attribute_length = 1;
  581|     42|		attr_out->attribute_value =  &coolkey_static_true;
  582|     42|		return SC_SUCCESS;
  ------------------
  |  |   28|     42|#define SC_SUCCESS				0
  ------------------
  583|       |	/* string type has encoded length */
  584|    340|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|    340|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (584:2): [True: 340, False: 363]
  ------------------
  585|    340|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  586|    340|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|    340|#define SC_SUCCESS				0
  ------------------
  |  Branch (586:7): [True: 19, False: 321]
  ------------------
  587|     19|			return r;
  588|     19|		}
  589|    321|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (589:7): [True: 81, False: 240]
  ------------------
  590|     81|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     81|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  591|     81|		}
  592|    240|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  593|    240|		attr_out->attribute_length = len;
  594|    240|		return SC_SUCCESS;
  ------------------
  |  |   28|    240|#define SC_SUCCESS				0
  ------------------
  595|     42|	default:
  ------------------
  |  Branch (595:2): [True: 42, False: 661]
  ------------------
  596|     42|		break;
  597|    703|	}
  598|     42|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     42|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  599|    703|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  314|   301k|{
  315|   301k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  316|       |
  317|   301k|	*len = 0;
  318|       |	/* don't reference beyond our buffer */
  319|   301k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (319:6): [True: 291k, False: 10.0k]
  ------------------
  320|   291k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   291k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  321|   291k|	}
  322|  10.0k|	switch (attribute_head->attribute_data_type) {
  323|  4.76k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|  4.76k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (323:2): [True: 4.76k, False: 5.30k]
  ------------------
  324|  4.76k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (324:7): [True: 192, False: 4.57k]
  ------------------
  325|    192|			break;
  326|    192|		}
  327|  4.57k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  328|  4.57k|		if (encoded_len) {
  ------------------
  |  Branch (328:7): [True: 4.25k, False: 321]
  ------------------
  329|  4.25k|			*len += 2;
  330|  4.25k|		}
  331|  4.57k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.57k|#define SC_SUCCESS				0
  ------------------
  332|    525|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|    525|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (332:2): [True: 525, False: 9.54k]
  ------------------
  333|  1.07k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|  1.07k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (333:2): [True: 552, False: 9.52k]
  ------------------
  334|       |		/* NOTE: there is no encoded data from TYPE_BOOL_XXX, so we return length 0, but the length
  335|       |		 * of the attribute is actually 1 byte, so if encoded_len == false, return 1 */
  336|  1.07k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (336:10): [True: 1.07k, False: 0]
  ------------------
  337|  1.07k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
  338|      0|		break;
  339|  3.55k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|  3.55k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (339:2): [True: 3.55k, False: 6.51k]
  ------------------
  340|  3.55k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  341|  3.55k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.55k|#define SC_SUCCESS				0
  ------------------
  342|    677|	default:
  ------------------
  |  Branch (342:2): [True: 677, False: 9.39k]
  ------------------
  343|    677|		break;
  344|  10.0k|	}
  345|    869|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    869|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  346|  10.0k|}
card-coolkey.c:coolkey_read_object:
 1097|  22.6k|{
 1098|  22.6k|	coolkey_read_object_param_t params;
 1099|  22.6k|	u8 *out_ptr;
 1100|  22.6k|	size_t left = 0;
 1101|  22.6k|	size_t len;
 1102|  22.6k|	int r;
 1103|       |
 1104|  22.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  22.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  22.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  22.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 22.6k]
  |  |  ------------------
  ------------------
 1105|       |
 1106|  22.6k|	ulong2bebytes(&params.object_id[0], object_id);
 1107|       |
 1108|  22.6k|	out_ptr = out_buf;
 1109|  22.6k|	left = out_len;
 1110|  24.0k|	do {
 1111|  24.0k|		ulong2bebytes(&params.offset[0], offset);
 1112|  24.0k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   69|  24.0k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 14.9k, False: 9.14k]
  |  |  ------------------
  ------------------
 1113|  24.0k|		len = left;
 1114|  24.0k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   73|  24.0k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   89|  24.0k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1115|  24.0k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1116|  24.0k|		if (r < 0) {
  ------------------
  |  Branch (1116:7): [True: 18.2k, False: 5.81k]
  ------------------
 1117|  18.2k|			goto fail;
 1118|  18.2k|		}
 1119|       |		/* sanity check to make sure we don't overflow left */
 1120|  5.81k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1120:7): [True: 68, False: 5.74k]
  |  Branch (1120:23): [True: 2.26k, False: 3.48k]
  ------------------
 1121|  2.32k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.32k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1122|  2.32k|			goto fail;
 1123|  2.32k|		}
 1124|  3.48k|		out_ptr += len;
 1125|  3.48k|		offset += len;
 1126|  3.48k|		left -= len;
 1127|  3.48k|	} while (left != 0);
  ------------------
  |  Branch (1127:11): [True: 1.40k, False: 2.08k]
  ------------------
 1128|       |
 1129|  2.08k|	return (int)out_len;
 1130|       |
 1131|  20.6k|fail:
 1132|  20.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  20.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  20.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  20.6k|	int _ret = r; \
  |  |  |  |  155|  20.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  20.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  20.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  20.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  20.6k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  20.6k|	return _ret; \
  |  |  |  |  163|  20.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1133|  20.6k|}
card-coolkey.c:coolkey_apdu_io:
  913|  44.0k|{
  914|  44.0k|	int r;
  915|  44.0k|	sc_apdu_t apdu;
  916|  44.0k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  917|  44.0k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  918|  44.0k|	u8 *rbuf;
  919|  44.0k|	size_t rbuflen;
  920|  44.0k|	int cse = 0;
  921|       |
  922|       |
  923|  44.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  44.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  44.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  44.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 44.0k]
  |  |  ------------------
  ------------------
  924|       |
  925|  44.0k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  44.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  926|  44.0k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  927|       |
  928|  44.0k|	rbuf = rbufinitbuf;
  929|  44.0k|	rbuflen = sizeof(rbufinitbuf);
  930|       |
  931|       |	/* if caller provided a buffer and length */
  932|  44.0k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (932:6): [True: 33.8k, False: 10.1k]
  |  Branch (932:17): [True: 33.8k, False: 0]
  |  Branch (932:29): [True: 33.8k, False: 0]
  |  Branch (932:43): [True: 32.4k, False: 1.44k]
  ------------------
  933|  32.4k|		rbuf = *recvbuf;
  934|  32.4k|		rbuflen = *recvbuflen;
  935|  32.4k|	}
  936|       |
  937|  44.0k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (937:6): [True: 34.2k, False: 9.79k]
  |  Branch (937:17): [True: 0, False: 9.79k]
  ------------------
  938|  34.2k|		if (recvbuf) {
  ------------------
  |  Branch (938:7): [True: 24.0k, False: 10.1k]
  ------------------
  939|  24.0k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  24.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  940|  24.0k|		} else {
  941|  10.1k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  10.1k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  942|  10.1k|		}
  943|  34.2k|	} else {
  944|  9.79k|		if (recvbuf) {
  ------------------
  |  Branch (944:7): [True: 9.79k, False: 0]
  ------------------
  945|  9.79k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  9.79k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  946|  9.79k|		} else {
  947|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  948|      0|		}
  949|  9.79k|	}
  950|       |
  951|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  952|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  953|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  954|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  955|       |	 * and we should be fine */
  956|  44.0k|	if (nonce) {
  ------------------
  |  Branch (956:6): [True: 24.0k, False: 19.9k]
  ------------------
  957|  24.0k|		u8 *buf = rsendbuf;
  958|  24.0k|		if (sendbuf) {
  ------------------
  |  Branch (958:7): [True: 24.0k, False: 0]
  ------------------
  959|  24.0k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   69|  24.0k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 24.0k, False: 0]
  |  |  ------------------
  ------------------
  960|  24.0k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  961|  24.0k|			buf += sendbuflen;
  962|  24.0k|		}
  963|  24.0k|		memcpy(buf, nonce, nonce_len);
  964|  24.0k|		sendbuflen += nonce_len;
  965|  24.0k|		sendbuf =rsendbuf;
  966|  24.0k|	}
  967|       |
  968|  44.0k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  969|       |
  970|  44.0k|	apdu.lc = sendbuflen;
  971|  44.0k|	apdu.datalen = sendbuflen;
  972|  44.0k|	apdu.data = sendbuf;
  973|       |
  974|       |
  975|       |	/* coolkey uses non-standard classes */
  976|  44.0k|	apdu.cla = cla;
  977|       |
  978|  44.0k|	if (recvbuf) {
  ------------------
  |  Branch (978:6): [True: 33.8k, False: 10.1k]
  ------------------
  979|  33.8k|		apdu.resp = rbuf;
  980|  33.8k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (980:13): [True: 9.65k, False: 24.2k]
  ------------------
  981|  33.8k|		apdu.resplen = rbuflen;
  982|  33.8k|	} else {
  983|  10.1k|		 apdu.resp =  rbuf;
  984|  10.1k|		 apdu.le = 0;
  985|  10.1k|		 apdu.resplen = 0;
  986|  10.1k|	}
  987|       |
  988|  44.0k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  44.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  989|  44.0k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  990|       |
  991|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  992|  44.0k|	r = sc_transmit_apdu(card, &apdu);
  993|       |
  994|  44.0k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  44.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  995|  44.0k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  996|       |
  997|  44.0k|	if (r < 0) {
  ------------------
  |  Branch (997:6): [True: 908, False: 43.1k]
  ------------------
  998|    908|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    908|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  999|    908|		goto err;
 1000|    908|	}
 1001|  43.1k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1002|  43.1k|	if (r < 0) {
  ------------------
  |  Branch (1002:6): [True: 26.0k, False: 17.1k]
  ------------------
 1003|  26.0k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  26.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1004|  26.0k|		goto err;
 1005|  26.0k|	}
 1006|       |
 1007|  17.1k|	if (recvbuflen) {
  ------------------
  |  Branch (1007:6): [True: 14.6k, False: 2.45k]
  ------------------
 1008|  14.6k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1008:7): [True: 14.6k, False: 0]
  |  Branch (1008:18): [True: 0, False: 14.6k]
  ------------------
 1009|      0|			*recvbuf =  malloc(apdu.resplen);
 1010|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1010:8): [True: 0, False: 0]
  ------------------
 1011|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1012|      0|				goto err;
 1013|      0|			}
 1014|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1015|      0|		}
 1016|  14.6k|		*recvbuflen =  apdu.resplen;
 1017|  14.6k|		r = (int)*recvbuflen;
 1018|  14.6k|	}
 1019|       |
 1020|  44.0k|err:
 1021|  44.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  44.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  44.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  44.0k|	int _ret = r; \
  |  |  |  |  155|  44.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31.6k, False: 12.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  31.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  26.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26.9k, False: 4.72k]
  |  |  |  |  ------------------
  |  |  |  |  157|  31.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  31.6k|	} else { \
  |  |  |  |  159|  12.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  12.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  12.4k|	} \
  |  |  |  |  162|  44.0k|	return _ret; \
  |  |  |  |  163|  44.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1022|  44.0k|}
card-coolkey.c:coolkey_find_object_by_id:
  826|  10.5k|{
  827|  10.5k|	int pos;
  828|  10.5k|	static sc_cardctl_coolkey_object_t cmp = {{
  829|  10.5k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  10.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  830|  10.5k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  10.5k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  10.5k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  831|  10.5k|	}, 0, 0, NULL};
  832|       |
  833|  10.5k|	cmp.id = object_id;
  834|  10.5k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (834:6): [True: 5.48k, False: 5.09k]
  ------------------
  835|  5.48k|		return NULL;
  836|       |
  837|  5.09k|	return list_get_at(list, pos);
  838|  10.5k|}
card-coolkey.c:coolkey_find_attribute:
 1417|  59.3k|{
 1418|  59.3k|	u8 object_record_type;
 1419|  59.3k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1420|  59.3k|	const u8 *obj = attribute->object->data;
 1421|  59.3k|	const u8 *attr = NULL;
 1422|  59.3k|	size_t buf_len = attribute->object->length;
 1423|  59.3k|	coolkey_object_header_t *object_head;
 1424|  59.3k|	int attribute_count,i;
 1425|  59.3k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|  59.3k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1426|  59.3k|	attribute->attribute_length = 0;
 1427|  59.3k|	attribute->attribute_value = NULL;
 1428|       |
 1429|  59.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  59.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  59.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  59.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  59.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 59.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|       |
 1431|  59.3k|	if (obj == NULL) {
  ------------------
  |  Branch (1431:6): [True: 22.4k, False: 36.8k]
  ------------------
 1432|       |		/* cast away const so we can cache the data value */
 1433|  22.4k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1434|  22.4k|		if (r < 0) {
  ------------------
  |  Branch (1434:7): [True: 20.4k, False: 1.96k]
  ------------------
 1435|  20.4k|			return r;
 1436|  20.4k|		}
 1437|  1.96k|		obj = attribute->object->data;
 1438|  1.96k|		if (obj == NULL) {
  ------------------
  |  Branch (1438:7): [True: 0, False: 1.96k]
  ------------------
 1439|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1440|      0|		}
 1441|  1.96k|	}
 1442|       |
 1443|       |	/* should be a static assert so we catch this at compile time */
 1444|  59.3k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1445|       |	/* make sure we have enough of the object to read the record_type */
 1446|  38.8k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1446:6): [True: 227, False: 38.6k]
  ------------------
 1447|    227|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    227|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1448|    227|	}
 1449|  38.6k|	object_head = (coolkey_object_header_t *)obj;
 1450|  38.6k|	object_record_type = object_head->record_type;
 1451|       |	/* make sure it's a type we recognize */
 1452|  38.6k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  38.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  3.45k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1452:6): [True: 3.45k, False: 35.1k]
  |  Branch (1452:51): [True: 655, False: 2.79k]
  ------------------
 1453|    655|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    655|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1454|    655|	}
 1455|       |
 1456|       |	/*
 1457|       |	 * now loop through all the attributes in the list. first find the start of the list
 1458|       |	 */
 1459|  37.9k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1460|  37.9k|	if (attr == NULL) {
  ------------------
  |  Branch (1460:6): [True: 332, False: 37.6k]
  ------------------
 1461|    332|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    332|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1462|    332|	}
 1463|  37.6k|	buf_len -= (attr-obj);
 1464|       |
 1465|       |	/* now get the count */
 1466|  37.6k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1467|  48.4k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1467:12): [True: 13.3k, False: 35.0k]
  ------------------
 1468|  13.3k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1469|       |		/* make sure we have the complete record */
 1470|  13.3k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1470:7): [True: 0, False: 13.3k]
  |  Branch (1470:31): [True: 831, False: 12.5k]
  ------------------
 1471|    831|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    831|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1472|    831|		}
 1473|       |		/* does the attribute match the one we are looking for */
 1474|  12.5k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1474:7): [True: 1.70k, False: 10.8k]
  ------------------
 1475|       |			/* yup, return it */
 1476|  1.70k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1477|  1.70k|		}
 1478|       |		/* go to the next attribute on the list */
 1479|  10.8k|		buf_len -= record_len;
 1480|  10.8k|		attr += record_len;
 1481|  10.8k|	}
 1482|       |	/* not find in attribute list, check the fixed attribute record */
 1483|  35.0k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  35.0k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1483:6): [True: 33.2k, False: 1.82k]
  ------------------
 1484|  33.2k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1485|       |
 1486|  33.2k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1487|  33.2k|	}
 1488|  1.82k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  1.82k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.82k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.82k|	int _ret = r; \
  |  |  |  |  155|  1.82k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.82k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.82k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.82k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.82k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.82k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.82k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.82k|	return _ret; \
  |  |  |  |  163|  1.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1489|  1.82k|}
card-coolkey.c:coolkey_attribute_start:
  422|  40.4k|{
  423|  40.4k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  230|  40.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (423:18): [True: 35.1k, False: 5.32k]
  ------------------
  424|  40.4k|			sizeof(coolkey_v0_object_header_t);
  425|       |
  426|  40.4k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  40.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  5.32k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (426:6): [True: 5.32k, False: 35.1k]
  |  Branch (426:51): [True: 0, False: 5.32k]
  ------------------
  427|      0|		return NULL;
  428|      0|	}
  429|  40.4k|	if (offset > buf_len) {
  ------------------
  |  Branch (429:6): [True: 332, False: 40.1k]
  ------------------
  430|    332|		return NULL;
  431|    332|	}
  432|  40.1k|	return obj + offset;
  433|  40.4k|}
card-coolkey.c:coolkey_get_attribute_count:
  503|  37.6k|{
  504|  37.6k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  37.6k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (504:6): [True: 2.79k, False: 34.8k]
  ------------------
  505|  2.79k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  506|  2.79k|	}
  507|  34.8k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  34.8k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (507:6): [True: 0, False: 34.8k]
  ------------------
  508|      0|		return 0;
  509|      0|	}
  510|  34.8k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  511|  34.8k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  441|  2.79k|{
  442|  2.79k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  443|  2.79k|	const u8 *attr;
  444|  2.79k|	int count = 0;
  445|  2.79k|	size_t attribute_data_len;
  446|       |
  447|       |	/* make sure we have enough of the object to read the record_type */
  448|  2.79k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (448:6): [True: 274, False: 2.52k]
  ------------------
  449|    274|		return 0;
  450|    274|	}
  451|       |	/*
  452|       |	 * now loop through all the attributes in the list. first find the start of the list
  453|       |	 */
  454|  2.52k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|  2.52k|#define COOLKEY_V0_OBJECT 0
  ------------------
  455|  2.52k|	if (attr == NULL) {
  ------------------
  |  Branch (455:6): [True: 0, False: 2.52k]
  ------------------
  456|      0|		return 0;
  457|      0|	}
  458|       |
  459|  2.52k|	buf_len -= (attr-obj);
  460|  2.52k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  461|  2.52k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (461:6): [True: 410, False: 2.11k]
  ------------------
  462|    410|		return 0;
  463|    410|	}
  464|       |
  465|  4.95k|	while (attribute_data_len) {
  ------------------
  |  Branch (465:9): [True: 4.34k, False: 609]
  ------------------
  466|  4.34k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  467|       |
  468|  4.34k|		if (len == 0) {
  ------------------
  |  Branch (468:7): [True: 0, False: 4.34k]
  ------------------
  469|      0|			break;
  470|      0|		}
  471|       |		/*  This is an error in the token data, don't parse the last attribute */
  472|  4.34k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (472:7): [True: 1.50k, False: 2.83k]
  ------------------
  473|  1.50k|			break;
  474|  1.50k|		}
  475|       |		/* we know that coolkey_v0_get_attribute_record_len never
  476|       |		 * 	returns more than buf_len, so we can safely assert that.
  477|       |		 * 	If the assert is true, you can easily see that the loop
  478|       |		 * 	will eventually break with len == 0, even if attribute_data_len
  479|       |		 * 	was invalid */
  480|  2.83k|		if (len > buf_len)
  ------------------
  |  Branch (480:7): [True: 0, False: 2.83k]
  ------------------
  481|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  482|  2.83k|		count++;
  483|  2.83k|		attr += len;
  484|  2.83k|		buf_len -= len;
  485|  2.83k|		attribute_data_len -= len;
  486|  2.83k|	}
  487|  2.11k|	return count;
  488|  2.11k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  381|  7.05k|{
  382|  7.05k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  383|  7.05k|	size_t len;
  384|  7.05k|	int r;
  385|       |
  386|  7.05k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  387|  7.05k|	if (r < 0) {
  ------------------
  |  Branch (387:6): [True: 349, False: 6.71k]
  ------------------
  388|    349|		return buf_len; /* skip to the end, ignore the rest of the record */
  389|    349|	}
  390|  6.71k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  6.71k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.51k, False: 5.19k]
  |  |  ------------------
  ------------------
  391|  7.05k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  492|  34.8k|{
  493|  34.8k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  494|       |
  495|  34.8k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (495:6): [True: 32.0k, False: 2.80k]
  ------------------
  496|  32.0k|		return 0;
  497|  32.0k|	}
  498|  2.80k|	return bebytes2ushort(object_head->attribute_count);
  499|  34.8k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  395|  13.3k|{
  396|  13.3k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  13.3k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (396:6): [True: 2.71k, False: 10.6k]
  ------------------
  397|  2.71k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  398|  2.71k|	}
  399|  10.6k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  10.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (399:6): [True: 0, False: 10.6k]
  ------------------
  400|      0|		return buf_len; /* skip to the end */
  401|      0|	}
  402|  10.6k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  403|  10.6k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  365|   301k|{
  366|   301k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  367|   301k|	size_t len = 0;
  368|   301k|	int r;
  369|       |
  370|   301k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  371|   301k|	if (r < 0) {
  ------------------
  |  Branch (371:6): [True: 292k, False: 8.88k]
  ------------------
  372|   292k|		return buf_len; /* skip to the end, ignore the rest of the record */
  373|   292k|	}
  374|       |
  375|  8.88k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  8.88k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 631, False: 8.25k]
  |  |  ------------------
  ------------------
  376|   301k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  675|  33.2k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  676|  33.2k|	unsigned long cka_id = fixed_attributes & 0xf;
  677|  33.2k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  678|  33.2k|	unsigned long mask, bit;
  679|       |
  680|  33.2k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  33.2k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (680:6): [True: 3.44k, False: 29.8k]
  ------------------
  681|  3.44k|		attr_out->attribute_length = 1;
  682|  3.44k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  683|  3.44k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.44k|#define SC_SUCCESS				0
  ------------------
  684|  3.44k|	}
  685|  29.8k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  29.8k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (685:6): [True: 9.90k, False: 19.9k]
  ------------------
  686|  9.90k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|  9.90k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  687|  9.90k|		attr_out->attribute_length = 4;
  688|  9.90k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  689|  9.90k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.90k|#define SC_SUCCESS				0
  ------------------
  690|  9.90k|	}
  691|       |	/* If it matched, it must be one of the booleans */
  692|  19.9k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  693|  19.9k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  694|       |	/* attribute isn't in the list */
  695|  19.9k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (695:6): [True: 7.58k, False: 12.3k]
  ------------------
  696|  7.58k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  7.58k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  697|  7.58k|	}
  698|  12.3k|	attr_out->attribute_length = 1;
  699|  12.3k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (699:30): [True: 3.98k, False: 8.33k]
  ------------------
  700|  12.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  12.3k|#define SC_SUCCESS				0
  ------------------
  701|  19.9k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  621|  19.9k|{
  622|  19.9k|	switch(type) {
  623|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (623:2): [True: 0, False: 19.9k]
  ------------------
  624|  1.36k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  1.36k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (624:2): [True: 1.36k, False: 18.5k]
  ------------------
  625|  1.45k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  1.45k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (625:2): [True: 1.45k, False: 18.4k]
  ------------------
  626|    954|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|    954|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (626:2): [True: 954, False: 18.9k]
  ------------------
  627|    954|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|    954|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (627:2): [True: 954, False: 18.9k]
  ------------------
  628|    954|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|    954|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (628:2): [True: 954, False: 18.9k]
  ------------------
  629|    954|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|    954|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (629:2): [True: 954, False: 18.9k]
  ------------------
  630|    954|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|    954|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (630:2): [True: 954, False: 18.9k]
  ------------------
  631|    954|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|    954|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (631:2): [True: 954, False: 18.9k]
  ------------------
  632|    954|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|    954|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (632:2): [True: 954, False: 18.9k]
  ------------------
  633|    954|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|    954|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (633:2): [True: 954, False: 18.9k]
  ------------------
  634|    954|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|    954|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (634:2): [True: 954, False: 18.9k]
  ------------------
  635|    953|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|    953|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (635:2): [True: 953, False: 18.9k]
  ------------------
  636|    954|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|    954|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (636:2): [True: 954, False: 18.9k]
  ------------------
  637|    954|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|    954|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (637:2): [True: 954, False: 18.9k]
  ------------------
  638|    954|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|    954|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (638:2): [True: 954, False: 18.9k]
  ------------------
  639|    954|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|    954|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (639:2): [True: 954, False: 18.9k]
  ------------------
  640|  3.72k|	default: break;
  ------------------
  |  Branch (640:2): [True: 3.72k, False: 16.1k]
  ------------------
  641|  19.9k|	}
  642|  3.72k|	return 0; /* return no bits */
  643|  19.9k|}
card-coolkey.c:sc_get_driver:
 2442|  15.2k|{
 2443|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2444|       |
 2445|  15.2k|	coolkey_ops = *iso_drv->ops;
 2446|  15.2k|	coolkey_ops.match_card = coolkey_match_card;
 2447|  15.2k|	coolkey_ops.init = coolkey_init;
 2448|  15.2k|	coolkey_ops.finish = coolkey_finish;
 2449|       |
 2450|  15.2k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2451|  15.2k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2452|  15.2k|	coolkey_ops.read_binary = coolkey_read_binary;
 2453|  15.2k|	coolkey_ops.write_binary = coolkey_write_binary;
 2454|  15.2k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2455|  15.2k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2456|  15.2k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2457|  15.2k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2458|  15.2k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2459|  15.2k|	coolkey_ops.check_sw = coolkey_check_sw;
 2460|  15.2k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2461|  15.2k|	coolkey_ops.logout = coolkey_logout;
 2462|  15.2k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2463|       |
 2464|  15.2k|	return &coolkey_drv;
 2465|  15.2k|}
card-coolkey.c:coolkey_match_card:
 2281|  7.38k|{
 2282|  7.38k|	int r;
 2283|       |
 2284|  7.38k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.38k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.38k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.38k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.38k]
  |  |  ------------------
  ------------------
 2285|       |
 2286|  7.38k|	r = coolkey_select_applet(card);
 2287|  7.38k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.38k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2287:6): [True: 1.08k, False: 6.29k]
  ------------------
 2288|  1.08k|		sc_apdu_t apdu;
 2289|       |
 2290|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2291|       |		 * on Coolkey applet (reserved for GetMemory function),
 2292|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2293|       |		 */
 2294|  1.08k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.08k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   80|  1.08k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2295|  1.08k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   73|  1.08k|#define COOLKEY_CLASS           0xb0
  ------------------
 2296|  1.08k|		apdu.le = 0x00;
 2297|  1.08k|		apdu.resplen = 0;
 2298|  1.08k|		apdu.resp = NULL;
 2299|  1.08k|		r = sc_transmit_apdu(card, &apdu);
 2300|  1.08k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.17k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2300:7): [True: 1.08k, False: 1]
  |  Branch (2300:26): [True: 1.05k, False: 37]
  |  Branch (2300:46): [True: 1.04k, False: 7]
  ------------------
 2301|  1.04k|			return 1;
 2302|  1.04k|		}
 2303|     45|		return 0;
 2304|  1.08k|	}
 2305|  6.29k|	return 0;
 2306|  7.38k|}
card-coolkey.c:coolkey_select_applet:
 1071|  10.1k|{
 1072|  10.1k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1073|  10.1k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   72|  10.1k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   76|  10.1k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1074|  10.1k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1075|  10.1k|}
card-coolkey.c:coolkey_init:
 2310|  1.04k|{
 2311|  1.04k|	int r;
 2312|  1.04k|	unsigned long flags;
 2313|  1.04k|	unsigned long ext_flags;
 2314|  1.04k|	coolkey_private_data_t * priv;
 2315|       |
 2316|  1.04k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.04k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.04k]
  |  |  ------------------
  ------------------
 2317|       |
 2318|  1.04k|	r = coolkey_initialize(card);
 2319|  1.04k|	if (r < 0) {
  ------------------
  |  Branch (2319:6): [True: 440, False: 604]
  ------------------
 2320|    440|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    440|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    440|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    440|	int _ret = r; \
  |  |  |  |  155|    440|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 440, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    440|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    440|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 440, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    440|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    440|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    440|	return _ret; \
  |  |  |  |  163|    440|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2321|    440|	}
 2322|       |
 2323|    604|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2324|       |
 2325|       |	/* set Token Major/minor version */
 2326|    604|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    604|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2327|       |
 2328|    604|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2329|    604|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2330|    604|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2331|       |
 2332|    604|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    604|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    604|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    604|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    604|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2333|    604|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    604|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    604|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2334|       |
 2335|    604|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2336|    604|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2337|    604|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2338|       |
 2339|       |
 2340|    604|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    604|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2341|    604|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2341:6): [True: 401, False: 203]
  ------------------
 2342|    401|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    401|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2343|    401|	}
 2344|       |
 2345|    604|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    604|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    604|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    604|	int _ret = r; \
  |  |  |  |  155|    604|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 604, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    604|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 604]
  |  |  |  |  ------------------
  |  |  |  |  157|    604|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    604|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    604|	return _ret; \
  |  |  |  |  163|    604|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2346|    604|}
card-coolkey.c:coolkey_initialize:
 2150|  1.04k|{
 2151|  1.04k|	int r;
 2152|  1.04k|	coolkey_private_data_t *priv = NULL;
 2153|  1.04k|	coolkey_life_cycle_t life_cycle;
 2154|  1.04k|	coolkey_object_info_t object_info;
 2155|  1.04k|	int combined_processed = 0;
 2156|       |
 2157|       |	/* already found? */
 2158|  1.04k|	if (card->drv_data) {
  ------------------
  |  Branch (2158:6): [True: 0, False: 1.04k]
  ------------------
 2159|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2160|      0|	}
 2161|  1.04k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.04k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2162|       |
 2163|  1.04k|	priv = coolkey_new_private_data();
 2164|  1.04k|	if (priv == NULL) {
  ------------------
  |  Branch (2164:6): [True: 0, False: 1.04k]
  ------------------
 2165|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2166|      0|		goto cleanup;
 2167|      0|	}
 2168|  1.04k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2169|  1.04k|	if (r < 0) {
  ------------------
  |  Branch (2169:6): [True: 62, False: 982]
  ------------------
 2170|     62|		goto cleanup;
 2171|     62|	}
 2172|       |
 2173|       |	/* Select a coolkey read the coolkey objects out */
 2174|    982|	r = coolkey_select_applet(card);
 2175|    982|	if (r < 0) {
  ------------------
  |  Branch (2175:6): [True: 4, False: 978]
  ------------------
 2176|      4|		goto cleanup;
 2177|      4|	}
 2178|       |
 2179|    978|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2180|    978|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2181|    978|	priv->pin_count = life_cycle.pin_count;
 2182|    978|	priv->life_cycle = life_cycle.life_cycle;
 2183|       |
 2184|       |	/* walk down the list of objects and read them off the token */
 2185|    978|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  105|    978|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2186|  8.65k|	while (r >= 0) {
  ------------------
  |  Branch (2186:9): [True: 7.86k, False: 792]
  ------------------
 2187|  7.86k|		unsigned long object_id;
 2188|  7.86k|		unsigned long object_len;
 2189|       |
 2190|       |		/* The card did not return what we expected: Lets try other objects */
 2191|  7.86k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2191:7): [True: 10, False: 7.85k]
  ------------------
 2192|     10|			break;
 2193|       |
 2194|       |		/* TODO also look at the ACL... */
 2195|       |
 2196|  7.85k|		object_id = bebytes2ulong(object_info.object_id);
 2197|  7.85k|		object_len = bebytes2ulong(object_info.object_length);
 2198|       |		/* Avoid insanely large data */
 2199|  7.85k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  7.85k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2199:7): [True: 15, False: 7.83k]
  ------------------
 2200|     15|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     15|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2201|     15|			goto cleanup;
 2202|     15|		}
 2203|       |
 2204|       |		/* the combined object is a single object that can store the other objects.
 2205|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2206|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2207|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2208|       |		 * process it separately so that we can have both combined objects managed
 2209|       |		 * by TPS and user managed certs on the same token */
 2210|  7.83k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  110|  7.83k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2210:7): [True: 165, False: 7.67k]
  ------------------
 2211|    165|			u8 *object = malloc(object_len);
 2212|    165|			if (object == NULL) {
  ------------------
  |  Branch (2212:8): [True: 0, False: 165]
  ------------------
 2213|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2214|      0|				break;
 2215|      0|			}
 2216|    165|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  110|    165|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2217|    165|				priv->nonce, sizeof(priv->nonce));
 2218|    165|			if (r < 0) {
  ------------------
  |  Branch (2218:8): [True: 71, False: 94]
  ------------------
 2219|     71|				free(object);
 2220|     71|				break;
 2221|     71|			}
 2222|     94|			r = coolkey_process_combined_object(card, priv, object, r);
 2223|     94|			free(object);
 2224|     94|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     94|#define SC_SUCCESS				0
  ------------------
  |  Branch (2224:8): [True: 90, False: 4]
  ------------------
 2225|     90|				break;
 2226|     90|			}
 2227|      4|			combined_processed = 1;
 2228|  7.67k|		} else {
 2229|  7.67k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  7.67k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2230|  7.67k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2231|  7.67k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  7.67k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2231:8): [True: 2.88k, False: 4.79k]
  ------------------
 2232|  2.88k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  2.88k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2233|  7.67k|		}
 2234|       |
 2235|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2236|  7.67k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  106|  7.67k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2237|  7.67k|	}
 2238|    963|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    963|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2238:6): [True: 346, False: 617]
  ------------------
 2239|       |		/* This means the card does not cooperate at all: bail out */
 2240|    346|		if (r >= 0) {
  ------------------
  |  Branch (2240:7): [True: 10, False: 336]
  ------------------
 2241|     10|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     10|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2242|     10|		}
 2243|    346|		goto cleanup;
 2244|    346|	}
 2245|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2246|    617|	if (!combined_processed) {
  ------------------
  |  Branch (2246:6): [True: 615, False: 2]
  ------------------
 2247|    615|		global_platform_cplc_data_t cplc_data;
 2248|       |		/* select the card manager, because a card with applet only will have
 2249|       |		   already selected the coolkey applet */
 2250|       |
 2251|    615|		r = gp_select_card_manager(card);
 2252|    615|		if (r < 0) {
  ------------------
  |  Branch (2252:7): [True: 3, False: 612]
  ------------------
 2253|      3|			goto cleanup;
 2254|      3|		}
 2255|       |
 2256|    612|		r = gp_get_cplc_data(card, &cplc_data);
 2257|    612|		if (r < 0) {
  ------------------
  |  Branch (2257:7): [True: 10, False: 602]
  ------------------
 2258|     10|			goto cleanup;
 2259|     10|		}
 2260|    602|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2261|    602|		priv->token_name = (u8 *)strdup("COOLKEY");
 2262|    602|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2262:7): [True: 0, False: 602]
  ------------------
 2263|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2264|      0|			goto cleanup;
 2265|      0|		}
 2266|    602|		priv->token_name_length = sizeof("COOLKEY")-1;
 2267|    602|	}
 2268|    604|	card->drv_data = priv;
 2269|    604|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    604|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    604|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    604|	int _ret = r; \
  |  |  |  |  155|    604|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 604, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    604|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 604]
  |  |  |  |  ------------------
  |  |  |  |  157|    604|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    604|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    604|	return _ret; \
  |  |  |  |  163|    604|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2270|       |
 2271|    440|cleanup:
 2272|    440|	if (priv) {
  ------------------
  |  Branch (2272:6): [True: 440, False: 0]
  ------------------
 2273|    440|		coolkey_free_private_data(priv);
 2274|    440|	}
 2275|    440|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    440|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    440|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    440|	int _ret = r; \
  |  |  |  |  155|    440|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 440, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    440|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    440|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 440, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    440|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    440|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    440|	return _ret; \
  |  |  |  |  163|    440|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|    440|}
card-coolkey.c:coolkey_new_private_data:
  773|  1.04k|{
  774|  1.04k|	coolkey_private_data_t *priv;
  775|       |
  776|       |	/* allocate priv and zero all the fields */
  777|  1.04k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  778|  1.04k|	if (!priv)
  ------------------
  |  Branch (778:6): [True: 0, False: 1.04k]
  ------------------
  779|      0|		return NULL;
  780|       |
  781|       |	/* set other fields as appropriate */
  782|  1.04k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|  1.04k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  783|  1.04k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.04k]
  ------------------
  784|  1.04k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (784:6): [True: 0, False: 1.04k]
  ------------------
  785|  1.04k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (785:6): [True: 0, False: 1.04k]
  ------------------
  786|      0|		coolkey_free_private_data(priv);
  787|      0|		return NULL;
  788|      0|	}
  789|       |
  790|  1.04k|	return priv;
  791|  1.04k|}
card-coolkey.c:coolkey_get_life_cycle:
 1029|  1.04k|{
 1030|  1.04k|	coolkey_status_t status;
 1031|  1.04k|	u8 *receive_buf;
 1032|  1.04k|	size_t receive_len;
 1033|  1.04k|	int len;
 1034|       |
 1035|  1.04k|	receive_len = sizeof(*life_cycle);
 1036|  1.04k|	receive_buf = (u8 *)life_cycle;
 1037|  1.04k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|  1.04k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|  1.04k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1038|  1.04k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1039|  1.04k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1039:6): [True: 972, False: 72]
  ------------------
 1040|    972|		return SC_SUCCESS;
  ------------------
  |  |   28|    972|#define SC_SUCCESS				0
  ------------------
 1041|    972|	}
 1042|       |
 1043|     72|	receive_len = 1;
 1044|     72|	receive_buf = &life_cycle->life_cycle;
 1045|     72|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|     72|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|     72|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1046|     72|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1047|     72|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1047:6): [True: 49, False: 23]
  ------------------
 1048|     49|		return len;
 1049|     49|	}
 1050|     23|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1050:6): [True: 2, False: 21]
  ------------------
 1051|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1052|      2|	}
 1053|     21|	receive_len = sizeof(status);
 1054|     21|	receive_buf = (u8 *)&status;
 1055|     21|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   73|     21|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   80|     21|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1056|     21|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1057|     21|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1057:6): [True: 8, False: 13]
  ------------------
 1058|      8|		return len;
 1059|      8|	}
 1060|     13|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1060:6): [True: 3, False: 10]
  ------------------
 1061|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1062|      3|	}
 1063|     10|	life_cycle->protocol_version_major = status.protocol_version_major;
 1064|     10|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1065|     10|	life_cycle->pin_count = status.pin_count;
 1066|     10|	return SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 1067|     13|}
card-coolkey.c:coolkey_list_object:
 2137|  8.65k|{
 2138|  8.65k|	u8 *rbuf = (u8 *) object_info;
 2139|  8.65k|	size_t rbuflen = sizeof(*object_info);
 2140|       |
 2141|  8.65k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   73|  8.65k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   82|  8.65k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2142|  8.65k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2143|       |
 2144|  8.65k|}
card-coolkey.c:coolkey_process_combined_object:
 2001|     94|{
 2002|     94|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2003|     94|	unsigned short compressed_offset;
 2004|     94|	unsigned short compressed_length;
 2005|     94|	unsigned short compressed_type;
 2006|     94|	size_t object_offset;
 2007|     94|	unsigned short object_count;
 2008|     94|	coolkey_decompressed_header_t *decompressed_header;
 2009|     94|	u8 *decompressed_object = NULL;
 2010|     94|	size_t decompressed_object_len = 0;
 2011|     94|	int free_decompressed = 0;
 2012|     94|	int i, r;
 2013|       |
 2014|     94|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2014:6): [True: 2, False: 92]
  ------------------
 2015|      2|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      2|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2016|      2|	}
 2017|     92|	compressed_offset = bebytes2ushort(header->compression_offset);
 2018|     92|	compressed_length = bebytes2ushort(header->compression_length);
 2019|     92|	compressed_type   = bebytes2ushort(header->compression_type);
 2020|       |
 2021|     92|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2021:6): [True: 21, False: 71]
  ------------------
 2022|     21|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     21|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2023|     21|	}
 2024|       |
 2025|       |	/* store the CUID */
 2026|     71|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2027|       |
 2028|     71|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  181|     71|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2028:6): [True: 8, False: 63]
  ------------------
 2029|      8|#ifdef ENABLE_ZLIB
 2030|      8|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|      8|#define COMPRESSION_AUTO	0
  ------------------
 2031|      8|		if (r)
  ------------------
  |  Branch (2031:7): [True: 8, False: 0]
  ------------------
 2032|      8|			goto done;
 2033|      0|		free_decompressed = 1;
 2034|       |#else
 2035|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2036|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2037|       |#endif
 2038|     63|	}  else {
 2039|     63|		decompressed_object =&object[compressed_offset];
 2040|     63|		decompressed_object_len = (size_t) compressed_length;
 2041|     63|	}
 2042|       |
 2043|     63|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2044|       |
 2045|     63|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2045:6): [True: 9, False: 54]
  ------------------
 2046|      9|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      9|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2047|      9|		goto done;
 2048|      9|	}
 2049|     54|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2050|     54|	object_count = bebytes2ushort(decompressed_header->object_count);
 2051|       |
 2052|       |
 2053|       |	/*
 2054|       |	 * using 2 different tests here so we can log different errors if logging is
 2055|       |	 * turned on.
 2056|       |	 */
 2057|       |	/* make sure token_name doesn't overrun the buffer */
 2058|     54|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2058:6): [True: 0, False: 54]
  ------------------
 2059|     54|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2060|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2061|      0|		goto done;
 2062|      0|	}
 2063|       |	/* make sure it doesn't overlap the object space */
 2064|     54|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2064:6): [True: 7, False: 47]
  ------------------
 2065|     54|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2066|      7|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      7|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2067|      7|		goto done;
 2068|      7|	}
 2069|       |
 2070|       |	/* store the token name in the priv structure so the emulator can set it */
 2071|     47|	free(priv->token_name);
 2072|     47|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2073|     47|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2073:6): [True: 0, False: 47]
  ------------------
 2074|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2075|      0|		goto done;
 2076|      0|	}
 2077|     47|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2078|     47|							decompressed_header->token_name_length);
 2079|     47|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2080|     47|	priv->token_name_length = decompressed_header->token_name_length;
 2081|       |
 2082|     47|	if (object_count > decompressed_object_len / sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2082:6): [True: 18, False: 29]
  ------------------
 2083|     18|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     18|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2084|     18|		goto done;
 2085|     18|	}
 2086|       |
 2087|     77|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2087:12): [True: 73, False: 4]
  ------------------
 2088|     73|		u8 *current_object = NULL;
 2089|     73|		coolkey_combined_object_header_t *object_header = NULL;
 2090|     73|		unsigned long object_id;
 2091|     73|		int current_object_len;
 2092|       |
 2093|       |		/* Can we read the object header at all? */
 2094|     73|		if (decompressed_object_len < sizeof(coolkey_combined_object_header_t) ||
  ------------------
  |  Branch (2094:7): [True: 0, False: 73]
  ------------------
 2095|     73|		    object_offset > decompressed_object_len - sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2095:7): [True: 24, False: 49]
  ------------------
 2096|     24|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     24|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2097|     24|			goto done;
 2098|     24|		}
 2099|       |
 2100|     49|		current_object = &decompressed_object[object_offset];
 2101|     49|		object_header = (coolkey_combined_object_header_t *)current_object;
 2102|       |
 2103|       |		/* Parse object ID */
 2104|     49|		object_id = bebytes2ulong(object_header->object_id);
 2105|       |
 2106|       |		/* figure out how big it is */
 2107|     49|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2108|     49|		if (r < 0) {
  ------------------
  |  Branch (2108:7): [True: 0, False: 49]
  ------------------
 2109|      0|			goto done;
 2110|      0|		}
 2111|     49|		if ((size_t)r > decompressed_object_len - object_offset) {
  ------------------
  |  Branch (2111:7): [True: 0, False: 49]
  ------------------
 2112|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2113|      0|			goto done;
 2114|      0|		}
 2115|     49|		current_object_len = r;
 2116|     49|		object_offset += current_object_len;
 2117|       |
 2118|       |		/* record this object */
 2119|     49|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|     49|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2120|     49|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2121|     49|		if (r) {
  ------------------
  |  Branch (2121:7): [True: 1, False: 48]
  ------------------
 2122|      1|			goto done;
 2123|      1|		}
 2124|       |
 2125|     49|	}
 2126|      4|	r = SC_SUCCESS;
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|     71|done:
 2129|     71|	if (free_decompressed) {
  ------------------
  |  Branch (2129:6): [True: 0, False: 71]
  ------------------
 2130|      0|		free(decompressed_object);
 2131|      0|	}
 2132|     71|	return r;
 2133|      4|}
card-coolkey.c:coolkey_v1_get_object_length:
  707|     49|{
  708|     49|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  709|     49|	int attribute_count;
  710|     49|	u8 *current_attribute;
  711|     49|	int j;
  712|     49|	size_t len;
  713|       |
  714|     49|	len = sizeof(coolkey_combined_object_header_t);
  715|     49|	if (buf_len <= len) {
  ------------------
  |  Branch (715:6): [True: 1, False: 48]
  ------------------
  716|      1|		return (int)buf_len;
  717|      1|	}
  718|     48|	attribute_count = bebytes2ushort(object_head->attribute_count);
  719|     48|	buf_len -= len;
  720|       |
  721|   291k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (721:45): [True: 291k, False: 48]
  ------------------
  722|   291k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  723|       |
  724|   291k|		len += attribute_len;
  725|   291k|		current_attribute += attribute_len;
  726|   291k|		buf_len -= attribute_len;
  727|   291k|	}
  728|     48|	return (int)len;
  729|     49|}
card-coolkey.c:coolkey_add_object:
 1960|  7.72k|{
 1961|  7.72k|	sc_cardctl_coolkey_object_t new_object;
 1962|  7.72k|	int r;
 1963|       |
 1964|  7.72k|	memset(&new_object, 0, sizeof(new_object));
 1965|  7.72k|	new_object.path = coolkey_template_path;
 1966|  7.72k|	new_object.path.len = 4;
 1967|  7.72k|	ulong2bebytes(new_object.path.value, object_id);
 1968|  7.72k|	new_object.id = object_id;
 1969|  7.72k|	new_object.length = object_length;
 1970|       |
 1971|       |	/* The object ID needs to be unique */
 1972|  7.72k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1972:6): [True: 2.88k, False: 4.83k]
  ------------------
 1973|  2.88k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.88k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1974|  2.88k|	}
 1975|       |
 1976|  4.83k|	if (object_data) {
  ------------------
  |  Branch (1976:6): [True: 48, False: 4.79k]
  ------------------
 1977|     48|		new_object.data = malloc(object_length + add_v1_record);
 1978|     48|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1978:7): [True: 0, False: 48]
  ------------------
 1979|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1980|      0|		}
 1981|     48|		if (add_v1_record) {
  ------------------
  |  Branch (1981:7): [True: 48, False: 0]
  ------------------
 1982|     48|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  230|     48|#define COOLKEY_V1_OBJECT 1
  ------------------
 1983|     48|			new_object.length++;
 1984|     48|		}
 1985|     48|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1986|     48|	}
 1987|       |
 1988|  4.83k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 1989|  4.83k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  4.83k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1989:6): [True: 0, False: 4.83k]
  ------------------
 1990|       |		/* if we didn't successfully put the object on the list,
 1991|       |		 * the data space didn't get adopted. free it before we return */
 1992|      0|		free(new_object.data);
 1993|       |		new_object.data = NULL;
 1994|      0|	}
 1995|  4.83k|	return r;
 1996|  4.83k|}
card-coolkey.c:coolkey_add_object_to_list:
  817|  4.83k|{
  818|  4.83k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (818:6): [True: 0, False: 4.83k]
  ------------------
  819|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  820|  4.83k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.83k|#define SC_SUCCESS				0
  ------------------
  821|  4.83k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1079|    602|{
 1080|    602|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1081|    602|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1082|    602|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1083|    602|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1084|    602|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1085|    602|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1086|    602|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1087|    602|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1088|    602|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1089|    602|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1090|    602|}
card-coolkey.c:coolkey_free_private_data:
  794|  1.04k|{
  795|  1.04k|	list_t *l = &priv->objects_list;
  796|  1.04k|	sc_cardctl_coolkey_object_t *o;
  797|       |
  798|       |	/* Clean up the allocated memory in the items */
  799|  1.04k|	list_iterator_start(l);
  800|  5.88k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (800:9): [True: 4.83k, False: 1.04k]
  ------------------
  801|  4.83k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  802|  4.83k|		free(o->data);
  803|  4.83k|		o->data = NULL;
  804|  4.83k|	}
  805|  1.04k|	list_iterator_stop(l);
  806|       |
  807|  1.04k|	list_destroy(&priv->objects_list);
  808|  1.04k|	free(priv->token_name);
  809|  1.04k|	free(priv);
  810|  1.04k|	return;
  811|  1.04k|}
card-coolkey.c:coolkey_finish:
 1948|    604|{
 1949|    604|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    604|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1950|       |
 1951|    604|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    604|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    604|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    604|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 604]
  |  |  ------------------
  ------------------
 1952|    604|	if (priv) {
  ------------------
  |  Branch (1952:6): [True: 604, False: 0]
  ------------------
 1953|    604|		coolkey_free_private_data(priv);
 1954|    604|	}
 1955|    604|	return SC_SUCCESS;
  ------------------
  |  |   28|    604|#define SC_SUCCESS				0
  ------------------
 1956|    604|}
card-coolkey.c:coolkey_select_file:
 1901|  1.80k|{
 1902|  1.80k|	int r;
 1903|  1.80k|	struct sc_file *file = NULL;
 1904|  1.80k|	coolkey_private_data_t *priv;
 1905|  1.80k|	unsigned long object_id;
 1906|       |
 1907|  1.80k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1907:6): [True: 0, False: 1.80k]
  |  Branch (1907:22): [True: 0, False: 1.80k]
  ------------------
 1908|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1909|       |
 1910|  1.80k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.80k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.80k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.80k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.80k]
  |  |  ------------------
  ------------------
 1911|       |
 1912|  1.80k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  1.80k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1913|       |
 1914|  1.80k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1914:6): [True: 3, False: 1.80k]
  ------------------
 1915|      3|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      3|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1916|      3|	}
 1917|  1.80k|	r = coolkey_select_applet(card);
 1918|  1.80k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.80k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1918:6): [True: 1.41k, False: 385]
  ------------------
 1919|  1.41k|		return r;
 1920|  1.41k|	}
 1921|    385|	object_id = bebytes2ulong(in_path->value);
 1922|    385|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1923|    385|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1923:6): [True: 354, False: 31]
  ------------------
 1924|    354|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    354|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1925|    354|	}
 1926|       |
 1927|     31|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|     31|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1928|     31|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  112|     31|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1928:6): [True: 0, False: 31]
  ------------------
 1929|      0|		priv->key_id = coolkey_get_key_id(object_id);
 1930|      0|	}
 1931|     31|	if (file_out) {
  ------------------
  |  Branch (1931:6): [True: 30, False: 1]
  ------------------
 1932|     30|		file = sc_file_new();
 1933|     30|		if (file == NULL)
  ------------------
  |  Branch (1933:7): [True: 0, False: 30]
  ------------------
 1934|     30|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1935|     30|		file->path = *in_path;
 1936|       |		/* this could be like the FCI */
 1937|     30|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     30|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1938|     30|		file->shareable = 0;
 1939|     30|		file->ef_structure = 0;
 1940|     30|		file->size = priv->obj->length;
 1941|     30|		*file_out = file;
 1942|     30|	}
 1943|       |
 1944|     31|	return SC_SUCCESS;
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
 1945|     31|}
card-coolkey.c:coolkey_class:
 1874|     31|static u8 coolkey_class(unsigned long object_id) {
 1875|     31|	return (object_id >> 24) & 0xff;
 1876|     31|}
card-coolkey.c:coolkey_read_binary:
 1181|    117|{
 1182|    117|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    117|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1183|    117|	int r = 0;
 1184|    117|	size_t len;
 1185|    117|	u8 *data = NULL;
 1186|       |
 1187|    117|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    117|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    117|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    117|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 117]
  |  |  ------------------
  ------------------
 1188|    117|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1188:6): [True: 0, False: 117]
  ------------------
 1189|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_END_REACHED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      0|	}
 1191|       |
 1192|       |	/* if we've already read the data, just return it */
 1193|    117|	if (priv->obj->data) {
  ------------------
  |  Branch (1193:6): [True: 87, False: 30]
  ------------------
 1194|     87|		sc_log(card->ctx, "returning cached value idx=%u count=%zu", idx, count);
  ------------------
  |  |   71|     87|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1195|     87|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|     87|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 72, False: 15]
  |  |  ------------------
  ------------------
 1196|     87|		memcpy(buf, &priv->obj->data[idx], len);
 1197|     87|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|     87|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     87|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     87|	int _ret = r; \
  |  |  |  |  155|     87|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     87|	} else { \
  |  |  |  |  159|     87|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     87|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     87|	} \
  |  |  |  |  162|     87|	return _ret; \
  |  |  |  |  163|     87|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1198|     87|	}
 1199|       |
 1200|     30|	sc_log(card->ctx, "clearing cache idx=%u count=%zu", idx, count);
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1201|       |
 1202|     30|	data = malloc(priv->obj->length);
 1203|     30|	if (data == NULL) {
  ------------------
  |  Branch (1203:6): [True: 0, False: 30]
  ------------------
 1204|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1205|      0|		goto done;
 1206|      0|	}
 1207|       |
 1208|       |
 1209|     30|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1210|     30|		priv->nonce, sizeof(priv->nonce));
 1211|     30|	if (r < 0)
  ------------------
  |  Branch (1211:6): [True: 13, False: 17]
  ------------------
 1212|     13|		goto done;
 1213|       |
 1214|     17|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1214:6): [True: 0, False: 17]
  ------------------
 1215|      0|		priv->obj->length = r;
 1216|      0|	}
 1217|       |
 1218|       |
 1219|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1220|     17|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|     17|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 15, False: 2]
  |  |  ------------------
  ------------------
 1221|     17|	memcpy(buf, &data[idx], len);
 1222|     17|	r = (int)len;
 1223|       |	/* cache the data in the object */
 1224|     17|	priv->obj->data=data;
 1225|     17|	data = NULL;
 1226|       |
 1227|     30|done:
 1228|     30|	if (data)
  ------------------
  |  Branch (1228:6): [True: 13, False: 17]
  ------------------
 1229|     13|		free(data);
 1230|     30|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|     17|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     17|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     17|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1231|     30|}
card-coolkey.c:coolkey_card_ctl:
 1582|  43.8k|{
 1583|  43.8k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  43.8k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1584|       |
 1585|  43.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  43.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  43.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  43.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  43.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 43.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1586|  43.8k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  43.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1587|       |
 1588|  43.8k|	if (priv == NULL) {
  ------------------
  |  Branch (1588:6): [True: 0, False: 43.8k]
  ------------------
 1589|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1590|      0|	}
 1591|  43.8k|	switch(cmd) {
  ------------------
  |  Branch (1591:9): [True: 43.8k, False: 0]
  ------------------
 1592|      1|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1592:3): [True: 1, False: 43.8k]
  ------------------
 1593|      1|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1594|    603|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1594:3): [True: 603, False: 43.2k]
  ------------------
 1595|    603|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1596|  1.82k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1596:3): [True: 1.82k, False: 42.0k]
  ------------------
 1597|  1.82k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1598|    603|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1598:3): [True: 603, False: 43.2k]
  ------------------
 1599|    603|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1600|  4.11k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1600:3): [True: 4.11k, False: 39.7k]
  ------------------
 1601|  4.11k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1602|    603|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1602:3): [True: 603, False: 43.2k]
  ------------------
 1603|    603|			return coolkey_final_iterator(&priv->objects_list);
 1604|  36.1k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1604:3): [True: 36.1k, False: 7.75k]
  ------------------
 1605|  36.1k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1606|  43.8k|	}
 1607|       |
 1608|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1609|      0|}
card-coolkey.c:coolkey_get_serial_nr_from_CUID:
 1354|      1|{
 1355|      1|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|      1|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1356|       |
 1357|      1|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      1|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      1|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      1|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      1|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1358|      1|	memcpy(serial->value, &priv->cuid, sizeof(priv->cuid));
 1359|      1|	serial->len = sizeof(priv->cuid);
 1360|      1|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1361|      1|}
card-coolkey.c:coolkey_get_token_info:
 1327|    603|{
 1328|    603|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    603|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1329|    603|	char *label = NULL;
 1330|    603|	char *manufacturer_id = NULL;
 1331|    603|	char *serial_number = NULL;
 1332|       |
 1333|    603|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    603|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    603|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    603|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    603|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 603]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1334|    603|	label = strdup((char *)priv->token_name);
 1335|    603|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1336|    603|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1337|       |
 1338|    603|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1338:6): [True: 603, False: 0]
  |  Branch (1338:15): [True: 603, False: 0]
  |  Branch (1338:34): [True: 603, False: 0]
  ------------------
 1339|    603|		free(token_info->label);
 1340|    603|		token_info->label = label;
 1341|    603|		free(token_info->manufacturer_id);
 1342|    603|		token_info->manufacturer_id = manufacturer_id;
 1343|    603|		free(token_info->serial_number);
 1344|    603|		token_info->serial_number = serial_number;
 1345|    603|		return SC_SUCCESS;
  ------------------
  |  |   28|    603|#define SC_SUCCESS				0
  ------------------
 1346|    603|	}
 1347|      0|	free(label);
 1348|      0|	free(manufacturer_id);
 1349|      0|	free(serial_number);
 1350|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1351|    603|}
card-coolkey.c:coolkey_get_manufacturer:
 1298|    603|{
 1299|    603|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1300|    603|	int i;
 1301|    603|	char *buf;
 1302|    603|	const char *manufacturer_string = "%04x Unknown";
 1303|    603|	size_t len;
 1304|    603|	int r;
 1305|       |
 1306|  3.61k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1306:12): [True: 3.01k, False: 601]
  ------------------
 1307|  3.01k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1307:7): [True: 2, False: 3.00k]
  ------------------
 1308|      2|			manufacturer_string = manufacturer_list[i].string;
 1309|      2|			break;
 1310|      2|		}
 1311|  3.01k|	}
 1312|    603|	len = strlen(manufacturer_string)+1;
 1313|    603|	buf= malloc(len);
 1314|    603|	if (buf == NULL) {
  ------------------
  |  Branch (1314:6): [True: 0, False: 603]
  ------------------
 1315|      0|		return NULL;
 1316|      0|	}
 1317|    603|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1318|    603|	if (r < 0) {
  ------------------
  |  Branch (1318:6): [True: 0, False: 603]
  ------------------
 1319|      0|		free(buf);
 1320|      0|		return NULL;
 1321|      0|	}
 1322|    603|	return buf;
 1323|    603|}
card-coolkey.c:coolkey_cuid_to_string:
 1273|    603|{
 1274|    603|	char *buf;
 1275|    603|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1276|    603|	buf = malloc(len);
 1277|    603|	if (buf == NULL) {
  ------------------
  |  Branch (1277:6): [True: 0, False: 603]
  ------------------
 1278|      0|		return NULL;
 1279|      0|	}
 1280|    603|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1281|    603|	return buf;
 1282|    603|}
card-coolkey.c:coolkey_find_object:
 1553|  1.82k|{
 1554|  1.82k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1555|  1.82k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  1.82k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1556|  1.82k|	int r;
 1557|       |
 1558|  1.82k|	switch (fobj->type) {
 1559|    508|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1079|    508|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1559:2): [True: 508, False: 1.31k]
  ------------------
 1560|    508|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1561|    508|		break;
 1562|  1.31k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1080|  1.31k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1562:2): [True: 1.31k, False: 508]
  ------------------
 1563|  1.31k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1564|  1.31k|		break;
 1565|      0|	default:
  ------------------
  |  Branch (1565:2): [True: 0, False: 1.82k]
  ------------------
 1566|      0|		break;
 1567|  1.82k|	}
 1568|  1.82k|	if (obj == NULL) {
  ------------------
  |  Branch (1568:6): [True: 1.09k, False: 731]
  ------------------
 1569|  1.09k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  1.09k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1570|  1.09k|	}
 1571|    731|	if (obj->data == NULL) {
  ------------------
  |  Branch (1571:6): [True: 33, False: 698]
  ------------------
 1572|     33|		r = coolkey_fill_object(card, obj);
 1573|     33|		if (r < 0) {
  ------------------
  |  Branch (1573:7): [True: 24, False: 9]
  ------------------
 1574|     24|			return r;
 1575|     24|		}
 1576|     33|	}
 1577|    707|	fobj->obj = obj;
 1578|    707|	return SC_SUCCESS;
  ------------------
  |  |   28|    707|#define SC_SUCCESS				0
  ------------------
 1579|    731|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1246|    603|{
 1247|    603|	*countp = list_size(list);
 1248|    603|	list_iterator_start(list);
 1249|    603|	return SC_SUCCESS;
  ------------------
  |  |   28|    603|#define SC_SUCCESS				0
  ------------------
 1250|    603|}
card-coolkey.c:coolkey_fetch_object:
 1254|  4.11k|{
 1255|  4.11k|	sc_cardctl_coolkey_object_t *ptr;
 1256|  4.11k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1256:6): [True: 0, False: 4.11k]
  ------------------
 1257|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1258|      0|	}
 1259|       |
 1260|  4.11k|	ptr = list_iterator_next(list);
 1261|  4.11k|	*coolkey_obj = *ptr;
 1262|  4.11k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.11k|#define SC_SUCCESS				0
  ------------------
 1263|  4.11k|}
card-coolkey.c:coolkey_final_iterator:
 1267|    603|{
 1268|    603|	list_iterator_stop(list);
 1269|    603|	return SC_SUCCESS;
  ------------------
  |  |   28|    603|#define SC_SUCCESS				0
  ------------------
 1270|    603|}
card-coolkey.c:coolkey_check_sw:
  877|  45.2k|{
  878|  45.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  45.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  879|  45.2k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  880|       |
  881|  45.2k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (881:6): [True: 19.1k, False: 26.1k]
  |  Branch (881:21): [True: 18.5k, False: 557]
  ------------------
  882|  18.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  18.5k|#define SC_SUCCESS				0
  ------------------
  883|       |
  884|  26.6k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (884:6): [True: 118, False: 26.5k]
  ------------------
  885|    118|		if (sw2 == 0xff) {
  ------------------
  |  Branch (885:7): [True: 6, False: 112]
  ------------------
  886|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  887|      6|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      6|#define SC_ERROR_INTERNAL			-1400
  ------------------
  888|      6|		}
  889|    112|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (889:7): [True: 53, False: 59]
  ------------------
  890|     53|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     53|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  891|     53|		}
  892|     59|		return coolkey_error_codes[sw2].sc_error;
  893|    112|	}
  894|       |
  895|       |	/* iso error */
  896|  26.5k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  897|  26.6k|}
card-coolkey.c:coolkey_pin_cmd:
 2351|     10|{
 2352|     10|	int r;
 2353|     10|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|     10|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2354|     10|	size_t rbuflen;
 2355|     10|	u8 *rbuf;
 2356|       |
 2357|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2358|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2359|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2360|       |	 * maintain separate per application login states without the application
 2361|       |	 * having to cache the pin */
 2362|     10|	switch (data->cmd) {
 2363|      0|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2363:2): [True: 0, False: 10]
  ------------------
 2364|      0|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2364:7): [True: 0, False: 0]
  ------------------
 2365|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2366|      0|		} else {
 2367|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2368|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2369|       |			 * instead, coolkey slows down the login command exponentially
 2370|       |			 */
 2371|      0|			data->pin1.tries_left = 0xf;
 2372|      0|		}
 2373|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2374|      0|		break;
 2375|       |
 2376|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2376:2): [True: 0, False: 10]
  ------------------
 2377|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2377:2): [True: 0, False: 10]
  ------------------
 2378|       |		/* these 2 commands are currently reserved for TPS */
 2379|      0|	default:
  ------------------
  |  Branch (2379:2): [True: 0, False: 10]
  ------------------
 2380|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2381|      0|		break;
 2382|     10|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     10|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2382:2): [True: 10, False: 0]
  ------------------
 2383|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2384|       |		 * just support the one pin for now (we need an array of nonces to handle
 2385|       |		 * multiple pins) */
 2386|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2387|     10|		rbuflen = sizeof(priv->nonce);
 2388|     10|		rbuf = &priv->nonce[0];
 2389|     10|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   73|     10|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   81|     10|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2390|     10|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2391|     10|			&rbuf, &rbuflen, NULL, 0);
 2392|     10|		if (r < 0) {
  ------------------
  |  Branch (2392:7): [True: 8, False: 2]
  ------------------
 2393|      8|			break;
 2394|      8|		}
 2395|      2|		priv->nonce_valid = 1;
 2396|      2|		r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 2397|     10|	}
 2398|     10|	return r;
 2399|     10|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2420|  22.4k|{
 2421|  22.4k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  22.4k|#define SC_SUCCESS				0
  ------------------
 2422|       |
 2423|  22.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  22.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  22.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  22.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 22.4k]
  |  |  ------------------
  ------------------
 2424|       |
 2425|  22.4k|	if (was_reset > 0) {
  ------------------
  |  Branch (2425:6): [True: 0, False: 22.4k]
  ------------------
 2426|      0|		r = coolkey_select_applet(card);
 2427|      0|	}
 2428|       |
 2429|  22.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  22.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.4k|	int _ret = r; \
  |  |  |  |  155|  22.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.4k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 22.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.4k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  22.4k|	return _ret; \
  |  |  |  |  163|  22.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2430|  22.4k|}

sc_get_default_driver:
   67|  15.2k|{
   68|  15.2k|	return sc_get_driver();
   69|  15.2k|}
card-default.c:sc_get_driver:
   56|  15.2k|{
   57|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
   58|       |
   59|  15.2k|	default_ops = *iso_drv->ops;
   60|  15.2k|	default_ops.match_card = default_match_card;
   61|  15.2k|	default_ops.init = default_init;
   62|       |
   63|  15.2k|	return &default_drv;
   64|  15.2k|}

dnie_match_card:
  738|  18.3k|{
  739|  18.3k|	int result = 0;
  740|  18.3k|	int matched = -1;
  741|  18.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  18.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  18.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  18.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  18.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|  18.3k|	matched = _sc_match_atr(card, dnie_atrs, &card->type);
  743|  18.3k|	result = (matched >= 0) ? 1 : 0;
  ------------------
  |  Branch (743:11): [True: 1.64k, False: 16.6k]
  ------------------
  744|  18.3k|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|  18.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.3k|	int _ret = r; \
  |  |  |  |  155|  18.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.6k, False: 1.64k]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 16.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.6k|	} else { \
  |  |  |  |  159|  1.64k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.64k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.64k|	} \
  |  |  |  |  162|  18.3k|	return _ret; \
  |  |  |  |  163|  18.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  745|  18.3k|}
sc_get_dnie_driver:
 2301|  15.2k|{
 2302|  15.2k|	return get_dnie_driver();
 2303|  15.2k|}
card-dnie.c:get_dnie_driver:
 2238|  15.2k|{
 2239|  15.2k|	sc_card_driver_t *iso_drv = sc_get_iso7816_driver();
 2240|       |
 2241|       |	/* memcpy() from standard iso7816 declared operations */
 2242|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2242:6): [True: 1, False: 15.2k]
  ------------------
 2243|      1|		iso_ops = iso_drv->ops;
 2244|  15.2k|	dnie_ops = *iso_drv->ops;
 2245|       |
 2246|       |	/* fill card specific function pointers */
 2247|       |	/* NULL means that function is not supported neither by DNIe nor iso7816.c */
 2248|       |	/* if pointer is omitted, default ISO7816 function will be used */
 2249|       |
 2250|       |	/* initialization */
 2251|  15.2k|	dnie_ops.match_card	= dnie_match_card;
 2252|  15.2k|	dnie_ops.init		= dnie_init;
 2253|  15.2k|	dnie_ops.finish		= dnie_finish;
 2254|       |
 2255|       |	/* iso7816-4 functions */
 2256|  15.2k|	dnie_ops.read_binary	= dnie_read_binary;
 2257|  15.2k|	dnie_ops.write_binary	= NULL;
 2258|  15.2k|	dnie_ops.update_binary	= NULL;
 2259|  15.2k|	dnie_ops.erase_binary	= NULL;
 2260|  15.2k|	dnie_ops.read_record	= NULL;
 2261|  15.2k|	dnie_ops.write_record	= NULL;
 2262|  15.2k|	dnie_ops.append_record	= NULL;
 2263|  15.2k|	dnie_ops.update_record	= NULL;
 2264|  15.2k|	dnie_ops.select_file	= dnie_select_file;
 2265|  15.2k|	dnie_ops.get_challenge	= dnie_get_challenge;
 2266|       |
 2267|       |	/* iso7816-8 functions */
 2268|  15.2k|	dnie_ops.verify		= NULL;
 2269|  15.2k|	dnie_ops.logout		= dnie_logout;
 2270|       |	/* dnie_ops.restore_security_env */
 2271|  15.2k|	dnie_ops.set_security_env = dnie_set_security_env;
 2272|  15.2k|	dnie_ops.decipher	= dnie_decipher;
 2273|  15.2k|	dnie_ops.compute_signature = dnie_compute_signature;
 2274|  15.2k|	dnie_ops.change_reference_data = NULL;
 2275|  15.2k|	dnie_ops.reset_retry_counter = NULL;
 2276|       |
 2277|       |	/* iso7816-9 functions */
 2278|  15.2k|	dnie_ops.create_file	= NULL;
 2279|  15.2k|	dnie_ops.delete_file	= NULL;
 2280|  15.2k|	dnie_ops.list_files	= dnie_list_files;
 2281|  15.2k|	dnie_ops.check_sw	= dnie_check_sw;
 2282|  15.2k|	dnie_ops.card_ctl	= dnie_card_ctl;
 2283|  15.2k|	dnie_ops.process_fci	= dnie_process_fci;
 2284|       |	/* dnie_ops.construct_fci */
 2285|  15.2k|	dnie_ops.pin_cmd	= dnie_pin_cmd;
 2286|  15.2k|	dnie_ops.get_data	= NULL;
 2287|  15.2k|	dnie_ops.put_data	= NULL;
 2288|  15.2k|	dnie_ops.delete_record	= NULL;
 2289|       |
 2290|  15.2k|	return &dnie_driver;
 2291|  15.2k|}
card-dnie.c:dnie_init:
  829|    576|{
  830|    576|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    576|#define SC_SUCCESS				0
  ------------------
  831|    576|	sc_context_t *ctx = card->ctx;
  832|    576|	cwa_provider_t *provider = NULL;
  833|       |
  834|    576|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    576|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    576|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    576|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    576|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 576]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|       |
  836|       |	/* if recognized as terminated DNIe card, return error */
  837|    576|	if (card->type == SC_CARD_TYPE_DNIE_TERMINATED)
  ------------------
  |  Branch (837:6): [True: 7, False: 569]
  ------------------
  838|    576|	    LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "DNIe card is terminated.");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|       |	/* create and initialize cwa-dnie provider*/
  841|    569|	provider = dnie_get_cwa_provider(card);
  842|    569|	if (!provider)
  ------------------
  |  Branch (842:6): [True: 0, False: 569]
  ------------------
  843|    569|	    LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "Error initializing cwa-dnie provider");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|       |
  845|       |	/** Secure messaging initialization section **/
  846|    569|	memset(&(card->sm_ctx), 0, sizeof(sm_context_t));
  847|    569|	card->sm_ctx.ops.get_sm_apdu = dnie_sm_get_wrapped_apdu;
  848|    569|	card->sm_ctx.ops.free_sm_apdu = dnie_sm_free_wrapped_apdu;
  849|    569|	card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    569|#define SM_MODE_NONE		0x0
  ------------------
  850|       |
  851|    569|	res = cwa_create_secure_channel(card, provider, CWA_SM_OFF);
  ------------------
  |  |   31|    569|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  852|    569|	if (res < 0)
  ------------------
  |  Branch (852:6): [True: 33, False: 536]
  ------------------
  853|     33|		free(provider);
  854|    569|	LOG_TEST_RET(card->ctx, res, "Failure resetting CWA secure channel.");
  ------------------
  |  |  174|    569|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    569|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    569|	int _ret = (r); \
  |  |  |  |  168|    569|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 536]
  |  |  |  |  ------------------
  |  |  |  |  169|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     33|		return _ret; \
  |  |  |  |  172|     33|	} \
  |  |  |  |  173|    569|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 536]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  855|       |
  856|       |	/* initialize private data */
  857|    536|	card->drv_data = calloc(1, sizeof(dnie_private_data_t));
  858|    536|	if (card->drv_data == NULL) {
  ------------------
  |  Branch (858:6): [True: 0, False: 536]
  ------------------
  859|      0|		free(provider);
  860|      0|	    LOG_TEST_RET(card->ctx, SC_ERROR_OUT_OF_MEMORY, "Could not allocate DNIe private data.");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  861|      0|	}
  862|       |
  863|       |#ifdef ENABLE_DNIE_UI
  864|       |	/* read environment from configuration file */
  865|       |	res = dnie_get_environment(card, &(GET_DNIE_UI_CTX(card)));
  866|       |	if (res != SC_SUCCESS) {
  867|       |		free(card->drv_data);
  868|       |		free(provider);
  869|       |		LOG_TEST_RET(card->ctx, res, "Failure reading DNIe environment.");
  870|       |	}
  871|       |#endif
  872|       |
  873|    536|	init_flags(card);
  874|       |
  875|    536|	GET_DNIE_PRIV_DATA(card)->cwa_provider = provider;
  ------------------
  |  |   97|    536|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  876|       |
  877|    536|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|    536|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    536|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    536|	int _ret = r; \
  |  |  |  |  155|    536|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 536, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    536|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 536]
  |  |  |  |  ------------------
  |  |  |  |  157|    536|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    536|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    536|	return _ret; \
  |  |  |  |  163|    536|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    536|}
card-dnie.c:init_flags:
  705|    536|{
  706|    536|	unsigned long algoflags;
  707|       |	/* set up flags according documentation */
  708|    536|	card->name = DNIE_CHIP_SHORTNAME;
  ------------------
  |  |   68|    536|#define DNIE_CHIP_SHORTNAME "dnie"
  ------------------
  709|    536|	card->cla = 0x00;	/* default APDU class (interindustry) */
  710|    536|	card->caps |= SC_CARD_CAP_RNG;	/* we have a random number generator */
  ------------------
  |  |  550|    536|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  711|    536|	card->max_send_size = (255 - 12);	/* manual says 255, but we need 12 extra bytes when encoding */
  712|    536|	card->max_recv_size = 255;
  713|       |
  714|       |	/* RSA Support with PKCS1.5 padding */
  715|    536|	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  133|    536|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    536|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    536|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    536|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  716|    536|	_sc_card_add_rsa_alg(card, 1024, algoflags, 0);
  717|    536|	_sc_card_add_rsa_alg(card, 1920, algoflags, 0);
  718|    536|	_sc_card_add_rsa_alg(card, 2048, algoflags, 0);
  719|    536|}
card-dnie.c:dnie_finish:
  890|    536|{
  891|    536|	int result = SC_SUCCESS;
  ------------------
  |  |   28|    536|#define SC_SUCCESS				0
  ------------------
  892|    536|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    536|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    536|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    536|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    536|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 536]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  893|    536|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|    536|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  894|       |	/* disable sm channel if established */
  895|    536|	result = cwa_create_secure_channel(card, GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_OFF);
  ------------------
  |  |   97|    536|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
              	result = cwa_create_secure_channel(card, GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_OFF);
  ------------------
  |  |   31|    536|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  896|    536|	free(GET_DNIE_PRIV_DATA(card)->cwa_provider);
  ------------------
  |  |   97|    536|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  897|    536|	free(card->drv_data);
  898|    536|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|    536|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    536|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    536|	int _ret = r; \
  |  |  |  |  155|    536|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 536, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    536|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    528|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 528, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  157|    536|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    536|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    536|	return _ret; \
  |  |  |  |  163|    536|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  899|    536|}
card-dnie.c:dnie_clear_cache:
  689|  3.20k|{
  690|  3.20k|	if (data == NULL) return;
  ------------------
  |  Branch (690:6): [True: 520, False: 2.68k]
  ------------------
  691|  2.68k|	if (data->cache != NULL)
  ------------------
  |  Branch (691:6): [True: 294, False: 2.39k]
  ------------------
  692|    294|		free(data->cache);
  693|       |	data->cache = NULL;
  694|  2.68k|	data->cachelen = 0;
  695|  2.68k|}
card-dnie.c:dnie_read_binary:
 1091|  2.55k|{
 1092|  2.55k|	size_t res = 0;
 1093|  2.55k|	int rc;
 1094|  2.55k|	sc_context_t *ctx = NULL;
 1095|       |	/* preliminary checks */
 1096|  2.55k|	if (!card || !card->ctx || !buf || (count <= 0))
  ------------------
  |  Branch (1096:6): [True: 0, False: 2.55k]
  |  Branch (1096:15): [True: 0, False: 2.55k]
  |  Branch (1096:29): [True: 0, False: 2.55k]
  |  Branch (1096:37): [True: 0, False: 2.55k]
  ------------------
 1097|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1098|  2.55k|	ctx = card->ctx;
 1099|       |
 1100|  2.55k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.55k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.55k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.55k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|  2.55k|	if (idx == 0 || GET_DNIE_PRIV_DATA(card)->cache == NULL) {
  ------------------
  |  |   97|  2.19k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1101:6): [True: 353, False: 2.19k]
  |  Branch (1101:18): [True: 357, False: 1.84k]
  ------------------
 1102|       |		/* on first block or no cache, try to fill */
 1103|    710|		rc = dnie_fill_cache(card, flags);
 1104|    710|		if (rc < 0) {
  ------------------
  |  Branch (1104:7): [True: 409, False: 301]
  ------------------
 1105|    409|			sc_log(ctx, "Cannot fill cache. using iso_read_binary()");
  ------------------
  |  |   71|    409|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1106|    409|			return iso_ops->read_binary(card, idx, buf, count, flags);
 1107|    409|		}
 1108|    710|	}
 1109|  2.14k|	if (idx >= GET_DNIE_PRIV_DATA(card)->cachelen)
  ------------------
  |  |   97|  2.14k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1109:6): [True: 248, False: 1.89k]
  ------------------
 1110|    248|		return 0;	/* at eof */
 1111|  1.89k|	res = MIN(count, GET_DNIE_PRIV_DATA(card)->cachelen - idx);	/* eval how many bytes to read */
  ------------------
  |  |   69|  1.89k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.67k, False: 222]
  |  |  ------------------
  ------------------
 1112|  1.89k|	memcpy(buf, GET_DNIE_PRIV_DATA(card)->cache + idx, res);	/* copy data from buffer */
  ------------------
  |  |   97|  1.89k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1113|  1.89k|	sc_log(ctx, "dnie_read_binary() '%zu' bytes", res);
  ------------------
  |  |   71|  1.89k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1114|  1.89k|	LOG_FUNC_RETURN(ctx, (int)res);
  ------------------
  |  |  164|  1.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.89k|	int _ret = r; \
  |  |  |  |  155|  1.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.89k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.89k|	} else { \
  |  |  |  |  159|  1.89k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.89k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.89k|	} \
  |  |  |  |  162|  1.89k|	return _ret; \
  |  |  |  |  163|  1.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|  1.89k|}
card-dnie.c:dnie_fill_cache:
  966|    710|{
  967|    710|	u8 tmp[MAX_RESP_BUFFER_SIZE];
  968|    710|	sc_apdu_t apdu;
  969|    710|	size_t count = 0;
  970|    710|	size_t len = 0;
  971|    710|	u8 *buffer = NULL;
  972|    710|	u8 *p;
  973|    710|	sc_context_t *ctx = NULL;
  974|       |
  975|    710|	if (!card || !card->ctx)
  ------------------
  |  Branch (975:6): [True: 0, False: 710]
  |  Branch (975:15): [True: 0, False: 710]
  ------------------
  976|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  977|    710|	ctx = card->ctx;
  978|       |
  979|    710|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    710|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    710|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    710|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    710|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 710]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  980|       |
  981|       |	/* mark cache empty */
  982|    710|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|    710|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  983|       |
  984|       |	/* initialize apdu */
  985|    710|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00);
  ------------------
  |  |  292|    710|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  986|       |
  987|       |	/* try to read_binary while data available but never long than 32767 */
  988|    710|	count = card->max_recv_size;
  989|  2.35k|	for (len = 0; len < 0x7fff;) {
  ------------------
  |  Branch (989:16): [True: 2.35k, False: 1]
  ------------------
  990|  2.35k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.35k|#define SC_SUCCESS				0
  ------------------
  991|       |		/* fill apdu */
  992|  2.35k|		apdu.p1 = 0xff & (len >> 8);
  993|  2.35k|		apdu.p2 = 0xff & len;
  994|  2.35k|		apdu.le = count;
  995|  2.35k|		apdu.resplen = MAX_RESP_BUFFER_SIZE;
  ------------------
  |  |   56|  2.35k|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
  996|  2.35k|		apdu.resp = tmp;
  997|       |		/* transmit apdu */
  998|  2.35k|		r = sc_transmit_apdu(card, &apdu);
  999|  2.35k|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.35k|#define SC_SUCCESS				0
  ------------------
  |  Branch (999:7): [True: 273, False: 2.07k]
  ------------------
 1000|    273|			free(buffer);
 1001|    273|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1001:8): [True: 0, False: 273]
  ------------------
 1002|      0|				free(apdu.resp);
 1003|    273|			sc_log(ctx, "read_binary() APDU transmit failed");
  ------------------
  |  |   71|    273|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1004|    273|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    273|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    273|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    273|	int _ret = r; \
  |  |  |  |  155|    273|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 273, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    273|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    273|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 273, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    273|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    273|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    273|	return _ret; \
  |  |  |  |  163|    273|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1005|    273|		}
 1006|  2.07k|		if (apdu.resplen == 0) {
  ------------------
  |  Branch (1006:7): [True: 211, False: 1.86k]
  ------------------
 1007|       |			/* on no data received, check if requested len is longer than
 1008|       |			   available data in card. If so, ask just for remaining data */
 1009|    211|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1010|    211|			if (r == SC_ERROR_WRONG_LENGTH) {
  ------------------
  |  |   56|    211|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (1010:8): [True: 69, False: 142]
  ------------------
 1011|     69|				count = 0xff & apdu.sw2;
 1012|     69|				if (count != 0) {
  ------------------
  |  Branch (1012:9): [True: 67, False: 2]
  ------------------
 1013|     67|					if (apdu.resp != tmp)
  ------------------
  |  Branch (1013:10): [True: 0, False: 67]
  ------------------
 1014|      0|						free(apdu.resp);
 1015|     67|					continue;	/* read again with correct size */
 1016|     67|				}
 1017|      2|				goto read_done;	/* no more data to read */
 1018|     69|			}
 1019|    142|			if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    142|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1019:8): [True: 4, False: 138]
  ------------------
 1020|      4|				goto read_done;
 1021|    138|			free(buffer);
 1022|    138|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1022:8): [True: 0, False: 138]
  ------------------
 1023|      0|				free(apdu.resp);
 1024|    138|			LOG_FUNC_RETURN(ctx, r);	/* arriving here means response error */
  ------------------
  |  |  164|    138|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    138|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    138|	int _ret = r; \
  |  |  |  |  155|    138|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 138, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    138|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    136|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 136, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|    138|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    138|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    138|	return _ret; \
  |  |  |  |  163|    138|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|    138|		}
 1026|       |		/* copy received data into buffer. realloc() if not enough space */
 1027|  1.86k|		count = apdu.resplen;
 1028|  1.86k|		p = realloc(buffer, len + count);
 1029|  1.86k|		if (!p) {
  ------------------
  |  Branch (1029:7): [True: 0, False: 1.86k]
  ------------------
 1030|      0|			free(buffer);
 1031|      0|			free((void *)apdu.data);
 1032|      0|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1032:8): [True: 0, False: 0]
  ------------------
 1033|      0|				free(apdu.resp);
 1034|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1035|      0|		}
 1036|  1.86k|		buffer = p;
 1037|  1.86k|		memcpy(buffer + len, apdu.resp, count);
 1038|  1.86k|		if (apdu.resp != tmp) {
  ------------------
  |  Branch (1038:7): [True: 0, False: 1.86k]
  ------------------
 1039|      0|			free(apdu.resp);
 1040|      0|			apdu.resp = tmp;
 1041|      0|		}
 1042|  1.86k|		len += count;
 1043|  1.86k|		if (count != card->max_recv_size)
  ------------------
  |  Branch (1043:7): [True: 292, False: 1.57k]
  ------------------
 1044|    292|			goto read_done;
 1045|  1.86k|	}
 1046|       |
 1047|    299| read_done:
 1048|    299| 	free((void *)apdu.data);
 1049|    299|	if (apdu.resp != tmp)
  ------------------
  |  Branch (1049:6): [True: 0, False: 299]
  ------------------
 1050|      0|		free(apdu.resp);
 1051|       |
 1052|    299|	if (dnie_is_compressed(card, buffer, len)) {
  ------------------
  |  Branch (1052:6): [True: 19, False: 280]
  ------------------
 1053|     19|		if (flags)
  ------------------
  |  Branch (1053:7): [True: 0, False: 19]
  ------------------
 1054|      0|			*flags |= SC_FILE_FLAG_COMPRESSED_ZLIB;
  ------------------
  |  |  231|      0|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
 1055|       |		/* Remove first 8 bytes with compression info*/
 1056|     19|		len -= 8;
 1057|     19|		p = malloc(len);
 1058|     19|		if (!p) {
  ------------------
  |  Branch (1058:7): [True: 0, False: 19]
  ------------------
 1059|      0|			free(buffer);
 1060|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1061|      0|		}
 1062|     19|		memcpy(p, buffer + 8, len);
 1063|     19|		free(buffer);
 1064|     19|		buffer = p;
 1065|     19|	}
 1066|       |
 1067|       |
 1068|       |	/* ok: as final step, set correct cache data into dnie_priv structures */
 1069|    299|	GET_DNIE_PRIV_DATA(card)->cache = buffer;
  ------------------
  |  |   97|    299|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1070|    299|	GET_DNIE_PRIV_DATA(card)->cachelen = len;
  ------------------
  |  |   97|    299|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1071|    299|	sc_log(ctx, "fill_cache() done. length '%zu' bytes", len);
  ------------------
  |  |   71|    299|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1072|    299|	LOG_FUNC_RETURN(ctx, (int)len);
  ------------------
  |  |  164|    299|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    299|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    299|	int _ret = r; \
  |  |  |  |  155|    299|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    279|	} else { \
  |  |  |  |  159|    279|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    279|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    279|	} \
  |  |  |  |  162|    299|	return _ret; \
  |  |  |  |  163|    299|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1073|    299|}
card-dnie.c:dnie_is_compressed:
  913|    299|{
  914|    299|#ifdef ENABLE_ZLIB
  915|    299|	size_t uncompressed = 0L;
  916|    299|	size_t compressed = 0L;
  917|       |
  918|    299|	if (!card || !card->ctx || !from || !len)
  ------------------
  |  Branch (918:6): [True: 0, False: 299]
  |  Branch (918:15): [True: 0, False: 299]
  |  Branch (918:29): [True: 5, False: 294]
  |  Branch (918:38): [True: 0, False: 294]
  ------------------
  919|      5|		return 0;
  920|    294|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    294|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    294|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    294|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    294|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 294]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  921|       |
  922|       |	/* if data size not enough for compression header assume uncompressed */
  923|    294|	if (len < 8)
  ------------------
  |  Branch (923:6): [True: 18, False: 276]
  ------------------
  924|     18|		goto compress_exit;
  925|       |	/* evaluate compressed an uncompressed sizes (little endian format) */
  926|    276|	uncompressed = lebytes2ulong(from);
  927|    276|	compressed = lebytes2ulong(from + 4);
  928|       |	/* if compressed size doesn't match data length assume not compressed */
  929|    276|	if (compressed != len - 8)
  ------------------
  |  Branch (929:6): [True: 227, False: 49]
  ------------------
  930|    227|		goto compress_exit;
  931|       |	/* if compressed size greater than uncompressed, assume uncompressed data */
  932|     49|	if (uncompressed < compressed)
  ------------------
  |  Branch (932:6): [True: 1, False: 48]
  ------------------
  933|      1|		goto compress_exit;
  934|       |	/* Do not try to allocate insane size if we receive bogus data */
  935|     48|	if (uncompressed > MAX_FILE_SIZE)
  ------------------
  |  |  220|     48|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (935:6): [True: 29, False: 19]
  ------------------
  936|     29|		goto compress_exit;
  937|       |
  938|     19|	sc_log(card->ctx, "Data seems to be compressed.");
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  939|     19|	return 1;
  940|    275|compress_exit:
  941|    275|#endif
  942|       |
  943|    275|	sc_log(card->ctx, "Data not compressed.");
  ------------------
  |  |   71|    275|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  944|    275|	return 0;
  945|     48|}
card-dnie.c:dnie_select_file:
 1215|  4.29k|{
 1216|  4.29k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  4.29k|#define SC_SUCCESS				0
  ------------------
 1217|  4.29k|	sc_context_t *ctx = NULL;
 1218|  4.29k|	unsigned char tmp_path[sizeof(DNIE_MF_NAME)];
 1219|  4.29k|	size_t reminder = 0;
 1220|       |
 1221|  4.29k|	if (!card || !card->ctx || !in_path)
  ------------------
  |  Branch (1221:6): [True: 0, False: 4.29k]
  |  Branch (1221:15): [True: 0, False: 4.29k]
  |  Branch (1221:29): [True: 0, False: 4.29k]
  ------------------
 1222|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1223|  4.29k|	ctx = card->ctx;
 1224|       |
 1225|  4.29k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.29k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.29k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1226|       |
 1227|  4.29k|	switch (in_path->type) {
 1228|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1228:2): [True: 0, False: 4.29k]
  ------------------
 1229|       |		/* pathlen must be of len=2 */
 1230|       |		/*
 1231|       |		 * gscriptor shows that DNIe also handles
 1232|       |		 * Select child DF (p1=1) and Select EF (p1=2),
 1233|       |		 * but we'll use P1=0 as general solution for all cases
 1234|       |		 *
 1235|       |		 * According iso7816-4 sect 7.1.1  pathlen==0 implies
 1236|       |		 * select MF, but this case is not supported by DNIe
 1237|       |		 */
 1238|      0|		if (in_path->len != 2)
  ------------------
  |  Branch (1238:7): [True: 0, False: 0]
  ------------------
 1239|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1240|      0|		sc_log_hex(ctx, "select_file(ID)", in_path->value, in_path->len);
  ------------------
  |  |  129|      0|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      0|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1241|      0|		res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 0, file_out);
 1242|      0|		break;
 1243|    895|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    895|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1243:2): [True: 895, False: 3.40k]
  ------------------
 1244|    895|		sc_log_hex(ctx, "select_file(NAME)", in_path->value, in_path->len);
  ------------------
  |  |  129|    895|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    895|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1245|    895|		res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 4, file_out);
 1246|    895|		break;
 1247|  3.40k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  3.40k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (1247:2): [True: 3.40k, False: 895]
  ------------------
 1248|  3.40k|		if ((in_path->len == 0) || ((in_path->len & 1) != 0)) /* not divisible by 2 */
  ------------------
  |  Branch (1248:7): [True: 29, False: 3.37k]
  |  Branch (1248:30): [True: 0, False: 3.37k]
  ------------------
 1249|  3.40k|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     29|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     29|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     29|	int _ret = r; \
  |  |  |  |  155|     29|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     29|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     29|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     29|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     29|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     29|	return _ret; \
  |  |  |  |  163|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1250|       |
 1251|  3.37k|		sc_log_hex(ctx, "select_file(PATH): requested", in_path->value, in_path->len);
  ------------------
  |  |  129|  3.37k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  3.37k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|       |
 1253|       |		/* convert to SC_PATH_TYPE_FILE_ID */
 1254|  3.37k|		res = sc_lock(card); /* lock to ensure path traversal */
 1255|  3.37k|		LOG_TEST_RET(ctx, res, "sc_lock() failed");
  ------------------
  |  |  174|  3.37k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.37k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.37k|	int _ret = (r); \
  |  |  |  |  168|  3.37k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 3.37k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  3.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1256|  3.37k|		if (memcmp(in_path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (1256:7): [True: 3.22k, False: 143]
  ------------------
 1257|       |			/* if MF, use the name as path */
 1258|  3.22k|			strcpy((char *)tmp_path, DNIE_MF_NAME);
  ------------------
  |  |   69|  3.22k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1259|  3.22k|			sc_log_hex(ctx, "select_file(NAME): requested", tmp_path, sizeof(DNIE_MF_NAME) - 1);
  ------------------
  |  |  129|  3.22k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  3.22k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1260|  3.22k|			res = dnie_compose_and_send_apdu(card, tmp_path, sizeof(DNIE_MF_NAME) - 1, 4, file_out);
  ------------------
  |  |   69|  3.22k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1261|  3.22k|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  3.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1261:8): [True: 2.13k, False: 1.09k]
  ------------------
 1262|  2.13k|				sc_unlock(card);
 1263|  2.13k|				LOG_TEST_RET(ctx, res, "select_file(NAME) failed");
  ------------------
  |  |  174|  2.13k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.13k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.13k|	int _ret = (r); \
  |  |  |  |  168|  2.13k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.13k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.13k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.13k|		return _ret; \
  |  |  |  |  172|  2.13k|	} \
  |  |  |  |  173|  2.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1264|  2.13k|			}
 1265|  1.09k|			tmp_path[2] = 0;
 1266|  1.09k|			reminder = in_path->len - 2;
 1267|  1.09k|		} else {
 1268|    143|			tmp_path[2] = 0;
 1269|    143|			reminder = in_path->len;
 1270|    143|		}
 1271|  1.95k|		while (reminder > 0) {
  ------------------
  |  Branch (1271:10): [True: 887, False: 1.06k]
  ------------------
 1272|    887|			tmp_path[0] = in_path->value[in_path->len - reminder];
 1273|    887|			tmp_path[1] = in_path->value[1 + in_path->len - reminder];
 1274|    887|			sc_log(ctx, "select_file(PATH): requested:%s ", sc_dump_hex(tmp_path, 2));
  ------------------
  |  |   71|    887|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1275|    887|			res = dnie_compose_and_send_apdu(card, tmp_path, 2, 0, file_out);
 1276|    887|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|    887|#define SC_SUCCESS				0
  ------------------
  |  Branch (1276:8): [True: 174, False: 713]
  ------------------
 1277|    174|				sc_unlock(card);
 1278|    174|				LOG_TEST_RET(ctx, res, "select_file(PATH) failed");
  ------------------
  |  |  174|    174|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    174|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    174|	int _ret = (r); \
  |  |  |  |  168|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 174, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    174|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    174|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    174|		return _ret; \
  |  |  |  |  172|    174|	} \
  |  |  |  |  173|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1279|    174|			}
 1280|    713|			reminder -= 2;
 1281|    713|		}
 1282|  1.06k|		sc_unlock(card);
 1283|  1.06k|		break;
 1284|      0|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (1284:2): [True: 0, False: 4.29k]
  ------------------
 1285|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1286|      0|		break;
 1287|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (1287:2): [True: 0, False: 4.29k]
  ------------------
 1288|       |		/* Hey!! Manual doesn't says anything on this, but
 1289|       |		 * gscriptor shows that this type is supported
 1290|       |		 */
 1291|      0|		sc_log(ctx, "select_file(PARENT)");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1292|       |		/* according iso7816-4 sect 7.1.1 shouldn't have any parameters */
 1293|      0|		if (in_path->len != 0)
  ------------------
  |  Branch (1293:7): [True: 0, False: 0]
  ------------------
 1294|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1295|      0|		res = dnie_compose_and_send_apdu(card, NULL, 0, 3, file_out);
 1296|      0|		break;
 1297|      0|	default:
  ------------------
  |  Branch (1297:2): [True: 0, False: 4.29k]
  ------------------
 1298|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1299|      0|		break;
 1300|  4.29k|	}
 1301|       |
 1302|       |	/* as last step clear data cache and return */
 1303|  1.95k|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|  1.95k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1304|  1.95k|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|  1.95k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.95k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.95k|	int _ret = r; \
  |  |  |  |  155|  1.95k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.95k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.95k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    736|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 736, False: 1.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.95k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.95k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.95k|	return _ret; \
  |  |  |  |  163|  1.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1305|  1.95k|}
card-dnie.c:dnie_compose_and_send_apdu:
 1129|  5.01k|{
 1130|  5.01k|	int res = 0;
 1131|  5.01k|	sc_apdu_t apdu;
 1132|  5.01k|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
 1133|  5.01k|	sc_context_t *ctx = NULL;
 1134|       |
 1135|  5.01k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1135:6): [True: 0, False: 5.01k]
  |  Branch (1135:15): [True: 0, False: 5.01k]
  ------------------
 1136|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1137|  5.01k|	ctx = card->ctx;
 1138|       |
 1139|  5.01k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1140|       |
 1141|  5.01k|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0,
  ------------------
  |  |  294|  5.01k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1142|  5.01k|					sc_get_max_recv_size(card), pathlen,
 1143|  5.01k|					rbuf, sizeof(rbuf), path, pathlen);
 1144|  5.01k|	if (p1 == 3)
  ------------------
  |  Branch (1144:6): [True: 0, False: 5.01k]
  ------------------
 1145|      0|		apdu.cse= SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1146|       |
 1147|  5.01k|	if (file_out == NULL)
  ------------------
  |  Branch (1147:6): [True: 2.52k, False: 2.48k]
  ------------------
 1148|  2.52k|		apdu.cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  2.52k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1149|       |
 1150|  5.01k|	res = sc_transmit_apdu(card, &apdu);
 1151|  5.01k|	if ((res != SC_SUCCESS) || (file_out == NULL))
  ------------------
  |  |   28|  5.01k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1151:6): [True: 32, False: 4.97k]
  |  Branch (1151:29): [True: 2.50k, False: 2.47k]
  ------------------
 1152|  5.01k|		LOG_TEST_RET(ctx, res, "SelectFile() APDU transmit failed");
  ------------------
  |  |  174|  2.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.53k|	int _ret = (r); \
  |  |  |  |  168|  2.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 2.50k]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|  2.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.50k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1153|  4.97k|	if (file_out == NULL) {
  ------------------
  |  Branch (1153:6): [True: 2.50k, False: 2.47k]
  ------------------
 1154|  2.50k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1154:7): [True: 0, False: 2.50k]
  ------------------
 1155|      0|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, 0);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1156|  2.50k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  153|  2.50k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.50k|	int _ret = r; \
  |  |  155|  2.50k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.50k, False: 0]
  |  |  ------------------
  |  |  156|  2.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.77k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.77k, False: 730]
  |  |  ------------------
  |  |  157|  2.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.50k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.50k|	return _ret; \
  |  |  163|  2.50k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1157|  2.50k|			       sc_check_sw(card, apdu.sw1, apdu.sw2));
 1158|  2.50k|	}
 1159|       |
 1160|       |	/* analyze response. if FCI, try to parse */
 1161|  2.47k|	res = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1162|  2.47k|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  2.47k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1162:6): [True: 1.09k, False: 1.38k]
  ------------------
 1163|  1.09k|		LOG_TEST_RET(ctx, res, "SelectFile() check_sw failed");
  ------------------
  |  |  174|  1.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.09k|	int _ret = (r); \
  |  |  |  |  168|  1.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.09k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.09k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.09k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.09k|		return _ret; \
  |  |  |  |  172|  1.09k|	} \
  |  |  |  |  173|  1.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  1.09k|	}
 1165|  1.38k|	if ((apdu.resplen < 2) || (apdu.resp[0] == 0x00)) {
  ------------------
  |  Branch (1165:6): [True: 37, False: 1.34k]
  |  Branch (1165:28): [True: 12, False: 1.33k]
  ------------------
 1166|     49|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     49|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1167|     49|	}
 1168|       |
 1169|  1.33k|	if (file_out) {
  ------------------
  |  Branch (1169:6): [True: 1.33k, False: 0]
  ------------------
 1170|       |		/* finally process FCI response */
 1171|  1.33k|		size_t len = apdu.resp[1];
 1172|  1.33k|		sc_file_free(*file_out);
 1173|  1.33k|		*file_out = sc_file_new();
 1174|  1.33k|		if (*file_out == NULL) {
  ------------------
  |  Branch (1174:7): [True: 0, False: 1.33k]
  ------------------
 1175|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1176|      0|		}
 1177|  1.33k|		if (apdu.resplen - 2 < len || len < 1) {
  ------------------
  |  Branch (1177:7): [True: 30, False: 1.30k]
  |  Branch (1177:33): [True: 24, False: 1.27k]
  ------------------
 1178|     54|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1179|     54|		}
 1180|  1.27k|		res = card->ops->process_fci(card, *file_out, apdu.resp + 2, len);
 1181|  1.27k|	}
 1182|  1.27k|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|  1.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.27k|	int _ret = r; \
  |  |  |  |  155|  1.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 1.23k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.27k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.27k|	return _ret; \
  |  |  |  |  163|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1183|  1.27k|}
card-dnie.c:dnie_check_sw:
 1750|  5.93k|{
 1751|  5.93k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  5.93k|#define SC_SUCCESS				0
  ------------------
 1752|  5.93k|	int n = 0;
 1753|  5.93k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1753:6): [True: 0, False: 5.93k]
  |  Branch (1753:15): [True: 0, False: 5.93k]
  ------------------
 1754|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1755|  5.93k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1756|       |
 1757|       |	/* check specific dnie errors */
 1758|  23.6k|	for (n = 0; dnie_errors[n].SWs != 0; n++) {
  ------------------
  |  Branch (1758:14): [True: 17.7k, False: 5.89k]
  ------------------
 1759|  17.7k|		if (dnie_errors[n].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (1759:7): [True: 35, False: 17.7k]
  ------------------
 1760|     35|			sc_log(card->ctx, "%s", dnie_errors[n].errorstr);
  ------------------
  |  |   71|     35|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1761|     35|			return dnie_errors[n].errorno;
 1762|     35|		}
 1763|  17.7k|	}
 1764|       |
 1765|       |	/* arriving here means check for supported iso error codes */
 1766|  5.89k|	res = iso_ops->check_sw(card, sw1, sw2);
 1767|  5.89k|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|  5.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.89k|	int _ret = r; \
  |  |  |  |  155|  5.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.47k, False: 2.41k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.89k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.89k|	return _ret; \
  |  |  |  |  163|  5.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1768|  5.89k|}
card-dnie.c:dnie_card_ctl:
 1787|     15|{
 1788|     15|	int result = SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
 1789|     15|	if ((card == NULL) || (card->ctx == NULL))
  ------------------
  |  Branch (1789:6): [True: 0, False: 15]
  |  Branch (1789:24): [True: 0, False: 15]
  ------------------
 1790|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1791|     15|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     15|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     15|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     15|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     15|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1792|     15|	if (data == NULL) {
  ------------------
  |  Branch (1792:6): [True: 0, False: 15]
  ------------------
 1793|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1794|      0|	}
 1795|     15|	switch (request) {
 1796|       |		/* obtain lifecycle status by reading card->type */
 1797|      7|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1797:2): [True: 7, False: 8]
  ------------------
 1798|      7|		switch (card->type) {
  ------------------
  |  Branch (1798:11): [True: 7, False: 0]
  ------------------
 1799|      0|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (1799:3): [True: 0, False: 7]
  ------------------
 1800|      0|			result = SC_CARDCTRL_LIFECYCLE_ADMIN;
 1801|      0|			break;
 1802|      7|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (1802:3): [True: 7, False: 0]
  ------------------
 1803|      7|			result = SC_CARDCTRL_LIFECYCLE_USER;
 1804|      7|			break;
 1805|      0|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (1805:3): [True: 0, False: 7]
  ------------------
 1806|      0|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (1806:3): [True: 0, False: 7]
  ------------------
 1807|      0|			result = SC_CARDCTRL_LIFECYCLE_OTHER;
 1808|      0|			break;
 1809|      7|		}
 1810|      7|		*(int *)data = result;
 1811|      7|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|       |		/* call card to obtain serial number */
 1813|      8|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1813:2): [True: 8, False: 7]
  ------------------
 1814|      8|		result = dnie_get_serialnr(card, (sc_serial_number_t *) data);
 1815|      8|		LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      8|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      8|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1816|      0|	case SC_CARDCTL_DNIE_GENERATE_KEY:
  ------------------
  |  Branch (1816:2): [True: 0, False: 15]
  ------------------
 1817|       |		/* some reports says that this card supports genkey */
 1818|      0|		result = dnie_generate_key(card, data);
 1819|      0|		LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1820|      0|	case SC_CARDCTL_DNIE_GET_INFO:
  ------------------
  |  Branch (1820:2): [True: 0, False: 15]
  ------------------
 1821|       |		/* retrieve name, surname and eid number */
 1822|      0|		result = dnie_get_info(card, data);
 1823|      0|		LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1824|      0|	default:
  ------------------
  |  Branch (1824:2): [True: 0, False: 15]
  ------------------
 1825|       |		/* default: unsupported function */
 1826|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1827|     15|	}
 1828|     15|}
card-dnie.c:dnie_get_serialnr:
  637|      8|{
  638|      8|	int result;
  639|      8|	sc_apdu_t apdu;
  640|      8|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
  641|      8|	if ((card == NULL) || (card->ctx == NULL) || (serial == NULL))
  ------------------
  |  Branch (641:6): [True: 0, False: 8]
  |  Branch (641:24): [True: 0, False: 8]
  |  Branch (641:47): [True: 0, False: 8]
  ------------------
  642|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  643|       |
  644|      8|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      8|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      8|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|      8|	if (card->type != SC_CARD_TYPE_DNIE_USER)
  ------------------
  |  Branch (645:6): [True: 0, False: 8]
  ------------------
  646|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  647|       |	/* if serial number is cached, use it */
  648|      8|	if (card->serialnr.len) {
  ------------------
  |  Branch (648:6): [True: 0, False: 8]
  ------------------
  649|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  650|      0|		sc_log_hex(card->ctx, "Serial Number (cached)", serial->value, serial->len);
  ------------------
  |  |  129|      0|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      0|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|      0|	}
  653|       |	/* not cached, retrieve it by mean of an APDU */
  654|       |	/* official driver read 0x11 bytes, but only uses 7. Manual says just 7 (for le) */
  655|      8|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xb8, 0x00, 0x00, 0x07, 0,
  ------------------
  |  |  292|      8|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  656|      8|					rbuf, sizeof(rbuf), NULL, 0);
  657|      8|	apdu.cla = 0x90;	/* proprietary cmd */
  658|       |	/* send apdu */
  659|      8|	result = sc_transmit_apdu(card, &apdu);
  660|      8|	if (result != SC_SUCCESS) {
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  |  Branch (660:6): [True: 1, False: 7]
  ------------------
  661|      1|		LOG_TEST_RET(card->ctx, result, "APDU transmit failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  662|      1|	}
  663|      7|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (663:6): [True: 5, False: 2]
  |  Branch (663:26): [True: 1, False: 1]
  ------------------
  664|      6|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      6|#define SC_ERROR_INTERNAL			-1400
  ------------------
  665|       |	/* cache serial number */
  666|      1|	memcpy(card->serialnr.value, apdu.resp, 7 * sizeof(u8));
  667|      1|	card->serialnr.len = 7 * sizeof(u8);
  668|       |	/* TODO: fill Issuer Identification Number data with proper (ATR?) info */
  669|       |	/*
  670|       |	   card->serialnr.iin.mii=;
  671|       |	   card->serialnr.iin.country=;
  672|       |	   card->serialnr.iin.issuer_id=;
  673|       |	 */
  674|       |	/* copy and return serial number */
  675|      1|	memcpy(serial, &card->serialnr, sizeof(*serial));
  676|      1|	sc_log_hex(card->ctx, "Serial Number (apdu)", serial->value, serial->len);
  ------------------
  |  |  129|      1|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      1|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|      1|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  678|      1|}
card-dnie.c:dnie_process_fci:
 1925|  1.27k|{
 1926|  1.27k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  1.27k|#define SC_SUCCESS				0
  ------------------
 1927|  1.27k|	int *op = df_acl;
 1928|  1.27k|	int n = 0;
 1929|  1.27k|	sc_context_t *ctx = NULL;
 1930|  1.27k|	if ((card == NULL) || (card->ctx == NULL) || (file == NULL) || buflen == 0)
  ------------------
  |  Branch (1930:6): [True: 0, False: 1.27k]
  |  Branch (1930:24): [True: 0, False: 1.27k]
  |  Branch (1930:47): [True: 0, False: 1.27k]
  |  Branch (1930:65): [True: 0, False: 1.27k]
  ------------------
 1931|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1932|  1.27k|	ctx = card->ctx;
 1933|  1.27k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.27k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.27k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.27k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.27k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1934|       |	/* first of all, let iso do the hard work */
 1935|  1.27k|	res = iso_ops->process_fci(card, file, buf, buflen);
 1936|  1.27k|	LOG_TEST_RET(ctx, res, "iso7816_process_fci() failed");
  ------------------
  |  |  174|  1.27k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.27k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.27k|	int _ret = (r); \
  |  |  |  |  168|  1.27k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.27k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1937|       |	/* if tag 0x85 is received, then file->prop_attr_len should be filled
 1938|       |	 * by sc_file_set_prop_attr() code. So check and set data according manual
 1939|       |	 * Note errata at pg 35 of Manual  about DF identifier (should be 0x38) */
 1940|  1.27k|	if (file->prop_attr_len == 0) {	/* no proprietary tag (0x85) received */
  ------------------
  |  Branch (1940:6): [True: 586, False: 693]
  ------------------
 1941|    586|		res = SC_SUCCESS;
  ------------------
  |  |   28|    586|#define SC_SUCCESS				0
  ------------------
 1942|    586|		goto dnie_process_fci_end;
 1943|    586|	}
 1944|       |	/* at least 10 bytes should be received */
 1945|    693|	if (file->prop_attr_len < 10) {
  ------------------
  |  Branch (1945:6): [True: 13, False: 680]
  ------------------
 1946|     13|		res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     13|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1947|     13|		goto dnie_process_fci_end;
 1948|     13|	}
 1949|       |	/* byte 0 denotes file type */
 1950|    680|	switch (file->prop_attr[0]) {
 1951|    201|	case 0x01:		/* EF for plain files */
  ------------------
  |  Branch (1951:2): [True: 201, False: 479]
  ------------------
 1952|    201|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    201|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1953|    201|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    201|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1954|    201|		break;
 1955|     92|	case 0x15:		/* EF for keys: linear variable simple TLV */
  ------------------
  |  Branch (1955:2): [True: 92, False: 588]
  ------------------
 1956|     92|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     92|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1957|       |		/* pin file 3F000000 has also this EF type */
 1958|     92|		if ( ( file->prop_attr[2] == 0x00 ) && (file->prop_attr[3] == 0x00 ) ) {
  ------------------
  |  Branch (1958:8): [True: 53, False: 39]
  |  Branch (1958:42): [True: 20, False: 33]
  ------------------
 1959|     20|			sc_log(ctx,"Processing pin EF");
  ------------------
  |  |   71|     20|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1960|     20|			break;
 1961|     20|		}
 1962|       |		/* FCI response for Keys EF returns 3 additional bytes */
 1963|     72|		if (file->prop_attr_len < 13) {
  ------------------
  |  Branch (1963:7): [True: 12, False: 60]
  ------------------
 1964|     12|			sc_log(ctx, "FCI response len for Keys EF should be 13 bytes");
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1965|     12|			res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     12|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1966|     12|			goto dnie_process_fci_end;
 1967|     12|		}
 1968|     60|		break;
 1969|    364|	case 0x24:		/* EF for compressed certificates */
  ------------------
  |  Branch (1969:2): [True: 364, False: 316]
  ------------------
 1970|    364|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    364|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1971|    364|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    364|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1972|       |		/* evaluate real length by reading first 8 bytes from file */
 1973|    364|		res = dnie_read_header(card);
 1974|       |		/* Hey!, we need pin to read certificates... */
 1975|    364|		if (res == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|    364|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (1975:7): [True: 7, False: 357]
  ------------------
 1976|      7|			goto dnie_process_fci_end;
 1977|    357|		if (res <= 0) {
  ------------------
  |  Branch (1977:7): [True: 320, False: 37]
  ------------------
 1978|    320|			sc_log(ctx,
  ------------------
  |  |   71|    320|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1979|    320|			       "Cannot evaluate uncompressed size. use fci length");
 1980|    320|		} else {
 1981|     37|			sc_log(ctx, "Storing uncompressed size '%d' into fci",
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1982|     37|			       res);
 1983|     37|			file->prop_attr[3] = (u8) ((res >> 8) & 0xff);
 1984|     37|			file->prop_attr[4] = (u8) (res & 0xff);
 1985|     37|		}
 1986|    357|		break;
 1987|     13|	case 0x38:		/* Errata: manual page 35 says wrong 0x34 */
  ------------------
  |  Branch (1987:2): [True: 13, False: 667]
  ------------------
 1988|     13|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     13|#define SC_FILE_TYPE_DF			0x04
  ------------------
 1989|     13|		break;
 1990|     10|	default:
  ------------------
  |  Branch (1990:2): [True: 10, False: 670]
  ------------------
 1991|     10|		res = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     10|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 1992|     10|		goto dnie_process_fci_end;
 1993|    680|	}
 1994|       |
 1995|       |	/* bytes 1 and 2 stores file ID */
 1996|    651|	file->id = ( ( 0xff & (int)file->prop_attr[1] ) << 8 ) |
 1997|    651|			( 0xff & (int)file->prop_attr[2] ) ;
 1998|       |
 1999|       |	/* bytes 3 and 4 states file length */
 2000|    651|	file->size = ( ( 0xff & (int)file->prop_attr[3] ) << 8 ) |
 2001|    651|			( 0xff & (int)file->prop_attr[4] ) ;
 2002|       |
 2003|       |	/* bytes 5 to 9 states security attributes */
 2004|       |	/* NOTE:
 2005|       |	 * seems that these 5 bytes are handled according iso7816-9 sect 8.
 2006|       |	 * but sadly that each card uses their own bits :-(
 2007|       |	 * Moreover: Manual talks on 5 bytes, but official driver only uses 4
 2008|       |	 * No info available (yet), so copy code from card-jcos.c / card-flex.c
 2009|       |	 * card drivers and pray... */
 2010|    651|	op = (file->type == SC_FILE_TYPE_DF) ? df_acl : ef_acl;
  ------------------
  |  |  214|    651|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (2010:7): [True: 13, False: 638]
  ------------------
 2011|  3.90k|	for (n = 0; n < 5; n++) {
  ------------------
  |  Branch (2011:14): [True: 3.25k, False: 651]
  ------------------
 2012|  3.25k|		int key_ref = 0;
 2013|  3.25k|		if (*(op + n) == -1)
  ------------------
  |  Branch (2013:7): [True: 651, False: 2.60k]
  ------------------
 2014|    651|			continue;	/* unused entry: skip */
 2015|  2.60k|		key_ref = file->prop_attr[5 + n] & 0x0F;
 2016|  2.60k|		switch (0xF0 & file->prop_attr[5 + n]) {
 2017|    619|		case 0x00:
  ------------------
  |  Branch (2017:3): [True: 619, False: 1.98k]
  ------------------
 2018|    619|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NONE,
  ------------------
  |  |  150|    619|#define SC_AC_NONE			0x00000000
  ------------------
 2019|    619|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    619|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2020|    619|			break;
 2021|     50|		case 0x10:
  ------------------
  |  Branch (2021:3): [True: 50, False: 2.55k]
  ------------------
 2022|       |			/* this tag is omitted in official code
 2023|       |			   case 0x20:
 2024|       |			 */
 2025|    447|		case 0x30:
  ------------------
  |  Branch (2025:3): [True: 397, False: 2.20k]
  ------------------
 2026|    447|			sc_file_add_acl_entry(file, *(op + n), SC_AC_CHV,
  ------------------
  |  |  151|    447|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2027|    447|					      key_ref);
 2028|    447|			break;
 2029|    169|		case 0x40:
  ------------------
  |  Branch (2029:3): [True: 169, False: 2.43k]
  ------------------
 2030|    169|			sc_file_add_acl_entry(file, *(op + n), SC_AC_TERM,
  ------------------
  |  |  152|    169|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
 2031|    169|					      key_ref);
 2032|    169|			break;
 2033|    233|		case 0xF0:
  ------------------
  |  Branch (2033:3): [True: 233, False: 2.37k]
  ------------------
 2034|    233|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NEVER,
  ------------------
  |  |  163|    233|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 2035|    233|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    233|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2036|    233|			break;
 2037|  1.13k|		default:
  ------------------
  |  Branch (2037:3): [True: 1.13k, False: 1.46k]
  ------------------
 2038|  1.13k|			sc_file_add_acl_entry(file, *(op + n), SC_AC_UNKNOWN,
  ------------------
  |  |  162|  1.13k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
 2039|  1.13k|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|  1.13k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2040|  1.13k|			break;
 2041|  2.60k|		}
 2042|  2.60k|	}
 2043|       |	/* NOTE: Following bytes are described at DNIe manual pg 36, but No
 2044|       |	   documentation about what to do with following data is provided...
 2045|       |	   logs suggest that they are neither generated nor handled.
 2046|       |
 2047|       |	   UPDATE: these additional bytes are received when FileDescriptor tag
 2048|       |	   is 0x15 (EF for keys)
 2049|       |	 */
 2050|    651|	if (file->prop_attr[0] == 0x15) {
  ------------------
  |  Branch (2050:6): [True: 80, False: 571]
  ------------------
 2051|     80|		sc_log(card->ctx,
  ------------------
  |  |   71|     80|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2052|     80|		       "Processing flags for Cryptographic key files");
 2053|       |		/* byte 10 (if present) shows Control Flags for security files */
 2054|       |		/* bytes 11 and 12 (if present) states Control bytes for
 2055|       |		   RSA crypto files */
 2056|       |		/* TODO: write when know what to do */
 2057|     80|	}
 2058|    651|	res = SC_SUCCESS;	/* arriving here means success */
  ------------------
  |  |   28|    651|#define SC_SUCCESS				0
  ------------------
 2059|  1.27k| dnie_process_fci_end:
 2060|  1.27k|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|  1.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.27k|	int _ret = r; \
  |  |  |  |  155|  1.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 1.23k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.27k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.27k|	return _ret; \
  |  |  |  |  163|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2061|  1.27k|}
card-dnie.c:dnie_read_header:
 1848|    364|{
 1849|    364|	sc_apdu_t apdu;
 1850|    364|	int r;
 1851|    364|	u8 buf[MAX_RESP_BUFFER_SIZE];
 1852|    364|	unsigned long uncompressed = 0L;
 1853|    364|	unsigned long compressed = 0L;
 1854|    364|	sc_context_t *ctx = NULL;
 1855|       |
 1856|    364|	if (!card || !card->ctx)
  ------------------
  |  Branch (1856:6): [True: 0, False: 364]
  |  Branch (1856:15): [True: 0, False: 364]
  ------------------
 1857|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1858|    364|	ctx = card->ctx;
 1859|    364|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    364|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    364|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    364|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    364|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 364]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1860|       |
 1861|       |	/* initialize apdu */
 1862|    364|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00, 8, 0,
  ------------------
  |  |  292|    364|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1863|    364|					buf, MAX_RESP_BUFFER_SIZE, NULL, 0);
  ------------------
  |  |   56|    364|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
 1864|       |	/* transmit apdu */
 1865|    364|	r = sc_transmit_apdu(card, &apdu);
 1866|    364|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    364|#define SC_SUCCESS				0
  ------------------
  |  Branch (1866:6): [True: 13, False: 351]
  ------------------
 1867|     13|		sc_log(ctx, "read_header() APDU transmit failed");
  ------------------
  |  |   71|     13|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1868|     13|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1869|     13|	}
 1870|       |	/* check response */
 1871|    351|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1871:6): [True: 79, False: 272]
  ------------------
 1872|     79|		goto header_notcompressed;
 1873|    272|	uncompressed = lebytes2ulong(apdu.resp);
 1874|    272|	compressed = lebytes2ulong(apdu.resp + 4);
 1875|    272|	if (uncompressed < compressed)
  ------------------
  |  Branch (1875:6): [True: 40, False: 232]
  ------------------
 1876|     40|		goto header_notcompressed;
 1877|    232|	if (uncompressed > 32767)
  ------------------
  |  Branch (1877:6): [True: 195, False: 37]
  ------------------
 1878|    195|		goto header_notcompressed;
 1879|       |	/* ok: assume data is correct */
 1880|     37|	sc_log(ctx, "read_header: uncompressed file size is %lu", uncompressed);
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1881|     37|	return (int)(0x7FFF & uncompressed);
 1882|       |
 1883|    314| header_notcompressed:
 1884|    314|	sc_log(ctx, "response doesn't match compressed file header");
  ------------------
  |  |   71|    314|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1885|    314|	return 0;
 1886|    232|}
card-dnie.c:dnie_pin_cmd:
 2174|      7|{
 2175|      7|	int res = SC_SUCCESS;
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
 2176|      7|	int lc = SC_CARDCTRL_LIFECYCLE_USER;
 2177|       |
 2178|      7|	if ((card == NULL) || (card->ctx == NULL) || (data == NULL))
  ------------------
  |  Branch (2178:6): [True: 0, False: 7]
  |  Branch (2178:24): [True: 0, False: 7]
  |  Branch (2178:47): [True: 0, False: 7]
  ------------------
 2179|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2180|      7|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      7|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      7|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      7|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      7|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2181|       |
 2182|       |	/*
 2183|       |	* some flags and settings from documentation
 2184|       |	* No (easy) way to handle pinpad through SM, so disable it
 2185|       |	*/
 2186|      7|	data->flags &= ~SC_PIN_CMD_NEED_PADDING; /* no pin padding */
  ------------------
  |  |  422|      7|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2187|      7|	data->flags &= ~SC_PIN_CMD_USE_PINPAD;	 /* cannot handle pinpad */
  ------------------
  |  |  421|      7|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 2188|       |
 2189|       |	/* ensure that card is in USER Lifecycle */
 2190|      7|	res = dnie_card_ctl(card, SC_CARDCTL_LIFECYCLE_GET, &lc);
 2191|      7|	LOG_TEST_RET(card->ctx, res, "Cannot get card LC status");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2192|      7|	if (lc != SC_CARDCTRL_LIFECYCLE_USER) {
  ------------------
  |  Branch (2192:6): [True: 0, False: 7]
  ------------------
 2193|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2194|      0|	}
 2195|       |
 2196|       |	/* only allow changes on CHV pin ) */
 2197|      7|	switch (data->pin_type) {
 2198|      7|	case SC_AC_CHV:	/* Card Holder Verifier */
  ------------------
  |  |  151|      7|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2198:2): [True: 7, False: 0]
  ------------------
 2199|      7|		break;
 2200|      0|	case SC_AC_TERM:	/* Terminal auth */
  ------------------
  |  |  152|      0|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  |  Branch (2200:2): [True: 0, False: 7]
  ------------------
 2201|      0|	case SC_AC_PRO:	/* SM auth */
  ------------------
  |  |  153|      0|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  |  Branch (2201:2): [True: 0, False: 7]
  ------------------
 2202|      0|	case SC_AC_AUT:	/* Key auth */
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2202:2): [True: 0, False: 7]
  ------------------
 2203|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2204|      0|	default:
  ------------------
  |  Branch (2204:2): [True: 0, False: 7]
  ------------------
 2205|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2206|      7|	}
 2207|       |	/* This DNIe driver only supports VERIFY operation */
 2208|      7|	switch (data->cmd) {
 2209|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2209:2): [True: 0, False: 7]
  ------------------
 2210|      0|		res =  dnie_pin_verify(card,data);
 2211|      0|		break;
 2212|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2212:2): [True: 0, False: 7]
  ------------------
 2213|      0|		res =  dnie_pin_change(card,data);
 2214|      0|		break;
 2215|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2215:2): [True: 0, False: 7]
  ------------------
 2216|      7|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|      7|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2216:2): [True: 7, False: 0]
  ------------------
 2217|      7|		res= SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      7|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2218|      7|		break;
 2219|      0|	default:
  ------------------
  |  Branch (2219:2): [True: 0, False: 7]
  ------------------
 2220|      0|		res= SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2221|      0|		break;
 2222|      7|	}
 2223|       |	/* return result */
 2224|      7|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2225|      7|}

sc_get_dtrust_driver:
 1056|  15.2k|{
 1057|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1057:6): [True: 1, False: 15.2k]
  ------------------
 1058|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1059|       |
 1060|  15.2k|	dtrust_ops = *iso_ops;
 1061|  15.2k|	dtrust_ops.match_card = dtrust_match_card;
 1062|  15.2k|	dtrust_ops.init = dtrust_init;
 1063|  15.2k|	dtrust_ops.finish = dtrust_finish;
 1064|  15.2k|	dtrust_ops.pin_cmd = dtrust_pin_cmd;
 1065|  15.2k|	dtrust_ops.set_security_env = dtrust_set_security_env;
 1066|  15.2k|	dtrust_ops.compute_signature = dtrust_compute_signature;
 1067|  15.2k|	dtrust_ops.decipher = dtrust_decipher;
 1068|  15.2k|	dtrust_ops.logout = dtrust_logout;
 1069|       |
 1070|  15.2k|	return &dtrust_drv;
 1071|  15.2k|}
card-dtrust.c:dtrust_match_card:
  234|  14.7k|{
  235|  14.7k|	if (_sc_match_atr(card, dtrust_atrs, &card->type) < 0)
  ------------------
  |  Branch (235:6): [True: 14.6k, False: 107]
  ------------------
  236|  14.6k|		return 0;
  237|       |
  238|    107|	if (_dtrust_match_cardos(card) != SC_SUCCESS)
  ------------------
  |  |   28|    107|#define SC_SUCCESS				0
  ------------------
  |  Branch (238:6): [True: 105, False: 2]
  ------------------
  239|    105|		return 0;
  240|       |
  241|      2|	if (_dtrust_match_profile(card) != SC_SUCCESS)
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  |  Branch (241:6): [True: 2, False: 0]
  ------------------
  242|      2|		return 0;
  243|       |
  244|      0|	sc_log(card->ctx, "D-Trust Signature Card");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  245|       |
  246|      0|	return 1;
  247|      2|}
card-dtrust.c:_dtrust_match_cardos:
  114|    107|{
  115|    107|	int r;
  116|    107|	size_t prodlen;
  117|    107|	u8 buf[32];
  118|       |
  119|       |	/* check OS version */
  120|    107|	r = sc_get_data(card, 0x0182, buf, 32);
  121|    107|	LOG_TEST_RET(card->ctx, r, "OS version check failed");
  ------------------
  |  |  174|    107|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    107|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    107|	int _ret = (r); \
  |  |  |  |  168|    107|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 48, False: 59]
  |  |  |  |  ------------------
  |  |  |  |  169|     48|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     48|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     48|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     48|		return _ret; \
  |  |  |  |  172|     48|	} \
  |  |  |  |  173|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 59]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     59|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (123:6): [True: 24, False: 35]
  ------------------
  124|     24|		if (r != 2 || buf[0] != 0xc9 || buf[1] != 0x04)
  ------------------
  |  Branch (124:7): [True: 3, False: 21]
  |  Branch (124:17): [True: 7, False: 14]
  |  Branch (124:35): [True: 1, False: 13]
  ------------------
  125|     11|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     11|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  126|     35|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (126:13): [True: 35, False: 0]
  ------------------
  127|     35|		if (r != 2 || buf[0] != 0xcb || buf[1] != 0x01)
  ------------------
  |  Branch (127:7): [True: 7, False: 28]
  |  Branch (127:17): [True: 5, False: 23]
  |  Branch (127:35): [True: 3, False: 20]
  ------------------
  128|     15|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     15|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  129|     35|	}
  130|       |
  131|       |	/* check product name */
  132|     33|	r = sc_get_data(card, 0x0180, buf, 32);
  133|     33|	LOG_TEST_RET(card->ctx, r, "Product name check failed");
  ------------------
  |  |  174|     33|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     33|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     33|	int _ret = (r); \
  |  |  |  |  168|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|       |
  135|     30|	prodlen = (size_t)r;
  136|     30|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (136:6): [True: 11, False: 19]
  ------------------
  137|     11|		if (prodlen != strlen("CardOS V5.4     2019") + 1 || memcmp(buf, "CardOS V5.4     2019", prodlen))
  ------------------
  |  Branch (137:7): [True: 2, False: 9]
  |  Branch (137:56): [True: 8, False: 1]
  ------------------
  138|     10|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     10|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  139|     19|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (139:13): [True: 19, False: 0]
  ------------------
  140|     19|		if (prodlen != strlen("CardOS V6.0 2021") + 1 || memcmp(buf, "CardOS V6.0 2021", prodlen))
  ------------------
  |  Branch (140:7): [True: 5, False: 14]
  |  Branch (140:52): [True: 13, False: 1]
  ------------------
  141|     18|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     18|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|     19|	}
  143|       |
  144|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  145|     30|}
card-dtrust.c:_dtrust_match_profile:
  149|      2|{
  150|      2|	sc_path_t cia_path;
  151|      2|	int r;
  152|      2|	u8 buf[SC_MAX_APDU_BUFFER_SIZE];
  153|      2|	size_t slen, plen;
  154|      2|	const u8 *sp, *pp;
  155|      2|	char *name;
  156|       |
  157|      2|	sc_format_path("5032", &cia_path);
  158|      2|	cia_path.aid.len = sizeof(cia_path.aid.value);
  159|      2|	r = sc_hex_to_bin("E8:28:BD:08:0F:A0:00:00:01:67:45:53:49:47:4E", (u8 *)&cia_path.aid.value, &cia_path.aid.len);
  160|      2|	LOG_TEST_RET(card->ctx, r, "Formatting AID failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|       |
  162|      2|	r = sc_select_file(card, &cia_path, NULL);
  163|      2|	LOG_TEST_RET(card->ctx, r, "Selecting CIA path failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|      0|	r = sc_read_binary(card, 0, buf, SC_MAX_APDU_BUFFER_SIZE, NULL);
  ------------------
  |  |   34|      0|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  166|      0|	LOG_TEST_RET(card->ctx, r, "Reading CIA information failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|       |
  168|      0|	sp = sc_asn1_find_tag(card->ctx, buf, r, 0x30, &slen);
  169|      0|	if (sp == NULL)
  ------------------
  |  Branch (169:6): [True: 0, False: 0]
  ------------------
  170|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  171|       |
  172|       |	/* check vendor */
  173|      0|	pp = sc_asn1_find_tag(card->ctx, sp, slen, 0x0c, &plen);
  174|      0|	if (pp == NULL)
  ------------------
  |  Branch (174:6): [True: 0, False: 0]
  ------------------
  175|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  176|       |
  177|      0|	if (plen != 16 || memcmp(pp, "D-TRUST GmbH (C)", 16))
  ------------------
  |  Branch (177:6): [True: 0, False: 0]
  |  Branch (177:20): [True: 0, False: 0]
  ------------------
  178|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  179|       |
  180|       |	/* check profile */
  181|      0|	pp = sc_asn1_find_tag(card->ctx, sp, slen, 0x80, &plen);
  182|      0|	if (pp == NULL)
  ------------------
  |  Branch (182:6): [True: 0, False: 0]
  ------------------
  183|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  184|       |
  185|       |	/*
  186|       |	 * The profile string contains (two) additional characters. They depend
  187|       |	 * on the production process, but aren't relevant for determining the
  188|       |	 * card profile.
  189|       |	 */
  190|      0|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (190:6): [True: 0, False: 0]
  ------------------
  191|      0|		if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.1 Std. RSA 2", 27))
  ------------------
  |  Branch (191:7): [True: 0, False: 0]
  |  Branch (191:21): [True: 0, False: 0]
  ------------------
  192|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_STD;
  193|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 4.1 Multi ECC 2", 28))
  ------------------
  |  Branch (193:12): [True: 0, False: 0]
  |  Branch (193:26): [True: 0, False: 0]
  ------------------
  194|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_MULTI;
  195|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.1 M100 ECC 2", 27))
  ------------------
  |  Branch (195:12): [True: 0, False: 0]
  |  Branch (195:26): [True: 0, False: 0]
  ------------------
  196|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_M100;
  197|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.4 Std. RSA 2", 27))
  ------------------
  |  Branch (197:12): [True: 0, False: 0]
  |  Branch (197:26): [True: 0, False: 0]
  ------------------
  198|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_4_STD;
  199|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 4.4 Multi ECC 2", 28))
  ------------------
  |  Branch (199:12): [True: 0, False: 0]
  |  Branch (199:26): [True: 0, False: 0]
  ------------------
  200|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_4_MULTI;
  201|      0|		else
  202|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  203|      0|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (203:13): [True: 0, False: 0]
  ------------------
  204|      0|		if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.1 Std. RSA 2", 27))
  ------------------
  |  Branch (204:7): [True: 0, False: 0]
  |  Branch (204:21): [True: 0, False: 0]
  ------------------
  205|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_STD;
  206|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 5.1 Multi ECC 2", 28))
  ------------------
  |  Branch (206:12): [True: 0, False: 0]
  |  Branch (206:26): [True: 0, False: 0]
  ------------------
  207|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_MULTI;
  208|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.1 M100 ECC 2", 27))
  ------------------
  |  Branch (208:12): [True: 0, False: 0]
  |  Branch (208:26): [True: 0, False: 0]
  ------------------
  209|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_M100;
  210|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.4 Std. RSA 2", 27))
  ------------------
  |  Branch (210:12): [True: 0, False: 0]
  |  Branch (210:26): [True: 0, False: 0]
  ------------------
  211|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_4_STD;
  212|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 5.4 Multi ECC 2", 28))
  ------------------
  |  Branch (212:12): [True: 0, False: 0]
  |  Branch (212:26): [True: 0, False: 0]
  ------------------
  213|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_4_MULTI;
  214|      0|		else
  215|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  216|      0|	}
  217|       |
  218|      0|	name = malloc(plen + 1);
  219|      0|	if (name == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 0]
  ------------------
  220|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  221|      0|	memcpy(name, pp, plen);
  222|      0|	name[plen] = '\0';
  223|      0|	card->name = name;
  224|       |
  225|      0|	sc_log(card->ctx, "found %s", card->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  226|       |
  227|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  228|      0|}

sc_get_edo_driver:
  306|  15.2k|struct sc_card_driver* sc_get_edo_driver(void) {
  307|  15.2k|	edo_ops = *sc_get_iso7816_driver()->ops;
  308|  15.2k|	edo_ops.match_card = edo_match_card;
  309|  15.2k|	edo_ops.init = edo_init;
  310|  15.2k|	edo_ops.select_file = edo_select_file;
  311|  15.2k|	edo_ops.set_security_env = edo_set_security_env;
  312|  15.2k|	edo_ops.compute_signature = edo_compute_signature;
  313|  15.2k|	edo_ops.logout = edo_logout;
  314|       |
  315|  15.2k|	return &edo_drv;
  316|  15.2k|}
card-edo.c:edo_match_card:
   62|  7.44k|static int edo_match_card(sc_card_t* card) {
   63|  7.44k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.44k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.44k]
  |  |  ------------------
  ------------------
   64|  7.44k|	if (_sc_match_atr(card, edo_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (64:6): [True: 0, False: 7.44k]
  ------------------
   65|      0|		sc_log(card->ctx, "ATR recognized as Polish eID card.");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   66|      0|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   67|      0|	}
   68|  7.44k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  7.44k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.44k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.44k|	int _ret = r; \
  |  |  |  |  155|  7.44k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.44k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.44k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7.44k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.44k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.44k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.44k|	return _ret; \
  |  |  |  |  163|  7.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   69|  7.44k|}

sc_get_entersafe_driver:
 1579|  15.2k|{
 1580|  15.2k|	return sc_get_driver();
 1581|  15.2k|}
card-entersafe.c:sc_get_driver:
 1553|  15.2k|{
 1554|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1555|       |
 1556|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1556:6): [True: 1, False: 15.2k]
  ------------------
 1557|      1|		iso_ops = iso_drv->ops;
 1558|       |
 1559|  15.2k|	entersafe_ops = *iso_drv->ops;
 1560|  15.2k|	entersafe_ops.match_card = entersafe_match_card;
 1561|  15.2k|	entersafe_ops.init = entersafe_init;
 1562|  15.2k|	entersafe_ops.read_binary = entersafe_read_binary;
 1563|  15.2k|	entersafe_ops.write_binary = NULL;
 1564|  15.2k|	entersafe_ops.update_binary = entersafe_update_binary;
 1565|  15.2k|	entersafe_ops.select_file = entersafe_select_file;
 1566|  15.2k|	entersafe_ops.restore_security_env = entersafe_restore_security_env;
 1567|  15.2k|	entersafe_ops.set_security_env = entersafe_set_security_env;
 1568|  15.2k|	entersafe_ops.decipher = entersafe_decipher;
 1569|  15.2k|	entersafe_ops.compute_signature = entersafe_compute_signature;
 1570|  15.2k|	entersafe_ops.create_file = entersafe_create_file;
 1571|       |	entersafe_ops.delete_file = NULL;
 1572|  15.2k|	entersafe_ops.pin_cmd = entersafe_pin_cmd;
 1573|  15.2k|	entersafe_ops.card_ctl = entersafe_card_ctl_2048;
 1574|  15.2k|	entersafe_ops.process_fci = entersafe_process_fci;
 1575|  15.2k|	return &entersafe_drv;
 1576|  15.2k|}
card-entersafe.c:entersafe_match_card:
  135|  9.96k|{
  136|  9.96k|	int i;
  137|  9.96k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.96k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.96k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.96k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.96k]
  |  |  ------------------
  ------------------
  138|       |
  139|  9.96k|	i = _sc_match_atr(card, entersafe_atrs, &card->type);
  140|  9.96k|	if (i < 0)
  ------------------
  |  Branch (140:6): [True: 9.77k, False: 187]
  ------------------
  141|  9.77k|		return 0;
  142|       |
  143|    187|	return 1;
  144|  9.96k|}
card-entersafe.c:entersafe_init:
  147|    187|{
  148|    187|	unsigned int flags;
  149|       |
  150|    187|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    187|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    187|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    187|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 187]
  |  |  ------------------
  ------------------
  151|       |
  152|    187|	card->name = "entersafe";
  153|    187|	card->cla  = 0x00;
  154|    187|	card->drv_data = NULL;
  155|       |
  156|    187|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    187|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    187|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    187|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  157|       |
  158|    187|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  159|    187|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  160|    187|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  161|    187|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  162|       |
  163|    187|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    187|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  164|       |
  165|       |	/* we need read_binary&friends with max 224 bytes per read */
  166|    187|	card->max_send_size = 224;
  167|    187|	card->max_recv_size = 224;
  168|    187|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    187|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    187|	int _ret = r; \
  |  |  155|    187|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 187, False: 0]
  |  |  ------------------
  |  |  156|    187|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 187]
  |  |  ------------------
  |  |  157|    187|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    187|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    187|	return _ret; \
  |  |  163|    187|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  169|    187|}
card-entersafe.c:entersafe_read_binary:
  427|  2.39k|{
  428|  2.39k|	sc_apdu_t apdu;
  429|  2.39k|	u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  430|  2.39k|	int r;
  431|       |
  432|  2.39k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.39k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.39k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.39k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.39k]
  |  |  ------------------
  ------------------
  433|       |
  434|  2.39k|	if (count > card->max_recv_size)
  ------------------
  |  Branch (434:6): [True: 0, False: 2.39k]
  ------------------
  435|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  436|  2.39k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0xFF, idx & 0xFF);
  ------------------
  |  |  292|  2.39k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  437|       |
  438|  2.39k|	apdu.cla = idx > 0x7fff ? 0x80 : 0x00;
  ------------------
  |  Branch (438:13): [True: 156, False: 2.24k]
  ------------------
  439|  2.39k|	apdu.le = count;
  440|  2.39k|	apdu.resplen = count;
  441|  2.39k|	apdu.resp = recvbuf;
  442|       |
  443|  2.39k|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  444|  2.39k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.39k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.39k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.39k|	int _ret = (r); \
  |  |  |  |  168|  2.39k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 2.38k]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|  2.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.38k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  445|  2.38k|	if (apdu.resplen == 0)
  ------------------
  |  Branch (445:6): [True: 119, False: 2.26k]
  ------------------
  446|    119|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    119|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    119|	int _ret = r; \
  |  |  155|    119|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 119, False: 0]
  |  |  ------------------
  |  |  156|    119|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    116|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 116, False: 3]
  |  |  ------------------
  |  |  157|    119|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    119|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    119|	return _ret; \
  |  |  163|    119|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  447|  2.26k|	memcpy(buf, recvbuf, apdu.resplen);
  448|       |
  449|  2.26k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)apdu.resplen);
  ------------------
  |  |  153|  2.26k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.26k|	int _ret = r; \
  |  |  155|  2.26k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 2.26k]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.26k|	} else { \
  |  |  159|  2.26k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  2.26k|			"returning with: %d\n", _ret); \
  |  |  161|  2.26k|	} \
  |  |  162|  2.26k|	return _ret; \
  |  |  163|  2.26k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  450|  2.26k|}
card-entersafe.c:entersafe_transmit_apdu:
  370|  2.59k|{
  371|  2.59k|	u8 *cipher_data = NULL, *mac_data = NULL;
  372|  2.59k|	size_t cipher_data_size, mac_data_size, blocks;
  373|  2.59k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  374|  2.59k|	u8 *sbuf = NULL;
  375|  2.59k|	size_t ssize = 0;
  376|       |
  377|  2.59k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (377:6): [True: 0, False: 2.59k]
  |  Branch (377:22): [True: 0, False: 2.59k]
  ------------------
  378|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  379|       |
  380|  2.59k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.59k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.59k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.59k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.59k]
  |  |  ------------------
  ------------------
  381|       |
  382|  2.59k|	if ((cipher || mac) && (!key || (keylen != 8 && keylen != 16)))
  ------------------
  |  Branch (382:7): [True: 0, False: 2.59k]
  |  Branch (382:17): [True: 0, False: 2.59k]
  |  Branch (382:26): [True: 0, False: 0]
  |  Branch (382:35): [True: 0, False: 0]
  |  Branch (382:50): [True: 0, False: 0]
  ------------------
  383|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  384|       |
  385|  2.59k|	r = sc_apdu_get_octets(card->ctx, apdu, &sbuf, &ssize, SC_PROTO_RAW);
  ------------------
  |  |  354|  2.59k|#define SC_PROTO_RAW		0x00001000
  ------------------
  386|  2.59k|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (386:6): [True: 2.59k, False: 0]
  ------------------
  387|  2.59k|		sc_apdu_log(card->ctx, sbuf, ssize, 1);
  ------------------
  |  |  291|  2.59k|	sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
  |  |  ------------------
  |  |  |  |  127|  5.18k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (127:65): [True: 2.59k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|  2.59k|	if (sbuf)
  ------------------
  |  Branch (388:6): [True: 2.59k, False: 0]
  ------------------
  389|  2.59k|		free(sbuf);
  390|       |
  391|  2.59k|	if (cipher) {
  ------------------
  |  Branch (391:6): [True: 0, False: 2.59k]
  ------------------
  392|      0|		blocks = (apdu->lc + 2) / 8 + 1;
  393|      0|		cipher_data_size = blocks * 8;
  394|      0|		cipher_data = malloc(cipher_data_size);
  395|      0|		if (!cipher_data) {
  ------------------
  |  Branch (395:7): [True: 0, False: 0]
  ------------------
  396|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  397|      0|			goto out;
  398|      0|		}
  399|       |
  400|      0|		if ((r = entersafe_cipher_apdu(card, apdu, key, keylen, cipher_data, cipher_data_size)) < 0)
  ------------------
  |  Branch (400:7): [True: 0, False: 0]
  ------------------
  401|      0|			goto out;
  402|      0|	}
  403|  2.59k|	if (mac) {
  ------------------
  |  Branch (403:6): [True: 0, False: 2.59k]
  ------------------
  404|      0|		mac_data_size = apdu->lc + 4;
  405|      0|		mac_data = malloc(mac_data_size);
  406|      0|		if (!mac_data) {
  ------------------
  |  Branch (406:7): [True: 0, False: 0]
  ------------------
  407|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  408|      0|			goto out;
  409|      0|		}
  410|      0|		r = entersafe_mac_apdu(card, apdu, key, keylen, mac_data, mac_data_size);
  411|      0|		if (r < 0)
  ------------------
  |  Branch (411:7): [True: 0, False: 0]
  ------------------
  412|      0|			goto out;
  413|      0|	}
  414|       |
  415|  2.59k|	r = sc_transmit_apdu(card, apdu);
  416|       |
  417|  2.59k|out:
  418|  2.59k|	free(cipher_data);
  419|  2.59k|	free(mac_data);
  420|       |
  421|  2.59k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.59k|	int _ret = r; \
  |  |  155|  2.59k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.59k, False: 0]
  |  |  ------------------
  |  |  156|  2.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 18, False: 2.57k]
  |  |  ------------------
  |  |  157|  2.59k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.59k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.59k|	return _ret; \
  |  |  163|  2.59k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  422|  2.59k|}
card-entersafe.c:entersafe_select_file:
  590|    916|{
  591|    916|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (591:6): [True: 0, False: 916]
  |  Branch (591:22): [True: 0, False: 916]
  ------------------
  592|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  593|    916|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    916|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    916|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    916|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 916]
  |  |  ------------------
  ------------------
  594|       |
  595|    916|	switch (in_path->type) {
  596|      0|		case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (596:3): [True: 0, False: 916]
  ------------------
  597|      0|			if (in_path->len != 2)
  ------------------
  |  Branch (597:8): [True: 0, False: 0]
  ------------------
  598|      0|				SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  599|      0|			return entersafe_select_fid(card,in_path->value[0], in_path->value[1], file_out);
  600|    370|		case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    370|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (600:3): [True: 370, False: 546]
  ------------------
  601|    370|			return entersafe_select_aid(card, in_path, file_out);
  602|    546|		case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    546|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (602:3): [True: 546, False: 370]
  ------------------
  603|    546|			return entersafe_select_path(card, in_path->value, in_path->len, file_out);
  604|      0|		default:
  ------------------
  |  Branch (604:3): [True: 0, False: 916]
  ------------------
  605|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  606|    916|	}
  607|    916|}
card-entersafe.c:entersafe_select_fid:
  503|    736|{
  504|    736|	int r;
  505|    736|	sc_file_t *file = NULL;
  506|    736|	sc_path_t path;
  507|       |
  508|    736|	memset(&path, 0, sizeof(sc_path_t));
  509|       |
  510|    736|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    736|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  511|    736|	path.value[0] = id_hi;
  512|    736|	path.value[1] = id_lo;
  513|    736|	path.len = 2;
  514|       |
  515|    736|	r = iso_ops->select_file(card, &path, &file);
  516|    736|	if (r < 0)
  ------------------
  |  Branch (516:6): [True: 370, False: 366]
  ------------------
  517|    370|		sc_file_free(file);
  518|    736|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    736|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    736|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    736|	int _ret = (r); \
  |  |  |  |  168|    736|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 370, False: 366]
  |  |  |  |  ------------------
  |  |  |  |  169|    370|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    370|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    370|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    370|		return _ret; \
  |  |  |  |  172|    370|	} \
  |  |  |  |  173|    736|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 366]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|       |
  520|    366|	if (file_out)
  ------------------
  |  Branch (520:6): [True: 158, False: 208]
  ------------------
  521|    158|		*file_out = file;
  522|    208|	else
  523|    208|		sc_file_free(file);
  524|       |
  525|    366|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    366|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    366|	int _ret = r; \
  |  |  155|    366|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 366, False: 0]
  |  |  ------------------
  |  |  156|    366|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 366]
  |  |  ------------------
  |  |  157|    366|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    366|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    366|	return _ret; \
  |  |  163|    366|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  526|    366|}
card-entersafe.c:entersafe_select_aid:
  531|    370|{
  532|    370|	int r;
  533|       |
  534|    370|	r = iso_ops->select_file(card, in_path, file_out);
  535|    370|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    370|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    370|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    370|	int _ret = (r); \
  |  |  |  |  168|    370|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 328, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  169|    328|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    328|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    328|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    328|		return _ret; \
  |  |  |  |  172|    328|	} \
  |  |  |  |  173|    370|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|       |
  537|     42|	if (file_out) {
  ------------------
  |  Branch (537:6): [True: 0, False: 42]
  ------------------
  538|      0|		sc_file_t *file = *file_out;
  539|      0|		if (file == NULL)
  ------------------
  |  Branch (539:7): [True: 0, False: 0]
  ------------------
  540|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  541|       |
  542|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  543|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  544|      0|		file->path.len = 0;
  545|      0|		file->size = 0;
  546|       |		/* AID */
  547|      0|		memcpy(file->name, in_path->value, in_path->len);
  548|      0|		file->namelen = in_path->len;
  549|      0|		file->id = 0x0000;
  550|      0|	}
  551|     42|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     42|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     42|	int _ret = r; \
  |  |  155|     42|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 42, False: 0]
  |  |  ------------------
  |  |  156|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 42]
  |  |  ------------------
  |  |  157|     42|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     42|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     42|	return _ret; \
  |  |  163|     42|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  552|     42|}
card-entersafe.c:entersafe_select_path:
  557|    546|{
  558|    546|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
  559|    546|	const u8 *path = pathbuf;
  560|    546|	size_t pathlen = len;
  561|    546|	unsigned int i;
  562|    546|	int r;
  563|       |
  564|    546|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (564:6): [True: 0, False: 546]
  |  Branch (564:26): [True: 3, False: 543]
  |  Branch (564:41): [True: 0, False: 543]
  ------------------
  565|      3|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      3|	int _ret = r; \
  |  |  155|      3|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  ------------------
  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  ------------------
  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      3|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      3|	return _ret; \
  |  |  163|      3|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  566|       |
  567|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  568|    543|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (568:6): [True: 19, False: 524]
  |  Branch (568:23): [True: 3, False: 16]
  |  Branch (568:42): [True: 1, False: 15]
  ------------------
  569|      4|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      4|	int _ret = r; \
  |  |  155|      4|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  ------------------
  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  ------------------
  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      4|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      4|	return _ret; \
  |  |  163|      4|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  570|       |
  571|       |	/* unify path (the first FID should be MF) */
  572|    539|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (572:6): [True: 29, False: 510]
  |  Branch (572:25): [True: 1, False: 509]
  ------------------
  573|     30|		n_pathbuf[0] = 0x3f;
  574|     30|		n_pathbuf[1] = 0x00;
  575|     30|		memcpy(n_pathbuf + 2, path, pathlen);
  576|     30|		path = n_pathbuf;
  577|     30|		pathlen += 2;
  578|     30|	}
  579|       |
  580|    736|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (580:14): [True: 548, False: 188]
  ------------------
  581|    548|		r = entersafe_select_fid(card, path[i], path[i + 1], NULL);
  582|    548|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    548|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    548|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    548|	int _ret = (r); \
  |  |  |  |  168|    548|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 351, False: 197]
  |  |  |  |  ------------------
  |  |  |  |  169|    351|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    351|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    351|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    351|		return _ret; \
  |  |  |  |  172|    351|	} \
  |  |  |  |  173|    548|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 197]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|    548|	}
  584|    188|	return entersafe_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  585|    539|}
card-entersafe.c:entersafe_pin_cmd:
  880|      6|{
  881|      6|	int r;
  882|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
  883|      6|	entersafe_init_pin_info(&data->pin1, 0);
  884|      6|	entersafe_init_pin_info(&data->pin2, 1);
  885|      6|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      6|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  886|       |
  887|      6|	if (data->cmd != SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|      6|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (887:6): [True: 6, False: 0]
  ------------------
  888|      6|		r = iso_ops->pin_cmd(card, data);
  889|      6|		sc_log(card->ctx, "Verify rv:%i", r);
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  890|      6|	} else {
  891|      0|		{ /*verify*/
  892|      0|			sc_apdu_t apdu;
  893|      0|			u8 sbuf[0x10] = {0};
  894|       |
  895|      0|			if (data->pin1.len > sizeof(sbuf)) {
  ------------------
  |  Branch (895:8): [True: 0, False: 0]
  ------------------
  896|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  897|      0|			}
  898|       |
  899|      0|			memcpy(sbuf, data->pin1.data, data->pin1.len);
  900|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0x00, data->pin_reference + 1);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  901|      0|			apdu.lc = apdu.datalen = sizeof(sbuf);
  902|      0|			apdu.data = sbuf;
  903|       |
  904|      0|			r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  905|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  906|      0|		}
  907|       |
  908|      0|		{ /*change*/
  909|      0|			sc_apdu_t apdu;
  910|      0|			u8 sbuf[0x12] = {0};
  911|       |
  912|      0|			if (data->pin2.len + 2 > sizeof(sbuf)) {
  ------------------
  |  Branch (912:8): [True: 0, False: 0]
  ------------------
  913|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  914|      0|			}
  915|       |
  916|      0|			sbuf[0] = 0x33;
  917|      0|			sbuf[1] = 0x00;
  918|      0|			memcpy(sbuf + 2, data->pin2.data, data->pin2.len);
  919|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xF4, 0x0B, data->pin_reference);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  920|      0|			apdu.cla = 0x84;
  921|      0|			apdu.lc = apdu.datalen = sizeof(sbuf);
  922|      0|			apdu.data = sbuf;
  923|       |
  924|      0|			r = entersafe_transmit_apdu(card, &apdu, key_maintain, sizeof(key_maintain), 1, 1);
  925|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|      0|		}
  927|      0|	}
  928|      6|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      6|	int _ret = r; \
  |  |  155|      6|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  ------------------
  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  ------------------
  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      6|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      6|	return _ret; \
  |  |  163|      6|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  929|      6|}
card-entersafe.c:entersafe_init_pin_info:
  870|     12|{
  871|     12|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     12|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  872|     12|	pin->min_length = 4;
  873|     12|	pin->max_length = 16;
  874|     12|	pin->pad_length = 16;
  875|     12|	pin->offset     = 5 + num * 16;
  876|     12|	pin->pad_char   = 0x00;
  877|     12|}
card-entersafe.c:entersafe_card_ctl_2048:
 1522|    196|{
 1523|    196|	sc_entersafe_create_data *tmp = (sc_entersafe_create_data *)ptr;
 1524|       |
 1525|    196|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    196|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    196|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    196|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 196]
  |  |  ------------------
  ------------------
 1526|       |
 1527|    196|	switch (cmd) {
 1528|      0|		case SC_CARDCTL_ENTERSAFE_CREATE_FILE:
  ------------------
  |  Branch (1528:3): [True: 0, False: 196]
  ------------------
 1529|      0|			if (tmp->type == SC_ENTERSAFE_MF_DATA)
  ------------------
  |  |  666|      0|#define	SC_ENTERSAFE_MF_DATA	0x01
  ------------------
  |  Branch (1529:8): [True: 0, False: 0]
  ------------------
 1530|      0|				return entersafe_create_mf(card, tmp);
 1531|      0|			else if (tmp->type == SC_ENTERSAFE_DF_DATA)
  ------------------
  |  |  667|      0|#define SC_ENTERSAFE_DF_DATA	0x02
  ------------------
  |  Branch (1531:13): [True: 0, False: 0]
  ------------------
 1532|      0|				return entersafe_create_df(card, tmp);
 1533|      0|			else if (tmp->type == SC_ENTERSAFE_EF_DATA)
  ------------------
  |  |  668|      0|#define SC_ENTERSAFE_EF_DATA	0x04
  ------------------
  |  Branch (1533:13): [True: 0, False: 0]
  ------------------
 1534|      0|				return entersafe_create_ef(card, tmp);
 1535|      0|			else
 1536|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1537|      0|		case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
  ------------------
  |  Branch (1537:3): [True: 0, False: 196]
  ------------------
 1538|      0|			return entersafe_write_key(card, (sc_entersafe_wkey_data *)ptr);
 1539|      0|		case SC_CARDCTL_ENTERSAFE_GENERATE_KEY:
  ------------------
  |  Branch (1539:3): [True: 0, False: 196]
  ------------------
 1540|      0|			return entersafe_gen_key(card, (sc_entersafe_gen_key_data *)ptr);
 1541|      0|		case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (1541:3): [True: 0, False: 196]
  ------------------
 1542|      0|			return entersafe_erase_card(card);
 1543|    196|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1543:3): [True: 196, False: 0]
  ------------------
 1544|    196|			return entersafe_get_serialnr(card, (sc_serial_number_t *)ptr);
 1545|      0|		case SC_CARDCTL_ENTERSAFE_PREINSTALL_KEYS:
  ------------------
  |  Branch (1545:3): [True: 0, False: 196]
  ------------------
 1546|      0|			return entersafe_preinstall_keys(card, entersafe_preinstall_rsa_2048);
 1547|      0|		default:
  ------------------
  |  Branch (1547:3): [True: 0, False: 196]
  ------------------
 1548|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1549|    196|	}
 1550|    196|}
card-entersafe.c:entersafe_get_serialnr:
 1347|    196|{
 1348|    196|	int	r;
 1349|    196|	sc_apdu_t apdu;
 1350|    196|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1351|       |
 1352|    196|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    196|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    196|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    196|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 196]
  |  |  ------------------
  ------------------
 1353|    196|	if (serial == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 196]
  ------------------
 1354|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1355|       |
 1356|    196|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xEA, 0x00, 0x00);
  ------------------
  |  |  292|    196|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1357|    196|	apdu.cla = 0x80;
 1358|    196|	apdu.resp = rbuf;
 1359|    196|	apdu.resplen = sizeof(rbuf);
 1360|    196|	apdu.le = 0x08;
 1361|       |
 1362|    196|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
 1363|    196|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    196|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    196|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    196|	int _ret = (r); \
  |  |  |  |  168|    196|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 188]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|    196|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 188]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1364|    188|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "EnterSafe get SN failed");
  ------------------
  |  |  174|    188|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    188|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    188|	int _ret = (r); \
  |  |  |  |  168|    188|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 171, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|    171|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    171|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    171|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    171|		return _ret; \
  |  |  |  |  172|    171|	} \
  |  |  |  |  173|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1365|     17|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1365:6): [True: 14, False: 3]
  ------------------
 1366|     17|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of SN");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1367|       |
 1368|      3|	card->serialnr.len = serial->len = 8;
 1369|      3|	memcpy(card->serialnr.value, rbuf, 8);
 1370|      3|	memcpy(serial->value, rbuf, 8);
 1371|       |
 1372|      3|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      3|	int _ret = r; \
  |  |  155|      3|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  ------------------
  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  ------------------
  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      3|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      3|	return _ret; \
  |  |  163|      3|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1373|      3|}
card-entersafe.c:entersafe_process_fci:
  479|    321|{
  480|    321|	int r;
  481|       |
  482|    321|	if (file == NULL)
  ------------------
  |  Branch (482:6): [True: 0, False: 321]
  ------------------
  483|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  484|    321|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    321|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    321|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    321|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 321]
  |  |  ------------------
  ------------------
  485|       |
  486|    321|	r = iso_ops->process_fci(card, file, buf, buflen);
  487|    321|	LOG_TEST_RET(card->ctx, r, "Process fci failed");
  ------------------
  |  |  174|    321|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    321|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    321|	int _ret = (r); \
  |  |  |  |  168|    321|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 321]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    321|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 321]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  488|       |
  489|    321|	if (file->namelen) {
  ------------------
  |  Branch (489:6): [True: 56, False: 265]
  ------------------
  490|     56|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     56|#define SC_FILE_TYPE_DF			0x04
  ------------------
  491|     56|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     56|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  492|    265|	} else {
  493|    265|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    265|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  494|    265|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    265|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  495|    265|	}
  496|       |
  497|    321|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    321|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    321|	int _ret = r; \
  |  |  155|    321|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 321, False: 0]
  |  |  ------------------
  |  |  156|    321|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 321]
  |  |  ------------------
  |  |  157|    321|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    321|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    321|	return _ret; \
  |  |  163|    321|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  498|    321|}

sc_get_eoi_driver:
  580|  15.2k|{
  581|  15.2k|	eoi_ops = *sc_get_iso7816_driver()->ops;
  582|       |
  583|  15.2k|	eoi_ops.match_card = eoi_match_card;
  584|  15.2k|	eoi_ops.init = eoi_init;
  585|  15.2k|	eoi_ops.finish = eoi_finish;
  586|  15.2k|	eoi_ops.select_file = eoi_select_file;
  587|  15.2k|	eoi_ops.logout = eoi_logout;
  588|  15.2k|	eoi_ops.pin_cmd = eoi_pin_cmd;
  589|  15.2k|	eoi_ops.card_ctl = eoi_card_ctl;
  590|  15.2k|	eoi_ops.set_security_env = eoi_set_security_env;
  591|  15.2k|	eoi_ops.compute_signature = eoi_compute_signature;
  592|       |
  593|  15.2k|	return &eoi_drv;
  594|  15.2k|}
card-eoi.c:eoi_match_card:
  250|  2.46k|static int eoi_match_card(sc_card_t* card) {
  251|  2.46k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.46k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.46k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.46k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.46k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|  2.46k|	if (_sc_match_atr(card, eoi_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (252:6): [True: 0, False: 2.46k]
  ------------------
  253|      0|		sc_log(card->ctx, "ATR recognized as Slovenian eID card");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  254|      0|		LOG_FUNC_RETURN(card->ctx, ATR_MATCH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  255|      0|	}
  256|  2.46k|	LOG_FUNC_RETURN(card->ctx, !ATR_MATCH);
  ------------------
  |  |  164|  2.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.46k|	int _ret = r; \
  |  |  |  |  155|  2.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.46k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.46k|	return _ret; \
  |  |  |  |  163|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  2.46k|}

epass2003_refresh:
  926|    733|{
  927|    733|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    733|#define SC_SUCCESS				0
  ------------------
  928|    733|	epass2003_exdata *exdata = NULL;
  929|       |
  930|    733|	if (!card->drv_data)
  ------------------
  |  Branch (930:6): [True: 0, False: 733]
  ------------------
  931|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|       |
  933|    733|	exdata = (epass2003_exdata *)card->drv_data;
  934|       |
  935|    733|	if (exdata->sm) {
  ------------------
  |  Branch (935:6): [True: 617, False: 116]
  ------------------
  936|    617|		card->sm_ctx.sm_mode = 0;
  937|    617|		r = mutual_auth(card, g_init_key_enc, g_init_key_mac);
  938|    617|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|    617|#define SM_MODE_TRANSMIT	0x200
  ------------------
  939|    617|		LOG_TEST_RET(card->ctx, r, "mutual_auth failed");
  ------------------
  |  |  174|    617|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    617|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    617|	int _ret = (r); \
  |  |  |  |  168|    617|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 617, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    617|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    617|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    617|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    617|		return _ret; \
  |  |  |  |  172|    617|	} \
  |  |  |  |  173|    617|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  940|    617|	}
  941|       |
  942|    116|	return r;
  943|    733|}
sec_attr_to_entry:
 2253|  1.19k|{
 2254|  1.19k|	int i;
 2255|  1.19k|	int found = 0;
 2256|       |
 2257|  1.19k|	unsigned int method;
 2258|  1.19k|	unsigned long  keyref;
 2259|       |
 2260|  1.19k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.19k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.19k]
  |  |  ------------------
  ------------------
 2261|       |
 2262|  1.19k|	switch (file->sec_attr[index]) {
 2263|    246|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  739|    246|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  734|    246|#define EPASS2003_AC_EVERYONE		0x00
  ------------------
  |  Branch (2263:2): [True: 246, False: 948]
  ------------------
 2264|    246|		method = SC_AC_NONE;
  ------------------
  |  |  150|    246|#define SC_AC_NONE			0x00000000
  ------------------
 2265|    246|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    246|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2266|    246|		break;
 2267|    213|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  739|    213|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  735|    213|#define EPASS2003_AC_USER		0x06
  ------------------
  |  Branch (2267:2): [True: 213, False: 981]
  ------------------
 2268|    213|		method = SC_AC_CHV;
  ------------------
  |  |  151|    213|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2269|    213|		keyref = 1;
 2270|    213|		break;
 2271|    735|	default:
  ------------------
  |  Branch (2271:2): [True: 735, False: 459]
  ------------------
 2272|    735|		sc_log(card->ctx, "Unknown value 0x%2.2x in file->sec_attr[%d]", file->sec_attr[index], index);
  ------------------
  |  |   71|    735|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2273|    735|		method = SC_AC_NEVER;
  ------------------
  |  |  163|    735|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 2274|    735|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    735|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2275|    735|		break;
 2276|  1.19k|	}
 2277|       |
 2278|  40.5k|	for (i = 0; i < (int)(sizeof(sec_attr_to_acl_entry) / sizeof(sec_attr_to_acl_entries_t)); i++) {
  ------------------
  |  Branch (2278:14): [True: 39.4k, False: 1.19k]
  ------------------
 2279|  39.4k|		const sec_attr_to_acl_entries_t *e = &sec_attr_to_acl_entry[i];
 2280|       |
 2281|  39.4k|		if (index == e->index && file->type == e->file_type
  ------------------
  |  Branch (2281:7): [True: 2.26k, False: 37.1k]
  |  Branch (2281:28): [True: 443, False: 1.82k]
  ------------------
 2282|    443|				&& file->ef_structure == e->file_ef_structure) {
  ------------------
  |  Branch (2282:8): [True: 66, False: 377]
  ------------------
 2283|       |				/* may add multiple entries */
 2284|     66|			sc_file_add_acl_entry(file, e->op, method, keyref);
 2285|     66|			found++;
 2286|     66|		}
 2287|  39.4k|	}
 2288|  1.19k|	if (found != 1) {
  ------------------
  |  Branch (2288:6): [True: 1.14k, False: 54]
  ------------------
 2289|  1.14k|		sc_log(card->ctx,"found %d entries ", found);
  ------------------
  |  |   71|  1.14k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2290|  1.14k|	}
 2291|       |
 2292|  1.19k|	return 0;
 2293|  1.19k|}
sc_get_epass2003_driver:
 3322|  15.2k|{
 3323|  15.2k|	return sc_get_driver();
 3324|  15.2k|}
card-epass2003.c:mutual_auth:
  896|    617|{
  897|    617|	struct sc_context *ctx = card->ctx;
  898|    617|	int r;
  899|    617|	unsigned char result[256] = {0};
  900|    617|	unsigned char ran_key[8] = {0};
  901|    617|	epass2003_exdata *exdata = NULL;
  902|       |
  903|    617|	if (!card->drv_data)
  ------------------
  |  Branch (903:6): [True: 0, False: 617]
  ------------------
  904|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  905|    617|	exdata = (epass2003_exdata *)card->drv_data;
  906|       |
  907|    617|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    617|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    617|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    617|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    617|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 617]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  908|       |
  909|    617|	r = gen_init_key(card, key_enc, key_mac, result, exdata->smtype);
  910|    617|	LOG_TEST_RET(ctx, r, "gen_init_key failed");
  ------------------
  |  |  174|    617|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    617|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    617|	int _ret = (r); \
  |  |  |  |  168|    617|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 617, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    617|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    617|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    617|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    617|		return _ret; \
  |  |  |  |  172|    617|	} \
  |  |  |  |  173|    617|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  911|      0|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (911:6): [True: 0, False: 0]
  ------------------
  912|      0|		memcpy(ran_key, &result[12+1], 8);
  913|      0|	} else {
  914|      0|		memcpy(ran_key, &result[12], 8);
  915|      0|	}
  916|       |
  917|      0|	r = verify_init_key(card, ran_key, exdata->smtype);
  918|      0|	LOG_TEST_RET(ctx, r, "verify_init_key failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  919|       |
  920|      0|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  921|      0|}
card-epass2003.c:gen_init_key:
  679|    617|{
  680|    617|	int r;
  681|    617|	struct sc_apdu apdu;
  682|    617|	unsigned char data[256] = {0};
  683|    617|	unsigned char tmp_sm;
  684|    617|	unsigned char isFips;
  685|    617|	unsigned long blocksize = 0;
  686|    617|	unsigned char cryptogram[256] = {0}; /* host cryptogram */
  687|    617|	unsigned char iv[16] = {0};
  688|    617|	epass2003_exdata *exdata = NULL;
  689|       |
  690|    617|	if (!card->drv_data)
  ------------------
  |  Branch (690:6): [True: 0, False: 617]
  ------------------
  691|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  692|       |
  693|    617|	exdata = (epass2003_exdata *)card->drv_data;
  694|    617|	isFips = exdata->bFipsCertification;
  695|       |
  696|    617|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    617|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    617|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    617|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    617|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 617]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|    617|	if (1 != RAND_bytes(g_random, sizeof(g_random)))
  ------------------
  |  Branch (698:6): [True: 0, False: 617]
  ------------------
  699|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  700|       |
  701|    617|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x50, 0x00, 0x00);
  ------------------
  |  |  294|    617|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  702|    617|	apdu.cla = 0x80;
  703|    617|	apdu.lc = apdu.datalen = sizeof(g_random);
  704|    617|	apdu.data = g_random;	/* host random */
  705|    617|	if (isFips)
  ------------------
  |  Branch (705:6): [True: 52, False: 565]
  ------------------
  706|     52|		apdu.le = apdu.resplen = 29;
  707|    565|	else
  708|    565|		apdu.le = apdu.resplen = 28;
  709|       |
  710|    617|	apdu.resp = result;	/* card random is result[12~19] */
  711|       |
  712|    617|	tmp_sm = exdata->sm;
  713|    617|	exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    617|#define SM_PLAIN				0x00
  ------------------
  714|    617|	r = epass2003_transmit_apdu(card, &apdu);
  715|    617|	exdata->sm = tmp_sm;
  716|    617|	LOG_TEST_RET(card->ctx, r, "APDU gen_init_key failed");
  ------------------
  |  |  174|    617|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    617|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    617|	int _ret = (r); \
  |  |  |  |  168|    617|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 571]
  |  |  |  |  ------------------
  |  |  |  |  169|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     46|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     46|		return _ret; \
  |  |  |  |  172|     46|	} \
  |  |  |  |  173|    617|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 571]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  717|       |
  718|    571|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  719|    571|	LOG_TEST_RET(card->ctx, r, "gen_init_key failed");
  ------------------
  |  |  174|    571|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    571|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    571|	int _ret = (r); \
  |  |  |  |  168|    571|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 527, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  169|    527|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    527|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    527|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    527|		return _ret; \
  |  |  |  |  172|    527|	} \
  |  |  |  |  173|    571|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  720|       |
  721|       |	/* Step 1 - Generate Derivation data */
  722|     44|	if (isFips) {
  ------------------
  |  Branch (722:6): [True: 11, False: 33]
  ------------------
  723|     11|		memset(data, 0x00, 15);
  724|     11|		data[11] = 0x04;
  725|     11|		data[14] = 0x80;
  726|     11|		data[15] = 0x01;
  727|     11|		memcpy(&data[16], g_random, 8);
  728|     11|		memcpy(&data[24], &result[12 + 1], 8);
  729|     33|	} else {
  730|     33|		memcpy(data, &result[16], 4);
  731|     33|		memcpy(&data[4], g_random, 4);
  732|     33|		memcpy(&data[8], &result[12], 4);
  733|     33|		memcpy(&data[12], &g_random[4], 4);
  734|     33|	}
  735|       |
  736|       |	/* Step 2,3 - Create S-ENC/S-MAC Session Key */
  737|     44|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     44|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (737:6): [True: 26, False: 18]
  ------------------
  738|     26|		if (isFips) {
  ------------------
  |  Branch (738:7): [True: 11, False: 15]
  ------------------
  739|     11|			r = aes128_encrypt_cmac(card, key_enc, 128, data, 32, exdata->sk_enc);
  740|     11|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac enc failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  741|     11|			memset(&data[11], 0x06, 1);
  742|     11|			r = aes128_encrypt_cmac(card, key_mac, 128, data, 32, exdata->sk_mac);
  743|     11|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac mac  failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  744|     15|		} else {
  745|     15|			r = aes128_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  746|     15|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb enc  failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|     15|			r = aes128_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  748|     15|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb mac  failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|     15|		}
  750|     26|	} else {
  751|     18|		r = des3_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  752|     18|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|     18|		r = des3_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  754|     18|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  755|     18|	}
  756|       |
  757|     44|	if (isFips) {
  ------------------
  |  Branch (757:6): [True: 11, False: 33]
  ------------------
  758|     11|		data[11] = 0x00;
  759|     11|		data[14] = 0x40;
  760|     33|	} else {
  761|     33|		memcpy(data, g_random, 8);
  762|     33|		memcpy(&data[8], &result[12], 8);
  763|     33|		data[16] = 0x80;
  764|     33|		blocksize = (key_type == KEY_TYPE_AES ? 16 : 8);
  ------------------
  |  |   80|     33|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (764:16): [True: 15, False: 18]
  ------------------
  765|     33|		memset(&data[17], 0x00, blocksize - 1);
  766|     33|	}
  767|       |
  768|       |	/* calculate host cryptogram */
  769|     44|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     44|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (769:6): [True: 26, False: 18]
  ------------------
  770|     26|		if (isFips) {
  ------------------
  |  Branch (770:7): [True: 11, False: 15]
  ------------------
  771|     11|			r = aes128_encrypt_cmac(card, exdata->sk_enc, 128, data, 32, cryptogram);
  772|     15|		} else {
  773|     15|			r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  774|     15|		}
  775|     26|	} else {
  776|     18|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  777|     18|	}
  778|       |
  779|     44|	LOG_TEST_RET(card->ctx, r, "calculate host cryptogram failed");
  ------------------
  |  |  174|     44|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     44|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     44|	int _ret = (r); \
  |  |  |  |  168|     44|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|       |
  781|       |	/* verify card cryptogram */
  782|     44|	if (isFips) {
  ------------------
  |  Branch (782:6): [True: 11, False: 33]
  ------------------
  783|     11|		if (0 != memcmp(&cryptogram[0], &result[20+1], 8))
  ------------------
  |  Branch (783:7): [True: 11, False: 0]
  ------------------
  784|     11|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|     33|	} else {
  786|     33|		if (0 != memcmp(&cryptogram[16], &result[20], 8))
  ------------------
  |  Branch (786:7): [True: 33, False: 0]
  ------------------
  787|     33|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|     33|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     33|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     33|	int _ret = r; \
  |  |  |  |  155|     33|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     33|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     33|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     33|	return _ret; \
  |  |  |  |  163|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  788|     33|	}
  789|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  790|      0|}
card-epass2003.c:epass2003_transmit_apdu:
 1635|    617|{
 1636|    617|	int r;
 1637|       |
 1638|    617|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    617|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    617|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    617|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    617|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 617]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1639|       |
 1640|    617|	r = sc_transmit_apdu_t(card, apdu);
 1641|    617|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    617|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    617|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    617|	int _ret = (r); \
  |  |  |  |  168|    617|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 571]
  |  |  |  |  ------------------
  |  |  |  |  169|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     46|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     46|		return _ret; \
  |  |  |  |  172|     46|	} \
  |  |  |  |  173|    617|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 571]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1642|       |
 1643|    571|	return r;
 1644|    617|}
card-epass2003.c:sc_transmit_apdu_t:
  268|  3.07k|{
  269|  3.07k|	size_t resplen = apdu->resplen;
  270|  3.07k|	int r = sc_transmit_apdu(card, apdu);
  271|  3.07k|	if ((0x69 == apdu->sw1 && 0x85 == apdu->sw2) || (0x69 == apdu->sw1 && 0x88 == apdu->sw2)) {
  ------------------
  |  Branch (271:7): [True: 142, False: 2.93k]
  |  Branch (271:28): [True: 78, False: 64]
  |  Branch (271:51): [True: 64, False: 2.93k]
  |  Branch (271:72): [True: 34, False: 30]
  ------------------
  272|    112|		epass2003_refresh(card);
  273|       |		/* renew old resplen */
  274|    112|		apdu->resplen = resplen;
  275|    112|		r = sc_transmit_apdu(card, apdu);
  276|    112|	}
  277|  3.07k|	return r;
  278|  3.07k|}
card-epass2003.c:aes128_encrypt_cmac:
  415|    104|{
  416|    104|	size_t mactlen = 0;
  417|    104|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    104|#define SC_ERROR_INTERNAL			-1400
  ------------------
  418|    104|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  419|    104|	CMAC_CTX *ctx = CMAC_CTX_new();
  420|    104|	if (ctx == NULL) {
  ------------------
  |  Branch (420:6): [True: 0, False: 104]
  ------------------
  421|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  422|      0|	}
  423|       |
  424|    104|	if (!CMAC_Init(ctx, key, keysize / 8, EVP_aes_128_cbc(), NULL)) {
  ------------------
  |  Branch (424:6): [True: 0, False: 104]
  ------------------
  425|      0|		goto err;
  426|      0|	}
  427|    104|	if (!CMAC_Update(ctx, input, length)) {
  ------------------
  |  Branch (427:6): [True: 0, False: 104]
  ------------------
  428|      0|		goto err;
  429|      0|	}
  430|    104|	if (!CMAC_Final(ctx, output, &mactlen)) {
  ------------------
  |  Branch (430:6): [True: 0, False: 104]
  ------------------
  431|      0|		goto err;
  432|      0|	}
  433|    104|	r = SC_SUCCESS;
  ------------------
  |  |   28|    104|#define SC_SUCCESS				0
  ------------------
  434|    104|err:
  435|    104|	CMAC_CTX_free(ctx);
  436|       |#else
  437|       |	EVP_MAC *mac = EVP_MAC_fetch(card->ctx->ossl3ctx->libctx, "cmac", NULL);
  438|       |	if (mac == NULL) {
  439|       |		return r;
  440|       |	}
  441|       |
  442|       |	OSSL_PARAM params[2] = {0};
  443|       |	params[0] = OSSL_PARAM_construct_utf8_string("cipher","aes-128-cbc", 0);
  444|       |	params[1] = OSSL_PARAM_construct_end();
  445|       |
  446|       |	EVP_MAC_CTX *ctx = EVP_MAC_CTX_new(mac);
  447|       |	if (ctx == NULL) {
  448|       |		EVP_MAC_CTX_free(ctx);
  449|       |		sc_log_openssl(card->ctx);
  450|       |		return r;
  451|       |	}
  452|       |	if (!EVP_MAC_init(ctx, (const unsigned char *)key, keysize / 8, params)) {
  453|       |		sc_log_openssl(card->ctx);
  454|       |		goto err;
  455|       |	}
  456|       |	if (!EVP_MAC_update(ctx, input, length)) {
  457|       |		sc_log_openssl(card->ctx);
  458|       |		goto err;
  459|       |	}
  460|       |	if (!EVP_MAC_final(ctx, output, &mactlen, 16)) {
  461|       |		sc_log_openssl(card->ctx);
  462|       |		goto err;
  463|       |	}
  464|       |	r = SC_SUCCESS;
  465|       |err:
  466|       |	EVP_MAC_CTX_free(ctx);
  467|       |	EVP_MAC_free(mac);
  468|       |#endif
  469|    104|	return r;
  470|    104|}
card-epass2003.c:aes128_encrypt_ecb:
  475|     30|{
  476|     30|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  477|     30|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-ECB");
  478|     30|	int r;
  479|     30|	r = openssl_enc(alg, key, iv, input, length, output);
  480|     30|	sc_evp_cipher_free(alg);
  481|     30|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (481:6): [True: 0, False: 30]
  ------------------
  482|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  483|     30|	return r;
  484|     30|}
card-epass2003.c:openssl_enc:
  283|  1.84k|{
  284|  1.84k|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.84k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  285|  1.84k|	EVP_CIPHER_CTX * ctx = NULL;
  286|  1.84k|	int outl = 0;
  287|  1.84k|	int outl_tmp = 0;
  288|  1.84k|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  289|       |
  290|  1.84k|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  291|  1.84k|	ctx = EVP_CIPHER_CTX_new();
  292|  1.84k|	if (ctx == NULL)
  ------------------
  |  Branch (292:6): [True: 0, False: 1.84k]
  ------------------
  293|      0|		goto out;
  294|       |
  295|  1.84k|	if (!EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp) || !EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (295:6): [True: 0, False: 1.84k]
  |  Branch (295:61): [True: 0, False: 1.84k]
  ------------------
  296|      0|		goto out;
  297|       |
  298|  1.84k|	if (!EVP_EncryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (298:6): [True: 0, False: 1.84k]
  ------------------
  299|      0|		goto out;
  300|       |
  301|  1.84k|	if (!EVP_EncryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (301:6): [True: 0, False: 1.84k]
  ------------------
  302|      0|		goto out;
  303|       |
  304|  1.84k|	r = SC_SUCCESS;
  ------------------
  |  |   28|  1.84k|#define SC_SUCCESS				0
  ------------------
  305|  1.84k|out:
  306|  1.84k|	EVP_CIPHER_CTX_free(ctx);
  307|  1.84k|	return r;
  308|  1.84k|}
card-epass2003.c:des3_encrypt_ecb:
  518|     36|{
  519|     36|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  520|     36|	unsigned char bKey[24] = {0};
  521|     36|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3");
  522|     36|	int r;
  523|       |
  524|     36|	if (keysize == 16) {
  ------------------
  |  Branch (524:6): [True: 36, False: 0]
  ------------------
  525|     36|		memcpy(&bKey[0], key, 16);
  526|     36|		memcpy(&bKey[16], key, 8);
  527|     36|	} else {
  528|      0|		memcpy(&bKey[0], key, 24);
  529|      0|	}
  530|       |
  531|     36|	r = openssl_enc(alg, bKey, iv, input, length, output);
  532|     36|	sc_evp_cipher_free(alg);
  533|     36|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     36|#define SC_SUCCESS				0
  ------------------
  |  Branch (533:6): [True: 0, False: 36]
  ------------------
  534|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  535|     36|	return r;
  536|     36|}
card-epass2003.c:aes128_encrypt_cbc:
  490|    154|{
  491|    154|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-CBC");
  492|    154|	int r;
  493|    154|	r = openssl_enc(alg, key, iv, input, length, output);
  494|    154|	sc_evp_cipher_free(alg);
  495|    154|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    154|#define SC_SUCCESS				0
  ------------------
  |  Branch (495:6): [True: 0, False: 154]
  ------------------
  496|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  497|    154|	return r;
  498|    154|}
card-epass2003.c:des3_encrypt_cbc:
  542|    548|{
  543|    548|	unsigned char bKey[24] = {0};
  544|    548|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3-CBC");
  545|    548|	int r;
  546|       |
  547|    548|	if (keysize == 16) {
  ------------------
  |  Branch (547:6): [True: 548, False: 0]
  ------------------
  548|    548|		memcpy(&bKey[0], key, 16);
  549|    548|		memcpy(&bKey[16], key, 8);
  550|    548|	} else {
  551|      0|		memcpy(&bKey[0], key, 24);
  552|      0|	}
  553|       |
  554|    548|	r = openssl_enc(EVP_des_ede3_cbc(), bKey, iv, input, length, output);
  555|    548|	sc_evp_cipher_free(alg);
  556|    548|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    548|#define SC_SUCCESS				0
  ------------------
  |  Branch (556:6): [True: 0, False: 548]
  ------------------
  557|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  558|    548|	return r;
  559|    548|}
card-epass2003.c:sc_get_driver:
 3289|  15.2k|{
 3290|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3291|       |
 3292|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (3292:6): [True: 1, False: 15.2k]
  ------------------
 3293|      1|		iso_ops = iso_drv->ops;
 3294|       |
 3295|  15.2k|	epass2003_ops = *iso_ops;
 3296|       |
 3297|  15.2k|	epass2003_ops.match_card = epass2003_match_card;
 3298|  15.2k|	epass2003_ops.init = epass2003_init;
 3299|  15.2k|	epass2003_ops.finish = epass2003_finish;
 3300|  15.2k|	epass2003_ops.write_binary = NULL;
 3301|  15.2k|	epass2003_ops.write_record = NULL;
 3302|  15.2k|	epass2003_ops.select_file = epass2003_select_file;
 3303|       |	epass2003_ops.get_response = NULL;
 3304|  15.2k|	epass2003_ops.restore_security_env = epass2003_restore_security_env;
 3305|  15.2k|	epass2003_ops.set_security_env = epass2003_set_security_env;
 3306|  15.2k|	epass2003_ops.decipher = epass2003_decipher;
 3307|  15.2k|	epass2003_ops.compute_signature = epass2003_decipher;
 3308|  15.2k|	epass2003_ops.create_file = epass2003_create_file;
 3309|  15.2k|	epass2003_ops.delete_file = epass2003_delete_file;
 3310|  15.2k|	epass2003_ops.list_files = epass2003_list_files;
 3311|  15.2k|	epass2003_ops.card_ctl = epass2003_card_ctl;
 3312|  15.2k|	epass2003_ops.process_fci = epass2003_process_fci;
 3313|  15.2k|	epass2003_ops.construct_fci = epass2003_construct_fci;
 3314|  15.2k|	epass2003_ops.pin_cmd = epass2003_pin_cmd;
 3315|  15.2k|	epass2003_ops.check_sw = epass2003_check_sw;
 3316|  15.2k|	epass2003_ops.get_challenge = epass2003_get_challenge;
 3317|  15.2k|	epass2003_ops.logout = epass2003_logout;
 3318|  15.2k|	return &epass2003_drv;
 3319|  15.2k|}
card-epass2003.c:epass2003_match_card:
 1687|  9.77k|{
 1688|  9.77k|	int r;
 1689|       |
 1690|  9.77k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.77k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.77k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.77k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.77k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.77k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1691|  9.77k|	r = _sc_match_atr(card, epass2003_atrs, &card->type);
 1692|  9.77k|	if (r < 0)
  ------------------
  |  Branch (1692:6): [True: 9.13k, False: 643]
  ------------------
 1693|  9.13k|		return 0;
 1694|       |
 1695|    643|	return 1;
 1696|  9.77k|}
card-epass2003.c:epass2003_init:
 1701|    643|{
 1702|    643|	unsigned int flags;
 1703|    643|	unsigned int ext_flags;
 1704|    643|	unsigned char data[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1705|    643|	size_t datalen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    643|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1706|    643|	epass2003_exdata *exdata = NULL;
 1707|    643|	void *old_drv_data = card->drv_data;
 1708|       |
 1709|    643|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    643|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    643|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    643|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    643|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 643]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1710|       |
 1711|    643|	card->name = "epass2003";
 1712|    643|	card->cla = 0x00;
 1713|    643|	exdata = (epass2003_exdata *)calloc(1, sizeof(epass2003_exdata));
 1714|    643|	if (!exdata)
  ------------------
  |  Branch (1714:6): [True: 0, False: 643]
  ------------------
 1715|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1716|       |
 1717|    643|	card->drv_data = exdata;
 1718|       |
 1719|    643|	exdata->sm = SM_SCP01;
  ------------------
  |  |   92|    643|#define SM_SCP01				0x01
  ------------------
 1720|       |
 1721|       |	/* decide FIPS/Non-FIPS mode */
 1722|    643|	if (SC_SUCCESS != get_data(card, 0x86, data, datalen)) {
  ------------------
  |  |   28|    643|#define SC_SUCCESS				0
  ------------------
  |  Branch (1722:6): [True: 22, False: 621]
  ------------------
 1723|     22|		free(exdata);
 1724|     22|		card->drv_data = old_drv_data;
 1725|     22|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     22|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1726|     22|	}
 1727|       |
 1728|    621|	if (memcmp(&data[32], "\x87\x01\x01", 3) == 0 && memcmp(&data[0], "\x80\x01\x01", 3) == 0) {
  ------------------
  |  Branch (1728:6): [True: 68, False: 553]
  |  Branch (1728:51): [True: 44, False: 24]
  ------------------
 1729|     44|		exdata->bFipsCertification = 0x01;
 1730|    577|	} else {
 1731|    577|		exdata->bFipsCertification = 0x00;
 1732|    577|	}
 1733|       |
 1734|    621|	if (0x01 == data[2])
  ------------------
  |  Branch (1734:6): [True: 70, False: 551]
  ------------------
 1735|     70|		exdata->smtype = KEY_TYPE_AES;
  ------------------
  |  |   80|     70|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
 1736|    551|	else
 1737|    551|		exdata->smtype = KEY_TYPE_DES;
  ------------------
  |  |   81|    551|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
 1738|       |
 1739|    621|	if (0x84 == data[14]) {
  ------------------
  |  Branch (1739:6): [True: 102, False: 519]
  ------------------
 1740|    102|		if (0x00 == data[16]) {
  ------------------
  |  Branch (1740:7): [True: 98, False: 4]
  ------------------
 1741|     98|			exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|     98|#define SM_PLAIN				0x00
  ------------------
 1742|     98|		}
 1743|    102|	}
 1744|       |
 1745|       |	/* mutual authentication */
 1746|    621|	card->max_recv_size = 0xD8;
 1747|    621|	card->max_send_size = 0xE8;
 1748|       |
 1749|    621|	card->sm_ctx.ops.open = epass2003_refresh;
 1750|    621|	card->sm_ctx.ops.get_sm_apdu = epass2003_sm_get_wrapped_apdu;
 1751|    621|	card->sm_ctx.ops.free_sm_apdu = epass2003_sm_free_wrapped_apdu;
 1752|       |
 1753|       |	/* FIXME (VT): rather then set/unset 'g_sm', better to implement filter for APDUs to be wrapped */
 1754|    621|	epass2003_refresh(card);
 1755|       |
 1756|    621|	card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|    621|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1757|       |
 1758|    621|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    621|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    621|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    621|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1759|       |
 1760|    621|	_sc_card_add_rsa_alg(card, 512, flags, 0);
 1761|    621|	_sc_card_add_rsa_alg(card, 768, flags, 0);
 1762|    621|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1763|    621|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1764|       |
 1765|       |	//set EC Alg Flags
 1766|    621|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |   93|    621|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  176|    621|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    621|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  178|    621|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    621|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  175|    621|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    621|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|    621|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1767|    621|	ext_flags = 0;
 1768|    621|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1769|       |
 1770|    621|	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  550|    621|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    621|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
 1771|       |
 1772|    621|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    621|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    621|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    621|	int _ret = r; \
  |  |  |  |  155|    621|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 621, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    621|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 621]
  |  |  |  |  ------------------
  |  |  |  |  157|    621|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    621|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    621|	return _ret; \
  |  |  |  |  163|    621|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|    621|}
card-epass2003.c:get_data:
 1649|    649|{
 1650|    649|	int r;
 1651|    649|	struct sc_apdu apdu;
 1652|    649|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1653|    649|	size_t resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    649|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1654|    649|	epass2003_exdata *exdata = NULL;
 1655|       |
 1656|    649|	if (!card->drv_data)
  ------------------
  |  Branch (1656:6): [True: 0, False: 649]
  ------------------
 1657|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1658|       |
 1659|    649|	exdata = (epass2003_exdata *)card->drv_data;
 1660|       |
 1661|    649|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    649|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    649|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    649|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    649|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 649]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|       |
 1663|    649|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, type);
  ------------------
  |  |  292|    649|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1664|    649|	apdu.resp = resp;
 1665|    649|	apdu.le = 0;
 1666|    649|	apdu.resplen = resplen;
 1667|    649|	if (0x86 == type) {
  ------------------
  |  Branch (1667:6): [True: 643, False: 6]
  ------------------
 1668|       |		/* No SM temporarily */
 1669|    643|		unsigned char tmp_sm = exdata->sm;
 1670|    643|		exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    643|#define SM_PLAIN				0x00
  ------------------
 1671|    643|		r = sc_transmit_apdu(card, &apdu);
 1672|    643|		exdata->sm = tmp_sm;
 1673|    643|	} else {
 1674|      6|		r = sc_transmit_apdu_t(card, &apdu);
 1675|      6|	}
 1676|    649|	LOG_TEST_RET(card->ctx, r, "APDU get_data failed");
  ------------------
  |  |  174|    649|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    649|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    649|	int _ret = (r); \
  |  |  |  |  168|    649|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 645]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|    649|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 645]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1677|    645|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1678|    645|	LOG_TEST_RET(card->ctx, r, "get_data failed");
  ------------------
  |  |  174|    645|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    645|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    645|	int _ret = (r); \
  |  |  |  |  168|    645|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 622]
  |  |  |  |  ------------------
  |  |  |  |  169|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     23|		return _ret; \
  |  |  |  |  172|     23|	} \
  |  |  |  |  173|    645|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 622]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|       |
 1680|    622|	memcpy(data, resp, datalen);
 1681|    622|	return r;
 1682|    645|}
card-epass2003.c:epass2003_sm_get_wrapped_apdu:
 1584|  2.18k|{
 1585|  2.18k|	struct sc_context *ctx = card->ctx;
 1586|  2.18k|	struct sc_apdu *apdu = NULL;
 1587|  2.18k|	int rv;
 1588|       |
 1589|  2.18k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1590|  2.18k|	if (!plain || !sm_apdu)
  ------------------
  |  Branch (1590:6): [True: 0, False: 2.18k]
  |  Branch (1590:16): [True: 0, False: 2.18k]
  ------------------
 1591|  2.18k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1592|       |
 1593|  2.18k|	*sm_apdu = NULL;
 1594|       |	//construct new SM apdu from original apdu
 1595|  2.18k|	apdu = calloc(1, sizeof(struct sc_apdu));
 1596|  2.18k|	if (!apdu) {
  ------------------
  |  Branch (1596:6): [True: 0, False: 2.18k]
  ------------------
 1597|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1598|      0|		goto err;
 1599|      0|	}
 1600|  2.18k|	apdu->data = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  2.18k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1601|  2.18k|	if (!apdu->data) {
  ------------------
  |  Branch (1601:6): [True: 0, False: 2.18k]
  ------------------
 1602|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1603|      0|		goto err;
 1604|      0|	}
 1605|  2.18k|	apdu->resp = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  2.18k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1606|  2.18k|	if (!apdu->resp) {
  ------------------
  |  Branch (1606:6): [True: 0, False: 2.18k]
  ------------------
 1607|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1608|      0|		goto err;
 1609|      0|	}
 1610|  2.18k|	apdu->datalen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  2.18k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1611|  2.18k|	apdu->resplen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  2.18k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1612|       |
 1613|  2.18k|	rv = epass2003_sm_wrap_apdu(card, plain, apdu);
 1614|  2.18k|	if (rv) {
  ------------------
  |  Branch (1614:6): [True: 0, False: 2.18k]
  ------------------
 1615|      0|		rv = epass2003_sm_free_wrapped_apdu(card, NULL, &apdu);
 1616|      0|		if (rv < 0)
  ------------------
  |  Branch (1616:7): [True: 0, False: 0]
  ------------------
 1617|      0|			goto err;
 1618|      0|	}
 1619|       |
 1620|  2.18k|	*sm_apdu = apdu;
 1621|  2.18k|	apdu = NULL;
 1622|  2.18k|err:
 1623|  2.18k|	if (apdu) {
  ------------------
  |  Branch (1623:6): [True: 0, False: 2.18k]
  ------------------
 1624|      0|		free((unsigned char *) apdu->data);
 1625|      0|		free(apdu->resp);
 1626|      0|		free(apdu);
 1627|      0|		apdu = NULL;
 1628|      0|	}
 1629|  2.18k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.18k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.18k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.18k|	int _ret = r; \
  |  |  |  |  155|  2.18k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.18k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.18k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.18k|	return _ret; \
  |  |  |  |  163|  2.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1630|  2.18k|}
card-epass2003.c:epass2003_sm_wrap_apdu:
 1299|  2.18k|{
 1300|  2.18k|	unsigned char buf[4096] = {0}; /* APDU buffer */
 1301|  2.18k|	size_t buf_len = sizeof(buf);
 1302|  2.18k|	epass2003_exdata *exdata = NULL;
 1303|       |
 1304|  2.18k|	if (!card->drv_data)
  ------------------
  |  Branch (1304:6): [True: 0, False: 2.18k]
  ------------------
 1305|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1306|       |
 1307|  2.18k|	exdata = (epass2003_exdata *)card->drv_data;
 1308|       |
 1309|  2.18k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1310|       |
 1311|  2.18k|	if (exdata->sm)
  ------------------
  |  Branch (1311:6): [True: 634, False: 1.55k]
  ------------------
 1312|    634|		plain->cla |= 0x0C;
 1313|       |
 1314|  2.18k|	sm->cse = plain->cse;
 1315|  2.18k|	sm->cla = plain->cla;
 1316|  2.18k|	sm->ins = plain->ins;
 1317|  2.18k|	sm->p1 = plain->p1;
 1318|  2.18k|	sm->p2 = plain->p2;
 1319|  2.18k|	sm->lc = plain->lc;
 1320|  2.18k|	sm->le = plain->le;
 1321|  2.18k|	sm->control = plain->control;
 1322|  2.18k|	sm->flags = plain->flags;
 1323|       |
 1324|  2.18k|	switch (sm->cla & 0x0C) {
 1325|  1.55k|	case 0x00:
  ------------------
  |  Branch (1325:2): [True: 1.55k, False: 634]
  ------------------
 1326|  1.55k|	case 0x04:
  ------------------
  |  Branch (1326:2): [True: 0, False: 2.18k]
  ------------------
 1327|  1.55k|		sm->datalen = plain->datalen;
 1328|  1.55k|		memcpy((void *)sm->data, plain->data, plain->datalen);
 1329|  1.55k|		sm->resplen = plain->resplen;
 1330|  1.55k|		memcpy(sm->resp, plain->resp, plain->resplen);
 1331|  1.55k|		break;
 1332|    634|	case 0x0C:
  ------------------
  |  Branch (1332:2): [True: 634, False: 1.55k]
  ------------------
 1333|    634|		memset(buf, 0, sizeof(buf));
 1334|    634|		if (0 != encode_apdu(card, plain, sm, buf, &buf_len))
  ------------------
  |  Branch (1334:7): [True: 0, False: 634]
  ------------------
 1335|      0|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      0|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1336|    634|		break;
 1337|    634|	default:
  ------------------
  |  Branch (1337:2): [True: 0, False: 2.18k]
  ------------------
 1338|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
 1339|  2.18k|	}
 1340|       |
 1341|  2.18k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.18k|#define SC_SUCCESS				0
  ------------------
 1342|  2.18k|}
card-epass2003.c:encode_apdu:
 1202|    634|{
 1203|    634|	size_t block_size = 0;
 1204|    634|	unsigned char dataTLV[4096] = {0};
 1205|    634|	size_t data_tlv_len = 0;
 1206|    634|	unsigned char le_tlv[256] = {0};
 1207|    634|	size_t le_tlv_len = 0;
 1208|    634|	size_t mac_tlv_len = 10;
 1209|    634|	size_t tmp_lc = 0;
 1210|    634|	size_t tmp_le = 0;
 1211|    634|	size_t expected_total_len;
 1212|    634|	unsigned char mac_tlv[256] = {0};
 1213|    634|	epass2003_exdata *exdata = NULL;
 1214|       |
 1215|    634|	mac_tlv[0] = 0x8E;
 1216|    634|	mac_tlv[1] = 8;
 1217|       |	/* size_t plain_le = 0; */
 1218|    634|	if (!card->drv_data)
  ------------------
  |  Branch (1218:6): [True: 0, False: 634]
  ------------------
 1219|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1220|    634|	exdata = (epass2003_exdata*)card->drv_data;
 1221|    634|	block_size = (KEY_TYPE_DES == exdata->smtype ? 16 : 8);
  ------------------
  |  |   81|    634|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
  |  Branch (1221:16): [True: 531, False: 103]
  ------------------
 1222|       |
 1223|    634|	sm->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|    634|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1224|    634|	apdu_buf[0] = (unsigned char)plain->cla;
 1225|    634|	apdu_buf[1] = (unsigned char)plain->ins;
 1226|    634|	apdu_buf[2] = (unsigned char)plain->p1;
 1227|    634|	apdu_buf[3] = (unsigned char)plain->p2;
 1228|       |	/* plain_le = plain->le; */
 1229|       |	/* padding */
 1230|    634|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1230:6): [True: 71, False: 563]
  |  Branch (1230:36): [True: 1, False: 70]
  |  Branch (1230:54): [True: 0, False: 1]
  |  Branch (1230:77): [True: 0, False: 0]
  ------------------
 1231|      0|		apdu_buf[4] = 0x00;
 1232|    634|	} else {
 1233|    634|		apdu_buf[4] = 0x80;
 1234|    634|	}
 1235|    634|	memset(&apdu_buf[5], 0x00, block_size - 5);
 1236|       |
 1237|       |	/* Data -> Data' */
 1238|    634|	if (plain->lc != 0)
  ------------------
  |  Branch (1238:6): [True: 632, False: 2]
  ------------------
 1239|    632|		if (0 != construct_data_tlv(card, plain, apdu_buf, dataTLV, &data_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1239:7): [True: 0, False: 632]
  ------------------
 1240|      0|			return -1;
 1241|       |
 1242|    634|	if (plain->le != 0 || (plain->le == 0 && plain->resplen != 0))
  ------------------
  |  Branch (1242:6): [True: 15, False: 619]
  |  Branch (1242:25): [True: 619, False: 0]
  |  Branch (1242:43): [True: 615, False: 4]
  ------------------
 1243|    630|		if (0 != construct_le_tlv(plain, apdu_buf, data_tlv_len, le_tlv,
  ------------------
  |  Branch (1243:7): [True: 0, False: 630]
  ------------------
 1244|    630|				     &le_tlv_len, exdata->smtype))
 1245|      0|			return -1;
 1246|       |
 1247|    634|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1247:6): [True: 71, False: 563]
  |  Branch (1247:36): [True: 1, False: 70]
  |  Branch (1247:54): [True: 0, False: 1]
  |  Branch (1247:77): [True: 0, False: 0]
  ------------------
 1248|      0|		if (0 != construct_mac_tlv_case1(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1248:7): [True: 0, False: 0]
  ------------------
 1249|      0|			return -1;
 1250|    634|	} else {
 1251|    634|		if (0 != construct_mac_tlv(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1251:7): [True: 0, False: 634]
  ------------------
 1252|      0|			return -1;
 1253|    634|	}
 1254|       |
 1255|    634|	memset(apdu_buf + 4, 0, *apdu_buf_len - 4);
 1256|    634|	sm->lc = sm->datalen = data_tlv_len + le_tlv_len + mac_tlv_len;
 1257|    634|	if (sm->lc > 0xFF) {
  ------------------
  |  Branch (1257:6): [True: 0, False: 634]
  ------------------
 1258|      0|		sm->cse = SC_APDU_CASE_4_EXT;
  ------------------
  |  |  299|      0|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|      0|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1259|      0|		apdu_buf[4] = (unsigned char)((sm->lc) / 0x10000);
 1260|      0|		apdu_buf[5] = (unsigned char)(((sm->lc) / 0x100) % 0x100);
 1261|      0|		apdu_buf[6] = (unsigned char)((sm->lc) % 0x100);
 1262|      0|		tmp_lc = 3;
 1263|    634|	} else {
 1264|    634|		apdu_buf[4] = (unsigned char)sm->lc;
 1265|    634|		tmp_lc = 1;
 1266|    634|	}
 1267|       |
 1268|       |	/* 2 is for Le extension in the worst case */
 1269|    634|	expected_total_len = 4 + tmp_lc + data_tlv_len + le_tlv_len + mac_tlv_len + 2;
 1270|       |
 1271|    634|	if (expected_total_len > *apdu_buf_len) {
  ------------------
  |  Branch (1271:6): [True: 0, False: 634]
  ------------------
 1272|      0|	    return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1273|      0|	}
 1274|       |
 1275|    634|	memcpy(apdu_buf + 4 + tmp_lc, dataTLV, data_tlv_len);
 1276|    634|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len, le_tlv, le_tlv_len);
 1277|    634|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len + le_tlv_len, mac_tlv, mac_tlv_len);
 1278|    634|	memcpy((unsigned char *)sm->data, apdu_buf + 4 + tmp_lc, sm->datalen);
 1279|    634|	*apdu_buf_len = 0;
 1280|       |
 1281|    634|	if (4 == le_tlv_len) {
  ------------------
  |  Branch (1281:6): [True: 12, False: 622]
  ------------------
 1282|     12|		sm->cse = SC_APDU_CASE_4_EXT;
  ------------------
  |  |  299|     12|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|     12|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     12|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1283|     12|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)(plain->le / 0x100);
 1284|     12|		*(apdu_buf + 4 + tmp_lc + sm->lc + 1) = (unsigned char)(plain->le % 0x100);
 1285|     12|		tmp_le = 2;
 1286|    622|	} else if (3 == le_tlv_len) {
  ------------------
  |  Branch (1286:13): [True: 618, False: 4]
  ------------------
 1287|    618|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)plain->le;
 1288|    618|		tmp_le = 1;
 1289|    618|	}
 1290|       |
 1291|    634|	*apdu_buf_len += 4 + tmp_lc + data_tlv_len + le_tlv_len + mac_tlv_len + tmp_le;
 1292|       |	/* sm->le = calc_le(plain_le); */
 1293|    634|	return 0;
 1294|    634|}
card-epass2003.c:construct_data_tlv:
  950|    632|{
  951|    632|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    632|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (951:23): [True: 102, False: 530]
  ------------------
  952|    632|	unsigned char pad[4096] = {0};
  953|    632|	size_t pad_len;
  954|    632|	size_t tlv_more;	/* increased tlv length */
  955|    632|	unsigned char iv[16] = {0};
  956|    632|	epass2003_exdata *exdata = NULL;
  957|    632|	int r = 0;
  958|       |
  959|    632|	if (!card->drv_data)
  ------------------
  |  Branch (959:6): [True: 0, False: 632]
  ------------------
  960|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  961|       |
  962|    632|	exdata = (epass2003_exdata *)card->drv_data;
  963|       |
  964|       |	/* we encrypt the pad buffer and then write it to the apdu_buf at offset block_size + tlv_more */
  965|    632|	if (apdu->lc >= sizeof(pad) - block_size - 5)
  ------------------
  |  Branch (965:6): [True: 0, False: 632]
  ------------------
  966|    632|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  967|    632|				"ePass2003 secure messaging APDU data too large");
  968|       |
  969|       |	/* padding */
  970|    632|	apdu_buf[block_size] = 0x87;
  971|    632|	memcpy(pad, apdu->data, apdu->lc);
  972|    632|	pad[apdu->lc] = 0x80;
  973|    632|	if ((apdu->lc + 1) % block_size)
  ------------------
  |  Branch (973:6): [True: 629, False: 3]
  ------------------
  974|    629|		pad_len = ((apdu->lc + 1) / block_size + 1) * block_size;
  975|      3|	else
  976|      3|		pad_len = apdu->lc + 1;
  977|       |
  978|       |	/* encode Lc' */
  979|    632|	if (pad_len > 0x7E) {
  ------------------
  |  Branch (979:6): [True: 0, False: 632]
  ------------------
  980|       |		/* Lc' > 0x7E, use extended APDU */
  981|      0|		apdu_buf[block_size + 1] = 0x82;
  982|      0|		apdu_buf[block_size + 2] = (unsigned char)((pad_len + 1) / 0x100);
  983|      0|		apdu_buf[block_size + 3] = (unsigned char)((pad_len + 1) % 0x100);
  984|      0|		apdu_buf[block_size + 4] = 0x01;
  985|      0|		tlv_more = 5;
  986|    632|	} else {
  987|    632|		apdu_buf[block_size + 1] = (unsigned char)pad_len + 1;
  988|    632|		apdu_buf[block_size + 2] = 0x01;
  989|    632|		tlv_more = 3;
  990|    632|	}
  991|    632|	memcpy(data_tlv, &apdu_buf[block_size], tlv_more);
  992|       |
  993|       |	/* encrypt Data */
  994|    632|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    632|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (994:6): [True: 102, False: 530]
  ------------------
  995|    102|		r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
  996|    102|		LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc failed");
  ------------------
  |  |  174|    102|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    102|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    102|	int _ret = (r); \
  |  |  |  |  168|    102|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  997|    530|	} else {
  998|    530|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
  999|    530|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_cbc failed");
  ------------------
  |  |  174|    530|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    530|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    530|	int _ret = (r); \
  |  |  |  |  168|    530|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 530]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    530|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 530]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1000|    530|	}
 1001|       |
 1002|    632|	memcpy(data_tlv + tlv_more, apdu_buf + block_size + tlv_more, pad_len);
 1003|    632|	*data_tlv_len = tlv_more + pad_len;
 1004|    632|	return 0;
 1005|    632|}
card-epass2003.c:construct_le_tlv:
 1012|    630|{
 1013|    630|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    630|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1013:23): [True: 99, False: 531]
  ------------------
 1014|       |
 1015|    630|	*(apdu_buf + block_size + data_tlv_len) = 0x97;
 1016|    630|	if (apdu->le > 0x7F) {
  ------------------
  |  Branch (1016:6): [True: 12, False: 618]
  ------------------
 1017|       |		/* Le' > 0x7E, use extended APDU */
 1018|     12|		*(apdu_buf + block_size + data_tlv_len + 1) = 2;
 1019|     12|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)(apdu->le / 0x100);
 1020|     12|		*(apdu_buf + block_size + data_tlv_len + 3) = (unsigned char)(apdu->le % 0x100);
 1021|     12|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 4);
 1022|     12|		*le_tlv_len = 4;
 1023|    618|	} else {
 1024|    618|		*(apdu_buf + block_size + data_tlv_len + 1) = 1;
 1025|    618|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)apdu->le;
 1026|    618|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 3);
 1027|    618|		*le_tlv_len = 3;
 1028|    618|	}
 1029|    630|	return 0;
 1030|    630|}
card-epass2003.c:des_encrypt_cbc:
  588|  1.07k|{
  589|  1.07k|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  590|  1.07k|	int r;
  591|       |
  592|  1.07k|	r = openssl_enc(alg, key, iv, input, length, output);
  593|  1.07k|	sc_evp_cipher_free(alg);
  594|  1.07k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (594:6): [True: 0, False: 1.07k]
  ------------------
  595|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  596|  1.07k|	return r;
  597|  1.07k|}
card-epass2003.c:des_decrypt_cbc:
  603|    538|{
  604|    538|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  605|    538|	int r;
  606|       |
  607|    538|	r = openssl_dec(alg, key, iv, input, length, output);
  608|    538|	sc_evp_cipher_free(alg);
  609|    538|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    538|#define SC_SUCCESS				0
  ------------------
  |  Branch (609:6): [True: 0, False: 538]
  ------------------
  610|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  611|    538|	return r;
  612|    538|}
card-epass2003.c:openssl_dec:
  313|    549|{
  314|    549|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    549|#define SC_ERROR_INTERNAL			-1400
  ------------------
  315|    549|	EVP_CIPHER_CTX * ctx = NULL;
  316|    549|	int outl = 0;
  317|    549|	int outl_tmp = 0;
  318|    549|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  319|       |
  320|    549|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  321|    549|	ctx = EVP_CIPHER_CTX_new();
  322|    549|	if (ctx == NULL)
  ------------------
  |  Branch (322:6): [True: 0, False: 549]
  ------------------
  323|      0|		goto out;
  324|       |
  325|    549|	if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
  ------------------
  |  Branch (325:6): [True: 0, False: 549]
  ------------------
  326|    549|			!EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (326:4): [True: 0, False: 549]
  ------------------
  327|      0|		goto out;
  328|       |
  329|    549|	if (!EVP_DecryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (329:6): [True: 0, False: 549]
  ------------------
  330|      0|		goto out;
  331|       |
  332|    549|	if (!EVP_DecryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (332:6): [True: 9, False: 540]
  ------------------
  333|      9|		goto out;
  334|       |
  335|    540|	r = SC_SUCCESS;
  ------------------
  |  |   28|    540|#define SC_SUCCESS				0
  ------------------
  336|    549|out:
  337|    549|	EVP_CIPHER_CTX_free(ctx);
  338|    549|	return r;
  339|    540|}
card-epass2003.c:construct_mac_tlv:
 1037|    634|{
 1038|    634|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    634|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1038:23): [True: 103, False: 531]
  ------------------
 1039|    634|	unsigned char mac[4096] = {0};
 1040|    634|	size_t mac_len;
 1041|    634|	unsigned char icv[16] = {0};
 1042|    634|	int r ;
 1043|    634|	int i = (KEY_TYPE_AES == key_type ? 15 : 7);
  ------------------
  |  |   80|    634|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1043:11): [True: 103, False: 531]
  ------------------
 1044|    634|	epass2003_exdata *exdata = NULL;
 1045|       |
 1046|    634|	if (!card->drv_data)
  ------------------
  |  Branch (1046:6): [True: 0, False: 634]
  ------------------
 1047|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1048|       |
 1049|    634|	exdata = (epass2003_exdata *)card->drv_data;
 1050|       |
 1051|    634|	if (data_tlv_len + le_tlv_len + block_size + 1 > sizeof(mac)) {
  ------------------
  |  Branch (1051:6): [True: 0, False: 634]
  ------------------
 1052|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1053|      0|	}
 1054|       |
 1055|    634|	if (0 == data_tlv_len && 0 == le_tlv_len) {
  ------------------
  |  Branch (1055:6): [True: 2, False: 632]
  |  Branch (1055:27): [True: 0, False: 2]
  ------------------
 1056|      0|		mac_len = block_size;
 1057|    634|	} else {
 1058|       |		/* padding */
 1059|    634|		*(apdu_buf + block_size + data_tlv_len + le_tlv_len) = 0x80;
 1060|    634|		if ((data_tlv_len + le_tlv_len + 1) % block_size) {
  ------------------
  |  Branch (1060:7): [True: 622, False: 12]
  ------------------
 1061|    622|			mac_len = (((data_tlv_len + le_tlv_len + 1) / block_size) +
 1062|    622|					1) * block_size + block_size;
 1063|    622|		} else {
 1064|     12|			mac_len = data_tlv_len + le_tlv_len + 1 + block_size;
 1065|     12|		}
 1066|    634|		memset((apdu_buf + block_size + data_tlv_len + le_tlv_len + 1),
 1067|    634|		       0, (mac_len - (data_tlv_len + le_tlv_len + 1)));
 1068|    634|	}
 1069|       |
 1070|       |	/* increase icv */
 1071|    634|	for (; i >= 0; i--) {
  ------------------
  |  Branch (1071:9): [True: 634, False: 0]
  ------------------
 1072|    634|		if (exdata->icv_mac[i] == 0xff) {
  ------------------
  |  Branch (1072:7): [True: 0, False: 634]
  ------------------
 1073|      0|			exdata->icv_mac[i] = 0;
 1074|    634|		} else {
 1075|    634|			exdata->icv_mac[i]++;
 1076|    634|			break;
 1077|    634|		}
 1078|    634|	}
 1079|       |
 1080|       |	/* calculate MAC */
 1081|    634|	memset(icv, 0, sizeof(icv));
 1082|    634|	memcpy(icv, exdata->icv_mac, 16);
 1083|    634|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    634|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1083:6): [True: 103, False: 531]
  ------------------
 1084|    103|		if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1084:7): [True: 71, False: 32]
  ------------------
 1085|  1.20k|			for (int i = 0; i < 16; i++) {
  ------------------
  |  Branch (1085:20): [True: 1.13k, False: 71]
  ------------------
 1086|  1.13k|				apdu_buf[i] = apdu_buf[i] ^ icv[i];
 1087|  1.13k|			}
 1088|     71|			r = aes128_encrypt_cmac(card, exdata->sk_mac, 128, apdu_buf, data_tlv_len + le_tlv_len + block_size, mac);
 1089|     71|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac failed");
  ------------------
  |  |  174|     71|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     71|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     71|	int _ret = (r); \
  |  |  |  |  168|     71|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     71|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|     71|			memcpy(mac_tlv + 2, &mac[0 /*ulmacLen-16*/], 8);
 1091|    355|			for (int j = 0; j < 4; j++) {
  ------------------
  |  Branch (1091:20): [True: 284, False: 71]
  ------------------
 1092|    284|				apdu_buf[j] = apdu_buf[j] ^ icv[j];
 1093|    284|			}
 1094|     71|		} else {
 1095|     32|			r = aes128_encrypt_cbc(card, exdata->sk_mac, 16, icv, apdu_buf, mac_len, mac);
 1096|     32|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc failed");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1097|     32|			memcpy(mac_tlv + 2, &mac[mac_len - 16], 8);
 1098|     32|		}
 1099|    531|	} else {
 1100|    531|		unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
 1101|    531|		unsigned char tmp[8] = {0};
 1102|    531|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, icv, apdu_buf, mac_len, mac);
 1103|    531|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 1 failed");
  ------------------
  |  |  174|    531|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    531|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    531|	int _ret = (r); \
  |  |  |  |  168|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|    531|		r = des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv, &mac[mac_len - 8], 8, tmp);
 1105|    531|		LOG_TEST_RET(card->ctx, r, "des_decrypt_cbc failed");
  ------------------
  |  |  174|    531|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    531|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    531|	int _ret = (r); \
  |  |  |  |  168|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1106|    531|		memset(iv, 0x00, sizeof iv);
 1107|    531|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, iv, tmp, 8, mac_tlv + 2);
 1108|    531|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 2 failed");
  ------------------
  |  |  174|    531|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    531|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    531|	int _ret = (r); \
  |  |  |  |  168|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|    531|	}
 1110|       |
 1111|    634|	*mac_tlv_len = 2 + 8;
 1112|    634|	return 0;
 1113|    634|}
card-epass2003.c:epass2003_sm_free_wrapped_apdu:
 1552|  2.18k|{
 1553|  2.18k|	struct sc_context *ctx = card->ctx;
 1554|  2.18k|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|  2.18k|#define SC_SUCCESS				0
  ------------------
 1555|       |
 1556|  2.18k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1557|  2.18k|	if (!sm_apdu)
  ------------------
  |  Branch (1557:6): [True: 0, False: 2.18k]
  ------------------
 1558|  2.18k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1559|  2.18k|	if (!(*sm_apdu))
  ------------------
  |  Branch (1559:6): [True: 0, False: 2.18k]
  ------------------
 1560|  2.18k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1561|       |
 1562|       |
 1563|  2.18k|	if (plain)
  ------------------
  |  Branch (1563:6): [True: 2.18k, False: 0]
  ------------------
 1564|  2.18k|		rv = epass2003_sm_unwrap_apdu(card, *sm_apdu, plain);
 1565|       |
 1566|  2.18k|	if ((*sm_apdu)->data) {
  ------------------
  |  Branch (1566:6): [True: 2.18k, False: 0]
  ------------------
 1567|  2.18k|		unsigned char * p = (unsigned char *)((*sm_apdu)->data);
 1568|  2.18k|		free(p);
 1569|  2.18k|	}
 1570|  2.18k|	if ((*sm_apdu)->resp) {
  ------------------
  |  Branch (1570:6): [True: 2.18k, False: 0]
  ------------------
 1571|  2.18k|		free((*sm_apdu)->resp);
 1572|  2.18k|	}
 1573|       |
 1574|  2.18k|	free(*sm_apdu);
 1575|  2.18k|	*sm_apdu = NULL;
 1576|       |
 1577|  2.18k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.18k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.18k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.18k|	int _ret = r; \
  |  |  |  |  155|  2.18k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    613|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 613, False: 1.57k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.18k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.18k|	return _ret; \
  |  |  |  |  163|  2.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1578|  2.18k|}
card-epass2003.c:epass2003_sm_unwrap_apdu:
 1509|  2.18k|{
 1510|  2.18k|	int r;
 1511|  2.18k|	size_t len = 0;
 1512|  2.18k|	epass2003_exdata *exdata = NULL;
 1513|       |
 1514|  2.18k|	if (!card->drv_data)
  ------------------
  |  Branch (1514:6): [True: 0, False: 2.18k]
  ------------------
 1515|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1516|       |
 1517|  2.18k|	exdata = (epass2003_exdata *)card->drv_data;
 1518|       |
 1519|  2.18k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1520|       |
 1521|       |	/* verify MAC, and check if SW1,2 match SW1,2 encapsulated in SM */
 1522|  2.18k|	if (exdata->sm) {
  ------------------
  |  Branch (1522:6): [True: 634, False: 1.55k]
  ------------------
 1523|    634|		if (epass2003_check_response_mac_and_sw(card, sm)) {
  ------------------
  |  Branch (1523:7): [True: 590, False: 44]
  ------------------
 1524|    590|			sc_log(card->ctx, "MAC or SW incorrect");
  ------------------
  |  |   71|    590|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1525|    590|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    590|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1526|    590|		}
 1527|    634|	}
 1528|  1.59k|	r = sc_check_sw(card, sm->sw1, sm->sw2);
 1529|  1.59k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1529:6): [True: 1.08k, False: 508]
  ------------------
 1530|  1.08k|		if (exdata->sm) {
  ------------------
  |  Branch (1530:7): [True: 28, False: 1.05k]
  ------------------
 1531|     28|			len = plain->resplen;
 1532|     28|			if (0 != decrypt_response(card, sm->resp, sm->resplen, plain->resp, &len))
  ------------------
  |  Branch (1532:8): [True: 23, False: 5]
  ------------------
 1533|     23|				return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     23|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1534|  1.05k|		} else {
 1535|  1.05k|			memcpy(plain->resp, sm->resp, sm->resplen);
 1536|  1.05k|			len = sm->resplen;
 1537|  1.05k|		}
 1538|  1.08k|	}
 1539|       |
 1540|  1.57k|	plain->resplen = len;
 1541|  1.57k|	plain->sw1 = sm->sw1;
 1542|  1.57k|	plain->sw2 = sm->sw2;
 1543|       |
 1544|  1.57k|	sc_log(card->ctx, "unwrapped APDU: resplen %zu, SW %02X%02X", plain->resplen, plain->sw1, plain->sw2);
  ------------------
  |  |   71|  1.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1545|  1.57k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.57k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.57k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.57k|	int _ret = r; \
  |  |  |  |  155|  1.57k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.57k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.57k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.57k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.57k|	return _ret; \
  |  |  |  |  163|  1.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|  1.57k|}
card-epass2003.c:epass2003_check_response_mac_and_sw:
 1346|    634|{
 1347|    634|	unsigned char iv[16];
 1348|    634|	unsigned char *data = NULL, *mac = NULL;
 1349|    634|	size_t blocksize, mac_len;
 1350|    634|	int ret = -1;
 1351|    634|	size_t taglen;
 1352|    634|	const u8 *tag;
 1353|    634|	epass2003_exdata *exdata;
 1354|    634|	unsigned char *in = sm->resp;
 1355|    634|	unsigned char *alt_in;
 1356|    634|	size_t inlen = sm->resplen;
 1357|    634|	size_t len_correction;
 1358|       |
 1359|       |	/* card/ctx/drv_data is already checked by caller */
 1360|    634|	exdata = (epass2003_exdata *)card->drv_data;
 1361|       |
 1362|       |	/* The SM must contain at least TLV encoded SW and MAC fields. */
 1363|    634|	if (inlen < 14 )
  ------------------
  |  Branch (1363:6): [True: 465, False: 169]
  ------------------
 1364|    465|		return ret;
 1365|       |
 1366|       |	/* compare BER-TLV encoded SW (TAG 0x99) and raw SW */
 1367|    169|	alt_in = in;
 1368|    169|	tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x99, &taglen);
 1369|    169|	if (tag == NULL || taglen != 2) {
  ------------------
  |  Branch (1369:6): [True: 74, False: 95]
  |  Branch (1369:21): [True: 14, False: 81]
  ------------------
 1370|       |		/*
 1371|       |		 * It seems that the EPASS2003 firmware has some problem with BER-TLV encoding.
 1372|       |		 * Instead of (correct) TLV 87 81 81 [01 .. ..] incorrect TLV 87 81 [01 .. ..]
 1373|       |		 * is returned. There seems to be some proprietary fix for the faulty encoding
 1374|       |		 * in the decrypt_response() function, similar fix here:
 1375|       |		 */
 1376|     88|		if (0x01 == in[2] && 0x82 != in[1]) {
  ------------------
  |  Branch (1376:7): [True: 70, False: 18]
  |  Branch (1376:24): [True: 60, False: 10]
  ------------------
 1377|     60|			sc_log(card->ctx, "Workaround, wrong BER-TLV ?");
  ------------------
  |  |   71|     60|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1378|     60|			len_correction = in[1] + 2;
 1379|     60|			if (inlen < len_correction)
  ------------------
  |  Branch (1379:8): [True: 14, False: 46]
  ------------------
 1380|     14|				return ret;
 1381|     46|			inlen -= len_correction;
 1382|     46|			alt_in += len_correction;
 1383|     46|			tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x99, &taglen);
 1384|     46|			if (tag == NULL || taglen != 2)
  ------------------
  |  Branch (1384:8): [True: 28, False: 18]
  |  Branch (1384:23): [True: 3, False: 15]
  ------------------
 1385|     31|				return ret;
 1386|     46|		} else {
 1387|     28|			return ret;
 1388|     28|		}
 1389|     88|	}
 1390|     96|	if (sm->sw1 != tag[0] || sm->sw2 != tag[1])
  ------------------
  |  Branch (1390:6): [True: 18, False: 78]
  |  Branch (1390:27): [True: 16, False: 62]
  ------------------
 1391|     34|		return ret;
 1392|       |
 1393|       |	/* no documentation/real hardware to test, the response is accepted without MAC check */
 1394|     62|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1394:6): [True: 43, False: 19]
  ------------------
 1395|     43|		sc_log(card->ctx, "Warning, MAC is not checked");
  ------------------
  |  |   71|     43|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1396|     43|		return 0;
 1397|     43|	}
 1398|     19|	tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x8e, &taglen);
 1399|     19|	if (tag == NULL || taglen != 8)
  ------------------
  |  Branch (1399:6): [True: 6, False: 13]
  |  Branch (1399:21): [True: 1, False: 12]
  ------------------
 1400|      7|		return ret;
 1401|       |
 1402|     12|	if (KEY_TYPE_AES == exdata->smtype)
  ------------------
  |  |   80|     12|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1402:6): [True: 5, False: 7]
  ------------------
 1403|      5|		blocksize = 16;
 1404|      7|	else
 1405|      7|		blocksize = 8;
 1406|       |
 1407|     12|	mac_len = tag - in - 2;
 1408|     12|	if (NULL == (data = calloc(1, mac_len + blocksize)))
  ------------------
  |  Branch (1408:6): [True: 0, False: 12]
  ------------------
 1409|      0|		goto end;
 1410|     12|	if (NULL == (mac = malloc(mac_len + blocksize)))
  ------------------
  |  Branch (1410:6): [True: 0, False: 12]
  ------------------
 1411|      0|		goto end;
 1412|       |
 1413|       |	/* copy response to buffer and append padding */
 1414|     12|	memcpy(data, in, mac_len);
 1415|     12|	data[mac_len++] = 0x80;
 1416|       |
 1417|     12|	if (mac_len % blocksize)
  ------------------
  |  Branch (1417:6): [True: 11, False: 1]
  ------------------
 1418|     11|		mac_len += (blocksize - (mac_len % blocksize));
 1419|       |
 1420|       |	/* calculate MAC */
 1421|     12|	memcpy(iv, exdata->icv_mac, blocksize);
 1422|       |
 1423|     12|	if (KEY_TYPE_AES == exdata->smtype) {
  ------------------
  |  |   80|     12|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1423:6): [True: 5, False: 7]
  ------------------
 1424|      5|		if (aes128_encrypt_cbc(card, exdata->sk_mac, 16, iv, data, mac_len, mac))
  ------------------
  |  Branch (1424:7): [True: 0, False: 5]
  ------------------
 1425|      0|			goto end;
 1426|      7|	} else {
 1427|      7|		uint8_t tmp[8];
 1428|      7|		uint8_t iv0[EVP_MAX_IV_LENGTH];
 1429|      7|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv, data, mac_len, mac))
  ------------------
  |  Branch (1429:7): [True: 0, False: 7]
  ------------------
 1430|      0|			goto end;
 1431|      7|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1432|      7|		if (des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv0, &mac[mac_len - 8], 8, tmp))
  ------------------
  |  Branch (1432:7): [True: 0, False: 7]
  ------------------
 1433|      0|			goto end;
 1434|      7|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1435|      7|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv0, tmp, 8, &mac[mac_len - 8]))
  ------------------
  |  Branch (1435:7): [True: 0, False: 7]
  ------------------
 1436|      0|			goto end;
 1437|      7|	}
 1438|       |	/* compare MAC */
 1439|     12|	if (!memcmp(tag, mac + mac_len - blocksize, 8))
  ------------------
  |  Branch (1439:6): [True: 1, False: 11]
  ------------------
 1440|      1|		ret = 0;
 1441|     12|end:
 1442|     12|	if (data)
  ------------------
  |  Branch (1442:6): [True: 12, False: 0]
  ------------------
 1443|     12|		free(data);
 1444|     12|	if (mac)
  ------------------
  |  Branch (1444:6): [True: 12, False: 0]
  ------------------
 1445|     12|		free(mac);
 1446|     12|	return ret;
 1447|     12|}
card-epass2003.c:decrypt_response:
 1462|     28|{
 1463|     28|	unsigned int cla = 0, tag = 0;
 1464|     28|	const unsigned char *p = in;
 1465|     28|	size_t cipher_len;
 1466|     28|	unsigned char iv[16] = {0};
 1467|     28|	unsigned char plaintext[4096] = {0};
 1468|     28|	epass2003_exdata *exdata = NULL;
 1469|       |
 1470|     28|	if (!card->drv_data)
  ------------------
  |  Branch (1470:6): [True: 0, False: 28]
  ------------------
 1471|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1472|       |
 1473|     28|	exdata = (epass2003_exdata *)card->drv_data;
 1474|       |
 1475|     28|	if (SC_SUCCESS != sc_asn1_read_tag(&p, inlen, &cla, &tag, &cipher_len) || p == NULL) {
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  |  Branch (1475:6): [True: 1, False: 27]
  |  Branch (1475:76): [True: 1, False: 26]
  ------------------
 1476|      2|		return -1;
 1477|      2|	}
 1478|     26|	if ((cla | tag) == 0x99)
  ------------------
  |  Branch (1478:6): [True: 1, False: 25]
  ------------------
 1479|      1|		return 0;
 1480|     25|	if ((cla | tag) != 0x87)
  ------------------
  |  Branch (1480:6): [True: 13, False: 12]
  ------------------
 1481|     13|		return -1;
 1482|       |
 1483|     12|	if (cipher_len < 2 || cipher_len > sizeof plaintext)
  ------------------
  |  Branch (1483:6): [True: 1, False: 11]
  |  Branch (1483:24): [True: 0, False: 11]
  ------------------
 1484|      1|		return -1;
 1485|       |
 1486|       |	/* Skip the 0x01 separator between tag and ciphertext */
 1487|     11|	p++;
 1488|       |	/* decrypt */
 1489|     11|	if (KEY_TYPE_AES == exdata->smtype)
  ------------------
  |  |   80|     11|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1489:6): [True: 11, False: 0]
  ------------------
 1490|     11|		aes128_decrypt_cbc(card, exdata->sk_enc, 16, iv, p, cipher_len - 1, plaintext);
 1491|      0|	else
 1492|      0|		des3_decrypt_cbc(card, exdata->sk_enc, 16, iv, p, cipher_len - 1, plaintext);
 1493|       |
 1494|       |	/* unpadding */
 1495|    383|	while (0x80 != plaintext[cipher_len - 2] && (cipher_len > 2))
  ------------------
  |  Branch (1495:9): [True: 378, False: 5]
  |  Branch (1495:46): [True: 372, False: 6]
  ------------------
 1496|    372|		cipher_len--;
 1497|       |
 1498|     11|	if (2 == cipher_len || *out_len < cipher_len - 2)
  ------------------
  |  Branch (1498:6): [True: 7, False: 4]
  |  Branch (1498:25): [True: 0, False: 4]
  ------------------
 1499|      7|		return -1;
 1500|       |
 1501|      4|	memcpy(out, plaintext, cipher_len - 2);
 1502|      4|	*out_len = cipher_len - 2;
 1503|      4|	return 0;
 1504|     11|}
card-epass2003.c:aes128_decrypt_cbc:
  504|     11|{
  505|     11|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-CBC");
  506|     11|	int r;
  507|     11|	r = openssl_dec(alg, key, iv, input, length, output);
  508|     11|	sc_evp_cipher_free(alg);
  509|     11|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  |  Branch (509:6): [True: 9, False: 2]
  ------------------
  510|      9|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      9|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  511|     11|	return r;
  512|     11|}
card-epass2003.c:epass2003_finish:
 1777|    621|{
 1778|    621|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
 1779|       |
 1780|    621|	if (exdata)
  ------------------
  |  Branch (1780:6): [True: 621, False: 0]
  ------------------
 1781|    621|		free(exdata);
 1782|    621|	return SC_SUCCESS;
  ------------------
  |  |   28|    621|#define SC_SUCCESS				0
  ------------------
 1783|    621|}
card-epass2003.c:epass2003_select_file:
 2023|  3.04k|{
 2024|  3.04k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2025|       |
 2026|  3.04k|	switch (in_path->type) {
 2027|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (2027:2): [True: 0, False: 3.04k]
  ------------------
 2028|      0|		if (in_path->len != 2)
  ------------------
  |  Branch (2028:7): [True: 0, False: 0]
  ------------------
 2029|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2030|      0|		return epass2003_select_fid(card, in_path->value[0], in_path->value[1], file_out);
 2031|  1.17k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  1.17k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2031:2): [True: 1.17k, False: 1.87k]
  ------------------
 2032|  1.17k|		return epass2003_select_aid(card, in_path, file_out);
 2033|  1.87k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.87k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (2033:2): [True: 1.87k, False: 1.17k]
  ------------------
 2034|  1.87k|		return epass2003_select_path(card, in_path->value, in_path->len, file_out);
 2035|      0|	default:
  ------------------
  |  Branch (2035:2): [True: 0, False: 3.04k]
  ------------------
 2036|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2037|  3.04k|	}
 2038|  3.04k|}
card-epass2003.c:epass2003_select_fid:
 1936|  2.46k|{
 1937|  2.46k|	int r;
 1938|  2.46k|	sc_file_t *file = NULL;
 1939|  2.46k|	sc_path_t path;
 1940|       |
 1941|  2.46k|	memset(&path, 0, sizeof(path));
 1942|  2.46k|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  2.46k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1943|  2.46k|	path.value[0] = id_hi;
 1944|  2.46k|	path.value[1] = id_lo;
 1945|  2.46k|	path.len = 2;
 1946|       |
 1947|  2.46k|	r = epass2003_select_fid_(card, &path, &file);
 1948|  2.46k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.46k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.46k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.46k|	int _ret = (r); \
  |  |  |  |  168|  2.46k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.57k, False: 889]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.57k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.57k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.57k|		return _ret; \
  |  |  |  |  172|  1.57k|	} \
  |  |  |  |  173|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 889]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1949|       |
 1950|    889|	if (file_out) {
  ------------------
  |  Branch (1950:6): [True: 126, False: 763]
  ------------------
 1951|    126|		*file_out = file;
 1952|    763|	} else {
 1953|    763|		sc_file_free(file);
 1954|    763|	}
 1955|       |
 1956|    889|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    889|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    889|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    889|	int _ret = r; \
  |  |  |  |  155|    889|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 889, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    889|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 889]
  |  |  |  |  ------------------
  |  |  |  |  157|    889|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    889|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    889|	return _ret; \
  |  |  |  |  163|    889|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1957|    889|}
card-epass2003.c:epass2003_select_fid_:
 1841|  2.46k|{
 1842|  2.46k|	struct sc_apdu apdu;
 1843|  2.46k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1844|  2.46k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
 1845|  2.46k|	int r;
 1846|  2.46k|	size_t pathlen;
 1847|  2.46k|	sc_file_t *file = NULL;
 1848|       |
 1849|  2.46k|	r = epass2003_hook_path(in_path, 1);
 1850|  2.46k|	LOG_TEST_RET(card->ctx, r, "Can not hook path");
  ------------------
  |  |  174|  2.46k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.46k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.46k|	int _ret = (r); \
  |  |  |  |  168|  2.46k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|       |
 1852|  2.46k|	memcpy(path, in_path->value, in_path->len);
 1853|  2.46k|	pathlen = in_path->len;
 1854|       |
 1855|  2.46k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  2.46k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1856|       |
 1857|  2.46k|	switch (in_path->type) {
 1858|  2.46k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  2.46k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1858:2): [True: 2.46k, False: 0]
  ------------------
 1859|  2.46k|		apdu.p1 = 0;
 1860|  2.46k|		if (pathlen != 2)
  ------------------
  |  Branch (1860:7): [True: 0, False: 2.46k]
  ------------------
 1861|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1862|  2.46k|		break;
 1863|  2.46k|	default:
  ------------------
  |  Branch (1863:2): [True: 0, False: 2.46k]
  ------------------
 1864|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1865|  2.46k|	}
 1866|  2.46k|	apdu.p2 = 0;		/* first record, return FCI */
 1867|  2.46k|	apdu.lc = pathlen;
 1868|  2.46k|	apdu.data = path;
 1869|  2.46k|	apdu.datalen = pathlen;
 1870|       |
 1871|  2.46k|	if (file_out != NULL) {
  ------------------
  |  Branch (1871:6): [True: 2.46k, False: 0]
  ------------------
 1872|  2.46k|		apdu.resp = buf;
 1873|  2.46k|		apdu.resplen = sizeof(buf);
 1874|  2.46k|		apdu.le = 0;
 1875|  2.46k|	} else {
 1876|      0|		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1876:14): [True: 0, False: 0]
  ------------------
 1877|      0|	}
 1878|       |
 1879|  2.46k|	if (path[0] == 0x29) {	/* TODO:0x29 accords with FID prefix in profile  */
  ------------------
  |  Branch (1879:6): [True: 9, False: 2.45k]
  ------------------
 1880|       |		/* Not allowed to select private key file, so fake fci. */
 1881|       |		/* 62 16 82 02 11 00 83 02 29 00 85 02 08 00 86 08 FF 90 90 90 FF FF FF FF */
 1882|      9|		apdu.resplen = 0x18;
 1883|      9|		memcpy(apdu.resp,
 1884|      9|		       "\x6f\x16\x82\x02\x11\x00\x83\x02\x29\x00\x85\x02\x08\x00\x86\x08\xff\x90\x90\x90\xff\xff\xff\xff",
 1885|      9|		       apdu.resplen);
 1886|      9|		apdu.resp[9] = path[1];
 1887|      9|		apdu.sw1 = 0x90;
 1888|      9|		apdu.sw2 = 0x00;
 1889|      9|	}
 1890|  2.45k|	else {
 1891|  2.45k|		r = sc_transmit_apdu_t(card, &apdu);
 1892|  2.45k|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.45k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.45k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.45k|	int _ret = (r); \
  |  |  |  |  168|  2.45k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 612, False: 1.84k]
  |  |  |  |  ------------------
  |  |  |  |  169|    612|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    612|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    612|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    612|		return _ret; \
  |  |  |  |  172|    612|	} \
  |  |  |  |  173|  2.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|  2.45k|	}
 1894|       |
 1895|  1.85k|	if (file_out == NULL) {
  ------------------
  |  Branch (1895:6): [True: 0, False: 1.85k]
  ------------------
 1896|      0|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1896:7): [True: 0, False: 0]
  ------------------
 1897|      0|			LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1898|      0|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1899|      0|	}
 1900|       |
 1901|  1.85k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1902|  1.85k|	if (r)
  ------------------
  |  Branch (1902:6): [True: 910, False: 942]
  ------------------
 1903|  1.85k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    910|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    910|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    910|	int _ret = r; \
  |  |  |  |  155|    910|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 910, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    910|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    910|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 910, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    910|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    910|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    910|	return _ret; \
  |  |  |  |  163|    910|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1904|    942|	if (apdu.resplen < 2)
  ------------------
  |  Branch (1904:6): [True: 25, False: 917]
  ------------------
 1905|    942|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     25|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     25|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     25|	int _ret = r; \
  |  |  |  |  155|     25|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     25|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     25|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     25|	return _ret; \
  |  |  |  |  163|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1906|       |
 1907|    917|	switch (apdu.resp[0]) {
 1908|    889|	case 0x6F:
  ------------------
  |  Branch (1908:2): [True: 889, False: 28]
  ------------------
 1909|    889|		file = sc_file_new();
 1910|    889|		if (file == NULL)
  ------------------
  |  Branch (1910:7): [True: 0, False: 889]
  ------------------
 1911|    889|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1912|    889|		file->path = *in_path;
 1913|    889|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (1913:7): [True: 0, False: 889]
  ------------------
 1914|      0|			sc_file_free(file);
 1915|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1916|      0|		}
 1917|       |
 1918|    889|		if ((size_t) apdu.resp[1] + 2 <= apdu.resplen)
  ------------------
  |  Branch (1918:7): [True: 736, False: 153]
  ------------------
 1919|    736|			card->ops->process_fci(card, file, apdu.resp + 2, apdu.resp[1]);
 1920|    889|		epass2003_hook_file(file, 0);
 1921|    889|		*file_out = file;
 1922|    889|		break;
 1923|     11|	case 0x00:		/* proprietary coding */
  ------------------
  |  Branch (1923:2): [True: 11, False: 906]
  ------------------
 1924|     11|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1925|      0|		break;
 1926|     17|	default:
  ------------------
  |  Branch (1926:2): [True: 17, False: 900]
  ------------------
 1927|     17|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1928|    917|	}
 1929|    889|	return 0;
 1930|    917|}
card-epass2003.c:epass2003_hook_path:
 1789|  3.35k|{
 1790|  3.35k|	u8 fid_h = 0;
 1791|  3.35k|	u8 fid_l = 0;
 1792|       |
 1793|  3.35k|	if (!path || path->len < 2)
  ------------------
  |  Branch (1793:6): [True: 0, False: 3.35k]
  |  Branch (1793:15): [True: 0, False: 3.35k]
  ------------------
 1794|      0|		return -1;
 1795|  3.35k|	fid_h = path->value[path->len - 2];
 1796|  3.35k|	fid_l = path->value[path->len - 1];
 1797|       |
 1798|  3.35k|	switch (fid_h) {
 1799|     18|	case 0x29:
  ------------------
  |  Branch (1799:2): [True: 18, False: 3.33k]
  ------------------
 1800|     28|	case 0x30:
  ------------------
  |  Branch (1800:2): [True: 10, False: 3.34k]
  ------------------
 1801|     38|	case 0x31:
  ------------------
  |  Branch (1801:2): [True: 10, False: 3.34k]
  ------------------
 1802|     48|	case 0x32:
  ------------------
  |  Branch (1802:2): [True: 10, False: 3.34k]
  ------------------
 1803|     58|	case 0x33:
  ------------------
  |  Branch (1803:2): [True: 10, False: 3.34k]
  ------------------
 1804|     68|	case 0x34:
  ------------------
  |  Branch (1804:2): [True: 10, False: 3.34k]
  ------------------
 1805|     68|		if (inc)
  ------------------
  |  Branch (1805:7): [True: 39, False: 29]
  ------------------
 1806|     39|			fid_l = fid_l * FID_STEP;
  ------------------
  |  |  743|     39|#define FID_STEP 0x20
  ------------------
 1807|     29|		else
 1808|     29|			fid_l = fid_l / FID_STEP;
  ------------------
  |  |  743|     29|#define FID_STEP 0x20
  ------------------
 1809|     68|		path->value[path->len - 1] = fid_l;
 1810|     68|		return 1;
 1811|  3.28k|	default:
  ------------------
  |  Branch (1811:2): [True: 3.28k, False: 68]
  ------------------
 1812|  3.28k|		break;
 1813|  3.35k|	}
 1814|  3.28k|	return 0;
 1815|  3.35k|}
card-epass2003.c:epass2003_hook_file:
 1820|    889|{
 1821|    889|	int fidl = file->id & 0xff;
 1822|    889|	int fidh = file->id & 0xff00;
 1823|    889|	int rv = 0;
 1824|       |
 1825|    889|	rv = epass2003_hook_path(&file->path, inc);
 1826|       |
 1827|    889|	if (rv > 0) {
  ------------------
  |  Branch (1827:6): [True: 29, False: 860]
  ------------------
 1828|     29|		if (inc)
  ------------------
  |  Branch (1828:7): [True: 0, False: 29]
  ------------------
 1829|      0|			file->id = fidh + fidl * FID_STEP;
  ------------------
  |  |  743|      0|#define FID_STEP 0x20
  ------------------
 1830|     29|		else
 1831|     29|			file->id = fidh + fidl / FID_STEP;
  ------------------
  |  |  743|     29|#define FID_STEP 0x20
  ------------------
 1832|     29|	}
 1833|    889|	if (rv < 0)
  ------------------
  |  Branch (1833:6): [True: 0, False: 889]
  ------------------
 1834|      0|		return rv;
 1835|    889|	return SC_SUCCESS;
  ------------------
  |  |   28|    889|#define SC_SUCCESS				0
  ------------------
 1836|    889|}
card-epass2003.c:epass2003_select_aid:
 1962|  1.17k|{
 1963|  1.17k|	int r = 0;
 1964|       |
 1965|  1.17k|	r = iso_ops->select_file(card, in_path, file_out);
 1966|  1.17k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.17k|	int _ret = (r); \
  |  |  |  |  168|  1.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.12k, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.12k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.12k|		return _ret; \
  |  |  |  |  172|  1.12k|	} \
  |  |  |  |  173|  1.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1967|       |
 1968|     49|	if (file_out) {
  ------------------
  |  Branch (1968:6): [True: 0, False: 49]
  ------------------
 1969|      0|		sc_file_t *file = *file_out;
 1970|       |
 1971|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
 1972|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
 1973|      0|		file->path.len = 0;
 1974|      0|		file->size = 0;
 1975|       |		/* AID */
 1976|      0|		memcpy(file->name, in_path->value, in_path->len);
 1977|      0|		file->namelen = in_path->len;
 1978|      0|		file->id = 0x0000;
 1979|      0|	}
 1980|       |
 1981|     49|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1982|     49|}
card-epass2003.c:epass2003_select_path:
 1988|  1.87k|{
 1989|  1.87k|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
 1990|  1.87k|	const u8 *path = pathbuf;
 1991|  1.87k|	size_t pathlen = len;
 1992|  1.87k|	unsigned int i;
 1993|  1.87k|	int r;
 1994|       |
 1995|  1.87k|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (1995:6): [True: 0, False: 1.87k]
  |  Branch (1995:26): [True: 1, False: 1.86k]
  |  Branch (1995:41): [True: 0, False: 1.86k]
  ------------------
 1996|  1.87k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1997|       |
 1998|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
 1999|  1.86k|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (1999:6): [True: 170, False: 1.69k]
  |  Branch (1999:23): [True: 1, False: 169]
  |  Branch (1999:42): [True: 1, False: 168]
  ------------------
 2000|  1.86k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2001|       |
 2002|       |	/* unify path (the first FID should be MF) */
 2003|  1.86k|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (2003:6): [True: 85, False: 1.78k]
  |  Branch (2003:25): [True: 3, False: 1.77k]
  ------------------
 2004|     88|		n_pathbuf[0] = 0x3f;
 2005|     88|		n_pathbuf[1] = 0x00;
 2006|     88|		memcpy(n_pathbuf + 2, path, pathlen);
 2007|     88|		path = n_pathbuf;
 2008|     88|		pathlen += 2;
 2009|     88|	}
 2010|       |
 2011|  2.46k|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (2011:14): [True: 2.00k, False: 460]
  ------------------
 2012|  2.00k|		r = epass2003_select_fid(card, path[i], path[i + 1], NULL);
 2013|  2.00k|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|  2.00k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.00k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.00k|	int _ret = (r); \
  |  |  |  |  168|  2.00k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.40k, False: 597]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.40k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.40k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.40k|		return _ret; \
  |  |  |  |  172|  1.40k|	} \
  |  |  |  |  173|  2.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 597]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2014|  2.00k|	}
 2015|       |
 2016|    460|	return epass2003_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
 2017|  1.86k|}
card-epass2003.c:epass2003_card_ctl:
 3038|      6|{
 3039|      6|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      6|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      6|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3040|       |
 3041|      6|	sc_log(card->ctx, "cmd is %0lx", cmd);
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3042|      6|	switch (cmd) {
 3043|      0|	case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
  ------------------
  |  Branch (3043:2): [True: 0, False: 6]
  ------------------
 3044|      0|		return epass2003_write_key(card, (sc_epass2003_wkey_data *) ptr);
 3045|      0|	case SC_CARDCTL_ENTERSAFE_GENERATE_KEY:
  ------------------
  |  Branch (3045:2): [True: 0, False: 6]
  ------------------
 3046|      0|		return epass2003_gen_key(card, (sc_epass2003_gen_key_data *) ptr);
 3047|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (3047:2): [True: 0, False: 6]
  ------------------
 3048|      0|		return epass2003_erase_card(card);
 3049|      6|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (3049:2): [True: 6, False: 0]
  ------------------
 3050|      6|		return epass2003_get_serialnr(card, (sc_serial_number_t *) ptr);
 3051|      0|	default:
  ------------------
  |  Branch (3051:2): [True: 0, False: 6]
  ------------------
 3052|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3053|      6|	}
 3054|      6|}
card-epass2003.c:epass2003_get_serialnr:
 3019|      6|{
 3020|      6|	u8 rbuf[8];
 3021|      6|	size_t rbuf_len = sizeof(rbuf);
 3022|       |
 3023|      6|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      6|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      6|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3024|       |
 3025|      6|	if (SC_SUCCESS != get_data(card, 0x80, rbuf, rbuf_len))
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  |  Branch (3025:6): [True: 5, False: 1]
  ------------------
 3026|      5|		return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      5|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 3027|       |
 3028|      1|	card->serialnr.len = serial->len = 8;
 3029|      1|	memcpy(card->serialnr.value, rbuf, 8);
 3030|      1|	memcpy(serial->value, rbuf, 8);
 3031|       |
 3032|      1|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3033|      1|}
card-epass2003.c:epass2003_process_fci:
 2297|    736|{
 2298|    736|	sc_context_t *ctx = card->ctx;
 2299|    736|	size_t taglen, len = buflen;
 2300|    736|	const u8 *tag = NULL, *p = buf;
 2301|       |
 2302|    736|	sc_log(ctx, "processing FCI bytes");
  ------------------
  |  |   71|    736|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2303|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
 2304|    736|	if (tag != NULL && taglen == 2) {
  ------------------
  |  Branch (2304:6): [True: 67, False: 669]
  |  Branch (2304:21): [True: 47, False: 20]
  ------------------
 2305|     47|		file->id = (tag[0] << 8) | tag[1];
 2306|     47|		sc_log(ctx, "  file identifier: 0x%02X%02X", tag[0], tag[1]);
  ------------------
  |  |   71|     47|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2307|     47|	}
 2308|       |
 2309|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
 2310|    736|	if (tag != NULL && taglen > 0 && taglen < 3) {
  ------------------
  |  Branch (2310:6): [True: 93, False: 643]
  |  Branch (2310:21): [True: 61, False: 32]
  |  Branch (2310:35): [True: 34, False: 27]
  ------------------
 2311|     34|		file->size = tag[0];
 2312|     34|		if (taglen == 2)
  ------------------
  |  Branch (2312:7): [True: 11, False: 23]
  ------------------
 2313|     11|			file->size = (file->size << 8) + tag[1];
 2314|     34|		sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|     34|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2315|     34|	}
 2316|       |
 2317|    736|	if (tag == NULL) {
  ------------------
  |  Branch (2317:6): [True: 643, False: 93]
  ------------------
 2318|    643|		tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
 2319|    643|		if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (2319:7): [True: 57, False: 586]
  |  Branch (2319:22): [True: 33, False: 24]
  ------------------
 2320|     33|			int bytes = (tag[0] << 8) + tag[1];
 2321|       |
 2322|     33|			sc_log(ctx, "  bytes in file: %d", bytes);
  ------------------
  |  |   71|     33|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2323|     33|			file->size = bytes;
 2324|     33|		}
 2325|    643|	}
 2326|       |
 2327|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
 2328|    736|	if (tag != NULL) {
  ------------------
  |  Branch (2328:6): [True: 301, False: 435]
  ------------------
 2329|    301|		if (taglen > 0) {
  ------------------
  |  Branch (2329:7): [True: 278, False: 23]
  ------------------
 2330|    278|			unsigned char byte = tag[0];
 2331|    278|			const char *type;
 2332|       |
 2333|    278|			if (byte == 0x38) {
  ------------------
  |  Branch (2333:8): [True: 21, False: 257]
  ------------------
 2334|     21|				type = "DF";
 2335|     21|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     21|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2336|    257|			} else if (0x01 <= byte && byte <= 0x07) {
  ------------------
  |  Branch (2336:15): [True: 247, False: 10]
  |  Branch (2336:31): [True: 143, False: 104]
  ------------------
 2337|    143|				type = "working EF";
 2338|    143|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    143|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 2339|    143|				switch (byte) {
 2340|     21|				case 0x01:
  ------------------
  |  Branch (2340:5): [True: 21, False: 122]
  ------------------
 2341|     21|					file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     21|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 2342|     21|					break;
 2343|     19|				case 0x02:
  ------------------
  |  Branch (2343:5): [True: 19, False: 124]
  ------------------
 2344|     19|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     19|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2345|     19|					break;
 2346|     82|				case 0x04:
  ------------------
  |  Branch (2346:5): [True: 82, False: 61]
  ------------------
 2347|     82|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     82|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2348|     82|					break;
 2349|     21|				default:
  ------------------
  |  Branch (2349:5): [True: 21, False: 122]
  ------------------
 2350|     21|					break;
 2351|    143|				}
 2352|       |
 2353|    143|			} else if (0x10 == byte) {
  ------------------
  |  Branch (2353:15): [True: 18, False: 96]
  ------------------
 2354|     18|				type = "BSO";
 2355|     18|				file->type = SC_FILE_TYPE_BSO;
  ------------------
  |  |  217|     18|#define SC_FILE_TYPE_BSO		0x10
  ------------------
 2356|     96|			} else if (0x11 <= byte) {
  ------------------
  |  Branch (2356:15): [True: 82, False: 14]
  ------------------
 2357|     82|				type = "internal EF";
 2358|     82|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     82|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2359|     82|				switch (byte) {
 2360|     30|				case 0x11:
  ------------------
  |  Branch (2360:5): [True: 30, False: 52]
  ------------------
 2361|     30|					break;
 2362|     18|				case 0x12:
  ------------------
  |  Branch (2362:5): [True: 18, False: 64]
  ------------------
 2363|     18|					break;
 2364|     34|				default:
  ------------------
  |  Branch (2364:5): [True: 34, False: 48]
  ------------------
 2365|     34|					break;
 2366|     82|				}
 2367|     82|			} else {
 2368|     14|				type = "unknown";
 2369|     14|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     14|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2370|     14|			}
 2371|    278|			sc_log(ctx, "type %s, EF structure %d", type, byte);
  ------------------
  |  |   71|    278|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2372|    278|		}
 2373|    301|	}
 2374|       |
 2375|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
 2376|    736|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (2376:6): [True: 56, False: 680]
  |  Branch (2376:21): [True: 41, False: 15]
  |  Branch (2376:35): [True: 31, False: 10]
  ------------------
 2377|     31|		memcpy(file->name, tag, taglen);
 2378|     31|		file->namelen = taglen;
 2379|       |
 2380|     31|		sc_log_hex(ctx, "File name", file->name, file->namelen);
  ------------------
  |  |  129|     31|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     31|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2381|     31|		if (!file->type)
  ------------------
  |  Branch (2381:7): [True: 11, False: 20]
  ------------------
 2382|     11|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     11|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2383|     31|	}
 2384|       |
 2385|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
 2386|    736|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2386:6): [True: 84, False: 652]
  |  Branch (2386:21): [True: 53, False: 31]
  ------------------
 2387|     53|		sc_file_set_prop_attr(file, tag, taglen);
 2388|    683|	else
 2389|    683|		file->prop_attr_len = 0;
 2390|       |
 2391|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0xA5, &taglen);
 2392|    736|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2392:6): [True: 31, False: 705]
  |  Branch (2392:21): [True: 11, False: 20]
  ------------------
 2393|     11|		sc_file_set_prop_attr(file, tag, taglen);
 2394|       |
 2395|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x86, &taglen);
 2396|    736|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (2396:6): [True: 124, False: 612]
  |  Branch (2396:21): [True: 99, False: 25]
  ------------------
 2397|     99|		unsigned int i;
 2398|     99|		sc_file_set_sec_attr(file, tag, taglen);
 2399|  1.70k|		for (i = 0; i< taglen; i++)
  ------------------
  |  Branch (2399:15): [True: 1.60k, False: 99]
  ------------------
 2400|  1.60k|			if (tag[i] != 0xff) /* skip unused entries */
  ------------------
  |  Branch (2400:8): [True: 1.19k, False: 415]
  ------------------
 2401|  1.19k|				sec_attr_to_entry(card, file, i);
 2402|     99|	}
 2403|       |
 2404|    736|	tag = sc_asn1_find_tag(ctx, p, len, 0x8A, &taglen);
 2405|    736|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (2405:6): [True: 118, False: 618]
  |  Branch (2405:21): [True: 82, False: 36]
  ------------------
 2406|     82|		if (tag[0] == 0x01)
  ------------------
  |  Branch (2406:7): [True: 10, False: 72]
  ------------------
 2407|     10|			file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     10|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
 2408|     72|		else if (tag[0] == 0x07 || tag[0] == 0x05)
  ------------------
  |  Branch (2408:12): [True: 18, False: 54]
  |  Branch (2408:30): [True: 10, False: 44]
  ------------------
 2409|     28|			file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     28|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
 2410|     44|		else if (tag[0] == 0x06 || tag[0] == 0x04)
  ------------------
  |  Branch (2410:12): [True: 10, False: 34]
  |  Branch (2410:30): [True: 19, False: 15]
  ------------------
 2411|     29|			file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     29|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
 2412|     82|	}
 2413|    736|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    736|#define SC_FILE_MAGIC			0x14426950
  ------------------
 2414|       |
 2415|    736|	return 0;
 2416|    736|}
card-epass2003.c:epass2003_pin_cmd:
 3211|      6|{
 3212|      6|	int r;
 3213|      6|	u8 kid;
 3214|      6|	u8 retries = 0;
 3215|      6|	u8 pin_low = 3;
 3216|      6|	unsigned char maxtries = 0;
 3217|       |
 3218|      6|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      6|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      6|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3219|       |
 3220|      6|	internal_sanitize_pin_info(&data->pin1, 0);
 3221|      6|	internal_sanitize_pin_info(&data->pin2, 1);
 3222|      6|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      6|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 3223|      6|	kid = data->pin_reference;
 3224|       |
 3225|      6|	if (NULL == (unsigned char *)data->pin1.data || 0 == data->pin1.len)
  ------------------
  |  Branch (3225:6): [True: 6, False: 0]
  |  Branch (3225:50): [True: 0, False: 0]
  ------------------
 3226|      6|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_PIN_CODE_INCORRECT);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3227|       |
 3228|       |	/* get pin retries */
 3229|      0|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (3229:6): [True: 0, False: 0]
  ------------------
 3230|       |
 3231|      0|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3232|      0|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3232:7): [True: 0, False: 0]
  ------------------
 3233|      0|			data->pin1.tries_left = retries;
 3234|       |
 3235|      0|			r = get_external_key_maxtries(card, &maxtries);
 3236|      0|			LOG_TEST_RET(card->ctx, r, "get max counter failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3237|       |
 3238|      0|			data->pin1.max_tries = maxtries;
 3239|      0|		}
 3240|      0|		LOG_TEST_RET(card->ctx, r, "verify pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3241|      0|	} else if (data->cmd == SC_PIN_CMD_UNBLOCK) { /* verify */
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (3241:13): [True: 0, False: 0]
  ------------------
 3242|      0|		r = external_key_auth(card, (kid + 1), (unsigned char *)data->pin1.data,
 3243|      0|				data->pin1.len);
 3244|      0|		LOG_TEST_RET(card->ctx, r, "verify pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3245|      0|	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) { /* change */
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) { /* change */
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (3245:13): [True: 0, False: 0]
  |  Branch (3245:47): [True: 0, False: 0]
  ------------------
 3246|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3247|      0|				data->pin1.len);
 3248|      0|		LOG_TEST_RET(card->ctx, r, "verify pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3249|       |
 3250|      0|		r = update_secret_key(card, 0x04, kid, data->pin2.data,
 3251|      0|				(unsigned long)data->pin2.len);
 3252|      0|		LOG_TEST_RET(card->ctx, r, "change pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3253|      0|	} else {
 3254|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3255|      0|				data->pin1.len);
 3256|      0|		LOG_TEST_RET(card->ctx, r, "verify pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3257|       |
 3258|      0|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3259|      0|		if (retries < pin_low)
  ------------------
  |  Branch (3259:7): [True: 0, False: 0]
  ------------------
 3260|      0|			sc_log(card->ctx, "Verification failed (remaining tries: %d)", retries);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3261|       |
 3262|      0|		LOG_TEST_RET(card->ctx, r, "verify pin failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3263|      0|	}
 3264|       |
 3265|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3265:6): [True: 0, False: 0]
  ------------------
 3266|      0|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 3267|      0|	}
 3268|      0|	return r;
 3269|      0|}
card-epass2003.c:internal_sanitize_pin_info:
 3059|     12|{
 3060|     12|	pin->encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     12|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 3061|     12|	pin->min_length = 4;
 3062|     12|	pin->max_length = 16;
 3063|     12|	pin->pad_length = 16;
 3064|     12|	pin->offset = 5 + num * 16;
 3065|     12|	pin->pad_char = 0x00;
 3066|     12|}
card-epass2003.c:epass2003_check_sw:
  245|  6.80k|{
  246|  6.80k|	const int err_count = sizeof(epass2003_errors)/sizeof(epass2003_errors[0]);
  247|  6.80k|	int i;
  248|       |
  249|       |	/* Handle special cases here */
  250|  6.80k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (250:6): [True: 37, False: 6.77k]
  ------------------
  251|     37|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  252|     37|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     37|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  253|     37|	}
  254|       |
  255|   316k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (255:14): [True: 315k, False: 428]
  ------------------
  256|   315k|		if (epass2003_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (256:7): [True: 6.34k, False: 309k]
  ------------------
  257|  6.34k|			sc_log(card->ctx, "%s", epass2003_errors[i].errorstr);
  ------------------
  |  |   71|  6.34k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|  6.34k|			return epass2003_errors[i].errorno;
  259|  6.34k|		}
  260|   315k|	}
  261|       |
  262|    428|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|    428|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  263|    428|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    428|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  264|  6.77k|}

sc_get_esteid2018_driver:
  303|  15.2k|struct sc_card_driver *sc_get_esteid2018_driver(void) {
  304|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  305|       |
  306|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (306:6): [True: 1, False: 15.2k]
  ------------------
  307|      1|		iso_ops = iso_drv->ops;
  308|       |
  309|  15.2k|	esteid_ops = *iso_drv->ops;
  310|  15.2k|	esteid_ops.match_card = esteid_match_card;
  311|  15.2k|	esteid_ops.init = esteid_init;
  312|  15.2k|	esteid_ops.finish = esteid_finish;
  313|       |
  314|  15.2k|	esteid_ops.select_file = esteid_select_file;
  315|       |
  316|  15.2k|	esteid_ops.set_security_env = esteid_set_security_env;
  317|  15.2k|	esteid_ops.compute_signature = esteid_compute_signature;
  318|  15.2k|	esteid_ops.pin_cmd = esteid_pin_cmd;
  319|  15.2k|	esteid_ops.logout = esteid_logout;
  320|       |
  321|  15.2k|	return &esteid2018_driver;
  322|  15.2k|}
card-esteid2018.c:esteid_match_card:
   83|  7.44k|static int esteid_match_card(sc_card_t *card) {
   84|  7.44k|	int i = _sc_match_atr(card, esteid_atrs, &card->type);
   85|       |
   86|  7.44k|	if (i >= 0 && gp_select_aid(card, &IASECC_AID) == SC_SUCCESS) {
  ------------------
  |  |   28|     65|#define SC_SUCCESS				0
  ------------------
  |  Branch (86:6): [True: 65, False: 7.38k]
  |  Branch (86:16): [True: 60, False: 5]
  ------------------
   87|     60|		card->name = esteid_atrs[i].name;
   88|     60|		return 1;
   89|     60|	}
   90|  7.38k|	return 0;
   91|  7.44k|}
card-esteid2018.c:esteid_init:
  271|     60|static int esteid_init(sc_card_t *card) {
  272|     60|	unsigned long flags, ext_flags;
  273|     60|	struct esteid_priv_data *priv;
  274|       |
  275|     60|	priv = calloc(1, sizeof *priv);
  276|     60|	if (!priv)
  ------------------
  |  Branch (276:6): [True: 0, False: 60]
  ------------------
  277|     60|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|     60|	card->drv_data = priv;
  279|     60|	card->max_recv_size = 233; // XXX: empirical, not documented
  280|       |	// Workaround for the 2018 v2 card, with reader Alcor Micro AU9540
  281|     60|	if (card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025) {
  ------------------
  |  Branch (281:6): [True: 0, False: 60]
  ------------------
  282|      0|		card->max_recv_size = 0xC0;
  283|      0|	}
  284|       |
  285|     60|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|     60|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|     60|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|     60|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     60|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  286|     60|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|     60|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|     60|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  287|       |
  288|     60|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
  289|       |
  290|     60|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     60|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     60|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     60|	int _ret = r; \
  |  |  |  |  155|     60|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 60, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  157|     60|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     60|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     60|	return _ret; \
  |  |  |  |  163|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|     60|}
card-esteid2018.c:esteid_finish:
  293|     60|static int esteid_finish(sc_card_t *card) {
  294|     60|	if (card != NULL)
  ------------------
  |  Branch (294:6): [True: 60, False: 0]
  ------------------
  295|     60|		free(DRVDATA(card));
  ------------------
  |  |   75|     60|#define DRVDATA(card) ((struct esteid_priv_data *)((card)->drv_data))
  ------------------
  296|     60|	return 0;
  297|     60|}
card-esteid2018.c:esteid_select_file:
   93|    272|static int esteid_select_file(struct sc_card *card, const struct sc_path *in_path, struct sc_file **file_out) {
   94|    272|	const u8 *path = in_path->value;
   95|    272|	u8 resp[SC_MAX_APDU_RESP_SIZE];
   96|    272|	size_t resplen = sizeof(resp);
   97|    272|	int r;
   98|    272|	struct sc_file *file = NULL;
   99|    272|	struct sc_apdu apdu;
  100|       |
  101|    272|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    272|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    272|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    272|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    272|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 272]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  102|       |
  103|       |	// Only support full paths
  104|    272|	if (in_path->type != SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|    272|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (104:6): [True: 58, False: 214]
  ------------------
  105|     58|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     58|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     58|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     58|	int _ret = r; \
  |  |  |  |  155|     58|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     58|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     58|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     58|	return _ret; \
  |  |  |  |  163|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|     58|	}
  107|    214|	if (in_path->len % 2 != 0) {
  ------------------
  |  Branch (107:6): [True: 0, False: 214]
  ------------------
  108|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|      0|	}
  110|       |
  111|    216|	for (size_t pathlen = in_path->len; pathlen >= 2; pathlen -= 2, path += 2) {
  ------------------
  |  Branch (111:38): [True: 212, False: 4]
  ------------------
  112|    212|		if (pathlen == 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (112:7): [True: 28, False: 184]
  |  Branch (112:23): [True: 3, False: 25]
  ------------------
  113|      3|			sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x00, 0x0C, path, 0, NULL, 0);
  114|      3|			SC_TRANSMIT_TEST_RET(card, apdu, "MF select failed");
  ------------------
  |  |   78|      3|	do { \
  |  |   79|      3|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 1, False: 2]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  |  |  172|      1|	} \
  |  |  |  |  |  |  173|      3|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   80|      3|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 1, False: 1]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  |  |  172|      1|	} \
  |  |  |  |  |  |  173|      2|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   81|      2|	} while (0)
  |  |  ------------------
  |  |  |  Branch (81:11): [Folded, False: 1]
  |  |  ------------------
  ------------------
  115|    209|		} else if (pathlen == 2 && path[0] == 0xAD) {
  ------------------
  |  Branch (115:14): [True: 25, False: 184]
  |  Branch (115:30): [True: 4, False: 21]
  ------------------
  116|      4|			sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x01, 0x0C, path, 2, NULL, 0);
  117|      4|			SC_TRANSMIT_TEST_RET(card, apdu, "DF select failed");
  ------------------
  |  |   78|      4|	do { \
  |  |   79|      4|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 1, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  |  |  172|      1|	} \
  |  |  |  |  |  |  173|      4|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   80|      4|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 2, False: 1]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  |  |  172|      2|	} \
  |  |  |  |  |  |  173|      3|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   81|      3|	} while (0)
  |  |  ------------------
  |  |  |  Branch (81:11): [Folded, False: 1]
  |  |  ------------------
  ------------------
  118|    205|		} else {
  119|    205|			sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x09, 0x04, path, pathlen, resp, resplen);
  120|    205|			SC_TRANSMIT_TEST_RET(card, apdu, "EF select failed");
  ------------------
  |  |   78|    205|	do { \
  |  |   79|    205|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|    205|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|    205|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|    205|	int _ret = (r); \
  |  |  |  |  |  |  168|    205|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 13, False: 192]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  |  |  172|     13|	} \
  |  |  |  |  |  |  173|    205|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 192]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   80|    205|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|    192|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|    192|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|    192|	int _ret = (r); \
  |  |  |  |  |  |  168|    192|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 101, False: 91]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  169|    101|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   44|    101|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  170|    101|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  |  |  171|    101|		return _ret; \
  |  |  |  |  |  |  172|    101|	} \
  |  |  |  |  |  |  173|    192|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   81|    192|	} while (0)
  |  |  ------------------
  |  |  |  Branch (81:11): [Folded, False: 91]
  |  |  ------------------
  ------------------
  121|       |
  122|     91|			if (file_out != NULL) {
  ------------------
  |  Branch (122:8): [True: 47, False: 44]
  ------------------
  123|     47|				file = sc_file_new();
  124|     47|				if (file == NULL)
  ------------------
  |  Branch (124:9): [True: 0, False: 47]
  ------------------
  125|     47|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  126|     47|				r = iso_ops->process_fci(card, file, resp, apdu.resplen);
  127|     47|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
  |  Branch (127:9): [True: 0, False: 47]
  ------------------
  128|      0|					sc_file_free(file);
  129|     47|				} else {
  130|     47|					*file_out = file;
  131|     47|				}
  132|     47|				LOG_TEST_RET(card->ctx, r, "Process fci failed");
  ------------------
  |  |  174|     47|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     47|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     47|	int _ret = (r); \
  |  |  |  |  168|     47|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  133|     47|			}
  134|     91|			break;
  135|     91|		}
  136|    212|	}
  137|     95|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     95|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     95|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     95|	int _ret = r; \
  |  |  |  |  155|     95|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 95, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     95|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 95]
  |  |  |  |  ------------------
  |  |  |  |  157|     95|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     95|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     95|	return _ret; \
  |  |  |  |  163|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|     95|}

sc_get_esteid2025_driver:
  220|  15.2k|{
  221|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  222|       |
  223|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (223:6): [True: 1, False: 15.2k]
  ------------------
  224|      1|		iso_ops = iso_drv->ops;
  225|       |
  226|  15.2k|	esteid_ops = *iso_drv->ops;
  227|  15.2k|	esteid_ops.match_card = esteid_match_card;
  228|  15.2k|	esteid_ops.init = esteid_init;
  229|       |
  230|  15.2k|	esteid_ops.select_file = esteid_select_file;
  231|       |
  232|  15.2k|	esteid_ops.set_security_env = esteid_set_security_env;
  233|  15.2k|	esteid_ops.compute_signature = esteid_compute_signature;
  234|  15.2k|	esteid_ops.pin_cmd = esteid_pin_cmd;
  235|  15.2k|	esteid_ops.logout = esteid_logout;
  236|       |
  237|  15.2k|	return &esteid2025_driver;
  238|  15.2k|}
card-esteid2025.c:esteid_match_card:
   65|  7.38k|{
   66|  7.38k|	int i = _sc_match_atr(card, esteid_atrs, &card->type);
   67|       |
   68|  7.38k|	if (i >= 0 && gp_select_aid(card, &THALES_AID) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (68:6): [True: 0, False: 7.38k]
  |  Branch (68:16): [True: 0, False: 0]
  ------------------
   69|      0|		card->name = esteid_atrs[i].name;
   70|      0|		return 1;
   71|      0|	}
   72|  7.38k|	return 0;
   73|  7.38k|}

sc_get_cryptoflex_driver:
 1203|  15.2k|{
 1204|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1204:6): [True: 0, False: 15.2k]
  ------------------
 1205|      0|		iso_ops = sc_get_iso7816_driver()->ops;
 1206|       |
 1207|  15.2k|	cryptoflex_ops = *iso_ops;
 1208|  15.2k|	cryptoflex_ops.match_card = cryptoflex_match_card;
 1209|  15.2k|	cryptoflex_ops.init = flex_init;
 1210|  15.2k|	cryptoflex_ops.finish = flex_finish;
 1211|  15.2k|	cryptoflex_ops.process_fci = cryptoflex_process_file_attrs;
 1212|  15.2k|	cryptoflex_ops.construct_fci = cryptoflex_construct_file_attrs;
 1213|  15.2k|	cryptoflex_ops.select_file = flex_select_file;
 1214|  15.2k|	cryptoflex_ops.list_files = cryptoflex_list_files;
 1215|  15.2k|	cryptoflex_ops.delete_file = flex_delete_file;
 1216|  15.2k|	cryptoflex_ops.create_file = flex_create_file;
 1217|  15.2k|	cryptoflex_ops.card_ctl = flex_card_ctl;
 1218|  15.2k|	cryptoflex_ops.set_security_env = flex_set_security_env;
 1219|  15.2k|	cryptoflex_ops.restore_security_env = flex_restore_security_env;
 1220|  15.2k|	cryptoflex_ops.compute_signature = cryptoflex_compute_signature;
 1221|  15.2k|	cryptoflex_ops.decipher = flex_decipher;
 1222|  15.2k|	cryptoflex_ops.pin_cmd = flex_pin_cmd;
 1223|  15.2k|	cryptoflex_ops.logout = flex_logout;
 1224|  15.2k|	return &cryptoflex_drv;
 1225|  15.2k|}
sc_get_cyberflex_driver:
 1228|  15.2k|{
 1229|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1229:6): [True: 1, False: 15.2k]
  ------------------
 1230|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1231|       |
 1232|  15.2k|	cyberflex_ops = *iso_ops;
 1233|  15.2k|	cyberflex_ops.match_card = cyberflex_match_card;
 1234|  15.2k|	cyberflex_ops.init = flex_init;
 1235|  15.2k|	cyberflex_ops.finish = flex_finish;
 1236|  15.2k|	cyberflex_ops.process_fci = cyberflex_process_file_attrs;
 1237|  15.2k|	cyberflex_ops.construct_fci = cyberflex_construct_file_attrs;
 1238|  15.2k|	cyberflex_ops.select_file = flex_select_file;
 1239|  15.2k|	cyberflex_ops.list_files = cyberflex_list_files;
 1240|  15.2k|	cyberflex_ops.delete_file = flex_delete_file;
 1241|  15.2k|	cyberflex_ops.create_file = flex_create_file;
 1242|  15.2k|	cyberflex_ops.card_ctl = flex_card_ctl;
 1243|  15.2k|	cyberflex_ops.set_security_env = flex_set_security_env;
 1244|  15.2k|	cyberflex_ops.restore_security_env = flex_restore_security_env;
 1245|  15.2k|	cyberflex_ops.compute_signature = cyberflex_compute_signature;
 1246|  15.2k|	cyberflex_ops.decipher = flex_decipher;
 1247|  15.2k|	cyberflex_ops.pin_cmd = flex_pin_cmd;
 1248|  15.2k|	cyberflex_ops.logout = flex_logout;
 1249|  15.2k|	return &cyberflex_drv;
 1250|  15.2k|}
card-flex.c:cryptoflex_match_card:
  134|  14.9k|{
  135|  14.9k|	int i;
  136|       |
  137|  14.9k|	i = _sc_match_atr(card, flex_atrs, NULL);
  138|  14.9k|	if (i < 0)
  ------------------
  |  Branch (138:6): [True: 14.7k, False: 190]
  ------------------
  139|  14.7k|		return 0;
  140|    190|	switch (flex_atrs[i].type) {
  ------------------
  |  Branch (140:10): [True: 190, False: 0]
  ------------------
  141|    190|	case SC_CARD_TYPE_FLEX_CRYPTO:
  ------------------
  |  Branch (141:2): [True: 190, False: 0]
  ------------------
  142|    190|	case SC_CARD_TYPE_FLEX_MULTI:
  ------------------
  |  Branch (142:2): [True: 0, False: 190]
  ------------------
  143|    190|		card->name = flex_atrs[i].name;
  144|    190|		card->type = flex_atrs[i].type;
  145|    190|		card->flags = flex_atrs[i].flags;
  146|    190|		return 1;
  147|    190|	}
  148|      0|	return 0;
  149|    190|}
card-flex.c:flex_init:
  169|    190|{
  170|    190|	struct flex_private_data *data;
  171|       |
  172|    190|	if (!(data = malloc(sizeof(*data))))
  ------------------
  |  Branch (172:6): [True: 0, False: 190]
  ------------------
  173|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  174|    190|	card->drv_data = data;
  175|       |
  176|    190|	card->cla = 0xC0;
  177|    190|	data->aak_key_ref = 1;
  178|       |
  179|       |	/* Override Cryptoflex defaults for specific card types */
  180|    190|	switch (card->type) {
  ------------------
  |  Branch (180:10): [True: 0, False: 190]
  ------------------
  181|      0|	case SC_CARD_TYPE_FLEX_CYBER:
  ------------------
  |  Branch (181:2): [True: 0, False: 190]
  ------------------
  182|      0|		card->cla = 0x00;
  183|      0|		data->aak_key_ref = 0;
  184|      0|		break;
  185|    190|	}
  186|       |
  187|       |	/* FIXME: Card type detection */
  188|    190|	if (1) {
  ------------------
  |  Branch (188:6): [True: 190, Folded]
  ------------------
  189|    190|		unsigned long flags;
  190|       |
  191|    190|		flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    190|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  192|    190|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    190|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  193|    190|		if (card->flags & FLAG_KEYGEN)
  ------------------
  |  |   31|    190|#define FLAG_KEYGEN		0x80000000
  ------------------
  |  Branch (193:7): [True: 190, False: 0]
  ------------------
  194|    190|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    190|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  195|       |
  196|    190|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  197|    190|		_sc_card_add_rsa_alg(card, 768, flags, 0);
  198|    190|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  199|    190|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  200|    190|	}
  201|       |
  202|       |	/* SCardTransmit failed: 8010002f
  203|       |	 * this can be solved with a small delay. */
  204|    190|	msleep(100);
  ------------------
  |  |   59|    190|#define msleep(t)	usleep((t) * 1000)
  ------------------
  205|       |
  206|       |	/* State that we have an RNG */
  207|    190|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    190|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  208|       |
  209|    190|	return 0;
  210|    190|}
card-flex.c:flex_finish:
  128|    190|{
  129|    190|	free(card->drv_data);
  130|    190|	return 0;
  131|    190|}
card-flex.c:cryptoflex_process_file_attrs:
  270|    155|{
  271|    155|	sc_context_t *ctx = card->ctx;
  272|    155|	const u8 *p = buf + 2;
  273|    155|	u8 b1, b2;
  274|    155|	int is_mf = 0;
  275|       |
  276|    155|	if (buflen < 14)
  ------------------
  |  Branch (276:6): [True: 0, False: 155]
  ------------------
  277|      0|		return -1;
  278|    155|	b1 = *p++;
  279|    155|	b2 = *p++;
  280|    155|	file->size = (b1 << 8) + b2;
  281|    155|	b1 = *p++;
  282|    155|	b2 = *p++;
  283|    155|	file->id = (b1 << 8) + b2;
  284|    155|	if (file->id == 0x3F00)
  ------------------
  |  Branch (284:6): [True: 8, False: 147]
  ------------------
  285|      8|		is_mf = 1;
  286|    155|	switch (*p) {
  287|     82|	case 0x01:
  ------------------
  |  Branch (287:2): [True: 82, False: 73]
  ------------------
  288|     82|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     82|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  289|     82|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     82|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  290|     82|		break;
  291|     26|	case 0x02:
  ------------------
  |  Branch (291:2): [True: 26, False: 129]
  ------------------
  292|     26|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     26|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  293|     26|		file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     26|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  294|     26|		break;
  295|      7|	case 0x04:
  ------------------
  |  Branch (295:2): [True: 7, False: 148]
  ------------------
  296|      7|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      7|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  297|      7|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|      7|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  298|      7|		break;
  299|      9|	case 0x06:
  ------------------
  |  Branch (299:2): [True: 9, False: 146]
  ------------------
  300|      9|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      9|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  301|      9|		file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|      9|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  302|      9|		break;
  303|     15|	case 0x38:
  ------------------
  |  Branch (303:2): [True: 15, False: 140]
  ------------------
  304|     15|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     15|#define SC_FILE_TYPE_DF			0x04
  ------------------
  305|     15|		break;
  306|     16|	default:
  ------------------
  |  Branch (306:2): [True: 16, False: 139]
  ------------------
  307|     16|		sc_log(ctx,  "invalid file type: 0x%02X\n", *p);
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  308|     16|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     16|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  309|    155|	}
  310|    139|	p += 2;
  311|    139|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    139|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (311:6): [True: 15, False: 124]
  ------------------
  312|     15|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, (u8)(p[0] >> 4));
  ------------------
  |  |  172|     15|#define SC_AC_OP_LIST_FILES		6
  ------------------
  313|     15|		add_acl_entry(card, file, SC_AC_OP_DELETE, (u8)(p[1] >> 4));
  ------------------
  |  |  168|     15|#define SC_AC_OP_DELETE			2
  ------------------
  314|     15|		add_acl_entry(card, file, SC_AC_OP_CREATE, (u8)(p[1] & 0x0F));
  ------------------
  |  |  169|     15|#define SC_AC_OP_CREATE			3
  ------------------
  315|    124|	} else { /* EF */
  316|    124|		add_acl_entry(card, file, SC_AC_OP_READ, (u8)(p[0] >> 4));
  ------------------
  |  |  188|    124|#define SC_AC_OP_READ			22
  ------------------
  317|    124|		switch (file->ef_structure) {
  ------------------
  |  Branch (317:11): [True: 124, False: 0]
  ------------------
  318|     82|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     82|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (318:3): [True: 82, False: 42]
  ------------------
  319|     82|			add_acl_entry(card, file, SC_AC_OP_UPDATE, (u8)(p[0] & 0x0F));
  ------------------
  |  |  189|     82|#define SC_AC_OP_UPDATE			23
  ------------------
  320|     82|			break;
  321|     26|		case SC_FILE_EF_LINEAR_FIXED:
  ------------------
  |  |  222|     26|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  |  Branch (321:3): [True: 26, False: 98]
  ------------------
  322|     33|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     33|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (322:3): [True: 7, False: 117]
  ------------------
  323|     33|			add_acl_entry(card, file, SC_AC_OP_UPDATE, (u8)(p[0] & 0x0F));
  ------------------
  |  |  189|     33|#define SC_AC_OP_UPDATE			23
  ------------------
  324|     33|			break;
  325|      9|		case SC_FILE_EF_CYCLIC:
  ------------------
  |  |  226|      9|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  |  Branch (325:3): [True: 9, False: 115]
  ------------------
  326|      9|			break;
  327|    124|		}
  328|    124|	}
  329|    139|	if (file->type != SC_FILE_TYPE_DF || is_mf) {
  ------------------
  |  |  214|    278|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (329:6): [True: 124, False: 15]
  |  Branch (329:39): [True: 3, False: 12]
  ------------------
  330|    127|		add_acl_entry(card, file, SC_AC_OP_REHABILITATE, (u8)(p[2] >> 4));
  ------------------
  |  |  170|    127|#define SC_AC_OP_REHABILITATE		4
  ------------------
  331|    127|		add_acl_entry(card, file, SC_AC_OP_INVALIDATE, (u8)(p[2] & 0x0F));
  ------------------
  |  |  171|    127|#define SC_AC_OP_INVALIDATE		5
  ------------------
  332|    127|	}
  333|    139|	p += 3;
  334|    139|	if (*p)
  ------------------
  |  Branch (334:6): [True: 114, False: 25]
  ------------------
  335|    114|		file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    114|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  336|     25|	else
  337|     25|		file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     25|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  338|       |
  339|    139|	return cryptoflex_get_ac_keys(card, file);
  340|    139|}
card-flex.c:add_acl_entry:
  214|    538|{
  215|    538|	struct flex_private_data *prv = DRV_DATA(card);
  ------------------
  |  |  109|    538|#define DRV_DATA(card)	((struct flex_private_data *) (card)->drv_data)
  ------------------
  216|       |
  217|    538|	switch (nibble) {
  218|    134|	case 0:
  ------------------
  |  Branch (218:2): [True: 134, False: 404]
  ------------------
  219|    134|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    134|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    134|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  220|    134|		break;
  221|     26|	case 1:
  ------------------
  |  Branch (221:2): [True: 26, False: 512]
  ------------------
  222|     26|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     26|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  223|     26|		break;
  224|     29|	case 2:
  ------------------
  |  Branch (224:2): [True: 29, False: 509]
  ------------------
  225|     29|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 2);
  ------------------
  |  |  151|     29|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  226|     29|		break;
  227|     20|	case 3:
  ------------------
  |  Branch (227:2): [True: 20, False: 518]
  ------------------
  228|     20|		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  153|     20|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     20|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  229|     20|		break;
  230|     19|	case 4:
  ------------------
  |  Branch (230:2): [True: 19, False: 519]
  ------------------
  231|       |		/* Assume the key is the AAK */
  232|     19|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     19|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  233|     19|		break;
  234|     51|	case 6:
  ------------------
  |  Branch (234:2): [True: 51, False: 487]
  ------------------
  235|     51|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     51|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  236|     51|		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  153|     51|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     51|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  237|     51|		break;
  238|     30|	case 7:
  ------------------
  |  Branch (238:2): [True: 30, False: 508]
  ------------------
  239|     30|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 2);
  ------------------
  |  |  151|     30|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  240|     30|		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  153|     30|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     30|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  241|     30|		break;
  242|     73|	case 8:
  ------------------
  |  Branch (242:2): [True: 73, False: 465]
  ------------------
  243|     73|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     73|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  244|       |		/* Assume the key is the AAK */
  245|     73|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     73|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  246|     73|		break;
  247|     68|	case 9:
  ------------------
  |  Branch (247:2): [True: 68, False: 470]
  ------------------
  248|     68|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 2);
  ------------------
  |  |  151|     68|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  249|       |		/* Assume the key is the AAK */
  250|     68|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     68|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  251|     68|		break;
  252|     39|	case 15:
  ------------------
  |  Branch (252:2): [True: 39, False: 499]
  ------------------
  253|     39|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|     39|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     39|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  254|     39|		break;
  255|     49|	default:
  ------------------
  |  Branch (255:2): [True: 49, False: 489]
  ------------------
  256|     49|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|     49|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     49|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  257|     49|		break;
  258|    538|	}
  259|    538|}
card-flex.c:cryptoflex_get_ac_keys:
  263|    139|{
  264|    139|	return 0;
  265|    139|}
card-flex.c:flex_select_file:
  491|    913|{
  492|    913|	int r;
  493|    913|	const u8 *pathptr = path->value;
  494|    913|	size_t pathlen = path->len;
  495|    913|	int locked = 0;
  496|    913|	u8 p1 = 0;
  497|       |
  498|    913|	switch (path->type) {
  ------------------
  |  Branch (498:10): [True: 913, False: 0]
  ------------------
  499|    551|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    551|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (499:2): [True: 551, False: 362]
  ------------------
  500|    551|		if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (500:7): [True: 0, False: 551]
  ------------------
  501|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  502|    551|		if (pathlen == 0)
  ------------------
  |  Branch (502:7): [True: 0, False: 551]
  ------------------
  503|      0|			return 0;
  504|    551|		if (pathlen != 2 || memcmp(pathptr, "\x3F\x00", 2) != 0) {
  ------------------
  |  Branch (504:7): [True: 491, False: 60]
  |  Branch (504:23): [True: 59, False: 1]
  ------------------
  505|    550|			locked = 1;
  506|    550|			r = sc_lock(card);
  507|    550|			LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    550|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    550|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    550|	int _ret = (r); \
  |  |  |  |  168|    550|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 550]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    550|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 550]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|    550|			if (memcmp(pathptr, "\x3F\x00", 2) != 0) {
  ------------------
  |  Branch (508:8): [True: 61, False: 489]
  ------------------
  509|     61|				r = select_file_id(card, (const u8 *) "\x3F\x00", 2, 0, NULL);
  510|     61|				if (r)
  ------------------
  |  Branch (510:9): [True: 42, False: 19]
  ------------------
  511|     42|					sc_unlock(card);
  512|     61|				LOG_TEST_RET(card->ctx, r, "Unable to select Master File (MF)");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  169|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     42|		return _ret; \
  |  |  |  |  172|     42|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|     61|			}
  514|    739|			while (pathlen > 2) {
  ------------------
  |  Branch (514:11): [True: 498, False: 241]
  ------------------
  515|    498|				r = select_file_id(card, pathptr, 2, 0, NULL);
  516|    498|				if (r)
  ------------------
  |  Branch (516:9): [True: 267, False: 231]
  ------------------
  517|    267|					sc_unlock(card);
  518|    498|				LOG_TEST_RET(card->ctx, r, "Unable to select DF");
  ------------------
  |  |  174|    498|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    498|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    498|	int _ret = (r); \
  |  |  |  |  168|    498|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 267, False: 231]
  |  |  |  |  ------------------
  |  |  |  |  169|    267|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    267|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    267|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    267|		return _ret; \
  |  |  |  |  172|    267|	} \
  |  |  |  |  173|    498|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 231]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|    231|				pathptr += 2;
  520|    231|				pathlen -= 2;
  521|    231|			}
  522|    508|		}
  523|    242|		break;
  524|    362|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    362|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (524:2): [True: 362, False: 551]
  ------------------
  525|    362|		p1 = 0x04;
  526|    362|		break;
  527|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (527:2): [True: 0, False: 913]
  ------------------
  528|      0|		if (pathlen != 2)
  ------------------
  |  Branch (528:7): [True: 0, False: 0]
  ------------------
  529|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  530|      0|		break;
  531|    913|	}
  532|    604|	r = select_file_id(card, pathptr, pathlen, p1, file_out);
  533|    604|	if (locked)
  ------------------
  |  Branch (533:6): [True: 241, False: 363]
  ------------------
  534|    241|		sc_unlock(card);
  535|    604|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    604|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    604|	int _ret = r; \
  |  |  155|    604|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 604, False: 0]
  |  |  ------------------
  |  |  156|    604|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    404|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 404, False: 200]
  |  |  ------------------
  |  |  157|    604|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    604|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    604|	return _ret; \
  |  |  163|    604|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  536|    604|}
card-flex.c:select_file_id:
  438|  1.16k|{
  439|  1.16k|	int r;
  440|  1.16k|	sc_apdu_t apdu;
  441|  1.16k|        u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  442|  1.16k|        sc_file_t *file;
  443|       |
  444|  1.16k|	sc_log(card->ctx,  "called, p1=%u\n", p1);
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  445|  1.16k|	sc_log_hex(card->ctx, "path", buf, buflen);
  ------------------
  |  |  129|  1.16k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  1.16k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|       |
  447|  1.16k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0);
  ------------------
  |  |  294|  1.16k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  448|  1.16k|	apdu.resp = rbuf;
  449|  1.16k|	apdu.resplen = sizeof(rbuf);
  450|  1.16k|	apdu.datalen = buflen;
  451|  1.16k|	apdu.data = buf;
  452|  1.16k|	apdu.lc = buflen;
  453|  1.16k|	apdu.le = 252;
  454|       |
  455|       |	/* No need to get file information, if file is NULL. */
  456|  1.16k|	if (file_out == NULL) {
  ------------------
  |  Branch (456:6): [True: 941, False: 222]
  ------------------
  457|    941|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|    941|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  458|    941|		apdu.le = 0;
  459|    941|	}
  460|  1.16k|	r = sc_transmit_apdu(card, &apdu);
  461|  1.16k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.16k|	int _ret = (r); \
  |  |  |  |  168|  1.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 1.14k]
  |  |  |  |  ------------------
  |  |  |  |  169|     15|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     15|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     15|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     15|		return _ret; \
  |  |  |  |  172|     15|	} \
  |  |  |  |  173|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.14k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  462|  1.14k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  463|  1.14k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  1.14k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.14k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.14k|	int _ret = (r); \
  |  |  |  |  168|  1.14k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 653, False: 495]
  |  |  |  |  ------------------
  |  |  |  |  169|    653|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    653|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    653|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    653|		return _ret; \
  |  |  |  |  172|    653|	} \
  |  |  |  |  173|  1.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 495]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|       |
  465|    495|	if (file_out == NULL)
  ------------------
  |  Branch (465:6): [True: 311, False: 184]
  ------------------
  466|    311|		return 0;
  467|       |
  468|    184|	if (apdu.resplen < 14)
  ------------------
  |  Branch (468:6): [True: 23, False: 161]
  ------------------
  469|     23|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     23|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  470|    161|	if (apdu.resp[0] == 0x6F) {
  ------------------
  |  Branch (470:6): [True: 6, False: 155]
  ------------------
  471|      6|		sc_log(card->ctx,  "unsupported: card returned FCI\n");
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|      6|		return SC_ERROR_UNKNOWN_DATA_RECEIVED; /* FIXME */
  ------------------
  |  |   63|      6|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  473|      6|	}
  474|    155|	file = sc_file_new();
  475|    155|	if (file == NULL)
  ------------------
  |  Branch (475:6): [True: 0, False: 155]
  ------------------
  476|    155|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|       |
  478|       |	/* We abuse process_fci here even though it's not the real FCI. */
  479|    155|	r = card->ops->process_fci(card, file, apdu.resp, apdu.resplen);
  480|    155|	if (r) {
  ------------------
  |  Branch (480:6): [True: 16, False: 139]
  ------------------
  481|     16|		sc_file_free(file);
  482|     16|		return r;
  483|     16|	}
  484|       |
  485|    139|	*file_out = file;
  486|    139|	return 0;
  487|    155|}
card-flex.c:flex_card_ctl:
 1089|     11|{
 1090|     11|	switch (cmd) {
  ------------------
  |  Branch (1090:10): [True: 11, False: 0]
  ------------------
 1091|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1091:2): [True: 0, False: 11]
  ------------------
 1092|      0|		return flex_get_default_key(card,
 1093|      0|				(struct sc_cardctl_default_key *) ptr);
 1094|      0|	case SC_CARDCTL_CRYPTOFLEX_GENERATE_KEY:
  ------------------
  |  Branch (1094:2): [True: 0, False: 11]
  ------------------
 1095|      0|		return flex_generate_key(card,
 1096|      0|				(struct sc_cardctl_cryptoflex_genkey_info *) ptr);
 1097|     11|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1097:2): [True: 11, False: 0]
  ------------------
 1098|     11|		return flex_get_serialnr(card, (sc_serial_number_t *) ptr);
 1099|     11|	}
 1100|       |
 1101|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1102|     11|}
card-flex.c:flex_get_serialnr:
 1051|     11|{
 1052|     11|	int       r;
 1053|     11|	u8        buf[16];
 1054|     11|	size_t    len;
 1055|     11|	sc_path_t tpath;
 1056|     11|	sc_file_t *tfile = NULL;
 1057|       |
 1058|     11|	if (!serial)
  ------------------
  |  Branch (1058:6): [True: 0, False: 11]
  ------------------
 1059|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1060|       |	/* see if we have cached serial number */
 1061|     11|	if (card->serialnr.len) {
  ------------------
  |  Branch (1061:6): [True: 0, False: 11]
  ------------------
 1062|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1063|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1064|      0|	}
 1065|       |	/* read EF_ICCSN */
 1066|     11|	sc_format_path("3F000002", &tpath);
 1067|     11|	r = sc_select_file(card, &tpath, &tfile);
 1068|     11|	if (r < 0)
  ------------------
  |  Branch (1068:6): [True: 7, False: 4]
  ------------------
 1069|      7|		return r;
 1070|      4|	len = tfile->size;
 1071|      4|	sc_file_free(tfile);
 1072|      4|	if (len != 8) {
  ------------------
  |  Branch (1072:6): [True: 3, False: 1]
  ------------------
 1073|      3|		sc_log(card->ctx,  "unexpected file length of EF_ICCSN (%lu)\n",
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1074|      3|			(unsigned long) len);
 1075|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1076|      3|	}
 1077|      1|	r = sc_read_binary(card, 0, buf, len, 0);
 1078|      1|	if (r < 0)
  ------------------
  |  Branch (1078:6): [True: 1, False: 0]
  ------------------
 1079|      1|		return r;
 1080|      0|	card->serialnr.len = len;
 1081|      0|	memcpy(card->serialnr.value, buf, len);
 1082|       |
 1083|      0|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1084|       |
 1085|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1086|      1|}
card-flex.c:flex_pin_cmd:
 1151|     11|{
 1152|     11|	sc_apdu_t apdu;
 1153|     11|	int r;
 1154|     11|	int old_cla = -1;
 1155|       |
 1156|       |	/* Fix pin data */
 1157|     11|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     11|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1158|     11|	flex_init_pin_info(&data->pin1, 0);
 1159|     11|	flex_init_pin_info(&data->pin2, 1);
 1160|       |
 1161|     11|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|     11|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1161:6): [True: 0, False: 11]
  ------------------
 1162|      0|		r = flex_build_verify_apdu(card, &apdu, data);
 1163|      0|		if (r < 0)
  ------------------
  |  Branch (1163:7): [True: 0, False: 0]
  ------------------
 1164|      0|			return r;
 1165|      0|		data->apdu = &apdu;
 1166|     11|	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|     22|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|     11|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1166:13): [True: 0, False: 11]
  |  Branch (1166:47): [True: 0, False: 11]
  ------------------
 1167|      0|		if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1167:7): [True: 0, False: 0]
  ------------------
 1168|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1169|      0|		old_cla = card->cla;
 1170|      0|		if (!IS_CYBERFLEX(card))
  ------------------
  |  |   32|      0|#define IS_CYBERFLEX(card)	(card->type == SC_CARD_TYPE_FLEX_CYBER)
  ------------------
  |  Branch (1170:7): [True: 0, False: 0]
  ------------------
 1171|      0|			card->cla = 0xF0;
 1172|      0|	}
 1173|       |
 1174|       |	/* According to the Cryptoflex documentation, the card
 1175|       |	 * does not return the number of attempts left using
 1176|       |	 * the 63C0xx convention */
 1177|     11|	r = iso_ops->pin_cmd(card, data);
 1178|     11|	if (old_cla != -1)
  ------------------
  |  Branch (1178:6): [True: 0, False: 11]
  ------------------
 1179|      0|		card->cla = old_cla;
 1180|       |	data->apdu = NULL;
 1181|     11|	return r;
 1182|     11|}
card-flex.c:flex_init_pin_info:
 1142|     22|{
 1143|     22|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     22|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1144|     22|	pin->min_length = 4;
 1145|     22|	pin->max_length = 8;
 1146|     22|	pin->pad_length = 8;
 1147|     22|	pin->offset     = 5 + num * 8;
 1148|     22|}
card-flex.c:cyberflex_match_card:
  152|  14.9k|{
  153|  14.9k|	int i;
  154|       |
  155|  14.9k|	i = _sc_match_atr(card, flex_atrs, NULL);
  156|  14.9k|	if (i < 0)
  ------------------
  |  Branch (156:6): [True: 14.7k, False: 190]
  ------------------
  157|  14.7k|		return 0;
  158|    190|	switch (flex_atrs[i].type) {
  ------------------
  |  Branch (158:10): [True: 0, False: 190]
  ------------------
  159|      0|	case SC_CARD_TYPE_FLEX_CYBER:
  ------------------
  |  Branch (159:2): [True: 0, False: 190]
  ------------------
  160|      0|		card->name = flex_atrs[i].name;
  161|      0|		card->type = flex_atrs[i].type;
  162|      0|		card->flags = flex_atrs[i].flags;
  163|      0|		return 1;
  164|    190|	}
  165|    190|	return 0;
  166|    190|}

sc_get_gemsafeV1_driver:
  591|  15.2k|{
  592|  15.2k|	return sc_get_driver();
  593|  15.2k|}
card-gemsafeV1.c:sc_get_driver:
  566|  15.2k|{
  567|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  568|  15.2k|	if (!iso_ops)
  ------------------
  |  Branch (568:6): [True: 1, False: 15.2k]
  ------------------
  569|      1|		iso_ops = iso_drv->ops;
  570|       |	/* use the standard iso operations as default */
  571|  15.2k|	gemsafe_ops = *iso_drv->ops;
  572|       |	/* gemsafe specific functions */
  573|  15.2k|	gemsafe_ops.match_card	= gemsafe_match_card;
  574|  15.2k|	gemsafe_ops.init	= gemsafe_init;
  575|  15.2k|	gemsafe_ops.finish	= gemsafe_finish;
  576|  15.2k|	gemsafe_ops.select_file	= gemsafe_select_file;
  577|  15.2k|	gemsafe_ops.restore_security_env = gemsafe_restore_security_env;
  578|  15.2k|	gemsafe_ops.set_security_env     = gemsafe_set_security_env;
  579|  15.2k|	gemsafe_ops.decipher             = gemsafe_decipher;
  580|  15.2k|	gemsafe_ops.compute_signature    = gemsafe_compute_signature;
  581|  15.2k|	gemsafe_ops.get_challenge 		 = gemsafe_get_challenge;
  582|  15.2k|	gemsafe_ops.process_fci	= gemsafe_process_fci;
  583|  15.2k|	gemsafe_ops.pin_cmd		 = iso_ops->pin_cmd;
  584|  15.2k|	gemsafe_ops.card_reader_lock_obtained = gemsafe_card_reader_lock_obtained;
  585|  15.2k|	gemsafe_ops.logout = gemsafe_logout;
  586|       |
  587|  15.2k|	return &gemsafe_drv;
  588|  15.2k|}
card-gemsafeV1.c:gemsafe_match_card:
  124|  14.2k|{
  125|  14.2k|	int i;
  126|       |
  127|  14.2k|	i = _sc_match_atr(card, gemsafe_atrs, &card->type);
  128|  14.2k|	if (i < 0)
  ------------------
  |  Branch (128:6): [True: 13.6k, False: 673]
  ------------------
  129|  13.6k|		return 0;
  130|       |
  131|    673|	return 1;
  132|  14.2k|}
card-gemsafeV1.c:gemsafe_init:
  135|    673|{
  136|    673|	int	r;
  137|    673|	gemsafe_exdata *exdata = NULL;
  138|       |
  139|    673|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    673|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    673|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    673|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 673]
  |  |  ------------------
  ------------------
  140|       |
  141|    673|	card->name = "GemSAFE V1";
  142|    673|	card->cla  = 0x00;
  143|       |
  144|    673|	exdata = (gemsafe_exdata *)calloc(1, sizeof(gemsafe_exdata));
  145|    673|	if (!exdata)
  ------------------
  |  Branch (145:6): [True: 0, False: 673]
  ------------------
  146|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  147|    673|	exdata->aid_len = sizeof(exdata->aid);
  148|    673|	if(card->type == SC_CARD_TYPE_GEMSAFEV1_GENERIC) {
  ------------------
  |  Branch (148:5): [True: 64, False: 609]
  ------------------
  149|       |		/* try to get a AID from the config file */
  150|     64|		r = get_conf_aid(card, exdata->aid, &exdata->aid_len);
  151|     64|		if (r < 0) {
  ------------------
  |  Branch (151:7): [True: 64, False: 0]
  ------------------
  152|       |			/* failed, use default value */
  153|     64|			memcpy(exdata->aid, gemsafe_def_aid, sizeof(gemsafe_def_aid));
  154|     64|			exdata->aid_len = sizeof(gemsafe_def_aid);
  155|     64|		}
  156|    609|	} else if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID) {
  ------------------
  |  Branch (156:13): [True: 505, False: 104]
  ------------------
  157|    505|		memcpy(exdata->aid, gemsafe_pteid_aid, sizeof(gemsafe_pteid_aid));
  158|    505|		exdata->aid_len = sizeof(gemsafe_pteid_aid);
  159|    505|	} else if (card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (159:13): [True: 104, False: 0]
  ------------------
  160|    104|		memcpy(exdata->aid, gemsafe_seeid_aid, sizeof(gemsafe_seeid_aid));
  161|    104|		exdata->aid_len = sizeof(gemsafe_seeid_aid);
  162|    104|	}
  163|       |
  164|       |	/* increase lock_count here to prevent sc_unlock to select
  165|       |	 * applet twice in gp_select_applet */
  166|    673|	card->lock_count++;
  167|       |	/* SELECT applet */
  168|    673|	r = iso7816_select_aid(card, exdata->aid, exdata->aid_len, NULL, NULL);
  169|    673|	if (r < 0) {
  ------------------
  |  Branch (169:6): [True: 8, False: 665]
  ------------------
  170|      8|		free(exdata);
  171|      8|		sc_log(card->ctx,  "applet selection failed\n");
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  172|      8|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      8|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  173|      8|	}
  174|    665|	card->lock_count--;
  175|       |
  176|       |	/* set the supported algorithm */
  177|    665|	unsigned long flags;
  178|       |
  179|    665|	flags  = SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    665|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    665|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    665|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  180|    665|	flags |= SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  106|    665|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  181|    665|	flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    665|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  182|    665|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    665|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  183|       |
  184|       |	/* GemSAFE V3 cards support SHA256 */
  185|    665|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (185:6): [True: 500, False: 165]
  ------------------
  186|    165|	    card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID)
  ------------------
  |  Branch (186:6): [True: 103, False: 62]
  ------------------
  187|    603|		flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|    603|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  188|       |
  189|    665|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  190|    665|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  191|    665|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  192|    665|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  193|    665|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  194|    665|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  195|       |
  196|       |	/* fake algorithm to persuade register_mechanisms()
  197|       |	 * to register these hashes */
  198|    665|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (198:6): [True: 500, False: 165]
  ------------------
  199|    603|	    card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (199:6): [True: 103, False: 62]
  ------------------
  200|    603|		flags  = SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|    603|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  201|    603|		flags |= SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  135|    603|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  202|    603|		flags |= SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  136|    603|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  203|    603|		flags |= SC_ALGORITHM_RSA_HASH_RIPEMD160;
  ------------------
  |  |  137|    603|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  204|       |
  205|    603|		_sc_card_add_rsa_alg(card,  512, flags, 0);
  206|    603|	}
  207|       |
  208|    665|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    665|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  209|    665|	card->drv_data = exdata;
  210|       |
  211|    665|	return SC_SUCCESS;
  ------------------
  |  |   28|    665|#define SC_SUCCESS				0
  ------------------
  212|    673|}
card-gemsafeV1.c:get_conf_aid:
   93|     64|{
   94|     64|	sc_context_t		*ctx = card->ctx;
   95|     64|	scconf_block		*conf_block, **blocks;
   96|     64|	int			i;
   97|     64|	const char		*str_aid;
   98|       |
   99|     64|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     64|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     64|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     64|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 64]
  |  |  ------------------
  ------------------
  100|       |
  101|     64|	conf_block = NULL;
  102|    128|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (102:14): [True: 64, False: 64]
  ------------------
  103|     64|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  104|     64|						"card", "gemsafeV1");
  105|     64|		if (blocks != NULL && blocks[0] != NULL)
  ------------------
  |  Branch (105:7): [True: 64, False: 0]
  |  Branch (105:25): [True: 0, False: 64]
  ------------------
  106|      0|			conf_block = blocks[0];
  107|     64|		free(blocks);
  108|     64|	}
  109|       |
  110|     64|	if (!conf_block) {
  ------------------
  |  Branch (110:6): [True: 64, False: 0]
  ------------------
  111|     64|		sc_log(ctx,  "no card specific options configured, trying default AID\n");
  ------------------
  |  |   71|     64|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  112|     64|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     64|#define SC_ERROR_INTERNAL			-1400
  ------------------
  113|     64|	}
  114|       |
  115|      0|	str_aid = scconf_get_str(conf_block, "aid", NULL);
  116|      0|	if (!str_aid) {
  ------------------
  |  Branch (116:6): [True: 0, False: 0]
  ------------------
  117|      0|		sc_log(ctx,  "no aid configured, trying default AID\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  118|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  119|      0|	}
  120|      0|	return sc_hex_to_bin(str_aid, aid, len);
  121|      0|}
card-gemsafeV1.c:gemsafe_finish:
  215|    665|{
  216|    665|	gemsafe_exdata *exdata = (gemsafe_exdata *)card->drv_data;
  217|       |
  218|    665|	if (exdata)
  ------------------
  |  Branch (218:6): [True: 665, False: 0]
  ------------------
  219|    665|		free(exdata);
  220|    665|	return SC_SUCCESS;
  ------------------
  |  |   28|    665|#define SC_SUCCESS				0
  ------------------
  221|    665|}
card-gemsafeV1.c:gemsafe_select_file:
  225|  4.81k|{
  226|       |	/* so far just call the iso select file (but this will change) */
  227|  4.81k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.81k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.81k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.81k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.81k]
  |  |  ------------------
  ------------------
  228|       |
  229|  4.81k|	return iso_ops->select_file(card, path, file_out);
  230|  4.81k|}
card-gemsafeV1.c:gemsafe_set_security_env:
  406|     79|{
  407|     79|	u8 alg_ref;
  408|     79|	struct sc_security_env se_env = *env;
  409|     79|	struct sc_context *ctx = card->ctx;
  410|       |
  411|     79|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     79|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     79|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     79|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 79]
  |  |  ------------------
  ------------------
  412|       |
  413|     79|	if (!(se_env.flags & SC_SEC_ENV_ALG_REF_PRESENT)) {
  ------------------
  |  |   56|     79|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (413:6): [True: 79, False: 0]
  ------------------
  414|       |		/* set the algorithm reference */
  415|     79|		alg_ref = gemsafe_flags2algref(card, &se_env);
  416|     79|		if (alg_ref) {
  ------------------
  |  Branch (416:7): [True: 74, False: 5]
  ------------------
  417|     74|			se_env.algorithm_ref = alg_ref;
  418|     74|			se_env.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|     74|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  419|     74|		}
  420|     79|	}
  421|     79|	if (!(se_env.flags & SC_SEC_ENV_ALG_REF_PRESENT))
  ------------------
  |  |   56|     79|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (421:6): [True: 5, False: 74]
  ------------------
  422|      5|		sc_log(ctx, "unknown algorithm flags '%lx'\n", se_env.algorithm_flags);
  ------------------
  |  |   71|      5|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  423|       |
  424|     79|	se_env.flags &= ~SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|     79|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  425|     79|	return iso_ops->set_security_env(card, &se_env, se_num);
  426|     79|}
card-gemsafeV1.c:gemsafe_flags2algref:
  363|     79|{
  364|     79|	u8 ret = 0;
  365|       |
  366|     79|	if (env->operation == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   48|     79|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (366:6): [True: 32, False: 47]
  ------------------
  367|     32|		if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256)
  ------------------
  |  |  138|     32|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (367:7): [True: 15, False: 17]
  ------------------
  368|     15|			ret = GEMSAFEV3_ALG_REF_SHA256;
  ------------------
  |  |   34|     15|#define GEMSAFEV3_ALG_REF_SHA256	0x42
  ------------------
  369|     17|		else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|     17|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (369:12): [True: 17, False: 0]
  ------------------
  370|     17|			ret = (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (370:11): [True: 0, False: 17]
  ------------------
  371|     17|			       card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) ?
  ------------------
  |  Branch (371:11): [True: 5, False: 12]
  ------------------
  372|      5|			      GEMSAFEV3_ALG_REF_FREEFORM :
  ------------------
  |  |   32|      5|#define GEMSAFEV3_ALG_REF_FREEFORM	0x02
  ------------------
  373|     17|			      GEMSAFEV1_ALG_REF_FREEFORM;
  ------------------
  |  |   31|     12|#define GEMSAFEV1_ALG_REF_FREEFORM	0x12
  ------------------
  374|      0|		else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_ISO9796)
  ------------------
  |  |  106|      0|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  |  Branch (374:12): [True: 0, False: 0]
  ------------------
  375|      0|			ret = 0x11;
  376|     47|	} else if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|     47|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (376:13): [True: 47, False: 0]
  ------------------
  377|     47|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  110|     47|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (377:7): [True: 42, False: 5]
  ------------------
  378|     42|			ret = (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (378:11): [True: 1, False: 41]
  ------------------
  379|     41|			       card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) ?
  ------------------
  |  Branch (379:11): [True: 4, False: 37]
  ------------------
  380|      5|			      GEMSAFEV3_ALG_REF_FREEFORM :
  ------------------
  |  |   32|      5|#define GEMSAFEV3_ALG_REF_FREEFORM	0x02
  ------------------
  381|     42|			      GEMSAFEV1_ALG_REF_FREEFORM;
  ------------------
  |  |   31|     37|#define GEMSAFEV1_ALG_REF_FREEFORM	0x12
  ------------------
  382|     47|	}
  383|       |
  384|     79|	return ret;
  385|     79|}
card-gemsafeV1.c:gemsafe_decipher:
  495|     42|{
  496|     42|	int r;
  497|     42|	struct sc_apdu apdu;
  498|     42|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
  499|     42|	sc_context_t *ctx = card->ctx;
  500|       |
  501|     42|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     42|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     42|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     42|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 42]
  |  |  ------------------
  ------------------
  502|     42|	if (crgram_len > 255)
  ------------------
  |  Branch (502:6): [True: 0, False: 42]
  ------------------
  503|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  504|       |
  505|     42|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x84);
  ------------------
  |  |  294|     42|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  506|     42|	apdu.cla |= 0x80;
  507|     42|	apdu.resp = rbuf;
  508|     42|	apdu.resplen = sizeof(rbuf);
  509|     42|	apdu.le      = crgram_len;
  510|       |
  511|     42|	apdu.data = crgram;
  512|     42|	apdu.lc   = crgram_len;
  513|     42|	apdu.datalen = crgram_len;
  514|     42|	r = sc_transmit_apdu(card, &apdu);
  515|     42|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     42|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     42|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     42|	int _ret = (r); \
  |  |  |  |  168|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 38]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|     38|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (516:6): [True: 28, False: 10]
  |  Branch (516:26): [True: 28, False: 0]
  ------------------
  517|     28|		size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (517:16): [True: 1, False: 27]
  ------------------
  518|       |
  519|     28|		memcpy(out, apdu.resp, len);
  520|     28|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     28|	int _ret = r; \
  |  |  155|     28|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 11, False: 17]
  |  |  ------------------
  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 11]
  |  |  ------------------
  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     17|	} else { \
  |  |  159|     17|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     17|			"returning with: %d\n", _ret); \
  |  |  161|     17|	} \
  |  |  162|     28|	return _ret; \
  |  |  163|     28|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  521|     28|	}
  522|     10|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     10|	int _ret = r; \
  |  |  155|     10|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  ------------------
  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  ------------------
  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     10|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     10|	return _ret; \
  |  |  163|     10|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  523|     10|}
card-gemsafeV1.c:gemsafe_compute_signature:
  430|     30|{
  431|     30|	int r;
  432|     30|	size_t len;
  433|     30|	struct sc_apdu apdu;
  434|     30|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
  435|     30|	u8 sbuf[MAX_RESP_BUFFER_SIZE];
  436|     30|	sc_context_t *ctx = card->ctx;
  437|       |
  438|     30|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     30|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     30|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     30|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 30]
  |  |  ------------------
  ------------------
  439|       |
  440|       |	/* the card can sign 36 bytes of free form data */
  441|     30|	if (data_len > 36) {
  ------------------
  |  Branch (441:6): [True: 1, False: 29]
  ------------------
  442|      1|		sc_log(ctx, "error: input data too long: %zu bytes", data_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  443|      1|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  444|      1|	}
  445|       |
  446|       |	/* the Portuguese eID card requires a two-phase exchange */
  447|       |	/* and so does the Swedish one */
  448|     29|	if(card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (448:5): [True: 0, False: 29]
  ------------------
  449|     29|	   card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (449:5): [True: 18, False: 11]
  ------------------
  450|     18|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2A, 0x90, 0xA0);
  ------------------
  |  |  293|     18|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  451|     18|	} else {
  452|     11|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0xAC);
  ------------------
  |  |  294|     11|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  453|     11|		apdu.cla |= 0x80;
  454|     11|		apdu.resp = rbuf;
  455|     11|		apdu.resplen = sizeof(rbuf);
  456|     11|		apdu.le      = 256;
  457|     11|	}
  458|       |	/* we sign a digestInfo object => tag 0x90 */
  459|     29|	sbuf[0] = 0x90;
  460|     29|	sbuf[1] = (u8)data_len;
  461|     29|	memcpy(sbuf + 2, data, data_len);
  462|     29|	apdu.data = sbuf;
  463|     29|	apdu.lc   = data_len + 2;
  464|     29|	apdu.datalen = data_len + 2;
  465|       |
  466|     29|	r = sc_transmit_apdu(card, &apdu);
  467|     29|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 27]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|     27|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (468:6): [True: 15, False: 12]
  |  Branch (468:26): [True: 15, False: 0]
  ------------------
  469|     15|		if(card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
  ------------------
  |  Branch (469:6): [True: 0, False: 15]
  ------------------
  470|     15|		   card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (470:6): [True: 8, False: 7]
  ------------------
  471|       |			/* finalize the exchange */
  472|      8|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  292|      8|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  473|      8|			apdu.le = 128; /* 1024 bit keys */
  474|      8|			apdu.resp = rbuf;
  475|      8|			apdu.resplen = sizeof(rbuf);
  476|      8|			if(card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
  ------------------
  |  Branch (476:7): [True: 8, False: 0]
  ------------------
  477|       |			  /* cla 0x80 not supported */
  478|      8|			  apdu.cla = 0x00;
  479|      8|			}
  480|      8|			r = sc_transmit_apdu(card, &apdu);
  481|      8|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|      7|			if(apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (482:7): [True: 2, False: 5]
  |  Branch (482:27): [True: 1, False: 4]
  ------------------
  483|      3|				SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      3|	int _ret = r; \
  |  |  155|      3|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  ------------------
  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  ------------------
  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      3|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      3|	return _ret; \
  |  |  163|      3|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  484|      7|		}
  485|     11|		len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (485:9): [True: 1, False: 10]
  ------------------
  486|       |
  487|     11|		memcpy(out, apdu.resp, len);
  488|     11|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     11|	int _ret = r; \
  |  |  155|     11|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5, False: 6]
  |  |  ------------------
  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  ------------------
  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      6|	} else { \
  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  161|      6|	} \
  |  |  162|     11|	return _ret; \
  |  |  163|     11|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  489|     11|	}
  490|     12|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     12|	int _ret = r; \
  |  |  155|     12|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  ------------------
  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 12, False: 0]
  |  |  ------------------
  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     12|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     12|	return _ret; \
  |  |  163|     12|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  491|     12|}
card-gemsafeV1.c:gemsafe_process_fci:
  321|  1.19k|{
  322|  1.19k|	int        r;
  323|  1.19k|	size_t     tlen;
  324|  1.19k|	const u8   *tag = NULL, *p = buf;
  325|  1.19k|	const char *type;
  326|  1.19k|	struct sc_context *ctx = card->ctx;
  327|       |
  328|  1.19k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.19k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.19k]
  |  |  ------------------
  ------------------
  329|       |
  330|  1.19k|	r = iso_ops->process_fci(card, file, buf, len);
  331|  1.19k|	if (r < 0)
  ------------------
  |  Branch (331:6): [True: 0, False: 1.19k]
  ------------------
  332|      0|		return r;
  333|  1.19k|	sc_log(ctx,
  ------------------
  |  |   71|  1.19k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  334|  1.19k|		"processing GemSAFE V1 specific FCI information\n");
  335|       |
  336|       |
  337|  1.19k|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &tlen);
  338|  1.19k|	if (!tag) {
  ------------------
  |  Branch (338:6): [True: 676, False: 523]
  ------------------
  339|       |		/* no FDB => we have a DF */
  340|    676|		type = "DF";
  341|    676|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    676|#define SC_FILE_TYPE_DF			0x04
  ------------------
  342|    676|	} else {
  343|    523|		type = "EF";
  344|    523|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    523|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  345|    523|	}
  346|       |
  347|  1.19k|	sc_log(ctx,  "file type: %s\n", type);
  ------------------
  |  |   71|  1.19k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  348|       |
  349|  1.19k|	tag = sc_asn1_find_tag(ctx, p, len, 0x8C, &tlen);
  350|  1.19k|	if (tag && tlen > 1) {
  ------------------
  |  Branch (350:6): [True: 116, False: 1.08k]
  |  Branch (350:13): [True: 81, False: 35]
  ------------------
  351|     81|		r = gemsafe_setacl(card, file, tag, strcmp(type, "DF") ? 0 : 1);
  ------------------
  |  Branch (351:39): [True: 40, False: 41]
  ------------------
  352|     81|		if (r < 0) {
  ------------------
  |  Branch (352:7): [True: 0, False: 81]
  ------------------
  353|      0|			sc_log(ctx,  "unable to set ACL\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  354|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  355|      0|		}
  356|     81|	} else
  357|  1.11k|		sc_log(ctx,  "error: AM and SC bytes missing\n");
  ------------------
  |  |   71|  1.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  358|       |
  359|  1.19k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.19k|#define SC_SUCCESS				0
  ------------------
  360|  1.19k|}
card-gemsafeV1.c:gemsafe_setacl:
  260|     81|{
  261|     81|	int       r;
  262|     81|	u8        cond;
  263|     81|	const u8 *p = data + 1;
  264|     81|	struct sc_context *ctx = card->ctx;
  265|       |
  266|     81|	if (is_df) {
  ------------------
  |  Branch (266:6): [True: 41, False: 40]
  ------------------
  267|     41|		if (*data & 0x04)	/* CREATE DF */
  ------------------
  |  Branch (267:7): [True: 23, False: 18]
  ------------------
  268|     23|			cond = *p++;
  269|     18|		else
  270|     18|			cond = 0xff;
  271|     41|		sc_log(ctx,
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  272|     41|			"DF security byte CREATE DF: %02x\n", cond);
  273|     41|		r = gemsafe_sc2acl(file, SC_AC_OP_CREATE, cond);
  ------------------
  |  |  169|     41|#define SC_AC_OP_CREATE			3
  ------------------
  274|     41|		if (r < 0)
  ------------------
  |  Branch (274:7): [True: 0, False: 41]
  ------------------
  275|      0|			return r;
  276|     41|		if (*data & 0x02)	/* CREATE EF */
  ------------------
  |  Branch (276:7): [True: 31, False: 10]
  ------------------
  277|     31|			cond = *p;
  278|     10|		else
  279|     10|			cond = 0xff;
  280|     41|		sc_log(ctx,
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  281|     41|			"DF security byte CREATE EF: %02x\n", cond);
  282|       |		/* XXX: opensc doesn't currently separate access conditions for
  283|       |		 * CREATE EF and CREATE DF, this should be changed */
  284|     41|		r = gemsafe_sc2acl(file, SC_AC_OP_CREATE, cond);
  ------------------
  |  |  169|     41|#define SC_AC_OP_CREATE			3
  ------------------
  285|     41|		if (r < 0)
  ------------------
  |  Branch (285:7): [True: 0, False: 41]
  ------------------
  286|      0|			return r;
  287|     41|	} else {
  288|       |		/* XXX: ACTIVATE FILE and DEACTIVATE FILE ac are currently not
  289|       |		 * supported => ignore them */
  290|     40|		if (*data & 0x02)	/* UPDATE BINARY, ERASE BINARY */
  ------------------
  |  Branch (290:7): [True: 25, False: 15]
  ------------------
  291|     25|			cond = *p++;
  292|     15|		else
  293|     15|			cond = 0xff;
  294|     40|		sc_log(ctx,
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  295|     40|			"EF security byte UPDATE/ERASE BINARY: %02x\n", cond);
  296|     40|		r = gemsafe_sc2acl(file, SC_AC_OP_UPDATE, cond);
  ------------------
  |  |  189|     40|#define SC_AC_OP_UPDATE			23
  ------------------
  297|     40|		if (r < 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 40]
  ------------------
  298|      0|			return r;
  299|     40|		r = gemsafe_sc2acl(file, SC_AC_OP_WRITE, cond);
  ------------------
  |  |  190|     40|#define SC_AC_OP_WRITE			24
  ------------------
  300|     40|		if (r < 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 40]
  ------------------
  301|      0|			return r;
  302|     40|		r = gemsafe_sc2acl(file, SC_AC_OP_ERASE, cond);
  ------------------
  |  |  202|     40|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     40|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  303|     40|		if (r < 0)
  ------------------
  |  Branch (303:7): [True: 0, False: 40]
  ------------------
  304|      0|			return r;
  305|     40|		if (*data & 0x01)	/* READ BINARY */
  ------------------
  |  Branch (305:7): [True: 26, False: 14]
  ------------------
  306|     26|			cond = *p;
  307|     14|		else
  308|     14|			cond = 0xff;
  309|     40|		sc_log(ctx,
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  310|     40|			"EF security byte READ BINARY: %02x\n", cond);
  311|     40|		r = gemsafe_sc2acl(file, SC_AC_OP_READ, cond);
  ------------------
  |  |  188|     40|#define SC_AC_OP_READ			22
  ------------------
  312|     40|		if (r < 0)
  ------------------
  |  Branch (312:7): [True: 0, False: 40]
  ------------------
  313|      0|			return r;
  314|     40|	}
  315|       |
  316|     81|	return SC_SUCCESS;
  ------------------
  |  |   28|     81|#define SC_SUCCESS				0
  ------------------
  317|     81|}
card-gemsafeV1.c:gemsafe_sc2acl:
  233|    242|{
  234|    242|	int r;
  235|    242|	unsigned int meth = 0;
  236|       |
  237|    242|	if (sc_byte == 0xff) {
  ------------------
  |  Branch (237:6): [True: 93, False: 149]
  ------------------
  238|     93|		r = sc_file_add_acl_entry(file, ops, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     93|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  239|     93|		return r;
  240|     93|	}
  241|    149|	if (sc_byte == 0x00) {
  ------------------
  |  Branch (241:6): [True: 26, False: 123]
  ------------------
  242|     26|		r = sc_file_add_acl_entry(file, ops, SC_AC_NONE, 0);
  ------------------
  |  |  150|     26|#define SC_AC_NONE			0x00000000
  ------------------
  243|     26|		return r;
  244|     26|	}
  245|       |
  246|       |	/* XXX: OR combination of access rights are currently not supported
  247|       |	 * hence ignored */
  248|    123|	if (sc_byte & 0x40)
  ------------------
  |  Branch (248:6): [True: 59, False: 64]
  ------------------
  249|     59|		meth |= SC_AC_PRO;
  ------------------
  |  |  153|     59|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  250|    123|	if (sc_byte & 0x20)
  ------------------
  |  Branch (250:6): [True: 78, False: 45]
  ------------------
  251|     78|		meth |= SC_AC_AUT | SC_AC_TERM;
  ------------------
  |  |  154|     78|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
              		meth |= SC_AC_AUT | SC_AC_TERM;
  ------------------
  |  |  152|     78|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  252|    123|	if (sc_byte & 0x10)
  ------------------
  |  Branch (252:6): [True: 49, False: 74]
  ------------------
  253|     49|		meth |= SC_AC_CHV;
  ------------------
  |  |  151|     49|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  254|       |
  255|    123|	return sc_file_add_acl_entry(file, ops, meth, sc_byte & 0x0f);
  256|    149|}
card-gemsafeV1.c:gemsafe_card_reader_lock_obtained:
  545|  1.82k|{
  546|  1.82k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.82k|#define SC_SUCCESS				0
  ------------------
  547|  1.82k|	gemsafe_exdata *exdata = (gemsafe_exdata *)card->drv_data;
  548|       |
  549|  1.82k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.82k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.82k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.82k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.82k]
  |  |  ------------------
  ------------------
  550|       |
  551|  1.82k|	if (was_reset > 0 && exdata) {
  ------------------
  |  Branch (551:6): [True: 0, False: 1.82k]
  |  Branch (551:23): [True: 0, False: 0]
  ------------------
  552|      0|		r = iso7816_select_aid(card, exdata->aid, exdata->aid_len, NULL, NULL);
  553|      0|	}
  554|       |
  555|  1.82k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.82k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.82k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.82k|	int _ret = r; \
  |  |  |  |  155|  1.82k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.82k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.82k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.82k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.82k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.82k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.82k|	return _ret; \
  |  |  |  |  163|  1.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  1.82k|}

sc_get_gids_driver:
 2185|  15.2k|{
 2186|  15.2k|	return sc_get_driver();
 2187|  15.2k|}
card-gids.c:sc_get_driver:
 2140|  15.2k|{
 2141|       |
 2142|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2142:6): [True: 1, False: 15.2k]
  ------------------
 2143|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2144|       |
 2145|  15.2k|	gids_ops.match_card = gids_match_card;
 2146|  15.2k|	gids_ops.init = gids_init;
 2147|  15.2k|	gids_ops.finish = gids_finish;
 2148|  15.2k|	gids_ops.read_binary = gids_read_binary;
 2149|  15.2k|	gids_ops.write_binary = NULL;
 2150|  15.2k|	gids_ops.update_binary = NULL;
 2151|  15.2k|	gids_ops.erase_binary = NULL;
 2152|  15.2k|	gids_ops.read_record = NULL;
 2153|  15.2k|	gids_ops.write_record = NULL;
 2154|  15.2k|	gids_ops.append_record = NULL;
 2155|  15.2k|	gids_ops.update_record = NULL;
 2156|  15.2k|	gids_ops.select_file = gids_select_file;
 2157|  15.2k|	gids_ops.get_response = iso_ops->get_response;
 2158|  15.2k|	gids_ops.get_challenge = NULL;
 2159|  15.2k|	gids_ops.verify = NULL; // see pin_cmd
 2160|  15.2k|	gids_ops.logout = gids_logout;
 2161|  15.2k|	gids_ops.restore_security_env = NULL;
 2162|  15.2k|	gids_ops.set_security_env = gids_set_security_env;
 2163|  15.2k|	gids_ops.decipher = gids_decipher;
 2164|  15.2k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2165|  15.2k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2166|  15.2k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2167|  15.2k|	gids_ops.create_file = iso_ops->create_file;
 2168|  15.2k|	gids_ops.delete_file = NULL;
 2169|  15.2k|	gids_ops.list_files = NULL;
 2170|  15.2k|	gids_ops.check_sw = iso_ops->check_sw;
 2171|  15.2k|	gids_ops.card_ctl = gids_card_ctl;
 2172|  15.2k|	gids_ops.process_fci = iso_ops->process_fci;
 2173|  15.2k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2174|  15.2k|	gids_ops.pin_cmd = gids_pin_cmd;
 2175|  15.2k|	gids_ops.get_data = NULL;
 2176|  15.2k|	gids_ops.put_data = NULL;
 2177|  15.2k|	gids_ops.delete_record = NULL;
 2178|  15.2k|	gids_ops.read_public_key = gids_read_public_key;
 2179|  15.2k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2180|       |
 2181|  15.2k|	return &gids_drv;
 2182|  15.2k|}
card-gids.c:gids_match_card:
  563|  3.65k|{
  564|  3.65k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  565|  3.65k|	int r,i;
  566|  3.65k|	size_t resplen = sizeof(rbuf);
  567|  3.65k|	const u8 *tag;
  568|  3.65k|	size_t taglen;
  569|  3.65k|	const u8 *aid;
  570|  3.65k|	size_t aidlen;
  571|       |
  572|  3.65k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.65k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.65k]
  |  |  ------------------
  ------------------
  573|       |
  574|       |	/* Detect by selecting applet */
  575|  3.65k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  576|  3.65k|	if (r<0) return 0;
  ------------------
  |  Branch (576:6): [True: 3.53k, False: 120]
  ------------------
  577|       |
  578|    120|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  579|    120|	if (resplen > 2) {
  ------------------
  |  Branch (579:6): [True: 20, False: 100]
  ------------------
  580|     20|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     20|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  581|     20|		if (tag != NULL) {
  ------------------
  |  Branch (581:7): [True: 18, False: 2]
  ------------------
  582|     18|			aid = sc_asn1_find_tag(card->ctx, tag, taglen, GIDS_APPLICATION_AID_TAG, &aidlen);
  ------------------
  |  |  106|     18|#define GIDS_APPLICATION_AID_TAG 0x4F
  ------------------
  583|     18|			if (aid != NULL ) {
  ------------------
  |  Branch (583:8): [True: 17, False: 1]
  ------------------
  584|     17|				sc_log(card->ctx, "found AID");
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  585|     48|				for (i = 0; gids_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (585:17): [True: 33, False: 15]
  ------------------
  586|     33|					if ( aidlen > gids_aids[i].len_long && memcmp(aid, gids_aids[i].value,
  ------------------
  |  Branch (586:11): [True: 31, False: 2]
  |  Branch (586:45): [True: 2, False: 29]
  ------------------
  587|     31|									gids_aids[i].len_long) == 0) {
  588|      2|						card->type = gids_aids[i].enumtag;
  589|      2|						break;
  590|      2|					}
  591|     33|				}
  592|     17|			}
  593|     18|		}
  594|     20|	}
  595|       |
  596|    120|	return 1;
  597|  3.65k|}
card-gids.c:gids_select_aid:
  280|  3.65k|{
  281|  3.65k|	sc_apdu_t apdu;
  282|  3.65k|	int r;
  283|       |
  284|  3.65k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.65k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.65k]
  |  |  ------------------
  ------------------
  285|  3.65k|	sc_log(card->ctx, "Got args: aid=%p, aidlen=%zu, response=%p, responselen=%zu",
  ------------------
  |  |   71|  7.30k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.65k, False: 0]
  |  |  ------------------
  ------------------
  286|  3.65k|			aid, aidlen, response, responselen ? *responselen : 0);
  287|       |
  288|  3.65k|	sc_format_apdu(card, &apdu,
  289|  3.65k|		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |  294|  3.65k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   68|  3.65k|#define INS_SELECT 0xA4
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   72|  3.65k|#define P1_SELECT_DF_BY_NAME 0x04
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   75|  3.65k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (289:3): [True: 0, False: 3.65k]
  ------------------
  290|  3.65k|	apdu.lc = aidlen;
  291|  3.65k|	apdu.data = aid;
  292|  3.65k|	apdu.datalen = aidlen;
  293|  3.65k|	apdu.resp = response;
  294|  3.65k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (294:17): [True: 3.65k, False: 0]
  ------------------
  295|  3.65k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (295:12): [True: 0, False: 3.65k]
  ------------------
  296|       |
  297|  3.65k|	r = sc_transmit_apdu(card, &apdu);
  298|  3.65k|	if (responselen)
  ------------------
  |  Branch (298:6): [True: 3.65k, False: 0]
  ------------------
  299|  3.65k|		*responselen = apdu.resplen;
  300|  3.65k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  3.65k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.65k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.65k|	int _ret = (r); \
  |  |  |  |  168|  3.65k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 3.64k]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|  3.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|  3.64k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  3.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.64k|	int _ret = r; \
  |  |  155|  3.64k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.64k, False: 0]
  |  |  ------------------
  |  |  156|  3.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  3.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.52k, False: 120]
  |  |  ------------------
  |  |  157|  3.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.64k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  3.64k|	return _ret; \
  |  |  163|  3.64k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  302|  3.64k|}
card-gids.c:gids_init:
  631|    120|{
  632|    120|	unsigned long flags;
  633|    120|	struct gids_private_data *data;
  634|    120|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    120|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    120|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    120|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 120]
  |  |  ------------------
  ------------------
  635|       |
  636|       |	// cache some data in memory
  637|    120|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  638|    120|	if (!data) {
  ------------------
  |  Branch (638:6): [True: 0, False: 120]
  ------------------
  639|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|      0|	}
  641|    120|	memset(data, 0, sizeof(struct gids_private_data));
  642|    120|	card->drv_data = data;
  643|       |	// invalidate the master file and cmap file cache
  644|    120|	data->cmapfilesize = sizeof(data->cmapfile);
  645|    120|	data->masterfilesize = sizeof(data->masterfile);
  646|       |
  647|       |	/* supported RSA keys and how padding is done */
  648|    120|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|    120|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    120|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    120|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  133|    120|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    120|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  649|       |
  650|       |	/* fix me: add other algorithms when the gids specification will tell how to extract the algo id from the FCP */
  651|    120|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  652|    120|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  653|    120|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  654|    120|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  655|       |
  656|    120|	return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  657|    120|}
card-gids.c:gids_finish:
  661|    120|{
  662|    120|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    120|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    120|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    120|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 120]
  |  |  ------------------
  ------------------
  663|       |	/* free the private data */
  664|    120|	if (card->drv_data) {
  ------------------
  |  Branch (664:6): [True: 120, False: 0]
  ------------------
  665|    120|		free(card->drv_data);
  666|       |		card->drv_data = NULL;
  667|    120|	}
  668|    120|	return 0;
  669|    120|}
card-gids.c:gids_read_binary:
 1032|      6|		unsigned char *buf, size_t count, unsigned long *flags) {
 1033|      6|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
 1034|      6|	struct sc_context *ctx = card->ctx;
 1035|      6|	int r;
 1036|      6|	int size;
 1037|       |
 1038|      6|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      6|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      6|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1039|       |
 1040|      6|	if (! data->currentDO || ! data->currentEFID) {
  ------------------
  |  Branch (1040:6): [True: 6, False: 0]
  |  Branch (1040:27): [True: 0, False: 0]
  ------------------
 1041|      6|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1042|      6|	}
 1043|      0|	if (data->state != GIDS_STATE_READ_DATA_PRESENT) {
  ------------------
  |  |   58|      0|#define GIDS_STATE_READ_DATA_PRESENT 1
  ------------------
  |  Branch (1043:6): [True: 0, False: 0]
  ------------------
 1044|       |		// this function is called to read the certificate only
 1045|      0|		u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1046|      0|		size_t buffersize = sizeof(buffer);
 1047|      0|		r = gids_get_DO(card, data->currentEFID, data->currentDO, buffer, &(buffersize));
 1048|      0|		if (r <0) return r;
  ------------------
  |  Branch (1048:7): [True: 0, False: 0]
  ------------------
 1049|      0|		if (buffersize < 4) {
  ------------------
  |  Branch (1049:7): [True: 0, False: 0]
  ------------------
 1050|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1051|      0|		}
 1052|      0|		if (buffer[0] == 1 && buffer[1] == 0) {
  ------------------
  |  Branch (1052:7): [True: 0, False: 0]
  |  Branch (1052:25): [True: 0, False: 0]
  ------------------
 1053|      0|			if (flags)
  ------------------
  |  Branch (1053:8): [True: 0, False: 0]
  ------------------
 1054|      0|				*flags |= SC_FILE_FLAG_COMPRESSED_ZLIB;
  ------------------
  |  |  231|      0|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
 1055|       |			/* compressed data are starting on position buffer + 4 */
 1056|      0|			data->buffersize = buffersize - 4;
 1057|      0|			memcpy(data->buffer, buffer + 4, buffersize - 4);
 1058|      0|		} else {
 1059|      0|			sc_log(card->ctx, "unknown compression method %d", buffer[0] + (buffer[1] << 8));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1060|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1061|      0|		}
 1062|      0|		data->state = GIDS_STATE_READ_DATA_PRESENT;
  ------------------
  |  |   58|      0|#define GIDS_STATE_READ_DATA_PRESENT 1
  ------------------
 1063|      0|	}
 1064|      0|	if (offset >= data->buffersize) {
  ------------------
  |  Branch (1064:6): [True: 0, False: 0]
  ------------------
 1065|      0|		return 0;
 1066|      0|	}
 1067|      0|	size = (int) MIN((data->buffersize - offset), count);
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1068|      0|	memcpy(buf, data->buffer + offset, size);
 1069|      0|	return size;
 1070|      0|}
card-gids.c:gids_get_DO:
  210|    125|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|    125|	sc_apdu_t apdu;
  212|    125|	int r;
  213|    125|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|    125|	size_t datasize = 0;
  215|    125|	const u8* p;
  216|    125|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|    125|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|    125|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    125|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    125|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    125|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 125]
  |  |  ------------------
  ------------------
  220|    125|	sc_log(card->ctx, "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%zu",
  ------------------
  |  |   71|    250|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 125, False: 0]
  |  |  ------------------
  ------------------
  221|    125|			fileIdentifier, dataObjectIdentifier, response, responselen ? *responselen : 0);
  222|       |
  223|    125|	sc_format_apdu(card, &apdu,
  224|    125|		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_GET_DATA, (fileIdentifier&0xFF00)>>8, (fileIdentifier&0xFF));
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_GET_DATA, (fileIdentifier&0xFF00)>>8, (fileIdentifier&0xFF));
  ------------------
  |  |  294|    125|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_GET_DATA, (fileIdentifier&0xFF00)>>8, (fileIdentifier&0xFF));
  ------------------
  |  |   65|    125|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (224:3): [True: 0, False: 125]
  ------------------
  225|    125|	apdu.lc = 04;
  226|    125|	apdu.data = data;
  227|    125|	apdu.datalen = 04;
  228|    125|	apdu.resp = buffer;
  229|    125|	apdu.resplen = buffer_len;
  230|    125|	apdu.le = 256;
  231|       |
  232|    125|	r = sc_transmit_apdu(card, &apdu);
  233|    125|	LOG_TEST_RET(card->ctx, r, "gids get data failed");
  ------------------
  |  |  174|    125|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    125|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    125|	int _ret = (r); \
  |  |  |  |  168|    125|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    122|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  169|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     31|		return _ret; \
  |  |  |  |  172|     31|	} \
  |  |  |  |  173|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|     91|	buffer_len = apdu.resplen;
  236|       |
  237|     91|	p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize);
  238|     91|	if (!p) {
  ------------------
  |  Branch (238:6): [True: 5, False: 86]
  ------------------
  239|      5|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|      5|	}
  241|     86|	if (response && responselen) {
  ------------------
  |  Branch (241:6): [True: 86, False: 0]
  |  Branch (241:18): [True: 86, False: 0]
  ------------------
  242|     86|		if (datasize > *responselen) {
  ------------------
  |  Branch (242:7): [True: 0, False: 86]
  ------------------
  243|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|      0|		}
  245|     86|		memcpy(response, p, datasize);
  246|     86|		*responselen = datasize;
  247|     86|	}
  248|     86|	return SC_SUCCESS;
  ------------------
  |  |   28|     86|#define SC_SUCCESS				0
  ------------------
  249|     86|}
card-gids.c:gids_select_file:
  964|    604|			   struct sc_file **file_out) {
  965|    604|	struct sc_file *file = NULL;
  966|    604|	struct sc_context *ctx = card->ctx;
  967|    604|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  968|       |
  969|    604|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    604|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    604|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    604|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    604|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 604]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|       |
  971|    604|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    604|#define GIDS_STATE_NONE 0
  ------------------
  972|    604|	data->currentDO = 0;
  973|    604|	data->currentEFID = 0;
  974|    604|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (974:6): [True: 351, False: 253]
  |  Branch (974:27): [True: 0, False: 351]
  ------------------
  975|       |		// is it a DO pseudo file ?
  976|       |		// yes, succeed
  977|      0|		data->currentEFID = in_path->value[1] + (in_path->value[0]<<8);
  978|      0|		data->currentDO = in_path->value[3] + (in_path->value[2]<<8);
  979|       |
  980|      0|		if (file_out) {
  ------------------
  |  Branch (980:7): [True: 0, False: 0]
  ------------------
  981|      0|			file = sc_file_new();
  982|      0|			if (file == NULL)
  ------------------
  |  Branch (982:8): [True: 0, False: 0]
  ------------------
  983|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  984|      0|			file->path = *in_path;
  985|      0|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      0|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  986|      0|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|      0|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  987|      0|			file->size = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|      0|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  988|      0|			*file_out = file;
  989|      0|		}
  990|      0|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|    604|	} else if (in_path->len == 4 && in_path->value[0] == 0x3F && in_path->value[1] == 0xFF &&  in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|      0|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (991:13): [True: 351, False: 253]
  |  Branch (991:34): [True: 351, False: 0]
  |  Branch (991:63): [True: 0, False: 351]
  |  Branch (991:93): [True: 0, False: 0]
  ------------------
  992|       |		// GIDS does not allow a select with a path containing a DF
  993|       |		// replace the file selection from SC_PATH_TYPE_PATH to SC_PATH_TYPE_FILE_ID
  994|      0|		struct sc_path key_path;
  995|      0|		memset(&key_path, 0, sizeof(key_path));
  996|      0|		key_path.len = 2;
  997|      0|		key_path.value[0] = in_path->value[2];
  998|      0|		key_path.value[1] = in_path->value[3];
  999|      0|		key_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1000|      0|		return iso_ops->select_file(card, &key_path, file_out);
 1001|    604|	} else {
 1002|    604|		return iso_ops->select_file(card, in_path, file_out);
 1003|    604|	}
 1004|    604|}
card-gids.c:gids_card_ctl:
 2089|    126|{
 2090|    126|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    126|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    126|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    126|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    126|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 126]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2091|    126|	switch (cmd) {
 2092|      6|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2092:3): [True: 6, False: 120]
  ------------------
 2093|      6|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2094|    120|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2094:3): [True: 120, False: 6]
  ------------------
 2095|    120|			return gids_get_all_containers(card, (size_t*) ptr);
 2096|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2096:3): [True: 0, False: 126]
  ------------------
 2097|      0|			return gids_get_container_detail(card, (sc_cardctl_gids_get_container_t*) ptr);
 2098|      0|		case SC_CARDCTL_GIDS_SELECT_KEY_REFERENCE:
  ------------------
  |  Branch (2098:3): [True: 0, False: 126]
  ------------------
 2099|      0|			return gids_select_key_reference(card, (sc_pkcs15_prkey_info_t*) ptr);
 2100|      0|		case SC_CARDCTL_GIDS_CREATE_KEY:
  ------------------
  |  Branch (2100:3): [True: 0, False: 126]
  ------------------
 2101|      0|			return gids_create_keyfile(card, (sc_pkcs15_object_t*) ptr);
 2102|      0|		case SC_CARDCTL_GIDS_GENERATE_KEY:
  ------------------
  |  Branch (2102:3): [True: 0, False: 126]
  ------------------
 2103|      0|			return gids_generate_key(card, ((struct sc_cardctl_gids_genkey*) ptr)->object, ((struct sc_cardctl_gids_genkey*) ptr)->pubkey);
 2104|      0|		case SC_CARDCTL_GIDS_IMPORT_KEY:
  ------------------
  |  Branch (2104:3): [True: 0, False: 126]
  ------------------
 2105|      0|			return gids_import_key(card, ((struct sc_cardctl_gids_importkey*) ptr)->object, ((struct sc_cardctl_gids_importkey*) ptr)->key);
 2106|      0|		case SC_CARDCTL_GIDS_SAVE_CERT:
  ------------------
  |  Branch (2106:3): [True: 0, False: 126]
  ------------------
 2107|      0|			return gids_save_certificate(card, ((struct sc_cardctl_gids_save_cert*) ptr)->certobject,
 2108|      0|										((struct sc_cardctl_gids_save_cert*) ptr)->privkeyobject, ((struct sc_cardctl_gids_save_cert*) ptr)->path);
 2109|      0|		case SC_CARDCTL_GIDS_DELETE_CERT:
  ------------------
  |  Branch (2109:3): [True: 0, False: 126]
  ------------------
 2110|      0|			return gids_delete_cert(card, (sc_pkcs15_object_t*) ptr);
 2111|      0|		case SC_CARDCTL_GIDS_DELETE_KEY:
  ------------------
  |  Branch (2111:3): [True: 0, False: 126]
  ------------------
 2112|      0|			return gids_delete_key(card, (sc_pkcs15_object_t*) ptr);
 2113|      0|		case SC_CARDCTL_GIDS_INITIALIZE:
  ------------------
  |  Branch (2113:3): [True: 0, False: 126]
  ------------------
 2114|      0|			return gids_initialize(card, (sc_cardctl_gids_init_param_t*) ptr);
 2115|      0|		case SC_CARDCTL_GIDS_SET_ADMIN_KEY:
  ------------------
  |  Branch (2115:3): [True: 0, False: 126]
  ------------------
 2116|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2117|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2117:3): [True: 0, False: 126]
  ------------------
 2118|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2119|      0|		default:
  ------------------
  |  Branch (2119:3): [True: 0, False: 126]
  ------------------
 2120|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2121|    126|	}
 2122|    126|}
card-gids.c:gids_get_serialnr:
  602|      6|{
  603|      6|	int r;
  604|      6|	u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  605|      6|	size_t buffersize;
  606|       |
  607|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
  608|       |
  609|      6|	buffersize = sizeof(buffer);
  610|      6|	r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
  611|      6|	LOG_TEST_RET(card->ctx, r, "unable to read cardid");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|      0|	if (SC_MAX_SERIALNR < buffersize)
  ------------------
  |  |  372|      0|#define SC_MAX_SERIALNR         32
  ------------------
  |  Branch (613:6): [True: 0, False: 0]
  ------------------
  614|      0|	{
  615|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  616|      0|	}
  617|       |
  618|       |	/* cache serial number */
  619|      0|	card->serialnr.len = buffersize;
  620|      0|	memcpy(card->serialnr.value, buffer, card->serialnr.len);
  621|       |
  622|       |	/* return cached serial number */
  623|      0|	if (serial)
  ------------------
  |  Branch (623:6): [True: 0, False: 0]
  ------------------
  624|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  625|       |
  626|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  627|      0|}
card-gids.c:gids_read_gidsfile:
  385|     87|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  386|     87|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  387|     87|	int r;
  388|     87|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     87|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     87|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     87|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 87]
  |  |  ------------------
  ------------------
  389|     87|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (389:6): [True: 4, False: 83]
  ------------------
  390|      4|		r = gids_read_masterfile(card);
  391|      4|		LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|      4|	}
  393|     84|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  394|     84|		directory, filename, response, responselen);
  395|     84|	LOG_TEST_RET(card->ctx, r, "unable to read the file");
  ------------------
  |  |  174|     84|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     84|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     84|	int _ret = (r); \
  |  |  |  |  168|     84|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 84, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     84|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     84|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     84|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     84|		return _ret; \
  |  |  |  |  172|     84|	} \
  |  |  |  |  173|     84|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|      0|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  397|      0|}
card-gids.c:gids_read_masterfile:
  340|    124|static int gids_read_masterfile(sc_card_t* card) {
  341|    124|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  342|    124|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    124|#define SC_SUCCESS				0
  ------------------
  343|       |
  344|    124|	data->masterfilesize = sizeof(data->masterfile);
  345|    124|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|    124|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|    124|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|    124|#define MF_DO 0xDF1F
  ------------------
  346|    124|	if (r<0) {
  ------------------
  |  Branch (346:6): [True: 38, False: 86]
  ------------------
  347|     38|		data->masterfilesize = sizeof(data->masterfile);
  348|     38|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     38|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     38|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     38|	int _ret = r; \
  |  |  |  |  155|     38|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     38|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     38|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     38|	return _ret; \
  |  |  |  |  163|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|     38|	}
  350|     86|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (350:6): [True: 1, False: 85]
  |  Branch (350:34): [True: 3, False: 82]
  ------------------
  351|      4|		data->masterfilesize = sizeof(data->masterfile);
  352|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      4|	}
  354|     82|	return r;
  355|     86|}
card-gids.c:gids_read_gidsfile_without_cache:
  308|     84|static int gids_read_gidsfile_without_cache(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, u8* response, size_t *responselen) {
  309|     84|	int r;
  310|     84|	int fileIdentifier;
  311|     84|	int dataObjectIdentifier;
  312|       |
  313|     84|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     84|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     84|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     84|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 84]
  |  |  ------------------
  ------------------
  314|     84|	r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
  315|     84|	LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
  ------------------
  |  |  174|     84|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     84|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     84|	int _ret = (r); \
  |  |  |  |  168|     84|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 83, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     83|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     83|		return _ret; \
  |  |  |  |  172|     83|	} \
  |  |  |  |  173|     84|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|      1|	r = gids_get_DO(card, fileIdentifier, dataObjectIdentifier, response, responselen);
  317|      1|	LOG_TEST_RET(card->ctx, r, "unable to get the data from the file");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|      0|	return r;
  319|      1|}
card-gids.c:gids_get_identifiers:
  163|     84|static int gids_get_identifiers(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, int *fileIdentifier, int *dataObjectIdentifier) {
  164|     84|	gids_mf_record_t *records = (gids_mf_record_t *) (masterfile+1);
  165|     84|	size_t recordcount = ((masterfilesize-1) / sizeof(gids_mf_record_t));
  166|     84|	size_t i;
  167|     84|	if (masterfilesize < 1)
  ------------------
  |  Branch (167:6): [True: 0, False: 84]
  ------------------
  168|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  169|       |
  170|    184|	for (i = 0; i < recordcount; i++) {
  ------------------
  |  Branch (170:14): [True: 101, False: 83]
  ------------------
  171|    101|		if (strncmp(directory, records[i].directory, sizeof(records[i].directory)) == 0 && strncmp(filename, records[i].filename, sizeof(records[i].filename)) == 0) {
  ------------------
  |  Branch (171:7): [True: 76, False: 25]
  |  Branch (171:86): [True: 1, False: 75]
  ------------------
  172|      1|			*fileIdentifier = records[i].fileIdentifier;
  173|      1|			*dataObjectIdentifier = records[i].dataObjectIdentifier;
  174|      1|			sc_log(card->ctx,
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|      1|		"Identifiers of %s %s is fileIdentifier=%x, dataObjectIdentifier=%x\n", directory, filename, *fileIdentifier, *dataObjectIdentifier);
  176|      1|			return 0;
  177|      1|		}
  178|    101|	}
  179|     83|	sc_log(card->ctx, "file %s %s not found\n", directory, filename);
  ------------------
  |  |   71|     83|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  180|     83|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     83|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  181|     84|}
card-gids.c:gids_get_all_containers:
 1074|    120|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1075|    120|	int r;
 1076|    120|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1077|    120|	r = gids_read_masterfile(card);
 1078|    120|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  174|    120|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    120|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    120|	int _ret = (r); \
  |  |  |  |  168|    120|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|    120|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     81|	r = gids_read_cmapfile(card);
 1080|     81|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1081|      0|	*recordsnum = (privatedata ->cmapfilesize / sizeof(CONTAINER_MAP_RECORD));
 1082|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1083|     81|}
card-gids.c:gids_read_cmapfile:
  427|     81|static int gids_read_cmapfile(sc_card_t* card) {
  428|     81|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  429|     81|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     81|#define SC_SUCCESS				0
  ------------------
  430|       |
  431|     81|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     81|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     81|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     81|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 81]
  |  |  ------------------
  ------------------
  432|     81|	data->cmapfilesize = sizeof(data->cmapfile);
  433|     81|	r = gids_read_gidsfile(card, "mscp", "cmapfile", data->cmapfile, &data->cmapfilesize);
  434|     81|	if (r<0) {
  ------------------
  |  Branch (434:6): [True: 81, False: 0]
  ------------------
  435|     81|		data->cmapfilesize = sizeof(data->cmapfile);
  436|     81|	}
  437|     81|	LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|      0|	return r;
  439|     81|}
card-gids.c:gids_pin_cmd:
 1022|      6|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1023|      6|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      6|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1023:6): [True: 6, False: 0]
  ------------------
 1024|      6|		return gids_get_pin_policy(card, data);
 1025|      6|	} else {
 1026|      0|		return iso_ops->pin_cmd(card, data);
 1027|      0|	}
 1028|      6|}
card-gids.c:gids_get_pin_policy:
 1006|      6|static int gids_get_pin_policy(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1007|      6|	int r;
 1008|      6|	if (data->pin_type != SC_AC_CHV) {
  ------------------
  |  |  151|      6|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1008:6): [True: 0, False: 6]
  ------------------
 1009|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1010|      0|	}
 1011|      6|	r = gids_get_pin_status(card, data->pin_reference, &(data->pin1.tries_left), &(data->pin1.max_tries));
 1012|      6|	LOG_TEST_RET(card->ctx, r, "gids_get_pin_status failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1013|      0|	data->pin1.max_length = 16;
 1014|      0|	data->pin1.min_length = 4;
 1015|      0|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1016|      0|	data->pin1.offset = 5;
 1017|      0|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1018|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1019|      6|}
card-gids.c:gids_get_pin_status:
  516|      6|static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_left, int *max_tries) {
  517|      6|	int dataObjectIdentifier, r;
  518|      6|	u8 buffer[100];
  519|      6|	const u8* p;
  520|      6|	size_t buffersize = sizeof(buffer);
  521|      6|	size_t datasize;
  522|       |
  523|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
  524|      6|	if (tries_left) *tries_left = -1;
  ------------------
  |  Branch (524:6): [True: 6, False: 0]
  ------------------
  525|      6|	if (max_tries) *max_tries = -1;
  ------------------
  |  Branch (525:6): [True: 6, False: 0]
  ------------------
  526|      6|	switch(pinreference) {
  527|      0|	case GIDS_PIN_IDENTIFIER:
  ------------------
  |  |  100|      0|#define GIDS_PIN_IDENTIFIER 0x80
  ------------------
  |  Branch (527:2): [True: 0, False: 6]
  ------------------
  528|      0|		dataObjectIdentifier = GIDS_PIN_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   80|      0|#define GIDS_PIN_STATUS_OBJECT_IDENTIFIER 0x7F71
  ------------------
  529|      0|		break;
  530|      0|	case GIDS_PUK_IDENTIFIER:
  ------------------
  |  |  101|      0|#define GIDS_PUK_IDENTIFIER 0x81
  ------------------
  |  Branch (530:2): [True: 0, False: 6]
  ------------------
  531|      0|		dataObjectIdentifier = GIDS_PUK_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   81|      0|#define GIDS_PUK_STATUS_OBJECT_IDENTIFIER 0x7F73
  ------------------
  532|      0|		break;
  533|      6|	default:
  ------------------
  |  Branch (533:2): [True: 6, False: 0]
  ------------------
  534|      6|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|      6|	}
  536|      0|	r = gids_get_DO(card, GIDS_APPLET_EFID, dataObjectIdentifier, buffer, &buffersize);
  ------------------
  |  |   82|      0|#define GIDS_APPLET_EFID 0x3FFF
  ------------------
  537|      0|	LOG_TEST_RET(card->ctx, r, "unable to update the masterfile");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|       |
  539|      0|	buffersize = buffersize > sizeof(buffer) ? sizeof(buffer) : buffersize;
  ------------------
  |  Branch (539:15): [True: 0, False: 0]
  ------------------
  540|       |
  541|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_OLD_TAG, &datasize);
  ------------------
  |  |  102|      0|#define GIDS_TRY_COUNTER_OLD_TAG 0x9F17
  ------------------
  542|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (542:6): [True: 0, False: 0]
  |  Branch (542:11): [True: 0, False: 0]
  ------------------
  543|      0|		if (tries_left)
  ------------------
  |  Branch (543:7): [True: 0, False: 0]
  ------------------
  544|      0|			*tries_left = p[0];
  545|      0|	}
  546|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_TAG, &datasize);
  ------------------
  |  |  103|      0|#define GIDS_TRY_COUNTER_TAG 0x97
  ------------------
  547|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (547:6): [True: 0, False: 0]
  |  Branch (547:11): [True: 0, False: 0]
  ------------------
  548|      0|		if (tries_left)
  ------------------
  |  Branch (548:7): [True: 0, False: 0]
  ------------------
  549|      0|			*tries_left = p[0];
  550|      0|	}
  551|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize , GIDS_TRY_LIMIT_TAG, &datasize);
  ------------------
  |  |  104|      0|#define GIDS_TRY_LIMIT_TAG 0x93
  ------------------
  552|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (552:6): [True: 0, False: 0]
  |  Branch (552:11): [True: 0, False: 0]
  ------------------
  553|      0|		if (max_tries)
  ------------------
  |  Branch (553:7): [True: 0, False: 0]
  ------------------
  554|      0|			*max_tries = p[0];
  555|      0|	}
  556|       |
  557|      0|	sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  558|      0|		"Pin information for PIN 0x%x: triesleft=%d trieslimit=%d\n", pinreference, (tries_left?*tries_left:-1), (max_tries?*max_tries:-1));
  559|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|      0|}
card-gids.c:gids_card_reader_lock_obtained:
 2125|  3.89k|{
 2126|  3.89k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.89k|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|  3.89k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.89k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.89k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.89k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.89k]
  |  |  ------------------
  ------------------
 2129|       |
 2130|  3.89k|	if (was_reset > 0) {
  ------------------
  |  Branch (2130:6): [True: 0, False: 3.89k]
  ------------------
 2131|      0|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2132|      0|		size_t resplen = sizeof(rbuf);
 2133|      0|		r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
 2134|      0|	}
 2135|       |
 2136|  3.89k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.89k|	int _ret = r; \
  |  |  |  |  155|  3.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.89k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.89k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.89k|	return _ret; \
  |  |  |  |  163|  3.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2137|  3.89k|}

sc_invalidate_cache:
  164|  3.37k|{
  165|  3.37k|	if (card) {
  ------------------
  |  Branch (165:6): [True: 3.37k, False: 0]
  ------------------
  166|  3.37k|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|  3.37k|		sc_file_free(prv->cache.current_ef);
  168|  3.37k|		sc_file_free(prv->cache.current_df);
  169|  3.37k|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|  3.37k|		prv->cache.valid = 0;
  171|  3.37k|	}
  172|  3.37k|}
iasecc_se_get_info:
 1609|    255|{
 1610|    255|	struct sc_context *ctx = card->ctx;
 1611|    255|	struct sc_apdu apdu;
 1612|    255|	unsigned char rbuf[0x100];
 1613|    255|	unsigned char sbuf_iasecc[10] = {
 1614|    255|		0x4D, 0x08, IASECC_SDO_TEMPLATE_TAG, 0x06,
  ------------------
  |  |   29|    255|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 1615|    255|		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   27|    255|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |  102|    255|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   59|    255|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 1616|    255|		se->reference & 0x3F,
 1617|    255|		0x02, IASECC_SDO_CLASS_SE, 0x80
  ------------------
  |  |  102|    255|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 1618|    255|	};
 1619|    255|	int rv;
 1620|       |
 1621|    255|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    255|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    255|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    255|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    255|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|    255|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1623:6): [True: 13, False: 242]
  ------------------
 1624|     13|		rv = iasecc_select_mf(card, NULL);
 1625|     13|		LOG_TEST_RET(ctx, rv, "MF invalid");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1626|     13|	}
 1627|       |
 1628|    248|	if (se->reference > IASECC_SE_REF_MAX)
  ------------------
  |  |   66|    248|#define IASECC_SE_REF_MAX	0x0F
  ------------------
  |  Branch (1628:6): [True: 0, False: 248]
  ------------------
 1629|    248|                LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1630|       |
 1631|    248|	rv = iasecc_se_get_info_from_cache(card, se);
 1632|    248|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    248|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1632:6): [True: 244, False: 4]
  ------------------
 1633|    244|		sc_log(ctx, "No SE#%X info in cache, try to use 'GET DATA'", se->reference);
  ------------------
  |  |   71|    244|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1634|       |
 1635|    244|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    244|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1636|    244|		apdu.data = sbuf_iasecc;
 1637|    244|		apdu.datalen = sizeof(sbuf_iasecc);
 1638|    244|		apdu.lc = apdu.datalen;
 1639|    244|		apdu.resp = rbuf;
 1640|    244|		apdu.resplen = sizeof(rbuf);
 1641|    244|		apdu.le = sizeof(rbuf);
 1642|       |
 1643|    244|		rv = sc_transmit_apdu(card, &apdu);
 1644|    244|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    244|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    244|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    244|	int _ret = (r); \
  |  |  |  |  168|    244|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 233]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 233]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1645|    233|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1646|    233|		LOG_TEST_RET(ctx, rv, "get SE data  error");
  ------------------
  |  |  174|    233|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    233|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    233|	int _ret = (r); \
  |  |  |  |  168|    233|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 205]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|    233|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 205]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1647|       |
 1648|    205|		rv = iasecc_se_parse(card, apdu.resp, apdu.resplen, se);
 1649|    205|		LOG_TEST_RET(ctx, rv, "cannot parse SE data");
  ------------------
  |  |  174|    205|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    205|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    205|	int _ret = (r); \
  |  |  |  |  168|    205|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 177, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  169|    177|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    177|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    177|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    177|		return _ret; \
  |  |  |  |  172|    177|	} \
  |  |  |  |  173|    205|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|       |
 1651|     28|		rv = iasecc_se_cache_info(card, se);
 1652|     28|		LOG_TEST_RET(ctx, rv, "failed to put SE data into cache");
  ------------------
  |  |  174|     28|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     28|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     28|	int _ret = (r); \
  |  |  |  |  168|     28|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|     28|	}
 1654|       |
 1655|     32|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|     32|}
sc_get_iasecc_driver:
 3638|  15.2k|{
 3639|  15.2k|	return sc_get_driver();
 3640|  15.2k|}
card-iasecc.c:iasecc_is_cpx:
  586|  15.4k|{
  587|  15.4k|	switch(card->type) {
  588|  1.42k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (588:3): [True: 1.42k, False: 14.0k]
  ------------------
  589|  1.43k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (589:3): [True: 4, False: 15.4k]
  ------------------
  590|  1.43k|			return 1;
  591|  14.0k|		default:
  ------------------
  |  Branch (591:3): [True: 14.0k, False: 1.43k]
  ------------------
  592|  14.0k|			return 0;
  593|  15.4k|	}
  594|       |
  595|      0|	return 0;
  596|  15.4k|}
card-iasecc.c:iasecc_select_mf:
  283|  3.30k|{
  284|  3.30k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|  3.30k|	struct sc_context *ctx = card->ctx;
  286|  3.30k|	struct sc_file *mf_file = NULL;
  287|  3.30k|	struct sc_path path;
  288|  3.30k|	int rv;
  289|       |
  290|  3.30k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.30k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.30k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.30k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.30k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  3.30k|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 2.02k, False: 1.27k]
  ------------------
  293|  2.02k|		*file_out = NULL;
  294|       |
  295|  3.30k|	memset(&path, 0, sizeof(struct sc_path));
  296|  3.30k|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 198, False: 3.10k]
  |  Branch (296:23): [True: 137, False: 2.97k]
  ------------------
  297|    335|		struct sc_apdu apdu;
  298|    335|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|    335|		sc_format_path("3F00", &path);
  302|    335|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    335|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|    335|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    335|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|    335|		apdu.lc = path.len;
  306|    335|		apdu.data = path.value;
  307|    335|		apdu.datalen = path.len;
  308|    335|		apdu.resplen = sizeof(apdu_resp);
  309|    335|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|    335|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 94, False: 241]
  ------------------
  313|     94|			apdu.p2 = 0x04;
  314|       |
  315|    335|		rv = sc_transmit_apdu(card, &apdu);
  316|    335|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    335|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    335|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    335|	int _ret = (r); \
  |  |  |  |  168|    335|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 325]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    335|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 325]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|    325|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|    325|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|    325|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    325|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    325|	int _ret = (r); \
  |  |  |  |  168|    325|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 134, False: 191]
  |  |  |  |  ------------------
  |  |  |  |  169|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    134|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    134|		return _ret; \
  |  |  |  |  172|    134|	} \
  |  |  |  |  173|    325|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 191]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|    325|	}
  320|  2.97k|	else   {
  321|  2.97k|		memset(&path, 0, sizeof(path));
  322|  2.97k|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.97k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  323|  2.97k|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  324|  2.97k|		path.len = card->ef_atr->aid.len;
  325|  2.97k|		rv = iasecc_select_file(card, &path, file_out);
  326|  2.97k|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|  2.97k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.97k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.97k|	int _ret = (r); \
  |  |  |  |  168|  2.97k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.41k, False: 557]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.41k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.41k|		return _ret; \
  |  |  |  |  172|  2.41k|	} \
  |  |  |  |  173|  2.97k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 557]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|  2.97k|	}
  328|       |
  329|       |	/* Ignore the FCP of the MF, because:
  330|       |	 * - some cards do not return it;
  331|       |	 * - there is not need of it -- create/delete of the files in MF is not envisaged.
  332|       |	 */
  333|    748|	mf_file = sc_file_new();
  334|    748|	if (mf_file == NULL)
  ------------------
  |  Branch (334:6): [True: 0, False: 748]
  ------------------
  335|    748|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate MF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|    748|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    748|#define SC_FILE_TYPE_DF			0x04
  ------------------
  337|    748|	mf_file->path = path;
  338|       |
  339|    748|	sc_invalidate_cache(card);
  340|    748|	sc_file_dup(&prv->cache.current_df, mf_file);
  341|    748|	prv->cache.valid = 1;
  342|       |
  343|    748|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (343:6): [True: 625, False: 123]
  |  Branch (343:18): [True: 528, False: 97]
  ------------------
  344|    528|		*file_out = mf_file;
  345|    220|	else
  346|    220|		sc_file_free(mf_file);
  347|       |
  348|    748|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    748|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    748|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    748|	int _ret = r; \
  |  |  |  |  155|    748|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 748, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    748|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 748]
  |  |  |  |  ------------------
  |  |  |  |  157|    748|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    748|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    748|	return _ret; \
  |  |  |  |  163|    748|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|    748|}
card-iasecc.c:iasecc_select_file:
  863|  8.85k|{
  864|  8.85k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  865|  8.85k|	struct sc_context *ctx = card->ctx;
  866|  8.85k|	struct sc_path lpath;
  867|  8.85k|	int rv, ii;
  868|       |
  869|  8.85k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  8.85k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.85k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.85k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.85k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.85k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  870|  8.85k|	memcpy(&lpath, path, sizeof(struct sc_path));
  871|  8.85k|	if (file_out)
  ------------------
  |  Branch (871:6): [True: 4.19k, False: 4.65k]
  ------------------
  872|  4.19k|		*file_out = NULL;
  873|       |
  874|  8.85k|	sc_log(ctx, "iasecc_select_file(card:%p) path.len %zu; path.type %i; aid_len %zu",
  ------------------
  |  |   71|  8.85k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  875|  8.85k|			card, path->len, path->type, path->aid.len);
  876|  8.85k|	sc_log(ctx, "iasecc_select_file() path:%s", sc_print_path(path));
  ------------------
  |  |   71|  8.85k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  877|       |
  878|  8.85k|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (878:6): [True: 8.44k, False: 405]
  ------------------
  879|  8.44k|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (879:6): [True: 8.39k, False: 56]
  ------------------
  880|  8.39k|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  16.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (880:7): [True: 3.29k, False: 5.09k]
  ------------------
  881|  3.29k|			&& lpath.len >= 2
  ------------------
  |  Branch (881:7): [True: 3.29k, False: 0]
  ------------------
  882|  3.29k|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (882:7): [True: 3.22k, False: 69]
  |  Branch (882:33): [True: 3.21k, False: 11]
  ------------------
  883|  3.21k|		sc_log(ctx, "EF.ATR(aid:'%s')", card->ef_atr ? sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len) : "");
  ------------------
  |  |   71|  6.42k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.02k, False: 185]
  |  |  ------------------
  ------------------
  884|       |
  885|  3.21k|		rv = iasecc_select_mf(card, file_out);
  886|  3.21k|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|  3.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.21k|	int _ret = (r); \
  |  |  |  |  168|  3.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.48k, False: 728]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.48k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.48k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.48k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.48k|		return _ret; \
  |  |  |  |  172|  2.48k|	} \
  |  |  |  |  173|  3.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 728]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  887|       |
  888|    728|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  889|    728|		lpath.len -=  2;
  890|    728|	}
  891|       |
  892|  6.36k|	if (lpath.aid.len)	{
  ------------------
  |  Branch (892:6): [True: 28, False: 6.33k]
  ------------------
  893|     28|		struct sc_file *file = NULL;
  894|     28|		struct sc_path ppath;
  895|       |
  896|     28|		sc_log(ctx, "iasecc_select_file() select parent AID:%p/%zu", lpath.aid.value, lpath.aid.len);
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  897|     28|		sc_log(ctx, "iasecc_select_file() select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.aid.len));
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  898|     28|		memset(&ppath, 0, sizeof(ppath));
  899|     28|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  900|     28|		ppath.len = lpath.aid.len;
  901|     28|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|     28|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  902|       |
  903|     28|		rv = iasecc_select_file(card, &ppath, &file);
  904|     28|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path failed");
  ------------------
  |  |  184|     28|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     28|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     28|	int _ret = (r); \
  |  |  |  |  178|     28|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 12, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  179|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     12|		goto err; \
  |  |  |  |  182|     12|	} \
  |  |  |  |  183|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  905|       |
  906|     16|		if (file_out) {
  ------------------
  |  Branch (906:7): [True: 16, False: 0]
  ------------------
  907|     16|			sc_file_free(*file_out);
  908|     16|			*file_out = file;
  909|     16|		} else {
  910|      0|			sc_file_free(file);
  911|      0|		}
  912|       |
  913|     16|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|     16|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (913:7): [True: 0, False: 16]
  ------------------
  914|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  915|     16|	}
  916|       |
  917|  6.35k|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  6.35k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (917:6): [True: 1.18k, False: 5.17k]
  ------------------
  918|  1.18k|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|  1.18k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  919|       |
  920|  6.35k|	if (!lpath.len) {
  ------------------
  |  Branch (920:6): [True: 5, False: 6.35k]
  ------------------
  921|      5|		if (file_out) {
  ------------------
  |  Branch (921:7): [True: 0, False: 5]
  ------------------
  922|      0|			sc_file_free(*file_out);
  923|      0|			*file_out = NULL;
  924|      0|		}
  925|      5|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|      5|	}
  927|       |
  928|  6.35k|	do   {
  929|  6.35k|		struct sc_apdu apdu;
  930|  6.35k|		struct sc_file *file = NULL;
  931|  6.35k|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  932|  6.35k|		size_t pathlen = lpath.len;
  933|       |
  934|  6.35k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  6.35k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  935|       |
  936|  6.35k|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (936:7): [True: 6.29k, False: 56]
  ------------------
  937|  6.29k|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (937:8): [True: 6.16k, False: 130]
  ------------------
  938|  6.16k|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (938:8): [True: 6.04k, False: 119]
  ------------------
  939|  6.04k|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (939:8): [True: 6.04k, False: 0]
  ------------------
  940|  6.04k|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (940:8): [True: 462, False: 5.58k]
  ------------------
  941|    462|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (941:8): [True: 405, False: 57]
  ------------------
  942|    405|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (942:8): [True: 0, False: 405]
  ------------------
  943|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  944|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Unsupported card");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  945|      0|		}
  946|       |
  947|  6.35k|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  6.35k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (947:7): [True: 1, False: 6.34k]
  ------------------
  948|      1|			apdu.p1 = 0x02;
  949|      1|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (949:8): [True: 0, False: 1]
  ------------------
  950|      0|				apdu.p1 = 0x01;
  951|      1|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (951:8): [True: 0, False: 1]
  ------------------
  952|      1|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (952:8): [True: 0, False: 1]
  ------------------
  953|      1|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (953:8): [True: 0, False: 1]
  ------------------
  954|      1|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (954:8): [True: 0, False: 1]
  ------------------
  955|      1|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (955:8): [True: 0, False: 1]
  ------------------
  956|      1|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (956:8): [True: 1, False: 0]
  ------------------
  957|      1|			    )   {
  958|      1|				apdu.p2 = 0x04;
  959|      1|			}
  960|      1|		}
  961|  6.34k|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|  6.34k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (961:12): [True: 1.18k, False: 5.16k]
  ------------------
  962|  1.18k|			apdu.p1 = 0x09;
  963|  1.18k|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (963:8): [True: 54, False: 1.12k]
  ------------------
  964|  1.12k|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (964:8): [True: 0, False: 1.12k]
  ------------------
  965|  1.12k|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (965:8): [True: 607, False: 521]
  ------------------
  966|    521|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (966:8): [True: 39, False: 482]
  ------------------
  967|    482|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (967:8): [True: 49, False: 433]
  ------------------
  968|  1.09k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (968:8): [True: 342, False: 91]
  ------------------
  969|  1.09k|				apdu.p2 = 0x04;
  970|  1.09k|			}
  971|  1.18k|		}
  972|  5.16k|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|  5.16k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (972:12): [True: 0, False: 5.16k]
  ------------------
  973|      0|			apdu.p1 = 0x03;
  974|      0|			pathlen = 0;
  975|      0|			apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  976|      0|		}
  977|  5.16k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  5.16k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (977:12): [True: 5.16k, False: 0]
  ------------------
  978|  5.16k|			apdu.p1 = 0x04;
  979|  5.16k|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (979:8): [True: 0, False: 5.16k]
  ------------------
  980|  5.16k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (980:8): [True: 18, False: 5.14k]
  ------------------
  981|  5.14k|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (981:8): [True: 76, False: 5.07k]
  ------------------
  982|  5.07k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (982:8): [True: 7, False: 5.06k]
  ------------------
  983|  5.06k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (983:8): [True: 62, False: 5.00k]
  ------------------
  984|    163|				apdu.p2 = 0x04;
  985|    163|			}
  986|  5.16k|		}
  987|      0|		else   {
  988|      0|			sc_log(ctx, "Invalid PATH type: 0x%X", lpath.type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  989|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  990|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() invalid PATH type");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|      0|		}
  992|       |
  993|  6.44k|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (993:14): [True: 6.44k, False: 0]
  ------------------
  994|  6.44k|			apdu.lc = pathlen;
  995|  6.44k|			apdu.data = lpath.value;
  996|  6.44k|			apdu.datalen = pathlen;
  997|       |
  998|  6.44k|			apdu.resp = rbuf;
  999|  6.44k|			apdu.resplen = sizeof(rbuf);
 1000|  6.44k|			apdu.le = 256;
 1001|       |
 1002|  6.44k|			rv = sc_transmit_apdu(card, &apdu);
 1003|  6.44k|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|  6.44k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.44k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.44k|	int _ret = (r); \
  |  |  |  |  178|  6.44k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 27, False: 6.41k]
  |  |  |  |  ------------------
  |  |  |  |  179|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     27|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     27|		goto err; \
  |  |  |  |  182|     27|	} \
  |  |  |  |  183|  6.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 6.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1004|  6.41k|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  6.41k|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|  12.8k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1005:8): [True: 130, False: 6.28k]
  ------------------
 1006|    130|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|  6.54k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1006:6): [True: 111, False: 19]
  |  Branch (1006:44): [True: 96, False: 15]
  ------------------
 1007|     96|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   71|     96|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1008|     96|				apdu.p2 = 0x0C;
 1009|     96|				continue;
 1010|     96|			}
 1011|       |
 1012|  6.32k|			if (ii)   {
  ------------------
  |  Branch (1012:8): [True: 95, False: 6.22k]
  ------------------
 1013|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1014|     95|				apdu.resplen = sizeof(rbuf);
 1015|     95|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1016|     95|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  184|     95|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     95|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     95|	int _ret = (r); \
  |  |  |  |  178|     95|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 95]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 95]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1017|     95|			}
 1018|       |
 1019|  6.32k|			break;
 1020|  6.32k|		}
 1021|       |
 1022|  6.32k|		LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() check SW failed");
  ------------------
  |  |  184|  6.32k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.32k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.32k|	int _ret = (r); \
  |  |  |  |  178|  6.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.66k, False: 2.65k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.66k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.66k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.66k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.66k|		goto err; \
  |  |  |  |  182|  3.66k|	} \
  |  |  |  |  183|  6.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1023|       |
 1024|  2.65k|		sc_log(ctx, "iasecc_select_file() apdu.resp %zu", apdu.resplen);
  ------------------
  |  |   71|  2.65k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1025|  2.65k|		if (apdu.resplen)   {
  ------------------
  |  Branch (1025:7): [True: 965, False: 1.69k]
  ------------------
 1026|    965|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   71|    965|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1027|       |
 1028|    965|			switch (apdu.resp[0]) {
 1029|    127|			case 0x62:
  ------------------
  |  Branch (1029:4): [True: 127, False: 838]
  ------------------
 1030|    909|			case 0x6F:
  ------------------
  |  Branch (1030:4): [True: 782, False: 183]
  ------------------
 1031|    909|				file = sc_file_new();
 1032|    909|				if (file == NULL) {
  ------------------
  |  Branch (1032:9): [True: 0, False: 909]
  ------------------
 1033|      0|					if (file_out) {
  ------------------
  |  Branch (1033:10): [True: 0, False: 0]
  ------------------
 1034|      0|						sc_file_free(*file_out);
 1035|      0|						*file_out = NULL;
 1036|      0|					}
 1037|      0|					LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1038|      0|				}
 1039|    909|				file->path = lpath;
 1040|       |
 1041|    909|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1042|    909|				if (rv) {
  ------------------
  |  Branch (1042:9): [True: 69, False: 840]
  ------------------
 1043|     69|					sc_file_free(file);
 1044|     69|					if (file_out) {
  ------------------
  |  Branch (1044:10): [True: 39, False: 30]
  ------------------
 1045|     39|						sc_file_free(*file_out);
 1046|     39|						*file_out = NULL;
 1047|     39|					}
 1048|     69|					LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|     69|				}
 1050|    840|				break;
 1051|    840|			default:
  ------------------
  |  Branch (1051:4): [True: 56, False: 909]
  ------------------
 1052|     56|				if (file_out) {
  ------------------
  |  Branch (1052:9): [True: 31, False: 25]
  ------------------
 1053|     31|					sc_file_free(*file_out);
 1054|     31|					*file_out = NULL;
 1055|     31|				}
 1056|     56|				LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     56|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     56|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     56|	int _ret = r; \
  |  |  |  |  155|     56|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 56, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     56|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     56|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 56, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     56|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     56|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     56|	return _ret; \
  |  |  |  |  163|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|    965|			}
 1058|       |
 1059|    840|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   71|    840|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1060|    840|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    840|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1060:8): [True: 108, False: 732]
  ------------------
 1061|    108|				sc_invalidate_cache(card);
 1062|    108|				sc_file_dup(&prv->cache.current_df, file);
 1063|    108|				prv->cache.valid = 1;
 1064|    108|			}
 1065|    732|			else   {
 1066|    732|				sc_file_free(prv->cache.current_ef);
 1067|    732|				sc_file_dup(&prv->cache.current_ef, file);
 1068|    732|				prv->cache.valid = 1;
 1069|    732|			}
 1070|       |
 1071|    840|			if (file_out)   {
  ------------------
  |  Branch (1071:8): [True: 685, False: 155]
  ------------------
 1072|    685|				sc_file_free(*file_out);
 1073|    685|				*file_out = file;
 1074|    685|			}
 1075|    155|			else   {
 1076|    155|				sc_file_free(file);
 1077|    155|			}
 1078|    840|		}
 1079|  1.69k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.69k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1079:12): [True: 1.51k, False: 176]
  ------------------
 1080|  1.51k|			sc_invalidate_cache(card);
 1081|  1.51k|			prv->cache.valid = 1;
 1082|  1.51k|		}
 1083|  2.65k|	} while(0);
  ------------------
  |  Branch (1083:10): [Folded, False: 2.53k]
  ------------------
 1084|       |
 1085|  2.53k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.53k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.53k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.53k|	int _ret = r; \
  |  |  |  |  155|  2.53k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.53k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.53k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.53k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.53k|	return _ret; \
  |  |  |  |  163|  2.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1086|  3.70k|err:
 1087|  3.70k|	if (file_out) {
  ------------------
  |  Branch (1087:6): [True: 1.52k, False: 2.17k]
  ------------------
 1088|  1.52k|		sc_file_free(*file_out);
 1089|       |		*file_out = NULL;
 1090|  1.52k|	}
 1091|  3.70k|	return rv;
 1092|  2.53k|}
card-iasecc.c:iasecc_emulate_fcp:
  828|     95|{
  829|     95|	unsigned char dummy_df_fcp[] = {
  830|     95|		0x62,0xFF,
  831|     95|			0x82,0x01,0x38,
  832|     95|			0x8A,0x01,0x05,
  833|     95|			0xA1,0x04,0x8C,0x02,0x02,0x00,
  834|     95|			0x84,0xFF,
  835|     95|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  836|     95|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  837|     95|	};
  838|       |
  839|     95|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     95|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     95|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     95|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     95|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 95]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|       |
  841|     95|	if (apdu->p1 != 0x04)
  ------------------
  |  Branch (841:6): [True: 0, False: 95]
  ------------------
  842|     95|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "FCP emulation supported only for the DF-NAME selection type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     95|	if (apdu->datalen > 16)
  ------------------
  |  Branch (843:6): [True: 0, False: 95]
  ------------------
  844|     95|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid DF-NAME length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|     95|	if (apdu->resplen < apdu->datalen + 16)
  ------------------
  |  Branch (845:6): [True: 0, False: 95]
  ------------------
  846|     95|		LOG_TEST_RET(ctx, SC_ERROR_BUFFER_TOO_SMALL, "not enough space for FCP data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  847|       |
  848|     95|	memcpy(dummy_df_fcp + 16, apdu->data, apdu->datalen);
  849|     95|	dummy_df_fcp[15] = apdu->datalen;
  850|     95|	dummy_df_fcp[1] = apdu->datalen + 14;
  851|     95|	apdu->resplen = apdu->datalen + 16;
  852|     95|	memcpy(apdu->resp, dummy_df_fcp, apdu->resplen);
  853|       |
  854|     95|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     95|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     95|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     95|	int _ret = r; \
  |  |  |  |  155|     95|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 95, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     95|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 95]
  |  |  |  |  ------------------
  |  |  |  |  157|     95|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     95|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     95|	return _ret; \
  |  |  |  |  163|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  855|     95|}
card-iasecc.c:iasecc_process_fci:
 1098|    909|{
 1099|    909|	struct sc_context *ctx = card->ctx;
 1100|    909|	size_t taglen, offs, ii;
 1101|    909|	int rv;
 1102|    909|	const unsigned char *acls = NULL, *tag = NULL;
 1103|    909|	unsigned char mask;
 1104|    909|	unsigned char ops_DF[7] = {
 1105|    909|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|    909|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  186|    909|#define SC_AC_OP_ACTIVATE		20
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  187|    909|#define SC_AC_OP_DEACTIVATE		21
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  169|    909|#define SC_AC_OP_CREATE			3
  ------------------
 1106|    909|	};
 1107|    909|	unsigned char ops_EF[7] = {
 1108|    909|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|    909|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  186|    909|#define SC_AC_OP_ACTIVATE		20
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  187|    909|#define SC_AC_OP_DEACTIVATE		21
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  189|    909|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  188|    909|#define SC_AC_OP_READ			22
  ------------------
 1109|    909|	};
 1110|       |
 1111|    909|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    909|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    909|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    909|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    909|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 909]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|       |
 1113|    909|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1114|    909|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   71|    909|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1115|    909|	if (tag != NULL) {
  ------------------
  |  Branch (1115:6): [True: 759, False: 150]
  ------------------
 1116|    759|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    759|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1117|    759|		buf = tag;
 1118|    759|		buflen = taglen;
 1119|    759|	}
 1120|       |
 1121|    909|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1122|    909|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   71|    909|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1123|    909|	if (tag != NULL) {
  ------------------
  |  Branch (1123:6): [True: 102, False: 807]
  ------------------
 1124|    102|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1125|    102|		buf = tag;
 1126|    102|		buflen = taglen;
 1127|    102|	}
 1128|       |
 1129|    909|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1130|    909|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    909|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    909|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    909|	int _ret = (r); \
  |  |  |  |  168|    909|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 909]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    909|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 909]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|       |/*
 1132|       |	Gemalto:  6F 19 80 02 02 ED 82 01 01 83 02 B0 01 88 00	8C 07 7B 17 17 17 17 17 00 8A 01 05 90 00
 1133|       |	Sagem:    6F 17 62 15 80 02 00 7D 82 01 01                   8C 02 01 00 83 02 2F 00 88 01 F0 8A 01 05 90 00
 1134|       |	Oberthur: 62 1B 80 02 05 DC 82 01 01 83 02 B0 01 88 00 A1 09 8C 07 7B 17 FF 17 17 17 00 8A 01 05 90 00
 1135|       |*/
 1136|       |
 1137|    909|	sc_log(ctx, "iasecc_process_fci() type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   71|    909|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1138|    909|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|    909|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1139|    909|	if (tag)
  ------------------
  |  Branch (1139:6): [True: 95, False: 814]
  ------------------
 1140|     95|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|     95|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1141|    814|	else
 1142|    814|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    814|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1143|       |
 1144|    909|	if (!acls)   {
  ------------------
  |  Branch (1144:6): [True: 69, False: 840]
  ------------------
 1145|     69|		sc_log(ctx, "ACLs not found in data(%zu) %s", buflen, sc_dump_hex(buf, buflen));
  ------------------
  |  |   71|     69|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1146|     69|		LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     69|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     69|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     69|	int _ret = (r); \
  |  |  |  |  168|     69|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     69|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     69|		return _ret; \
  |  |  |  |  172|     69|	} \
  |  |  |  |  173|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|     69|	}
 1148|       |
 1149|    840|	sc_log(ctx, "ACLs(%zu) '%s'", taglen, sc_dump_hex(acls, taglen));
  ------------------
  |  |   71|    840|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1150|    840|	mask = 0x40, offs = 1;
 1151|  5.50k|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1151:15): [True: 4.96k, False: 545]
  ------------------
 1152|  4.96k|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|  4.96k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1152:22): [True: 724, False: 4.23k]
  ------------------
 1153|       |
 1154|       |		/* avoid any access to acls[offs] beyond the taglen */
 1155|  4.96k|		if (offs >= taglen) {
  ------------------
  |  Branch (1155:7): [True: 295, False: 4.66k]
  ------------------
 1156|    295|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   71|    295|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1157|    295|			break;
 1158|    295|		}
 1159|  4.66k|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1159:7): [True: 2.43k, False: 2.23k]
  ------------------
 1160|  2.43k|			continue;
 1161|       |
 1162|  2.23k|		sc_log(ctx, "ACLs mask 0x%X, offs %zu, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|  2.23k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1163|  2.23k|		if (op == 0xFF)   {
  ------------------
  |  Branch (1163:7): [True: 459, False: 1.77k]
  ------------------
 1164|    459|			;
 1165|    459|		}
 1166|  1.77k|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1166:12): [True: 500, False: 1.27k]
  ------------------
 1167|    500|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    500|#define SC_AC_NONE			0x00000000
  ------------------
 1168|    500|		}
 1169|  1.27k|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1169:12): [True: 211, False: 1.06k]
  ------------------
 1170|    211|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    211|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1171|    211|		}
 1172|  1.06k|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|  1.06k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|  1.06k|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1172:12): [True: 265, False: 796]
  ------------------
 1173|    265|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|    265|#define SC_AC_SEN                       0x00000020 /* Security Environment. */
  ------------------
              			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |   90|    265|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1174|    265|		}
 1175|    796|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|    796|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1175:12): [True: 628, False: 168]
  ------------------
 1176|    628|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|    628|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1177|    628|		}
 1178|    168|		else   {
 1179|    168|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   71|    168|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1180|    168|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    168|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1181|    168|		}
 1182|       |
 1183|  2.23k|		offs++;
 1184|  2.23k|	}
 1185|       |
 1186|    840|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    840|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    840|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    840|	int _ret = r; \
  |  |  |  |  155|    840|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 840, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    840|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 840]
  |  |  |  |  ------------------
  |  |  |  |  157|    840|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    840|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    840|	return _ret; \
  |  |  |  |  163|    840|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1187|    840|}
card-iasecc.c:iasecc_se_get_info_from_cache:
 1568|    248|{
 1569|    248|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1570|    248|	struct sc_context *ctx = card->ctx;
 1571|    248|	struct iasecc_se_info *si = NULL;
 1572|    248|	int rv;
 1573|       |
 1574|    248|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    248|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    248|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    248|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    248|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 248]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1575|       |
 1576|    265|	for(si = prv->se_info; si; si = si->next)   {
  ------------------
  |  Branch (1576:25): [True: 21, False: 244]
  ------------------
 1577|     21|		if (si->reference != se->reference)
  ------------------
  |  Branch (1577:7): [True: 14, False: 7]
  ------------------
 1578|     14|			continue;
 1579|      7|		if (!(prv->cache.valid && prv->cache.current_df) && si->df)
  ------------------
  |  Branch (1579:9): [True: 7, False: 0]
  |  Branch (1579:29): [True: 5, False: 2]
  |  Branch (1579:55): [True: 2, False: 0]
  ------------------
 1580|      2|			continue;
 1581|      5|		if (prv->cache.valid && prv->cache.current_df && !si->df)
  ------------------
  |  Branch (1581:7): [True: 5, False: 0]
  |  Branch (1581:27): [True: 5, False: 0]
  |  Branch (1581:52): [True: 0, False: 5]
  ------------------
 1582|      0|			continue;
 1583|      5|		if (prv->cache.valid && prv->cache.current_df && si->df)
  ------------------
  |  Branch (1583:7): [True: 5, False: 0]
  |  Branch (1583:27): [True: 5, False: 0]
  |  Branch (1583:52): [True: 5, False: 0]
  ------------------
 1584|      5|			if (memcmp(&prv->cache.current_df->path, &si->df->path, sizeof(struct sc_path)))
  ------------------
  |  Branch (1584:8): [True: 1, False: 4]
  ------------------
 1585|      1|				continue;
 1586|      4|		break;
 1587|      5|	}
 1588|       |
 1589|    248|	if (!si)
  ------------------
  |  Branch (1589:6): [True: 244, False: 4]
  ------------------
 1590|    244|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    244|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1591|       |
 1592|      4|	memcpy(se, si, sizeof(struct iasecc_se_info));
 1593|       |
 1594|      4|	if (si->df)   {
  ------------------
  |  Branch (1594:6): [True: 4, False: 0]
  ------------------
 1595|      4|		sc_file_dup(&se->df, si->df);
 1596|      4|		if (se->df == NULL)
  ------------------
  |  Branch (1596:7): [True: 0, False: 4]
  ------------------
 1597|      4|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot duplicate current DF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1598|      4|	}
 1599|       |
 1600|      4|	rv = iasecc_docp_copy(ctx, &si->docp, &se->docp);
 1601|      4|	LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1602|       |
 1603|      4|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1604|      4|}
card-iasecc.c:iasecc_se_cache_info:
 1525|     28|{
 1526|     28|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1527|     28|	struct sc_context *ctx = card->ctx;
 1528|     28|	struct iasecc_se_info *se_info = NULL, *si = NULL;
 1529|     28|	int rv;
 1530|       |
 1531|     28|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     28|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     28|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     28|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     28|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|       |
 1533|     28|	se_info = calloc(1, sizeof(struct iasecc_se_info));
 1534|     28|	if (!se_info)
  ------------------
  |  Branch (1534:6): [True: 0, False: 28]
  ------------------
 1535|     28|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "SE info allocation error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1536|     28|	memcpy(se_info, se, sizeof(struct iasecc_se_info));
 1537|       |
 1538|     28|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (1538:6): [True: 28, False: 0]
  |  Branch (1538:26): [True: 27, False: 1]
  ------------------
 1539|     27|		sc_file_dup(&se_info->df, prv->cache.current_df);
 1540|     27|		if (se_info->df == NULL)   {
  ------------------
  |  Branch (1540:7): [True: 0, False: 27]
  ------------------
 1541|      0|			free(se_info);
 1542|      0|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot duplicate current DF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1543|      0|		}
 1544|     27|	}
 1545|       |
 1546|     28|	rv = iasecc_docp_copy(ctx, &se->docp, &se_info->docp);
 1547|     28|	if (rv < 0)   {
  ------------------
  |  Branch (1547:6): [True: 0, False: 28]
  ------------------
 1548|      0|		free(se_info->df);
 1549|      0|		free(se_info);
 1550|      0|		LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1551|      0|	}
 1552|       |
 1553|     28|	if (!prv->se_info)   {
  ------------------
  |  Branch (1553:6): [True: 23, False: 5]
  ------------------
 1554|     23|		prv->se_info = se_info;
 1555|     23|	}
 1556|      5|	else    {
 1557|      6|		for (si = prv->se_info; si->next; si = si->next)
  ------------------
  |  Branch (1557:27): [True: 1, False: 5]
  ------------------
 1558|      1|			;
 1559|      5|		si->next = se_info;
 1560|      5|	}
 1561|       |
 1562|     28|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1563|     28|}
card-iasecc.c:sc_get_driver:
 3591|  15.2k|{
 3592|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3593|       |
 3594|  15.2k|	if (!iso_ops)
  ------------------
  |  Branch (3594:6): [True: 1, False: 15.2k]
  ------------------
 3595|      1|		iso_ops = iso_drv->ops;
 3596|       |
 3597|  15.2k|	iasecc_ops = *iso_ops;
 3598|       |
 3599|  15.2k|	iasecc_ops.match_card = iasecc_match_card;
 3600|  15.2k|	iasecc_ops.init = iasecc_init;
 3601|  15.2k|	iasecc_ops.finish = iasecc_finish;
 3602|  15.2k|	iasecc_ops.read_binary = iasecc_read_binary;
 3603|       |	/*	write_binary: ISO7816 implementation works	*/
 3604|       |	/*	update_binary: ISO7816 implementation works	*/
 3605|  15.2k|	iasecc_ops.erase_binary = iasecc_erase_binary;
 3606|       |	/*	resize_binary	*/
 3607|       |	/* 	read_record: Untested	*/
 3608|       |	/*	write_record: Untested	*/
 3609|       |	/*	append_record: Untested	*/
 3610|       |	/*	update_record: Untested	*/
 3611|  15.2k|	iasecc_ops.select_file = iasecc_select_file;
 3612|       |	/*	get_response: Untested	*/
 3613|  15.2k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3614|  15.2k|	iasecc_ops.logout = iasecc_logout;
 3615|       |	/*	restore_security_env	*/
 3616|  15.2k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3617|  15.2k|	iasecc_ops.decipher = iasecc_decipher;
 3618|  15.2k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3619|  15.2k|	iasecc_ops.create_file = iasecc_create_file;
 3620|  15.2k|	iasecc_ops.delete_file = iasecc_delete_file;
 3621|       |	/*	list_files	*/
 3622|  15.2k|	iasecc_ops.check_sw = iasecc_check_sw;
 3623|  15.2k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3624|  15.2k|	iasecc_ops.process_fci = iasecc_process_fci;
 3625|       |	/*	construct_fci: Not needed	*/
 3626|  15.2k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3627|       |	/*	get_data: Not implemented	*/
 3628|       |	/*	put_data: Not implemented	*/
 3629|       |	/*	delete_record: Not implemented	*/
 3630|       |
 3631|  15.2k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3632|       |
 3633|  15.2k|	return &iasecc_drv;
 3634|  15.2k|}
card-iasecc.c:iasecc_match_card:
  353|  11.0k|{
  354|  11.0k|	struct sc_context *ctx = card->ctx;
  355|  11.0k|	int i;
  356|       |
  357|  11.0k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  358|  11.0k|	if (i < 0)   {
  ------------------
  |  Branch (358:6): [True: 10.0k, False: 1.00k]
  ------------------
  359|  10.0k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  10.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  360|  10.0k|		return 0;
  361|  10.0k|	}
  362|       |
  363|  1.00k|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|  1.00k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  364|  1.00k|	return 1;
  365|  11.0k|}
card-iasecc.c:iasecc_init:
  624|  1.00k|{
  625|  1.00k|	struct sc_context *ctx = card->ctx;
  626|  1.00k|	struct iasecc_private_data *private_data = NULL;
  627|  1.00k|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  1.00k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  628|  1.00k|	void *old_drv_data = card->drv_data;
  629|       |
  630|  1.00k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.00k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.00k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  1.00k|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  632|  1.00k|	if (private_data == NULL)
  ------------------
  |  Branch (632:6): [True: 0, False: 1.00k]
  ------------------
  633|  1.00k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  634|       |
  635|  1.00k|	card->cla  = 0x00;
  636|  1.00k|	card->drv_data = private_data;
  637|       |
  638|  1.00k|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (638:6): [True: 16, False: 985]
  ------------------
  639|     16|		rv = iasecc_init_gemalto(card);
  640|    985|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (640:11): [True: 69, False: 916]
  ------------------
  641|     69|		rv = iasecc_init_oberthur(card);
  642|    916|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (642:11): [True: 74, False: 842]
  ------------------
  643|     74|		rv = iasecc_init_amos_or_sagem(card);
  644|    842|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (644:11): [True: 0, False: 842]
  ------------------
  645|      0|		rv = iasecc_init_amos_or_sagem(card);
  646|    842|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (646:11): [True: 644, False: 198]
  ------------------
  647|    644|		rv = iasecc_init_amos_or_sagem(card);
  648|    198|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (648:11): [True: 198, False: 0]
  ------------------
  649|    198|		rv = iasecc_init_cpx(card);
  650|      0|	else {
  651|      0|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_CARD, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|      0|	}
  653|       |
  654|       |
  655|  1.00k|	if (!rv)   {
  ------------------
  |  Branch (655:6): [True: 670, False: 331]
  ------------------
  656|    670|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (656:7): [True: 670, False: 0]
  |  Branch (656:23): [True: 613, False: 57]
  ------------------
  657|    613|			struct sc_path path;
  658|       |
  659|    613|			memset(&path, 0, sizeof(struct sc_path));
  660|    613|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    613|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  661|    613|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  662|    613|			path.len = card->ef_atr->aid.len;
  663|       |
  664|    613|			rv = iasecc_select_file(card, &path, NULL);
  665|    613|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", rv);
  ------------------
  |  |   71|    613|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  666|    613|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID failed");
  ------------------
  |  |  184|    613|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    613|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    613|	int _ret = (r); \
  |  |  |  |  178|    613|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 12, False: 601]
  |  |  |  |  ------------------
  |  |  |  |  179|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     12|		goto err; \
  |  |  |  |  182|     12|	} \
  |  |  |  |  183|    613|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 601]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|    613|		}
  668|       |
  669|    658|		iasecc_get_serialnr(card, NULL);
  670|    658|	}
  671|       |
  672|    989|#ifdef ENABLE_SM
  673|    989|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  674|    989|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  675|    989|#endif
  676|       |
  677|    989|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (677:6): [True: 658, False: 331]
  |  Branch (677:13): [True: 658, False: 0]
  |  Branch (677:29): [True: 601, False: 57]
  ------------------
  678|    601|		sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|    601|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  679|    601|	}
  680|       |
  681|  1.00k|err:
  682|  1.00k|	if (rv < 0) {
  ------------------
  |  Branch (682:6): [True: 343, False: 658]
  ------------------
  683|    343|		sc_invalidate_cache(card);
  684|    343|		free(private_data);
  685|    343|		card->drv_data = old_drv_data;
  686|    658|	} else {
  687|    658|		free(old_drv_data);
  688|    658|	}
  689|       |
  690|  1.00k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.00k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.00k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.00k|	int _ret = r; \
  |  |  |  |  155|  1.00k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.00k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.00k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    343|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 343, False: 658]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.00k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.00k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.00k|	return _ret; \
  |  |  |  |  163|  1.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|  1.00k|}
card-iasecc.c:iasecc_init_gemalto:
  419|     16|{
  420|     16|	struct sc_context *ctx = card->ctx;
  421|     16|	struct sc_path path;
  422|     16|	unsigned int flags;
  423|     16|	int rv = 0;
  424|       |
  425|     16|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     16|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     16|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     16|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     16|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|       |
  427|     16|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     16|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     16|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     16|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     16|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     16|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     16|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     16|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|     16|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|     16|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     16|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     16|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     16|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     16|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     16|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     16|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  428|       |
  429|     16|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     16|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     16|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     16|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     16|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     16|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     16|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     16|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     16|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     16|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  430|       |
  431|     16|	sc_format_path("3F00", &path);
  432|     16|	if (SC_SUCCESS != sc_select_file(card, &path, NULL)) {
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  |  Branch (432:6): [True: 12, False: 4]
  ------------------
  433|       |		/* Result ignored*/
  434|     12|		sc_log(card->ctx, "Warning, MF select failed");
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  435|     12|	}
  436|       |
  437|     16|	rv = iasecc_parse_ef_atr(card);
  438|     16|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  439|     16|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     16|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (439:6): [True: 2, False: 14]
  ------------------
  440|      2|		sc_log(ctx, "Select MF");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  441|      2|		rv = iasecc_select_mf(card, NULL);
  442|      2|		sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  443|      2|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  444|       |
  445|      1|		rv = iasecc_parse_ef_atr(card);
  446|      1|		sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  447|      1|	}
  448|     15|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   71|     15|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  449|     15|	LOG_TEST_RET(ctx, rv, "Cannot read/parse EF.ATR");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|       |
  451|      4|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  452|      4|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  453|       |
  454|      4|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|      4|}
card-iasecc.c:iasecc_parse_ef_atr:
  369|    407|{
  370|    407|	struct sc_context *ctx = card->ctx;
  371|    407|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  372|    407|	struct iasecc_version *version = &pdata->version;
  373|    407|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  374|    407|	int rv;
  375|       |
  376|    407|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    407|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    407|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    407|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    407|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 407]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    407|	rv = sc_parse_ef_atr(card);
  378|    407|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    407|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    407|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    407|	int _ret = (r); \
  |  |  |  |  168|    407|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 203, False: 204]
  |  |  |  |  ------------------
  |  |  |  |  169|    203|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    203|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    203|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    203|		return _ret; \
  |  |  |  |  172|    203|	} \
  |  |  |  |  173|    407|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 204]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|    204|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (380:6): [True: 140, False: 64]
  ------------------
  381|    204|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  174|    140|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    140|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    140|	int _ret = (r); \
  |  |  |  |  168|    140|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 140, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    140|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    140|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    140|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    140|		return _ret; \
  |  |  |  |  172|    140|	} \
  |  |  |  |  173|    140|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|     64|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  384|     64|	version->ic_type =		card->ef_atr->pre_issuing[1];
  385|     64|	version->os_version =		card->ef_atr->pre_issuing[2];
  386|     64|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  387|     64|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   71|     64|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  388|     64|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  389|       |
  390|     64|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (390:6): [True: 2, False: 62]
  ------------------
  391|     64|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |
  393|     62|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  394|     62|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  395|     62|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  396|     62|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  397|       |
  398|     62|	sc_log(ctx, "EF.ATR: IO Buffer Size send/sc %zd/%zd recv/sc %zd/%zd",
  ------------------
  |  |   71|     62|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  399|     62|			sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  400|       |
  401|     62|	card->max_send_size = sizes->send;
  402|     62|	card->max_recv_size = sizes->recv;
  403|       |
  404|       |	/* Most of the card producers interpret 'send' values as "maximum APDU data size".
  405|       |	 * Oberthur strictly follows specification and interpret these values as "maximum APDU command size".
  406|       |	 * Here we need 'data size'.
  407|       |	 */
  408|     62|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (408:6): [True: 51, False: 11]
  ------------------
  409|     51|		card->max_send_size -= 5;
  410|       |
  411|     62|	sc_log(ctx, "EF.ATR: max send/recv sizes %zX/%zX", card->max_send_size, card->max_recv_size);
  ------------------
  |  |   71|     62|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  412|       |
  413|     62|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|     62|}
card-iasecc.c:iasecc_init_oberthur:
  488|     69|{
  489|     69|	struct sc_context *ctx = card->ctx;
  490|     69|	unsigned int flags;
  491|     69|	int rv = 0;
  492|       |
  493|     69|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     69|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     69|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     69|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     69|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|       |
  495|     69|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     69|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     69|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     69|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     69|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     69|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     69|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     69|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|     69|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|     69|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     69|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     69|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     69|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     69|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     69|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     69|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  496|       |
  497|     69|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  498|     69|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  499|       |
  500|     69|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     69|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     69|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     69|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     69|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     69|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     69|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     69|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     69|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     69|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  501|       |
  502|     69|	iasecc_parse_ef_atr(card);
  503|       |
  504|       |	/* if we fail to select CM, */
  505|     69|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (505:6): [True: 62, False: 7]
  ------------------
  506|     62|		gp_select_isd_rid(card);
  507|     62|	}
  508|       |
  509|     69|	rv = iasecc_oberthur_match(card);
  510|     69|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|     69|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     69|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     69|	int _ret = (r); \
  |  |  |  |  168|     69|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|       |
  512|     69|	rv = iasecc_select_mf(card, NULL);
  513|     69|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|     69|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     69|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     69|	int _ret = (r); \
  |  |  |  |  168|     69|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 62, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     62|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     62|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     62|		return _ret; \
  |  |  |  |  172|     62|	} \
  |  |  |  |  173|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|      7|	rv = iasecc_parse_ef_atr(card);
  516|      7|	LOG_TEST_RET(ctx, rv, "EF.ATR read or parse error");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|       |
  518|      0|	sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  519|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      0|}
card-iasecc.c:iasecc_oberthur_match:
  460|     69|{
  461|     69|	struct sc_context *ctx = card->ctx;
  462|     69|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  463|       |
  464|     69|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     69|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     69|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     69|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     69|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|       |
  466|     69|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (466:6): [True: 0, False: 69]
  |  Branch (466:23): [True: 0, False: 69]
  ------------------
  467|     69|		LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|       |
  469|     69|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|     69|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     69|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|       |
  471|     69|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (471:6): [True: 0, False: 69]
  ------------------
  472|     69|		LOG_FUNC_RETURN(ctx, SC_ERROR_RECORD_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|       |
  474|     69|	if (!card->ef_atr)
  ------------------
  |  Branch (474:6): [True: 44, False: 25]
  ------------------
  475|     44|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  476|     69|	if (!card->ef_atr)
  ------------------
  |  Branch (476:6): [True: 0, False: 69]
  ------------------
  477|     69|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|       |
  479|     69|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  480|     69|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  481|       |
  482|     69|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  483|     69|}
card-iasecc.c:iasecc_init_amos_or_sagem:
  550|    718|{
  551|    718|	struct sc_context *ctx = card->ctx;
  552|    718|	unsigned int flags;
  553|    718|	int rv = 0;
  554|       |
  555|    718|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    718|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    718|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    718|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    718|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 718]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|       |
  557|    718|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    718|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    718|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    718|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    718|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    718|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    718|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    718|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|    718|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    718|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    718|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    718|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    718|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    718|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    718|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    718|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  558|       |
  559|    718|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  560|    718|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  561|       |
  562|    718|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    718|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    718|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    718|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    718|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    718|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    718|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    718|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    718|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    718|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  563|       |
  564|    718|	if (card->type == SC_CARD_TYPE_IASECC_MI)   {
  ------------------
  |  Branch (564:6): [True: 644, False: 74]
  ------------------
  565|    644|		rv = iasecc_mi_match(card);
  566|    644|		if (rv)
  ------------------
  |  Branch (566:7): [True: 36, False: 608]
  ------------------
  567|     36|			card->type = SC_CARD_TYPE_IASECC_MI2;
  568|    608|		else
  569|    644|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    608|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    608|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    608|	int _ret = r; \
  |  |  |  |  155|    608|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 608, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    608|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 608]
  |  |  |  |  ------------------
  |  |  |  |  157|    608|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    608|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    608|	return _ret; \
  |  |  |  |  163|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|    644|	}
  571|       |
  572|    110|	rv = iasecc_parse_ef_atr(card);
  573|    110|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|    110|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (573:6): [True: 11, False: 99]
  ------------------
  574|     11|		rv = iasecc_select_mf(card, NULL);
  575|     11|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  576|       |
  577|      6|		rv = iasecc_parse_ef_atr(card);
  578|      6|	}
  579|    105|	LOG_TEST_RET(ctx, rv, "IASECC: ATR parse failed");
  ------------------
  |  |  174|    105|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    105|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    105|	int _ret = (r); \
  |  |  |  |  168|    105|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|    105|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|     24|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|     24|}
card-iasecc.c:iasecc_mi_match:
  525|    644|{
  526|    644|	struct sc_context *ctx = card->ctx;
  527|    644|	unsigned char resp[0x100];
  528|    644|	size_t resp_len = sizeof(resp);
  529|    644|	int rv = 0;
  530|       |
  531|    644|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    644|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    644|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    644|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    644|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 644]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  532|       |
  533|    644|	rv = iso7816_select_aid(card, MIIASECC_AID.value, MIIASECC_AID.len, resp, &resp_len);
  534|    644|	LOG_TEST_RET(ctx, rv, "IASECC: failed to select MI IAS/ECC applet");
  ------------------
  |  |  174|    644|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    644|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    644|	int _ret = (r); \
  |  |  |  |  168|    644|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36, False: 608]
  |  |  |  |  ------------------
  |  |  |  |  169|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     36|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     36|		return _ret; \
  |  |  |  |  172|     36|	} \
  |  |  |  |  173|    644|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 608]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|       |
  536|    608|	if (!card->ef_atr)
  ------------------
  |  Branch (536:6): [True: 608, False: 0]
  ------------------
  537|    608|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  538|    608|	if (!card->ef_atr)
  ------------------
  |  Branch (538:6): [True: 0, False: 608]
  ------------------
  539|    608|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|       |
  541|    608|	memcpy(card->ef_atr->aid.value, MIIASECC_AID.value, MIIASECC_AID.len);
  542|    608|	card->ef_atr->aid.len = MIIASECC_AID.len;
  543|       |
  544|    608|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    608|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    608|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    608|	int _ret = r; \
  |  |  |  |  155|    608|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 608, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    608|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 608]
  |  |  |  |  ------------------
  |  |  |  |  157|    608|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    608|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    608|	return _ret; \
  |  |  |  |  163|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  545|    608|}
card-iasecc.c:iasecc_init_cpx:
  600|    198|{
  601|    198|	struct sc_context *ctx = card->ctx;
  602|    198|	unsigned int flags;
  603|    198|	int rv = 0;
  604|       |
  605|    198|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    198|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    198|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    198|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    198|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 198]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  606|       |
  607|    198|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    198|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    198|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    198|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    198|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    198|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    198|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    198|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    198|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    198|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  608|       |
  609|    198|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    198|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    198|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    198|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    198|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    198|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    198|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    198|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|    198|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    198|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    198|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    198|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    198|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    198|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    198|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    198|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  610|       |
  611|    198|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  612|    198|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  613|    198|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  614|       |
  615|    198|	rv = iasecc_parse_ef_atr(card);
  616|    198|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  174|    198|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    198|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    198|	int _ret = (r); \
  |  |  |  |  168|    198|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 164, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  169|    164|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    164|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    164|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    164|		return _ret; \
  |  |  |  |  172|    164|	} \
  |  |  |  |  173|    198|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|       |
  618|     34|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|     34|}
card-iasecc.c:iasecc_get_serialnr:
 2464|    922|{
 2465|    922|	struct sc_context *ctx = card->ctx;
 2466|    922|	struct sc_iin *iin = &card->serialnr.iin;
 2467|    922|	struct sc_apdu apdu;
 2468|    922|	unsigned char rbuf[0xC0];
 2469|    922|	size_t ii, offs, len;
 2470|    922|	int rv;
 2471|       |
 2472|    922|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    922|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    922|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    922|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    922|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 922]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2473|    922|	if (card->serialnr.len)
  ------------------
  |  Branch (2473:6): [True: 1, False: 921]
  ------------------
 2474|      1|		goto end;
 2475|       |
 2476|    921|	memset(&card->serialnr, 0, sizeof(card->serialnr));
 2477|       |
 2478|    921|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |  292|    921|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
              	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |   73|    921|#define IASECC_SFI_EF_SN	0x1C
  ------------------
 2479|    921|	apdu.le = sizeof(rbuf);
 2480|    921|	apdu.resp = rbuf;
 2481|    921|	apdu.resplen = sizeof(rbuf);
 2482|       |
 2483|    921|	rv = sc_transmit_apdu(card, &apdu);
 2484|    921|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    921|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    921|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    921|	int _ret = (r); \
  |  |  |  |  168|    921|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 917]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|    921|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 917]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|    917|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2486|    917|	LOG_TEST_RET(ctx, rv, "Get 'serial number' data failed");
  ------------------
  |  |  174|    917|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    917|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    917|	int _ret = (r); \
  |  |  |  |  168|    917|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 857, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  169|    857|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    857|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    857|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    857|		return _ret; \
  |  |  |  |  172|    857|	} \
  |  |  |  |  173|    917|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 60]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2487|       |
 2488|     60|	if (apdu.resplen < 2 || rbuf[0] != ISO7812_PAN_SN_TAG || rbuf[1] > (apdu.resplen-2))
  ------------------
  |  |   29|     95|#define ISO7812_PAN_SN_TAG	0x5A
  ------------------
  |  Branch (2488:6): [True: 25, False: 35]
  |  Branch (2488:26): [True: 16, False: 19]
  |  Branch (2488:59): [True: 4, False: 15]
  ------------------
 2489|     60|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "serial number parse error");
  ------------------
  |  |  174|     45|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     45|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     45|	int _ret = (r); \
  |  |  |  |  168|     45|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     45|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     45|		return _ret; \
  |  |  |  |  172|     45|	} \
  |  |  |  |  173|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2490|     15|	len = rbuf[1];
 2491|       |
 2492|     15|	iin->mii = (rbuf[2] >> 4) & 0x0F;
 2493|       |
 2494|     15|	iin->country = 0;
 2495|     60|	for (ii=5; ii<8; ii++)   {
  ------------------
  |  Branch (2495:13): [True: 45, False: 15]
  ------------------
 2496|     45|		iin->country *= 10;
 2497|     45|		iin->country += (rbuf[ii/2] >> ((ii & 0x01) ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2497:35): [True: 30, False: 15]
  ------------------
 2498|     45|	}
 2499|       |
 2500|     15|	iin->issuer_id = 0;
 2501|     45|	for (ii=8; ii<10; ii++)   {
  ------------------
  |  Branch (2501:13): [True: 30, False: 15]
  ------------------
 2502|     30|		iin->issuer_id *= 10;
 2503|     30|		iin->issuer_id += (rbuf[ii/2] >> (ii & 0x01 ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2503:37): [True: 15, False: 15]
  ------------------
 2504|     30|	}
 2505|       |
 2506|       |	/* Copy the serial number from the last 8 bytes (at most) */
 2507|     15|	offs = len > 8 ? len - 8 : 0;
  ------------------
  |  Branch (2507:9): [True: 2, False: 13]
  ------------------
 2508|     15|	if (card->type == SC_CARD_TYPE_IASECC_SAGEM)   {
  ------------------
  |  Branch (2508:6): [True: 5, False: 10]
  ------------------
 2509|       |		/* 5A 0A 92 50 00 20 10 10 25 00 01 3F */
 2510|       |		/*            00 02 01 01 02 50 00 13  */
 2511|     25|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2511:14): [True: 20, False: 5]
  ------------------
 2512|     20|			*(card->serialnr.value + ii) = ((rbuf[ii + offs + 1] & 0x0F) << 4)
 2513|     20|				+ ((rbuf[ii + offs + 2] & 0xF0) >> 4) ;
 2514|      5|		card->serialnr.len = ii;
 2515|      5|	}
 2516|     10|	else   {
 2517|     38|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2517:14): [True: 28, False: 10]
  ------------------
 2518|     28|			*(card->serialnr.value + ii) = rbuf[ii + offs + 2];
 2519|     10|		card->serialnr.len = ii;
 2520|     10|	}
 2521|       |
 2522|     15|	do  {
 2523|     15|		char txt[0x200];
 2524|       |
 2525|     63|		for (ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (2525:13): [True: 48, False: 15]
  ------------------
 2526|     48|			sprintf(txt + ii*2, "%02X", *(card->serialnr.value + ii));
 2527|       |
 2528|     15|		sc_log(ctx, "serial number '%s'; mii %i; country %i; issuer_id %li", txt, iin->mii, iin->country, iin->issuer_id);
  ------------------
  |  |   71|     15|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2529|     15|	} while(0);
  ------------------
  |  Branch (2529:10): [Folded, False: 15]
  ------------------
 2530|       |
 2531|     16|end:
 2532|     16|	if (serial)
  ------------------
  |  Branch (2532:6): [True: 2, False: 14]
  ------------------
 2533|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 2534|       |
 2535|     16|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2536|     16|}
card-iasecc.c:_iasecc_sm_read_binary:
  760|    322|{
  761|    322|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  762|    322|	struct sc_context *ctx = card->ctx;
  763|    322|	const struct sc_acl_entry *entry = NULL;
  764|    322|	int rv;
  765|       |
  766|    322|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    322|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    322|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    322|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    322|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 322]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|    322|	sc_log(ctx, "iasecc_sm_read_binary() card:%p offs:%i count:%zu ", card, offs, count);
  ------------------
  |  |   71|    322|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  768|    322|	if (offs > 0x7fff)
  ------------------
  |  Branch (768:6): [True: 0, False: 322]
  ------------------
  769|    322|		LOG_TEST_RET(ctx, SC_ERROR_OFFSET_TOO_LARGE, "Invalid arguments");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  770|       |
  771|    322|	if (count == 0)
  ------------------
  |  Branch (771:6): [True: 0, False: 322]
  ------------------
  772|      0|		return 0;
  773|       |
  774|    322|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (774:6): [True: 322, False: 0]
  |  Branch (774:26): [True: 310, False: 12]
  ------------------
  775|    310|		entry = sc_file_get_acl_entry(prv->cache.current_ef, SC_AC_OP_READ);
  ------------------
  |  |  188|    310|#define SC_AC_OP_READ			22
  ------------------
  776|    310|		if (!entry)
  ------------------
  |  Branch (776:7): [True: 7, False: 303]
  ------------------
  777|    310|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "iasecc_sm_read() 'READ' ACL not present");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|       |
  779|    303|		sc_log(ctx, "READ method/reference %X/%X", entry->method, entry->key_ref);
  ------------------
  |  |   71|    303|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  780|    303|		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |  157|    303|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
              		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |   91|    272|#define IASECC_SCB_METHOD_SM		0x40
  ------------------
  |  Branch (780:7): [True: 272, False: 31]
  |  Branch (780:39): [True: 255, False: 17]
  ------------------
  781|    255|			unsigned char se_num = entry->key_ref & IASECC_SCB_METHOD_MASK_REF;
  ------------------
  |  |   90|    255|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
  782|       |
  783|    255|			rv = iasecc_sm_read_binary(card, se_num, offs, buff, count);
  784|    255|			LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    255|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    255|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    255|	int _ret = r; \
  |  |  |  |  155|    255|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 255, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    255|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    255|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 255, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    255|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    255|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    255|	return _ret; \
  |  |  |  |  163|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    255|		}
  786|    303|	}
  787|       |
  788|     60|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     60|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     60|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     60|	int _ret = r; \
  |  |  |  |  155|     60|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 60, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  157|     60|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     60|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     60|	return _ret; \
  |  |  |  |  163|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|     60|}
card-iasecc.c:iasecc_finish:
 1414|    658|{
 1415|    658|	struct sc_context *ctx = card->ctx;
 1416|    658|	struct iasecc_private_data *private_data = (struct iasecc_private_data *)card->drv_data;
 1417|    658|	struct iasecc_se_info *se_info = private_data->se_info, *next;
 1418|       |
 1419|    658|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    658|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    658|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    658|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    658|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 658]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1420|       |
 1421|    658|	sc_invalidate_cache(card);
 1422|       |
 1423|    686|	while (se_info)   {
  ------------------
  |  Branch (1423:9): [True: 28, False: 658]
  ------------------
 1424|     28|		sc_file_free(se_info->df);
 1425|     28|		next = se_info->next;
 1426|     28|		free(se_info);
 1427|     28|		se_info = next;
 1428|     28|	}
 1429|       |
 1430|    658|	free(card->drv_data);
 1431|    658|	card->drv_data = NULL;
 1432|       |
 1433|    658|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    658|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    658|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    658|	int _ret = r; \
  |  |  |  |  155|    658|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 658, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    658|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 658]
  |  |  |  |  ------------------
  |  |  |  |  157|    658|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    658|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    658|	return _ret; \
  |  |  |  |  163|    658|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1434|    658|}
card-iasecc.c:iasecc_read_binary:
  697|  2.72k|{
  698|  2.72k|	struct sc_context *ctx = card->ctx;
  699|  2.72k|	struct sc_apdu apdu;
  700|  2.72k|	int rv;
  701|       |
  702|  2.72k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.72k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.72k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.72k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  703|  2.72k|	sc_log(ctx, "iasecc_read_binary(card:%p) offs %i; count %zu", card, offs, count);
  ------------------
  |  |   71|  2.72k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  704|  2.72k|	if (offs > 0x7fff) {
  ------------------
  |  Branch (704:6): [True: 7, False: 2.71k]
  ------------------
  705|      7|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", offs);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  706|      7|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      7|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  707|      7|	}
  708|       |
  709|  2.71k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|  2.71k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  710|  2.71k|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (710:12): [True: 227, False: 2.48k]
  ------------------
  711|  2.71k|	apdu.resplen = count;
  712|  2.71k|	apdu.resp = buf;
  713|       |
  714|  2.71k|	rv = sc_transmit_apdu(card, &apdu);
  715|  2.71k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  2.71k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.71k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.71k|	int _ret = (r); \
  |  |  |  |  168|  2.71k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 175, False: 2.53k]
  |  |  |  |  ------------------
  |  |  |  |  169|    175|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    175|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    175|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    175|		return _ret; \
  |  |  |  |  172|    175|	} \
  |  |  |  |  173|  2.71k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  2.53k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  717|  2.53k|	LOG_TEST_RET(ctx, rv, "iasecc_read_binary() failed");
  ------------------
  |  |  174|  2.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.53k|	int _ret = (r); \
  |  |  |  |  168|  2.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 268, False: 2.27k]
  |  |  |  |  ------------------
  |  |  |  |  169|    268|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    268|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    268|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    268|		return _ret; \
  |  |  |  |  172|    268|	} \
  |  |  |  |  173|  2.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  718|  2.27k|	sc_log(ctx, "iasecc_read_binary() apdu.resplen %zu", apdu.resplen);
  ------------------
  |  |   71|  2.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  719|       |
  720|  2.27k|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  4.54k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (720:6): [True: 307, False: 1.96k]
  |  Branch (720:55): [True: 306, False: 1]
  ------------------
  721|    306|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  722|    306|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|    306|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (722:7): [True: 155, False: 151]
  ------------------
  723|    155|			LOG_TEST_RET(ctx, rv, "iasecc_read_binary() read tail failed");
  ------------------
  |  |  174|    155|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    155|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    155|	int _ret = (r); \
  |  |  |  |  168|    155|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  169|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     26|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     26|		return _ret; \
  |  |  |  |  172|     26|	} \
  |  |  |  |  173|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|    129|			apdu.resplen += rv;
  725|    129|		}
  726|    306|	}
  727|       |
  728|  2.24k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.24k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.24k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.24k|	int _ret = r; \
  |  |  |  |  155|  2.24k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 2.22k]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.22k|	} else { \
  |  |  |  |  159|  2.22k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.22k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.22k|	} \
  |  |  |  |  162|  2.24k|	return _ret; \
  |  |  |  |  163|  2.24k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|  2.24k|}
card-iasecc.c:iasecc_sdo_get_data:
 2848|    243|{
 2849|    243|	struct sc_context *ctx = card->ctx;
 2850|    243|	int rv, sdo_tag;
 2851|       |
 2852|    243|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    243|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    243|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    243|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    243|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 243]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2853|       |
 2854|    243|	sdo_tag = iasecc_sdo_tag_from_class(sdo->sdo_class);
 2855|       |
 2856|    243|	rv = iasecc_sdo_get_tagged_data(card, sdo_tag, sdo);
 2857|       |	/* When there is no public data 'GET DATA' returns error */
 2858|    243|	if (rv != SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    243|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (2858:6): [True: 235, False: 8]
  ------------------
 2859|    243|		LOG_TEST_RET(ctx, rv, "cannot parse ECC SDO data");
  ------------------
  |  |  174|    235|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    235|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    235|	int _ret = (r); \
  |  |  |  |  168|    235|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    232|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    232|		return _ret; \
  |  |  |  |  172|    232|	} \
  |  |  |  |  173|    235|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2860|       |
 2861|     11|	rv = iasecc_sdo_get_tagged_data(card, IASECC_DOCP_TAG, sdo);
  ------------------
  |  |   31|     11|#define IASECC_DOCP_TAG				0xA0
  ------------------
 2862|     11|	LOG_TEST_RET(ctx, rv, "cannot parse ECC DOCP data");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2863|       |
 2864|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2865|      0|}
card-iasecc.c:iasecc_sdo_tag_from_class:
 2749|    243|{
 2750|    243|	switch (sdo_class & ~IASECC_OBJECT_REF_LOCAL)   {
  ------------------
  |  |   59|    243|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2750:10): [True: 243, False: 0]
  ------------------
 2751|    243|	case IASECC_SDO_CLASS_CHV:
  ------------------
  |  |   98|    243|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (2751:2): [True: 243, False: 0]
  ------------------
 2752|    243|		return IASECC_SDO_CHV_TAG;
  ------------------
  |  |   63|    243|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
 2753|      0|	case IASECC_SDO_CLASS_RSA_PRIVATE:
  ------------------
  |  |  100|      0|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (2753:2): [True: 0, False: 243]
  ------------------
 2754|      0|		return IASECC_SDO_PRVKEY_TAG;
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
 2755|      0|	case IASECC_SDO_CLASS_RSA_PUBLIC:
  ------------------
  |  |  101|      0|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (2755:2): [True: 0, False: 243]
  ------------------
 2756|      0|		return IASECC_SDO_PUBKEY_TAG;
  ------------------
  |  |   76|      0|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
 2757|      0|	case IASECC_SDO_CLASS_SE:
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (2757:2): [True: 0, False: 243]
  ------------------
 2758|      0|		return IASECC_SDO_CLASS_SE;
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 2759|      0|	case IASECC_SDO_CLASS_KEYSET:
  ------------------
  |  |   99|      0|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (2759:2): [True: 0, False: 243]
  ------------------
 2760|      0|		return IASECC_SDO_KEYSET_TAG;
  ------------------
  |  |   83|      0|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
 2761|    243|	}
 2762|       |
 2763|      0|	return -1;
 2764|    243|}
card-iasecc.c:iasecc_sdo_get_tagged_data:
 2769|    254|{
 2770|    254|	struct sc_context *ctx = card->ctx;
 2771|    254|	struct sc_apdu apdu;
 2772|    254|	unsigned char sbuf[0x100];
 2773|    254|	size_t offs = sizeof(sbuf) - 1;
 2774|    254|	unsigned char rbuf[0x400];
 2775|    254|	int rv;
 2776|       |
 2777|    254|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    254|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    254|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    254|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    254|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 254]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2778|       |
 2779|    254|	sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag,
  ------------------
  |  |   71|    254|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2780|    254|			sdo->sdo_ref, sdo->sdo_class);
 2781|       |
 2782|       |	/* XXX: for the CPx, the SDO are available from some specific path */
 2783|    254|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (2783:6): [True: 6, False: 248]
  ------------------
 2784|      6|		struct sc_path path;
 2785|      6|		char *path_str = NULL;
 2786|      6|		switch(sdo_tag) {
 2787|      0|			case IASECC_SDO_PRVKEY_TAG:
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (2787:4): [True: 0, False: 6]
  ------------------
 2788|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 90 02 03 7F 48 80 */
 2789|      0|			path_str = "3F00:0001";
 2790|      0|			break;
 2791|      4|			case IASECC_SDO_CHV_TAG:
  ------------------
  |  |   63|      4|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (2791:4): [True: 4, False: 2]
  ------------------
 2792|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */
 2793|      4|			path_str = "3F00";
 2794|      4|			break;
 2795|      2|			default:
  ------------------
  |  Branch (2795:4): [True: 2, False: 4]
  ------------------
 2796|      2|			path_str = NULL;
 2797|      2|			break;
 2798|      6|		}
 2799|      6|		if (path_str) {
  ------------------
  |  Branch (2799:7): [True: 4, False: 2]
  ------------------
 2800|      4|			sc_log(ctx, "Warning: Enforce the path=%s", path_str);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2801|      4|			sc_format_path(path_str, &path);
 2802|      4|			rv = iasecc_select_file(card, &path, NULL);
 2803|      4|			LOG_TEST_RET(ctx, rv, "path error");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2804|      4|		}
 2805|      6|	}
 2806|       |
 2807|    251|	sbuf[offs--] = 0x80;
 2808|    251|	sbuf[offs--] = sdo_tag & 0xFF;
 2809|    251|	if ((sdo_tag >> 8) & 0xFF)
  ------------------
  |  Branch (2809:6): [True: 240, False: 11]
  ------------------
 2810|    240|		sbuf[offs--] = (sdo_tag >> 8) & 0xFF;
 2811|    251|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2812|    251|	offs--;
 2813|       |
 2814|    251|	sbuf[offs--] = sdo->sdo_ref & 0x9F;
 2815|    251|	sbuf[offs--] = sdo->sdo_class | IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    251|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2816|    251|	sbuf[offs--] = IASECC_SDO_TAG_HEADER;
  ------------------
  |  |   27|    251|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
 2817|       |
 2818|    251|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2819|    251|	offs--;
 2820|    251|	sbuf[offs--] = IASECC_SDO_TEMPLATE_TAG;
  ------------------
  |  |   29|    251|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 2821|       |
 2822|    251|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2823|    251|	offs--;
 2824|    251|	sbuf[offs] = 0x4D;
 2825|       |
 2826|    251|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    251|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 2827|    251|	apdu.data = sbuf + offs;
 2828|    251|	apdu.datalen = sizeof(sbuf) - offs;
 2829|    251|	apdu.lc = sizeof(sbuf) - offs;
 2830|    251|	apdu.resp = rbuf;
 2831|    251|	apdu.resplen = sizeof(rbuf);
 2832|    251|	apdu.le = 0x100;
 2833|       |
 2834|    251|	rv = sc_transmit_apdu(card, &apdu);
 2835|    251|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    251|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    251|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    251|	int _ret = (r); \
  |  |  |  |  168|    251|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 245]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    251|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 245]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2836|    245|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2837|    245|	LOG_TEST_RET(ctx, rv, "SDO get data error");
  ------------------
  |  |  174|    245|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    245|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    245|	int _ret = (r); \
  |  |  |  |  168|    245|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 223]
  |  |  |  |  ------------------
  |  |  |  |  169|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     22|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     22|		return _ret; \
  |  |  |  |  172|     22|	} \
  |  |  |  |  173|    245|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 223]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2838|       |
 2839|    223|	rv = iasecc_sdo_parse(card, apdu.resp, apdu.resplen, sdo);
 2840|    223|	LOG_TEST_RET(ctx, rv, "cannot parse SDO data");
  ------------------
  |  |  174|    223|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    223|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    223|	int _ret = (r); \
  |  |  |  |  168|    223|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 220, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|    220|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    220|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    220|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    220|		return _ret; \
  |  |  |  |  172|    220|	} \
  |  |  |  |  173|    223|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|       |
 2842|      3|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2843|      3|}
card-iasecc.c:iasecc_check_sw:
 1487|  13.1k|{
 1488|  13.1k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1488:6): [True: 268, False: 12.9k]
  |  Branch (1488:21): [True: 225, False: 43]
  ------------------
 1489|    225|		return SC_SUCCESS;
  ------------------
  |  |   28|    225|#define SC_SUCCESS				0
  ------------------
 1490|       |
 1491|  12.9k|	return iso_ops->check_sw(card, sw1, sw2);
 1492|  13.1k|}
card-iasecc.c:iasecc_card_ctl:
 2973|    264|{
 2974|    264|	struct sc_context *ctx = card->ctx;
 2975|    264|	struct iasecc_sdo *sdo = (struct iasecc_sdo *) ptr;
 2976|       |
 2977|    264|	switch (cmd) {
  ------------------
  |  Branch (2977:10): [True: 264, False: 0]
  ------------------
 2978|    264|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2978:2): [True: 264, False: 0]
  ------------------
 2979|    264|		return iasecc_get_serialnr(card, (struct sc_serial_number *)ptr);
 2980|      0|	case SC_CARDCTL_IASECC_SDO_CREATE:
  ------------------
  |  Branch (2980:2): [True: 0, False: 264]
  ------------------
 2981|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_CREATE: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2982|      0|		return iasecc_sdo_create(card, (struct iasecc_sdo *) ptr);
 2983|      0|	case SC_CARDCTL_IASECC_SDO_DELETE:
  ------------------
  |  Branch (2983:2): [True: 0, False: 264]
  ------------------
 2984|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_DELETE: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2985|      0|		return iasecc_sdo_delete(card, (struct iasecc_sdo *) ptr);
 2986|      0|	case SC_CARDCTL_IASECC_SDO_PUT_DATA:
  ------------------
  |  Branch (2986:2): [True: 0, False: 264]
  ------------------
 2987|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_PUT_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2988|      0|		return iasecc_sdo_put_data(card, (struct iasecc_sdo_update *) ptr);
 2989|      0|	case SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA:
  ------------------
  |  Branch (2989:2): [True: 0, False: 264]
  ------------------
 2990|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2991|      0|		return iasecc_sdo_key_rsa_put_data(card, (struct iasecc_sdo_rsa_update *) ptr);
 2992|      0|	case SC_CARDCTL_IASECC_SDO_GET_DATA:
  ------------------
  |  Branch (2992:2): [True: 0, False: 264]
  ------------------
 2993|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_GET_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2994|      0|		return iasecc_sdo_get_data(card, (struct iasecc_sdo *) ptr);
 2995|      0|	case SC_CARDCTL_IASECC_SDO_GENERATE:
  ------------------
  |  Branch (2995:2): [True: 0, False: 264]
  ------------------
 2996|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_GET_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2997|      0|		return iasecc_sdo_generate(card, (struct iasecc_sdo *) ptr);
 2998|      0|	case SC_CARDCTL_GET_SE_INFO:
  ------------------
  |  Branch (2998:2): [True: 0, False: 264]
  ------------------
 2999|      0|		sc_log(ctx, "CMD SC_CARDCTL_GET_SE_INFO: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3000|      0|		return iasecc_se_get_info(card, (struct iasecc_se_info *) ptr);
 3001|      0|	case SC_CARDCTL_GET_CHV_REFERENCE_IN_SE:
  ------------------
  |  Branch (3001:2): [True: 0, False: 264]
  ------------------
 3002|      0|		sc_log(ctx, "CMD SC_CARDCTL_GET_CHV_REFERENCE_IN_SE");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3003|      0|		return iasecc_get_chv_reference_from_se(card, (int *)ptr);
 3004|      0|	case SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE:
  ------------------
  |  Branch (3004:2): [True: 0, False: 264]
  ------------------
 3005|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3006|      0|		return iasecc_get_free_reference(card, (struct iasecc_ctl_get_free_reference *)ptr);
 3007|    264|	}
 3008|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3009|    264|}
card-iasecc.c:iasecc_pin_cmd:
 2428|    264|{
 2429|    264|	struct sc_context *ctx = card->ctx;
 2430|    264|	int rv;
 2431|       |
 2432|    264|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    264|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    264|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    264|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    264|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 264]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2433|    264|	sc_log(ctx, "iasecc_pin_cmd() cmd 0x%X, PIN type 0x%X, PIN reference %i, PIN-1 %p:%zu, PIN-2 %p:%zu",
  ------------------
  |  |   71|    264|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2434|    264|			data->cmd, data->pin_type, data->pin_reference,
 2435|    264|			data->pin1.data, data->pin1.len, data->pin2.data, data->pin2.len);
 2436|       |
 2437|    264|	switch (data->cmd)   {
 2438|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2438:2): [True: 0, False: 264]
  ------------------
 2439|      0|		rv = iasecc_pin_verify(card, data);
 2440|      0|		break;
 2441|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2441:2): [True: 0, False: 264]
  ------------------
 2442|      0|		if (data->pin_type == SC_AC_AUT)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2442:7): [True: 0, False: 0]
  ------------------
 2443|      0|			rv = iasecc_keyset_change(card, data);
 2444|      0|		else
 2445|      0|			rv = iasecc_pin_change(card, data);
 2446|      0|		break;
 2447|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2447:2): [True: 0, False: 264]
  ------------------
 2448|      0|		rv = iasecc_pin_reset(card, data);
 2449|      0|		break;
 2450|    264|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    264|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2450:2): [True: 264, False: 0]
  ------------------
 2451|    264|		rv = iasecc_pin_get_info(card, data);
 2452|    264|		break;
 2453|      0|	default:
  ------------------
  |  Branch (2453:2): [True: 0, False: 264]
  ------------------
 2454|      0|		sc_log(ctx, "Other pin commands not supported yet: 0x%X", data->cmd);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2455|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2456|    264|	}
 2457|       |
 2458|    264|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    264|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    264|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    264|	int _ret = r; \
  |  |  |  |  155|    264|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 264, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    264|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    264|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 264, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    264|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    264|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    264|	return _ret; \
  |  |  |  |  163|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|    264|}
card-iasecc.c:iasecc_pin_get_status:
 1895|    264|{
 1896|    264|	struct sc_context *ctx = card->ctx;
 1897|    264|	struct sc_pin_cmd_data info;
 1898|    264|	int rv;
 1899|       |
 1900|    264|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    264|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    264|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    264|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    264|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 264]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1901|       |
 1902|    264|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    264|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1902:6): [True: 0, False: 264]
  ------------------
 1903|    264|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "PIN type is not supported for status");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1904|       |
 1905|    264|	memset(&info, 0, sizeof(info));
 1906|    264|	info.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    264|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1907|    264|	info.pin_type = data->pin_type;
 1908|    264|	info.pin_reference = data->pin_reference;
 1909|       |
 1910|    264|	rv = iso_ops->pin_cmd(card, &info);
 1911|    264|	LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
  ------------------
  |  |  174|    264|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    264|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    264|	int _ret = (r); \
  |  |  |  |  168|    264|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 247]
  |  |  |  |  ------------------
  |  |  |  |  169|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     17|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     17|		return _ret; \
  |  |  |  |  172|     17|	} \
  |  |  |  |  173|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 247]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1912|       |
 1913|    247|	data->pin1.max_tries = info.pin1.max_tries;
 1914|    247|	data->pin1.tries_left = info.pin1.tries_left;
 1915|    247|	data->pin1.logged_in = info.pin1.logged_in;
 1916|       |
 1917|    247|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    247|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    247|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    247|	int _ret = r; \
  |  |  |  |  155|    247|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 247, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    247|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 247]
  |  |  |  |  ------------------
  |  |  |  |  157|    247|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    247|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    247|	return _ret; \
  |  |  |  |  163|    247|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1918|    247|}
card-iasecc.c:iasecc_pin_get_policy:
 2014|    247|{
 2015|    247|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 2016|    247|	struct sc_context *ctx = card->ctx;
 2017|    247|	struct sc_file *save_current_df = NULL, *save_current_ef = NULL;
 2018|    247|	struct iasecc_sdo sdo;
 2019|    247|	struct sc_path path;
 2020|    247|	int rv;
 2021|       |
 2022|    247|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    247|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    247|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    247|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    247|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 247]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|    247|	sc_log(ctx, "iasecc_pin_get_policy(card:%p)", card);
  ------------------
  |  |   71|    247|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2024|       |
 2025|    247|	if (data->pin_type != SC_AC_CHV)   {
  ------------------
  |  |  151|    247|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2025:6): [True: 0, False: 247]
  ------------------
 2026|      0|		sc_log(ctx, "PIN policy only available for CHV type");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2027|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2028|      0|	}
 2029|       |
 2030|    247|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (2030:6): [True: 247, False: 0]
  |  Branch (2030:26): [True: 7, False: 240]
  ------------------
 2031|      7|		sc_file_dup(&save_current_df, prv->cache.current_df);
 2032|      7|		if (save_current_df == NULL) {
  ------------------
  |  Branch (2032:7): [True: 0, False: 7]
  ------------------
 2033|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2034|      0|			sc_log(ctx, "Cannot duplicate current DF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2035|      0|			goto err;
 2036|      0|		}
 2037|      7|	}
 2038|       |
 2039|    247|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (2039:6): [True: 247, False: 0]
  |  Branch (2039:26): [True: 3, False: 244]
  ------------------
 2040|      3|		sc_file_dup(&save_current_ef, prv->cache.current_ef);
 2041|      3|		if (save_current_ef == NULL) {
  ------------------
  |  Branch (2041:7): [True: 0, False: 3]
  ------------------
 2042|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2043|      0|			sc_log(ctx, "Cannot duplicate current EF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2044|      0|			goto err;
 2045|      0|		}
 2046|      3|	}
 2047|       |
 2048|    247|	if (!(data->pin_reference & IASECC_OBJECT_REF_LOCAL) && prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  |   59|    247|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2048:6): [True: 247, False: 0]
  |  Branch (2048:58): [True: 247, False: 0]
  |  Branch (2048:78): [True: 7, False: 240]
  ------------------
 2049|      7|		sc_format_path("3F00", &path);
 2050|      7|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      7|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2051|      7|		rv = iasecc_select_file(card, &path, NULL);
 2052|      7|		LOG_TEST_GOTO_ERR(ctx, rv, "Unable to select MF");
  ------------------
  |  |  184|      7|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      7|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      7|	int _ret = (r); \
  |  |  |  |  178|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2053|      7|	}
 2054|       |
 2055|    243|	memset(&sdo, 0, sizeof(sdo));
 2056|    243|	sdo.sdo_class = IASECC_SDO_CLASS_CHV;
  ------------------
  |  |   98|    243|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
 2057|       |
 2058|    243|	sdo.sdo_ref = data->pin_reference & ~IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    243|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2059|       |
 2060|    243|	sc_log(ctx, "iasecc_pin_get_policy() reference %i", sdo.sdo_ref);
  ------------------
  |  |   71|    243|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2061|       |
 2062|    243|	rv = iasecc_sdo_get_data(card, &sdo);
 2063|    243|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot get SDO PIN data");
  ------------------
  |  |  184|    243|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    243|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    243|	int _ret = (r); \
  |  |  |  |  178|    243|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 243, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    243|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    243|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    243|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    243|		goto err; \
  |  |  |  |  182|    243|	} \
  |  |  |  |  183|    243|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2064|       |
 2065|      0|	if (sdo.docp.acls_contact.size == 0) {
  ------------------
  |  Branch (2065:6): [True: 0, False: 0]
  ------------------
 2066|      0|		rv = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2067|      0|		sc_log(ctx, "Extremely strange ... there is no ACLs");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2068|      0|		goto err;
 2069|      0|	}
 2070|       |
 2071|      0|	sc_log(ctx, "iasecc_pin_get_policy() sdo.docp.size.size %zu", sdo.docp.size.size);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2072|       |
 2073|      0|	memcpy(pin->scbs, sdo.docp.scbs, sizeof(pin->scbs));
 2074|       |
 2075|      0|	pin->min_length = (sdo.data.chv.size_min.value ? *sdo.data.chv.size_min.value : -1);
  ------------------
  |  Branch (2075:21): [True: 0, False: 0]
  ------------------
 2076|      0|	pin->max_length = (sdo.data.chv.size_max.value ? *sdo.data.chv.size_max.value : -1);
  ------------------
  |  Branch (2076:21): [True: 0, False: 0]
  ------------------
 2077|      0|	pin->tries_maximum = (sdo.docp.tries_maximum.value ? *sdo.docp.tries_maximum.value : -1);
  ------------------
  |  Branch (2077:24): [True: 0, False: 0]
  ------------------
 2078|      0|	pin->tries_remaining = (sdo.docp.tries_remaining.value ? *sdo.docp.tries_remaining.value : -1);
  ------------------
  |  Branch (2078:26): [True: 0, False: 0]
  ------------------
 2079|      0|	if (sdo.docp.size.value && sdo.docp.size.size <= sizeof(int)) {
  ------------------
  |  Branch (2079:6): [True: 0, False: 0]
  |  Branch (2079:29): [True: 0, False: 0]
  ------------------
 2080|      0|		unsigned int n = 0;
 2081|      0|		unsigned int i;
 2082|      0|		for (i=0; i<sdo.docp.size.size; i++)
  ------------------
  |  Branch (2082:13): [True: 0, False: 0]
  ------------------
 2083|      0|			n = (n << 8) + *(sdo.docp.size.value + i);
 2084|      0|		pin->stored_length = n;
 2085|      0|	} else {
 2086|      0|		pin->stored_length = -1;
 2087|      0|	}
 2088|       |
 2089|      0|	sc_log(ctx, "PIN policy: size max/min %i/%i, tries max/left %i/%i",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2090|      0|	       pin->max_length, pin->min_length, pin->tries_maximum, pin->tries_remaining);
 2091|      0|	iasecc_sdo_free_fields(card, &sdo);
 2092|       |
 2093|      0|	if (save_current_df)   {
  ------------------
  |  Branch (2093:6): [True: 0, False: 0]
  ------------------
 2094|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current DF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2095|      0|		rv = iasecc_select_file(card, &save_current_df->path, NULL);
 2096|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Cannot return to saved DF");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2097|      0|	}
 2098|       |
 2099|      0|	if (save_current_ef)   {
  ------------------
  |  Branch (2099:6): [True: 0, False: 0]
  ------------------
 2100|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current EF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2101|      0|		rv = iasecc_select_file(card, &save_current_ef->path, NULL);
 2102|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Cannot return to saved EF");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2103|      0|	}
 2104|       |
 2105|    247|err:
 2106|    247|	sc_file_free(save_current_df);
 2107|    247|	sc_file_free(save_current_ef);
 2108|       |
 2109|    247|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    247|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    247|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    247|	int _ret = r; \
  |  |  |  |  155|    247|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 247, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    247|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    247|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 247, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    247|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    247|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    247|	return _ret; \
  |  |  |  |  163|    247|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2110|    247|}
card-iasecc.c:iasecc_pin_get_info:
 2115|    264|{
 2116|    264|	struct sc_context *ctx = card->ctx;
 2117|    264|	struct iasecc_pin_policy policy;
 2118|    264|	int rv;
 2119|       |
 2120|    264|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    264|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    264|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    264|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    264|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 264]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|    264|	sc_log(ctx, "iasecc_pin_get_info(card:%p)", card);
  ------------------
  |  |   71|    264|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2122|       |
 2123|       |	/*
 2124|       |	 * Get PIN status first and thereafter update with info from PIN policy, when available.
 2125|       |	 * The first one is typically used for the PIN verification status and number of remaining
 2126|       |	 * tries, and the second one for the maximum tries. If a field is present in both, the
 2127|       |	 * policy takes precedence.
 2128|       |	 */
 2129|    264|	rv = iasecc_pin_get_status(card, data);
 2130|    264|	LOG_TEST_RET(ctx, rv, "Failed to get PIN status");
  ------------------
  |  |  174|    264|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    264|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    264|	int _ret = (r); \
  |  |  |  |  168|    264|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 247]
  |  |  |  |  ------------------
  |  |  |  |  169|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     17|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     17|		return _ret; \
  |  |  |  |  172|     17|	} \
  |  |  |  |  173|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 247]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2131|       |
 2132|    247|	rv = iasecc_pin_get_policy(card, data, &policy);
 2133|    247|	LOG_TEST_RET(ctx, rv, "Failed to get PIN policy");
  ------------------
  |  |  174|    247|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    247|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    247|	int _ret = (r); \
  |  |  |  |  168|    247|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 247, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    247|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    247|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    247|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    247|		return _ret; \
  |  |  |  |  172|    247|	} \
  |  |  |  |  173|    247|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|       |	/*
 2136|       |	 * We only care about the tries_xxx fields in the PIN policy, since the other ones are not
 2137|       |	 * commonly expected or used in a SC_PIN_CMD_GET_INFO response.	Note that max_tries is
 2138|       |	 * always taken from the policy, since it is never expected to be available in status (it
 2139|       |	 * is set to -1 when not available in policy).
 2140|       |	 */
 2141|      0|	data->pin1.max_tries = policy.tries_maximum;
 2142|      0|	if (policy.tries_remaining >= 0)
  ------------------
  |  Branch (2142:6): [True: 0, False: 0]
  ------------------
 2143|      0|		data->pin1.tries_left = policy.tries_remaining;
 2144|       |
 2145|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2146|      0|}

idprime_free_private_data:
  225|    535|{
  226|    535|	free(priv->cache_buf);
  227|    535|	list_destroy(&priv->pki_list);
  228|    535|	list_destroy(&priv->containers);
  229|    535|	list_destroy(&priv->keyrefmap);
  230|    535|	free(priv);
  231|    535|	return;
  232|    535|}
idprime_new_private_data:
  235|    535|{
  236|    535|	idprime_private_data_t *priv;
  237|       |
  238|    535|	priv = calloc(1, sizeof(idprime_private_data_t));
  239|    535|	if (priv == NULL)
  ------------------
  |  Branch (239:6): [True: 0, False: 535]
  ------------------
  240|      0|		return NULL;
  241|       |
  242|       |	/* Initialize PKI Applets list */
  243|    535|	if (list_init(&priv->pki_list) != 0 ||
  ------------------
  |  Branch (243:6): [True: 0, False: 535]
  ------------------
  244|    535|	    list_attributes_copy(&priv->pki_list, idprime_list_meter, 1) != 0) {
  ------------------
  |  Branch (244:6): [True: 0, False: 535]
  ------------------
  245|      0|		idprime_free_private_data(priv);
  246|      0|		return NULL;
  247|      0|	}
  248|       |
  249|       |	/* Initialize container list */
  250|    535|	if (list_init(&priv->containers) != 0 ||
  ------------------
  |  Branch (250:6): [True: 0, False: 535]
  ------------------
  251|    535|	    list_attributes_copy(&priv->containers, idprime_container_list_meter, 1) != 0 ||
  ------------------
  |  Branch (251:6): [True: 0, False: 535]
  ------------------
  252|    535|	    list_attributes_seeker(&priv->containers, idprime_container_list_seeker) != 0) {
  ------------------
  |  Branch (252:6): [True: 0, False: 535]
  ------------------
  253|      0|		idprime_free_private_data(priv);
  254|      0|		return NULL;
  255|      0|	}
  256|       |
  257|       |	/* Initialize keyref list */
  258|    535|	if (list_init(&priv->keyrefmap) != 0 ||
  ------------------
  |  Branch (258:6): [True: 0, False: 535]
  ------------------
  259|    535|	    list_attributes_copy(&priv->keyrefmap, idprime_keyref_list_meter, 1) != 0 ||
  ------------------
  |  Branch (259:6): [True: 0, False: 535]
  ------------------
  260|    535|	    list_attributes_seeker(&priv->keyrefmap, idprime_keyref_list_seeker) != 0) {
  ------------------
  |  Branch (260:6): [True: 0, False: 535]
  ------------------
  261|      0|		idprime_free_private_data(priv);
  262|      0|		return NULL;
  263|      0|	}
  264|    535|	return priv;
  265|    535|}
idprime_add_object_to_list:
  268|  2.15k|{
  269|  2.15k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (269:6): [True: 0, False: 2.15k]
  ------------------
  270|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  271|  2.15k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.15k|#define SC_SUCCESS				0
  ------------------
  272|  2.15k|}
sc_get_idprime_driver:
 1281|  15.2k|{
 1282|  15.2k|	return sc_get_driver();
 1283|  15.2k|}
card-idprime.c:idprime_list_meter:
  176|  2.15k|static size_t idprime_list_meter(const void *el) {
  177|  2.15k|	return sizeof(idprime_object_t);
  178|  2.15k|}
card-idprime.c:idprime_container_list_meter:
  180|    165|static size_t idprime_container_list_meter(const void *el) {
  181|    165|	return sizeof(idprime_container_t);
  182|    165|}
card-idprime.c:idprime_container_list_seeker:
  196|  1.27k|{
  197|  1.27k|	const idprime_container_t *container = (idprime_container_t *)el;
  198|       |
  199|  1.27k|	if ((el == NULL) || (key == NULL))
  ------------------
  |  Branch (199:6): [True: 0, False: 1.27k]
  |  Branch (199:22): [True: 0, False: 1.27k]
  ------------------
  200|      0|		return 0;
  201|  1.27k|	if (container->index == *(uint8_t *)key)
  ------------------
  |  Branch (201:6): [True: 1.11k, False: 162]
  ------------------
  202|  1.11k|		return 1;
  203|    162|	return 0;
  204|  1.27k|}
card-idprime.c:idprime_keyref_list_meter:
  184|  11.3k|static size_t idprime_keyref_list_meter(const void *el) {
  185|  11.3k|	return sizeof(idprime_keyref_t);
  186|  11.3k|}
card-idprime.c:idprime_keyref_list_seeker:
  214|  1.19k|{
  215|  1.19k|	const idprime_keyref_t *keyref = (idprime_keyref_t *)el;
  216|       |
  217|  1.19k|	if ((el == NULL) || (key == NULL))
  ------------------
  |  Branch (217:6): [True: 0, False: 1.19k]
  |  Branch (217:22): [True: 0, False: 1.19k]
  ------------------
  218|      0|		return 0;
  219|  1.19k|	if (keyref->index == *(uint8_t *)key)
  ------------------
  |  Branch (219:6): [True: 91, False: 1.10k]
  ------------------
  220|     91|		return 1;
  221|  1.10k|	return 0;
  222|  1.19k|}
card-idprime.c:sc_get_driver:
 1258|  15.2k|{
 1259|  15.2k|	if (iso_ops == NULL) {
  ------------------
  |  Branch (1259:6): [True: 1, False: 15.2k]
  ------------------
 1260|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1261|      1|	}
 1262|       |
 1263|  15.2k|	idprime_ops = *iso_ops;
 1264|  15.2k|	idprime_ops.match_card = idprime_match_card;
 1265|  15.2k|	idprime_ops.init = idprime_init;
 1266|  15.2k|	idprime_ops.finish = idprime_finish;
 1267|       |
 1268|  15.2k|	idprime_ops.read_binary = idprime_read_binary;
 1269|  15.2k|	idprime_ops.select_file = idprime_select_file;
 1270|  15.2k|	idprime_ops.card_ctl = idprime_card_ctl;
 1271|  15.2k|	idprime_ops.set_security_env = idprime_set_security_env;
 1272|  15.2k|	idprime_ops.compute_signature = idprime_compute_signature;
 1273|  15.2k|	idprime_ops.decipher = idprime_decipher;
 1274|       |
 1275|  15.2k|	idprime_ops.get_challenge = idprime_get_challenge;
 1276|       |
 1277|  15.2k|	return &idprime_drv;
 1278|  15.2k|}
card-idprime.c:idprime_match_card:
  754|  8.07k|{
  755|  8.07k|	int i, r;
  756|       |
  757|  8.07k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  8.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.07k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.07k]
  |  |  ------------------
  ------------------
  758|  8.07k|	i = _sc_match_atr(card, idprime_atrs, &card->type);
  759|  8.07k|	if (i < 0)
  ------------------
  |  Branch (759:6): [True: 7.49k, False: 578]
  ------------------
  760|  7.49k|		return 0;
  761|       |
  762|    578|	r = idprime_select_file_by_path(card, "0101");
  763|    578|	LOG_FUNC_RETURN(card->ctx, r > 0);
  ------------------
  |  |  164|    578|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    578|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    578|	int _ret = r; \
  |  |  |  |  155|    578|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 43, False: 535]
  |  |  |  |  ------------------
  |  |  |  |  156|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    535|	} else { \
  |  |  |  |  159|    535|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    535|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    535|	} \
  |  |  |  |  162|    578|	return _ret; \
  |  |  |  |  163|    578|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  764|    578|}
card-idprime.c:idprime_select_file_by_path:
  283|  1.60k|{
  284|  1.60k|	int r;
  285|  1.60k|	sc_file_t *file = NULL;
  286|  1.60k|	sc_path_t index_path;
  287|       |
  288|       |	/* First, we need to make sure the IDPrime AID is selected */
  289|  1.60k|	r = idprime_select_idprime(card);
  290|  1.60k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.60k|#define SC_SUCCESS				0
  ------------------
  |  Branch (290:6): [True: 124, False: 1.48k]
  ------------------
  291|    124|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    124|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    124|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    124|	int _ret = r; \
  |  |  |  |  155|    124|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 124, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    124|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    124|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 124, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    124|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    124|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    124|	return _ret; \
  |  |  |  |  163|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|    124|	}
  293|       |
  294|       |	/* Returns FCI with expected length of data */
  295|  1.48k|	sc_format_path(str_path, &index_path);
  296|  1.48k|	r = iso_ops->select_file(card, &index_path, &file);
  297|       |
  298|  1.48k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.48k|#define SC_SUCCESS				0
  ------------------
  |  Branch (298:6): [True: 18, False: 1.46k]
  ------------------
  299|     18|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  300|     18|	}
  301|       |	/* Ignore too large files */
  302|  1.46k|	if (file->size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  1.46k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (302:6): [True: 0, False: 1.46k]
  ------------------
  303|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  304|  1.46k|	} else {
  305|  1.46k|		r = (int)file->size;
  306|  1.46k|	}
  307|  1.46k|	sc_file_free(file);
  308|  1.46k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.46k|	int _ret = r; \
  |  |  |  |  155|  1.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 1.45k]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.45k|	} else { \
  |  |  |  |  159|  1.45k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.45k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.45k|	} \
  |  |  |  |  162|  1.46k|	return _ret; \
  |  |  |  |  163|  1.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|  1.46k|}
card-idprime.c:idprime_select_idprime:
  277|  1.60k|{
  278|       |	return iso_ops->select_file(card, &idprime_path, NULL);
  279|  1.60k|}
card-idprime.c:idprime_init:
  565|    535|{
  566|    535|	int r;
  567|    535|	unsigned long flags, ext_flags;
  568|    535|	idprime_private_data_t *priv = NULL;
  569|    535|	struct sc_apdu apdu;
  570|    535|	u8 rbuf[CPLC_LENGTH];
  571|    535|	size_t rbuflen = sizeof(rbuf);
  572|       |
  573|    535|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    535|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    535|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    535|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 535]
  |  |  ------------------
  ------------------
  574|       |
  575|       |	/* We need to differentiate the OS version since they behave slightly differently */
  576|    535|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  301|    535|#define SC_APDU_CASE_2			0x22
  ------------------
  577|    535|	apdu.resp = rbuf;
  578|    535|	apdu.resplen = rbuflen;
  579|    535|	apdu.le = rbuflen;
  580|    535|	r = sc_transmit_apdu(card, &apdu);
  581|    535|	if (r == SC_SUCCESS && apdu.resplen == CPLC_LENGTH) {
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
              	if (r == SC_SUCCESS && apdu.resplen == CPLC_LENGTH) {
  ------------------
  |  |  563|    534|#define CPLC_LENGTH 45
  ------------------
  |  Branch (581:6): [True: 534, False: 1]
  |  Branch (581:25): [True: 115, False: 419]
  ------------------
  582|       |		/* We are interested in the OS release level here */
  583|    115|		switch (rbuf[11]) {
  584|     64|		case 0x01:
  ------------------
  |  Branch (584:3): [True: 64, False: 51]
  ------------------
  585|     64|			sc_log(card->ctx, "Detected IDPrime applet version 1");
  ------------------
  |  |   71|     64|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  586|     64|			break;
  587|      1|		case 0x02:
  ------------------
  |  Branch (587:3): [True: 1, False: 114]
  ------------------
  588|      1|			sc_log(card->ctx, "Detected IDPrime applet version 2");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  589|      1|			break;
  590|      6|		case 0x03:
  ------------------
  |  Branch (590:3): [True: 6, False: 109]
  ------------------
  591|      6|			sc_log(card->ctx, "Detected IDPrime applet version 3");
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  592|      6|			break;
  593|      1|		case 0x04:
  ------------------
  |  Branch (593:3): [True: 1, False: 114]
  ------------------
  594|      1|			sc_log(card->ctx, "Detected IDPrime applet version 4");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  595|      1|			break;
  596|     43|		default:
  ------------------
  |  Branch (596:3): [True: 43, False: 72]
  ------------------
  597|     43|			sc_log(card->ctx, "Unknown OS version received: %d", rbuf[11]);
  ------------------
  |  |   71|     43|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  598|     43|			break;
  599|    115|		}
  600|    420|	} else {
  601|    420|		sc_log(card->ctx, "Failed to get CPLC data or invalid length returned, err=%d, len=%zu",
  ------------------
  |  |   71|    420|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  602|    420|				r, apdu.resplen);
  603|    420|	}
  604|       |
  605|       |	/* Proprietary data -- Applet version */
  606|    535|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  301|    535|#define SC_APDU_CASE_2			0x22
  ------------------
  607|    535|	apdu.resp = rbuf;
  608|    535|	apdu.resplen = rbuflen;
  609|    535|	apdu.le = rbuflen;
  610|    535|	r = sc_transmit_apdu(card, &apdu);
  611|    535|	if (r == SC_SUCCESS && apdu.resplen >= 10) {
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (611:6): [True: 534, False: 1]
  |  Branch (611:25): [True: 34, False: 500]
  ------------------
  612|       |		/* Ber-TLV encoded */
  613|     34|		if (rbuf[0] == 0xDF && rbuf[1] == 0x30 && rbuf[2] == apdu.resplen - 3) {
  ------------------
  |  Branch (613:7): [True: 9, False: 25]
  |  Branch (613:26): [True: 8, False: 1]
  |  Branch (613:45): [True: 1, False: 7]
  ------------------
  614|      1|			sc_log(card->ctx, "IDPrime Java Applet version %.*s", (int)apdu.resplen - 3, rbuf + 3);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  615|      1|		}
  616|     34|	}
  617|       |
  618|    535|	priv = idprime_new_private_data();
  619|    535|	if (!priv) {
  ------------------
  |  Branch (619:6): [True: 0, False: 535]
  ------------------
  620|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|      0|	}
  622|       |
  623|       |	/* Select and process container file */
  624|    535|	r = idprime_select_file_by_path(card, "0204");;
  625|    535|	if (r <= 0) {
  ------------------
  |  Branch (625:6): [True: 49, False: 486]
  ------------------
  626|     49|		idprime_free_private_data(priv);
  627|     49|		if (r == 0)
  ------------------
  |  Branch (627:7): [True: 1, False: 48]
  ------------------
  628|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  629|     49|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     49|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|     49|	}
  631|       |
  632|    486|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Container file found");
  ------------------
  |  |   70|    486|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  633|       |
  634|    486|	r = idprime_process_containermap(card, priv, r);
  635|    486|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    486|#define SC_SUCCESS				0
  ------------------
  |  Branch (635:6): [True: 69, False: 417]
  ------------------
  636|     69|		idprime_free_private_data(priv);
  637|     69|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|     69|	}
  639|       |
  640|    417|	if (card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (640:6): [True: 117, False: 300]
  ------------------
  641|    117|		if ((r = idprime_select_file_by_path(card, "0005")) <= 0) {
  ------------------
  |  Branch (641:7): [True: 11, False: 106]
  ------------------
  642|     11|			idprime_free_private_data(priv);
  643|     11|			if (r == 0)
  ------------------
  |  Branch (643:8): [True: 1, False: 10]
  ------------------
  644|      1|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  645|     11|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  646|     11|		}
  647|       |
  648|    106|		if ((r = idprime_process_keyrefmap(card, priv, r)) != SC_SUCCESS) {
  ------------------
  |  |   28|    106|#define SC_SUCCESS				0
  ------------------
  |  Branch (648:7): [True: 28, False: 78]
  ------------------
  649|     28|			idprime_free_private_data(priv);
  650|     28|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|     28|		}
  652|    106|	}
  653|       |
  654|       |	/* Select and process the index file */
  655|    378|	r = idprime_select_file_by_path(card, "0101");
  656|    378|	if (r <= 0) {
  ------------------
  |  Branch (656:6): [True: 48, False: 330]
  ------------------
  657|     48|		idprime_free_private_data(priv);
  658|     48|		if (r == 0)
  ------------------
  |  Branch (658:7): [True: 1, False: 47]
  ------------------
  659|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  660|     48|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     48|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     48|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     48|	int _ret = r; \
  |  |  |  |  155|     48|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     48|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     48|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     48|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     48|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     48|	return _ret; \
  |  |  |  |  163|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  661|     48|	}
  662|       |
  663|    330|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Index file found");
  ------------------
  |  |   70|    330|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  664|       |
  665|    330|	r = idprime_process_index(card, priv, r);
  666|    330|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    330|#define SC_SUCCESS				0
  ------------------
  |  Branch (666:6): [True: 28, False: 302]
  ------------------
  667|     28|		idprime_free_private_data(priv);
  668|     28|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  669|     28|	}
  670|       |
  671|    302|	card->drv_data = priv;
  672|       |
  673|    302|	switch (card->type) {
  674|     17|	case SC_CARD_TYPE_IDPRIME_3810:
  ------------------
  |  Branch (674:2): [True: 17, False: 285]
  ------------------
  675|     17|		card->name = "Gemalto IDPrime 3810";
  676|     17|		break;
  677|     12|	case SC_CARD_TYPE_IDPRIME_830:
  ------------------
  |  Branch (677:2): [True: 12, False: 290]
  ------------------
  678|     12|		card->name = "Gemalto IDPrime MD 830";
  679|     12|		break;
  680|     11|	case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (680:2): [True: 11, False: 291]
  ------------------
  681|     11|	case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (681:2): [True: 0, False: 302]
  ------------------
  682|     11|		card->name = "Gemalto IDPrime 930/3930";
  683|     11|		break;
  684|     50|	case SC_CARD_TYPE_IDPRIME_940:
  ------------------
  |  Branch (684:2): [True: 50, False: 252]
  ------------------
  685|     50|		card->name = "Gemalto IDPrime 940";
  686|     50|		break;
  687|     31|	case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (687:2): [True: 31, False: 271]
  ------------------
  688|     31|		card->name = "Gemalto IDPrime MD 840";
  689|     31|		break;
  690|    181|	case SC_CARD_TYPE_IDPRIME_GENERIC:
  ------------------
  |  Branch (690:2): [True: 181, False: 121]
  ------------------
  691|    181|	default:
  ------------------
  |  Branch (691:2): [True: 0, False: 302]
  ------------------
  692|    181|		card->name = "Gemalto IDPrime (generic)";
  693|    181|		break;
  694|    302|	}
  695|    302|	card->cla = 0x00;
  696|       |
  697|       |	/* Set up algorithm info for RSA. */
  698|    302|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    302|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    302|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    302|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  699|    302|		| SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  107|    302|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  700|    302|		| SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  108|    302|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  701|       |		/* SHA-1 mechanisms are not allowed in the card I have */
  702|    302|		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  138|    302|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
              		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  139|    302|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
              		| (SC_ALGORITHM_RSA_HASH_SHA256 | SC_ALGORITHM_RSA_HASH_SHA384 | SC_ALGORITHM_RSA_HASH_SHA512)
  ------------------
  |  |  140|    302|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  703|    302|		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  146|    302|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  147|    302|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              		| (SC_ALGORITHM_MGF1_SHA256 | SC_ALGORITHM_MGF1_SHA384 | SC_ALGORITHM_MGF1_SHA512)
  ------------------
  |  |  148|    302|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
  704|    302|		;
  705|       |
  706|    302|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  707|    302|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  708|    302|	switch (card->type) {
  709|      0|	case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (709:2): [True: 0, False: 302]
  ------------------
  710|     50|	case SC_CARD_TYPE_IDPRIME_940:
  ------------------
  |  Branch (710:2): [True: 50, False: 252]
  ------------------
  711|     50|		_sc_card_add_rsa_alg(card, 3072, flags, 0);
  712|       |		/* fallthrough */
  713|     61|	case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (713:2): [True: 11, False: 291]
  ------------------
  714|     61|		_sc_card_add_rsa_alg(card, 4096, flags, 0);
  715|       |		/* fallthrough */
  716|     92|	case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (716:2): [True: 31, False: 271]
  ------------------
  717|       |		/* Set up algorithm info for EC */
  718|     92|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|     92|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|     92|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     92|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  719|     92|		if (card->type == SC_CARD_TYPE_IDPRIME_930_PLUS || card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (719:7): [True: 0, False: 92]
  |  Branch (719:54): [True: 50, False: 42]
  ------------------
  720|     50|			flags |= SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|     50|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  721|     50|		}
  722|     92|		ext_flags = SC_ALGORITHM_EXT_EC_F_P
  ------------------
  |  |  198|     92|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
  723|     92|			| SC_ALGORITHM_EXT_EC_ECPARAMETERS
  ------------------
  |  |  200|     92|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
  724|     92|			| SC_ALGORITHM_EXT_EC_NAMEDCURVE
  ------------------
  |  |  201|     92|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  725|     92|			| SC_ALGORITHM_EXT_EC_UNCOMPRESES
  ------------------
  |  |  202|     92|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  726|     92|			;
  727|     92|		_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
  728|     92|		_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
  729|     92|		_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
  730|     92|		break;
  731|    210|	default:
  ------------------
  |  Branch (731:2): [True: 210, False: 92]
  ------------------
  732|    210|		break;
  733|    302|	}
  734|       |
  735|    302|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    302|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  736|       |
  737|    302|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    302|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  738|       |
  739|    302|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|    302|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    302|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    302|	int _ret = r; \
  |  |  |  |  155|    302|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 302, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    302|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  157|    302|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    302|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    302|	return _ret; \
  |  |  |  |  163|    302|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  740|    302|}
card-idprime.c:idprime_process_containermap:
  312|    486|{
  313|    486|	u8 *buf = NULL;
  314|    486|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|    486|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  315|    486|	int i;
  316|    486|	uint8_t max_entries, container_index;
  317|       |
  318|    486|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    486|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    486|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    486|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 486]
  |  |  ------------------
  ------------------
  319|       |
  320|    486|	buf = malloc(length);
  321|    486|	if (buf == NULL) {
  ------------------
  |  Branch (321:6): [True: 0, False: 486]
  ------------------
  322|      0|		goto done;
  323|      0|	}
  324|       |
  325|    486|	r = 0;
  326|  1.56k|	do {
  327|       |		/* Read at most CONTAINER_OBJ_LEN bytes */
  328|  1.56k|		int read_length = length - r > CONTAINER_OBJ_LEN ? CONTAINER_OBJ_LEN : length - r;
  ------------------
  |  |  142|  1.56k|#define CONTAINER_OBJ_LEN 86
  ------------------
              		int read_length = length - r > CONTAINER_OBJ_LEN ? CONTAINER_OBJ_LEN : length - r;
  ------------------
  |  |  142|  1.01k|#define CONTAINER_OBJ_LEN 86
  ------------------
  |  Branch (328:21): [True: 1.01k, False: 551]
  ------------------
  329|  1.56k|		if (length == r) {
  ------------------
  |  Branch (329:7): [True: 0, False: 1.56k]
  ------------------
  330|      0|			r = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      0|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  331|      0|			goto done;
  332|      0|		}
  333|  1.56k|		const int got = iso_ops->read_binary(card, r, buf + r, read_length, 0);
  334|  1.56k|		if (got < 1) {
  ------------------
  |  Branch (334:7): [True: 69, False: 1.49k]
  ------------------
  335|     69|			if (got < 0) {
  ------------------
  |  Branch (335:8): [True: 68, False: 1]
  ------------------
  336|     68|				r = got;
  337|     68|			} else {
  338|      1|				r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      1|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  339|      1|			}
  340|     69|			goto done;
  341|     69|		}
  342|       |
  343|  1.49k|		r += got;
  344|       |
  345|       |		/* Try to read chunks of container size and stop when last container looks empty */
  346|  1.49k|		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|  1.49k|#define CONTAINER_OBJ_LEN 86
  ------------------
              		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|    771|#define CONTAINER_OBJ_LEN 86
  ------------------
              		container_index = r > CONTAINER_OBJ_LEN ? (r / CONTAINER_OBJ_LEN - 1) * CONTAINER_OBJ_LEN : 0;
  ------------------
  |  |  142|    771|#define CONTAINER_OBJ_LEN 86
  ------------------
  |  Branch (346:21): [True: 771, False: 726]
  ------------------
  347|  1.49k|	} while(length - r > 0 && buf[container_index] != 0);
  ------------------
  |  Branch (347:10): [True: 1.10k, False: 394]
  |  Branch (347:28): [True: 1.08k, False: 23]
  ------------------
  348|    417|	max_entries = r / CONTAINER_OBJ_LEN;
  ------------------
  |  |  142|    417|#define CONTAINER_OBJ_LEN 86
  ------------------
  349|       |
  350|    582|	for (i = 0; i < max_entries; i++) {
  ------------------
  |  Branch (350:14): [True: 185, False: 397]
  ------------------
  351|    185|		u8 *start = &buf[i * CONTAINER_OBJ_LEN];
  ------------------
  |  |  142|    185|#define CONTAINER_OBJ_LEN 86
  ------------------
  352|    185|		idprime_container_t new_container = {0};
  353|    185|		if (start[0] == 0) /* Empty record */
  ------------------
  |  Branch (353:7): [True: 20, False: 165]
  ------------------
  354|     20|			break;
  355|       |
  356|    165|		new_container.index = i;
  357|       |		/* Reading UNICODE characters but skipping second byte */
  358|    165|		int j = 0;
  359|  2.89k|		for (j = 0; j < MAX_CONTAINER_NAME_LEN; j++) {
  ------------------
  |  |  141|  2.89k|#define MAX_CONTAINER_NAME_LEN 39
  ------------------
  |  Branch (359:15): [True: 2.85k, False: 42]
  ------------------
  360|  2.85k|			if (start[2 * j] == 0)
  ------------------
  |  Branch (360:8): [True: 123, False: 2.73k]
  ------------------
  361|    123|				break;
  362|  2.73k|			new_container.guid[j] = start[2 * j];
  363|  2.73k|		}
  364|       |
  365|    165|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found container with index=%d, guid=%s", new_container.index, new_container.guid);
  ------------------
  |  |   70|    165|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  366|       |
  367|    165|		if ((r = idprime_add_container_to_list(&priv->containers, &new_container)) != SC_SUCCESS) {
  ------------------
  |  |   28|    165|#define SC_SUCCESS				0
  ------------------
  |  Branch (367:7): [True: 0, False: 165]
  ------------------
  368|      0|			goto done;
  369|      0|		}
  370|    165|	}
  371|       |
  372|    417|	r = SC_SUCCESS;
  ------------------
  |  |   28|    417|#define SC_SUCCESS				0
  ------------------
  373|    486|done:
  374|    486|	free(buf);
  375|    486|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    486|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    486|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    486|	int _ret = r; \
  |  |  |  |  155|    486|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 486, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    486|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 69, False: 417]
  |  |  |  |  ------------------
  |  |  |  |  157|    486|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    486|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    486|	return _ret; \
  |  |  |  |  163|    486|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    486|}
card-idprime.c:idprime_add_container_to_list:
  189|    165|{
  190|    165|	if (list_append(list, container) < 0)
  ------------------
  |  Branch (190:6): [True: 0, False: 165]
  ------------------
  191|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  192|    165|	return SC_SUCCESS;
  ------------------
  |  |   28|    165|#define SC_SUCCESS				0
  ------------------
  193|    165|}
card-idprime.c:idprime_process_keyrefmap:
  379|    106|{
  380|    106|	u8 *buf = NULL;
  381|    106|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|    106|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  382|    106|	int i, max_entries;
  383|       |
  384|    106|	buf = malloc(length);
  385|    106|	if (buf == NULL) {
  ------------------
  |  Branch (385:6): [True: 0, False: 106]
  ------------------
  386|      0|		goto done;
  387|      0|	}
  388|       |
  389|    106|	r = 0;
  390|    378|	do {
  391|    378|		if (length == r) {
  ------------------
  |  Branch (391:7): [True: 0, False: 378]
  ------------------
  392|      0|			r = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      0|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  393|      0|			goto done;
  394|      0|		}
  395|    378|		const int got = iso_ops->read_binary(card, r, buf + r, length - r, 0);
  396|    378|		if (got < 1) {
  ------------------
  |  Branch (396:7): [True: 28, False: 350]
  ------------------
  397|     28|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     28|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  398|     28|			goto done;
  399|     28|		}
  400|       |
  401|    350|		r += got;
  402|    350|	} while(length - r > 0);
  ------------------
  |  Branch (402:10): [True: 272, False: 78]
  ------------------
  403|     78|	max_entries = r / KEYREF_OBJ_LEN;
  ------------------
  |  |  151|     78|#define KEYREF_OBJ_LEN 8
  ------------------
  404|       |
  405|  12.3k|	for (i = 0; i < max_entries; i++) {
  ------------------
  |  Branch (405:14): [True: 12.2k, False: 78]
  ------------------
  406|  12.2k|		idprime_keyref_t new_keyref;
  407|  12.2k|		u8 *start = &buf[i * KEYREF_OBJ_LEN];
  ------------------
  |  |  151|  12.2k|#define KEYREF_OBJ_LEN 8
  ------------------
  408|  12.2k|		if (start[0] == 0) /* Empty key ref */
  ------------------
  |  Branch (408:7): [True: 922, False: 11.3k]
  ------------------
  409|    922|			continue;
  410|       |
  411|  11.3k|		new_keyref.index = start[2];
  412|  11.3k|		new_keyref.key_reference = start[1];
  413|  11.3k|		new_keyref.pin_index = start[7];
  414|  11.3k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found key reference with index=%d, pin=%d, keyref=%d", new_keyref.index, new_keyref.pin_index, new_keyref.key_reference);
  ------------------
  |  |   70|  11.3k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  415|       |
  416|  11.3k|		if ((r = idprime_add_keyref_to_list(&priv->keyrefmap, &new_keyref)) != SC_SUCCESS) {
  ------------------
  |  |   28|  11.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (416:7): [True: 0, False: 11.3k]
  ------------------
  417|      0|			goto done;
  418|      0|		}
  419|  11.3k|	}
  420|     78|	r = SC_SUCCESS;
  ------------------
  |  |   28|     78|#define SC_SUCCESS				0
  ------------------
  421|    106|done:
  422|    106|	free(buf);
  423|    106|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    106|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    106|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    106|	int _ret = r; \
  |  |  |  |  155|    106|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 106, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    106|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 78]
  |  |  |  |  ------------------
  |  |  |  |  157|    106|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    106|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    106|	return _ret; \
  |  |  |  |  163|    106|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  424|    106|}
card-idprime.c:idprime_add_keyref_to_list:
  207|  11.3k|{
  208|  11.3k|	if (list_append(list, keyref) < 0)
  ------------------
  |  Branch (208:6): [True: 0, False: 11.3k]
  ------------------
  209|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  210|  11.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  11.3k|#define SC_SUCCESS				0
  ------------------
  211|  11.3k|}
card-idprime.c:idprime_process_index:
  427|    330|{
  428|    330|	u8 *buf = NULL;
  429|    330|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|    330|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  430|    330|	int i, num_entries;
  431|    330|	idprime_object_t new_object;
  432|       |
  433|    330|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    330|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    330|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    330|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 330]
  |  |  ------------------
  ------------------
  434|       |
  435|    330|	buf = malloc(length);
  436|    330|	if (buf == NULL) {
  ------------------
  |  Branch (436:6): [True: 0, False: 330]
  ------------------
  437|      0|		goto done;
  438|      0|	}
  439|       |
  440|    330|	r = 0;
  441|    551|	do {
  442|    551|		if (length == r) {
  ------------------
  |  Branch (442:7): [True: 1, False: 550]
  ------------------
  443|      1|			r = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      1|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  444|      1|			goto done;
  445|      1|		}
  446|    550|		const int got = iso_ops->read_binary(card, r, buf + r, length - r, 0);
  447|    550|		if (got < 1) {
  ------------------
  |  Branch (447:7): [True: 27, False: 523]
  ------------------
  448|     27|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     27|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  449|     27|			goto done;
  450|     27|		}
  451|       |		/* First byte shows the number of entries, each of them 21 bytes long */
  452|    523|		num_entries = buf[0];
  453|    523|		r += got;
  454|    523|	} while(r < num_entries * 21 + 1);
  ------------------
  |  Branch (454:10): [True: 221, False: 302]
  ------------------
  455|       |
  456|    302|	new_object.fd = 0;
  457|  7.70k|	for (i = 0; i < num_entries; i++) {
  ------------------
  |  Branch (457:14): [True: 7.39k, False: 302]
  ------------------
  458|  7.39k|		u8 *start = &buf[i*21+1];
  459|       |
  460|       |		/* First two bytes specify the object DF */
  461|  7.39k|		new_object.df[0] = start[0];
  462|  7.39k|		new_object.df[1] = start[1];
  463|       |		/* Second two bytes refer to the object size */
  464|  7.39k|		new_object.length = bebytes2ushort(&start[2]);
  465|  7.39k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "df=%s, len=%u",
  ------------------
  |  |   70|  7.39k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|  7.39k|			sc_dump_hex(new_object.df, sizeof(new_object.df)), new_object.length);
  467|       |		/* in minidriver, mscp/kxcNN or kscNN lists certificates */
  468|  7.39k|		if (((memcmp(&start[4], "ksc", 3) == 0) || memcmp(&start[4], "kxc", 3) == 0)
  ------------------
  |  Branch (468:8): [True: 66, False: 7.33k]
  |  Branch (468:46): [True: 2.49k, False: 4.84k]
  ------------------
  469|  2.55k|			&& (memcmp(&start[12], "mscp", 5) == 0)) {
  ------------------
  |  Branch (469:7): [True: 2.15k, False: 404]
  ------------------
  470|  2.15k|			uint8_t cert_id = 0;
  471|  2.15k|			idprime_container_t *container = NULL;
  472|       |
  473|  2.15k|			if (start[7] >= '0' && start[7] <= '9' && start[8] >= '0' && start[8] <= '9') {
  ------------------
  |  Branch (473:8): [True: 2.07k, False: 81]
  |  Branch (473:27): [True: 1.24k, False: 825]
  |  Branch (473:46): [True: 1.02k, False: 227]
  |  Branch (473:65): [True: 487, False: 533]
  ------------------
  474|    487|				cert_id = (start[7] - '0') * 10 + start[8] - '0';
  475|    487|			}
  476|  2.15k|			new_object.fd++;
  477|  2.15k|			new_object.key_reference = -1;
  478|  2.15k|			new_object.valid_key_ref = 0;
  479|  2.15k|			new_object.pin_index = 1;
  480|       |
  481|  2.15k|			container = (idprime_container_t *) list_seek(&priv->containers, &cert_id);
  482|  2.15k|			if (!container) {
  ------------------
  |  Branch (482:8): [True: 1.03k, False: 1.11k]
  ------------------
  483|       |				/* Container map missing container with certificate ID */
  484|  1.03k|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "No corresponding container with private key found for certificate with id=%d", cert_id);
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  485|  1.03k|				if (card->type != SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (485:9): [True: 825, False: 213]
  ------------------
  486|       |					/* For cards other than the 940, we don't know how to recognize
  487|       |					certificates missing keys other than to check
  488|       |					that there is a corresponding entry in the container map.*/
  489|    825|					sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Adding certificate with fd=%d", new_object.fd);
  ------------------
  |  |   70|    825|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  490|    825|					idprime_add_object_to_list(&priv->pki_list, &new_object);
  491|    825|					continue;
  492|    825|				}
  493|  1.03k|			}
  494|       |
  495|  1.32k|			switch (card->type) {
  496|     99|			case SC_CARD_TYPE_IDPRIME_3810:
  ------------------
  |  Branch (496:4): [True: 99, False: 1.22k]
  ------------------
  497|     99|				new_object.key_reference = 0x31 + cert_id;
  498|     99|				break;
  499|    106|			case SC_CARD_TYPE_IDPRIME_830:
  ------------------
  |  Branch (499:4): [True: 106, False: 1.22k]
  ------------------
  500|    106|				new_object.key_reference = 0x41 + cert_id;
  501|    106|				break;
  502|     91|			case SC_CARD_TYPE_IDPRIME_930:
  ------------------
  |  Branch (502:4): [True: 91, False: 1.23k]
  ------------------
  503|     91|				new_object.key_reference = 0x11 + cert_id * 2;
  504|     91|				break;
  505|      0|			case SC_CARD_TYPE_IDPRIME_930_PLUS:
  ------------------
  |  Branch (505:4): [True: 0, False: 1.32k]
  ------------------
  506|      0|				new_object.key_reference = 0x10 + cert_id * 2;
  507|      0|				break;
  508|    213|			case SC_CARD_TYPE_IDPRIME_940: {
  ------------------
  |  Branch (508:4): [True: 213, False: 1.11k]
  ------------------
  509|    213|					idprime_keyref_t *keyref = (idprime_keyref_t *) list_seek(&priv->keyrefmap, &cert_id);
  510|    213|					if (!keyref) {
  ------------------
  |  Branch (510:10): [True: 122, False: 91]
  ------------------
  511|       |						/* Key reference file does not contain record of the key for given certificate */
  512|    122|						sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "No corresponding key reference found for certificate with id=%d", cert_id);
  ------------------
  |  |   70|    122|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  513|    122|						sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Adding certificate with fd=%d", new_object.fd);
  ------------------
  |  |   70|    122|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  514|    122|						idprime_add_object_to_list(&priv->pki_list, &new_object);
  515|    122|						continue;
  516|    122|					}
  517|     91|					new_object.key_reference = keyref->key_reference;
  518|     91|					new_object.pin_index = keyref->pin_index;
  519|     91|					break;
  520|    213|				}
  521|    725|			case SC_CARD_TYPE_IDPRIME_840:
  ------------------
  |  Branch (521:4): [True: 725, False: 603]
  ------------------
  522|    725|				new_object.key_reference = 0xf7 + cert_id;
  523|    725|				break;
  524|     94|			default:
  ------------------
  |  Branch (524:4): [True: 94, False: 1.23k]
  ------------------
  525|     94|				new_object.key_reference = 0x56 + cert_id;
  526|     94|				break;
  527|  1.32k|			}
  528|  1.20k|			new_object.valid_key_ref = 1;
  529|  1.20k|			if (container != NULL) {
  ------------------
  |  Branch (529:8): [True: 1.11k, False: 91]
  ------------------
  530|  1.11k|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found certificate with fd=%d, key_ref=%d corresponding to container \"%s\"",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  531|  1.11k|					new_object.fd, new_object.key_reference, container->guid);
  532|  1.11k|			} else {
  533|     91|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found certificate with fd=%d, key_ref=%d without corresponding container",
  ------------------
  |  |   70|     91|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  534|     91|					new_object.fd, new_object.key_reference);
  535|     91|			}
  536|       |
  537|  1.20k|			idprime_add_object_to_list(&priv->pki_list, &new_object);
  538|       |
  539|       |		/* This looks like non-standard extension listing pkcs11 token info label in my card */
  540|  5.24k|		} else if ((memcmp(&start[4], "tinfo", 6) == 0) && (memcmp(&start[12], "p11", 4) == 0)) {
  ------------------
  |  Branch (540:14): [True: 99, False: 5.14k]
  |  Branch (540:54): [True: 46, False: 53]
  ------------------
  541|     46|			memcpy(priv->tinfo_df, new_object.df, sizeof(priv->tinfo_df));
  542|     46|			priv->tinfo_present = 1;
  543|     46|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found p11/tinfo object");
  ------------------
  |  |   70|     46|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  544|  5.19k|		} else if ((memcmp(&start[4], "cmapfile", 8) == 0) && (memcmp(&start[12], "mscp", 4) == 0)) {
  ------------------
  |  Branch (544:14): [True: 36, False: 5.16k]
  |  Branch (544:57): [True: 21, False: 15]
  ------------------
  545|     21|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found mscp/cmapfile object %s",
  ------------------
  |  |   70|     74|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 11, False: 10]
  |  |  |  Branch (70:115): [True: 8, False: 3]
  |  |  ------------------
  ------------------
  546|     21|					(start[0] == 02 && start[1] == 04 ? "(already processed)" : "(in non-standard path!)"));
  547|  5.17k|		} else if (memcmp(&start[4], "cardapps", 8) == 0) {
  ------------------
  |  Branch (547:14): [True: 12, False: 5.16k]
  ------------------
  548|     12|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardapps object");
  ------------------
  |  |   70|     12|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  549|  5.16k|		} else if (memcmp(&start[4], "cardid", 6) == 0) {
  ------------------
  |  Branch (549:14): [True: 21, False: 5.14k]
  ------------------
  550|     21|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardid object");
  ------------------
  |  |   70|     21|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|  5.14k|		} else if (memcmp(&start[4], "cardcf", 6) == 0) {
  ------------------
  |  Branch (551:14): [True: 17, False: 5.12k]
  ------------------
  552|     17|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Found cardcf object");
  ------------------
  |  |   70|     17|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  553|     17|		}
  554|  7.39k|	}
  555|       |
  556|    302|	r = SC_SUCCESS;
  ------------------
  |  |   28|    302|#define SC_SUCCESS				0
  ------------------
  557|    330|done:
  558|    330|	free(buf);
  559|    330|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    330|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    330|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    330|	int _ret = r; \
  |  |  |  |  155|    330|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 330, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    330|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  157|    330|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    330|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    330|	return _ret; \
  |  |  |  |  163|    330|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|    330|}
card-idprime.c:idprime_finish:
  743|    302|{
  744|    302|	idprime_private_data_t * priv = card->drv_data;
  745|       |
  746|    302|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    302|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    302|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    302|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 302]
  |  |  ------------------
  ------------------
  747|    302|	if (priv) {
  ------------------
  |  Branch (747:6): [True: 302, False: 0]
  ------------------
  748|    302|		idprime_free_private_data(priv);
  749|    302|	}
  750|    302|	return SC_SUCCESS;
  ------------------
  |  |   28|    302|#define SC_SUCCESS				0
  ------------------
  751|    302|}
card-idprime.c:idprime_read_binary:
  968|    480|{
  969|    480|	struct idprime_private_data *priv = card->drv_data;
  970|    480|	int r = 0;
  971|    480|	int size;
  972|    480|	size_t sz;
  973|       |
  974|    480|	sc_log(card->ctx, "called; %zu bytes at offset %d", count, offset);
  ------------------
  |  |   71|    480|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  975|       |
  976|    480|	if (!priv->cached && offset == 0) {
  ------------------
  |  Branch (976:6): [True: 136, False: 344]
  |  Branch (976:23): [True: 136, False: 0]
  ------------------
  977|       |		/* Read what was reported by FCI from select command */
  978|    136|		size_t left = priv->file_size;
  979|    136|		unsigned read = 0;
  980|       |
  981|       |		// this function is called to read and uncompress the certificate
  982|    136|		u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  983|    136|		u8 *data_buffer = buffer;
  984|    136|		if (sizeof(buffer) < count || sizeof(buffer) < priv->file_size) {
  ------------------
  |  Branch (984:7): [True: 0, False: 136]
  |  Branch (984:33): [True: 0, False: 136]
  ------------------
  985|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  986|      0|		}
  987|    254|		while (left > 0) {
  ------------------
  |  Branch (987:10): [True: 169, False: 85]
  ------------------
  988|    169|			r = iso_ops->read_binary(card, read, buffer + read, priv->file_size - read, flags);
  989|    169|			if (r <= 0) {
  ------------------
  |  Branch (989:8): [True: 51, False: 118]
  ------------------
  990|     51|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|     51|			}
  992|    118|			left -= r;
  993|    118|			read += r;
  994|    118|		}
  995|     85|		if (read < 4 || read != priv->file_size) {
  ------------------
  |  Branch (995:7): [True: 31, False: 54]
  |  Branch (995:19): [True: 0, False: 54]
  ------------------
  996|     31|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     31|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     31|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     31|	int _ret = r; \
  |  |  |  |  155|     31|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     31|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     31|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     31|	return _ret; \
  |  |  |  |  163|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  997|     31|		}
  998|     54|		if (buffer[0] == 1 && buffer[1] == 0) {
  ------------------
  |  Branch (998:7): [True: 29, False: 25]
  |  Branch (998:25): [True: 18, False: 11]
  ------------------
  999|       |			/* Data will be decompressed later */
 1000|     18|			data_buffer += 4;
 1001|     18|			sz = priv->file_size - 4;
 1002|     18|			if (flags)
  ------------------
  |  Branch (1002:8): [True: 12, False: 6]
  ------------------
 1003|     12|				*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     12|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 1004|     36|		} else {
 1005|     36|			sz = priv->file_size;
 1006|     36|		}
 1007|     54|		priv->cache_buf = malloc(sz);
 1008|     54|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (1008:7): [True: 0, False: 54]
  ------------------
 1009|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1010|      0|		}
 1011|     54|		memcpy(priv->cache_buf, data_buffer, sz);
 1012|     54|		priv->cache_buf_len = sz;
 1013|     54|		priv->cached = 1;
 1014|     54|	}
 1015|    398|	if (offset >= priv->cache_buf_len) {
  ------------------
  |  Branch (1015:6): [True: 18, False: 380]
  ------------------
 1016|     18|		return 0;
 1017|     18|	}
 1018|    380|	size = (int) MIN((priv->cache_buf_len - offset), count);
  ------------------
  |  |   69|    380|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 18, False: 362]
  |  |  ------------------
  ------------------
 1019|    380|	memcpy(buf, priv->cache_buf + offset, size);
 1020|    380|	return size;
 1021|    398|}
card-idprime.c:idprime_select_file:
  942|  3.05k|{
  943|  3.05k|	int r;
  944|  3.05k|	idprime_private_data_t * priv = card->drv_data;
  945|       |
  946|  3.05k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.05k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.05k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.05k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.05k]
  |  |  ------------------
  ------------------
  947|       |
  948|       |	/* forget any old cached values */
  949|  3.05k|	if (priv->cache_buf) {
  ------------------
  |  Branch (949:6): [True: 41, False: 3.01k]
  ------------------
  950|     41|		free(priv->cache_buf);
  951|     41|		priv->cache_buf = NULL;
  952|     41|	}
  953|  3.05k|	priv->cache_buf_len = 0;
  954|  3.05k|	priv->cached = 0;
  955|       |
  956|  3.05k|	r = iso_ops->select_file(card, in_path, file_out);
  957|  3.05k|	if (r == SC_SUCCESS && file_out != NULL) {
  ------------------
  |  |   28|  6.11k|#define SC_SUCCESS				0
  ------------------
  |  Branch (957:6): [True: 207, False: 2.84k]
  |  Branch (957:25): [True: 167, False: 40]
  ------------------
  958|       | 	 	/* Cache the real file size for the caching read_binary() */
  959|    167| 	 	priv->file_size = (*file_out)->size;
  960|    167|	}
  961|       |	/* Return the exit code of the select command */
  962|  3.05k|	return r;
  963|  3.05k|}
card-idprime.c:idprime_card_ctl:
  909|  5.50k|{
  910|  5.50k|	idprime_private_data_t * priv = card->drv_data;
  911|       |
  912|  5.50k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.50k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.50k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.50k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.50k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.50k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  913|  5.50k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  5.50k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  914|       |
  915|  5.50k|	if (priv == NULL) {
  ------------------
  |  Branch (915:6): [True: 0, False: 5.50k]
  ------------------
  916|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  917|      0|	}
  918|  5.50k|	switch (cmd) {
  ------------------
  |  Branch (918:10): [True: 5.50k, False: 0]
  ------------------
  919|    303|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (919:3): [True: 303, False: 5.20k]
  ------------------
  920|    303|			return idprime_get_serial(card, (sc_serial_number_t *) ptr);
  921|    300|		case SC_CARDCTL_IDPRIME_GET_TOKEN_NAME:
  ------------------
  |  Branch (921:3): [True: 300, False: 5.20k]
  ------------------
  922|    300|			return idprime_get_token_name(card, (char **) ptr);
  923|    300|		case SC_CARDCTL_IDPRIME_INIT_GET_OBJECTS:
  ------------------
  |  Branch (923:3): [True: 300, False: 5.20k]
  ------------------
  924|    300|			return idprime_get_init_and_get_count(&priv->pki_list, &priv->pki_current,
  925|    300|				(int *)ptr);
  926|  2.15k|		case SC_CARDCTL_IDPRIME_GET_NEXT_OBJECT:
  ------------------
  |  Branch (926:3): [True: 2.15k, False: 3.35k]
  ------------------
  927|  2.15k|			return idprime_fill_prkey_info(&priv->pki_list, &priv->pki_current,
  928|  2.15k|				(sc_pkcs15_prkey_info_t *)ptr);
  929|    300|		case SC_CARDCTL_IDPRIME_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (929:3): [True: 300, False: 5.20k]
  ------------------
  930|    300|			return idprime_final_iterator(&priv->pki_list);
  931|  2.15k|		case SC_CARDCTL_IDPRIME_GET_PIN_ID:
  ------------------
  |  Branch (931:3): [True: 2.15k, False: 3.35k]
  ------------------
  932|  2.15k|			return idprime_get_pin_id(&priv->pki_list, &priv->pki_current,
  933|  2.15k|				(const char **)ptr);
  934|  5.50k|	}
  935|       |
  936|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  937|      0|}
card-idprime.c:idprime_get_serial:
  826|    303|{
  827|    303|	sc_path_t cardid_path;
  828|    303|	sc_file_t *file = NULL;
  829|    303|	u8 buf[IDPRIME_CARDID_LEN];
  830|    303|	int r;
  831|       |
  832|    303|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    303|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    303|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    303|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    303|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 303]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  833|       |
  834|       |	/* XXX this is assumed to be cardid for windows. It can be read from the index file */
  835|    303|	sc_format_path("0201", &cardid_path);
  836|    303|	r = iso_ops->select_file(card, &cardid_path, &file);
  837|    303|	if (r != SC_SUCCESS || file->size != IDPRIME_CARDID_LEN) { /* The cardid is always 16 B */
  ------------------
  |  |   28|    606|#define SC_SUCCESS				0
  ------------------
              	if (r != SC_SUCCESS || file->size != IDPRIME_CARDID_LEN) { /* The cardid is always 16 B */
  ------------------
  |  |  823|     11|#define IDPRIME_CARDID_LEN 16
  ------------------
  |  Branch (837:6): [True: 292, False: 11]
  |  Branch (837:25): [True: 7, False: 4]
  ------------------
  838|    299|		sc_file_free(file);
  839|    299|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|    299|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    299|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    299|	int _ret = r; \
  |  |  |  |  155|    299|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 299, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    299|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    299|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 299, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    299|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    299|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    299|	return _ret; \
  |  |  |  |  163|    299|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|    299|	}
  841|       |
  842|      4|	r = iso_ops->read_binary(card, 0, buf, file->size, 0);
  843|      4|	sc_file_free(file);
  844|      4|	if (r < 1) {
  ------------------
  |  Branch (844:6): [True: 1, False: 3]
  ------------------
  845|      1|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|      3|	} else if (r != IDPRIME_CARDID_LEN) {
  ------------------
  |  |  823|      3|#define IDPRIME_CARDID_LEN 16
  ------------------
  |  Branch (846:13): [True: 1, False: 2]
  ------------------
  847|      1|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  848|      1|	}
  849|       |
  850|      2|	serial->len = MIN(IDPRIME_CARDID_LEN, SC_MAX_SERIALNR);
  ------------------
  |  |   69|      2|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 2, Folded]
  |  |  ------------------
  ------------------
  851|      2|	memcpy(serial->value, buf, serial->len);
  852|      2|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|      2|}
card-idprime.c:idprime_get_token_name:
  856|    300|{
  857|    300|	idprime_private_data_t * priv = card->drv_data;
  858|    300|	sc_path_t tinfo_path = {"\x00\x00", 2, 0, 0, SC_PATH_TYPE_PATH, {"", 0}};
  ------------------
  |  |  119|    300|#define SC_PATH_TYPE_PATH		2
  ------------------
  859|    300|	sc_file_t *file = NULL;
  860|    300|	u8 buf[2];
  861|    300|	char *name;
  862|    300|	int r;
  863|       |
  864|    300|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    300|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    300|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    300|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    300|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  865|       |
  866|    300|	if (tname == NULL) {
  ------------------
  |  Branch (866:6): [True: 0, False: 300]
  ------------------
  867|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  868|      0|	}
  869|       |
  870|    300|	if (!priv->tinfo_present) {
  ------------------
  |  Branch (870:6): [True: 267, False: 33]
  ------------------
  871|    267|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    267|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    267|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    267|	int _ret = r; \
  |  |  |  |  155|    267|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 267, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    267|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    267|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 267, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    267|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    267|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    267|	return _ret; \
  |  |  |  |  163|    267|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  872|    267|	}
  873|       |
  874|     33|	memcpy(tinfo_path.value, priv->tinfo_df, 2);
  875|     33|	r = iso_ops->select_file(card, &tinfo_path, &file);
  876|     33|	if (r != SC_SUCCESS || file->size == 0) {
  ------------------
  |  |   28|     66|#define SC_SUCCESS				0
  ------------------
  |  Branch (876:6): [True: 10, False: 23]
  |  Branch (876:25): [True: 1, False: 22]
  ------------------
  877|     11|		sc_file_free(file);
  878|     11|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  879|     11|	}
  880|       |
  881|       |	/* First two bytes lists 0x01, the second indicates length */
  882|     22|	r = iso_ops->read_binary(card, 0, buf, 2, 0);
  883|     22|	if (r < 2 || buf[1] > file->size) { /* make sure we do not overrun */
  ------------------
  |  Branch (883:6): [True: 2, False: 20]
  |  Branch (883:15): [True: 1, False: 19]
  ------------------
  884|      3|		sc_file_free(file);
  885|      3|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|      3|	}
  887|     19|	sc_file_free(file);
  888|       |
  889|     19|	name = malloc(buf[1]);
  890|     19|	if (name == NULL) {
  ------------------
  |  Branch (890:6): [True: 0, False: 19]
  ------------------
  891|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  892|      0|	}
  893|       |
  894|     19|	r = iso_ops->read_binary(card, 2, (unsigned char *)name, buf[1], 0);
  895|     19|	if (r < 1) {
  ------------------
  |  Branch (895:6): [True: 9, False: 10]
  ------------------
  896|      9|		free(name);
  897|      9|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  898|      9|	}
  899|       |
  900|     10|	if (name[r-1] != '\0') {
  ------------------
  |  Branch (900:6): [True: 9, False: 1]
  ------------------
  901|      9|		name[r-1] = '\0';
  902|      9|	}
  903|     10|	*tname = name;
  904|       |
  905|     10|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  906|     10|}
card-idprime.c:idprime_get_init_and_get_count:
  768|    300|{
  769|    300|	if (countp == NULL || entry == NULL) {
  ------------------
  |  Branch (769:6): [True: 0, False: 300]
  |  Branch (769:24): [True: 0, False: 300]
  ------------------
  770|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  771|      0|	}
  772|    300|	*countp = list_size(list);
  773|    300|	list_iterator_start(list);
  774|    300|	*entry = list_iterator_next(list);
  775|    300|	return SC_SUCCESS;
  ------------------
  |  |   28|    300|#define SC_SUCCESS				0
  ------------------
  776|    300|}
card-idprime.c:idprime_fill_prkey_info:
  787|  2.15k|{
  788|  2.15k|	memset(prkey_info, 0, sizeof(sc_pkcs15_prkey_info_t));
  789|  2.15k|	if (*entry == NULL) {
  ------------------
  |  Branch (789:6): [True: 0, False: 2.15k]
  ------------------
  790|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  791|      0|	}
  792|       |
  793|  2.15k|	prkey_info->path.len = sizeof((*entry)->df);
  794|  2.15k|	memcpy(prkey_info->path.value, (*entry)->df, sizeof((*entry)->df));
  795|  2.15k|	prkey_info->path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  2.15k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  796|       |	/* Do not specify the length -- it will be read from the FCI */
  797|  2.15k|	prkey_info->path.count = -1;
  798|       |
  799|       |	/* TODO figure out the IDs as the original driver? */
  800|  2.15k|	prkey_info->id.value[0] = ((*entry)->fd >> 8) & 0xff;
  801|  2.15k|	prkey_info->id.value[1] = (*entry)->fd & 0xff;
  802|  2.15k|	prkey_info->id.len = 2;
  803|  2.15k|	if ((*entry)->valid_key_ref)
  ------------------
  |  Branch (803:6): [True: 1.20k, False: 946]
  ------------------
  804|  1.20k|		prkey_info->key_reference = (*entry)->key_reference;
  805|    946|	else
  806|    946|		prkey_info->key_reference = -1;
  807|  2.15k|	*entry = list_iterator_next(list);
  808|  2.15k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.15k|#define SC_SUCCESS				0
  ------------------
  809|  2.15k|}
card-idprime.c:idprime_final_iterator:
  780|    300|{
  781|    300|	list_iterator_stop(list);
  782|    300|	return SC_SUCCESS;
  ------------------
  |  |   28|    300|#define SC_SUCCESS				0
  ------------------
  783|    300|}
card-idprime.c:idprime_get_pin_id:
  813|  2.15k|{
  814|  2.15k|	if (pin_id == NULL || entry == NULL) {
  ------------------
  |  Branch (814:6): [True: 0, False: 2.15k]
  |  Branch (814:24): [True: 0, False: 2.15k]
  ------------------
  815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  816|      0|	}
  817|  2.15k|	*pin_id = "11"; // normal PIN id
  818|  2.15k|	if ((*entry)->pin_index != 1)
  ------------------
  |  Branch (818:6): [True: 89, False: 2.06k]
  ------------------
  819|     89|		*pin_id = "83"; // signature PIN id
  820|  2.15k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.15k|#define SC_SUCCESS				0
  ------------------
  821|  2.15k|}

sc_get_isoApplet_driver:
 1295|  15.2k|{
 1296|  15.2k|	return sc_get_driver();
 1297|  15.2k|}
card-isoApplet.c:sc_get_driver:
 1259|  15.2k|{
 1260|  15.2k|	sc_card_driver_t *iso_drv = sc_get_iso7816_driver();
 1261|       |
 1262|  15.2k|	if(iso_ops == NULL)
  ------------------
  |  Branch (1262:5): [True: 1, False: 15.2k]
  ------------------
 1263|      1|	{
 1264|      1|		iso_ops = iso_drv->ops;
 1265|      1|	}
 1266|       |
 1267|  15.2k|	isoApplet_ops = *iso_drv->ops;
 1268|       |
 1269|  15.2k|	isoApplet_ops.match_card = isoApplet_match_card;
 1270|  15.2k|	isoApplet_ops.init = isoApplet_init;
 1271|  15.2k|	isoApplet_ops.finish = isoApplet_finish;
 1272|       |
 1273|  15.2k|	isoApplet_ops.card_ctl = isoApplet_card_ctl;
 1274|       |
 1275|  15.2k|	isoApplet_ops.create_file = isoApplet_create_file;
 1276|  15.2k|	isoApplet_ops.process_fci = isoApplet_process_fci;
 1277|  15.2k|	isoApplet_ops.set_security_env = isoApplet_set_security_env;
 1278|  15.2k|	isoApplet_ops.compute_signature = isoApplet_compute_signature;
 1279|  15.2k|	isoApplet_ops.get_challenge = isoApplet_get_challenge;
 1280|  15.2k|	isoApplet_ops.card_reader_lock_obtained = isoApplet_card_reader_lock_obtained;
 1281|  15.2k|	isoApplet_ops.logout = isoApplet_logout;
 1282|       |
 1283|       |	/* unsupported functions */
 1284|  15.2k|	isoApplet_ops.write_binary = NULL;
 1285|  15.2k|	isoApplet_ops.read_record = NULL;
 1286|  15.2k|	isoApplet_ops.write_record = NULL;
 1287|  15.2k|	isoApplet_ops.append_record = NULL;
 1288|  15.2k|	isoApplet_ops.update_record = NULL;
 1289|  15.2k|	isoApplet_ops.restore_security_env = NULL;
 1290|       |
 1291|  15.2k|	return &isoApplet_drv;
 1292|  15.2k|}
card-isoApplet.c:isoApplet_match_card:
  111|  3.72k|{
  112|  3.72k|	int rv;
  113|       |
  114|  3.72k|	rv = iso7816_select_aid(card, isoApplet_aid, sizeof(isoApplet_aid), NULL, NULL);
  115|  3.72k|	if(rv != SC_SUCCESS)
  ------------------
  |  |   28|  3.72k|#define SC_SUCCESS				0
  ------------------
  |  Branch (115:5): [True: 3.64k, False: 78]
  ------------------
  116|  3.64k|	{
  117|  3.64k|		return 0;
  118|  3.64k|	}
  119|       |
  120|     78|	return 1;
  121|  3.72k|}
card-isoApplet.c:isoApplet_init:
  155|     78|{
  156|     78|	int i, r;
  157|     78|	unsigned int major_version = 0;
  158|     78|	unsigned long flags = 0;
  159|     78|	unsigned long ext_flags = 0;
  160|     78|	struct isoApplet_drv_data *drvdata;
  161|       |
  162|     78|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     78|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     78|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     78|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     78|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 78]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|     78|	drvdata=calloc(1, sizeof(*drvdata));
  165|     78|	if (!drvdata)
  ------------------
  |  Branch (165:6): [True: 0, False: 78]
  ------------------
  166|     78|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|       |
  168|     78|	card->drv_data = drvdata;
  169|     78|	card->cla = 0x00;
  170|       |
  171|       |	/* Obtain applet version and specific features */
  172|     78|	r = isoApplet_get_info(card, drvdata);
  173|     78|	LOG_TEST_GOTO_ERR(card->ctx, r, "Error obtaining information about applet.");
  ------------------
  |  |  184|     78|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     78|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     78|	int _ret = (r); \
  |  |  |  |  178|     78|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  179|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     11|		goto err; \
  |  |  |  |  182|     11|	} \
  |  |  |  |  183|     78|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|     67|	major_version = drvdata->isoapplet_version & 0xFF00;
  176|     67|	if(major_version != (ISOAPPLET_VERSION_V0 & 0xFF00) && major_version != (ISOAPPLET_VERSION_V1 & 0xFF00))
  ------------------
  |  |   36|     67|#define ISOAPPLET_VERSION_V0 0x0006
  ------------------
              	if(major_version != (ISOAPPLET_VERSION_V0 & 0xFF00) && major_version != (ISOAPPLET_VERSION_V1 & 0xFF00))
  ------------------
  |  |   37|     12|#define ISOAPPLET_VERSION_V1 0x0100
  ------------------
  |  Branch (176:5): [True: 12, False: 55]
  |  Branch (176:57): [True: 6, False: 6]
  ------------------
  177|      6|	{
  178|      6|		sc_log(card->ctx, "IsoApplet: Mismatching major API version. Not proceeding. "
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  180|      6|			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|      6|#define ISOAPPLET_VERSION_V0 0x0006
  |  |  |  |  ------------------
  |  |  |  |               			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  |  |  |  |  ------------------
  |  |  |  |  |  |   37|      6|#define ISOAPPLET_VERSION_V1 0x0100
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  179|      6|			   "API versions: Driver (%04X or %04X), applet (%04X). Please update accordingly.",
  180|      6|			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  181|      6|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      6|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  182|      6|		goto err;
  183|      6|	}
  184|     61|	else if(drvdata->isoapplet_version != ISOAPPLET_VERSION_V0 && drvdata->isoapplet_version != ISOAPPLET_VERSION_V1)
  ------------------
  |  |   36|    122|#define ISOAPPLET_VERSION_V0 0x0006
  ------------------
              	else if(drvdata->isoapplet_version != ISOAPPLET_VERSION_V0 && drvdata->isoapplet_version != ISOAPPLET_VERSION_V1)
  ------------------
  |  |   37|     60|#define ISOAPPLET_VERSION_V1 0x0100
  ------------------
  |  Branch (184:10): [True: 60, False: 1]
  |  Branch (184:64): [True: 59, False: 1]
  ------------------
  185|     59|	{
  186|     59|		sc_log(card->ctx, "IsoApplet: Mismatching minor version. Proceeding anyway. "
  ------------------
  |  |   71|     59|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  189|     59|			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|     59|#define ISOAPPLET_VERSION_V0 0x0006
  |  |  |  |  ------------------
  |  |  |  |               			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  |  |  |  |  ------------------
  |  |  |  |  |  |   37|     59|#define ISOAPPLET_VERSION_V1 0x0100
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  187|     59|			   "API versions: Driver (%04X or %04X), applet (%04X). "
  188|     59|			   "Please update accordingly whenever possible.",
  189|     59|			   ISOAPPLET_VERSION_V0, ISOAPPLET_VERSION_V1, drvdata->isoapplet_version);
  190|     59|	}
  191|       |
  192|     61|	if(drvdata->isoapplet_features & ISOAPPLET_API_FEATURE_EXT_APDU)
  ------------------
  |  |   39|     61|#define ISOAPPLET_API_FEATURE_EXT_APDU 0x01
  ------------------
  |  Branch (192:5): [True: 15, False: 46]
  ------------------
  193|     15|		card->caps |=  SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     15|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  194|     61|	if(drvdata->isoapplet_features & ISOAPPLET_API_FEATURE_SECURE_RANDOM)
  ------------------
  |  |   40|     61|#define ISOAPPLET_API_FEATURE_SECURE_RANDOM 0x02
  ------------------
  |  Branch (194:5): [True: 11, False: 50]
  ------------------
  195|     11|		card->caps |=  SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     11|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  196|     61|	if(drvdata->isoapplet_version <= 0x0005
  ------------------
  |  Branch (196:5): [True: 35, False: 26]
  ------------------
  197|     26|			|| drvdata->isoapplet_features & ISOAPPLET_API_FEATURE_ECC)
  ------------------
  |  |   41|     26|#define ISOAPPLET_API_FEATURE_ECC 0x04
  ------------------
  |  Branch (197:7): [True: 13, False: 13]
  ------------------
  198|     48|	{
  199|       |		/* There are Java Cards that do not support ECDSA at all. The IsoApplet
  200|       |		 * started to report this with version 00.06.
  201|       |		 *
  202|       |		 * Curves supported by the pkcs15-init driver are indicated per curve. This
  203|       |		 * should be kept in sync with the explicit parameters in the pkcs15-init
  204|       |		 * driver. */
  205|     48|		flags = 0;
  206|     48|		if (major_version == (ISOAPPLET_VERSION_V0 & 0xFF00)) {
  ------------------
  |  |   36|     48|#define ISOAPPLET_VERSION_V0 0x0006
  ------------------
  |  Branch (206:7): [True: 44, False: 4]
  ------------------
  207|     44|			flags |= SC_ALGORITHM_ECDSA_HASH_SHA1;
  ------------------
  |  |  176|     44|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|     44|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  208|     44|		} else { // ISOAPPLET_VERSION_V1
  209|      4|			flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|      4|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  210|      4|			flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|      4|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|      4|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  211|      4|		}
  212|     48|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     48|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  213|     48|		ext_flags = SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|     48|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  214|     48|		ext_flags |=  SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|     48|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  215|     48|		ext_flags |= SC_ALGORITHM_EXT_EC_F_P;
  ------------------
  |  |  198|     48|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
  216|    528|		for (i=0; ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (216:13): [True: 480, False: 48]
  ------------------
  217|    480|		{
  218|    480|			if(drvdata->isoapplet_version >= ec_curves[i].min_applet_version)
  ------------------
  |  Branch (218:7): [True: 410, False: 70]
  ------------------
  219|    410|				_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
  220|    480|		}
  221|     48|	}
  222|       |
  223|       |	/* RSA */
  224|     61|	flags = 0;
  225|     61|	flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|     61|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     61|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     61|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  226|     61|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     61|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  227|     61|	if(drvdata->isoapplet_features & ISOAPPLET_API_FEATURE_RSA_PSS) {
  ------------------
  |  |   42|     61|#define ISOAPPLET_API_FEATURE_RSA_PSS 0x08
  ------------------
  |  Branch (227:5): [True: 14, False: 47]
  ------------------
  228|     14|		flags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|     14|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  229|     14|	}
  230|       |	/* Key-generation: */
  231|     61|	flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     61|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  232|       |	/* Modulus lengths: */
  233|     61|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  234|     61|	if (drvdata->isoapplet_features & ISOAPPLET_API_FEATURE_RSA_4096) {
  ------------------
  |  |   43|     61|#define ISOAPPLET_API_FEATURE_RSA_4096 0x20
  ------------------
  |  Branch (234:6): [True: 14, False: 47]
  ------------------
  235|     14|		_sc_card_add_rsa_alg(card, 4096, flags, 0);
  236|     14|	}
  237|       |
  238|     61|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     61|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     61|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     61|	int _ret = r; \
  |  |  |  |  155|     61|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  157|     61|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     61|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     61|	return _ret; \
  |  |  |  |  163|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|     17|err:
  240|     17|	free(drvdata);
  241|     17|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  242|     17|}
card-isoApplet.c:isoApplet_get_info:
  124|     78|isoApplet_get_info(sc_card_t * card, struct isoApplet_drv_data * drvdata) {
  125|     78|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  126|     78|	int rv;
  127|     78|	sc_context_t * ctx = card->ctx;
  128|       |
  129|     78|	rv = sc_get_data(card, 0x0101, rbuf, 3);
  130|     78|	if(rv == SC_ERROR_INS_NOT_SUPPORTED) {
  ------------------
  |  |   54|     78|#define SC_ERROR_INS_NOT_SUPPORTED		-1204
  ------------------
  |  Branch (130:5): [True: 9, False: 69]
  ------------------
  131|       |		/* INS not supported. This is an older IsoApplet that might return the
  132|       |		 * applet information upon selection. For backward compatibility, try this. */
  133|      9|		size_t rlen = sizeof(rbuf);
  134|      9|		rv = iso7816_select_aid(card, isoApplet_aid, sizeof(isoApplet_aid), rbuf, &rlen);
  135|      9|		LOG_TEST_RET(ctx, rv, "Error selecting applet.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  136|      2|		rv = (int)rlen;
  137|      2|	}
  138|       |
  139|     71|	if (rv < 0) {
  ------------------
  |  Branch (139:6): [True: 4, False: 67]
  ------------------
  140|      4|		LOG_TEST_RET(ctx, rv, "Card returned error.");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|      4|	}
  142|       |
  143|       |	/* Fill up drvdata */
  144|     67|	if(rv >= 3)
  ------------------
  |  Branch (144:5): [True: 34, False: 33]
  ------------------
  145|     34|	{
  146|     34|		drvdata->isoapplet_version = rbuf[0] << 8 | rbuf[1];
  147|     34|		drvdata->isoapplet_features = rbuf[2];
  148|     34|	}
  149|       |
  150|     67|	return SC_SUCCESS;
  ------------------
  |  |   28|     67|#define SC_SUCCESS				0
  ------------------
  151|     71|}
card-isoApplet.c:isoApplet_finish:
   97|     61|{
   98|     61|	struct isoApplet_drv_data *drvdata=DRVDATA(card);
  ------------------
  |  |   59|     61|#define DRVDATA(card)	((struct isoApplet_drv_data *) ((card)->drv_data))
  ------------------
   99|       |
  100|     61|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|     61|	if (drvdata)
  ------------------
  |  Branch (101:6): [True: 61, False: 0]
  ------------------
  102|     61|	{
  103|     61|		free(drvdata);
  104|     61|		card->drv_data=NULL;
  105|     61|	}
  106|     61|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     61|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     61|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     61|	int _ret = r; \
  |  |  |  |  155|     61|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  157|     61|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     61|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     61|	return _ret; \
  |  |  |  |  163|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|     61|}
card-isoApplet.c:isoApplet_card_ctl:
 1037|      5|{
 1038|      5|	int r = 0;
 1039|       |
 1040|      5|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      5|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      5|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      5|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      5|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1041|      5|	switch (cmd)
 1042|      5|	{
 1043|      0|	case SC_CARDCTL_ISOAPPLET_GENERATE_KEY:
  ------------------
  |  Branch (1043:2): [True: 0, False: 5]
  ------------------
 1044|      0|		r = isoApplet_ctl_generate_key(card,
 1045|      0|		                               (sc_cardctl_isoApplet_genkey_t *) ptr);
 1046|      0|		break;
 1047|      0|	case SC_CARDCTL_ISOAPPLET_IMPORT_KEY:
  ------------------
  |  Branch (1047:2): [True: 0, False: 5]
  ------------------
 1048|      0|		r = isoApplet_ctl_import_key(card,
 1049|      0|		                             (sc_cardctl_isoApplet_import_key_t *) ptr);
 1050|      0|		break;
 1051|      5|	default:
  ------------------
  |  Branch (1051:2): [True: 5, False: 0]
  ------------------
 1052|      5|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      5|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1053|      5|	}
 1054|      5|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1055|      5|}
card-isoApplet.c:isoApplet_process_fci:
  405|     65|{
  406|     65|	int r;
  407|     65|	u8 *sa = NULL;
  408|       |
  409|     65|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     65|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     65|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     65|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     65|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  410|       |
  411|     65|	r = iso_ops->process_fci(card, file, buf, buflen);
  412|     65|	LOG_TEST_RET(card->ctx, r, "Error while processing the FCI.");
  ------------------
  |  |  174|     65|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     65|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     65|	int _ret = (r); \
  |  |  |  |  168|     65|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  413|       |	/* Construct the ACL from the sec_attr. */
  414|     65|	if(file->sec_attr && file->sec_attr_len == 8)
  ------------------
  |  Branch (414:5): [True: 45, False: 20]
  |  Branch (414:23): [True: 39, False: 6]
  ------------------
  415|     39|	{
  416|     39|		sa = file->sec_attr;
  417|     39|		if(sa[0] != 0xFF)
  ------------------
  |  Branch (417:6): [True: 13, False: 26]
  ------------------
  418|     13|		{
  419|     13|			LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA,
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|     13|			             "File security attribute does not contain a ACL byte for every operation.");
  421|     13|		}
  422|     26|		if(file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|     26|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (422:6): [True: 11, False: 15]
  ------------------
  423|     11|		{
  424|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_DELETE_SELF, sa[1]);
  ------------------
  |  |  174|     11|#define SC_AC_OP_DELETE_SELF		8
  ------------------
  425|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_LOCK, sa[2]);
  ------------------
  |  |  167|     11|#define SC_AC_OP_LOCK			1
  ------------------
  427|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  428|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_ACTIVATE, sa[3]);
  ------------------
  |  |  186|     11|#define SC_AC_OP_ACTIVATE		20
  ------------------
  429|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  430|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_DEACTIVATE, sa[4]);
  ------------------
  |  |  187|     11|#define SC_AC_OP_DEACTIVATE		21
  ------------------
  431|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_CREATE_DF, sa[5]);
  ------------------
  |  |  194|     11|#define SC_AC_OP_CREATE_DF		28
  ------------------
  433|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_CREATE_EF, sa[6]);
  ------------------
  |  |  193|     11|#define SC_AC_OP_CREATE_EF		27
  ------------------
  435|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|     11|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_DELETE, sa[7]);
  ------------------
  |  |  168|     11|#define SC_AC_OP_DELETE			2
  ------------------
  437|     11|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|     11|		}
  439|     15|		else if(file->type == SC_FILE_TYPE_INTERNAL_EF
  ------------------
  |  |  215|     30|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (439:11): [True: 6, False: 9]
  ------------------
  440|      9|		        || file->type == SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|      9|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (440:14): [True: 3, False: 6]
  ------------------
  441|      9|		{
  442|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_DELETE_SELF, sa[1]);
  ------------------
  |  |  174|      9|#define SC_AC_OP_DELETE_SELF		8
  ------------------
  443|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  444|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_LOCK, sa[2]);
  ------------------
  |  |  167|      9|#define SC_AC_OP_LOCK			1
  ------------------
  445|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_ACTIVATE, sa[3]);
  ------------------
  |  |  186|      9|#define SC_AC_OP_ACTIVATE		20
  ------------------
  447|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  448|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_DEACTIVATE, sa[4]);
  ------------------
  |  |  187|      9|#define SC_AC_OP_DEACTIVATE		21
  ------------------
  449|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_WRITE, sa[5]);
  ------------------
  |  |  190|      9|#define SC_AC_OP_WRITE			24
  ------------------
  451|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  452|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_UPDATE, sa[6]);
  ------------------
  |  |  189|      9|#define SC_AC_OP_UPDATE			23
  ------------------
  453|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  454|      9|			r = isoApplet_add_sa_to_acl(file, SC_AC_OP_READ, sa[7]);
  ------------------
  |  |  188|      9|#define SC_AC_OP_READ			22
  ------------------
  455|      9|			LOG_TEST_RET(card->ctx, r, "Error adding ACL entry.");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  456|      9|		}
  457|       |
  458|     26|	}
  459|       |
  460|     52|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     52|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     52|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     52|	int _ret = r; \
  |  |  |  |  155|     52|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 52, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     52|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 52]
  |  |  |  |  ------------------
  |  |  |  |  157|     52|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     52|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     52|	return _ret; \
  |  |  |  |  163|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  461|     52|}
card-isoApplet.c:isoApplet_add_sa_to_acl:
  368|    140|{
  369|    140|	int r;
  370|       |
  371|    140|	switch(saByte)
  372|    140|	{
  373|     24|	case 0x90:
  ------------------
  |  Branch (373:2): [True: 24, False: 116]
  ------------------
  374|     24|		r = sc_file_add_acl_entry(file, operation, SC_AC_CHV, 1);
  ------------------
  |  |  151|     24|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  375|     24|		if(r < 0)
  ------------------
  |  Branch (375:6): [True: 0, False: 24]
  ------------------
  376|      0|			return r;
  377|     24|		break;
  378|     35|	case 0xFF:
  ------------------
  |  Branch (378:2): [True: 35, False: 105]
  ------------------
  379|     35|		r = sc_file_add_acl_entry(file, operation, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|     35|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		r = sc_file_add_acl_entry(file, operation, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     35|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  380|     35|		if(r < 0)
  ------------------
  |  Branch (380:6): [True: 0, False: 35]
  ------------------
  381|      0|			return r;
  382|     35|		break;
  383|     42|	case 0x00:
  ------------------
  |  Branch (383:2): [True: 42, False: 98]
  ------------------
  384|     42|		r = sc_file_add_acl_entry(file, operation, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     42|#define SC_AC_NONE			0x00000000
  ------------------
              		r = sc_file_add_acl_entry(file, operation, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     42|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  385|     42|		if(r < 0)
  ------------------
  |  Branch (385:6): [True: 0, False: 42]
  ------------------
  386|      0|			return r;
  387|     42|		break;
  388|     42|	default:
  ------------------
  |  Branch (388:2): [True: 39, False: 101]
  ------------------
  389|     39|		r = sc_file_add_acl_entry(file, operation, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|     39|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		r = sc_file_add_acl_entry(file, operation, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     39|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  390|     39|		if(r < 0)
  ------------------
  |  Branch (390:6): [True: 0, False: 39]
  ------------------
  391|      0|			return r;
  392|    140|	}
  393|    140|	return SC_SUCCESS;
  ------------------
  |  |   28|    140|#define SC_SUCCESS				0
  ------------------
  394|    140|}
card-isoApplet.c:isoApplet_card_reader_lock_obtained:
 1241|  3.94k|{
 1242|  3.94k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.94k|#define SC_SUCCESS				0
  ------------------
 1243|       |
 1244|  3.94k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.94k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.94k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.94k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
 1245|       |
 1246|  3.94k|	if (was_reset > 0) {
  ------------------
  |  Branch (1246:6): [True: 0, False: 3.94k]
  ------------------
 1247|      0|		r = iso7816_select_aid(card, isoApplet_aid, sizeof(isoApplet_aid), NULL, NULL);
 1248|      0|	}
 1249|       |
 1250|  3.94k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.94k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.94k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.94k|	int _ret = r; \
  |  |  |  |  155|  3.94k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.94k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.94k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.94k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.94k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.94k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.94k|	return _ret; \
  |  |  |  |  163|  3.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1251|  3.94k|}

sc_get_itacns_driver:
  523|  15.2k|{
  524|  15.2k|	return sc_get_driver();
  525|  15.2k|}
card-itacns.c:sc_get_driver:
  504|  15.2k|{
  505|  15.2k|	if (!default_ops)
  ------------------
  |  Branch (505:6): [True: 1, False: 15.2k]
  ------------------
  506|      1|		default_ops = sc_get_iso7816_driver()->ops;
  507|  15.2k|	itacns_ops = *default_ops;
  508|  15.2k|	itacns_ops.match_card = itacns_match_card;
  509|  15.2k|	itacns_ops.init = itacns_init;
  510|  15.2k|	itacns_ops.finish = itacns_finish;
  511|  15.2k|	itacns_ops.set_security_env = itacns_set_security_env;
  512|  15.2k|	itacns_ops.restore_security_env = itacns_restore_security_env;
  513|  15.2k|	itacns_ops.pin_cmd = itacns_pin_cmd;
  514|  15.2k|	itacns_ops.read_binary = itacns_read_binary;
  515|  15.2k|	itacns_ops.list_files = itacns_list_files;
  516|  15.2k|	itacns_ops.select_file = itacns_select_file;
  517|  15.2k|	itacns_ops.card_ctl = itacns_card_ctl;
  518|  15.2k|	itacns_ops.get_challenge = itacns_get_challenge;
  519|  15.2k|	return &itacns_drv;
  520|  15.2k|}
card-itacns.c:itacns_match_card:
  122|  4.00k|{
  123|  4.00k|	int r = 0;
  124|       |
  125|       |	/* Try table first */
  126|  4.00k|	r = _sc_match_atr(card, itacns_atrs, &card->type);
  127|  4.00k|	if(r >= 0) return 1;
  ------------------
  |  Branch (127:5): [True: 225, False: 3.78k]
  ------------------
  128|       |
  129|  3.78k|	if (itacns_match_cns_card(card)) return 1;
  ------------------
  |  Branch (129:6): [True: 55, False: 3.72k]
  ------------------
  130|  3.72k|	if (itacns_match_cie_card(card)) return 1;
  ------------------
  |  Branch (130:6): [True: 3, False: 3.72k]
  ------------------
  131|       |
  132|       |	/* No card type was matched. */
  133|  3.72k|	return 0;
  134|  3.72k|}
card-itacns.c:itacns_match_cns_card:
   85|  3.78k|{
   86|  3.78k|	u8 manufacturer_code;
   87|  3.78k|	u8 manufacturer_mask;
   88|  3.78k|	u8 fw_major;
   89|       |
   90|  3.78k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (90:6): [True: 3.65k, False: 134]
  ------------------
   91|    134|	    0 != memcmp(card->reader->atr_info.hist_bytes+9, "CNS", 3))
  ------------------
  |  Branch (91:6): [True: 79, False: 55]
  ------------------
   92|  3.72k|		return 0;
   93|       |
   94|     55|	card->type = SC_CARD_TYPE_ITACNS_CNS;
   95|       |
   96|     55|	manufacturer_code = card->reader->atr_info.hist_bytes[2];
   97|     55|	manufacturer_mask = card->reader->atr_info.hist_bytes[3];
   98|     55|	fw_major = card->reader->atr_info.hist_bytes[4];
   99|       |
  100|     55|	if (manufacturer_code == ITACNS_ICMAN_INFINEON &&
  ------------------
  |  |    9|    110|#define ITACNS_ICMAN_INFINEON		0x05
  ------------------
  |  Branch (100:6): [True: 6, False: 49]
  ------------------
  101|      6|	    manufacturer_mask == ITACNS_MASKMAN_IDEMIA &&
  ------------------
  |  |   11|     61|#define ITACNS_MASKMAN_IDEMIA		0x05
  ------------------
  |  Branch (101:6): [True: 5, False: 1]
  ------------------
  102|      5|	    fw_major >= 32) {
  ------------------
  |  Branch (102:6): [True: 1, False: 4]
  ------------------
  103|      1|			card->type = SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021;
  104|      1|	}
  105|       |
  106|     55|	return 1;
  107|  3.78k|}
card-itacns.c:itacns_match_cie_card:
  110|  3.72k|{
  111|  3.72k|	u8 h7_to_h15[] = { 0x02, 'I', 'T', 'I', 'D', 0x20, 0x20, 0x31, 0x80, };
  112|  3.72k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (112:6): [True: 3.65k, False: 79]
  ------------------
  113|     79|	    0 != memcmp(card->reader->atr_info.hist_bytes+6,
  ------------------
  |  Branch (113:6): [True: 76, False: 3]
  ------------------
  114|     79|			h7_to_h15, sizeof h7_to_h15))
  115|  3.72k|		return 0;
  116|       |
  117|      3|	card->type = SC_CARD_TYPE_ITACNS_CIE_V2;
  118|      3|	return 1;
  119|  3.72k|}
card-itacns.c:itacns_init:
  141|    283|{
  142|    283|	unsigned long	flags;
  143|       |
  144|    283|	SC_FUNC_CALLED(card->ctx, 1);
  ------------------
  |  |  148|    283|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    283|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    283|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 283]
  |  |  ------------------
  ------------------
  145|       |
  146|    283|	card->name = "CNS card";
  147|    283|	card->cla = 0x00;
  148|       |
  149|    283|	card->drv_data = calloc(1, sizeof(itacns_drv_data_t));
  150|    283|	if (!card->drv_data)
  ------------------
  |  Branch (150:6): [True: 0, False: 283]
  ------------------
  151|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  152|       |
  153|    283|	if (card->type == SC_CARD_TYPE_ITACNS_CNS)
  ------------------
  |  Branch (153:6): [True: 54, False: 229]
  ------------------
  154|     54|		itacns_init_cns_card(card);
  155|       |
  156|    283|	DRVDATA(card)->ic_manufacturer_code = card->reader->atr_info.hist_bytes[2];
  ------------------
  |  |   64|    283|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  157|    283|	DRVDATA(card)->mask_manufacturer_code = card->reader->atr_info.hist_bytes[3];
  ------------------
  |  |   64|    283|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  158|    283|	card->version.fw_major = card->reader->atr_info.hist_bytes[4];
  159|    283|	card->version.fw_minor = card->reader->atr_info.hist_bytes[5];
  160|       |
  161|       |	/* Set up algorithm info. */
  162|    283|	flags = SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|    283|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  163|    283|		| SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    283|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  164|    283|		| SC_ALGORITHM_RSA_HASHES
  ------------------
  |  |  142|    283|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  165|    283|		;
  166|       |
  167|    283|	if ((card->version.hw_major >= 1 && card->version.hw_minor >= 1) ||
  ------------------
  |  Branch (167:7): [True: 48, False: 235]
  |  Branch (167:38): [True: 41, False: 7]
  ------------------
  168|    242|	    card->type == SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021) {
  ------------------
  |  Branch (168:6): [True: 2, False: 240]
  ------------------
  169|     43|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     43|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  170|     43|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  171|    240|	} else {
  172|    240|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  173|    240|	}
  174|    283|	return SC_SUCCESS;
  ------------------
  |  |   28|    283|#define SC_SUCCESS				0
  ------------------
  175|    283|}
card-itacns.c:itacns_init_cns_card:
   67|     54|{
   68|     54|	if (15 != card->reader->atr_info.hist_bytes_len)
  ------------------
  |  Branch (68:6): [True: 0, False: 54]
  ------------------
   69|      0|		return;
   70|       |
   71|     54|	u8 cns_version = card->reader->atr_info.hist_bytes[12];
   72|     54|	card->version.hw_major = (cns_version >> 4) & 0x0f;
   73|     54|	card->version.hw_minor = cns_version & 0x0f;
   74|       |
   75|       |	/* Warn if version is not 1.X. */
   76|     54|	if (cns_version != 0x10 && cns_version != 0x11) {
  ------------------
  |  Branch (76:6): [True: 51, False: 3]
  |  Branch (76:29): [True: 50, False: 1]
  ------------------
   77|     50|		char version[8];
   78|     50|		snprintf(version, sizeof(version), "%d.%d", card->version.hw_major, card->version.hw_minor);
   79|     50|		sc_log(card->ctx, "CNS card version %s; no official specifications "
  ------------------
  |  |   71|     50|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   80|     50|		       "are published. Proceeding anyway.\n", version);
   81|     50|	}
   82|     54|}
card-itacns.c:itacns_finish:
  178|    283|{
  179|    283|	if(card->drv_data) {
  ------------------
  |  Branch (179:5): [True: 283, False: 0]
  ------------------
  180|    283|		free(card->drv_data);
  181|    283|	}
  182|    283|	return 0;
  183|    283|}
card-itacns.c:itacns_pin_cmd:
  297|     22|{
  298|     22|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     22|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  299|       |	/* Enable backtracking for STIncard cards. */
  300|     22|	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   64|     22|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
              	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   13|     22|#define ITACNS_MASKMAN_STINCARD		0x09
  ------------------
  |  Branch (300:5): [True: 1, False: 21]
  ------------------
  301|      1|		data->pin_reference |= 0x80;
  302|      1|	}
  303|       |
  304|       |	/* FIXME: the following values depend on what pin length was
  305|       |	 * used when creating the BS objects */
  306|     22|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (306:6): [True: 22, False: 0]
  ------------------
  307|     22|		data->pin1.max_length = 8;
  308|     22|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (308:6): [True: 22, False: 0]
  ------------------
  309|     22|		data->pin2.max_length = 8;
  310|     22|	return default_ops->pin_cmd(card, data);
  311|     22|}
card-itacns.c:itacns_read_binary:
  316|    965|{
  317|    965|	size_t already_read = 0;
  318|    965|	size_t requested;
  319|    965|	int r;
  320|  1.09k|	while(1) {
  ------------------
  |  Branch (320:8): [True: 1.09k, Folded]
  ------------------
  321|  1.09k|		requested = count - already_read;
  322|  1.09k|		if(requested > ITACNS_MAX_PAYLOAD)
  ------------------
  |  |   36|  1.09k|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  |  Branch (322:6): [True: 643, False: 454]
  ------------------
  323|    643|			requested = ITACNS_MAX_PAYLOAD;
  ------------------
  |  |   36|    643|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  324|  1.09k|		r = default_ops->read_binary(card, (unsigned)(idx + already_read),
  325|  1.09k|			&buf[already_read], requested, flags);
  326|  1.09k|		if(r < 0)
  ------------------
  |  Branch (326:6): [True: 156, False: 941]
  ------------------
  327|    156|			return r;
  328|    941|		already_read += r;
  329|    941|		if (r == 0 || (size_t)r < requested || already_read == count) {
  ------------------
  |  Branch (329:7): [True: 34, False: 907]
  |  Branch (329:17): [True: 503, False: 404]
  |  Branch (329:42): [True: 272, False: 132]
  ------------------
  330|       |			/* We have finished */
  331|    809|			return (int)already_read;
  332|    809|		}
  333|    941|	}
  334|    965|}
card-itacns.c:itacns_select_file:
  421|  2.36k|{
  422|  2.36k|	int r;
  423|       |
  424|  2.36k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.36k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.36k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.36k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.36k]
  |  |  ------------------
  ------------------
  425|  2.36k|	r = default_ops->select_file(card, in_path, file);
  426|  2.36k|	if (r >= 0 && file) {
  ------------------
  |  Branch (426:6): [True: 719, False: 1.64k]
  |  Branch (426:16): [True: 281, False: 438]
  ------------------
  427|    281|		parse_sec_attr((*file), (*file)->sec_attr,
  428|    281|			(*file)->sec_attr_len);
  429|    281|	}
  430|  2.36k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.36k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.36k|	int _ret = r; \
  |  |  |  |  155|  2.36k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.36k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.36k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.64k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.64k, False: 719]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.36k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.36k|	return _ret; \
  |  |  |  |  163|  2.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  2.36k|}
card-itacns.c:parse_sec_attr:
  403|    281|{
  404|    281|	size_t i;
  405|    281|	const int *idx;
  406|       |
  407|    281|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    281|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (407:8): [True: 6, False: 275]
  ------------------
  408|       |
  409|       |	/* acl defaults to 0xFF if unspecified */
  410|  2.81k|	for (i = 0; i < 9; i++) {
  ------------------
  |  Branch (410:14): [True: 2.52k, False: 281]
  ------------------
  411|  2.52k|		if (idx[i] != -1) {
  ------------------
  |  Branch (411:7): [True: 1.96k, False: 562]
  ------------------
  412|  1.96k|			add_acl_entry(file, idx[i],
  413|  1.96k|				(u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (413:10): [True: 174, False: 1.79k]
  ------------------
  414|  1.96k|		}
  415|  2.52k|	}
  416|    281|}
card-itacns.c:add_acl_entry:
  350|  1.96k|{
  351|  1.96k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.96k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  352|       |
  353|  1.96k|	switch (byte) {
  354|     43|	case 0x00:
  ------------------
  |  Branch (354:2): [True: 43, False: 1.92k]
  ------------------
  355|     43|		method = SC_AC_NONE;
  ------------------
  |  |  150|     43|#define SC_AC_NONE			0x00000000
  ------------------
  356|     43|		break;
  357|  1.79k|	case 0xFF:
  ------------------
  |  Branch (357:2): [True: 1.79k, False: 171]
  ------------------
  358|  1.81k|	case 0x66:
  ------------------
  |  Branch (358:2): [True: 22, False: 1.94k]
  ------------------
  359|  1.81k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.81k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  360|  1.81k|		break;
  361|    106|	default:
  ------------------
  |  Branch (361:2): [True: 106, False: 1.86k]
  ------------------
  362|    106|		if (byte > 0x1F) {
  ------------------
  |  Branch (362:7): [True: 69, False: 37]
  ------------------
  363|     69|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     69|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  364|     69|		} else {
  365|     37|			method = SC_AC_CHV;
  ------------------
  |  |  151|     37|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  366|     37|			key_ref = byte;
  367|     37|		}
  368|    106|		break;
  369|  1.96k|	}
  370|  1.96k|	sc_file_add_acl_entry(file, op, method, key_ref);
  371|  1.96k|}
card-itacns.c:itacns_card_ctl:
  486|     22|{
  487|     22|	switch (cmd) {
  ------------------
  |  Branch (487:10): [True: 22, False: 0]
  ------------------
  488|     22|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (488:3): [True: 22, False: 0]
  ------------------
  489|     22|		return itacns_get_serialnr(card, ptr);
  490|     22|	}
  491|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  492|     22|}
card-itacns.c:itacns_get_serialnr:
  434|     22|{
  435|     22|	sc_path_t path;
  436|     22|	sc_file_t *file;
  437|     22|	size_t    len;
  438|     22|	int r;
  439|     22|	u8        rbuf[256];
  440|       |
  441|     22|	if (!serial) return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  |  Branch (441:6): [True: 0, False: 22]
  ------------------
  442|       |
  443|       |	/* see if we have cached serial number */
  444|     22|	if (card->serialnr.len) {
  ------------------
  |  Branch (444:6): [True: 0, False: 22]
  ------------------
  445|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  446|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  447|      0|	}
  448|       |
  449|     22|	sc_log(card->ctx, "Reading EF_IDCarta.\n");
  ------------------
  |  |   71|     22|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  450|       |
  451|     22|	sc_format_path("3F0010001003", &path);
  452|       |
  453|     22|	r = sc_select_file(card, &path, &file);
  454|     22|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  |  Branch (454:6): [True: 7, False: 15]
  ------------------
  455|      7|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      7|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  456|      7|	}
  457|     15|	len = file->size;
  458|     15|	sc_file_free(file);
  459|       |
  460|       |	//Returned file->size should be 16.
  461|       |	//We choose to not consider it as critical, because some cards
  462|       |	//do not return FCI/FCP templates that include the file size.
  463|       |	//Notify abnormal length anyway.
  464|     15|	if (len != 16) {
  ------------------
  |  Branch (464:6): [True: 14, False: 1]
  ------------------
  465|     14|		sc_log(card->ctx,
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|     14|				"Unexpected file length of EF_IDCarta (%lu)\n",
  467|     14|				(unsigned long) len);
  468|     14|	}
  469|       |
  470|     15|	r = sc_read_binary(card, 0, rbuf, 256, 0);
  471|     15|	if ( r != 16 ) {
  ------------------
  |  Branch (471:7): [True: 14, False: 1]
  ------------------
  472|     14|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     14|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  473|     14|	}
  474|       |
  475|       |	/* cache serial number */
  476|      1|	memcpy(card->serialnr.value, rbuf, 16);
  477|      1|	card->serialnr.len = 16;
  478|       |	/* copy and return serial number */
  479|      1|	memcpy(serial, &card->serialnr, sizeof(*serial));
  480|       |
  481|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  482|     15|}

jpki_select_ap:
   46|  2.73k|{
   47|  2.73k|	int rc;
   48|  2.73k|	sc_path_t path;
   49|       |
   50|  2.73k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.73k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.73k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.73k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.73k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   51|       |
   52|       |	/* Select JPKI application */
   53|  2.73k|	sc_format_path(AID_JPKI, &path);
  ------------------
  |  |   27|  2.73k|#define AID_JPKI "D392f000260100000001"
  ------------------
   54|  2.73k|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.73k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   55|  2.73k|	rc = sc_select_file(card, &path, NULL);
   56|  2.73k|	LOG_TEST_RET(card->ctx, rc, "select JPKI AP failed");
  ------------------
  |  |  174|  2.73k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.73k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.73k|	int _ret = (r); \
  |  |  |  |  168|  2.73k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.65k, False: 83]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.65k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.65k|		return _ret; \
  |  |  |  |  172|  2.65k|	} \
  |  |  |  |  173|  2.73k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 83]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   57|       |
   58|     83|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     83|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     83|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     83|	int _ret = r; \
  |  |  |  |  155|     83|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 83, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 83]
  |  |  |  |  ------------------
  |  |  |  |  157|     83|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     83|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     83|	return _ret; \
  |  |  |  |  163|     83|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|     83|}
sc_get_jpki_driver:
  382|  15.2k|{
  383|  15.2k|	return sc_get_driver();
  384|  15.2k|}
card-jpki.c:sc_get_driver:
  363|  15.2k|{
  364|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  365|       |
  366|  15.2k|	jpki_ops = *iso_drv->ops;
  367|  15.2k|	jpki_ops.match_card = jpki_match_card;
  368|  15.2k|	jpki_ops.init = jpki_init;
  369|  15.2k|	jpki_ops.finish = jpki_finish;
  370|  15.2k|	jpki_ops.select_file = jpki_select_file;
  371|  15.2k|	jpki_ops.pin_cmd = jpki_pin_cmd;
  372|  15.2k|	jpki_ops.set_security_env = jpki_set_security_env;
  373|  15.2k|	jpki_ops.compute_signature = jpki_compute_signature;
  374|  15.2k|	jpki_ops.card_reader_lock_obtained = jpki_card_reader_lock_obtained;
  375|  15.2k|	jpki_ops.logout = jpki_logout;
  376|       |
  377|  15.2k|	return &jpki_drv;
  378|  15.2k|}
card-jpki.c:jpki_match_card:
   63|  2.69k|{
   64|  2.69k|	int i, rc;
   65|       |
   66|  2.69k|	i = _sc_match_atr(card, jpki_atrs, &card->type);
   67|  2.69k|	if (i >= 0) {
  ------------------
  |  Branch (67:6): [True: 2, False: 2.68k]
  ------------------
   68|      2|		return 1;
   69|      2|	}
   70|       |
   71|  2.68k|	rc = jpki_select_ap(card);
   72|  2.68k|	if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|  2.68k|#define SC_SUCCESS				0
  ------------------
  |  Branch (72:6): [True: 47, False: 2.64k]
  ------------------
   73|     47|		card->type = SC_CARD_TYPE_JPKI_BASE;
   74|     47|		return 1;
   75|     47|	}
   76|  2.64k|	return 0;
   77|  2.68k|}
card-jpki.c:jpki_init:
   95|     49|{
   96|     49|	struct jpki_private_data *drvdata;
   97|     49|	sc_file_t *mf;
   98|     49|	int flags;
   99|       |
  100|     49|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     49|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     49|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     49|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     49|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|       |
  102|     49|	drvdata = malloc(sizeof (struct jpki_private_data));
  103|     49|	if (!drvdata)
  ------------------
  |  Branch (103:6): [True: 0, False: 49]
  ------------------
  104|     49|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  105|       |
  106|     49|	memset(drvdata, 0, sizeof (struct jpki_private_data));
  107|       |
  108|       |	/* create virtual MF */
  109|     49|	mf = sc_file_new();
  110|     49|	if (!mf) {
  ------------------
  |  Branch (110:6): [True: 0, False: 49]
  ------------------
  111|      0|		free(drvdata);
  112|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  113|      0|	}
  114|     49|	sc_format_path("3f00", &mf->path);
  115|     49|	mf->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     49|#define SC_FILE_TYPE_DF			0x04
  ------------------
  116|     49|	mf->shareable = 0;
  117|     49|	mf->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     49|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  118|     49|	mf->size = 0;
  119|     49|	mf->id = 0x3f00;
  120|     49|	mf->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     49|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  121|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  166|     49|#define SC_AC_OP_SELECT			0
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  150|     49|#define SC_AC_NONE			0x00000000
  ------------------
  122|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  172|     49|#define SC_AC_OP_LIST_FILES		6
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  150|     49|#define SC_AC_NONE			0x00000000
  ------------------
  123|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  167|     49|#define SC_AC_OP_LOCK			1
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  124|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  168|     49|#define SC_AC_OP_DELETE			2
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  125|     49|	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  169|     49|#define SC_AC_OP_CREATE			3
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     49|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  126|     49|	drvdata->mf = mf;
  127|     49|	drvdata->selected = SELECT_MF;
  ------------------
  |  |   24|     49|#define SELECT_MF 0
  ------------------
  128|       |
  129|     49|	card->name = "jpki";
  130|     49|	card->drv_data = drvdata;
  131|       |
  132|     49|	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  133|     49|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  133|     49|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  134|       |
  135|     49|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  136|     49|}
card-jpki.c:jpki_finish:
   81|     49|{
   82|     49|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     49|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   83|       |
   84|     49|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     49|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     49|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     49|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     49|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|     49|	if (drvdata) {
  ------------------
  |  Branch (85:6): [True: 49, False: 0]
  ------------------
   86|     49|		sc_file_free(drvdata->mf);
   87|     49|		free(drvdata);
   88|     49|		card->drv_data = NULL;
   89|     49|	}
   90|     49|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|     49|}
card-jpki.c:jpki_select_file:
  141|  3.03k|{
  142|  3.03k|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|  3.03k|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  143|  3.03k|	int rc;
  144|  3.03k|	sc_apdu_t apdu;
  145|  3.03k|	struct sc_file *file = NULL;
  146|       |
  147|  3.03k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.03k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.03k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|  3.03k|	sc_log(card->ctx, "jpki_select_file: path=%s, len=%zu", sc_print_path(path), path->len);
  ------------------
  |  |   71|  3.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  149|  3.03k|	if (path->len == 2 && memcmp(path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (149:6): [True: 93, False: 2.94k]
  |  Branch (149:24): [True: 0, False: 93]
  ------------------
  150|      0|		drvdata->selected = SELECT_MF;
  ------------------
  |  |   24|      0|#define SELECT_MF 0
  ------------------
  151|      0|		if (file_out) {
  ------------------
  |  Branch (151:7): [True: 0, False: 0]
  ------------------
  152|      0|			sc_file_dup(file_out, drvdata->mf);
  153|      0|			if (*file_out == NULL) {
  ------------------
  |  Branch (153:8): [True: 0, False: 0]
  ------------------
  154|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|      0|			}
  156|      0|		}
  157|      0|		return 0;
  158|      0|	}
  159|       |
  160|  3.03k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  293|  3.03k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  161|  3.03k|	switch (path->type) {
  162|     88|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|     88|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (162:2): [True: 88, False: 2.94k]
  ------------------
  163|     88|		apdu.p1 = 2;
  164|     88|		break;
  165|  2.80k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  2.80k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (165:2): [True: 2.80k, False: 232]
  ------------------
  166|  2.80k|		apdu.p1 = 4;
  167|  2.80k|		break;
  168|    144|	default:
  ------------------
  |  Branch (168:2): [True: 144, False: 2.89k]
  ------------------
  169|    144|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    144|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    144|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    144|	int _ret = r; \
  |  |  |  |  155|    144|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 144, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    144|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    144|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 144, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    144|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    144|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    144|	return _ret; \
  |  |  |  |  163|    144|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|  3.03k|	}
  171|  2.89k|	apdu.p2 = 0x0C;
  172|  2.89k|	apdu.data = path->value;
  173|  2.89k|	apdu.datalen = path->len;
  174|  2.89k|	apdu.lc = path->len;
  175|       |
  176|  2.89k|	rc = sc_transmit_apdu(card, &apdu);
  177|  2.89k|	LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|  2.89k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.89k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.89k|	int _ret = (r); \
  |  |  |  |  168|  2.89k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  169|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     22|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     22|		return _ret; \
  |  |  |  |  172|     22|	} \
  |  |  |  |  173|  2.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|  2.87k|	rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  179|  2.87k|	LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|  2.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.87k|	int _ret = (r); \
  |  |  |  |  168|  2.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.68k, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.68k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.68k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.68k|		return _ret; \
  |  |  |  |  172|  2.68k|	} \
  |  |  |  |  173|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 181]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  180|    181|	if (!file_out) {
  ------------------
  |  Branch (180:6): [True: 181, False: 0]
  ------------------
  181|    181|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    181|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    181|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    181|	int _ret = r; \
  |  |  |  |  155|    181|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 181, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    181|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    181|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    181|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    181|	return _ret; \
  |  |  |  |  163|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|    181|	}
  183|       |
  184|       |	/* read certificate file size */
  185|      0|	if (path->len == 2 && (
  ------------------
  |  Branch (185:6): [True: 0, False: 0]
  ------------------
  186|      0|		    memcmp(path->value, "\x00\x0A", 2) == 0 ||
  ------------------
  |  Branch (186:7): [True: 0, False: 0]
  ------------------
  187|      0|		    memcmp(path->value, "\x00\x01", 2) == 0 ||
  ------------------
  |  Branch (187:7): [True: 0, False: 0]
  ------------------
  188|      0|		    memcmp(path->value, "\x00\x0B", 2) == 0 ||
  ------------------
  |  Branch (188:7): [True: 0, False: 0]
  ------------------
  189|      0|		    memcmp(path->value, "\x00\x02", 2) == 0 )
  ------------------
  |  Branch (189:7): [True: 0, False: 0]
  ------------------
  190|      0|		) {
  191|      0|		u8 buf[4];
  192|      0|		rc = sc_read_binary(card, 0, buf, 4, 0);
  193|      0|		LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|      0|		if (rc < 4)
  ------------------
  |  Branch (194:7): [True: 0, False: 0]
  ------------------
  195|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Received data too short");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|      0|		file = sc_file_new();
  197|      0|		if (!file) {
  ------------------
  |  Branch (197:7): [True: 0, False: 0]
  ------------------
  198|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|      0|		}
  200|      0|		file->path = *path;
  201|      0|		file->size = (buf[2] << 8 | buf[3]) + 4;
  202|      0|		*file_out = file;
  203|      0|	}
  204|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      0|}
card-jpki.c:jpki_pin_cmd:
  209|     76|{
  210|     76|	int rc;
  211|     76|	sc_path_t path;
  212|     76|	sc_apdu_t apdu;
  213|     76|	struct jpki_private_data *priv = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     76|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  214|     76|	int max_tries = 0;
  215|       |
  216|     76|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     76|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     76|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     76|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     76|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|       |
  218|     76|	switch (data->pin_reference) {
  219|     49|	case 1:
  ------------------
  |  Branch (219:2): [True: 49, False: 27]
  ------------------
  220|     49|		sc_format_path(JPKI_AUTH_PIN, &path);
  ------------------
  |  |   29|     49|#define JPKI_AUTH_PIN "0018"
  ------------------
  221|     49|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     49|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  222|     49|		rc = sc_select_file(card, &path, NULL);
  223|     49|		max_tries = JPKI_AUTH_PIN_MAX_TRIES;
  ------------------
  |  |   30|     49|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  224|     49|		break;
  225|     27|	case 2:
  ------------------
  |  Branch (225:2): [True: 27, False: 49]
  ------------------
  226|     27|		sc_format_path(JPKI_SIGN_PIN, &path);
  ------------------
  |  |   33|     27|#define JPKI_SIGN_PIN "001B"
  ------------------
  227|     27|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     27|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  228|     27|		rc = sc_select_file(card, &path, NULL);
  229|     27|		max_tries = JPKI_SIGN_PIN_MAX_TRIES;
  ------------------
  |  |   34|     27|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  230|     27|		break;
  231|      0|	default:
  ------------------
  |  Branch (231:2): [True: 0, False: 76]
  ------------------
  232|      0|		sc_log(card->ctx, "Unknown PIN reference: %d", data->pin_reference);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  233|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     76|	}
  235|     76|	LOG_TEST_RET(card->ctx, rc, "SELECT_FILE error");
  ------------------
  |  |  174|     76|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     76|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     76|	int _ret = (r); \
  |  |  |  |  168|     76|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|     67|	switch (data->cmd) {
  238|     12|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     12|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (238:2): [True: 12, False: 55]
  ------------------
  239|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
  240|     12|		if (data->pin1.len == 0 && !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (240:7): [True: 0, False: 12]
  |  Branch (240:30): [True: 0, False: 0]
  ------------------
  241|     12|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  242|     12|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0x20, 0x00, 0x80);
  ------------------
  |  |  302|     12|#define SC_APDU_CASE_3			0x23
  ------------------
  243|     12|		apdu.data = data->pin1.data;
  244|     12|		apdu.datalen = data->pin1.len;
  245|     12|		apdu.lc = data->pin1.len;
  246|     12|		rc = sc_transmit_apdu(card, &apdu);
  247|     12|		LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  248|     11|		rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  249|     11|		if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  |  Branch (249:7): [True: 10, False: 1]
  ------------------
  250|     10|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     10|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  251|     10|			data->pin1.tries_left = max_tries;
  252|     10|		} else {
  253|      1|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      1|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
  254|      1|			data->pin1.tries_left = apdu.sw2 & 0xF;
  255|      1|		}
  256|     11|		priv->logged_in = data->pin1.logged_in;
  257|     11|		LOG_TEST_RET(card->ctx, rc, "VERIFY failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  258|     10|		break;
  259|     55|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|     55|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (259:2): [True: 55, False: 12]
  ------------------
  260|     55|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0x00, 0x80);
  ------------------
  |  |  291|     55|#define SC_APDU_CASE_1			0x01
  ------------------
  261|     55|		rc = sc_transmit_apdu(card, &apdu);
  262|     55|		LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|     55|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     55|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     55|	int _ret = (r); \
  |  |  |  |  168|     55|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 52]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 52]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|     52|		if (apdu.sw1 != 0x63) {
  ------------------
  |  Branch (263:7): [True: 17, False: 35]
  ------------------
  264|     17|			sc_log(card->ctx, "VERIFY GET_INFO error");
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  265|     17|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|     17|		}
  267|     35|		data->pin1.logged_in = priv->logged_in;
  268|     35|		data->pin1.tries_left = apdu.sw2 & 0xF;
  269|     35|		break;
  270|      0|	default:
  ------------------
  |  Branch (270:2): [True: 0, False: 67]
  ------------------
  271|      0|		sc_log(card->ctx, "Card does not support PIN command: %d", data->cmd);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  272|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|     67|	}
  274|       |
  275|     45|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  276|     45|}
card-jpki.c:jpki_set_security_env:
  281|     12|{
  282|     12|	int rc;
  283|     12|	sc_path_t path;
  284|       |
  285|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  286|     12|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  287|     12|			env->flags, env->operation, env->algorithm, env->algorithm_flags, env->algorithm_ref,
  288|     12|			env->key_ref[0], env->key_ref_len);
  289|       |
  290|     12|	switch (env->operation) {
  291|     12|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     12|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (291:2): [True: 12, False: 0]
  ------------------
  292|     12|		break;
  293|      0|	default:
  ------------------
  |  Branch (293:2): [True: 0, False: 12]
  ------------------
  294|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|     12|	}
  296|       |
  297|     12|	switch (env->key_ref[0]) {
  298|     12|	case 1:
  ------------------
  |  Branch (298:2): [True: 12, False: 0]
  ------------------
  299|     12|		sc_format_path(JPKI_AUTH_KEY, &path);
  ------------------
  |  |   28|     12|#define JPKI_AUTH_KEY "0017"
  ------------------
  300|     12|		break;
  301|      0|	case 2:
  ------------------
  |  Branch (301:2): [True: 0, False: 12]
  ------------------
  302|      0|		sc_format_path(JPKI_SIGN_KEY, &path);
  ------------------
  |  |   32|      0|#define JPKI_SIGN_KEY "001A"
  ------------------
  303|      0|		break;
  304|      0|	default:
  ------------------
  |  Branch (304:2): [True: 0, False: 12]
  ------------------
  305|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|     12|	}
  307|     12|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     12|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  308|     12|	rc = sc_select_file(card, &path, NULL);
  309|     12|	LOG_TEST_RET(card->ctx, rc, "select key failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  310|       |
  311|     11|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|     11|}
card-jpki.c:jpki_compute_signature:
  317|     11|{
  318|     11|	int rc;
  319|     11|	sc_apdu_t apdu;
  320|     11|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
  321|       |
  322|     11|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     11|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     11|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     11|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     11|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|     11|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x00, 0x80);
  ------------------
  |  |  294|     11|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  325|     11|	apdu.cla = 0x80;
  326|     11|	apdu.data = data;
  327|     11|	apdu.datalen = datalen;
  328|     11|	apdu.lc = datalen;
  329|     11|	apdu.resp = resp;
  330|     11|	apdu.resplen = sizeof(resp);
  331|     11|	apdu.le = 0;
  332|     11|	rc = sc_transmit_apdu(card, &apdu);
  333|     11|	LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  334|     10|	rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  335|     10|	LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|      7|	if (apdu.resplen > outlen) {
  ------------------
  |  Branch (336:6): [True: 0, False: 7]
  ------------------
  337|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  338|      0|	}
  339|      7|	memcpy(out, resp, apdu.resplen);
  340|      7|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      4|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      4|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      4|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|      7|}
card-jpki.c:jpki_card_reader_lock_obtained:
  344|  2.76k|{
  345|  2.76k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.76k|#define SC_SUCCESS				0
  ------------------
  346|       |
  347|  2.76k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.76k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.76k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.76k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.76k]
  |  |  ------------------
  ------------------
  348|       |
  349|  2.76k|	if (was_reset > 0) {
  ------------------
  |  Branch (349:6): [True: 0, False: 2.76k]
  ------------------
  350|      0|		r = jpki_select_ap(card);
  351|      0|	}
  352|       |
  353|  2.76k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.76k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.76k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.76k|	int _ret = r; \
  |  |  |  |  155|  2.76k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.76k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.76k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.76k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.76k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.76k|	return _ret; \
  |  |  |  |  163|  2.76k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  354|  2.76k|}

sc_get_lteid_driver:
  555|  15.2k|{
  556|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  557|       |
  558|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (558:6): [True: 1, False: 15.2k]
  ------------------
  559|      1|		iso_ops = iso_drv->ops;
  560|       |
  561|  15.2k|	lteid_ops = *iso_ops;
  562|  15.2k|	lteid_ops.init = lteid_init;
  563|  15.2k|	lteid_ops.finish = lteid_finish;
  564|  15.2k|	lteid_ops.set_security_env = lteid_set_security_env;
  565|  15.2k|	lteid_ops.compute_signature = lteid_compute_signature;
  566|  15.2k|	lteid_ops.pin_cmd = lteid_pin_cmd;
  567|  15.2k|	lteid_ops.logout = lteid_logout;
  568|  15.2k|	lteid_ops.process_fci = lteid_process_fci;
  569|       |
  570|  15.2k|	return &lteid_drv;
  571|  15.2k|}

sc_get_masktech_driver:
  374|  15.2k|{
  375|  15.2k|	return sc_get_driver();
  376|  15.2k|}
card-masktech.c:sc_get_driver:
  355|  15.2k|{
  356|       |
  357|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (357:6): [True: 1, False: 15.2k]
  ------------------
  358|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  359|       |
  360|  15.2k|	masktech_ops = *iso_ops;
  361|       |
  362|  15.2k|	masktech_ops.match_card = masktech_match_card;
  363|  15.2k|	masktech_ops.init = masktech_init;
  364|  15.2k|	masktech_ops.finish = masktech_finish;
  365|  15.2k|	masktech_ops.set_security_env = masktech_set_security_env;
  366|  15.2k|	masktech_ops.compute_signature = masktech_compute_signature;
  367|  15.2k|	masktech_ops.decipher = masktech_decipher;
  368|  15.2k|	masktech_ops.pin_cmd = masktech_pin_cmd;
  369|  15.2k|	masktech_ops.card_ctl = masktech_card_ctl;
  370|  15.2k|	return &masktech_drv;
  371|  15.2k|}
card-masktech.c:masktech_match_card:
   62|  8.10k|{
   63|       |	/* check if the ATR is in the known ATR */
   64|  8.10k|	if (_sc_match_atr(card, masktech_atrs, &card->type) < 0)
  ------------------
  |  Branch (64:6): [True: 8.07k, False: 34]
  ------------------
   65|  8.07k|		return 0;
   66|       |
   67|     34|	return 1;
   68|  8.10k|}
card-masktech.c:masktech_init:
   71|     34|{
   72|     34|	unsigned long flags;
   73|     34|	struct masktech_private_data *data;
   74|       |
   75|     34|	sc_log(card->ctx,  "masktech_init()\n");
  ------------------
  |  |   71|     34|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   76|       |
   77|       |	/* private data kept during the live of the driver */
   78|     34|	if (!(data = (struct masktech_private_data *) malloc(sizeof(*data))))
  ------------------
  |  Branch (78:6): [True: 0, False: 34]
  ------------------
   79|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
   80|     34|	card->drv_data = data;
   81|       |
   82|       |	/* supported RSA keys and how padding is done */
   83|     34|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|     34|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     34|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     34|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     34|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   84|     34|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
   85|     34|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
   86|     34|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
   87|     34|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     34|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
   88|     34|	return SC_SUCCESS;
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
   89|     34|}
card-masktech.c:masktech_finish:
   93|     34|{
   94|       |	/* free the private data */
   95|     34|	if (card->drv_data) {
  ------------------
  |  Branch (95:6): [True: 34, False: 0]
  ------------------
   96|     34|		free(card->drv_data);
   97|       |		card->drv_data = NULL;
   98|     34|	}
   99|     34|	return 0;
  100|     34|}
card-masktech.c:masktech_pin_cmd:
  283|     16|{
  284|     16|	int       rv;
  285|     16|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     16|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     16|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     16|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16]
  |  |  ------------------
  ------------------
  286|       |
  287|     16|	switch(data->cmd)
  288|     16|	{
  289|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (289:2): [True: 0, False: 16]
  ------------------
  290|      0|		rv = masktech_pin_unblock(card, data);
  291|      0|		break;
  292|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (292:2): [True: 0, False: 16]
  ------------------
  293|      0|		rv = masktech_pin_change(card, data);
  294|      0|		break;
  295|     16|	default:
  ------------------
  |  Branch (295:2): [True: 16, False: 0]
  ------------------
  296|     16|		rv = iso_ops->pin_cmd(card, data);
  297|     16|		break;
  298|     16|	}
  299|     16|	return rv;
  300|       |
  301|       |
  302|     16|}
card-masktech.c:masktech_card_ctl:
  344|     30|{
  345|     30|	sc_log(card->ctx,  "masktech_card_ctl()\n");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  346|     30|	switch (cmd) {
  347|     30|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (347:3): [True: 30, False: 0]
  ------------------
  348|     30|			return masktech_get_serialnr(card, (sc_serial_number_t *) ptr);
  349|      0|		default:
  ------------------
  |  Branch (349:3): [True: 0, False: 30]
  ------------------
  350|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  351|     30|	}
  352|     30|}
card-masktech.c:masktech_get_serialnr:
  305|     30|{
  306|     30|	struct sc_apdu apdu;
  307|     30|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE-2];
  308|     30|	int rv;
  309|       |
  310|     30|	if (!serial)
  ------------------
  |  Branch (310:6): [True: 0, False: 30]
  ------------------
  311|     30|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|       |
  313|       |	/* Get smart card serial number */
  314|     30|	card->cla = 0x80;
  315|     30|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x08, 0x00, 0x00);
  ------------------
  |  |  292|     30|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  316|     30|	apdu.resplen = sizeof(apdu_resp);
  317|     30|	apdu.resp = apdu_resp;
  318|       |
  319|     30|	rv = sc_transmit_apdu(card, &apdu);
  320|     30|	card->cla = 0x00;
  321|       |
  322|     30|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     30|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     30|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     30|	int _ret = (r); \
  |  |  |  |  168|     30|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|     28|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (324:6): [True: 10, False: 18]
  |  Branch (324:26): [True: 4, False: 14]
  ------------------
  325|     14|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     14|#define SC_ERROR_INTERNAL			-1400
  ------------------
  326|       |
  327|     14|	if (SC_MAX_SERIALNR < apdu.resplen)
  ------------------
  |  |  372|     14|#define SC_MAX_SERIALNR         32
  ------------------
  |  Branch (327:6): [True: 3, False: 11]
  ------------------
  328|      3|	{
  329|      3|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|      3|	}
  331|       |	/* cache serial number */
  332|     11|	card->serialnr.len = apdu.resplen;
  333|     11|	memcpy(card->serialnr.value, apdu.resp, card->serialnr.len);
  334|       |
  335|       |	/* copy and return serial number */
  336|     11|	if (serial)
  ------------------
  |  Branch (336:6): [True: 11, False: 0]
  ------------------
  337|     11|		memcpy(serial, &card->serialnr, sizeof(*serial));
  338|       |
  339|     11|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  340|     11|}

sc_get_mcrd_driver:
 1066|  15.2k|{
 1067|  15.2k|	return sc_get_driver();
 1068|  15.2k|}
card-mcrd.c:sc_get_driver:
 1047|  15.2k|{
 1048|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1049|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1049:6): [True: 1, False: 15.2k]
  ------------------
 1050|      1|		iso_ops = iso_drv->ops;
 1051|       |
 1052|  15.2k|	mcrd_ops = *iso_drv->ops;
 1053|  15.2k|	mcrd_ops.match_card = mcrd_match_card;
 1054|  15.2k|	mcrd_ops.init = mcrd_init;
 1055|  15.2k|	mcrd_ops.finish = mcrd_finish;
 1056|  15.2k|	mcrd_ops.select_file = mcrd_select_file;
 1057|  15.2k|	mcrd_ops.set_security_env = mcrd_set_security_env;
 1058|  15.2k|	mcrd_ops.compute_signature = mcrd_compute_signature;
 1059|  15.2k|	mcrd_ops.pin_cmd = mcrd_pin_cmd;
 1060|  15.2k|	mcrd_ops.logout = mcrd_logout;
 1061|       |
 1062|  15.2k|	return &mcrd_drv;
 1063|  15.2k|}
card-mcrd.c:mcrd_match_card:
  191|  14.7k|{
  192|  14.7k|	int i = 0;
  193|       |
  194|  14.7k|	i = _sc_match_atr(card, mcrd_atrs, &card->type);
  195|  14.7k|	if (i >= 0) {
  ------------------
  |  Branch (195:6): [True: 0, False: 14.7k]
  ------------------
  196|      0|		card->name = mcrd_atrs[i].name;
  197|      0|		return 1;
  198|      0|	}
  199|       |
  200|  14.7k|	return 0;
  201|  14.7k|}

sc_get_muscle_driver:
  903|  15.2k|{
  904|  15.2k|	return sc_get_driver();
  905|  15.2k|}
card-muscle.c:sc_get_driver:
  871|  15.2k|{
  872|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  873|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (873:6): [True: 1, False: 15.2k]
  ------------------
  874|      1|		iso_ops = iso_drv->ops;
  875|       |
  876|  15.2k|	muscle_ops = *iso_drv->ops;
  877|  15.2k|	muscle_ops.check_sw = muscle_check_sw;
  878|  15.2k|	muscle_ops.pin_cmd = muscle_pin_cmd;
  879|  15.2k|	muscle_ops.match_card = muscle_match_card;
  880|  15.2k|	muscle_ops.init = muscle_init;
  881|  15.2k|	muscle_ops.finish = muscle_finish;
  882|       |
  883|  15.2k|	muscle_ops.get_challenge = muscle_get_challenge;
  884|       |
  885|  15.2k|	muscle_ops.set_security_env = muscle_set_security_env;
  886|  15.2k|	muscle_ops.restore_security_env = muscle_restore_security_env;
  887|  15.2k|	muscle_ops.compute_signature = muscle_compute_signature;
  888|  15.2k|	muscle_ops.decipher = muscle_decipher;
  889|  15.2k|	muscle_ops.card_ctl = muscle_card_ctl;
  890|  15.2k|	muscle_ops.read_binary = muscle_read_binary;
  891|  15.2k|	muscle_ops.update_binary = muscle_update_binary;
  892|  15.2k|	muscle_ops.create_file = muscle_create_file;
  893|  15.2k|	muscle_ops.select_file = muscle_select_file;
  894|  15.2k|	muscle_ops.delete_file = muscle_delete_file;
  895|  15.2k|	muscle_ops.list_files = muscle_list_files;
  896|  15.2k|	muscle_ops.card_reader_lock_obtained = muscle_card_reader_lock_obtained;
  897|  15.2k|	muscle_ops.logout = muscle_logout;
  898|       |
  899|  15.2k|	return &muscle_drv;
  900|  15.2k|}
card-muscle.c:muscle_check_sw:
  809|  30.6k|static int muscle_check_sw(sc_card_t * card, unsigned int sw1, unsigned int sw2) {
  810|  30.6k|	if(sw1 == 0x9C) {
  ------------------
  |  Branch (810:5): [True: 157, False: 30.5k]
  ------------------
  811|    157|		switch(sw2) {
  ------------------
  |  Branch (811:10): [True: 146, False: 11]
  ------------------
  812|     20|			case 0x01: /* SW_NO_MEMORY_LEFT */
  ------------------
  |  Branch (812:4): [True: 20, False: 137]
  ------------------
  813|     20|				return SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|     20|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  814|     10|			case 0x02: /* SW_AUTH_FAILED */
  ------------------
  |  Branch (814:4): [True: 10, False: 147]
  ------------------
  815|     10|				return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     10|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  816|     10|			case 0x03: /* SW_OPERATION_NOT_ALLOWED */
  ------------------
  |  Branch (816:4): [True: 10, False: 147]
  ------------------
  817|     10|				return SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     10|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  818|     12|			case 0x05: /* SW_UNSUPPORTED_FEATURE */
  ------------------
  |  Branch (818:4): [True: 12, False: 145]
  ------------------
  819|     12|				return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|     12|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  820|     10|			case 0x06: /* SW_UNAUTHORIZED */
  ------------------
  |  Branch (820:4): [True: 10, False: 147]
  ------------------
  821|     10|				return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     10|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  822|     11|			case 0x07: /* SW_OBJECT_NOT_FOUND */
  ------------------
  |  Branch (822:4): [True: 11, False: 146]
  ------------------
  823|     11|				return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     11|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  824|     10|			case 0x08: /* SW_OBJECT_EXISTS */
  ------------------
  |  Branch (824:4): [True: 10, False: 147]
  ------------------
  825|     10|				return SC_ERROR_FILE_ALREADY_EXISTS;
  ------------------
  |  |   65|     10|#define SC_ERROR_FILE_ALREADY_EXISTS		-1215
  ------------------
  826|     11|			case 0x09: /* SW_INCORRECT_ALG */
  ------------------
  |  Branch (826:4): [True: 11, False: 146]
  ------------------
  827|     11|				return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|     11|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  828|     10|			case 0x0B: /* SW_SIGNATURE_INVALID */
  ------------------
  |  Branch (828:4): [True: 10, False: 147]
  ------------------
  829|     10|				return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     10|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  830|     10|			case 0x0C: /* SW_IDENTITY_BLOCKED */
  ------------------
  |  Branch (830:4): [True: 10, False: 147]
  ------------------
  831|     10|				return SC_ERROR_AUTH_METHOD_BLOCKED;
  ------------------
  |  |   62|     10|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  832|     10|			case 0x0F: /* SW_INVALID_PARAMETER */
  ------------------
  |  Branch (832:4): [True: 10, False: 147]
  ------------------
  833|     22|			case 0x10: /* SW_INCORRECT_P1 */
  ------------------
  |  Branch (833:4): [True: 12, False: 145]
  ------------------
  834|     32|			case 0x11: /* SW_INCORRECT_P2 */
  ------------------
  |  Branch (834:4): [True: 10, False: 147]
  ------------------
  835|     32|				return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|     32|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  836|    157|		}
  837|    157|	}
  838|  30.5k|	return iso_ops->check_sw(card, sw1, sw2);
  839|  30.6k|}
card-muscle.c:muscle_match_card:
   79|  6.78k|{
   80|  6.78k|	sc_apdu_t apdu;
   81|  6.78k|	u8 response[64];
   82|  6.78k|	int r;
   83|       |
   84|  6.78k|	if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) == 1) {
  ------------------
  |  Branch (84:6): [True: 596, False: 6.18k]
  ------------------
   85|       |		/* Muscle applet is present, check the protocol version to be sure */
   86|    596|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x3C, 0x00, 0x00);
  ------------------
  |  |  301|    596|#define SC_APDU_CASE_2			0x22
  ------------------
   87|    596|		apdu.cla = 0xB0;
   88|    596|		apdu.le = 64;
   89|    596|		apdu.resplen = 64;
   90|    596|		apdu.resp = response;
   91|    596|		r = sc_transmit_apdu(card, &apdu);
   92|    596|		if (r == SC_SUCCESS && apdu.resplen > 1 && response[0] == 0x01) {
  ------------------
  |  |   28|  1.19k|#define SC_SUCCESS				0
  ------------------
  |  Branch (92:7): [True: 570, False: 26]
  |  Branch (92:26): [True: 28, False: 542]
  |  Branch (92:46): [True: 1, False: 27]
  ------------------
   93|      1|			card->type = SC_CARD_TYPE_MUSCLE_V1;
   94|    595|		} else {
   95|    595|			card->type = SC_CARD_TYPE_MUSCLE_GENERIC;
   96|    595|		}
   97|    596|		return 1;
   98|    596|	}
   99|  6.18k|	return 0;
  100|  6.78k|}
card-muscle.c:muscle_init:
  464|    596|{
  465|    596|	muscle_private_t *priv;
  466|    596|	int r;
  467|       |
  468|    596|	card->name = "MuscleApplet";
  469|    596|	card->drv_data = malloc(sizeof(muscle_private_t));
  470|    596|	if(!card->drv_data) {
  ------------------
  |  Branch (470:5): [True: 0, False: 596]
  ------------------
  471|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|      0|	}
  473|    596|	memset(card->drv_data, 0, sizeof(muscle_private_t));
  474|    596|	priv = MUSCLE_DATA(card);
  ------------------
  |  |   57|    596|#define MUSCLE_DATA(card) ( (muscle_private_t*)card->drv_data )
  ------------------
  475|    596|	priv->verifiedPins = 0;
  476|    596|	priv->fs = mscfs_new();
  477|    596|	if(!priv->fs) {
  ------------------
  |  Branch (477:5): [True: 0, False: 596]
  ------------------
  478|      0|		free(card->drv_data);
  479|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|      0|	}
  481|    596|	priv->fs->udata = card;
  482|    596|	priv->fs->listFile = _listFile;
  483|       |
  484|    596|	card->cla = 0xB0;
  485|       |
  486|    596|	card->flags |= SC_CARD_FLAG_RNG;
  ------------------
  |  |  536|    596|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  487|    596|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    596|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  488|       |
  489|       |	/* Card type detection */
  490|    596|	r = _sc_match_atr(card, muscle_atrs, &card->type);
  491|    596|	if (r < 0) {
  ------------------
  |  Branch (491:6): [True: 595, False: 1]
  ------------------
  492|    595|		sc_log(card->ctx, "Failed to match the ATRs");
  ------------------
  |  |   71|    595|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  493|    595|	}
  494|    596|	if(card->type == SC_CARD_TYPE_MUSCLE_ETOKEN_72K) {
  ------------------
  |  Branch (494:5): [True: 0, False: 596]
  ------------------
  495|      0|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      0|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  496|      0|	}
  497|    596|	if(card->type == SC_CARD_TYPE_MUSCLE_JCOP241) {
  ------------------
  |  Branch (497:5): [True: 1, False: 595]
  ------------------
  498|      1|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      1|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  499|      1|	}
  500|    596|	if (!(card->caps & SC_CARD_CAP_APDU_EXT)) {
  ------------------
  |  |  547|    596|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (500:6): [True: 595, False: 1]
  ------------------
  501|    595|		card->max_recv_size = 255;
  502|    595|		card->max_send_size = 255;
  503|    595|	}
  504|    596|	if(card->type == SC_CARD_TYPE_MUSCLE_JCOP242R2_NO_EXT_APDU) {
  ------------------
  |  Branch (504:5): [True: 0, False: 596]
  ------------------
  505|       |	        /* Tyfone JCOP v242R2 card that doesn't support extended APDUs */
  506|      0|	}
  507|       |
  508|       |
  509|       |	/* FIXME: Card type detection */
  510|    596|	if (1) {
  ------------------
  |  Branch (510:6): [True: 596, Folded]
  ------------------
  511|    596|		unsigned long flags;
  512|       |
  513|    596|		flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    596|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  514|    596|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    596|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  515|    596|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    596|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  516|       |
  517|    596|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  518|    596|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  519|    596|	}
  520|    596|	return SC_SUCCESS;
  ------------------
  |  |   28|    596|#define SC_SUCCESS				0
  ------------------
  521|    596|}
card-muscle.c:_listFile:
  458|  30.6k|{
  459|  30.6k|	int next = reset ? 0x00 : 0x01;
  ------------------
  |  Branch (459:13): [True: 1.37k, False: 29.2k]
  ------------------
  460|  30.6k|	return msc_list_objects( (sc_card_t*)udata, next, file);
  461|  30.6k|}
card-muscle.c:muscle_finish:
   68|    596|{
   69|    596|	muscle_private_t *priv = MUSCLE_DATA(card);
  ------------------
  |  |   57|    596|#define MUSCLE_DATA(card) ( (muscle_private_t*)card->drv_data )
  ------------------
   70|    596|	mscfs_free(priv->fs);
   71|    596|	free(priv);
   72|    596|	return 0;
   73|    596|}
card-muscle.c:muscle_read_binary:
  199|    389|{
  200|    389|	mscfs_t *fs = MUSCLE_FS(card);
  ------------------
  |  |   58|    389|#define MUSCLE_FS(card) ( ((muscle_private_t*)card->drv_data)->fs )
  ------------------
  201|    389|	int r;
  202|    389|	msc_id objectId;
  203|    389|	u8* oid = objectId.id;
  204|    389|	mscfs_file_t *file;
  205|       |
  206|    389|	r = mscfs_check_selection(fs, -1);
  207|    389|	if(r < 0) LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (207:5): [True: 0, False: 389]
  ------------------
  208|    389|	file = &fs->cache.array[fs->currentFileIndex];
  209|    389|	objectId = file->objectId;
  210|       |	/* memcpy(objectId.id, file->objectId.id, 4); */
  211|    389|	if(!file->ef) {
  ------------------
  |  Branch (211:5): [True: 72, False: 317]
  ------------------
  212|     72|		oid[0] = oid[2];
  213|     72|		oid[1] = oid[3];
  214|     72|		oid[2] = oid[3] = 0;
  215|     72|	}
  216|    389|	r = msc_read_object(card, objectId, idx, buf, count);
  217|    389|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    389|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    389|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    389|	int _ret = r; \
  |  |  |  |  155|    389|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 101, False: 288]
  |  |  |  |  ------------------
  |  |  |  |  156|    101|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    101|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 101, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    101|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    288|	} else { \
  |  |  |  |  159|    288|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    288|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    288|	} \
  |  |  |  |  162|    389|	return _ret; \
  |  |  |  |  163|    389|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  218|    389|}
card-muscle.c:muscle_select_file:
  434|  2.59k|{
  435|  2.59k|	int r;
  436|       |
  437|  2.59k|	if (card == NULL || path_in == NULL)
  ------------------
  |  Branch (437:6): [True: 0, False: 2.59k]
  |  Branch (437:22): [True: 0, False: 2.59k]
  ------------------
  438|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  439|       |
  440|  2.59k|	switch (path_in->type) {
  441|      5|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      5|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (441:2): [True: 5, False: 2.58k]
  ------------------
  442|      5|		r = select_item(card, path_in, file_out, 1);
  443|      5|		break;
  444|  1.06k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  1.06k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (444:2): [True: 1.06k, False: 1.52k]
  ------------------
  445|  1.06k|		r = select_item(card, path_in, file_out, 0);
  446|  1.06k|		break;
  447|  1.52k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.52k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (447:2): [True: 1.52k, False: 1.07k]
  ------------------
  448|  1.52k|		r = select_item(card, path_in, file_out, -1);
  449|  1.52k|		break;
  450|      0|	default:
  ------------------
  |  Branch (450:2): [True: 0, False: 2.59k]
  ------------------
  451|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  452|  2.59k|	}
  453|  2.59k|	if(r > 0) r = 0;
  ------------------
  |  Branch (453:5): [True: 0, False: 2.59k]
  ------------------
  454|  2.59k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
  ------------------
  |  |  153|  2.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.59k|	int _ret = r; \
  |  |  155|  2.59k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.59k, False: 0]
  |  |  ------------------
  |  |  156|  2.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  2.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.01k, False: 584]
  |  |  ------------------
  |  |  157|  2.59k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.59k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.59k|	return _ret; \
  |  |  163|  2.59k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  455|  2.59k|}
card-muscle.c:select_item:
  370|  2.59k|{
  371|  2.59k|	mscfs_t *fs = MUSCLE_FS(card);
  ------------------
  |  |   58|  2.59k|#define MUSCLE_FS(card) ( ((muscle_private_t*)card->drv_data)->fs )
  ------------------
  372|  2.59k|	mscfs_file_t *file_data = NULL;
  373|  2.59k|	size_t pathlen = path_in->len;
  374|  2.59k|	int r = 0;
  375|  2.59k|	int objectIndex;
  376|  2.59k|	u8* oid;
  377|       |
  378|  2.59k|	r = mscfs_check_cache(fs);
  379|  2.59k|	if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.08k|	int _ret = r; \
  |  |  155|  1.08k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.08k, False: 0]
  |  |  ------------------
  |  |  156|  1.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.08k, False: 0]
  |  |  ------------------
  |  |  157|  1.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.08k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.08k|	return _ret; \
  |  |  163|  1.08k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (379:5): [True: 1.08k, False: 1.50k]
  ------------------
  380|  1.50k|	r = mscfs_loadFileInfo(fs, path_in->value, path_in->len, &file_data, &objectIndex);
  381|  1.50k|	if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
  ------------------
  |  |  153|    921|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    921|	int _ret = r; \
  |  |  155|    921|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 921, False: 0]
  |  |  ------------------
  |  |  156|    921|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    921|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 921, False: 0]
  |  |  ------------------
  |  |  157|    921|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    921|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    921|	return _ret; \
  |  |  163|    921|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (381:5): [True: 921, False: 586]
  ------------------
  382|       |
  383|       |	/* Check if its the right type */
  384|    586|	if(requiredType >= 0 && requiredType != file_data->ef) {
  ------------------
  |  Branch (384:5): [True: 14, False: 572]
  |  Branch (384:26): [True: 1, False: 13]
  ------------------
  385|      1|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|      1|	}
  387|    585|	oid = file_data->objectId.id;
  388|       |	/* Is it a file or directory */
  389|    585|	if(file_data->ef) {
  ------------------
  |  Branch (389:5): [True: 315, False: 270]
  ------------------
  390|    315|		fs->currentPath[0] = oid[0];
  391|    315|		fs->currentPath[1] = oid[1];
  392|    315|		fs->currentFile[0] = oid[2];
  393|    315|		fs->currentFile[1] = oid[3];
  394|    315|	} else {
  395|    270|		if(pathlen < 2) {
  ------------------
  |  Branch (395:6): [True: 1, False: 269]
  ------------------
  396|      1|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  397|      1|		}
  398|    269|		fs->currentPath[0] = oid[pathlen - 2];
  399|    269|		fs->currentPath[1] = oid[pathlen - 1];
  400|    269|		fs->currentFile[0] = 0;
  401|    269|		fs->currentFile[1] = 0;
  402|    269|	}
  403|       |
  404|    584|	fs->currentFileIndex = objectIndex;
  405|    584|	if(file_out) {
  ------------------
  |  Branch (405:5): [True: 330, False: 254]
  ------------------
  406|    330|		sc_file_t *file;
  407|    330|		file = sc_file_new();
  408|    330|		file->path = *path_in;
  409|    330|		file->size = file_data->size;
  410|    330|		file->id = (oid[2] << 8) | oid[3];
  411|    330|		if(!file_data->ef) {
  ------------------
  |  Branch (411:6): [True: 15, False: 315]
  ------------------
  412|     15|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     15|#define SC_FILE_TYPE_DF			0x04
  ------------------
  413|    315|		} else {
  414|    315|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    315|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  415|    315|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    315|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  416|    315|		}
  417|       |
  418|       |		/* Setup ACLS */
  419|    330|		if(file_data->ef) {
  ------------------
  |  Branch (419:6): [True: 315, False: 15]
  ------------------
  420|    315|			muscle_load_file_acls(file, file_data);
  421|    315|		} else {
  422|     15|			muscle_load_dir_acls(file, file_data);
  423|       |			/* Setup directory acls... */
  424|     15|		}
  425|       |
  426|    330|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    330|#define SC_FILE_MAGIC			0x14426950
  ------------------
  427|    330|		*file_out = file;
  428|    330|	}
  429|    584|	return 0;
  430|    585|}
card-muscle.c:muscle_load_file_acls:
  353|    315|{
  354|    315|	muscle_load_single_acl(file, SC_AC_OP_READ, file_data->read);
  ------------------
  |  |  188|    315|#define SC_AC_OP_READ			22
  ------------------
  355|    315|	muscle_load_single_acl(file, SC_AC_OP_WRITE, file_data->write);
  ------------------
  |  |  190|    315|#define SC_AC_OP_WRITE			24
  ------------------
  356|    315|	muscle_load_single_acl(file, SC_AC_OP_UPDATE, file_data->write);
  ------------------
  |  |  189|    315|#define SC_AC_OP_UPDATE			23
  ------------------
  357|    315|	muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete);
  ------------------
  |  |  168|    315|#define SC_AC_OP_DELETE			2
  ------------------
  358|    315|}
card-muscle.c:muscle_load_single_acl:
  338|  1.33k|{
  339|  1.33k|	int key;
  340|       |	/* Everybody by default.... */
  341|  1.33k|	sc_file_add_acl_entry(file, operation, SC_AC_NONE, 0);
  ------------------
  |  |  150|  1.33k|#define SC_AC_NONE			0x00000000
  ------------------
  342|  1.33k|	if(acl == 0xFFFF) {
  ------------------
  |  Branch (342:5): [True: 155, False: 1.18k]
  ------------------
  343|    155|		sc_file_add_acl_entry(file, operation, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    155|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  344|    155|		return;
  345|    155|	}
  346|  20.0k|	for(key = 0; key < 16; key++) {
  ------------------
  |  Branch (346:15): [True: 18.8k, False: 1.18k]
  ------------------
  347|  18.8k|		if(acl >> key & 1) {
  ------------------
  |  Branch (347:6): [True: 8.60k, False: 10.2k]
  ------------------
  348|  8.60k|			sc_file_add_acl_entry(file, operation, SC_AC_CHV, key);
  ------------------
  |  |  151|  8.60k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  349|  8.60k|		}
  350|  18.8k|	}
  351|  1.18k|}
card-muscle.c:muscle_load_dir_acls:
  360|     15|{
  361|     15|	muscle_load_single_acl(file, SC_AC_OP_SELECT, 0);
  ------------------
  |  |  166|     15|#define SC_AC_OP_SELECT			0
  ------------------
  362|     15|	muscle_load_single_acl(file, SC_AC_OP_LIST_FILES, 0);
  ------------------
  |  |  172|     15|#define SC_AC_OP_LIST_FILES		6
  ------------------
  363|     15|	muscle_load_single_acl(file, SC_AC_OP_LOCK, 0xFFFF);
  ------------------
  |  |  167|     15|#define SC_AC_OP_LOCK			1
  ------------------
  364|     15|	muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete);
  ------------------
  |  |  168|     15|#define SC_AC_OP_DELETE			2
  ------------------
  365|     15|	muscle_load_single_acl(file, SC_AC_OP_CREATE, file_data->write);
  ------------------
  |  |  169|     15|#define SC_AC_OP_CREATE			3
  ------------------
  366|     15|}
card-muscle.c:muscle_card_reader_lock_obtained:
  842|  37.7k|{
  843|  37.7k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  37.7k|#define SC_SUCCESS				0
  ------------------
  844|       |
  845|  37.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  37.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  37.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  37.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 37.7k]
  |  |  ------------------
  ------------------
  846|       |
  847|  37.7k|	if (was_reset > 0) {
  ------------------
  |  Branch (847:6): [True: 0, False: 37.7k]
  ------------------
  848|      0|		if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) != 1) {
  ------------------
  |  Branch (848:7): [True: 0, False: 0]
  ------------------
  849|      0|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  850|      0|		}
  851|      0|	}
  852|       |
  853|  37.7k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  37.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  37.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  37.7k|	int _ret = r; \
  |  |  |  |  155|  37.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 37.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  37.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 37.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  37.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  37.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  37.7k|	return _ret; \
  |  |  |  |  163|  37.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  854|  37.7k|}

sc_get_myeid_driver:
 2183|  15.2k|{
 2184|  15.2k|	return sc_get_driver();
 2185|  15.2k|}
card-myeid.c:sc_get_driver:
 2148|  15.2k|{
 2149|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2150|       |
 2151|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2151:6): [True: 1, False: 15.2k]
  ------------------
 2152|      1|		iso_ops = iso_drv->ops;
 2153|       |
 2154|  15.2k|	myeid_ops			= *iso_drv->ops;
 2155|  15.2k|	myeid_ops.match_card		= myeid_match_card;
 2156|  15.2k|	myeid_ops.init			= myeid_init;
 2157|  15.2k|	myeid_ops.finish		= myeid_finish;
 2158|       |	/* no record oriented file services */
 2159|  15.2k|	myeid_ops.read_record		= NULL;
 2160|  15.2k|	myeid_ops.write_record		= NULL;
 2161|  15.2k|	myeid_ops.append_record		= NULL;
 2162|       |	myeid_ops.update_record		= NULL;
 2163|  15.2k|	myeid_ops.select_file		= myeid_select_file;
 2164|  15.2k|	myeid_ops.get_response		= iso_ops->get_response;
 2165|  15.2k|	myeid_ops.logout		= myeid_logout;
 2166|  15.2k|	myeid_ops.create_file		= myeid_create_file;
 2167|  15.2k|	myeid_ops.delete_file		= myeid_delete_file;
 2168|  15.2k|	myeid_ops.list_files		= myeid_list_files;
 2169|  15.2k|	myeid_ops.set_security_env	= myeid_set_security_env;
 2170|  15.2k|	myeid_ops.compute_signature	= myeid_compute_signature;
 2171|  15.2k|	myeid_ops.decipher		= myeid_decipher;
 2172|  15.2k|	myeid_ops.process_fci		= myeid_process_fci;
 2173|  15.2k|	myeid_ops.card_ctl		= myeid_card_ctl;
 2174|  15.2k|	myeid_ops.pin_cmd		= myeid_pin_cmd;
 2175|  15.2k|	myeid_ops.wrap			= myeid_wrap_key;
 2176|  15.2k|	myeid_ops.unwrap		= myeid_unwrap_key;
 2177|  15.2k|	myeid_ops.encrypt_sym		= myeid_encrypt_sym;
 2178|  15.2k|	myeid_ops.decrypt_sym		= myeid_decrypt_sym;
 2179|  15.2k|	return &myeid_drv;
 2180|  15.2k|}
card-myeid.c:myeid_match_card:
  122|  8.98k|{
  123|  8.98k|	size_t len = card->reader->atr_info.hist_bytes_len;
  124|       |	/* Normally the historical bytes are exactly "MyEID", but there might
  125|       |	 * be some historic units which have a small prefix byte sequence. */
  126|  8.98k|	if (len >= 5) {
  ------------------
  |  Branch (126:6): [True: 2.56k, False: 6.42k]
  ------------------
  127|  2.56k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "MyEID", 5)) {
  ------------------
  |  Branch (127:7): [True: 171, False: 2.39k]
  ------------------
  128|    171|			sc_log(card->ctx, "Matched MyEID card");
  ------------------
  |  |   71|    171|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|    171|			card->type = SC_CARD_TYPE_MYEID_GENERIC;
  130|    171|			return 1;
  131|    171|		}
  132|       |		/* The software implementation of MyEID is identified by OsEID bytes */
  133|  2.39k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "OsEID", 5)) {
  ------------------
  |  Branch (133:7): [True: 140, False: 2.25k]
  ------------------
  134|    140|			sc_log(card->ctx, "Matched OsEID card");
  ------------------
  |  |   71|    140|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  135|    140|			card->type = SC_CARD_TYPE_MYEID_OSEID;
  136|    140|			return 1;
  137|    140|		}
  138|  2.39k|	}
  139|  8.67k|	return 0;
  140|  8.98k|}
card-myeid.c:myeid_init:
  171|    311|{
  172|    311|	unsigned long flags = 0, ext_flags = 0;
  173|    311|	myeid_private_data_t *priv;
  174|    311|	u8 appletInfo[20];
  175|    311|	size_t appletInfoLen;
  176|    311|	myeid_card_caps_t card_caps;
  177|    311|	static struct sc_aid myeid_aid = { "\xA0\x00\x00\x00\x63\x50\x4B\x43\x53\x2D\x31\x35", 0x0C };
  178|    311|	int rv = 0;
  179|    311|	void *old_drv_data = card->drv_data;
  180|       |
  181|    311|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    311|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    311|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    311|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    311|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 311]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|    311|	switch (card->type) {
  184|    140|	case SC_CARD_TYPE_MYEID_OSEID:
  ------------------
  |  Branch (184:2): [True: 140, False: 171]
  ------------------
  185|    140|		card->name = oseid_card_name;
  186|    140|		break;
  187|    171|	case SC_CARD_TYPE_MYEID_GENERIC:
  ------------------
  |  Branch (187:2): [True: 171, False: 140]
  ------------------
  188|    171|		card->name = myeid_card_name;
  189|    171|		break;
  190|      0|	default:
  ------------------
  |  Branch (190:2): [True: 0, False: 311]
  ------------------
  191|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|    311|	}
  193|       |
  194|    311|	priv = calloc(1, sizeof(myeid_private_data_t));
  195|       |
  196|    311|	if (!priv)
  ------------------
  |  Branch (196:6): [True: 0, False: 311]
  ------------------
  197|    311|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|    311|	rv = myeid_load_options (card->ctx, priv);
  200|    311|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Unable to read options from opensc.conf");
  ------------------
  |  |  184|    311|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    311|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    311|	int _ret = (r); \
  |  |  |  |  178|    311|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 311]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 311]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|    311|	priv->card_state = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|    311|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  203|    311|	card->drv_data = priv;
  204|       |
  205|       |	/* Ensure that the MyEID applet is selected. */
  206|    311|	rv = iso7816_select_aid(card, myeid_aid.value, myeid_aid.len, NULL, NULL);
  207|    311|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to select MyEID applet.");
  ------------------
  |  |  184|    311|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    311|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    311|	int _ret = (r); \
  |  |  |  |  178|    311|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 13, False: 298]
  |  |  |  |  ------------------
  |  |  |  |  179|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     13|		goto err; \
  |  |  |  |  182|     13|	} \
  |  |  |  |  183|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 298]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|       |	/* find out MyEID version */
  210|       |
  211|    298|	appletInfoLen = 20;
  212|       |
  213|    298|	if (0 > myeid_get_info(card, appletInfo, appletInfoLen))
  ------------------
  |  Branch (213:6): [True: 96, False: 202]
  ------------------
  214|    298|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information.");
  ------------------
  |  |  184|     96|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     96|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     96|	int _ret = (r); \
  |  |  |  |  178|     96|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 96, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     96|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     96|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     96|		goto err; \
  |  |  |  |  182|     96|	} \
  |  |  |  |  183|     96|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|       |
  216|    202|	priv->change_counter = appletInfo[19] | appletInfo[18] << 8;
  217|       |
  218|    202|	memset(&card_caps, 0, sizeof(myeid_card_caps_t));
  219|    202|	card_caps.max_ecc_key_length = 256;
  220|    202|	card_caps.max_rsa_key_length = 2048;
  221|       |
  222|    202|	if (card->version.fw_major >= 40) {
  ------------------
  |  Branch (222:6): [True: 77, False: 125]
  ------------------
  223|       |	    /* Since 4.0, we can query available algorithms and key sizes.
  224|       |	     * Since 3.5.0 RSA up to 2048 and ECC up to 256 are always supported, so we check only max ECC key length. */
  225|     77|	    if (myeid_get_card_caps(card, &card_caps) != SC_SUCCESS) {
  ------------------
  |  |   28|     77|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:10): [True: 32, False: 45]
  ------------------
  226|     32|			sc_log(card->ctx, "Failed to get card capabilities. Using default max ECC key length 256.");
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  227|     32|	    }
  228|     77|	}
  229|       |
  230|    202|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    202|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    202|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  231|    202|	if (priv->disable_hw_pkcs1_padding == 0)
  ------------------
  |  Branch (231:6): [True: 202, False: 0]
  ------------------
  232|    202|		flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    202|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    202|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    202|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  233|    202|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    202|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  234|       |
  235|    202|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  236|    202|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  237|    202|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  238|    202|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  239|    202|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  240|       |
  241|    202|	if (card_caps.card_supported_features & MYEID_CARD_CAP_RSA) {
  ------------------
  |  |   50|    202|#define MYEID_CARD_CAP_RSA		0x01
  ------------------
  |  Branch (241:6): [True: 40, False: 162]
  ------------------
  242|     40|		if (card_caps.max_rsa_key_length >= 3072)
  ------------------
  |  Branch (242:7): [True: 26, False: 14]
  ------------------
  243|     26|			_sc_card_add_rsa_alg(card, 3072, flags, 0);
  244|     40|		if (card_caps.max_rsa_key_length >= 4096)
  ------------------
  |  Branch (244:7): [True: 23, False: 17]
  ------------------
  245|     23|			_sc_card_add_rsa_alg(card, 4096, flags, 0);
  246|     40|	}
  247|       |
  248|       |	/* show ECC algorithms if the applet version of the inserted card supports them */
  249|    202|	if (card->version.fw_major >= 35) {
  ------------------
  |  Branch (249:6): [True: 81, False: 121]
  ------------------
  250|     81|		int i;
  251|       |
  252|     81|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  174|     81|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  173|     81|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     81|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  253|     81|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|     81|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     81|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  254|     81|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|     81|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|     81|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  255|       |
  256|    405|		for (i=0; ec_curves[i].curve_name != NULL; i++) {
  ------------------
  |  Branch (256:13): [True: 324, False: 81]
  ------------------
  257|    324|			if (card_caps.max_ecc_key_length >= ec_curves[i].size)
  ------------------
  |  Branch (257:8): [True: 212, False: 112]
  ------------------
  258|    212|				_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].curve_oid);
  259|    324|		}
  260|     81|	}
  261|       |
  262|       |	/* show supported symmetric algorithms */
  263|    202|	flags = 0;
  264|    202|	if (card_caps.card_supported_features & MYEID_CARD_CAP_3DES) {
  ------------------
  |  |   51|    202|#define MYEID_CARD_CAP_3DES		0x02
  ------------------
  |  Branch (264:6): [True: 37, False: 165]
  ------------------
  265|     37|		if (card_caps.max_des_key_length >= 64)
  ------------------
  |  Branch (265:7): [True: 28, False: 9]
  ------------------
  266|     28|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_DES, 64, flags);
  ------------------
  |  |   76|     28|#define SC_ALGORITHM_DES		64
  ------------------
  267|     37|		if (card_caps.max_des_key_length >= 128)
  ------------------
  |  Branch (267:7): [True: 27, False: 10]
  ------------------
  268|     27|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 128, flags);
  ------------------
  |  |   77|     27|#define SC_ALGORITHM_3DES		65
  ------------------
  269|     37|		if (card_caps.max_des_key_length >= 192)
  ------------------
  |  Branch (269:7): [True: 25, False: 12]
  ------------------
  270|     25|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 192, flags);
  ------------------
  |  |   77|     25|#define SC_ALGORITHM_3DES		65
  ------------------
  271|     37|	}
  272|    202|	if (card_caps.card_supported_features & MYEID_CARD_CAP_AES) {
  ------------------
  |  |   52|    202|#define MYEID_CARD_CAP_AES		0x04
  ------------------
  |  Branch (272:6): [True: 36, False: 166]
  ------------------
  273|     36|		if (card_caps.max_aes_key_length >= 128)
  ------------------
  |  Branch (273:7): [True: 29, False: 7]
  ------------------
  274|     29|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 128, flags);
  ------------------
  |  |   79|     29|#define SC_ALGORITHM_AES		67
  ------------------
  275|     36|		if (card_caps.max_aes_key_length >= 256)
  ------------------
  |  Branch (275:7): [True: 24, False: 12]
  ------------------
  276|     24|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 256, flags);
  ------------------
  |  |   79|     24|#define SC_ALGORITHM_AES		67
  ------------------
  277|     36|	}
  278|       |
  279|       |	/* State that we have an RNG */
  280|    202|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    202|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    202|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  281|       |
  282|    202|	if ((card->version.fw_major == 40 && card->version.fw_minor >= 10 )
  ------------------
  |  Branch (282:7): [True: 4, False: 198]
  |  Branch (282:39): [True: 2, False: 2]
  ------------------
  283|    200|		|| card->version.fw_major >= 41)
  ------------------
  |  Branch (283:6): [True: 73, False: 127]
  ------------------
  284|     75|		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  572|     75|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  574|     75|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  285|     75|			   | SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  569|     75|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  286|       |
  287|    202|	if (card->version.fw_major >= 45)
  ------------------
  |  Branch (287:6): [True: 63, False: 139]
  ------------------
  288|     63|		priv->cap_chaining = 1;
  289|    202|	if (card->version.fw_major >= 40)
  ------------------
  |  Branch (289:6): [True: 77, False: 125]
  ------------------
  290|     77|		card->max_recv_size = 256;
  291|    125|	else
  292|    125|		card->max_recv_size = 255;
  293|    202|	card->max_send_size = 255;
  294|       |
  295|    202|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    202|#define SC_SUCCESS				0
  ------------------
  296|       |
  297|    311|err:
  298|    311|	if (rv < 0) {
  ------------------
  |  Branch (298:6): [True: 13, False: 298]
  ------------------
  299|     13|		free(priv);
  300|     13|		card->drv_data = old_drv_data;
  301|     13|	}
  302|       |
  303|    311|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    311|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    311|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    311|	int _ret = r; \
  |  |  |  |  155|    311|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 311, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    311|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 298]
  |  |  |  |  ------------------
  |  |  |  |  157|    311|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    311|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    311|	return _ret; \
  |  |  |  |  163|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|    311|}
card-myeid.c:myeid_load_options:
  143|    311|{
  144|    311|	int r;
  145|    311|	size_t i, j;
  146|    311|	scconf_block **found_blocks, *block;
  147|       |
  148|    311|	if (!ctx || !priv) {
  ------------------
  |  Branch (148:6): [True: 0, False: 311]
  |  Branch (148:14): [True: 0, False: 311]
  ------------------
  149|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  150|      0|		goto err;
  151|      0|	}
  152|    311|	priv->disable_hw_pkcs1_padding = 0;
  153|    622|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (153:14): [True: 311, False: 311]
  ------------------
  154|    311|		found_blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  155|    311|				"card_driver", "myeid");
  156|    311|		if (!found_blocks)
  ------------------
  |  Branch (156:7): [True: 0, False: 311]
  ------------------
  157|      0|			continue;
  158|    311|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (158:40): [True: 0, False: 311]
  ------------------
  159|      0|			priv->disable_hw_pkcs1_padding = scconf_get_int(block, "disable_hw_pkcs1_padding", 0);
  160|      0|			sc_log(ctx,"Found config option: disable_hw_pkcs1_padding = %d\n", priv->disable_hw_pkcs1_padding);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  161|      0|		}
  162|    311|		free(found_blocks);
  163|    311|	}
  164|    311|	r = SC_SUCCESS;
  ------------------
  |  |   28|    311|#define SC_SUCCESS				0
  ------------------
  165|       |
  166|    311|err:
  167|    311|	return r;
  168|    311|}
card-myeid.c:myeid_get_info:
 1740|    446|{
 1741|    446|	sc_apdu_t apdu;
 1742|    446|	int r;
 1743|       |
 1744|    446|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    446|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    446|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    446|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    446|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 446]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1745|       |
 1746|    446|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xA0);
  ------------------
  |  |  292|    446|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1747|    446|	apdu.resp    = rbuf;
 1748|    446|	apdu.resplen = buflen;
 1749|    446|	apdu.le      = buflen;
 1750|       |
 1751|    446|	r = sc_transmit_apdu(card, &apdu);
 1752|    446|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|    446|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    446|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    446|	int _ret = (r); \
  |  |  |  |  168|    446|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 435]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 435]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1753|       |
 1754|    435|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1754:6): [True: 206, False: 229]
  |  Branch (1754:26): [True: 8, False: 221]
  ------------------
 1755|    214|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    214|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1756|       |
 1757|    221|	if (apdu.resplen != 20)
  ------------------
  |  Branch (1757:6): [True: 17, False: 204]
  ------------------
 1758|     17|	{
 1759|     17|		sc_log(card->ctx, "Unexpected response to GET DATA (applet info)");
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1760|     17|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     17|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1761|     17|	}
 1762|       |
 1763|       |	/* store the applet version */
 1764|    204|	card->version.fw_major = rbuf[5] * 10 + rbuf[6];
 1765|    204|	card->version.fw_minor = rbuf[7];
 1766|       |	/* add version to name */
 1767|    204|	snprintf(card_name_buf, sizeof(card_name_buf),
 1768|    204|			"%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
 1769|    204|	card->name = card_name_buf;
 1770|       |
 1771|    204|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    204|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    204|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    204|	int _ret = r; \
  |  |  |  |  155|    204|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 204, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    204|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 204]
  |  |  |  |  ------------------
  |  |  |  |  157|    204|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    204|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    204|	return _ret; \
  |  |  |  |  163|    204|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1772|    204|}
card-myeid.c:myeid_get_card_caps:
 1823|     77|{
 1824|     77|	sc_apdu_t apdu;
 1825|     77|	int r;
 1826|     77|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1827|       |
 1828|     77|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     77|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     77|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     77|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     77|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 77]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1829|       |
 1830|     77|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xAA);
  ------------------
  |  |  292|     77|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1831|     77|	apdu.resp    = rbuf;
 1832|     77|	apdu.resplen = sizeof(myeid_card_caps_t);
 1833|     77|	apdu.le      = sizeof(myeid_card_caps_t);
 1834|       |
 1835|     77|	r = sc_transmit_apdu(card, &apdu);
 1836|     77|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     77|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     77|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     77|	int _ret = (r); \
  |  |  |  |  168|     77|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 76]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1837|       |
 1838|     76|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1838:6): [True: 22, False: 54]
  |  Branch (1838:26): [True: 6, False: 48]
  ------------------
 1839|     28|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     28|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1840|       |
 1841|     48|	if (apdu.resplen < 11) {
  ------------------
  |  Branch (1841:6): [True: 3, False: 45]
  ------------------
 1842|      3|		sc_log(card->ctx, "Unexpected response to GET DATA (MyEIC card capabilities)");
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1843|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1844|      3|	}
 1845|       |
 1846|     45|	card_caps->card_caps_ver = rbuf[0];
 1847|       |	/* the card returns big endian values */
 1848|     45|	card_caps->card_supported_features = (unsigned short) rbuf[1] << 8 | rbuf[2];
 1849|     45|	card_caps->max_rsa_key_length = (unsigned short) rbuf[3] << 8 | rbuf[4];
 1850|     45|	card_caps->max_des_key_length = (unsigned short) rbuf[5] << 8 | rbuf[6];
 1851|     45|	card_caps->max_aes_key_length = (unsigned short) rbuf[7] << 8 | rbuf[8];
 1852|     45|	card_caps->max_ecc_key_length = (unsigned short) rbuf[9] << 8 | rbuf[10];
 1853|       |
 1854|     45|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1855|     45|}
card-myeid.c:myeid_finish:
 1893|    298|{
 1894|    298|	struct myeid_private_data *priv = (struct myeid_private_data *) card->drv_data;
 1895|    298|	free(priv);
 1896|    298|	return SC_SUCCESS;
  ------------------
  |  |   28|    298|#define SC_SUCCESS				0
  ------------------
 1897|    298|}
card-myeid.c:myeid_select_file:
  392|  2.04k|{
  393|  2.04k|	int r;
  394|       |
  395|  2.04k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|  2.04k|	r = iso_ops->select_file(card, in_path, file);
  397|       |
  398|  2.04k|	if (r == 0 && file != NULL && *file != NULL)
  ------------------
  |  Branch (398:6): [True: 569, False: 1.47k]
  |  Branch (398:16): [True: 111, False: 458]
  |  Branch (398:32): [True: 111, False: 0]
  ------------------
  399|    111|		parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  400|       |
  401|  2.04k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.04k|	int _ret = r; \
  |  |  |  |  155|  2.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.47k, False: 569]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.04k|	return _ret; \
  |  |  |  |  163|  2.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|  2.04k|}
card-myeid.c:parse_sec_attr:
  350|    111|{
  351|    111|	int i;
  352|    111|	const int df_ops[4] =
  353|    111|		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|    111|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|    111|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|    111|#define SC_AC_OP_DELETE			2
  ------------------
  354|    111|	const int ef_ops[4] =
  355|    111|		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  188|    111|#define SC_AC_OP_READ			22
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  189|    111|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|    111|#define SC_AC_OP_DELETE			2
  ------------------
  356|    111|	const int key_ops[4] =
  357|    111|		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  173|    111|#define SC_AC_OP_CRYPTO			7
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  189|    111|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  168|    111|#define SC_AC_OP_DELETE			2
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  192|    111|#define SC_AC_OP_GENERATE		26
  ------------------
  358|       |
  359|    111|	const int *ops;
  360|       |
  361|    111|	if (len < 2)
  ------------------
  |  Branch (361:6): [True: 52, False: 59]
  ------------------
  362|     52|		return;
  363|       |
  364|     59|	switch (file->type) {
  365|      7|	case SC_FILE_TYPE_WORKING_EF:
  ------------------
  |  |  216|      7|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (365:2): [True: 7, False: 52]
  ------------------
  366|      7|		ops = ef_ops;
  367|      7|		break;
  368|     12|	case SC_FILE_TYPE_INTERNAL_EF:
  ------------------
  |  |  215|     12|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (368:2): [True: 12, False: 47]
  ------------------
  369|     12|		ops = key_ops;
  370|     12|		break;
  371|     10|	case SC_FILE_TYPE_DF:
  ------------------
  |  |  214|     10|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (371:2): [True: 10, False: 49]
  ------------------
  372|     10|		ops = df_ops;
  373|     10|		break;
  374|     30|	default:
  ------------------
  |  Branch (374:2): [True: 30, False: 29]
  ------------------
  375|     30|		ops = key_ops;
  376|     30|		break;
  377|     59|	}
  378|       |
  379|    295|	for (i = 0; i < 4; i++)
  ------------------
  |  Branch (379:14): [True: 236, False: 59]
  ------------------
  380|    236|	{
  381|    236|		if (ops[i] == -1)
  ------------------
  |  Branch (381:7): [True: 17, False: 219]
  ------------------
  382|     17|			continue;
  383|    219|		if ((i & 1) == 0)
  ------------------
  |  Branch (383:7): [True: 118, False: 101]
  ------------------
  384|    118|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] >> 4));
  385|    101|		else
  386|    101|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] & 0x0F));
  387|    219|	}
  388|     59|}
card-myeid.c:add_acl_entry:
  330|    219|{
  331|    219|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    219|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  332|       |
  333|    219|	switch (byte)
  334|    219|	{
  335|     34|	case 0:
  ------------------
  |  Branch (335:2): [True: 34, False: 185]
  ------------------
  336|     34|		method = SC_AC_NONE;
  ------------------
  |  |  150|     34|#define SC_AC_NONE			0x00000000
  ------------------
  337|     34|		break;
  338|     47|	case 15:
  ------------------
  |  Branch (338:2): [True: 47, False: 172]
  ------------------
  339|     47|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     47|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  340|     47|		break;
  341|    138|	default:
  ------------------
  |  Branch (341:2): [True: 138, False: 81]
  ------------------
  342|    138|		method = SC_AC_CHV;
  ------------------
  |  |  151|    138|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  343|    138|		key_ref = byte;
  344|    138|		break;
  345|    219|	}
  346|    219|	sc_file_add_acl_entry(file, op, method, key_ref);
  347|    219|}
card-myeid.c:myeid_set_security_env:
  985|    132|{
  986|    132|	struct sc_context *ctx = card->ctx;
  987|    132|	myeid_private_data_t* priv;
  988|       |
  989|    132|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    132|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    132|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    132|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    132|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 132]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  990|       |
  991|    132|	priv = (myeid_private_data_t*) card->drv_data;
  992|       |	/* store security environment to differentiate between ECDH and RSA in decipher - Hannu*/
  993|    132|	priv->sec_env = env;
  994|       |
  995|       |	/* for symmetric operation save algo and algo flags */
  996|    132|	priv->algorithm_flags = env->algorithm_flags;
  997|    132|	priv->algorithm = env->algorithm;
  998|       |
  999|    132|	if (env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   60|    132|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (999:6): [True: 132, False: 0]
  ------------------
 1000|    132|	{
 1001|    132|		sc_security_env_t tmp;
 1002|       |
 1003|    132|		tmp = *env;
 1004|    132|		tmp.flags &= ~SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|    132|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
 1005|    132|		tmp.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|    132|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
 1006|       |
 1007|    132|		if (tmp.algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    132|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1007:7): [True: 132, False: 0]
  ------------------
 1008|    132|		{
 1009|    132|			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   52|    264|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   51|    132|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (1009:8): [True: 0, False: 132]
  |  Branch (1009:52): [True: 0, False: 132]
  ------------------
 1010|      0|			{
 1011|      0|			    tmp.algorithm_ref = 0x0A;
 1012|      0|			}
 1013|    132|			else
 1014|    132|			{
 1015|    132|				tmp.algorithm_ref = 0x00;
 1016|       |				/* potential FIXME: return an error, if an unsupported
 1017|       |				* pad or hash was requested, although this shouldn't happen */
 1018|    132|				if ((env->operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |   48|    264|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
              				if ((env->operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|     34|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1018:10): [True: 34, False: 98]
  |  Branch (1018:53): [True: 0, False: 34]
  ------------------
 1019|    132|					|| (env->operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02))
  ------------------
  |  |   47|    264|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
              					|| (env->operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02))
  ------------------
  |  |  110|     98|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1019:10): [True: 98, False: 34]
  |  Branch (1019:57): [True: 0, False: 98]
  ------------------
 1020|      0|					tmp.algorithm_ref = 0x02;
 1021|    132|				if (tmp.algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1)
  ------------------
  |  |  134|    132|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1021:9): [True: 0, False: 132]
  ------------------
 1022|      0|					tmp.algorithm_ref |= 0x10;
 1023|    132|			}
 1024|       |
 1025|    132|			return myeid_set_security_env_rsa(card, &tmp, se_num);
 1026|    132|		}
 1027|      0|		else if (tmp.algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1027:12): [True: 0, False: 0]
  ------------------
 1028|      0|		{
 1029|      0|			tmp.algorithm_ref = 0x04;
 1030|      0|			tmp.algorithm_flags = 0;
 1031|      0|			return myeid_set_security_env_ec(card, &tmp, se_num);
 1032|      0|		}
 1033|      0|		else if (tmp.algorithm == SC_ALGORITHM_AES)
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (1033:12): [True: 0, False: 0]
  ------------------
 1034|      0|		{
 1035|      0|			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   52|      0|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   51|      0|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (1035:8): [True: 0, False: 0]
  |  Branch (1035:52): [True: 0, False: 0]
  ------------------
 1036|      0|			{
 1037|      0|				tmp.algorithm_ref = 0x0A;
 1038|      0|			}
 1039|      0|			else
 1040|      0|			{
 1041|      0|				tmp.algorithm_ref = 0x00;
 1042|      0|			}
 1043|       |
 1044|      0|			if ((tmp.algorithm_flags & SC_ALGORITHM_AES_CBC_PAD) == SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
              			if ((tmp.algorithm_flags & SC_ALGORITHM_AES_CBC_PAD) == SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (1044:8): [True: 0, False: 0]
  ------------------
 1045|      0|				tmp.algorithm_ref |= 0x80;		/* set PKCS#7 padding */
 1046|       |			/* Tag 0x80 algorithm_ref - value 0x80 or 0x8A is working only for UNWRAP/WRAP
 1047|       |			 * AES is supported from version 4.0 but without pkcs#7 padding.
 1048|       |			 * For SC_SEC_OPERATION_ENCRYPT_SYM and SC_SEC_OPERATION_DECRYPT_SYM we running
 1049|       |			 * PKCS#7 in software, here we fix the algorithm_ref variable.
 1050|       |			 */
 1051|      0|			if (IS_SYMETRIC_CRYPT(env->operation))
  ------------------
  |  |  739|      0|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   53|      0|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   54|      0|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (739:31): [True: 0, False: 0]
  |  |  |  Branch (739:70): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1052|      0|				tmp.algorithm_ref &= ~0x80; /* do not handle padding in card */
 1053|       |
 1054|       |			/* from this point, there's no difference to RSA SE */
 1055|      0|			return myeid_set_security_env_rsa(card, &tmp, se_num);
 1056|      0|		}
 1057|      0|		else
 1058|      0|		{
 1059|       |
 1060|      0|			sc_log(ctx, "Unsupported algorithm.");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1061|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1062|      0|		}
 1063|    132|	}
 1064|      0|	return myeid_set_security_env_rsa(card, env, se_num);
 1065|    132|}
card-myeid.c:myeid_set_security_env_rsa:
  743|    154|{
  744|    154|	sc_apdu_t apdu;
  745|    154|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  746|    154|	u8 *p;
  747|    154|	int r;
  748|    154|	size_t i, sz;
  749|    154|	sc_path_t *target_file;
  750|       |
  751|    154|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (751:6): [True: 0, False: 154]
  |  Branch (751:22): [True: 0, False: 154]
  ------------------
  752|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  753|    154|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    154|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    154|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    154|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    154|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 154]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|       |
  755|    154|	if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|    154|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (755:6): [True: 0, False: 154]
  ------------------
  756|      0|	{
  757|      0|		sc_log(card->ctx, "symmetric keyref not supported.\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  758|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  759|      0|	}
  760|    154|	if (se_num > 0)
  ------------------
  |  Branch (760:6): [True: 0, False: 154]
  ------------------
  761|      0|	{
  762|      0|		sc_log(card->ctx, "restore security environment not supported.\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  763|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  764|      0|	}
  765|       |
  766|    154|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0, 0);
  ------------------
  |  |  293|    154|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  767|    154|	switch (env->operation)
  768|    154|	{
  769|    120|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    120|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (769:2): [True: 120, False: 34]
  ------------------
  770|    120|		apdu.p1 = 0x41;
  771|    120|		apdu.p2 = 0xB8;
  772|    120|		break;
  773|     34|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     34|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (773:2): [True: 34, False: 120]
  ------------------
  774|     34|		apdu.p1 = 0x41;
  775|     34|		apdu.p2 = 0xB6;
  776|     34|		break;
  777|      0|	case SC_SEC_OPERATION_UNWRAP:
  ------------------
  |  |   52|      0|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (777:2): [True: 0, False: 154]
  ------------------
  778|      0|		apdu.p1 = 0x41;
  779|      0|		apdu.p2 = 0xB8;
  780|      0|		break;
  781|      0|	case SC_SEC_OPERATION_WRAP:
  ------------------
  |  |   51|      0|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (781:2): [True: 0, False: 154]
  ------------------
  782|      0|		apdu.p1 = 0x81;
  783|      0|		apdu.p2 = 0xB8;
  784|      0|		break;
  785|      0|	case SC_SEC_OPERATION_ENCRYPT_SYM:
  ------------------
  |  |   53|      0|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  ------------------
  |  Branch (785:2): [True: 0, False: 154]
  ------------------
  786|      0|		apdu.p1 = 0x81;
  787|      0|		apdu.p2 = 0xB8;
  788|      0|		break;
  789|      0|	case SC_SEC_OPERATION_DECRYPT_SYM:
  ------------------
  |  |   54|      0|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  ------------------
  |  Branch (789:2): [True: 0, False: 154]
  ------------------
  790|      0|		apdu.p1 = 0x41;
  791|      0|		apdu.p2 = 0xB8;
  792|      0|		break;
  793|      0|	default:
  ------------------
  |  Branch (793:2): [True: 0, False: 154]
  ------------------
  794|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  795|    154|	}
  796|    154|	apdu.le = 0;
  797|    154|	p = sbuf;
  798|    154|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT)
  ------------------
  |  |   56|    154|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (798:6): [True: 154, False: 0]
  ------------------
  799|    154|	{
  800|    154|		*p++ = 0x80;	/* algorithm reference */
  801|    154|		*p++ = 0x01;
  802|    154|		*p++ = env->algorithm_ref & 0xFF;
  803|    154|	}
  804|    154|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   57|    154|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (804:6): [True: 22, False: 132]
  ------------------
  805|     22|	{
  806|     22|		*p++ = 0x81;
  807|     22|		*p++ = 2;
  808|     22|		memcpy(p, env->file_ref.value, 2);
  809|     22|		p += 2;
  810|     22|	}
  811|       |	/* symmetric operations: we need to set the key reference */
  812|    154|	if (IS_SYMETRIC_CRYPT(env->operation)) {
  ------------------
  |  |  739|    154|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   53|    308|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   54|    154|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (739:31): [True: 0, False: 154]
  |  |  |  Branch (739:70): [True: 0, False: 154]
  |  |  ------------------
  ------------------
  813|      0|		*p++ = 0x83;
  814|      0|		*p++ = 1;
  815|      0|		*p++ = 0;
  816|      0|	}
  817|    154|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT && env->operation != SC_SEC_OPERATION_UNWRAP &&
  ------------------
  |  |   58|    308|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
              	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT && env->operation != SC_SEC_OPERATION_UNWRAP &&
  ------------------
  |  |   52|    308|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (817:6): [True: 154, False: 0]
  |  Branch (817:49): [True: 154, False: 0]
  ------------------
  818|    154|			env->operation != SC_SEC_OPERATION_WRAP &&
  ------------------
  |  |   51|    308|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (818:4): [True: 154, False: 0]
  ------------------
  819|    154|			env->operation != SC_SEC_OPERATION_ENCRYPT_SYM &&
  ------------------
  |  |   53|    308|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  ------------------
  |  Branch (819:4): [True: 154, False: 0]
  ------------------
  820|    154|			env->operation != SC_SEC_OPERATION_DECRYPT_SYM) {
  ------------------
  |  |   54|    154|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  ------------------
  |  Branch (820:4): [True: 154, False: 0]
  ------------------
  821|    154|		*p++ = 0x84;
  822|    154|		*p++ = 1;
  823|    154|		*p++ = 0;
  824|    154|	}
  825|  1.69k|	for (i = 0; i < SC_SEC_ENV_MAX_PARAMS; i++)
  ------------------
  |  |   64|  1.69k|#define SC_SEC_ENV_MAX_PARAMS		10
  ------------------
  |  Branch (825:14): [True: 1.54k, False: 154]
  ------------------
  826|  1.54k|	    if (env->params[i].param_type == SC_SEC_ENV_PARAM_TARGET_FILE) {
  ------------------
  |  |   66|  1.54k|#define SC_SEC_ENV_PARAM_TARGET_FILE	2
  ------------------
  |  Branch (826:10): [True: 0, False: 1.54k]
  ------------------
  827|      0|			target_file = (sc_path_t*) env->params[i].value;
  828|      0|			if (env->params[i].value_len < sizeof(sc_path_t) || target_file->len != 2) {
  ------------------
  |  Branch (828:8): [True: 0, False: 0]
  |  Branch (828:56): [True: 0, False: 0]
  ------------------
  829|      0|				sc_log(card->ctx, "wrong length of target file reference.\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  830|      0|				return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  831|      0|			}
  832|      0|			*p++ = 0x83;
  833|      0|			*p++ = 2;
  834|      0|			memcpy(p, target_file->value, 2);
  835|      0|			p+= 2;
  836|      0|			break;
  837|      0|	    }
  838|       |
  839|    154|	r = 0;
  840|    154|	if (env->operation == SC_SEC_OPERATION_UNWRAP || env->operation == SC_SEC_OPERATION_WRAP ||
  ------------------
  |  |   52|    308|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              	if (env->operation == SC_SEC_OPERATION_UNWRAP || env->operation == SC_SEC_OPERATION_WRAP ||
  ------------------
  |  |   51|    308|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (840:6): [True: 0, False: 154]
  |  Branch (840:51): [True: 0, False: 154]
  ------------------
  841|    154|			IS_SYMETRIC_CRYPT(env->operation)) {
  ------------------
  |  |  739|    154|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   53|    308|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   54|    154|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (739:31): [True: 0, False: 154]
  |  |  |  Branch (739:70): [True: 0, False: 154]
  |  |  ------------------
  ------------------
  842|       |		/* add IV if present */
  843|      0|		for (i = 0; i < SC_SEC_ENV_MAX_PARAMS; i++)
  ------------------
  |  |   64|      0|#define SC_SEC_ENV_MAX_PARAMS		10
  ------------------
  |  Branch (843:15): [True: 0, False: 0]
  ------------------
  844|      0|			if (env->params[i].param_type == SC_SEC_ENV_PARAM_IV) {
  ------------------
  |  |   65|      0|#define SC_SEC_ENV_PARAM_IV		1
  ------------------
  |  Branch (844:8): [True: 0, False: 0]
  ------------------
  845|      0|				r = 1;
  846|      0|				*p++ = 0x87;
  847|      0|				*p++ = (unsigned char) env->params[i].value_len;
  848|      0|				if (p + env->params[i].value_len >= sbuf + SC_MAX_APDU_BUFFER_SIZE) {
  ------------------
  |  |   34|      0|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (848:9): [True: 0, False: 0]
  ------------------
  849|      0|					sc_log(card->ctx, "IV too long.\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  850|      0|					return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  851|      0|				}
  852|      0|				memcpy(p, env->params[i].value, env->params[i].value_len);
  853|      0|				p+=(unsigned char) env->params[i].value_len;
  854|      0|				break;
  855|      0|			}
  856|      0|	}
  857|       |	/* for AES_ECB we need to reset the IV but we respect if the IV is already present */
  858|    154|	if (IS_SYMETRIC_CRYPT(env->operation) && env->algorithm == SC_ALGORITHM_AES &&
  ------------------
  |  |  739|    308|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   53|    308|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   54|    154|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (739:31): [True: 0, False: 154]
  |  |  |  Branch (739:70): [True: 0, False: 154]
  |  |  ------------------
  ------------------
              	if (IS_SYMETRIC_CRYPT(env->operation) && env->algorithm == SC_ALGORITHM_AES &&
  ------------------
  |  |   79|    154|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (858:43): [True: 0, False: 0]
  ------------------
  859|      0|			env->algorithm_flags == SC_ALGORITHM_AES_ECB && r == 0) {
  ------------------
  |  |  206|    154|#define SC_ALGORITHM_AES_ECB		 0x01000000
  ------------------
  |  Branch (859:4): [True: 0, False: 0]
  |  Branch (859:52): [True: 0, False: 0]
  ------------------
  860|      0|		*p++ = 0x87;
  861|      0|		*p++ = 16;
  862|      0|		memset(p, 0, 16);
  863|      0|		p += 16;
  864|      0|	}
  865|       |
  866|    154|	sz = p - sbuf;
  867|    154|	apdu.lc = sz;
  868|    154|	apdu.datalen = sz;
  869|    154|	apdu.data = sbuf;
  870|    154|	apdu.resplen = 0;
  871|    154|	r = (int)sz;
  872|    154|	if (apdu.datalen != 0)
  ------------------
  |  Branch (872:6): [True: 154, False: 0]
  ------------------
  873|    154|	{
  874|    154|		r = sc_transmit_apdu(card, &apdu);
  875|    154|		if (r)
  ------------------
  |  Branch (875:7): [True: 3, False: 151]
  ------------------
  876|      3|		{
  877|      3|			sc_log(card->ctx,
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  878|      3|				"%s: APDU transmit failed", sc_strerror(r));
  879|      3|			goto err;
  880|      3|		}
  881|    151|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  882|    151|		if (r)
  ------------------
  |  Branch (882:7): [True: 30, False: 121]
  ------------------
  883|     30|		{
  884|     30|			sc_log(card->ctx,
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  885|     30|				"%s: Card returned error", sc_strerror(r));
  886|     30|			goto err;
  887|     30|		}
  888|    151|	}
  889|    154|err:
  890|    154|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    154|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    154|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    154|	int _ret = r; \
  |  |  |  |  155|    154|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 154, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    154|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 121]
  |  |  |  |  ------------------
  |  |  |  |  157|    154|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    154|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    154|	return _ret; \
  |  |  |  |  163|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  891|    154|}
card-myeid.c:myeid_compute_signature:
 1198|     29|{
 1199|     29|	struct sc_context *ctx;
 1200|     29|	struct sc_apdu apdu;
 1201|     29|	u8 rbuf[MYEID_MAX_EXT_APDU_BUFFER_SIZE];
 1202|     29|	u8 sbuf[MYEID_MAX_EXT_APDU_BUFFER_SIZE];
 1203|     29|	struct myeid_private_data* priv;
 1204|     29|	int r;
 1205|     29|	size_t field_length = 0;
 1206|     29|	size_t pad_chars = 0;
 1207|       |
 1208|     29|	if (card == NULL || data == NULL || out == NULL)
  ------------------
  |  Branch (1208:6): [True: 0, False: 29]
  |  Branch (1208:22): [True: 0, False: 29]
  |  Branch (1208:38): [True: 0, False: 29]
  ------------------
 1209|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1210|     29|	ctx = card->ctx;
 1211|     29|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     29|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     29|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     29|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     29|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1212|       |
 1213|     29|	priv = (myeid_private_data_t*) card->drv_data;
 1214|     29|	sc_log(ctx, "key type %lu, key length %lu", priv->sec_env->algorithm, priv->sec_env->algorithm_ref);
  ------------------
  |  |   71|     29|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1215|       |
 1216|     29|	if (priv->sec_env->algorithm == SC_ALGORITHM_EC ) {
  ------------------
  |  |   70|     29|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1216:6): [True: 0, False: 29]
  ------------------
 1217|       |
 1218|      0|	    field_length = priv->sec_env->algorithm_ref;
 1219|       |
 1220|       |	    /* pad with zeros if needed */
 1221|      0|		if (datalen < BYTES4BITS(field_length)) {
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  |  Branch (1221:7): [True: 0, False: 0]
  ------------------
 1222|      0|			pad_chars = BYTES4BITS(field_length) - datalen;
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1223|       |
 1224|      0|			memset(sbuf, 0, pad_chars);
 1225|      0|		}
 1226|      0|	}
 1227|       |
 1228|     29|	if ((datalen + pad_chars) > sizeof(sbuf))
  ------------------
  |  Branch (1228:6): [True: 0, False: 29]
  ------------------
 1229|     29|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1230|       |
 1231|     29|	if (priv->sec_env->algorithm == SC_ALGORITHM_RSA && datalen == 256 && !priv->cap_chaining)
  ------------------
  |  |   69|     58|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1231:6): [True: 29, False: 0]
  |  Branch (1231:54): [True: 29, False: 0]
  |  Branch (1231:72): [True: 22, False: 7]
  ------------------
 1232|     22|		return myeid_compute_raw_2048_signature(card, data, datalen, out, outlen);
 1233|       |
 1234|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1235|       |		* P1:  0x9E  Resp: Digital Signature
 1236|       |		* P2:  0x9A  Cmd: Input for Digital Signature */
 1237|      7|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|      7|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1238|      7|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      7|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1239|      7|	apdu.resp = rbuf;
 1240|      7|	apdu.resplen = sizeof(rbuf);
 1241|      7|	apdu.le = 256;
 1242|      7|	memcpy(sbuf + pad_chars, data, datalen);
 1243|      7|	apdu.lc = datalen + pad_chars;
 1244|      7|	apdu.datalen = datalen + pad_chars;
 1245|       |
 1246|      7|	apdu.data = sbuf;
 1247|      7|	r = sc_transmit_apdu(card, &apdu);
 1248|      7|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1249|      4|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1250|      4|	LOG_TEST_RET(ctx, r, "compute_signature failed");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1251|       |
 1252|      2|	if (priv->sec_env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|      2|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1252:6): [True: 0, False: 2]
  ------------------
 1253|      0|		r = myeid_convert_ec_signature(ctx, priv->sec_env->algorithm_ref, apdu.resp, apdu.resplen);
 1254|      0|		LOG_TEST_RET(ctx, r, "compute_signature convert signature failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1255|      0|		apdu.resplen = r;
 1256|      0|	}
 1257|       |
 1258|      2|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (1258:6): [True: 0, False: 2]
  ------------------
 1259|      2|		LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1260|       |
 1261|      2|	memcpy(out, apdu.resp, apdu.resplen);
 1262|      2|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1263|      2|}
card-myeid.c:myeid_compute_raw_2048_signature:
 1135|     22|{
 1136|     22|	int r;
 1137|     22|	struct sc_context *ctx;
 1138|     22|	struct myeid_private_data *priv;
 1139|     22|	struct sc_apdu apdu;
 1140|     22|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1141|     22|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1142|     22|	sc_security_env_t env;
 1143|       |
 1144|     22|	ctx = card->ctx;
 1145|     22|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     22|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     22|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     22|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     22|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|       |
 1147|     22|	priv = (myeid_private_data_t *) card->drv_data;
 1148|       |
 1149|       |/* security env change - use DECIPHER operation */
 1150|     22|	memcpy(&env, priv->sec_env, sizeof(sc_security_env_t));
 1151|     22|	env.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|     22|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
 1152|     22|	env.flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|     22|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
 1153|     22|	env.flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|     22|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
 1154|     22|	env.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|     22|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
 1155|     22|	myeid_set_security_env_rsa(card, &env, 0);
 1156|       |
 1157|     22|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  293|     22|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1158|     22|	apdu.resp = rbuf;
 1159|     22|	apdu.resplen = sizeof(rbuf);
 1160|     22|	apdu.le = 0;	/* there is no response to 1st part of data */
 1161|       |
 1162|       |/* prepare 1st part of data */
 1163|     22|	sbuf[0] = 0x81;
 1164|     22|	memcpy(sbuf + 1, data, datalen / 2);
 1165|     22|	apdu.lc = datalen / 2 + 1;
 1166|     22|	apdu.datalen = apdu.lc;
 1167|     22|	apdu.data = sbuf;
 1168|       |
 1169|     22|	r = sc_transmit_apdu(card, &apdu);
 1170|     22|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     22|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     22|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     22|	int _ret = (r); \
  |  |  |  |  168|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 21]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1171|     21|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1171:6): [True: 15, False: 6]
  |  Branch (1171:26): [True: 13, False: 2]
  ------------------
 1172|       |/* prepare 2nd part of data */
 1173|     13|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     13|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1174|     13|		apdu.resp = rbuf;
 1175|     13|		apdu.resplen = sizeof(rbuf);
 1176|     13|		apdu.le = datalen;
 1177|     13|		sbuf[0] = 0x82;
 1178|     13|		memcpy(sbuf + 1, data + datalen / 2, datalen / 2);
 1179|     13|		apdu.lc = datalen / 2 + 1;
 1180|     13|		apdu.datalen = apdu.lc;
 1181|     13|		apdu.data = sbuf;
 1182|       |
 1183|     13|		r = sc_transmit_apdu(card, &apdu);
 1184|     13|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1185|       |
 1186|     12|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1186:7): [True: 4, False: 8]
  |  Branch (1186:27): [True: 2, False: 2]
  ------------------
 1187|      2|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1187:17): [True: 0, False: 2]
  ------------------
 1188|      2|			memcpy(out, apdu.resp, len);
 1189|      2|			LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      2|		}
 1191|     12|	}
 1192|     18|	LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1193|     18|}
card-myeid.c:myeid_decipher:
 1420|     88|{
 1421|     88|	int r;
 1422|     88|	myeid_private_data_t* priv;
 1423|       |
 1424|     88|	if (card == NULL || crgram == NULL || out == NULL)
  ------------------
  |  Branch (1424:6): [True: 0, False: 88]
  |  Branch (1424:22): [True: 0, False: 88]
  |  Branch (1424:40): [True: 0, False: 88]
  ------------------
 1425|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1426|       |
 1427|     88|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     88|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     88|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     88|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     88|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1428|       |
 1429|     88|	priv = (myeid_private_data_t*)card->drv_data;
 1430|       |
 1431|     88|	if (priv->sec_env && priv->sec_env->algorithm == SC_ALGORITHM_EC
  ------------------
  |  |   70|    176|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1431:6): [True: 88, False: 0]
  |  Branch (1431:23): [True: 0, False: 88]
  ------------------
 1432|      0|		&& priv->sec_env->operation == SC_SEC_OPERATION_DERIVE
  ------------------
  |  |   50|     88|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1432:6): [True: 0, False: 0]
  ------------------
 1433|      0|		&& priv->sec_env->algorithm_flags & SC_ALGORITHM_ECDH_CDH_RAW)
  ------------------
  |  |  173|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  |  Branch (1433:6): [True: 0, False: 0]
  ------------------
 1434|      0|	{
 1435|      0|		r = myeid_ecdh_derive(card, crgram, crgram_len, out, outlen);
 1436|      0|		priv->sec_env = NULL; /* clear after operation */
 1437|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1438|      0|	}
 1439|       |
 1440|     88|	r = myeid_transmit_decipher(card, 0x80, 0x86, crgram, crgram_len, out, outlen);
 1441|     88|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     88|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     88|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     88|	int _ret = r; \
  |  |  |  |  155|     88|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|     54|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     54|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     54|	} \
  |  |  |  |  162|     88|	return _ret; \
  |  |  |  |  163|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1442|     88|}
card-myeid.c:myeid_transmit_decipher:
 1365|     88|{
 1366|     88|	myeid_private_data_t *priv = card->drv_data;
 1367|     88|	struct sc_apdu apdu;
 1368|     88|	u8 rbuf[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1369|     88|	u8 sbuf[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1370|     88|	int r;
 1371|       |
 1372|     88|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     88|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     88|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     88|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     88|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|       |
 1374|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1375|       |	 * P1:  0x00  Resp: No response (unwrapping)
 1376|       |	 * P1:  0x80  Resp: Plain value
 1377|       |	 * P2:  0x84  Cmd: Cryptogram (no padding byte)
 1378|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1379|     88|	sc_format_apdu(card, &apdu, p1 ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT, 0x2A, p1, p2);
  ------------------
  |  |  294|     88|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	sc_format_apdu(card, &apdu, p1 ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT, 0x2A, p1, p2);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1379:30): [True: 88, False: 0]
  ------------------
 1380|     88|	if (p2 == 0x86) {
  ------------------
  |  Branch (1380:6): [True: 88, False: 0]
  ------------------
 1381|     88|		if (crgram_len+1 > sizeof(sbuf))
  ------------------
  |  Branch (1381:7): [True: 0, False: 88]
  ------------------
 1382|     88|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|     88|		sbuf[0] = 0; /* Padding indicator: 0x00 = No further indication */
 1384|     88|		memcpy(sbuf + 1, crgram, crgram_len);
 1385|     88|		apdu.data = sbuf;
 1386|     88|		apdu.datalen = apdu.lc = crgram_len + 1;
 1387|     88|	} else {
 1388|      0|		apdu.data = crgram;
 1389|      0|		apdu.datalen = apdu.lc = crgram_len;
 1390|      0|	}
 1391|     88|	if (p1 != 0x00) {
  ------------------
  |  Branch (1391:6): [True: 88, False: 0]
  ------------------
 1392|     88|		apdu.resp = rbuf;
 1393|     88|		apdu.resplen = sizeof(rbuf);
 1394|     88|		apdu.le = MIN(card->max_recv_size, crgram_len);
  ------------------
  |  |   69|     88|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 15, False: 73]
  |  |  ------------------
  ------------------
 1395|     88|	}
 1396|       |
 1397|       |	/* In MyEID 4.5.x, unwrapping with 2K RSA using APDU chaining doesn't work properly. Split the APDU in the old way in this case. */
 1398|     88|	if (p2 == 0x86 && crgram_len == 256 && priv && (!priv->cap_chaining || (card->version.fw_major == 45 && priv->sec_env != NULL && priv->sec_env->operation == SC_SEC_OPERATION_UNWRAP))) {
  ------------------
  |  |   52|      3|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (1398:6): [True: 88, False: 0]
  |  Branch (1398:20): [True: 23, False: 65]
  |  Branch (1398:41): [True: 23, False: 0]
  |  Branch (1398:50): [True: 18, False: 5]
  |  Branch (1398:74): [True: 3, False: 2]
  |  Branch (1398:106): [True: 3, False: 0]
  |  Branch (1398:131): [True: 0, False: 3]
  ------------------
 1399|     18|		r = myeid_transmit_decipher_pi_split(card, &apdu, sbuf);
 1400|     70|	} else {
 1401|     70|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     70|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1402|     70|		r = sc_transmit_apdu(card, &apdu);
 1403|     70|	}
 1404|     88|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 74]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1405|       |
 1406|     74|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1407|     74|	LOG_TEST_RET(card->ctx, r, "DECIPHER returned error");
  ------------------
  |  |  174|     74|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     74|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     74|	int _ret = (r); \
  |  |  |  |  168|     74|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 55]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1408|       |
 1409|     55|	if (out && outlen) {
  ------------------
  |  Branch (1409:6): [True: 55, False: 0]
  |  Branch (1409:13): [True: 55, False: 0]
  ------------------
 1410|     55|		outlen = MIN(apdu.resplen, outlen);
  ------------------
  |  |   69|     55|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 37, False: 18]
  |  |  ------------------
  ------------------
 1411|     55|		memcpy(out, apdu.resp, outlen);
 1412|     55|	} else {
 1413|      0|		outlen = 0;
 1414|      0|	}
 1415|     55|	LOG_FUNC_RETURN(card->ctx, (int)outlen);
  ------------------
  |  |  164|     55|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     55|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     55|	int _ret = r; \
  |  |  |  |  155|     55|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|     54|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     54|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     54|	} \
  |  |  |  |  162|     55|	return _ret; \
  |  |  |  |  163|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|     55|}
card-myeid.c:myeid_transmit_decipher_pi_split:
 1324|     18|{
 1325|       |	/* MyEID before 4.5.x does not support APDU chaining. The payload
 1326|       |	 * is split to two regular APDUs and Padding Indicator field is used to
 1327|       |	 * describe which slice it is. */
 1328|     18|	size_t crgram_len = apdu->lc - 1;
 1329|     18|	size_t crgram_half = crgram_len / 2;
 1330|     18|	size_t resplen = apdu->resplen;
 1331|     18|	unsigned char *resp = apdu->resp;
 1332|     18|	int r;
 1333|       |
 1334|     18|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     18|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     18|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     18|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     18|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|       |
 1336|       |	/* Send 1st part, no response */
 1337|     18|	apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     18|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1338|     18|	apdu->data = &sbuf[0];
 1339|     18|	apdu->datalen = apdu->lc = crgram_half + 1;
 1340|     18|	apdu->resp = 0;
 1341|     18|	apdu->resplen = 0;
 1342|     18|	apdu->le = 0;
 1343|     18|	sbuf[0] = 0x81;			/* Padding Indicator, 0x81 = First half */
 1344|       |
 1345|     18|	r = sc_transmit_apdu(card, apdu);
 1346|     18|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1347|     17|	if (apdu->sw1 != 0x90 || apdu->sw2 != 0x00)
  ------------------
  |  Branch (1347:6): [True: 9, False: 8]
  |  Branch (1347:27): [True: 1, False: 7]
  ------------------
 1348|     10|		return 0;
 1349|       |
 1350|       |	/* Send 2nd part, expect response */
 1351|      7|	apdu->cse = resplen ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  294|      7|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	apdu->cse = resplen ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|      7|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1351:14): [True: 7, False: 0]
  ------------------
 1352|      7|	apdu->data = &sbuf[crgram_half];
 1353|      7|	apdu->datalen = apdu->lc = crgram_len - crgram_half + 1;
 1354|      7|	apdu->resp = resp;
 1355|      7|	apdu->resplen = resplen;
 1356|      7|	apdu->le = resplen ? MIN(card->max_recv_size, crgram_len) : 0;
  ------------------
  |  |   69|      7|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 6, False: 1]
  |  |  ------------------
  ------------------
  |  Branch (1356:13): [True: 7, False: 0]
  ------------------
 1357|      7|	sbuf[crgram_half] = 0x82;	/* Padding Indicator, 0x82 = Second half */
 1358|       |
 1359|      7|	r = sc_transmit_apdu(card, apdu);
 1360|      7|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1361|      7|}
card-myeid.c:myeid_process_fci:
  442|    108|{
  443|    108|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  444|    108|	size_t taglen = 0;
  445|    108|	const u8 *tag = NULL;
  446|    108|	int r;
  447|       |
  448|    108|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    108|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    108|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    108|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    108|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  449|    108|	r = iso_ops->process_fci(card, file, buf, buflen);
  450|    108|	if (r < 0)
  ------------------
  |  Branch (450:6): [True: 0, False: 108]
  ------------------
  451|    108|	 LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  452|       |
  453|    108|	if(file->type == SC_FILE_EF_UNKNOWN)
  ------------------
  |  |  220|    108|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  |  Branch (453:5): [True: 77, False: 31]
  ------------------
  454|     77|	{
  455|     77|		tag = sc_asn1_find_tag(NULL, buf, buflen, 0x82, &taglen);
  456|     77|		if (tag != NULL && taglen > 0 && *tag == 17)
  ------------------
  |  Branch (456:7): [True: 37, False: 40]
  |  Branch (456:22): [True: 30, False: 7]
  |  Branch (456:36): [True: 10, False: 20]
  ------------------
  457|     10|		{
  458|     10|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     10|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  459|     10|		}
  460|     77|	}
  461|    108|	if(file->sec_attr_len >= 3)
  ------------------
  |  Branch (461:5): [True: 55, False: 53]
  ------------------
  462|     55|	{
  463|     55|		sc_log(card->ctx, "id (%X) sec_attr (%X %X %X)", file->id,
  ------------------
  |  |   71|     55|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|     55|			file->sec_attr[0],file->sec_attr[1],file->sec_attr[2]);
  465|     55|	}
  466|       |
  467|    108|	priv->card_state = file->status;
  468|    108|	switch (file->status) {
  469|      3|		case SC_FILE_STATUS_CREATION:
  ------------------
  |  |  240|      3|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (469:3): [True: 3, False: 105]
  ------------------
  470|      3|			file->acl_inactive = 1;
  471|      3|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_CREATION", file->id);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|      3|			break;
  473|      6|		case SC_FILE_STATUS_ACTIVATED:
  ------------------
  |  |  236|      6|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  |  Branch (473:3): [True: 6, False: 102]
  ------------------
  474|      6|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_ACTIVATED", file->id);
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  475|      6|			break;
  476|     99|		default:
  ------------------
  |  Branch (476:3): [True: 99, False: 9]
  ------------------
  477|     99|			sc_log(card->ctx, "File id (%X) unusual status (0x%X)", file->id, file->status);
  ------------------
  |  |   71|     99|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  478|    108|	}
  479|       |
  480|    108|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|    108|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    108|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    108|	int _ret = r; \
  |  |  |  |  155|    108|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    108|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  157|    108|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    108|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    108|	return _ret; \
  |  |  |  |  163|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|    108|}
card-myeid.c:myeid_card_ctl:
 1858|    148|{
 1859|    148|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    148|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1860|    148|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    148|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    148|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    148|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    148|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 148]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1861|       |
 1862|    148|	switch(cmd) {
  ------------------
  |  Branch (1862:9): [True: 148, False: 0]
  ------------------
 1863|      0|	case SC_CARDCTL_MYEID_PUTDATA:
  ------------------
  |  Branch (1863:2): [True: 0, False: 148]
  ------------------
 1864|      0|		r = myeid_putdata(card,
 1865|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1866|      0|		break;
 1867|      0|	case SC_CARDCTL_MYEID_GETDATA:
  ------------------
  |  Branch (1867:2): [True: 0, False: 148]
  ------------------
 1868|      0|		r = myeid_getdata(card,
 1869|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1870|      0|		break;
 1871|      0|	case SC_CARDCTL_MYEID_GENERATE_STORE_KEY:
  ------------------
  |  Branch (1871:2): [True: 0, False: 148]
  ------------------
 1872|      0|		r = myeid_generate_store_key(card,
 1873|      0|			(struct sc_cardctl_myeid_gen_store_key_info *) ptr);
 1874|      0|		break;
 1875|      0|	case SC_CARDCTL_MYEID_ACTIVATE_CARD:
  ------------------
  |  Branch (1875:2): [True: 0, False: 148]
  ------------------
 1876|      0|		r = myeid_activate_card(card);
 1877|      0|		break;
 1878|    148|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1878:2): [True: 148, False: 0]
  ------------------
 1879|    148|		r = myeid_get_serialnr(card, (sc_serial_number_t *)ptr);
 1880|    148|		break;
 1881|      0|	case SC_CARDCTL_GET_CHANGE_COUNTER:
  ------------------
  |  Branch (1881:2): [True: 0, False: 148]
  ------------------
 1882|      0|		r = myeid_get_change_counter(card, (size_t *)ptr);
 1883|      0|		break;
 1884|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1884:2): [True: 0, False: 148]
  ------------------
 1885|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1885:2): [True: 0, False: 148]
  ------------------
 1886|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1886:2): [True: 0, False: 148]
  ------------------
 1887|      0|		break;
 1888|    148|	}
 1889|    148|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    148|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    148|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    148|	int _ret = r; \
  |  |  |  |  155|    148|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 148, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    148|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    146|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 146, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|    148|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    148|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    148|	return _ret; \
  |  |  |  |  163|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1890|    148|}
card-myeid.c:myeid_get_serialnr:
 1775|    148|{
 1776|    148|	int r;
 1777|    148|	u8  rbuf[256];
 1778|       |
 1779|    148|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    148|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    148|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    148|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    148|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 148]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1780|       |
 1781|       |	/* if number cached, get it
 1782|       |	if(card->serialnr.value) {
 1783|       |		memcpy(serial, &card->serialnr, sizeof(*serial));
 1784|       |		LOG_FUNC_RETURN(card->ctx, r);
 1785|       |	}*/
 1786|       |
 1787|       |	/* get number from card */
 1788|    148|	r = myeid_get_info(card, rbuf, sizeof(rbuf));
 1789|    148|	LOG_TEST_RET(card->ctx, r,  "Get applet info failed");
  ------------------
  |  |  174|    148|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    148|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    148|	int _ret = (r); \
  |  |  |  |  168|    148|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 146, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|    146|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    146|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    146|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    146|		return _ret; \
  |  |  |  |  172|    146|	} \
  |  |  |  |  173|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1790|       |
 1791|       |	/* cache serial number */
 1792|      2|	memcpy(card->serialnr.value, &rbuf[8], 10);
 1793|      2|	card->serialnr.len = 10;
 1794|       |
 1795|       |	/* copy and return serial number */
 1796|      2|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1797|       |
 1798|      2|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1799|      2|}
card-myeid.c:myeid_pin_cmd:
  666|    219|{
  667|    219|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  668|       |
  669|    219|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    219|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    219|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    219|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    219|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 219]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  670|       |
  671|    219|	sc_log(card->ctx, "cmd (%d), ref (%d), pin1 len(%zu), pin2 len (%zu), puk ref (%d)\n",
  ------------------
  |  |   71|    219|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  672|    219|			data->cmd, data->pin_reference, data->pin1.len, data->pin2.len, data->puk_reference);
  673|       |
  674|    219|	if(data->pin1.len > 8 || data->pin2.len > 8)
  ------------------
  |  Branch (674:5): [True: 0, False: 219]
  |  Branch (674:27): [True: 0, False: 219]
  ------------------
  675|    219|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  676|       |
  677|    219|	data->pin1.pad_length = data->pin2.pad_length = 8;
  678|    219|	data->pin1.pad_char = data->pin2.pad_char = 0xFF;
  679|       |
  680|    219|	if (data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|    219|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (680:6): [True: 0, False: 219]
  ------------------
  681|       |		/* In case the PUK reference is set, the PIN is being unblocked implicitly using a global unblocker PIN instead of the
  682|       |		directly associated PUK. In this case, we must issue a VERIFY command first and then the RESET RETRY COUNTER command with only
  683|       |		the new PIN in the data field. */
  684|       |
  685|      0|		struct sc_pin_cmd_data global_unblocker_verif_data;
  686|      0|		int r;
  687|       |
  688|      0|		if (data->puk_reference != 0) {
  ------------------
  |  Branch (688:7): [True: 0, False: 0]
  ------------------
  689|       |			/* Call the iso driver to do the VERIFY */
  690|      0|			memset(&global_unblocker_verif_data, 0, sizeof(global_unblocker_verif_data));
  691|      0|			global_unblocker_verif_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  692|      0|			global_unblocker_verif_data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  693|      0|			global_unblocker_verif_data.pin1 = data->pin1;
  694|      0|			global_unblocker_verif_data.pin_reference = data->puk_reference;
  695|      0|			global_unblocker_verif_data.flags = data->flags;
  696|      0|			r = iso_ops->pin_cmd(card, &global_unblocker_verif_data);
  697|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  698|       |
  699|      0|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (699:8): [True: 0, False: 0]
  ------------------
  700|      0|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  701|      0|		}
  702|       |
  703|       |		/* In case puk_reference is 0 and pin1 is empty, we may have end up here from a C_InitPIN call and a pin is being unblocked using the
  704|       |		'user_pin_unblock_style = init_pin_in_so_session' workflow. In this case, the SO-PIN, used as the unblocking PIN, should already have been authenticated
  705|       |		in a separate C_Login call and we don't need the PUK here */
  706|       |
  707|      0|		if (data->puk_reference != 0 || data->pin1.len == 0) {
  ------------------
  |  Branch (707:7): [True: 0, False: 0]
  |  Branch (707:35): [True: 0, False: 0]
  ------------------
  708|      0|			memset(&data->pin1, 0, sizeof(struct sc_pin_cmd_pin));
  709|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  710|      0|			data->flags |= SC_PIN_CMD_NEED_PADDING; /* we don't have this set in the C_InitPIN use case. Perhaps should be fixed at higher level */
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  711|      0|			struct sc_apdu apdu;
  712|      0|			u8 buf[SC_MAX_APDU_BUFFER_SIZE];
  713|       |
  714|       |			/* Let iso driver build the RESET RETRY COUNTER APDU, but we'll have to modify it before transmitting it. */
  715|      0|			r = iso7816_build_pin_apdu(card, &apdu, data, buf, sizeof(buf));
  716|       |
  717|      0|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (717:8): [True: 0, False: 0]
  ------------------
  718|      0|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  719|       |
  720|       |			/* MyEID's implementation of unblocking a PIN implicitly contradicts with ISO 7816-4 here. The iso driver properly sets P2=0x02
  721|       |			while MyEID expects 0x00 */
  722|      0|			apdu.p1 = 0x00;
  723|       |
  724|      0|			r = sc_transmit_apdu(card, &apdu);
  725|       |
  726|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|      0|			LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  728|      0|		}
  729|      0|	}
  730|       |
  731|    219|	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  415|    438|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  240|     73|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (731:6): [True: 73, False: 146]
  |  Branch (731:40): [True: 71, False: 2]
  ------------------
  732|     71|		sc_log(card->ctx, "Card in creation state, no need to verify");
  ------------------
  |  |   71|     71|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  733|     71|		return SC_SUCCESS;
  ------------------
  |  |   28|     71|#define SC_SUCCESS				0
  ------------------
  734|     71|	}
  735|       |
  736|    148|	LOG_FUNC_RETURN(card->ctx, iso_ops->pin_cmd(card, data));
  ------------------
  |  |  164|    148|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    148|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    148|	int _ret = r; \
  |  |  |  |  155|    148|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 148, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    148|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 134]
  |  |  |  |  ------------------
  |  |  |  |  157|    148|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    148|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    148|	return _ret; \
  |  |  |  |  163|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|    148|}

sc_get_npa_driver:
  810|  15.2k|{
  811|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  812|       |
  813|  15.2k|	npa_ops = *iso_drv->ops;
  814|  15.2k|	npa_ops.match_card = npa_match_card;
  815|  15.2k|	npa_ops.init = npa_init;
  816|  15.2k|	npa_ops.finish = npa_finish;
  817|  15.2k|	npa_ops.set_security_env = npa_set_security_env;
  818|  15.2k|	npa_ops.pin_cmd = npa_pin_cmd;
  819|  15.2k|	npa_ops.logout = npa_logout;
  820|       |
  821|  15.2k|	return &npa_drv;
  822|  15.2k|}
card-npa.c:npa_match_card:
  153|  2.64k|{
  154|  2.64k|	unsigned char dir_content[sizeof dir_content_ref];
  155|  2.64k|	unsigned char id[] = {0x2F, 0x00};
  156|  2.64k|	sc_apdu_t select_ef_dir;
  157|       |
  158|  2.64k|	sc_format_apdu_ex(&select_ef_dir, 0x00, 0xA4, 0x02, 0x0C, id, sizeof id, NULL, 0);
  159|       |
  160|  2.64k|	if (SC_SUCCESS == sc_select_file(card, sc_get_mf_path(), NULL)
  ------------------
  |  |   28|  2.64k|#define SC_SUCCESS				0
  ------------------
  |  Branch (160:6): [True: 31, False: 2.61k]
  ------------------
  161|     31|			&& SC_SUCCESS == sc_transmit_apdu(card, &select_ef_dir)
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
  |  Branch (161:7): [True: 30, False: 1]
  ------------------
  162|     30|			&& select_ef_dir.sw1 == 0x90 && select_ef_dir.sw2 == 0x00
  ------------------
  |  Branch (162:7): [True: 25, False: 5]
  |  Branch (162:36): [True: 22, False: 3]
  ------------------
  163|     22|			&& sizeof dir_content == sc_read_binary(card, 0, dir_content, sizeof dir_content, 0)
  ------------------
  |  Branch (163:7): [True: 9, False: 13]
  ------------------
  164|      9|			&& 0 == memcmp(dir_content_ref, dir_content, sizeof dir_content))
  ------------------
  |  Branch (164:7): [True: 0, False: 9]
  ------------------
  165|      0|		return 1;
  166|       |
  167|  2.64k|	return 0;
  168|  2.64k|}

sc_get_nqApplet_driver:
  471|  15.2k|{
  472|  15.2k|	sc_card_driver_t *iso_driver = sc_get_iso7816_driver();
  473|       |
  474|  15.2k|	if (iso_operations == NULL) {
  ------------------
  |  Branch (474:6): [True: 1, False: 15.2k]
  ------------------
  475|      1|		iso_operations = iso_driver->ops;
  476|      1|	}
  477|       |
  478|  15.2k|	nqapplet_operations = *iso_driver->ops;
  479|       |
  480|       |	/* supported operations */
  481|  15.2k|	nqapplet_operations.match_card = nqapplet_match_card;
  482|  15.2k|	nqapplet_operations.init = nqapplet_init;
  483|  15.2k|	nqapplet_operations.finish = nqapplet_finish;
  484|  15.2k|	nqapplet_operations.get_response = nqapplet_get_response;
  485|  15.2k|	nqapplet_operations.get_challenge = nqapplet_get_challenge;
  486|  15.2k|	nqapplet_operations.logout = nqapplet_logout;
  487|  15.2k|	nqapplet_operations.set_security_env = nqapplet_set_security_env;
  488|  15.2k|	nqapplet_operations.decipher = nqapplet_decipher;
  489|  15.2k|	nqapplet_operations.compute_signature = nqapplet_compute_signature;
  490|  15.2k|	nqapplet_operations.check_sw = nqapplet_check_sw;
  491|  15.2k|	nqapplet_operations.get_data = nqapplet_get_data;
  492|  15.2k|	nqapplet_operations.select_file = nqapplet_select_file;
  493|  15.2k|	nqapplet_operations.card_ctl = nqapplet_card_ctl;
  494|  15.2k|	nqapplet_operations.pin_cmd = nqapplet_pin_cmd;
  495|       |
  496|       |	/* unsupported operations */
  497|  15.2k|	nqapplet_operations.read_binary = NULL;
  498|  15.2k|	nqapplet_operations.write_binary = NULL;
  499|  15.2k|	nqapplet_operations.update_binary = NULL;
  500|  15.2k|	nqapplet_operations.erase_binary = NULL;
  501|  15.2k|	nqapplet_operations.read_record = NULL;
  502|  15.2k|	nqapplet_operations.write_record = NULL;
  503|  15.2k|	nqapplet_operations.append_record = NULL;
  504|  15.2k|	nqapplet_operations.update_record = NULL;
  505|       |
  506|  15.2k|	nqapplet_operations.verify = NULL;
  507|  15.2k|	nqapplet_operations.restore_security_env = NULL;
  508|  15.2k|	nqapplet_operations.change_reference_data = NULL;
  509|  15.2k|	nqapplet_operations.reset_retry_counter = NULL;
  510|  15.2k|	nqapplet_operations.create_file = NULL;
  511|  15.2k|	nqapplet_operations.delete_file = NULL;
  512|  15.2k|	nqapplet_operations.list_files = NULL;
  513|  15.2k|	nqapplet_operations.process_fci = NULL;
  514|  15.2k|	nqapplet_operations.construct_fci = NULL;
  515|  15.2k|	nqapplet_operations.put_data = NULL;
  516|  15.2k|	nqapplet_operations.delete_record = NULL;
  517|  15.2k|	nqapplet_operations.read_public_key = NULL;
  518|       |
  519|       |	/* let iso driver handle these operations
  520|       |	nqapplet_operations.card_reader_lock_obtained;
  521|       |	nqapplet_operations.wrap;
  522|       |	nqapplet_operations.unwrap;
  523|       |	*/
  524|       |
  525|  15.2k|	return &nqapplet_driver;
  526|  15.2k|}
card-nqApplet.c:nqapplet_match_card:
  143|  2.46k|{
  144|  2.46k|	int rv = _sc_match_atr(card, nqapplet_atrs, &card->type);
  145|  2.46k|	return (rv >= 0);
  146|  2.46k|}

sc_get_oberthur_driver:
 2319|  15.2k|{
 2320|  15.2k|	return sc_get_driver();
 2321|  15.2k|}
card-oberthur.c:sc_get_driver:
 2288|  15.2k|{
 2289|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2289:6): [True: 1, False: 15.2k]
  ------------------
 2290|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2291|       |
 2292|  15.2k|	auth_ops = *iso_ops;
 2293|  15.2k|	auth_ops.match_card = auth_match_card;
 2294|  15.2k|	auth_ops.init = auth_init;
 2295|  15.2k|	auth_ops.finish = auth_finish;
 2296|  15.2k|	auth_ops.select_file = auth_select_file;
 2297|  15.2k|	auth_ops.list_files = auth_list_files;
 2298|  15.2k|	auth_ops.delete_file = auth_delete_file;
 2299|  15.2k|	auth_ops.create_file = auth_create_file;
 2300|  15.2k|	auth_ops.read_binary = auth_read_binary;
 2301|  15.2k|	auth_ops.update_binary = auth_update_binary;
 2302|  15.2k|	auth_ops.read_record = auth_read_record;
 2303|  15.2k|	auth_ops.delete_record = auth_delete_record;
 2304|  15.2k|	auth_ops.card_ctl = auth_card_ctl;
 2305|  15.2k|	auth_ops.set_security_env = auth_set_security_env;
 2306|  15.2k|	auth_ops.restore_security_env = auth_restore_security_env;
 2307|  15.2k|	auth_ops.compute_signature = auth_compute_signature;
 2308|  15.2k|	auth_ops.decipher = auth_decipher;
 2309|  15.2k|	auth_ops.process_fci = auth_process_fci;
 2310|  15.2k|	auth_ops.pin_cmd = auth_pin_cmd;
 2311|  15.2k|	auth_ops.logout = auth_logout;
 2312|  15.2k|	auth_ops.check_sw = auth_check_sw;
 2313|  15.2k|	return &auth_drv;
 2314|  15.2k|}
card-oberthur.c:auth_match_card:
  204|  12.0k|{
  205|  12.0k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 11.2k, False: 799]
  ------------------
  206|  11.2k|		return 0;
  207|    799|	else
  208|    799|		return 1;
  209|  12.0k|}
card-oberthur.c:auth_init:
  214|    799|{
  215|    799|	struct auth_private_data *data;
  216|    799|	struct sc_path path;
  217|    799|	unsigned long flags;
  218|    799|	int rv = 0;
  219|       |
  220|    799|	data = calloc(1, sizeof(struct auth_private_data));
  221|    799|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 799]
  ------------------
  222|    799|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  223|       |
  224|    799|	card->cla = 0x00;
  225|    799|	card->drv_data = data;
  226|       |
  227|    799|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    799|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    799|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    799|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    799|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 46, False: 753]
  ------------------
  231|     46|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   71|     46|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  232|     46|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     46|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     46|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to initialize");
  ------------------
  |  |  184|     46|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     46|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     46|	int _ret = (r); \
  |  |  |  |  178|     46|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 46, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     46|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     46|		goto err; \
  |  |  |  |  182|     46|	} \
  |  |  |  |  183|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     46|	}
  235|       |
  236|    753|	sc_format_path("3F00", &path);
  237|    753|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    799|err:
  240|    799|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    799|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 753, False: 46]
  ------------------
  241|    753|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    753|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    753|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    753|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  106|    753|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    753|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    753|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    753|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    753|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    753|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    753|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    753|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    753|	} else {
  249|     46|		free(card->drv_data);
  250|     46|		card->drv_data = NULL;
  251|     46|	}
  252|       |
  253|    799|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    799|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    799|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    799|	int _ret = r; \
  |  |  |  |  155|    799|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 799, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    799|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 46, False: 753]
  |  |  |  |  ------------------
  |  |  |  |  157|    799|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    799|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    799|	return _ret; \
  |  |  |  |  163|    799|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    799|}
card-oberthur.c:auth_select_aid:
  145|    799|{
  146|    799|	struct sc_apdu apdu;
  147|    799|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    799|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    799|	int rv, ii;
  150|    799|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    799|	rv = gp_select_card_manager(card);
  154|    799|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    799|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    799|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    799|	int _ret = (r); \
  |  |  |  |  168|    799|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 774]
  |  |  |  |  ------------------
  |  |  |  |  169|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     25|		return _ret; \
  |  |  |  |  172|     25|	} \
  |  |  |  |  173|    799|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 774]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    774|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    774|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    774|	apdu.cla = 0x80;
  159|    774|	apdu.le = 0x2D;
  160|    774|	apdu.resplen = 0x30;
  161|    774|	apdu.resp = apdu_resp;
  162|       |
  163|    774|	rv = sc_transmit_apdu(card, &apdu);
  164|    774|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    774|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    774|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    774|	int _ret = (r); \
  |  |  |  |  168|    774|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 772]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|    774|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 772]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    772|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 9, False: 763]
  ------------------
  166|      9|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect length");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      9|	}
  168|    763|	card->serialnr.len = 4;
  169|    763|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  3.81k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 3.05k, False: 763]
  ------------------
  172|  3.05k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    763|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   71|    763|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|       |
  176|    763|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    763|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    763|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    763|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    763|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    763|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    763|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    763|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    763|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    763|	int _ret = (r); \
  |  |  |  |  168|    763|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 757]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    763|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 757]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    757|	sc_format_path("3F00", &tmp_path);
  185|    757|	sc_file_free(auth_current_df);
  186|    757|	auth_current_df = NULL;
  187|    757|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    757|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    757|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    757|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    757|	int _ret = (r); \
  |  |  |  |  168|    757|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 753]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|    757|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 753]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    753|	sc_file_free(auth_current_ef);
  191|    753|	auth_current_ef = NULL;
  192|    753|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    753|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    753|	data->aid_len = lenAidAuthentIC_V5;
  196|    753|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    753|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    753|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    753|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    753|	int _ret = r; \
  |  |  |  |  155|    753|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 753, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    753|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 753]
  |  |  |  |  ------------------
  |  |  |  |  157|    753|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    753|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    753|	return _ret; \
  |  |  |  |  163|    753|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    753|}
card-oberthur.c:auth_finish:
  137|    753|{
  138|    753|	free(card->drv_data);
  139|    753|	return SC_SUCCESS;
  ------------------
  |  |   28|    753|#define SC_SUCCESS				0
  ------------------
  140|    753|}
card-oberthur.c:auth_select_file:
  443|  12.8k|{
  444|  12.8k|	struct sc_path path;
  445|  12.8k|	struct sc_file *tmp_file = NULL;
  446|  12.8k|	size_t offs, ii;
  447|  12.8k|	int rv;
  448|       |
  449|  12.8k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (449:6): [True: 0, False: 12.8k]
  |  Branch (449:22): [True: 0, False: 12.8k]
  ------------------
  450|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  451|       |
  452|  12.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  12.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|       |
  454|  12.8k|	memcpy(&path, in_path, sizeof(struct sc_path));
  455|       |
  456|  12.8k|	if (!auth_current_df)
  ------------------
  |  Branch (456:6): [True: 0, False: 12.8k]
  ------------------
  457|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  458|       |
  459|  12.8k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  12.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  460|  12.8k|			in_path->type, sc_print_path(in_path), file_out);
  461|  12.8k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  12.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  12.8k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  463|  12.8k|	if (auth_current_ef)
  ------------------
  |  Branch (463:6): [True: 7.78k, False: 5.08k]
  ------------------
  464|  7.78k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   71|  7.78k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  465|  12.8k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  466|       |
  467|  12.8k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  25.7k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  12.7k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (467:6): [True: 102, False: 12.7k]
  |  Branch (467:42): [True: 6.08k, False: 6.68k]
  ------------------
  468|  6.18k|		sc_file_free(auth_current_ef);
  469|  6.18k|		auth_current_ef = NULL;
  470|       |
  471|  6.18k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  472|  6.18k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  6.18k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.18k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.18k|	int _ret = (r); \
  |  |  |  |  168|  6.18k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.31k, False: 3.87k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.31k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.31k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.31k|		return _ret; \
  |  |  |  |  172|  2.31k|	} \
  |  |  |  |  173|  6.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|  3.87k|		if (!tmp_file)
  ------------------
  |  Branch (473:7): [True: 0, False: 3.87k]
  ------------------
  474|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  475|       |
  476|  3.87k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  3.87k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (476:7): [True: 55, False: 3.81k]
  ------------------
  477|     55|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  478|     55|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (478:8): [True: 55, False: 0]
  ------------------
  479|     55|				tmp_file->path.len -= 2;
  480|       |
  481|     55|			sc_file_free(auth_current_df);
  482|     55|			auth_current_df = NULL;
  483|     55|			sc_file_dup(&auth_current_df, tmp_file);
  484|  3.81k|		} else {
  485|  3.81k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  3.81k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (485:8): [True: 93, False: 3.72k]
  ------------------
  486|     93|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  487|       |
  488|     93|				sc_file_free(auth_current_df);
  489|     93|				auth_current_df = NULL;
  490|     93|				sc_file_dup(&auth_current_df, tmp_file);
  491|  3.72k|			} else {
  492|  3.72k|				sc_file_free(auth_current_ef);
  493|  3.72k|				auth_current_ef = NULL;
  494|       |
  495|  3.72k|				sc_file_dup(&auth_current_ef, tmp_file);
  496|  3.72k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  497|  3.72k|			}
  498|  3.81k|		}
  499|  3.87k|		if (file_out) {
  ------------------
  |  Branch (499:7): [True: 3.27k, False: 596]
  ------------------
  500|  3.27k|			sc_file_free(*file_out);
  501|  3.27k|			sc_file_dup(file_out, tmp_file);
  502|  3.27k|		}
  503|       |
  504|  3.87k|		sc_file_free(tmp_file);
  505|  6.68k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  6.68k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (505:13): [True: 1.43k, False: 5.25k]
  ------------------
  506|  1.43k|		rv = iso_ops->select_file(card, &path, NULL);
  507|  1.43k|		if (rv) {
  ------------------
  |  Branch (507:7): [True: 1.38k, False: 49]
  ------------------
  508|  1.38k|			sc_file_free(auth_current_ef);
  509|  1.38k|			auth_current_ef = NULL;
  510|  1.38k|		}
  511|  1.43k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  1.43k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.43k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.43k|	int _ret = (r); \
  |  |  |  |  168|  1.43k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.38k, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.38k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.38k|		return _ret; \
  |  |  |  |  172|  1.38k|	} \
  |  |  |  |  173|  1.43k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|  5.25k|	} else {
  513|  10.5k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (513:18): [True: 9.75k, False: 753]
  |  Branch (513:37): [True: 5.38k, False: 4.36k]
  ------------------
  514|  5.38k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (514:8): [True: 107, False: 5.27k]
  ------------------
  515|  5.27k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (515:6): [True: 29, False: 5.25k]
  ------------------
  516|    136|				break;
  517|       |
  518|  5.25k|		sc_log(card->ctx, "offs %zu", offs);
  ------------------
  |  |   71|  5.25k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  519|  5.25k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (519:7): [True: 5.21k, False: 40]
  |  Branch (519:15): [True: 96, False: 5.11k]
  ------------------
  520|     96|			size_t deep = auth_current_df->path.len - offs;
  521|       |
  522|     96|			sc_log(card->ctx, "deep %zu", deep);
  ------------------
  |  |   71|     96|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|    151|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (523:17): [True: 102, False: 49]
  ------------------
  524|    102|				struct sc_path tmp_path;
  525|       |
  526|    102|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  527|    102|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|    102|#define SC_PATH_TYPE_PARENT		5
  ------------------
  528|       |
  529|    102|				if (file_out) {
  ------------------
  |  Branch (529:9): [True: 26, False: 76]
  ------------------
  530|     26|					sc_file_free(*file_out);
  531|     26|					*file_out = NULL;
  532|     26|				}
  533|       |
  534|    102|				rv = auth_select_file (card, &tmp_path, file_out);
  535|    102|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|    102|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    102|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    102|	int _ret = (r); \
  |  |  |  |  168|    102|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 47, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  169|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     47|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     47|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     47|		return _ret; \
  |  |  |  |  172|     47|	} \
  |  |  |  |  173|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 55]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    102|			}
  537|     96|		}
  538|       |
  539|  5.20k|		if (path.len > offs) {
  ------------------
  |  Branch (539:7): [True: 4.45k, False: 753]
  ------------------
  540|  4.45k|			struct sc_path tmp_path;
  541|       |
  542|  4.45k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  543|  4.45k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  4.45k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  544|  4.45k|			tmp_path.len = 2;
  545|       |
  546|  8.27k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (546:17): [True: 6.08k, False: 2.18k]
  ------------------
  547|  6.08k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  548|       |
  549|  6.08k|				if (file_out) {
  ------------------
  |  Branch (549:9): [True: 4.62k, False: 1.45k]
  ------------------
  550|  4.62k|					sc_file_free(*file_out);
  551|  4.62k|					*file_out = NULL;
  552|  4.62k|				}
  553|       |
  554|  6.08k|				rv = auth_select_file(card, &tmp_path, file_out);
  555|  6.08k|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  6.08k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.08k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.08k|	int _ret = (r); \
  |  |  |  |  168|  6.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.26k, False: 3.81k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.26k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.26k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.26k|		return _ret; \
  |  |  |  |  172|  2.26k|	} \
  |  |  |  |  173|  6.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  6.08k|			}
  557|  4.45k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (557:14): [True: 753, False: 0]
  |  Branch (557:38): [True: 0, False: 753]
  ------------------
  558|      0|			if (sc_compare_path(&path, &auth_current_df->path) && file_out) {
  ------------------
  |  Branch (558:8): [True: 0, False: 0]
  |  Branch (558:58): [True: 0, False: 0]
  ------------------
  559|      0|				sc_file_free(*file_out);
  560|      0|				sc_file_dup(file_out, auth_current_df);
  561|      0|			} else  if (auth_current_ef && file_out) {
  ------------------
  |  Branch (561:16): [True: 0, False: 0]
  |  Branch (561:35): [True: 0, False: 0]
  ------------------
  562|      0|				sc_file_free(*file_out);
  563|      0|				sc_file_dup(file_out, auth_current_ef);
  564|      0|			} else {
  565|      0|				LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "No current EF");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|      0|			}
  567|      0|		}
  568|  5.20k|	}
  569|       |
  570|  6.85k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  6.85k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.85k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.85k|	int _ret = r; \
  |  |  |  |  155|  6.85k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.85k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6.85k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.85k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.85k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.85k|	return _ret; \
  |  |  |  |  163|  6.85k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|  6.85k|}
card-oberthur.c:auth_read_binary:
 2102|  10.1k|{
 2103|  10.1k|	int rv;
 2104|  10.1k|	size_t sz;
 2105|  10.1k|	struct sc_pkcs15_bignum bn[2];
 2106|  10.1k|	unsigned char *out = NULL;
 2107|  10.1k|	bn[0].data = NULL;
 2108|  10.1k|	bn[1].data = NULL;
 2109|       |
 2110|  10.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  10.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2111|       |
 2112|  10.1k|	if (!auth_current_ef)
  ------------------
  |  Branch (2112:6): [True: 19, False: 10.0k]
  ------------------
 2113|  10.1k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid auth_current_ef");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2114|       |
 2115|  10.0k|	sc_log(card->ctx, "offset %i; size %zu; flags 0x%lX", offset, count, flags ? *flags : 0);
  ------------------
  |  |   71|  20.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 10.0k]
  |  |  ------------------
  ------------------
 2116|  10.0k|	sc_log(card->ctx, "last selected : magic %X; ef %X",
  ------------------
  |  |   71|  10.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2117|  10.0k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2118|       |
 2119|  10.0k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2119:6): [True: 1, False: 10.0k]
  ------------------
 2120|  10.0k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid file offset");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|       |
 2122|  10.0k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   56|  20.1k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2122:6): [True: 10.0k, False: 0]
  ------------------
 2123|  10.0k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2123:4): [True: 181, False: 9.90k]
  ------------------
 2124|    181|		int jj;
 2125|    181|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2126|    181|		size_t resp_len, out_len;
 2127|    181|		struct sc_pkcs15_pubkey_rsa key;
 2128|       |
 2129|    181|		resp_len = sizeof(resp);
 2130|    181|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2131|    181|				2, resp, resp_len);
 2132|    181|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    181|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    181|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    181|	int _ret = (r); \
  |  |  |  |  168|    181|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 149]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 149]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2133|       |
 2134|    374|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2134:14): [True: 357, False: 17]
  |  Branch (2134:23): [True: 225, False: 132]
  ------------------
 2135|    225|			;
 2136|       |
 2137|    149|		if (rv - jj == 0)
  ------------------
  |  Branch (2137:7): [True: 17, False: 132]
  ------------------
 2138|     17|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     17|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2139|    132|		bn[0].data = calloc(1, rv - jj);
 2140|    132|		if (!bn[0].data) {
  ------------------
  |  Branch (2140:7): [True: 0, False: 132]
  ------------------
 2141|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2142|      0|			goto err;
 2143|      0|		}
 2144|    132|		bn[0].len = rv - jj;
 2145|    132|		memcpy(bn[0].data, resp + jj, rv - jj);
 2146|       |
 2147|    132|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2148|    132|				1, resp, resp_len);
 2149|    132|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|    132|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    132|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    132|	int _ret = (r); \
  |  |  |  |  178|    132|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 16, False: 116]
  |  |  |  |  ------------------
  |  |  |  |  179|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     16|		goto err; \
  |  |  |  |  182|     16|	} \
  |  |  |  |  183|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 116]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|       |
 2151|    116|		bn[1].data = calloc(1, rv);
 2152|    116|		if (!bn[1].data) {
  ------------------
  |  Branch (2152:7): [True: 0, False: 116]
  ------------------
 2153|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2154|      0|			goto err;
 2155|      0|		}
 2156|    116|		bn[1].len = rv;
 2157|    116|		memcpy(bn[1].data, resp, rv);
 2158|       |
 2159|    116|		key.exponent = bn[0];
 2160|    116|		key.modulus = bn[1];
 2161|       |
 2162|    116|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|    116|#define SC_SUCCESS				0
  ------------------
  |  Branch (2162:7): [True: 4, False: 112]
  ------------------
 2163|      4|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2164|      4|			LOG_TEST_GOTO_ERR(card->ctx, rv, "cannot encode RSA public key");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2165|      4|		}
 2166|    112|		else {
 2167|    112|			if (out_len < offset) {
  ------------------
  |  Branch (2167:8): [True: 12, False: 100]
  ------------------
 2168|     12|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     12|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2169|     12|				goto err;
 2170|     12|			}
 2171|    100|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   69|    100|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 76, False: 24]
  |  |  ------------------
  ------------------
 2172|    100|			memcpy(buf, out + offset, sz);
 2173|       |
 2174|    100|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|    100|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    100|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2175|    100|			rv = (int)sz;
 2176|    100|		}
 2177|  9.90k|	} else {
 2178|  9.90k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2179|  9.90k|	}
 2180|       |
 2181|  10.0k|err:
 2182|  10.0k|	free(bn[0].data);
 2183|  10.0k|	free(bn[1].data);
 2184|  10.0k|	free(out);
 2185|       |
 2186|  10.0k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  10.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.0k|	int _ret = r; \
  |  |  |  |  155|  10.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 951, False: 9.08k]
  |  |  |  |  ------------------
  |  |  |  |  156|    951|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    925|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 925, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  157|    951|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.08k|	} else { \
  |  |  |  |  159|  9.08k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  9.08k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  9.08k|	} \
  |  |  |  |  162|  10.0k|	return _ret; \
  |  |  |  |  163|  10.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2187|  10.0k|}
card-oberthur.c:auth_read_component:
 1463|    313|{
 1464|    313|	struct sc_apdu apdu;
 1465|    313|	int rv;
 1466|    313|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1467|       |
 1468|    313|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    313|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    313|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    313|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    313|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 313]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1469|    313|	sc_log(card->ctx, "num %i, outlen %zu, type %i", num, outlen, type);
  ------------------
  |  |   71|    313|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1470|       |
 1471|    313|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1471:6): [True: 0, False: 313]
  |  Branch (1471:17): [True: 0, False: 313]
  ------------------
 1472|    313|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|       |
 1474|    313|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    313|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1475|    313|	apdu.cla |= 0x80;
 1476|    313|	apdu.le = outlen;
 1477|    313|	apdu.resp = resp;
 1478|    313|	apdu.resplen = sizeof(resp);
 1479|    313|	rv = sc_transmit_apdu(card, &apdu);
 1480|    313|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    313|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    313|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    313|	int _ret = (r); \
  |  |  |  |  168|    313|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 307]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|    313|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 307]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1481|       |
 1482|    307|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1483|    307|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    307|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    307|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    307|	int _ret = (r); \
  |  |  |  |  168|    307|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 265]
  |  |  |  |  ------------------
  |  |  |  |  169|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     42|		return _ret; \
  |  |  |  |  172|     42|	} \
  |  |  |  |  173|    307|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 265]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1484|       |
 1485|    265|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1485:6): [True: 0, False: 265]
  ------------------
 1486|    265|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|       |
 1488|    265|	memcpy(out, apdu.resp, apdu.resplen);
 1489|    265|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    265|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    265|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    265|	int _ret = r; \
  |  |  |  |  155|    265|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 252]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    252|	} else { \
  |  |  |  |  159|    252|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    252|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    252|	} \
  |  |  |  |  162|    265|	return _ret; \
  |  |  |  |  163|    265|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1490|    265|}
card-oberthur.c:auth_read_record:
 2193|    457|{
 2194|    457|	struct sc_apdu apdu;
 2195|    457|	int rv = 0;
 2196|    457|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2197|       |
 2198|    457|	sc_log(card->ctx, "auth_read_record(): nr_rec %i; count %zu", nr_rec, count);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2199|       |
 2200|    457|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2200:6): [True: 0, False: 457]
  |  Branch (2200:23): [True: 78, False: 379]
  ------------------
 2201|    457|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     78|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     78|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     78|	int _ret = r; \
  |  |  |  |  155|     78|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 78, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     78|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     78|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 78, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     78|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     78|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     78|	return _ret; \
  |  |  |  |  163|     78|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2202|       |
 2203|    379|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|    379|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2204|    379|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|    379|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2205|    379|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|    379|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2205:6): [True: 379, False: 0]
  ------------------
 2206|    379|		apdu.p2 |= 0x04;
 2207|       |
 2208|    379|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   69|    379|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 379, False: 0]
  |  |  ------------------
  ------------------
 2209|    379|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    379|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2210|    379|	apdu.resp = recvbuf;
 2211|       |
 2212|    379|	rv = sc_transmit_apdu(card, &apdu);
 2213|    379|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    379|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    379|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    379|	int _ret = (r); \
  |  |  |  |  168|    379|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 372]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|    379|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 372]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2214|    372|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2214:6): [True: 86, False: 286]
  ------------------
 2215|    372|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|     86|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     86|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     86|	int _ret = r; \
  |  |  |  |  155|     86|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 86, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     86|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  157|     86|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     86|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     86|	return _ret; \
  |  |  |  |  163|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2216|    286|	if (count < apdu.resplen)
  ------------------
  |  Branch (2216:6): [True: 6, False: 280]
  ------------------
 2217|    286|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2218|    280|	memcpy(buf, recvbuf, apdu.resplen);
 2219|       |
 2220|    280|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2221|    280|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    280|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    280|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    280|	int _ret = (r); \
  |  |  |  |  168|    280|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 268]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|    280|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 268]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2222|       |
 2223|    268|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    268|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    268|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    268|	int _ret = r; \
  |  |  |  |  155|    268|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 268]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    268|	} else { \
  |  |  |  |  159|    268|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    268|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    268|	} \
  |  |  |  |  162|    268|	return _ret; \
  |  |  |  |  163|    268|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2224|    268|}
card-oberthur.c:auth_card_ctl:
 1435|      5|{
 1436|      5|	switch (cmd) {
 1437|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1437:2): [True: 0, False: 5]
  ------------------
 1438|      0|		return auth_get_default_key(card,
 1439|      0|				(struct sc_cardctl_default_key *) ptr);
 1440|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1440:2): [True: 0, False: 5]
  ------------------
 1441|      0|		return auth_generate_key(card, 0,
 1442|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1443|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1443:2): [True: 0, False: 5]
  ------------------
 1444|      0|		return auth_update_key(card,
 1445|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1446|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1446:2): [True: 0, False: 5]
  ------------------
 1447|      0|		return auth_create_reference_data(card,
 1448|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1449|      5|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1449:2): [True: 5, False: 0]
  ------------------
 1450|      5|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1451|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1451:2): [True: 0, False: 5]
  ------------------
 1452|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1452:2): [True: 0, False: 5]
  ------------------
 1453|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1454|      0|	default:
  ------------------
  |  Branch (1454:2): [True: 0, False: 5]
  ------------------
 1455|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1456|      5|	}
 1457|      5|}
card-oberthur.c:auth_init_pin_info:
 1521|    852|{
 1522|    852|	pin->offset = 0;
 1523|    852|	pin->pad_char   = 0xFF;
 1524|    852|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    852|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1525|       |
 1526|    852|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|    852|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1526:6): [True: 852, False: 0]
  ------------------
 1527|    852|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    852|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1528|    852|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    852|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1529|    852|	} else {
 1530|      0|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1531|      0|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1532|      0|	}
 1533|    852|}
card-oberthur.c:auth_get_serialnr:
 2249|      5|{
 2250|      5|	if (!serial)
  ------------------
  |  Branch (2250:6): [True: 0, False: 5]
  ------------------
 2251|      5|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2252|       |
 2253|      5|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2253:6): [True: 0, False: 5]
  ------------------
 2254|      5|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2255|       |
 2256|      5|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2257|       |
 2258|      5|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2259|      5|}
card-oberthur.c:auth_process_fci:
  297|  3.16k|{
  298|  3.16k|	unsigned char type;
  299|  3.16k|	const unsigned char *attr;
  300|  3.16k|	size_t attr_len = 0;
  301|       |
  302|  3.16k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.16k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.16k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.16k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.16k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  3.16k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  3.16k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 1.45k, False: 1.70k]
  |  Branch (304:15): [True: 28, False: 1.68k]
  ------------------
  305|  3.16k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.48k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.48k|	int _ret = r; \
  |  |  |  |  155|  1.48k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.48k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.48k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.48k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.48k|	return _ret; \
  |  |  |  |  163|  1.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  1.68k|	type = attr[0];
  307|       |
  308|  1.68k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  1.68k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 23, False: 1.65k]
  |  Branch (309:15): [True: 11, False: 1.64k]
  ------------------
  310|  1.68k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  1.64k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  1.64k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 945, False: 702]
  ------------------
  314|  1.64k|	switch (type) {
  315|    945|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 945, False: 702]
  ------------------
  316|    945|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 12, False: 933]
  |  Branch (316:16): [True: 10, False: 923]
  ------------------
  317|    945|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     22|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     22|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     22|	int _ret = r; \
  |  |  |  |  155|     22|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     22|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     22|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     22|	return _ret; \
  |  |  |  |  163|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    923|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    923|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    923|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    923|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    923|		file->size = attr[0]*0x100 + attr[1];
  321|    923|		break;
  322|    173|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 173, False: 1.47k]
  ------------------
  323|    173|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 11, False: 162]
  |  Branch (323:16): [True: 18, False: 144]
  ------------------
  324|    173|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     29|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     29|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     29|	int _ret = r; \
  |  |  |  |  155|     29|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     29|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     29|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 29, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     29|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     29|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     29|	return _ret; \
  |  |  |  |  163|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|    144|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    144|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|    144|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|    144|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|    144|		file->size = attr[0];
  328|    144|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|    144|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 144]
  |  Branch (329:16): [True: 49, False: 95]
  ------------------
  330|    144|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     49|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     49|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     49|	int _ret = r; \
  |  |  |  |  155|     49|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     49|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     49|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     49|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     49|	return _ret; \
  |  |  |  |  163|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|     95|		file->record_length = attr[2]*0x100+attr[3];
  332|     95|		file->record_count = attr[4];
  333|     95|		break;
  334|    103|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 103, False: 1.54k]
  ------------------
  335|    103|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 18, False: 85]
  |  Branch (335:16): [True: 10, False: 75]
  ------------------
  336|    103|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|     75|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     75|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     75|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     75|		file->size = attr[0]*0x100 + attr[1];
  340|     75|		file->size /= 8;
  341|     75|		break;
  342|    191|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 191, False: 1.45k]
  ------------------
  343|    191|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 11, False: 180]
  |  Branch (343:16): [True: 19, False: 161]
  ------------------
  344|    191|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|    161|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    161|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    161|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    161|		file->size = attr[0]*0x100 + attr[1];
  349|    161|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 24, False: 137]
  ------------------
  350|     24|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     24|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    137|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 18, False: 119]
  ------------------
  352|     18|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     18|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|    119|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 0, False: 119]
  ------------------
  354|      0|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      0|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|    119|		else {
  356|    119|			sc_log(card->ctx, "Not supported public key size: %zu", file->size);
  ------------------
  |  |   71|    119|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|    119|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    119|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    119|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    119|	int _ret = r; \
  |  |  |  |  155|    119|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 119, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    119|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    119|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 119, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    119|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    119|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    119|	return _ret; \
  |  |  |  |  163|    119|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|    119|		}
  359|     42|		break;
  360|     42|	case 0x14:
  ------------------
  |  Branch (360:2): [True: 30, False: 1.61k]
  ------------------
  361|     30|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (361:7): [True: 10, False: 20]
  |  Branch (361:16): [True: 10, False: 10]
  ------------------
  362|     30|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     10|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     10|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  364|     10|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  365|     10|		file->size = attr[0]*0x100 + attr[1];
  366|     10|		break;
  367|    178|	case 0x38:
  ------------------
  |  Branch (367:2): [True: 178, False: 1.46k]
  ------------------
  368|    178|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (368:7): [True: 25, False: 153]
  |  Branch (368:16): [True: 11, False: 142]
  ------------------
  369|    178|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     36|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     36|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     36|	int _ret = r; \
  |  |  |  |  155|     36|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     36|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     36|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     36|	return _ret; \
  |  |  |  |  163|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|    142|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    142|#define SC_FILE_TYPE_DF			0x04
  ------------------
  371|    142|		file->size = attr[0];
  372|    142|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    142|#define SC_SUCCESS				0
  ------------------
  |  Branch (372:7): [True: 0, False: 142]
  ------------------
  373|    142|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|    142|		break;
  375|    142|	default:
  ------------------
  |  Branch (375:2): [True: 27, False: 1.62k]
  ------------------
  376|     27|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     27|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     27|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     27|	int _ret = r; \
  |  |  |  |  155|     27|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     27|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     27|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     27|	return _ret; \
  |  |  |  |  163|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|  1.64k|	}
  378|       |
  379|  1.28k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  380|  1.28k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (380:6): [True: 1.03k, False: 256]
  |  Branch (380:15): [True: 18, False: 238]
  ------------------
  381|  1.28k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.04k|	int _ret = r; \
  |  |  |  |  155|  1.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.04k|	return _ret; \
  |  |  |  |  163|  1.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    238|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    238|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (383:6): [True: 120, False: 118]
  ------------------
  384|    120|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    120|#define SC_AC_OP_CREATE			3
  ------------------
  385|    120|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    120|#define SC_AC_OP_CRYPTO			7
  ------------------
  386|    120|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    120|#define SC_AC_OP_LIST_FILES		6
  ------------------
  387|    120|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    120|#define SC_AC_OP_DELETE			2
  ------------------
  388|    120|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    120|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  389|    120|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    120|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  390|    120|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    120|#define SC_AC_OP_PIN_RESET		19
  ------------------
  391|    120|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   71|    120|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  392|    120|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    118|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (392:13): [True: 96, False: 22]
  ------------------
  393|     96|		switch (file->ef_structure) {
  ------------------
  |  Branch (393:11): [True: 96, False: 0]
  ------------------
  394|     64|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (394:3): [True: 64, False: 32]
  ------------------
  395|     64|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     64|#define SC_AC_OP_UPDATE			23
  ------------------
  396|     64|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     64|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  397|     64|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     64|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  398|     64|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     64|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  399|     64|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     64|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  400|     64|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     64|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  401|     64|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     64|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  402|     64|			break;
  403|     22|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (403:3): [True: 22, False: 74]
  ------------------
  404|     22|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     22|#define SC_AC_OP_UPDATE			23
  ------------------
  405|     22|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     22|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  406|     22|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_SIGNATURE, attr[4]);
  ------------------
  |  |  178|     22|#define SC_AC_OP_PSO_VERIFY_SIGNATURE	12
  ------------------
  407|     22|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     22|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  408|     22|			break;
  409|     10|		case SC_CARDCTL_OBERTHUR_KEY_RSA_CRT:
  ------------------
  |  Branch (409:3): [True: 10, False: 86]
  ------------------
  410|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  411|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     10|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  412|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_SIGNATURE, attr[3]);
  ------------------
  |  |  177|     10|#define SC_AC_OP_PSO_COMPUTE_SIGNATURE	11
  ------------------
  413|     10|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     10|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  414|     10|			break;
  415|     96|		}
  416|     96|	} else {
  417|     22|		switch (file->ef_structure) {
  ------------------
  |  Branch (417:11): [True: 22, False: 0]
  ------------------
  418|     10|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     10|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (418:3): [True: 10, False: 12]
  ------------------
  419|     10|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     10|#define SC_AC_OP_WRITE			24
  ------------------
  420|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  421|     10|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     10|#define SC_AC_OP_READ			22
  ------------------
  422|     10|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     10|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     10|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  423|     10|			break;
  424|     12|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     12|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (424:3): [True: 12, False: 10]
  ------------------
  425|     12|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     12|#define SC_AC_OP_WRITE			24
  ------------------
  426|     12|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     12|#define SC_AC_OP_UPDATE			23
  ------------------
  427|     12|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     12|#define SC_AC_OP_READ			22
  ------------------
  428|     12|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     12|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     12|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  429|     12|			break;
  430|     22|		}
  431|     22|	}
  432|       |
  433|    238|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    238|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  434|    238|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    238|#define SC_FILE_MAGIC			0x14426950
  ------------------
  435|       |
  436|    238|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    238|}
card-oberthur.c:add_acl_entry:
  260|  1.50k|{
  261|  1.50k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 212, False: 1.29k]
  ------------------
  262|    212|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    212|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  263|    212|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    212|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    212|		return;
  265|    212|	}
  266|       |
  267|  1.29k|	switch (acl_byte) {
  268|    168|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 168, False: 1.12k]
  ------------------
  269|    168|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    168|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    168|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    168|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     41|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 41, False: 1.25k]
  ------------------
  273|     84|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 43, False: 1.24k]
  ------------------
  274|     84|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|     84|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |   41|     84|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|     84|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    142|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 142, False: 1.15k]
  ------------------
  278|    265|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 123, False: 1.16k]
  ------------------
  279|    265|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    265|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 40, False: 225]
  ------------------
  280|     40|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     40|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    225|		else
  282|    225|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    225|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    265|		break;
  284|    144|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 144, False: 1.14k]
  ------------------
  285|    144|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    144|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    144|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    144|		break;
  287|    631|	default:
  ------------------
  |  Branch (287:2): [True: 631, False: 661]
  ------------------
  288|    631|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    631|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    631|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    631|		break;
  290|  1.29k|	}
  291|  1.29k|}
card-oberthur.c:auth_pin_cmd:
 1875|    857|{
 1876|    857|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    857|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1877|       |
 1878|    857|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    857|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    857|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    857|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    857|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 857]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1879|    857|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    857|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1879:6): [True: 0, False: 857]
  ------------------
 1880|    857|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "auth_pin_cmd() unsupported PIN type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1881|       |
 1882|    857|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   71|    857|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1883|    857|			data->pin_reference, data->pin1.data, data->pin1.len,
 1884|    857|			data->pin2.data, data->pin2.len);
 1885|    857|	switch (data->cmd) {
 1886|    852|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|    852|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1886:2): [True: 852, False: 5]
  ------------------
 1887|    852|		rv = auth_pin_verify(card, SC_AC_CHV, data);
  ------------------
  |  |  151|    852|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1888|    852|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|    852|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    852|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    852|	int _ret = (r); \
  |  |  |  |  168|    852|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 74, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  169|     74|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     74|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     74|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     74|		return _ret; \
  |  |  |  |  172|     74|	} \
  |  |  |  |  173|    852|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 778]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1889|    778|		break;
 1890|    778|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1890:2): [True: 0, False: 857]
  ------------------
 1891|      0|		rv = auth_pin_change(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1892|      0|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|      0|		break;
 1894|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1894:2): [True: 0, False: 857]
  ------------------
 1895|      0|		rv = auth_pin_reset(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1896|      0|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|      0|		break;
 1898|      5|	default:
  ------------------
  |  Branch (1898:2): [True: 5, False: 852]
  ------------------
 1899|      5|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN operation");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|    857|	}
 1901|       |
 1902|    778|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    778|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    778|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    778|	int _ret = r; \
  |  |  |  |  155|    778|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 778, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    778|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  157|    778|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    778|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    778|	return _ret; \
  |  |  |  |  163|    778|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1903|    778|}
card-oberthur.c:auth_pin_verify:
 1595|    852|{
 1596|    852|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1597|    852|	int rv;
 1598|       |
 1599|    852|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    852|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    852|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    852|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    852|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 852]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1600|       |
 1601|    852|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|    852|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1601:6): [True: 0, False: 852]
  ------------------
 1602|    852|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "PIN type other then SC_AC_CHV is not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1603|       |
 1604|    852|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    852|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1605|       |
 1606|    852|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|    852|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1607|       |
 1608|       |	/* User PIN is always local. */
 1609|    852|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  1.70k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1609:6): [True: 398, False: 454]
  ------------------
 1610|    454|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    454|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1610:7): [True: 0, False: 454]
  ------------------
 1611|    398|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    398|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1612|       |
 1613|    852|        rv = auth_pin_is_verified(card, data->pin_reference, &data->pin1.tries_left);
 1614|    852|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   71|    852|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1615|       |
 1616|       |	/* Return if only PIN status has been asked. */
 1617|    852|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1617:6): [True: 852, False: 0]
  |  Branch (1617:25): [True: 852, False: 0]
  ------------------
 1618|    852|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    852|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    852|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    852|	int _ret = r; \
  |  |  |  |  155|    852|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 852, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    852|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     74|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 74, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  157|    852|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    852|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    852|	return _ret; \
  |  |  |  |  163|    852|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|       |	/* Return SUCCESS without verifying if
 1621|       |	 * PIN has been already verified and PIN pad has to be used. */
 1622|      0|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1622:6): [True: 0, False: 0]
  |  Branch (1622:13): [True: 0, False: 0]
  |  Branch (1622:33): [True: 0, False: 0]
  ------------------
 1623|      0|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1624|       |
 1625|      0|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1625:6): [True: 0, False: 0]
  |  Branch (1625:26): [True: 0, False: 0]
  ------------------
 1626|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1627|      0|	else
 1628|      0|		rv = iso_drv->ops->pin_cmd(card, data);
 1629|       |
 1630|      0|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1631|      0|}
card-oberthur.c:auth_pin_is_verified:
 1636|    852|{
 1637|    852|	struct sc_apdu apdu;
 1638|    852|	int rv;
 1639|       |
 1640|    852|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|    852|#define SC_APDU_CASE_1			0x01
  ------------------
 1641|       |
 1642|    852|	rv = sc_transmit_apdu(card, &apdu);
 1643|    852|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    852|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    852|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    852|	int _ret = (r); \
  |  |  |  |  168|    852|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 847]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|    852|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 847]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1644|       |
 1645|    847|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1645:6): [True: 847, False: 0]
  |  Branch (1645:20): [True: 23, False: 824]
  |  Branch (1645:40): [True: 15, False: 8]
  ------------------
 1646|     15|		*tries_left = apdu.sw2 & 0x0F;
 1647|       |
 1648|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1649|    847|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1649:6): [True: 23, False: 824]
  |  Branch (1649:26): [True: 5, False: 18]
  ------------------
 1650|      5|		apdu.sw1 = 0x69;
 1651|      5|		apdu.sw2 = 0x83;
 1652|      5|	}
 1653|       |
 1654|    847|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1655|       |
 1656|    847|	return rv;
 1657|    852|}
card-oberthur.c:auth_check_sw:
 2272|  21.4k|{
 2273|  21.4k|	int ii;
 2274|       |
 2275|  42.4k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2275:15): [True: 21.4k, False: 21.0k]
  ------------------
 2276|  21.4k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2276:7): [True: 445, False: 21.0k]
  ------------------
 2277|    445|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   71|    445|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2278|    445|			return auth_warnings[ii].errorno;
 2279|    445|		}
 2280|  21.4k|	}
 2281|       |
 2282|  21.0k|	return iso_ops->check_sw(card, sw1, sw2);
 2283|  21.4k|}

populate_blobs_to_mf:
  381|    843|{
  382|    843|	pgp_do_info_t	*info;
  383|       |
  384|    843|	if (priv->mf == NULL)
  ------------------
  |  Branch (384:6): [True: 0, False: 843]
  ------------------
  385|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  386|       |
  387|  49.5k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (387:33): [True: 49.5k, False: 0]
  |  Branch (387:51): [True: 48.7k, False: 843]
  ------------------
  388|  48.7k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (388:7): [True: 35.9k, False: 12.8k]
  |  Branch (388:53): [True: 15.7k, False: 20.1k]
  ------------------
  389|  15.7k|			pgp_blob_t *child = NULL;
  390|  15.7k|			sc_file_t *file = sc_file_new();
  391|       |
  392|  15.7k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  393|       |
  394|       |			/* catch out of memory condition */
  395|  15.7k|			if (child == NULL) {
  ------------------
  |  Branch (395:8): [True: 0, False: 15.7k]
  ------------------
  396|      0|				sc_file_free(file);
  397|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|      0|			}
  399|  15.7k|		}
  400|  48.7k|	}
  401|    843|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    843|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    843|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    843|	int _ret = r; \
  |  |  |  |  155|    843|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 843, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    843|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 843]
  |  |  |  |  ------------------
  |  |  |  |  157|    843|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    843|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    843|	return _ret; \
  |  |  |  |  163|    843|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    843|}
_pgp_handle_curve25519:
  721|  1.37k|{
  722|  1.37k|	if (!card || !key_info)
  ------------------
  |  Branch (722:6): [True: 0, False: 1.37k]
  |  Branch (722:15): [True: 0, False: 1.37k]
  ------------------
  723|      0|		return 0;
  724|  1.37k|	if (!sc_compare_oid(&key_info->u.ec.oid, &curve25519_oid) &&
  ------------------
  |  Branch (724:6): [True: 1.37k, False: 0]
  ------------------
  725|  1.37k|			!sc_compare_oid(&key_info->u.ec.oid, &X25519_oid))
  ------------------
  |  Branch (725:4): [True: 584, False: 795]
  ------------------
  726|    584|		return 0;
  727|       |
  728|       |	/* CKM_XEDDSA supports both Sign and Derive, but
  729|       |	* OpenPGP card supports only derivation using these
  730|       |	* keys as far as I know */
  731|    795|	_sc_card_add_xeddsa_alg(card, key_info->u.ec.key_length,
  732|    795|			SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  173|    795|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              			SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |   93|    795|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  733|    795|	sc_log(card->ctx, "DO %uX: Added XEDDSA algorithm (%d), mod_len = %zu",
  ------------------
  |  |   71|    795|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  734|    795|	    do_num, SC_ALGORITHM_XEDDSA, key_info->u.ec.key_length);
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|    795|#define SC_ALGORITHM_XEDDSA		5
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  734|    795|	    do_num, SC_ALGORITHM_XEDDSA, key_info->u.ec.key_length);
  735|    795|	return 1;
  736|  1.37k|}
_pgp_add_algo:
  740|  3.09k|{
  741|  3.09k|	unsigned long flags = 0, ext_flags = 0;
  742|       |
  743|  3.09k|	if (!card || !key_info)
  ------------------
  |  Branch (743:6): [True: 0, False: 3.09k]
  |  Branch (743:15): [True: 0, False: 3.09k]
  ------------------
  744|      0|		return 0;
  745|       |
  746|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  747|  3.09k|	switch (key_info->algorithm) {
  748|    498|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    498|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (748:2): [True: 498, False: 2.59k]
  ------------------
  749|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 /
  750|       |		 * v3.x section 7.2.11 & 7.2.12 */
  751|    498|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  111|    498|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    498|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    498|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  752|    498|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  133|    498|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  753|    498|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |   93|    498|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  754|       |
  755|    498|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  756|    498|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %zu",
  ------------------
  |  |   71|    498|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  757|    498|				do_num, key_info->u.rsa.modulus_len);
  758|    498|		break;
  759|    795|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|    795|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (759:2): [True: 795, False: 2.29k]
  ------------------
  760|       |		/* The montgomery curve (curve25519) needs to go through
  761|       |		 * different paths, otherwise we handle it as a normal EC key */
  762|    795|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (762:7): [True: 438, False: 357]
  ------------------
  763|    438|			break;
  764|       |		/* fall through */
  765|  1.57k|	case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|  1.57k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (765:2): [True: 1.21k, False: 1.87k]
  ------------------
  766|       |		/* v3.0+: ECC [RFC 4880 & 6637] */
  767|       |
  768|       |		/* Allow curve to be used by both ECDH and ECDSA.
  769|       |		 * pgp_init set these flags the same way */
  770|  1.57k|		flags = SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|  1.57k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  771|  1.57k|		flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|  1.57k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  772|  1.57k|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|  1.57k|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|  1.57k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  773|  1.57k|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|  1.57k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  774|  1.57k|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|  1.57k|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  775|       |
  776|  1.57k|		_sc_card_add_ec_alg(card, key_info->u.ec.key_length, flags, ext_flags,
  777|  1.57k|			&key_info->u.ec.oid);
  778|  1.57k|		sc_log(card->ctx, "DO %uX: Added EC algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|  1.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  779|  1.57k|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  780|  1.57k|		break;
  781|    584|	case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|    584|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (781:2): [True: 584, False: 2.51k]
  ------------------
  782|       |		/* EdDSA from draft-ietf-openpgp-rfc4880bis-08 */
  783|       |		/* Handle Yubikey bug, that in DO FA curve25519 has EDDSA algo */
  784|    584|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (784:7): [True: 357, False: 227]
  ------------------
  785|    357|			break;
  786|    227|		_sc_card_add_eddsa_alg(card, key_info->u.ec.key_length,
  787|    227|				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  188|    227|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
              				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |   93|    227|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  788|       |
  789|    227|		sc_log(card->ctx, "DO %uX: Added EDDSA algorithm (%d), mod_len = %zu" ,
  ------------------
  |  |   71|    227|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  790|    227|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  791|    227|		break;
  792|      0|	default:
  ------------------
  |  Branch (792:2): [True: 0, False: 3.09k]
  ------------------
  793|      0|		sc_log(card->ctx, "DO %uX: Unknown algorithm ID (%d)" ,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  794|      0|			do_num, key_info->algorithm);
  795|       |		/* return "false" if we do not understand algo */
  796|      0|		return 0;
  797|  3.09k|	}
  798|       |	/* return true */
  799|  3.09k|	return 1;
  800|  3.09k|}
sc_get_openpgp_driver:
 4209|  15.2k|{
 4210|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4211|       |
 4212|  15.2k|	iso_ops = iso_drv->ops;
 4213|       |
 4214|  15.2k|	pgp_ops = *iso_ops;
 4215|  15.2k|	pgp_ops.match_card	= pgp_match_card;
 4216|  15.2k|	pgp_ops.init		= pgp_init;
 4217|  15.2k|	pgp_ops.finish		= pgp_finish;
 4218|  15.2k|	pgp_ops.select_file	= pgp_select_file;
 4219|  15.2k|	pgp_ops.list_files	= pgp_list_files;
 4220|  15.2k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4221|  15.2k|	pgp_ops.read_binary	= pgp_read_binary;
 4222|  15.2k|	pgp_ops.write_binary	= NULL;
 4223|  15.2k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4224|  15.2k|	pgp_ops.logout		= pgp_logout;
 4225|  15.2k|	pgp_ops.get_data	= pgp_get_data;
 4226|  15.2k|	pgp_ops.put_data	= pgp_put_data;
 4227|  15.2k|	pgp_ops.set_security_env= pgp_set_security_env;
 4228|  15.2k|	pgp_ops.compute_signature= pgp_compute_signature;
 4229|  15.2k|	pgp_ops.decipher	= pgp_decipher;
 4230|  15.2k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4231|  15.2k|	pgp_ops.delete_file	= pgp_delete_file;
 4232|  15.2k|	pgp_ops.update_binary	= pgp_update_binary;
 4233|  15.2k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4234|       |
 4235|  15.2k|	return &pgp_drv;
 4236|  15.2k|}
card-openpgp.c:pgp_new_blob:
 1240|  45.1k|{
 1241|  45.1k|	pgp_blob_t *blob = NULL;
 1242|       |
 1243|  45.1k|	if (file == NULL)
  ------------------
  |  Branch (1243:6): [True: 0, False: 45.1k]
  ------------------
 1244|      0|		return NULL;
 1245|       |
 1246|  45.1k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1246:6): [True: 45.1k, False: 0]
  ------------------
 1247|  45.1k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  45.1k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1248|  45.1k|		pgp_do_info_t *info;
 1249|       |
 1250|  45.1k|		blob->file = file;
 1251|       |
 1252|  45.1k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  45.1k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1253|  45.1k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  45.1k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1254|  45.1k|		blob->file->id           = file_id;
 1255|       |
 1256|  45.1k|		blob->id     = file_id;
 1257|  45.1k|		blob->parent = parent;
 1258|       |
 1259|  45.1k|		if (parent != NULL) {
  ------------------
  |  Branch (1259:7): [True: 44.3k, False: 843]
  ------------------
 1260|  44.3k|			pgp_blob_t **p;
 1261|       |
 1262|       |			/* set file's path = parent's path + file's id */
 1263|  44.3k|			blob->file->path = parent->file->path;
 1264|  44.3k|			sc_append_file_id(&blob->file->path, file_id);
 1265|       |
 1266|       |			/* append blob to list of parent's children */
 1267|  7.70M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1267:29): [True: 7.66M, False: 44.3k]
  ------------------
 1268|  7.66M|				;
 1269|  44.3k|			*p = blob;
 1270|  44.3k|		}
 1271|    843|		else {
 1272|    843|			char path[10] = "0000";	/* long enough */
 1273|       |
 1274|       |			/* no parent: set file's path = file's id */
 1275|    843|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1275:8): [True: 0, False: 843]
  ------------------
 1276|      0|				free(blob);
 1277|      0|				return NULL;
 1278|      0|			}
 1279|       |
 1280|    843|			sc_format_path(path, &blob->file->path);
 1281|    843|		}
 1282|       |
 1283|       |		/* find matching DO info: set file type depending on it */
 1284|  1.77M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1284:34): [True: 1.77M, False: 0]
  |  Branch (1284:52): [True: 1.76M, False: 8.37k]
  ------------------
 1285|  1.76M|			if (info->id == file_id) {
  ------------------
  |  Branch (1285:8): [True: 36.7k, False: 1.73M]
  ------------------
 1286|  36.7k|				blob->info = info;
 1287|  36.7k|				blob->file->type = blob->info->type;
 1288|  36.7k|				pgp_attach_acl(card, blob->file, info);
 1289|  36.7k|				break;
 1290|  36.7k|			}
 1291|  1.76M|		}
 1292|  45.1k|	}
 1293|       |
 1294|  45.1k|	return blob;
 1295|  45.1k|}
card-openpgp.c:pgp_attach_acl:
 1172|  36.7k|{
 1173|  36.7k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  36.7k|#define SC_AC_NONE			0x00000000
  ------------------
 1174|  36.7k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  36.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1175|       |
 1176|       |	/* Write access */
 1177|  36.7k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1177:10): [True: 36.7k, False: 0]
  ------------------
 1178|  9.09k|	case WRITE_NEVER:
  ------------------
  |  Branch (1178:2): [True: 9.09k, False: 27.7k]
  ------------------
 1179|  9.09k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  9.09k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1180|  9.09k|		break;
 1181|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1181:2): [True: 0, False: 36.7k]
  ------------------
 1182|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1183|      0|		key_ref = 0x01;
 1184|      0|		break;
 1185|  1.68k|	case WRITE_PIN2:
  ------------------
  |  Branch (1185:2): [True: 1.68k, False: 35.1k]
  ------------------
 1186|  1.68k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.68k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1187|  1.68k|		key_ref = 0x02;
 1188|  1.68k|		break;
 1189|  26.0k|	case WRITE_PIN3:
  ------------------
  |  Branch (1189:2): [True: 26.0k, False: 10.7k]
  ------------------
 1190|  26.0k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  26.0k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1191|  26.0k|		key_ref = 0x03;
 1192|  26.0k|		break;
 1193|  36.7k|	}
 1194|       |
 1195|  36.7k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  73.5k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|      0|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1195:6): [True: 36.7k, False: 0]
  |  Branch (1195:30): [True: 0, False: 0]
  ------------------
 1196|  36.7k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  36.7k|#define SC_AC_OP_WRITE			24
  ------------------
 1197|  36.7k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  36.7k|#define SC_AC_OP_UPDATE			23
  ------------------
 1198|  36.7k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  36.7k|#define SC_AC_OP_DELETE			2
  ------------------
 1199|  36.7k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  36.7k|#define SC_AC_OP_CREATE			3
  ------------------
 1200|  36.7k|	}
 1201|      0|	else {
 1202|       |		/* When SC_AC_OP_DELETE is absent, we need to provide
 1203|       |		 * SC_AC_OP_DELETE_SELF for sc_pkcs15init_delete_by_path() */
 1204|      0|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE_SELF, method, key_ref);
  ------------------
  |  |  174|      0|#define SC_AC_OP_DELETE_SELF		8
  ------------------
 1205|      0|	}
 1206|       |
 1207|  36.7k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  36.7k|#define SC_AC_NONE			0x00000000
  ------------------
 1208|  36.7k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  36.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1209|       |	/* Read access */
 1210|  36.7k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1210:10): [True: 2.72k, False: 34.0k]
  ------------------
 1211|  1.03k|	case READ_NEVER:
  ------------------
  |  Branch (1211:2): [True: 1.03k, False: 35.7k]
  ------------------
 1212|  1.03k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.03k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1213|  1.03k|		break;
 1214|      0|	case READ_PIN1:
  ------------------
  |  Branch (1214:2): [True: 0, False: 36.7k]
  ------------------
 1215|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1216|      0|		key_ref = 0x01;
 1217|      0|		break;
 1218|    843|	case READ_PIN2:
  ------------------
  |  Branch (1218:2): [True: 843, False: 35.9k]
  ------------------
 1219|    843|		method = SC_AC_CHV;
  ------------------
  |  |  151|    843|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1220|    843|		key_ref = 0x02;
 1221|    843|		break;
 1222|    843|	case READ_PIN3:
  ------------------
  |  Branch (1222:2): [True: 843, False: 35.9k]
  ------------------
 1223|    843|		method = SC_AC_CHV;
  ------------------
  |  |  151|    843|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1224|    843|		key_ref = 0x03;
 1225|    843|		break;
 1226|  36.7k|	}
 1227|       |
 1228|  36.7k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  73.5k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  34.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1228:6): [True: 2.72k, False: 34.0k]
  |  Branch (1228:30): [True: 0, False: 34.0k]
  ------------------
 1229|  2.72k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  2.72k|#define SC_AC_OP_READ			22
  ------------------
 1230|  2.72k|	}
 1231|  36.7k|}
card-openpgp.c:pgp_match_card:
  326|  3.53k|{
  327|  3.53k|	int i;
  328|       |
  329|  3.53k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.53k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.53k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 40, False: 3.49k]
  ------------------
  333|     40|		card->name = pgp_atrs[i].name;
  334|     40|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|     40|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     40|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     40|	int _ret = r; \
  |  |  |  |  155|     40|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     40|	} else { \
  |  |  |  |  159|     40|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     40|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     40|	} \
  |  |  |  |  162|     40|	return _ret; \
  |  |  |  |  163|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|     40|	}
  336|  3.49k|	else {
  337|  3.49k|		sc_path_t	partial_aid;
  338|  3.49k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.49k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.49k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.49k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.49k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.49k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.49k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 829, False: 2.66k]
  ------------------
  346|    829|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    829|			card->name = default_cardname;
  348|       |
  349|    829|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 828, False: 1]
  ------------------
  350|    828|				(void) get_full_pgp_aid(card, file);
  351|    829|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 11, False: 818]
  ------------------
  352|     11|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     11|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     11|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 7]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|      3|					case 2:
  ------------------
  |  Branch (359:6): [True: 3, False: 8]
  ------------------
  360|      3|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|      3|						card->name = default_cardname_v2;
  362|      3|						break;
  363|      3|					case 3:
  ------------------
  |  Branch (363:6): [True: 3, False: 8]
  ------------------
  364|      3|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      3|						card->name = default_cardname_v3;
  366|      3|						break;
  367|      1|					default:
  ------------------
  |  Branch (367:6): [True: 1, False: 10]
  ------------------
  368|      1|						break;
  369|     11|				}
  370|     11|			}
  371|    829|			sc_file_free(file);
  372|    829|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    829|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    829|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    829|	int _ret = r; \
  |  |  |  |  155|    829|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 829]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    829|	} else { \
  |  |  |  |  159|    829|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    829|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    829|	} \
  |  |  |  |  162|    829|	return _ret; \
  |  |  |  |  163|    829|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    829|		}
  374|  3.49k|	}
  375|  2.66k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.66k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.66k|	int _ret = r; \
  |  |  |  |  155|  2.66k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.66k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.66k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.66k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.66k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.66k|	return _ret; \
  |  |  |  |  163|  2.66k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.66k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.67k|{
  308|  1.67k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.67k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.67k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.67k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.67k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.67k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   66|  1.67k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (66:20): [True: 596, False: 1.08k]
  |  |  ------------------
  ------------------
  314|  1.67k|	}
  315|       |
  316|  1.67k|	return r;
  317|  1.67k|}
card-openpgp.c:pgp_init:
  409|    869|{
  410|    869|	struct pgp_priv_data *priv;
  411|    869|	sc_path_t	path;
  412|    869|	sc_file_t	*file = NULL;
  413|    869|	int		r, i;
  414|       |
  415|    869|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    869|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    869|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    869|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    869|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 869]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |
  417|    869|	priv = calloc (1, sizeof *priv);
  418|    869|	if (!priv)
  ------------------
  |  Branch (418:6): [True: 0, False: 869]
  ------------------
  419|    869|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|    869|	card->drv_data = priv;
  421|       |
  422|    869|	card->cla = 0x00;
  423|       |
  424|       |	/* select application "OpenPGP" */
  425|    869|	sc_format_path("D276:0001:2401", &path);
  426|    869|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    869|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  427|    869|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (427:6): [True: 20, False: 849]
  ------------------
  428|     20|		sc_file_free(file);
  429|     20|		pgp_finish(card);
  430|     20|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|     20|	}
  432|       |
  433|       |	/* defensive programming check */
  434|    849|	if (!file)   {
  ------------------
  |  Branch (434:6): [True: 0, False: 849]
  ------------------
  435|      0|		pgp_finish(card);
  436|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|      0|	}
  438|       |
  439|    849|	if (file->namelen != 16) {
  ------------------
  |  Branch (439:6): [True: 848, False: 1]
  ------------------
  440|       |		/* explicitly get the full aid */
  441|    848|		r = get_full_pgp_aid(card, file);
  442|    848|		if (r < 0) {
  ------------------
  |  Branch (442:7): [True: 6, False: 842]
  ------------------
  443|      6|			sc_file_free(file);
  444|      6|			pgp_finish(card);
  445|      6|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      6|		}
  447|    848|	}
  448|       |
  449|       |	/* read information from AID */
  450|    843|	if (file->namelen == 16) {
  ------------------
  |  Branch (450:6): [True: 563, False: 280]
  ------------------
  451|    563|		static char card_name[SC_MAX_APDU_BUFFER_SIZE] = "OpenPGP card";
  452|       |
  453|       |		/* OpenPGP card spec 1.1, 2.x & 3.x, section 4.2.1 & 4.1.2.1 */
  454|    563|		priv->bcd_version = bebytes2ushort(file->name + 6);
  455|    563|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    563|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  456|    563|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    563|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  457|       |
  458|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  459|    563|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (459:7): [True: 1, False: 562]
  ------------------
  460|    562|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (460:7): [True: 1, False: 561]
  ------------------
  461|    561|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (461:7): [True: 1, False: 560]
  ------------------
  462|      3|			snprintf(card_name, sizeof(card_name),
  463|      3|				 "OpenPGP card v%u.%u (%04X %08lX)",
  464|      3|				 card->version.hw_major, card->version.hw_minor,
  465|      3|				 bebytes2ushort(file->name + 8),
  466|      3|				 bebytes2ulong(file->name + 10));
  467|      3|		}
  468|    560|		else if (card->name != NULL) {
  ------------------
  |  Branch (468:12): [True: 560, False: 0]
  ------------------
  469|       |			/* for other cards, append serial number to the card name */
  470|    560|			snprintf(card_name, sizeof(card_name),
  471|    560|				 "%s (%04X %08lX)",
  472|    560|				 card->name,
  473|    560|				 bebytes2ushort(file->name + 8),
  474|    560|				 bebytes2ulong(file->name + 10));
  475|    560|		}
  476|    563|		card->name = card_name;
  477|       |
  478|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  479|    563|		memcpy(card->serialnr.value, file->name + 8, 6);
  480|    563|		card->serialnr.len = 6;
  481|    563|	} else {
  482|       |		/* set detailed card version */
  483|    280|		switch (card->type) {
  484|      6|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (484:4): [True: 6, False: 274]
  ------------------
  485|      6|				priv->bcd_version = OPENPGP_CARD_3_0;
  486|      6|				break;
  487|     30|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (487:4): [True: 30, False: 250]
  ------------------
  488|     31|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (488:4): [True: 1, False: 279]
  ------------------
  489|     31|				priv->bcd_version = OPENPGP_CARD_2_0;
  490|     31|				break;
  491|    243|			default:
  ------------------
  |  Branch (491:4): [True: 243, False: 37]
  ------------------
  492|    243|				priv->bcd_version = OPENPGP_CARD_1_1;
  493|    243|				break;
  494|    280|		}
  495|    280|	}
  496|       |
  497|       |	/* set pointer to correct list of card objects */
  498|    843|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (498:22): [True: 291, False: 552]
  ------------------
  499|    843|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (499:8): [True: 36, False: 516]
  ------------------
  500|    552|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (500:8): [True: 31, False: 485]
  ------------------
  501|    516|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (501:8): [True: 10, False: 475]
  ------------------
  502|    485|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (502:8): [True: 22, False: 453]
  ------------------
  503|    475|			  :					     pgp34_objects;
  504|       |
  505|       |	/* With gnuk, we use different curves */
  506|    843|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (506:6): [True: 33, False: 810]
  ------------------
  507|     33|		priv->ec_curves = ec_curves_gnuk;
  508|    810|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (508:13): [True: 452, False: 358]
  ------------------
  509|    452|		priv->ec_curves = ec_curves_openpgp34;
  510|    452|	} else {
  511|    358|		priv->ec_curves = ec_curves_openpgp;
  512|    358|	}
  513|       |
  514|       |	/* change file path to MF for reuse in MF */
  515|    843|	sc_format_path("3f00", &file->path);
  516|       |
  517|       |	/* set up the root of our fake file tree */
  518|       |	/* Transfers ownership of the file to the priv->mf structure */
  519|    843|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  520|    843|	if (!priv->mf) {
  ------------------
  |  Branch (520:6): [True: 0, False: 843]
  ------------------
  521|      0|		sc_file_free(file);
  522|      0|		pgp_finish(card);
  523|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|      0|	}
  525|       |
  526|       |	/* select MF */
  527|    843|	priv->current = priv->mf;
  528|       |
  529|    843|	r = populate_blobs_to_mf(card, priv);
  530|    843|	if (r < 0) {
  ------------------
  |  Branch (530:6): [True: 0, False: 843]
  ------------------
  531|      0|		pgp_finish(card);
  532|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  533|      0|	}
  534|       |
  535|       |	/* get card_features from ATR & DOs */
  536|    843|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (536:6): [True: 103, False: 740]
  ------------------
  537|    103|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    103|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    103|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    103|	int _ret = r; \
  |  |  |  |  155|    103|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 103]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    103|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    103|	return _ret; \
  |  |  |  |  163|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|    103|	}
  539|       |
  540|       |	/* if algorithm attributes can be changed,
  541|       |	 * add supported algorithms based on specification for pkcs15-init */
  542|    740|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (542:6): [True: 17, False: 723]
  ------------------
  543|     17|		unsigned long flags_rsa, flags_ecc, ext_flags;
  544|     17|		unsigned long flags_eddsa, flags_xeddsa;
  545|       |
  546|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 / v3.x section 7.2.11 & 7.2.12 */
  547|     17|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  111|     17|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     17|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     17|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  548|     17|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  133|     17|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  549|     17|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     17|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     17|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|     17|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  551|     17|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|     17|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  552|     17|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|     17|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     17|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  553|     17|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     17|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|     17|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|     17|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  555|       |
  556|     17|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  188|     17|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  557|     17|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     17|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  558|       |		/* xeddsa may allow signing at some time */
  559|     17|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  173|     17|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  560|     17|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     17|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  561|       |
  562|     17|		switch (card->type) {
  563|      0|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (563:4): [True: 0, False: 17]
  ------------------
  564|       |				/* RSA 1024 was removed for v3+ */
  565|      0|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  566|      0|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  567|       |				/* fallthrough */
  568|      3|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (568:4): [True: 3, False: 14]
  ------------------
  569|      3|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  570|     21|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (570:15): [True: 18, False: 3]
  ------------------
  571|     18|				{
  572|     18|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   70|     18|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (572:10): [True: 6, False: 12]
  ------------------
  573|      6|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  574|      6|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  575|     12|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|     12|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (575:15): [True: 6, False: 6]
  ------------------
  576|      6|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  577|      6|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  578|      6|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|      6|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (578:15): [True: 6, False: 0]
  ------------------
  579|      6|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  580|      6|								flags_xeddsa, ext_flags, &priv->ec_curves[i].oid);
  581|      0|					else
  582|      0|						LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|     18|				}
  584|      3|				break;
  585|      3|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (585:4): [True: 0, False: 17]
  ------------------
  586|     14|			default:
  ------------------
  |  Branch (586:4): [True: 14, False: 3]
  ------------------
  587|     14|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  588|     14|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  589|     14|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  590|     14|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  591|     14|				break;
  592|     17|		}
  593|     17|	}
  594|       |
  595|    740|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    740|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    740|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    740|	int _ret = r; \
  |  |  |  |  155|    740|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 740, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    740|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 740]
  |  |  |  |  ------------------
  |  |  |  |  157|    740|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    740|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    740|	return _ret; \
  |  |  |  |  163|    740|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|    740|}
card-openpgp.c:pgp_get_blob:
 1480|  11.1k|{
 1481|  11.1k|	pgp_blob_t		*child;
 1482|  11.1k|	int			r;
 1483|       |
 1484|  11.1k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1484:6): [True: 1.35k, False: 9.81k]
  ------------------
 1485|  1.35k|		return r;
 1486|       |
 1487|  66.7k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1487:28): [True: 64.1k, False: 2.56k]
  ------------------
 1488|  64.1k|		if (child->id == id) {
  ------------------
  |  Branch (1488:7): [True: 7.25k, False: 56.9k]
  ------------------
 1489|  7.25k|			(void) pgp_read_blob(card, child);
 1490|  7.25k|			*ret = child;
 1491|  7.25k|			return SC_SUCCESS;
  ------------------
  |  |   28|  7.25k|#define SC_SUCCESS				0
  ------------------
 1492|  7.25k|		}
 1493|  64.1k|	}
 1494|       |
 1495|       |	/* This part is for "NOT FOUND" cases */
 1496|       |
 1497|       |	/* Special case:
 1498|       |	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
 1499|       |	 * So, if these blob was not found, we create it. */
 1500|  2.56k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  5.13k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|    442|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|    442|#define DO_LANG_PREF             0x5f2d
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  157|      0|#define DO_SEX                   0x5f35
  ------------------
  |  Branch (1500:6): [True: 221, False: 2.34k]
  |  Branch (1500:36): [True: 0, False: 221]
  |  Branch (1500:53): [True: 221, False: 0]
  |  Branch (1500:75): [True: 0, False: 0]
  ------------------
 1501|    221|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   71|    221|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1502|    221|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1503|    221|		if (child) {
  ------------------
  |  Branch (1503:7): [True: 221, False: 0]
  ------------------
 1504|    221|			pgp_set_blob(child, NULL, 0);
 1505|    221|			*ret = child;
 1506|    221|			return SC_SUCCESS;
  ------------------
  |  |   28|    221|#define SC_SUCCESS				0
  ------------------
 1507|    221|		}
 1508|      0|		else
 1509|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1510|    221|			       "Not enough memory to create blob for DO %X",
 1511|    221|			       id);
 1512|    221|	}
 1513|       |
 1514|  2.34k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  2.34k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1515|  2.56k|}
card-openpgp.c:pgp_enumerate_blob:
 1398|  11.6k|{
 1399|  11.6k|	const u8	*in;
 1400|  11.6k|	int		r;
 1401|  11.6k|	sc_file_t	*file = NULL;
 1402|       |
 1403|  11.6k|	if (blob->files != NULL)
  ------------------
  |  Branch (1403:6): [True: 9.14k, False: 2.48k]
  ------------------
 1404|  9.14k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.14k|#define SC_SUCCESS				0
  ------------------
 1405|       |
 1406|  2.48k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1406:6): [True: 1.18k, False: 1.30k]
  ------------------
 1407|  1.18k|		return r;
 1408|       |
 1409|  1.30k|	in = blob->data;
 1410|       |
 1411|  29.8k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1411:9): [True: 29.0k, False: 806]
  ------------------
 1412|  29.0k|		unsigned int	cla, tag, tmptag;
 1413|  29.0k|		size_t		len;
 1414|  29.0k|		const u8	*data = in;
 1415|  29.0k|		pgp_blob_t	*new;
 1416|       |
 1417|  29.0k|		if (!in)
  ------------------
  |  Branch (1417:7): [True: 0, False: 29.0k]
  ------------------
 1418|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1419|       |
 1420|  29.0k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1421|  29.0k|					&cla, &tag, &len);
 1422|  29.0k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  29.0k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1422:7): [True: 128, False: 28.9k]
  ------------------
 1423|    128|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   71|    128|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1424|    128|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    128|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1425|    128|		}
 1426|       |		/* Check for unknown error, or empty data */
 1427|  28.9k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    227|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1427:8): [True: 227, False: 28.6k]
  |  Branch (1427:19): [True: 0, False: 227]
  ------------------
 1428|  28.9k|		    (data == NULL)) {
  ------------------
  |  Branch (1428:7): [True: 205, False: 28.7k]
  ------------------
 1429|    205|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    205|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1430|    205|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    205|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1431|    205|		}
 1432|       |
 1433|       |		/* undo ASN1's split of tag & class */
 1434|  29.3k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1434:22): [True: 649, False: 28.7k]
  ------------------
 1435|    649|			cla <<= 8;
 1436|    649|		}
 1437|  28.7k|		tag |= cla;
 1438|       |		/* Check for length mismatch */
 1439|  28.7k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  28.7k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1439:7): [True: 227, False: 28.4k]
  ------------------
 1440|  28.4k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1440:7): [True: 0, False: 28.4k]
  ------------------
 1441|       |			// Check if it is not known Yubikey 5 issue
 1442|    227|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1442:8): [True: 149, False: 78]
  |  Branch (1442:29): [True: 12, False: 66]
  ------------------
 1443|    161|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    161|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1444|    161|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    161|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1445|    161|			}
 1446|    227|		}
 1447|       |
 1448|       |		/* Awful hack for composite DOs that have
 1449|       |		 * a TLV with the DO's id encompassing the
 1450|       |		 * entire blob. Example: Yubikey Neo */
 1451|  28.5k|		if (tag == blob->id) {
  ------------------
  |  Branch (1451:7): [True: 235, False: 28.3k]
  ------------------
 1452|    235|			in = data;
 1453|    235|			continue;
 1454|    235|		}
 1455|       |
 1456|       |		/* create fake file system hierarchy by
 1457|       |		 * using constructed DOs as DF */
 1458|  28.3k|		file = sc_file_new();
 1459|  28.3k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1459:7): [True: 0, False: 28.3k]
  ------------------
 1460|      0|			sc_file_free(file);
 1461|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1462|      0|		}
 1463|  28.3k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  28.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1463:7): [True: 0, False: 28.3k]
  ------------------
 1464|      0|			sc_file_free(file);
 1465|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1466|      0|		}
 1467|  28.3k|		in = data + len;
 1468|  28.3k|	}
 1469|       |
 1470|    806|	return SC_SUCCESS;
  ------------------
  |  |   28|    806|#define SC_SUCCESS				0
  ------------------
 1471|  1.30k|}
card-openpgp.c:pgp_set_blob:
 1140|  29.7k|{
 1141|  29.7k|	if (blob->data)
  ------------------
  |  Branch (1141:6): [True: 0, False: 29.7k]
  ------------------
 1142|      0|		free(blob->data);
 1143|  29.7k|	blob->data = NULL;
 1144|  29.7k|	blob->len    = 0;
 1145|  29.7k|	blob->status = 0;
 1146|       |
 1147|  29.7k|	if (len > 0) {
  ------------------
  |  Branch (1147:6): [True: 12.1k, False: 17.5k]
  ------------------
 1148|  12.1k|		void *tmp = calloc(1, len);
 1149|       |
 1150|  12.1k|		if (tmp == NULL)
  ------------------
  |  Branch (1150:7): [True: 0, False: 12.1k]
  ------------------
 1151|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|  12.1k|		blob->data = tmp;
 1154|  12.1k|		blob->len  = (unsigned int)len;
 1155|  12.1k|		if (data != NULL)
  ------------------
  |  Branch (1155:7): [True: 12.1k, False: 0]
  ------------------
 1156|  12.1k|			memcpy(blob->data, data, len);
 1157|  12.1k|	}
 1158|       |
 1159|  29.7k|	if (blob->file)
  ------------------
  |  Branch (1159:6): [True: 29.7k, False: 0]
  ------------------
 1160|  29.7k|		blob->file->size = len;
 1161|       |
 1162|  29.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  29.7k|#define SC_SUCCESS				0
  ------------------
 1163|  29.7k|}
card-openpgp.c:pgp_read_blob:
 1348|  10.9k|{
 1349|  10.9k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  10.9k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1350|       |
 1351|  10.9k|	if (blob->data != NULL)
  ------------------
  |  Branch (1351:6): [True: 6.65k, False: 4.28k]
  ------------------
 1352|  6.65k|		return SC_SUCCESS;
  ------------------
  |  |   28|  6.65k|#define SC_SUCCESS				0
  ------------------
 1353|  4.28k|	if (blob->info == NULL)
  ------------------
  |  Branch (1353:6): [True: 3, False: 4.28k]
  ------------------
 1354|      3|		return blob->status;
 1355|       |
 1356|  4.28k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1356:6): [True: 4.22k, False: 59]
  ------------------
 1357|  4.22k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1358|  4.22k|		size_t	buf_len = sizeof(buffer);
 1359|  4.22k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.22k|#define SC_SUCCESS				0
  ------------------
 1360|       |
 1361|       |		/* buffer length for certificate */
 1362|  4.22k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  8.44k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1362:7): [True: 63, False: 4.16k]
  |  Branch (1362:30): [True: 0, False: 63]
  ------------------
 1363|      0|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1364|      0|		}
 1365|       |
 1366|       |		/* buffer length for Gnuk pubkey */
 1367|  4.22k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1367:7): [True: 180, False: 4.04k]
  ------------------
 1368|    180|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|    360|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1368:8): [True: 0, False: 180]
  ------------------
 1369|    180|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|    360|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1369:8): [True: 0, False: 180]
  ------------------
 1370|    180|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|    360|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1370:8): [True: 0, False: 180]
  ------------------
 1371|    180|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|    360|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1371:8): [True: 0, False: 180]
  ------------------
 1372|    180|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|    360|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1372:8): [True: 0, False: 180]
  ------------------
 1373|    180|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|    180|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1373:8): [True: 0, False: 180]
  ------------------
 1374|      0|			buf_len = MIN(MAXLEN_RESP_PUBKEY_GNUK, sizeof(buffer));
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, Folded]
  |  |  ------------------
  ------------------
 1375|      0|		}
 1376|       |
 1377|  4.22k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1378|       |
 1379|  4.22k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1379:7): [True: 3.02k, False: 1.19k]
  ------------------
 1380|  3.02k|			blob->status = r;
 1381|  3.02k|			return r;
 1382|  3.02k|		}
 1383|       |
 1384|  1.19k|		return pgp_set_blob(blob, buffer, r);
 1385|  4.22k|	}
 1386|     59|	else {		/* un-readable DO or part of a constructed DO */
 1387|     59|		return SC_SUCCESS;
  ------------------
  |  |   28|     59|#define SC_SUCCESS				0
  ------------------
 1388|     59|	}
 1389|  4.28k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  634|  16.3k|{
  635|  16.3k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  16.3k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  636|  16.3k|	struct sc_object_id oid;
  637|  16.3k|	unsigned int j, r;
  638|       |
  639|  16.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  16.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  16.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  16.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  16.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 16.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |
  641|  16.3k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (641:6): [True: 0, False: 16.3k]
  |  Branch (641:22): [True: 8.02k, False: 8.30k]
  |  Branch (641:44): [True: 0, False: 8.30k]
  ------------------
  642|  8.30k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 8.30k]
  |  Branch (642:27): [True: 0, False: 8.30k]
  |  Branch (642:48): [True: 0, False: 8.30k]
  ------------------
  643|  8.02k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  8.02k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.02k|	int _ret = r; \
  |  |  |  |  155|  8.02k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.02k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.02k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.02k|	return _ret; \
  |  |  |  |  163|  8.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|  8.02k|	}
  645|       |
  646|  8.30k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  647|       |
  648|  8.30k|	switch (blob->data[0]) {
  649|    708|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    708|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (649:3): [True: 708, False: 7.59k]
  ------------------
  650|    708|			if (blob->len < 5) {
  ------------------
  |  Branch (650:8): [True: 210, False: 498]
  ------------------
  651|    210|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|    210|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    210|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    210|	int _ret = r; \
  |  |  |  |  155|    210|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 210, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    210|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    210|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 210, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    210|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    210|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    210|	return _ret; \
  |  |  |  |  163|    210|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|    210|			}
  653|       |
  654|    498|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  877|    498|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  655|    498|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  656|    498|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  657|       |
  658|    498|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (658:32): [True: 298, False: 200]
  ------------------
  659|    498|						  ? blob->data[5]
  660|    498|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  882|    698|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  661|    498|			break;
  662|  1.87k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|  1.87k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (662:3): [True: 1.87k, False: 6.43k]
  ------------------
  663|  4.48k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|  4.48k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (663:3): [True: 2.61k, False: 5.69k]
  ------------------
  664|  6.91k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|  6.91k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (664:3): [True: 2.43k, False: 5.87k]
  ------------------
  665|       |
  666|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  667|  6.91k|			key_info->algorithm = blob->data[0];
  668|       |
  669|       |			/* last byte is set to 0xFF if pubkey import is supported */
  670|  6.91k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  888|  6.91k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (670:8): [True: 517, False: 6.39k]
  ------------------
  671|    517|				if (blob->len < 3)
  ------------------
  |  Branch (671:9): [True: 196, False: 321]
  ------------------
  672|    196|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    196|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  673|    321|				key_info->u.ec.oidv_len = blob->len - 2;
  674|    321|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  888|    321|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  675|    321|			}
  676|  6.39k|			else {
  677|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  678|       |				 * it is not part of OID */
  679|  6.39k|				if (blob->len < 2)
  ------------------
  |  Branch (679:9): [True: 457, False: 5.94k]
  ------------------
  680|    457|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    457|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  681|  5.94k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  887|  5.94k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (681:9): [True: 3.52k, False: 2.41k]
  ------------------
  682|  3.52k|					key_info->u.ec.oidv_len = blob->len - 2;
  683|  2.41k|				else
  684|  2.41k|					key_info->u.ec.oidv_len = blob->len - 1;
  685|  5.94k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  887|  5.94k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  686|  5.94k|			}
  687|       |
  688|       |			/* Create copy of oid from blob */
  689|  6.26k|			sc_init_oid(&oid);
  690|  6.26k|			r = sc_asn1_decode_object_id(&blob->data[1], key_info->u.ec.oidv_len, &oid);
  691|       |
  692|       |			/* decoding failed, return sc_asn1_decode_object_id error code */
  693|  6.26k|			if (r > 0){
  ------------------
  |  Branch (693:8): [True: 2.25k, False: 4.01k]
  ------------------
  694|  2.25k|				return r;
  695|  2.25k|			}
  696|       |			/* compare with list of supported ec_curves */
  697|  26.0k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (697:16): [True: 24.6k, False: 1.41k]
  ------------------
  698|  24.6k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (698:9): [True: 2.59k, False: 22.0k]
  ------------------
  699|  2.59k|					sc_log(card->ctx, "Matched EC oid %s (%d)",
  ------------------
  |  |   71|  2.59k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  700|  2.59k|						sc_dump_oid(&oid), j);
  701|  2.59k|					key_info->u.ec.oid = priv->ec_curves[j].oid;
  702|  2.59k|					key_info->u.ec.key_length = priv->ec_curves[j].size;
  703|  2.59k|					break;
  704|  2.59k|				}
  705|  24.6k|			}
  706|       |			/* We did not match the OID */
  707|  4.01k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (707:8): [True: 1.41k, False: 2.59k]
  ------------------
  708|  1.41k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.41k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.41k|	int _ret = r; \
  |  |  |  |  155|  1.41k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.41k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.41k|	return _ret; \
  |  |  |  |  163|  1.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  1.41k|			}
  710|  2.59k|			break;
  711|  2.59k|		default:
  ------------------
  |  Branch (711:3): [True: 680, False: 7.62k]
  ------------------
  712|    680|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    680|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|  8.30k|	}
  714|       |
  715|  3.09k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.09k|	int _ret = r; \
  |  |  |  |  155|  3.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.09k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.09k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.09k|	return _ret; \
  |  |  |  |  163|  3.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  3.09k|}
card-openpgp.c:pgp_get_card_features:
  909|    843|{
  910|    843|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    843|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  911|    843|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  912|    843|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  913|    843|	unsigned int i;
  914|    843|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  915|    843|	int handled_algos = 0;
  916|       |
  917|    843|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    843|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    843|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    843|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    843|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 843]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  918|       |
  919|       |	/* parse card capabilities from historical bytes in ATR */
  920|    843|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (920:6): [True: 89, False: 754]
  ------------------
  921|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  922|     89|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (922:11): [True: 67, False: 22]
  ------------------
  923|     56|			case 0x00:
  ------------------
  |  Branch (923:4): [True: 56, False: 33]
  ------------------
  924|     56|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (924:9): [True: 55, False: 1]
  ------------------
  925|     55|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  926|     55|				}
  927|     56|				break;
  928|      9|			case 0x80:
  ------------------
  |  Branch (928:4): [True: 9, False: 80]
  ------------------
  929|      9|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (929:9): [True: 8, False: 1]
  ------------------
  930|      8|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  931|      8|				}
  932|      9|				break;
  933|      2|			case 0x10:
  ------------------
  |  Branch (933:4): [True: 2, False: 87]
  ------------------
  934|      2|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (934:9): [True: 1, False: 1]
  ------------------
  935|      1|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  936|      1|				}
  937|      2|				break;
  938|     89|		}
  939|     89|	}
  940|       |
  941|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  942|    843|	priv->ext_caps &= ~EXT_CAP_LCS;
  943|       |
  944|    843|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (944:6): [True: 552, False: 291]
  ------------------
  945|       |		/* get card capabilities from "historical bytes" DO */
  946|    552|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (946:7): [True: 552, False: 0]
  ------------------
  947|    552|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (947:7): [True: 53, False: 499]
  |  Branch (947:31): [True: 43, False: 10]
  ------------------
  948|       |
  949|     43|			if (blob->len > 4) {
  ------------------
  |  Branch (949:8): [True: 41, False: 2]
  ------------------
  950|     41|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  951|     41|			}
  952|       |
  953|       |			/* get card status from historical bytes status indicator */
  954|     43|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (954:8): [True: 43, False: 0]
  |  Branch (954:35): [True: 42, False: 1]
  ------------------
  955|     42|				priv->state = blob->data[blob->len-3];
  956|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  957|     42|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (957:9): [True: 31, False: 11]
  ------------------
  958|     31|					priv->ext_caps |= EXT_CAP_LCS;
  959|     42|			}
  960|     43|		}
  961|    552|	}
  962|       |
  963|    843|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (963:6): [True: 476, False: 367]
  ------------------
  964|    476|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    476|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  965|    476|	}
  966|       |
  967|    843|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (967:6): [True: 453, False: 390]
  ------------------
  968|       |		/* Parse supported algorithms from Algorithm Information DO
  969|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  970|    453|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (970:7): [True: 453, False: 0]
  ------------------
  971|    453|			pgp_blob_t *child;
  972|    453|			pgp_enumerate_blob(card, blobfa);
  973|       |			/* There will be multiple children with the same ID, but
  974|       |			 * different algos, so we need to iterate over all of them */
  975|  24.0k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (975:32): [True: 23.6k, False: 453]
  ------------------
  976|  23.6k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (976:9): [True: 6.19k, False: 17.4k]
  |  Branch (976:33): [True: 1.42k, False: 15.9k]
  ------------------
  977|  7.62k|					continue;
  978|  15.9k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  979|  15.9k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (979:9): [True: 2.98k, False: 12.9k]
  ------------------
  980|  2.98k|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  981|  15.9k|			}
  982|    453|		}
  983|    453|	}
  984|       |
  985|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  986|    843|	priv->max_specialDO_size = 254;
  987|       |
  988|    843|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (988:6): [True: 843, False: 0]
  ------------------
  989|    843|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (989:6): [True: 246, False: 597]
  ------------------
  990|       |
  991|       |		/* get "extended capabilities" DO */
  992|    246|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (992:7): [True: 57, False: 189]
  ------------------
  993|     57|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (993:7): [True: 55, False: 2]
  |  Branch (993:31): [True: 55, False: 0]
  ------------------
  994|     55|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (994:8): [True: 47, False: 8]
  |  Branch (994:34): [True: 30, False: 17]
  ------------------
  995|     30|				priv->ext_caps |= EXT_CAP_KDF_DO;
  996|     30|			}
  997|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  998|     55|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (998:8): [True: 23, False: 32]
  ------------------
  999|     23|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (999:6): [True: 17, False: 6]
  ------------------
 1000|     17|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
 1001|       |			/* bit 0x08 in first byte means "support for private use DOs" */
 1002|     55|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (1002:8): [True: 20, False: 35]
  ------------------
 1003|     20|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1004|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1005|     55|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1005:8): [True: 11, False: 44]
  ------------------
 1006|     11|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1007|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1008|     55|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1008:8): [True: 14, False: 41]
  ------------------
 1009|     14|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1010|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1011|     55|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1011:8): [True: 19, False: 36]
  ------------------
 1012|     19|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     19|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1013|     19|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1014|     19|			}
 1015|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1016|     55|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1016:8): [True: 23, False: 32]
  ------------------
 1017|     23|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1017:6): [True: 15, False: 8]
  ------------------
 1018|     15|				priv->ext_caps |= EXT_CAP_SM;
 1019|       |
 1020|     55|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1020:8): [True: 46, False: 9]
  |  Branch (1020:51): [True: 45, False: 1]
  ------------------
 1021|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1022|     45|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1023|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1024|     45|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1025|       |
 1026|     45|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1026:9): [True: 11, False: 34]
  ------------------
 1027|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1028|     11|					priv->sm_algo = blob->data[1];
 1029|     11|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1029:10): [True: 7, False: 4]
  |  Branch (1029:45): [True: 2, False: 5]
  ------------------
 1030|      2|						priv->sm_algo = SM_ALGO_3DES;
 1031|       |
 1032|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1033|     11|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1034|     11|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1035|     11|				}
 1036|     34|				else {
 1037|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1038|     34|					priv->sm_algo = blob->data[1];
 1039|     34|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1039:10): [True: 7, False: 27]
  |  Branch (1039:45): [True: 3, False: 4]
  ------------------
 1040|      3|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1041|       |
 1042|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1043|     34|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1044|     34|				}
 1045|     45|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1045:9): [True: 32, False: 13]
  |  Branch (1045:50): [True: 32, False: 0]
  ------------------
 1046|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1047|     32|					if (blob->data[9])
  ------------------
  |  Branch (1047:10): [True: 20, False: 12]
  ------------------
 1048|     20|						priv->ext_caps |= EXT_CAP_MSE;
 1049|     32|				}
 1050|     45|			}
 1051|     55|		}
 1052|       |
 1053|       |		/* get max. PIN length from "CHV status bytes" DO */
 1054|    246|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1054:7): [True: 173, False: 73]
  ------------------
 1055|    173|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1055:4): [True: 171, False: 2]
  |  Branch (1055:28): [True: 169, False: 2]
  ------------------
 1056|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1057|    169|			card->max_pin_len = blob->data[1];
 1058|    169|		}
 1059|       |
 1060|    246|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1060:7): [True: 86, False: 160]
  ------------------
 1061|       |			/* v3.0+: get length info from "extended length information" DO */
 1062|     86|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1062:8): [True: 3, False: 83]
  ------------------
 1063|      3|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1063:5): [True: 2, False: 1]
  |  Branch (1063:29): [True: 1, False: 1]
  ------------------
 1064|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1065|      1|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1066|      1|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1067|      1|			}
 1068|     86|		}
 1069|       |
 1070|    246|#ifdef ENABLE_OPENSSL
 1071|    246|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1071:7): [True: 30, False: 216]
  ------------------
 1072|     30|			int r = pgp_decode_kdf_do(card, priv);
 1073|     30|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (1073:8): [True: 28, False: 2]
  ------------------
 1074|     28|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1075|     28|			}
 1076|     30|		}
 1077|    246|#endif /* ENABLE_OPENSSL */
 1078|       |
 1079|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1080|    246|		if (handled_algos) {
  ------------------
  |  Branch (1080:7): [True: 16, False: 230]
  ------------------
 1081|     16|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1082|     16|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|     16|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     16|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     16|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1083|     16|		}
 1084|       |
 1085|       |		/* get _current_ algorithms & key lengths from "algorithm attributes" DOs
 1086|       |		 *
 1087|       |		 * All available algorithms should be already provided by pgp_init. However, if another
 1088|       |		 * algorithm is found in the "algorithm attributes" DOs, it is supported by the card as
 1089|       |		 * well and therefore added
 1090|       |		 * see OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1091|    920|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1091:20): [True: 690, False: 230]
  ------------------
 1092|    690|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1093|       |
 1094|    690|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   71|    690|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1095|       |
 1096|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1097|    690|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1097:8): [True: 351, False: 339]
  ------------------
 1098|    351|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1098:8): [True: 105, False: 246]
  ------------------
 1099|    105|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1099:9): [True: 0, False: 105]
  ------------------
 1100|    105|					LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "Cannot add algorithm");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|    105|			}
 1102|    690|		}
 1103|       |
 1104|    230|	}
 1105|       |
 1106|    827|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    827|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    827|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    827|	int _ret = r; \
  |  |  |  |  155|    827|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 740, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  156|    740|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 740]
  |  |  |  |  ------------------
  |  |  |  |  157|    740|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    740|	} else { \
  |  |  |  |  159|     87|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     87|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     87|	} \
  |  |  |  |  162|    827|	return _ret; \
  |  |  |  |  163|    827|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|    827|}
card-openpgp.c:pgp_parse_hist_bytes:
  604|    105|{
  605|    105|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    105|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  606|    105|	const u8 *ptr;
  607|       |
  608|       |	/* IS07816-4 hist bytes: 3rd function table */
  609|    105|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (609:6): [True: 56, False: 49]
  ------------------
  610|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  611|     56|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (611:7): [True: 15, False: 41]
  ------------------
  612|     15|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     15|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  613|     15|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  614|     15|		}
  615|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  616|     56|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (616:7): [True: 46, False: 10]
  ------------------
  617|     46|			priv->ext_caps |= EXT_CAP_CHAINING;
  618|     46|		}
  619|     56|	}
  620|       |
  621|    105|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (621:6): [True: 49, False: 56]
  ------------------
  622|     49|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (622:6): [True: 12, False: 37]
  ------------------
  623|       |		// ToDo ...
  624|     12|	}
  625|    105|}
card-openpgp.c:pgp_decode_kdf_do:
  805|     30|{
  806|     30|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  807|     30|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     30|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  808|     30|	pgp_blob_t *kdf_blob;
  809|     30|	const uint8_t *data;
  810|     30|	size_t data_len;
  811|     30|	size_t tag_len;
  812|     30|	const uint8_t *p;
  813|     30|	pgp_blob_t *blob;
  814|       |
  815|     30|	if (!pin_kdf_info) {
  ------------------
  |  Branch (815:6): [True: 0, False: 30]
  ------------------
  816|      0|		return r;
  817|      0|	}
  818|       |
  819|     30|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     30|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  820|     30|	priv->pin_kdf_info = NULL;
  821|     30|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     30|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (821:6): [True: 0, False: 30]
  |  Branch (821:73): [True: 9, False: 21]
  ------------------
  822|      9|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  823|      9|		goto out;
  824|      9|	}
  825|       |
  826|     21|	data = kdf_blob->data;
  827|     21|	data_len = kdf_blob->len;
  828|     21|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  829|     21|	if (!p) {
  ------------------
  |  Branch (829:6): [True: 7, False: 14]
  ------------------
  830|      7|		sc_log(card->ctx, "KDF algorithm byte not found");
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  831|      7|		goto out;
  832|      7|	}
  833|     14|	if (tag_len != 1) {
  ------------------
  |  Branch (833:6): [True: 1, False: 13]
  ------------------
  834|      1|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  835|      1|		goto out;
  836|      1|	}
  837|       |
  838|     13|	if (*p != 0x3) {
  ------------------
  |  Branch (838:6): [True: 5, False: 8]
  ------------------
  839|      5|		if (*p == 0x0) {
  ------------------
  |  Branch (839:7): [True: 1, False: 4]
  ------------------
  840|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  841|      1|			sc_log(card->ctx, "KDF derived PIN format disabled");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  842|      4|		} else {
  843|      4|			sc_log(card->ctx, "Unknown KDF algorithm ID %x", *p);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  844|      4|		}
  845|      5|		goto out;
  846|      5|	}
  847|       |
  848|      8|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  849|      8|	if (!p) {
  ------------------
  |  Branch (849:6): [True: 1, False: 7]
  ------------------
  850|      1|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  851|      1|		goto out;
  852|      1|	}
  853|      7|	if (tag_len != 1) {
  ------------------
  |  Branch (853:6): [True: 1, False: 6]
  ------------------
  854|      1|		sc_log(card->ctx, "Unexpected KDF hash algorithm byte length, expects 1, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  855|      1|		goto out;
  856|      1|	}
  857|       |
  858|      6|	switch (*p) {
  859|      1|	case 0x08:
  ------------------
  |  Branch (859:2): [True: 1, False: 5]
  ------------------
  860|      1|		pin_kdf_info->hash_algo = "SHA256";
  861|      1|		break;
  862|      4|	case 0x0A:
  ------------------
  |  Branch (862:2): [True: 4, False: 2]
  ------------------
  863|      4|		pin_kdf_info->hash_algo = "SHA512";
  864|      4|		break;
  865|      1|	default:
  ------------------
  |  Branch (865:2): [True: 1, False: 5]
  ------------------
  866|      1|		sc_log(card->ctx, "Unknown KDF hash algorithm ID %x", *p);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  867|      1|		goto out;
  868|      6|	}
  869|       |
  870|      5|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  871|      5|	if (!p) {
  ------------------
  |  Branch (871:6): [True: 1, False: 4]
  ------------------
  872|      1|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  873|      1|		goto out;
  874|      1|	}
  875|      4|	if (tag_len != 4) {
  ------------------
  |  Branch (875:6): [True: 1, False: 3]
  ------------------
  876|      1|		sc_log(card->ctx, "Unexpected KDF iteration count length, expects 4, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  877|      1|		goto out;
  878|      1|	}
  879|      3|	pin_kdf_info->iterations = (uint32_t)bebytes2ulong(p);
  880|       |
  881|      3|	r = pgp_get_blob(card, kdf_blob, 0x84, &blob);
  882|      3|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (882:6): [True: 1, False: 2]
  ------------------
  883|      1|		sc_log(card->ctx, "Failed to get salt bytes of user password");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  884|      1|		goto out;
  885|      1|	}
  886|      2|	pin_kdf_info->userpw_salt = blob;
  887|       |
  888|      2|	r = pgp_get_blob(card, kdf_blob, 0x86, &blob);
  889|      2|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  |  Branch (889:6): [True: 1, False: 1]
  ------------------
  890|      1|		sc_log(card->ctx, "Failed to get salt bytes of admin password");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  891|      1|		goto out;
  892|      1|	}
  893|      1|	pin_kdf_info->adminpw_salt = blob;
  894|       |
  895|      1|	sc_log(card->ctx, "KDF derived PIN format enabled");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  896|      1|	priv->pin_kdf_info = pin_kdf_info;
  897|      1|	return r;
  898|     29|out:
  899|     29|	free(pin_kdf_info);
  900|     29|	return r;
  901|      2|}
card-openpgp.c:pgp_finish:
 1115|    869|{
 1116|    869|	if (card != NULL) {
  ------------------
  |  Branch (1116:6): [True: 869, False: 0]
  ------------------
 1117|    869|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    869|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1118|       |
 1119|    869|		if (priv != NULL) {
  ------------------
  |  Branch (1119:7): [True: 869, False: 0]
  ------------------
 1120|       |			/* delete fake file hierarchy */
 1121|    869|			pgp_free_blobs(priv->mf);
 1122|       |
 1123|       |			/* delete kdf do related data if exists */
 1124|    869|			free(priv->pin_kdf_info);
 1125|       |
 1126|       |			/* delete private data */
 1127|    869|			free(priv);
 1128|    869|		}
 1129|    869|		card->drv_data = NULL;
 1130|    869|	}
 1131|    869|	return SC_SUCCESS;
  ------------------
  |  |   28|    869|#define SC_SUCCESS				0
  ------------------
 1132|    869|}
card-openpgp.c:pgp_free_blobs:
 1328|  45.1k|{
 1329|  45.1k|	if (blob) {
  ------------------
  |  Branch (1329:6): [True: 45.1k, False: 26]
  ------------------
 1330|  45.1k|		pgp_blob_t *child = blob->files;
 1331|       |
 1332|  89.4k|		while (child != NULL) {
  ------------------
  |  Branch (1332:10): [True: 44.3k, False: 45.1k]
  ------------------
 1333|  44.3k|			pgp_blob_t *next = child->next;
 1334|       |
 1335|  44.3k|			pgp_free_blobs(child);
 1336|  44.3k|			child = next;
 1337|  44.3k|		}
 1338|  45.1k|		pgp_free_blob(blob);
 1339|  45.1k|	}
 1340|  45.1k|}
card-openpgp.c:pgp_free_blob:
 1303|  45.1k|{
 1304|  45.1k|	if (blob) {
  ------------------
  |  Branch (1304:6): [True: 45.1k, False: 0]
  ------------------
 1305|  45.1k|		if (blob->parent) {
  ------------------
  |  Branch (1305:7): [True: 44.3k, False: 843]
  ------------------
 1306|  44.3k|			pgp_blob_t **p;
 1307|       |
 1308|       |			/* remove blob from list of parent's children */
 1309|  44.3k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1309:35): [True: 44.3k, False: 0]
  |  Branch (1309:49): [True: 0, False: 44.3k]
  ------------------
 1310|      0|				;
 1311|  44.3k|			if (*p == blob)
  ------------------
  |  Branch (1311:8): [True: 44.3k, False: 0]
  ------------------
 1312|  44.3k|				*p = blob->next;
 1313|  44.3k|		}
 1314|       |
 1315|  45.1k|		sc_file_free(blob->file);
 1316|  45.1k|		if (blob->data)
  ------------------
  |  Branch (1316:7): [True: 12.1k, False: 32.9k]
  ------------------
 1317|  12.1k|			free(blob->data);
 1318|  45.1k|		free(blob);
 1319|  45.1k|	}
 1320|  45.1k|}
card-openpgp.c:pgp_select_file:
 1614|  6.18k|{
 1615|  6.18k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  6.18k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1616|  6.18k|	pgp_blob_t	*blob;
 1617|  6.18k|	unsigned int	path_start = 0;
 1618|  6.18k|	unsigned int	n;
 1619|  6.18k|	sc_path_t dummy_path;
 1620|       |
 1621|  6.18k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  6.18k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  6.18k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1623:6): [True: 1.38k, False: 4.79k]
  ------------------
 1624|  6.18k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  164|  1.38k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.38k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.38k|	int _ret = r; \
  |  |  |  |  155|  1.38k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.35k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.35k, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.38k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.38k|	return _ret; \
  |  |  |  |  163|  1.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|       |
 1626|  4.79k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1626:6): [True: 0, False: 4.79k]
  |  Branch (1626:23): [True: 0, False: 4.79k]
  ------------------
 1627|  4.79k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1628|  4.79k|				"invalid path length");
 1629|       |
 1630|  4.79k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  9.58k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1630:6): [True: 0, False: 4.79k]
  |  Branch (1630:44): [True: 0, False: 0]
  ------------------
 1631|  4.79k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1632|  4.79k|				"invalid path type");
 1633|       |
 1634|       |	/* Due to pkcs15init implementation, sometimes a file at path "11001101"
 1635|       |	 * need to be written (one use case is when importing key&cert from p12 file).
 1636|       |	 * This file does not exist in OpenPGP but pkcs15 requires that
 1637|       |	 * writing this file must be successful.
 1638|       |	 * So, we pretend that selecting & writing this file is successful.
 1639|       |	 * The "11001101"is defined in sc_pkcs15emu_get_df() function, pkcs15-sync.c file. */
 1640|  4.79k|	sc_format_path("11001101", &dummy_path);
 1641|  4.79k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1641:6): [True: 0, False: 4.79k]
  ------------------
 1642|      0|		if (ret != NULL) {
  ------------------
  |  Branch (1642:7): [True: 0, False: 0]
  ------------------
 1643|      0|			*ret = sc_file_new();
 1644|       |			/* One use case of this dummy file is after writing certificate in pkcs15init.
 1645|       |			 * So we set its size to be the same as max certificate size the card supports. */
 1646|      0|			(*ret)->size = priv->max_cert_size;
 1647|      0|		}
 1648|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1649|      0|	}
 1650|       |
 1651|       |	/* ignore explicitly mentioned MF at the path's beginning */
 1652|  4.79k|	path_start = pgp_strip_path(card, path);
 1653|       |
 1654|       |	/* starting with the MF ... */
 1655|  4.79k|	blob = priv->mf;
 1656|       |	/* ... recurse through the tree following the path */
 1657|  9.55k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1657:23): [True: 7.18k, False: 2.37k]
  ------------------
 1658|  7.18k|		unsigned int	id = bebytes2ushort(path->value + n);
 1659|  7.18k|		int		r = pgp_get_blob(card, blob, id, &blob);
 1660|       |
 1661|       |		/* This file ID is referred when importing key&certificate via pkcs15init, like above.
 1662|       |		 * We pretend to successfully find this inexistent file. */
 1663|  7.18k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1663:7): [True: 0, False: 7.18k]
  |  Branch (1663:23): [True: 0, False: 7.18k]
  ------------------
 1664|      0|			if (ret == NULL)
  ------------------
  |  Branch (1664:8): [True: 0, False: 0]
  ------------------
 1665|       |				/* No need to return file */
 1666|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1667|       |
 1668|       |			/* Else, need to return file */
 1669|      0|			*ret = sc_file_new();
 1670|      0|			(*ret)->size = priv->max_cert_size;
 1671|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1672|      0|		}
 1673|       |
 1674|  7.18k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1674:7): [True: 2.42k, False: 4.76k]
  ------------------
 1675|  2.42k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.42k|	int _ret = r; \
  |  |  |  |  155|  2.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.42k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.42k|	return _ret; \
  |  |  |  |  163|  2.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1676|  2.42k|		}
 1677|  7.18k|	}
 1678|       |
 1679|       |	/* success: select file = set "current" pointer to blob found */
 1680|  2.37k|	priv->current = blob;
 1681|       |
 1682|  2.37k|	if (ret)
  ------------------
  |  Branch (1682:6): [True: 1.49k, False: 876]
  ------------------
 1683|  1.49k|		sc_file_dup(ret, blob->file);
 1684|       |
 1685|  2.37k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.37k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.37k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.37k|	int _ret = r; \
  |  |  |  |  155|  2.37k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.37k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.37k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.37k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.37k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.37k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.37k|	return _ret; \
  |  |  |  |  163|  2.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1686|  2.37k|}
card-openpgp.c:pgp_strip_path:
 1595|  4.79k|{
 1596|  4.79k|	unsigned int start_point = 0;
 1597|       |	/* start_point will move through the path string */
 1598|  4.79k|	if (path->len == 0)
  ------------------
  |  Branch (1598:6): [True: 0, False: 4.79k]
  ------------------
 1599|      0|		return 0;
 1600|       |
 1601|       |	/* ignore 3F00 (MF) at the beginning */
 1602|  4.79k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1602:16): [True: 2.62k, False: 2.17k]
  ------------------
 1603|       |	/* strip path of PKCS15-App DF (5015) */
 1604|  4.79k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1604:17): [True: 1.62k, False: 3.17k]
  ------------------
 1605|  4.79k|	return start_point;
 1606|  4.79k|}
card-openpgp.c:pgp_read_binary:
 1755|  1.19k|{
 1756|  1.19k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.19k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1757|  1.19k|	pgp_blob_t	*blob;
 1758|  1.19k|	int		r;
 1759|       |
 1760|  1.19k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.19k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.19k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1761|       |
 1762|       |	/* jump to selected file */
 1763|  1.19k|	blob = priv->current;
 1764|       |
 1765|  1.19k|	if (blob == NULL)
  ------------------
  |  Branch (1765:6): [True: 0, False: 1.19k]
  ------------------
 1766|  1.19k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|       |
 1768|  1.19k|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|  1.19k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1768:6): [True: 0, False: 1.19k]
  ------------------
 1769|  1.19k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|       |
 1771|  1.19k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1771:6): [True: 0, False: 1.19k]
  ------------------
 1772|  1.19k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|       |
 1774|  1.19k|	if (idx > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 1.19k]
  ------------------
 1775|  1.19k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1776|       |
 1777|  1.19k|	if (idx + count > blob->len)
  ------------------
  |  Branch (1777:6): [True: 0, False: 1.19k]
  ------------------
 1778|      0|		count = blob->len - idx;
 1779|  1.19k|	memcpy(buf, blob->data + idx, count);
 1780|       |
 1781|  1.19k|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  164|  1.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.19k|	int _ret = r; \
  |  |  |  |  155|  1.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.19k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.19k|	} else { \
  |  |  |  |  159|  1.19k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.19k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.19k|	} \
  |  |  |  |  162|  1.19k|	return _ret; \
  |  |  |  |  163|  1.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|  1.19k|}
card-openpgp.c:pgp_pin_cmd:
 2388|     79|{
 2389|     79|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     79|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2390|     79|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2391|       |
 2392|     79|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     79|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     79|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     79|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     79|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 79]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2393|       |
 2394|     79|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|     79|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2394:6): [True: 0, False: 79]
  ------------------
 2395|     79|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2396|     79|				"invalid PIN type");
 2397|       |
 2398|       |	/* In general, the PIN Reference is extracted from the key-id,
 2399|       |	 * for example, CHV0 -> Ref=0, CHV1 -> Ref=1.
 2400|       |	 * However, in the case of OpenPGP, the PIN Ref to compose APDU
 2401|       |	 * must be 81, 82, 83.
 2402|       |	 * So, if we receive Ref=1, Ref=2, we must convert to 81, 82...
 2403|       |	 * In OpenPGP v1, the PINs are named CHV1, CHV2, CHV3.
 2404|       |	 * In v2, they are named PW1, PW3 (PW1 operates in 2 modes).
 2405|       |	 *
 2406|       |	 * The PIN references (P2 in APDU) for "VERIFY" are the same in both versions:
 2407|       |	 * 81 (CHV1 or PW1), 82 (CHV2 or PW1-mode 2), 83 (CHV3 or PW3),
 2408|       |	 * On the other hand from version 2.0 "CHANGE REFERENCE DATA" and
 2409|       |	 * "RESET RETRY COUNTER" don't support PW1-mode 2 (82) and need this
 2410|       |	 * value changed to PW1 (81).
 2411|       |	 * Both of these commands also differ between card versions in that
 2412|       |	 * v1 cards can use only implicit old PIN or CHV3 test for both commands
 2413|       |	 * whereas v2 can use both implicit (for PW3) and explicit
 2414|       |	 * (for special "Resetting Code") PIN test for "RESET RETRY COUNTER"
 2415|       |	 * and only explicit test for "CHANGE REFERENCE DATA".
 2416|       |	 *
 2417|       |	 * Note that if this function is called from sc_pkcs15_verify_pin() in pkcs15-pin.c,
 2418|       |	 * the Ref is already 81, 82, 83.
 2419|       |	 */
 2420|       |
 2421|       |	/* convert the PIN Reference if needed */
 2422|     79|	data->pin_reference |= 0x80;
 2423|       |
 2424|       |	/* check version-dependent constraints */
 2425|     79|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|    158|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|     79|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2425:6): [True: 0, False: 79]
  |  Branch (2425:40): [True: 0, False: 79]
  ------------------
 2426|      0|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2426:7): [True: 0, False: 0]
  ------------------
 2427|      0|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2427:8): [True: 0, False: 0]
  ------------------
 2428|      0|				data->pin_reference = 0x81;
 2429|       |
 2430|      0|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2430:8): [True: 0, False: 0]
  ------------------
 2431|      0|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2431:9): [True: 0, False: 0]
  ------------------
 2432|      0|				    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2432:9): [True: 0, False: 0]
  ------------------
 2433|      0|					LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2434|      0|							"v2 cards don't support implicit old PIN for PIN change");
 2435|       |
 2436|      0|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2437|      0|			}
 2438|      0|		} else {
 2439|      0|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2439:8): [True: 0, False: 0]
  ------------------
 2440|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2441|      0|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2442|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2443|      0|				       "please make sure that you have verified the relevant PIN first.");
 2444|      0|				data->pin1.len = 0;
 2445|      0|			}
 2446|       |
 2447|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2448|      0|		}
 2449|      0|	}
 2450|       |
 2451|     79|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  417|    158|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2451:6): [True: 0, False: 79]
  |  Branch (2451:41): [True: 0, False: 0]
  ------------------
 2452|      0|	    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2452:6): [True: 0, False: 0]
  ------------------
 2453|     79|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2454|     79|				"new PIN must be provided for unblock operation");
 2455|       |
 2456|       |	/* ensure pin_reference is 81, 82, 83 */
 2457|     79|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2457:6): [True: 0, False: 79]
  |  Branch (2457:36): [True: 0, False: 79]
  ------------------
 2458|     79|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|     79|				"Invalid key ID; must be 1, 2, or 3");
 2460|       |
 2461|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2462|     79|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  418|    158|#define SC_PIN_CMD_GET_INFO	3
  ------------------
              	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  553|     13|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2462:6): [True: 13, False: 66]
  |  Branch (2462:42): [True: 9, False: 4]
  ------------------
 2463|      9|		u8 c4data[10];
 2464|      9|		int r;
 2465|       |
 2466|      9|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2467|      9|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2468|       |
 2469|      7|		if (r != 7)
  ------------------
  |  Branch (2469:7): [True: 2, False: 5]
  ------------------
 2470|      7|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2471|      5|				"CHV status bytes have unexpected length");
 2472|       |
 2473|       |		/* The definition of fields of DO C4 changed between OpenPGP
 2474|       |		 * card specification v1.1 and v2.0. There is no longer a separate
 2475|       |		 * CHV2 retry counter but only one retry counter for both PW1 mode 1
 2476|       |		 * and mode 2 at byte 5 (count from 1) of the DO.
 2477|       |		 */
 2478|      5|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2478:7): [True: 1, False: 4]
  |  Branch (2478:48): [True: 1, False: 0]
  ------------------
 2479|      1|			data->pin_reference = 0x81;
 2480|       |
 2481|      5|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2482|      5|		data->pin1.max_tries = 3;
 2483|      5|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      5|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2484|       |
 2485|      5|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2486|      5|	}
 2487|       |
 2488|     70|#ifdef ENABLE_OPENSSL
 2489|     70|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2489:6): [True: 0, False: 70]
  ------------------
 2490|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2491|      0|	}
 2492|     70|#endif /* ENABLE_OPENSSL */
 2493|       |
 2494|     70|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  157|     70|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     70|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     70|	return _ret; \
  |  |  |  |  163|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|     70|}
card-openpgp.c:pgp_get_data:
 1994|  6.01k|{
 1995|  6.01k|	sc_apdu_t	apdu;
 1996|  6.01k|	int		r;
 1997|       |
 1998|  6.01k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1999|       |
 2000|  6.01k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  6.01k|#define SC_APDU_CASE_2			0x22
  ------------------
 2001|  6.01k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  547|  4.32k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2001:13): [True: 4.32k, False: 1.68k]
  |  Branch (2001:33): [True: 4.27k, False: 55]
  ------------------
 2002|  6.01k|	apdu.resp = buf;
 2003|  6.01k|	apdu.resplen = buf_len;
 2004|       |
 2005|  6.01k|	r = sc_transmit_apdu(card, &apdu);
 2006|  6.01k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.01k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.01k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.01k|	int _ret = (r); \
  |  |  |  |  168|  6.01k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 200, False: 5.81k]
  |  |  |  |  ------------------
  |  |  |  |  169|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    200|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    200|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    200|		return _ret; \
  |  |  |  |  172|    200|	} \
  |  |  |  |  173|  6.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2007|       |
 2008|  5.81k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2009|       |
 2010|       |	/* Gnuk returns an error instead of empty data if there is no certificate or private DO.
 2011|       |	 * So, for this case, we ignore error and consider success */
 2012|  5.81k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2012:6): [True: 256, False: 5.55k]
  ------------------
 2013|    256|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|    512|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2013:7): [True: 64, False: 192]
  ------------------
 2014|    192|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|    448|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2014:7): [True: 9, False: 183]
  ------------------
 2015|    183|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|    439|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2015:7): [True: 9, False: 174]
  ------------------
 2016|    174|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|    430|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2016:7): [True: 9, False: 165]
  ------------------
 2017|    165|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|    165|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2017:7): [True: 9, False: 156]
  ------------------
 2018|    100|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    100|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2018:7): [True: 1, False: 99]
  ------------------
 2019|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2020|      1|			apdu.resplen = 0;
 2021|      1|		}
 2022|    100|	}
 2023|  5.81k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  5.81k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.81k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.81k|	int _ret = (r); \
  |  |  |  |  168|  5.81k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.65k, False: 2.15k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.65k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.65k|		return _ret; \
  |  |  |  |  172|  3.65k|	} \
  |  |  |  |  173|  5.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2024|       |
 2025|  2.15k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.15k|	int _ret = r; \
  |  |  |  |  155|  2.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.63k|	} else { \
  |  |  |  |  159|  1.63k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.63k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.63k|	} \
  |  |  |  |  162|  2.15k|	return _ret; \
  |  |  |  |  163|  2.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|  2.15k|}
card-openpgp.c:pgp_set_security_env:
 2538|     37|{
 2539|     37|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     37|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2540|       |
 2541|     37|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     37|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     37|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     37|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     37|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2542|       |
 2543|       |	/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
 2544|     37|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   60|     37|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (2544:6): [True: 37, False: 0]
  ------------------
 2545|     37|		&& (env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|     37|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2545:6): [True: 0, False: 37]
  ------------------
 2546|      0|		&& (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (2546:6): [True: 0, False: 0]
  ------------------
 2547|      0|		&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
  ------------------
  |  Branch (2547:6): [True: 0, False: 0]
  ------------------
 2548|     37|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2549|     37|				"only RSA algorithm supported");
 2550|       |
 2551|     37|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len != 1))
  ------------------
  |  |   58|     37|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (2551:6): [True: 0, False: 37]
  |  Branch (2551:52): [True: 0, False: 37]
  ------------------
 2552|     37|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2553|     37|				"exactly one key reference required");
 2554|       |
 2555|     37|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   57|     37|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (2555:6): [True: 0, False: 37]
  ------------------
 2556|     37|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2557|     37|			"passing file references not supported");
 2558|       |
 2559|     37|	sc_log(card->ctx, "Key ref %d", env->key_ref[0]);
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2560|     37|	switch (env->operation) {
 2561|     18|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     18|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2561:2): [True: 18, False: 19]
  ------------------
 2562|     18|		sc_log(card->ctx, "Operation: Sign.");
  ------------------
  |  |   71|     18|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2563|     18|		if (env->key_ref[0] != 0x00 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2563:7): [True: 0, False: 18]
  |  Branch (2563:34): [True: 0, False: 0]
  ------------------
 2564|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2565|      0|				"Key reference not compatible with "
 2566|      0|				"requested usage");
 2567|      0|		}
 2568|     18|		break;
 2569|     19|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     19|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2569:2): [True: 19, False: 18]
  ------------------
 2570|     19|		sc_log(card->ctx, "Operation: Decipher.");
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2571|       |		/* we allow key ref 2 (auth key) to be used for deciphering */
 2572|     19|		if (env->key_ref[0] != 0x01 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2572:7): [True: 0, False: 19]
  |  Branch (2572:34): [True: 0, False: 0]
  ------------------
 2573|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2574|      0|				"Key reference not compatible with "
 2575|      0|				"requested usage");
 2576|      0|		}
 2577|     19|		break;
 2578|     19|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2578:2): [True: 0, False: 37]
  ------------------
 2579|      0|		sc_log(card->ctx, "Operation: Derive: No particular action needed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2580|      0|		break;
 2581|      0|	default:
  ------------------
  |  Branch (2581:2): [True: 0, False: 37]
  ------------------
 2582|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2583|     37|				"invalid operation");
 2584|     37|	}
 2585|       |
 2586|     37|	priv->sec_env = *env;
 2587|       |
 2588|     37|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     37|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     37|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     37|	int _ret = r; \
  |  |  |  |  155|     37|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 37, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  157|     37|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     37|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     37|	return _ret; \
  |  |  |  |  163|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2589|     37|}
card-openpgp.c:pgp_compute_signature:
 2643|     18|{
 2644|     18|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     18|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2645|     18|	sc_security_env_t	*env = &priv->sec_env;
 2646|     18|	sc_apdu_t		apdu;
 2647|     18|	u8 apdu_case = (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
  ------------------
  |  Branch (2647:17): [True: 0, False: 18]
  ------------------
 2648|     18|			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  303|     36|#define SC_APDU_CASE_4			0x24
  ------------------
 2649|     18|	int			r;
 2650|       |
 2651|     18|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     18|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     18|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     18|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     18|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2652|       |
 2653|     18|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|     18|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2653:6): [True: 0, False: 18]
  ------------------
 2654|     18|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2655|     18|				"invalid operation");
 2656|       |
 2657|     18|	switch (env->key_ref[0]) {
 2658|     18|	case 0x00: /* signature key */
  ------------------
  |  Branch (2658:2): [True: 18, False: 0]
  ------------------
 2659|       |		/* PSO SIGNATURE */
 2660|     18|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x9E, 0x9A);
 2661|     18|		break;
 2662|      0|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2662:2): [True: 0, False: 18]
  ------------------
 2663|       |		/* INTERNAL AUTHENTICATE */
 2664|      0|		sc_format_apdu(card, &apdu, apdu_case, 0x88, 0, 0);
 2665|      0|		break;
 2666|      0|	case 0x01:
  ------------------
  |  Branch (2666:2): [True: 0, False: 18]
  ------------------
 2667|      0|	default:
  ------------------
  |  Branch (2667:2): [True: 0, False: 18]
  ------------------
 2668|       |		/* From PKCS #11 point of view, we should be able to use
 2669|       |		 * curve25519 to do digital signature, but it is not how it
 2670|       |		 * is used in OpenPGP so we will not allow it here */
 2671|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2672|     18|			"invalid key reference");
 2673|     18|	}
 2674|       |
 2675|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2676|     18|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|     18|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2676:6): [True: 18, False: 0]
  |  Branch (2676:52): [True: 0, False: 18]
  ------------------
 2677|      0|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      0|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2678|       |
 2679|     18|	apdu.lc = data_len;
 2680|     18|	apdu.data = (u8 *)data;
 2681|     18|	apdu.datalen = data_len;
 2682|     18|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|     18|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2682:13): [True: 18, False: 0]
  |  Branch (2682:32): [True: 18, False: 0]
  ------------------
 2683|     18|	apdu.resp    = out;
 2684|     18|	apdu.resplen = outlen;
 2685|       |
 2686|     18|	r = sc_transmit_apdu(card, &apdu);
 2687|     18|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2688|       |
 2689|     17|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2690|     17|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2691|       |
 2692|      6|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      6|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2693|      6|}
card-openpgp.c:pgp_decipher:
 2702|     19|{
 2703|     19|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     19|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2704|     19|	sc_security_env_t	*env = &priv->sec_env;
 2705|     19|	sc_apdu_t	apdu;
 2706|     19|	u8 apdu_case = SC_APDU_CASE_4;
  ------------------
  |  |  303|     19|#define SC_APDU_CASE_4			0x24
  ------------------
 2707|     19|	u8		*temp = NULL, *p = NULL;
 2708|     19|	size_t		templen, pklen, dolen;
 2709|     19|	int		r;
 2710|       |
 2711|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2712|       |
 2713|       |	/* padding according to OpenPGP card spec 1.1 & 2.x section 7.2.9 / 3.x section 7.2.11
 2714|       |	 * The longest possible prefix is 10 bytes for ECDH */
 2715|     19|	templen = inlen + 10;
 2716|     19|	if (!(temp = malloc(templen)))
  ------------------
  |  Branch (2716:6): [True: 0, False: 19]
  ------------------
 2717|     19|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2718|       |
 2719|       |	/* padding byte: 0xa6 = ECC; 0x00 = RSA; 0x02 = AES */
 2720|     19|	switch (env->algorithm) {
 2721|     19|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|     19|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2721:2): [True: 19, False: 0]
  ------------------
 2722|       |		/* This is just PKCS#1.5 start byte and it should be already
 2723|       |		 * provided by the padding routines. But it lets put it here
 2724|       |		 * to make sure it does not conflict with following indicators */
 2725|     19|		temp[0] = 0x00;
 2726|     19|		memcpy(temp + 1, in, inlen);
 2727|     19|		inlen += 1;
 2728|     19|		break;
 2729|       |
 2730|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2730:2): [True: 0, False: 19]
  ------------------
 2731|      0|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (2731:2): [True: 0, False: 19]
  ------------------
 2732|       |		/* Calculate length of External Public Key (0x86) */
 2733|      0|		r = sc_asn1_put_tag(0x86, NULL, inlen, NULL, 0, NULL);
 2734|      0|		if (r <= 0) {
  ------------------
  |  Branch (2734:7): [True: 0, False: 0]
  ------------------
 2735|      0|			free(temp);
 2736|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2737|      0|		}
 2738|      0|		pklen = r;
 2739|       |
 2740|       |		/* Calculate length of Public Key DO (0x7F49) */
 2741|      0|		r = sc_asn1_put_tag(0x7f49, NULL, pklen, NULL, 0, NULL);
 2742|      0|		if (r <= 0) {
  ------------------
  |  Branch (2742:7): [True: 0, False: 0]
  ------------------
 2743|      0|			free(temp);
 2744|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2745|      0|		}
 2746|      0|		dolen = r;
 2747|       |
 2748|      0|		p = temp;
 2749|       |		/* This is 0xA6 Cipher DO with associated length field */
 2750|      0|		r = sc_asn1_put_tag(0xA6, NULL, dolen, p, templen - (p - temp), &p);
 2751|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2751:7): [True: 0, False: 0]
  ------------------
 2752|      0|			free(temp);
 2753|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2754|      0|		}
 2755|       |
 2756|       |		/* Public Key DO (0x7F49) with associated length field */
 2757|      0|		r = sc_asn1_put_tag(0x7F49, NULL, pklen, p, templen - (p - temp), &p);
 2758|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2758:7): [True: 0, False: 0]
  ------------------
 2759|      0|			free(temp);
 2760|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2761|      0|		}
 2762|       |
 2763|       |		/* External Public Key (0x86) with associated length */
 2764|      0|		r = sc_asn1_put_tag(0x86, in, inlen, p, templen - (p - temp), &p);
 2765|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2765:7): [True: 0, False: 0]
  ------------------
 2766|      0|			free(temp);
 2767|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2768|      0|		}
 2769|      0|		inlen = (p - temp);
 2770|      0|		break;
 2771|      0|	case SC_ALGORITHM_AES:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (2771:2): [True: 0, False: 19]
  ------------------
 2772|       |		/* not supported yet */
 2773|       |		/*
 2774|       |		temp[0] = 0x02;
 2775|       |		memcpy(temp + 1, in, inlen);
 2776|       |		inlen += 1;
 2777|       |		*/
 2778|       |		/* fall through */
 2779|      0|	default:
  ------------------
  |  Branch (2779:2): [True: 0, False: 19]
  ------------------
 2780|      0|		free(temp);
 2781|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2782|     19|	}
 2783|       |
 2784|     19|	in = temp;
 2785|       |
 2786|     19|	if (env->operation != SC_SEC_OPERATION_DECIPHER &&
  ------------------
  |  |   47|     38|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2786:6): [True: 0, False: 19]
  ------------------
 2787|      0|			env->operation != SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2787:4): [True: 0, False: 0]
  ------------------
 2788|      0|		free(temp);
 2789|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2790|      0|				"invalid operation");
 2791|      0|	}
 2792|       |
 2793|     19|	switch (env->key_ref[0]) {
 2794|     19|	case 0x01: /* Decryption key */
  ------------------
  |  Branch (2794:2): [True: 19, False: 0]
  ------------------
 2795|     19|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2795:2): [True: 0, False: 19]
  ------------------
 2796|       |		/* PSO DECIPHER */
 2797|     19|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x80, 0x86);
 2798|     19|		break;
 2799|      0|	case 0x00: /* signature key */
  ------------------
  |  Branch (2799:2): [True: 0, False: 19]
  ------------------
 2800|      0|	default:
  ------------------
  |  Branch (2800:2): [True: 0, False: 19]
  ------------------
 2801|      0|		free(temp);
 2802|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2803|     19|				"invalid key reference");
 2804|     19|	}
 2805|       |
 2806|       |	/* Gnuk only supports short APDU, so we need to use command chaining */
 2807|     19|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (2807:6): [True: 0, False: 19]
  ------------------
 2808|      0|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      0|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2809|      0|	}
 2810|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2811|     19|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|     19|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2811:6): [True: 16, False: 3]
  |  Branch (2811:52): [True: 4, False: 12]
  ------------------
 2812|      4|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      4|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2813|       |
 2814|     19|	apdu.lc = inlen;
 2815|     19|	apdu.data = (u8 *)in;
 2816|     19|	apdu.datalen = inlen;
 2817|     19|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|     19|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2817:13): [True: 19, False: 0]
  |  Branch (2817:32): [True: 16, False: 3]
  ------------------
 2818|     19|	apdu.resp = out;
 2819|     19|	apdu.resplen = outlen;
 2820|       |
 2821|       |	/* For OpenPGP Card >=v3.3, key slot 3 instead of 2 can be used for deciphering,
 2822|       |	 * but this has to be set via MSE beforehand on every usage (slot 2 is used by default)
 2823|       |	 * see section 7.2.18 of the specification of OpenPGP Card v3.3 */
 2824|     19|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2824:6): [True: 6, False: 13]
  |  Branch (2824:47): [True: 0, False: 6]
  ------------------
 2825|      0|		pgp_set_MSE(card, 3, 0xb8);
 2826|      0|	}
 2827|       |
 2828|     19|	r = sc_transmit_apdu(card, &apdu);
 2829|     19|	free(temp);
 2830|     19|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2831|       |
 2832|     17|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2833|     17|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2834|       |
 2835|       |	/* For OpenPGP Card >=v3.3, use key slot 2 for deciphering again (set to default) */
 2836|      4|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2836:6): [True: 2, False: 2]
  |  Branch (2836:47): [True: 0, False: 2]
  ------------------
 2837|      0|		pgp_set_MSE(card, 2, 0xb8);
 2838|      0|	}
 2839|       |
 2840|      4|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      3|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      3|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      3|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|      4|}
card-openpgp.c:pgp_card_ctl:
 4009|    119|{
 4010|    119|	int r;
 4011|       |
 4012|    119|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    119|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    119|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    119|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    119|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 119]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4013|       |
 4014|    119|	switch(cmd) {
  ------------------
  |  Branch (4014:9): [True: 119, False: 0]
  ------------------
 4015|     13|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4015:2): [True: 13, False: 106]
  ------------------
 4016|     13|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4017|     13|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4018|      0|		break;
 4019|    106|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4019:2): [True: 106, False: 13]
  ------------------
 4020|    106|		r = pgp_select_data(card, *((u8 *) ptr));
 4021|    106|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    106|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    106|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    106|	int _ret = r; \
  |  |  |  |  155|    106|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 106, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    106|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     89|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 89, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  157|    106|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    106|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    106|	return _ret; \
  |  |  |  |  163|    106|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4022|      0|		break;
 4023|      0|#ifdef ENABLE_OPENSSL
 4024|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4024:2): [True: 0, False: 119]
  ------------------
 4025|      0|		r = pgp_gen_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4026|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4027|      0|		break;
 4028|      0|	case SC_CARDCTL_OPENPGP_STORE_KEY:
  ------------------
  |  Branch (4028:2): [True: 0, False: 119]
  ------------------
 4029|      0|		r = pgp_store_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4030|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4031|      0|		break;
 4032|      0|#endif /* ENABLE_OPENSSL */
 4033|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (4033:2): [True: 0, False: 119]
  ------------------
 4034|      0|		r = pgp_erase_card(card);
 4035|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4036|      0|		break;
 4037|    119|	}
 4038|       |
 4039|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4040|      0|}
card-openpgp.c:pgp_select_data:
 1956|    106|{
 1957|    106|	sc_apdu_t	apdu;
 1958|    106|	u8	apdu_data[6];
 1959|    106|	int	r;
 1960|    106|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    106|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1961|       |
 1962|    106|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    106|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    106|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    106|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    106|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 106]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1963|       |
 1964|    106|	if (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (1964:6): [True: 58, False: 48]
  ------------------
 1965|    106|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     58|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     58|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     58|	int _ret = r; \
  |  |  |  |  155|     58|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     58|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     58|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     58|	return _ret; \
  |  |  |  |  163|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1966|       |
 1967|     48|	sc_log(card->ctx, "select data with: %u", p1);
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1968|       |
 1969|       |	// create apdu data (taken from spec: SELECT DATA 7.2.5.)
 1970|     48|	apdu_data[0] = 0x60;
 1971|     48|	apdu_data[1] = 0x04;
 1972|     48|	apdu_data[2] = 0x5c;
 1973|     48|	apdu_data[3] = 0x02;
 1974|     48|	apdu_data[4] = 0x7f;
 1975|     48|	apdu_data[5] = 0x21;
 1976|       |
 1977|       |	// apdu, cla, ins, p1, p2, data, datalen, resp, resplen
 1978|     48|	sc_format_apdu_ex(&apdu, 0x00, 0xA5, p1, 0x04, apdu_data, sizeof(apdu_data), NULL, 0);
 1979|       |
 1980|       |	// transmit apdu
 1981|     48|	r = sc_transmit_apdu(card, &apdu);
 1982|     48|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     48|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     48|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     48|	int _ret = (r); \
  |  |  |  |  168|     48|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|     42|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1984|     42|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     42|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     42|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     42|	int _ret = (r); \
  |  |  |  |  168|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     25|		return _ret; \
  |  |  |  |  172|     25|	} \
  |  |  |  |  173|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1985|     17|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1986|     17|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4169|  9.47k|{
 4170|  9.47k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  9.47k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4171|  9.47k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  9.47k|#define SC_SUCCESS				0
  ------------------
 4172|       |
 4173|  9.47k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.47k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.47k]
  |  |  ------------------
  ------------------
 4174|       |
 4175|  9.47k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  537|  18.9k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4175:6): [True: 0, False: 9.47k]
  ------------------
 4176|      0|			&& was_reset <= 0
  ------------------
  |  Branch (4176:7): [True: 0, False: 0]
  ------------------
 4177|      0|			&& priv != NULL && priv->mf && priv->mf->file) {
  ------------------
  |  Branch (4177:7): [True: 0, False: 0]
  |  Branch (4177:23): [True: 0, False: 0]
  |  Branch (4177:35): [True: 0, False: 0]
  ------------------
 4178|       |		/* check whether applet is still selected */
 4179|      0|		unsigned char aid[16];
 4180|       |
 4181|      0|		r = sc_get_data(card, 0x004F, aid, sizeof aid);
 4182|      0|		if ((size_t) r != priv->mf->file->namelen
  ------------------
  |  Branch (4182:7): [True: 0, False: 0]
  ------------------
 4183|      0|				|| 0 != memcmp(aid, priv->mf->file->name, r)) {
  ------------------
  |  Branch (4183:8): [True: 0, False: 0]
  ------------------
 4184|       |			/* reselect is required */
 4185|      0|			was_reset = 1;
 4186|      0|		}
 4187|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 4188|      0|	}
 4189|       |
 4190|  9.47k|	if (was_reset > 0) {
  ------------------
  |  Branch (4190:6): [True: 0, False: 9.47k]
  ------------------
 4191|      0|		sc_file_t	*file = NULL;
 4192|      0|		sc_path_t	path;
 4193|       |		/* select application "OpenPGP" */
 4194|      0|		sc_format_path("D276:0001:2401", &path);
 4195|      0|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 4196|      0|		r = iso_ops->select_file(card, &path, &file);
 4197|      0|		sc_file_free(file);
 4198|      0|	}
 4199|       |
 4200|  9.47k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  9.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.47k|	int _ret = r; \
  |  |  |  |  155|  9.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9.47k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.47k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.47k|	return _ret; \
  |  |  |  |  163|  9.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4201|  9.47k|}

sc_get_piv_driver:
 6708|  15.2k|{
 6709|  15.2k|	return sc_get_driver();
 6710|  15.2k|}
card-piv.c:sc_get_driver:
 6681|  15.2k|{
 6682|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6683|       |
 6684|  15.2k|	piv_ops = *iso_drv->ops;
 6685|  15.2k|	piv_ops.match_card = piv_match_card;
 6686|  15.2k|	piv_ops.init = piv_init;
 6687|  15.2k|	piv_ops.finish = piv_finish;
 6688|       |
 6689|  15.2k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6690|  15.2k|	piv_ops.get_challenge = piv_get_challenge;
 6691|  15.2k|	piv_ops.logout = piv_logout;
 6692|  15.2k|	piv_ops.read_binary = piv_read_binary;
 6693|  15.2k|	piv_ops.write_binary = piv_write_binary;
 6694|  15.2k|	piv_ops.set_security_env = piv_set_security_env;
 6695|  15.2k|	piv_ops.restore_security_env = piv_restore_security_env;
 6696|  15.2k|	piv_ops.compute_signature = piv_compute_signature;
 6697|  15.2k|	piv_ops.decipher = piv_decipher;
 6698|  15.2k|	piv_ops.check_sw = piv_check_sw;
 6699|  15.2k|	piv_ops.card_ctl = piv_card_ctl;
 6700|  15.2k|	piv_ops.pin_cmd = piv_pin_cmd;
 6701|  15.2k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6702|       |
 6703|  15.2k|	return &piv_drv;
 6704|  15.2k|}
card-piv.c:piv_match_card:
 5629|  5.73k|{
 5630|  5.73k|	int r = 0;
 5631|       |
 5632|  5.73k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.73k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5633|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5634|       |	/* user provided card type must be one we know */
 5635|  5.73k|	switch (card->type) {
 5636|  5.73k|	case -1:
  ------------------
  |  Branch (5636:2): [True: 5.73k, False: 0]
  ------------------
 5637|  5.73k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5637:2): [True: 0, False: 5.73k]
  ------------------
 5638|  5.73k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5638:2): [True: 0, False: 5.73k]
  ------------------
 5639|  5.73k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5639:2): [True: 0, False: 5.73k]
  ------------------
 5640|  5.73k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5640:2): [True: 0, False: 5.73k]
  ------------------
 5641|  5.73k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5641:2): [True: 0, False: 5.73k]
  ------------------
 5642|  5.73k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5642:2): [True: 0, False: 5.73k]
  ------------------
 5643|  5.73k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5643:2): [True: 0, False: 5.73k]
  ------------------
 5644|  5.73k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5644:2): [True: 0, False: 5.73k]
  ------------------
 5645|  5.73k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5645:2): [True: 0, False: 5.73k]
  ------------------
 5646|  5.73k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5646:2): [True: 0, False: 5.73k]
  ------------------
 5647|  5.73k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5647:2): [True: 0, False: 5.73k]
  ------------------
 5648|  5.73k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5648:2): [True: 0, False: 5.73k]
  ------------------
 5649|  5.73k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5649:2): [True: 0, False: 5.73k]
  ------------------
 5650|  5.73k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5650:2): [True: 0, False: 5.73k]
  ------------------
 5651|  5.73k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5651:2): [True: 0, False: 5.73k]
  ------------------
 5652|  5.73k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5652:2): [True: 0, False: 5.73k]
  ------------------
 5653|  5.73k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5653:2): [True: 0, False: 5.73k]
  ------------------
 5654|  5.73k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5654:2): [True: 0, False: 5.73k]
  ------------------
 5655|  5.73k|		break;
 5656|      0|	default:
  ------------------
  |  Branch (5656:2): [True: 0, False: 5.73k]
  ------------------
 5657|      0|		return 0; /* can not handle the card */
 5658|  5.73k|	}
 5659|       |
 5660|  5.73k|	r = sc_lock(card);
 5661|  5.73k|	if (r < 0)
  ------------------
  |  Branch (5661:6): [True: 0, False: 5.73k]
  ------------------
 5662|      0|		return 0;
 5663|       |	/* its one we know, or we can test for it in piv_init */
 5664|  5.73k|	r = piv_match_card_continued(card);
 5665|  5.73k|	sc_unlock(card);
 5666|       |
 5667|  5.73k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5667:6): [True: 4.79k, False: 945]
  |  Branch (5667:15): [True: 0, False: 945]
  ------------------
 5668|       |		/* clean up what we left in card */
 5669|  4.79k|		piv_finish(card);
 5670|  4.79k|		return 0; /* match failed */
 5671|  4.79k|	}
 5672|       |
 5673|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5674|    945|	return 1; /* matched */
 5675|  5.73k|}
card-piv.c:piv_match_card_continued:
 5679|  5.73k|{
 5680|  5.73k|	int i, r = 0, r2 = 0;
 5681|  5.73k|	int type = -1;
 5682|  5.73k|	piv_private_data_t *priv = NULL;
 5683|  5.73k|	int saved_type = card->type;
 5684|  5.73k|	sc_apdu_t apdu;
 5685|  5.73k|	u8 yubico_version_buf[3] = {0};
 5686|       |
 5687|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5688|       |	/* User provided card type must be one we know */
 5689|       |
 5690|  5.73k|	switch (card->type) {
 5691|  5.73k|	case -1:
  ------------------
  |  Branch (5691:2): [True: 5.73k, False: 0]
  ------------------
 5692|  5.73k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5692:2): [True: 0, False: 5.73k]
  ------------------
 5693|  5.73k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5693:2): [True: 0, False: 5.73k]
  ------------------
 5694|  5.73k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5694:2): [True: 0, False: 5.73k]
  ------------------
 5695|  5.73k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5695:2): [True: 0, False: 5.73k]
  ------------------
 5696|  5.73k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5696:2): [True: 0, False: 5.73k]
  ------------------
 5697|  5.73k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5697:2): [True: 0, False: 5.73k]
  ------------------
 5698|  5.73k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5698:2): [True: 0, False: 5.73k]
  ------------------
 5699|  5.73k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5699:2): [True: 0, False: 5.73k]
  ------------------
 5700|  5.73k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5700:2): [True: 0, False: 5.73k]
  ------------------
 5701|  5.73k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5701:2): [True: 0, False: 5.73k]
  ------------------
 5702|  5.73k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5702:2): [True: 0, False: 5.73k]
  ------------------
 5703|  5.73k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5703:2): [True: 0, False: 5.73k]
  ------------------
 5704|  5.73k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5704:2): [True: 0, False: 5.73k]
  ------------------
 5705|  5.73k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5705:2): [True: 0, False: 5.73k]
  ------------------
 5706|  5.73k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5706:2): [True: 0, False: 5.73k]
  ------------------
 5707|  5.73k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5707:2): [True: 0, False: 5.73k]
  ------------------
 5708|  5.73k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5708:2): [True: 0, False: 5.73k]
  ------------------
 5709|  5.73k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5709:2): [True: 0, False: 5.73k]
  ------------------
 5710|       |
 5711|  5.73k|		type = card->type;
 5712|  5.73k|		break;
 5713|      0|	default:
  ------------------
  |  Branch (5713:2): [True: 0, False: 5.73k]
  ------------------
 5714|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5715|  5.73k|	}
 5716|  5.73k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.73k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5717|  5.73k|	if (type == -1) {
  ------------------
  |  Branch (5717:6): [True: 5.73k, False: 0]
  ------------------
 5718|       |		/*
 5719|       |		 * Try to identify card by ATR or historical data in ATR
 5720|       |		 * currently all PIV card will respond to piv_find_aid
 5721|       |		 * the same. But in future may need to know card type first,
 5722|       |		 * so do it here.
 5723|       |		 */
 5724|       |
 5725|  5.73k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5725:7): [True: 1.24k, False: 4.49k]
  ------------------
 5726|  1.24k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5726:8): [True: 78, False: 1.16k]
  ------------------
 5727|     78|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5727:6): [True: 24, False: 54]
  ------------------
 5728|     24|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5729|  1.22k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5729:15): [True: 644, False: 578]
  ------------------
 5730|    644|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5730:6): [True: 82, False: 562]
  ------------------
 5731|     82|				type = SC_CARD_TYPE_PIV_II_NEO;
 5732|  1.14k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5732:15): [True: 625, False: 515]
  ------------------
 5733|    625|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5733:6): [True: 45, False: 580]
  ------------------
 5734|     45|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5735|  1.09k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5735:15): [True: 580, False: 515]
  ------------------
 5736|    580|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5736:6): [True: 11, False: 569]
  ------------------
 5737|     11|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5738|     11|			}
 5739|       |			/* look for TLV historic data */
 5740|  1.08k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5740:13): [True: 1.07k, False: 14]
  ------------------
 5741|  1.07k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5741:6): [True: 205, False: 865]
  ------------------
 5742|    205|				size_t datalen;
 5743|    205|				const u8 *data;
 5744|       |
 5745|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5746|    205|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5746:9): [True: 116, False: 89]
  ------------------
 5747|    205|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5748|    116|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5748:10): [True: 34, False: 82]
  |  Branch (5748:26): [True: 19, False: 15]
  ------------------
 5749|     19|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5750|     97|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5750:17): [True: 76, False: 21]
  |  Branch (5750:33): [True: 69, False: 7]
  ------------------
 5751|     69|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5752|     69|					}
 5753|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5754|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5755|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5756|       |					 * will look at only 6 bytes that do match
 5757|       |					 */
 5758|     28|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5758:15): [True: 7, False: 21]
  |  Branch (5758:31): [True: 4, False: 3]
  ------------------
 5759|      4|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5760|      4|					}
 5761|    116|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5761:16): [True: 41, False: 48]
  ------------------
 5762|     89|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5763|     41|					int k;
 5764|       |
 5765|    120|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5765:18): [True: 81, False: 39]
  ------------------
 5766|     81|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5766:11): [True: 73, False: 8]
  ------------------
 5767|     73|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5767:9): [True: 2, False: 71]
  ------------------
 5768|      2|							type = SC_CARD_TYPE_PIV_II_HIST;
 5769|      2|							break;
 5770|      2|						}
 5771|     81|					}
 5772|     41|				}
 5773|    205|			}
 5774|  1.24k|		}
 5775|       |
 5776|  5.73k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.73k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5777|       |
 5778|  5.73k|		if (type == -1) {
  ------------------
  |  Branch (5778:7): [True: 5.48k, False: 256]
  ------------------
 5779|       |			/* use known ATRs  which changes the type */
 5780|  5.48k|			i = _sc_match_atr(card, piv_atrs, &type);
 5781|  5.48k|			if (i < 0)
  ------------------
  |  Branch (5781:8): [True: 5.47k, False: 6]
  ------------------
 5782|  5.47k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5783|  5.48k|		}
 5784|  5.73k|	}
 5785|       |
 5786|  5.73k|	card->type = type;
 5787|       |
 5788|       |	/* we either found via ATR historic bytes or ATR directly */
 5789|  5.73k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.73k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5790|       |
 5791|       |	/* allocate and init basic fields */
 5792|  5.73k|	priv = calloc(1, sizeof(piv_private_data_t));
 5793|       |
 5794|  5.73k|	if (!priv)
  ------------------
  |  Branch (5794:6): [True: 0, False: 5.73k]
  ------------------
 5795|  5.73k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5796|       |
 5797|  5.73k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5798|       |	/*
 5799|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5800|       |	 * If for some reason future cards have larger objects, this value needs to
 5801|       |	 * be increased here.
 5802|       |	 */
 5803|  5.73k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  5.73k|#define MAX_FILE_SIZE 65535
  ------------------
 5804|  5.73k|	priv->selected_obj = -1;
 5805|  5.73k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5806|  5.73k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  5.73k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5807|  5.73k|	priv->pstate = PIV_STATE_MATCH;
 5808|       |
 5809|       |#ifdef ENABLE_PIV_SM
 5810|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5811|       |	card->sm_ctx.ops.open = piv_sm_open;
 5812|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5813|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5814|       |	card->sm_ctx.ops.close = piv_sm_close;
 5815|       |#endif /* ENABLE_PIV_SM */
 5816|       |
 5817|       |	/* See if contactless  or run as virtual card */
 5818|       |	/* PivApplet in .github/test_piv.sh for example */
 5819|  5.73k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5819:6): [True: 1.38k, False: 4.35k]
  ------------------
 5820|  1.38k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5820:4): [True: 1.26k, False: 121]
  ------------------
 5821|  1.26k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5821:4): [True: 84, False: 1.17k]
  ------------------
 5822|     84|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5822:4): [True: 49, False: 35]
  ------------------
 5823|     49|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5823:4): [True: 30, False: 19]
  ------------------
 5824|     30|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|     30|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5825|     30|	}
 5826|       |
 5827|   349k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5827:14): [True: 344k, False: 5.73k]
  ------------------
 5828|   344k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  655|   344k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5828:7): [True: 114k, False: 229k]
  ------------------
 5829|   114k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|   120k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5830|       |	/*
 5831|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5832|       |	 * and PIV must be the default application.
 5833|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5834|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5835|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5836|       |	 *
 5837|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5838|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5839|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5840|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5841|       |	 */
 5842|       |
 5843|       |	/*
 5844|       |	 * if ATR matched or user forced card type
 5845|       |	 * test if PIV is active applet without using AID If fails try AID
 5846|       |	 */
 5847|       |
 5848|  5.73k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5848:6): [True: 262, False: 5.47k]
  ------------------
 5849|    262|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|    262|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5849:4): [True: 259, False: 3]
  ------------------
 5850|    259|		r = piv_find_discovery(card);
 5851|    259|		if (r < 0) {
  ------------------
  |  Branch (5851:7): [True: 220, False: 39]
  ------------------
 5852|    220|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5853|    220|			r = piv_find_aid(card);
 5854|    220|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    220|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    220|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    220|	int _ret = (r); \
  |  |  |  |  178|    220|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 97, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  179|     97|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     97|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     97|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     97|		goto err; \
  |  |  |  |  182|     97|	} \
  |  |  |  |  183|    220|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5855|    220|		}
 5856|  5.47k|	} else {
 5857|       |		/* piv_find_aid saves al_label from response */
 5858|  5.47k|		r = piv_find_aid(card);
 5859|  5.47k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  5.47k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.47k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.47k|	int _ret = (r); \
  |  |  |  |  178|  5.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.69k, False: 783]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.69k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.69k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.69k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.69k|		goto err; \
  |  |  |  |  182|  4.69k|	} \
  |  |  |  |  183|  5.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 783]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5860|  5.47k|	}
 5861|       |
 5862|       |	/* Know to be PIV card but not the type */
 5863|       |
 5864|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5865|    945|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5865:6): [True: 18, False: 927]
  |  Branch (5865:24): [True: 16, False: 2]
  ------------------
 5866|     16|		switch (card->type) {
  ------------------
  |  Branch (5866:11): [True: 14, False: 2]
  ------------------
 5867|     14|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5867:3): [True: 14, False: 2]
  ------------------
 5868|     14|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5868:3): [True: 0, False: 16]
  ------------------
 5869|     39|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5869:16): [True: 27, False: 12]
  ------------------
 5870|     27|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5870:9): [True: 25, False: 2]
  ------------------
 5871|     25|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5871:7): [True: 2, False: 23]
  ------------------
 5872|      2|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_type);
  ------------------
  |  |   70|      2|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5873|      2|					card->type = al_map[i].al_type;
 5874|      2|					break;
 5875|      2|				}
 5876|     27|			}
 5877|     14|			break;
 5878|     16|		}
 5879|     16|	}
 5880|       |
 5881|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5882|    945|			card->type, priv->card_issues, r, priv->alg_ids);
 5883|       |
 5884|       |	/*
 5885|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5886|       |	 * via ATR, ATR Historic bytes or Application Label
 5887|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5888|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5889|       |	 */
 5890|    945|	switch (card->type) {
  ------------------
  |  Branch (5890:10): [True: 938, False: 7]
  ------------------
 5891|     68|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5891:2): [True: 68, False: 877]
  ------------------
 5892|    135|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5892:2): [True: 67, False: 878]
  ------------------
 5893|    153|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5893:2): [True: 18, False: 927]
  ------------------
 5894|    155|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5894:2): [True: 2, False: 943]
  ------------------
 5895|    156|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5895:2): [True: 1, False: 944]
  ------------------
 5896|    157|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5896:2): [True: 1, False: 944]
  ------------------
 5897|    157|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5897:2): [True: 0, False: 945]
  ------------------
 5898|    938|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5898:2): [True: 781, False: 164]
  ------------------
 5899|    938|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    938|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5900|    938|		apdu.lc = 0;
 5901|    938|		apdu.data = NULL;
 5902|    938|		apdu.datalen = 0;
 5903|    938|		apdu.resp = yubico_version_buf;
 5904|    938|		apdu.resplen = sizeof(yubico_version_buf);
 5905|    938|		apdu.le = apdu.resplen;
 5906|    938|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5907|    938|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  1.87k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5907:7): [True: 932, False: 6]
  |  Branch (5907:27): [True: 500, False: 432]
  ------------------
 5908|    500|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5909|    500|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    500|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5910|    500|			if (priv->yubico_version == 1) {
  ------------------
  |  Branch (5910:8): [True: 1, False: 499]
  ------------------
 5911|      1|				sc_log(card->ctx, "Detected Alpha/development version of yubikey. Assuming v6");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5912|      1|				priv->yubico_version = 0x060000;
 5913|      1|			}
 5914|    500|		}
 5915|    938|		break;
 5916|    945|	}
 5917|       |
 5918|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5919|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5920|       |
 5921|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5922|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5923|    945|	switch (card->type) {
  ------------------
  |  Branch (5923:10): [True: 785, False: 160]
  ------------------
 5924|       |	/*
 5925|       |	 * For cards that may also be CAC, try and read the CCC
 5926|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5927|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5928|       |	 */
 5929|    781|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5929:2): [True: 781, False: 164]
  ------------------
 5930|    781|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5930:2): [True: 0, False: 945]
  ------------------
 5931|    782|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5931:2): [True: 1, False: 944]
  ------------------
 5932|    782|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5932:2): [True: 0, False: 945]
  ------------------
 5933|    783|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5933:2): [True: 1, False: 944]
  ------------------
 5934|    785|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5934:2): [True: 2, False: 943]
  ------------------
 5935|    785|		r2 = piv_process_ccc(card);
 5936|    785|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    785|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5937|    785|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5938|       |		/* Ignore any error. */
 5939|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5940|    785|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    785|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5940:7): [True: 10, False: 775]
  ------------------
 5941|     10|			switch (card->type) {
  ------------------
  |  Branch (5941:12): [True: 10, False: 0]
  ------------------
 5942|     10|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5942:4): [True: 10, False: 0]
  ------------------
 5943|     10|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5943:4): [True: 0, False: 10]
  ------------------
 5944|     10|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5944:4): [True: 0, False: 10]
  ------------------
 5945|     10|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5945:4): [True: 0, False: 10]
  ------------------
 5946|     10|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5947|     10|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|     10|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5948|     10|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|     10|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5949|     10|				break;
 5950|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5950:4): [True: 0, False: 10]
  ------------------
 5951|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5952|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5953|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5954|      0|				break;
 5955|      0|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5955:4): [True: 0, False: 10]
  ------------------
 5956|      0|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5957|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5958|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5959|      0|				break;
 5960|     10|			}
 5961|     10|		}
 5962|    785|		break;
 5963|       |
 5964|    785|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5964:2): [True: 0, False: 945]
  ------------------
 5965|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5965:2): [True: 0, False: 945]
  ------------------
 5966|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5966:2): [True: 0, False: 945]
  ------------------
 5967|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5968|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5969|      0|		break;
 5970|    945|	}
 5971|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5972|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5973|       |
 5974|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5975|    945|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  380|    945|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  385|     39|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5975:6): [True: 39, False: 906]
  |  Branch (5975:51): [True: 0, False: 39]
  ------------------
 5976|      0|		r2 = piv_find_aid(card);
 5977|      0|	}
 5978|       |
 5979|       |	/* Read AID if needed for these cards types */
 5980|    945|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|    945|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5980:6): [True: 39, False: 906]
  ------------------
 5981|     39|		switch (card->type) {
  ------------------
  |  Branch (5981:11): [True: 1, False: 38]
  ------------------
 5982|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5982:3): [True: 0, False: 39]
  ------------------
 5983|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5983:3): [True: 0, False: 39]
  ------------------
 5984|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5984:3): [True: 0, False: 39]
  ------------------
 5985|      0|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5985:3): [True: 0, False: 39]
  ------------------
 5986|      1|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5986:3): [True: 1, False: 38]
  ------------------
 5987|      1|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5987:3): [True: 0, False: 39]
  ------------------
 5988|      1|		case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5988:3): [True: 0, False: 39]
  ------------------
 5989|       |
 5990|      1|			r2 = piv_find_aid(card);
 5991|     39|		}
 5992|     39|	}
 5993|       |
 5994|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5995|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5996|       |
 5997|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5998|    945|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  617|    945|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  608|    945|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  609|    945|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  610|    945|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  612|    945|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  613|    945|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5998:6): [True: 943, False: 2]
  ------------------
 5999|    943|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  617|    943|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  608|    943|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  609|    943|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  610|    943|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  612|    943|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  613|    943|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 6000|    943|	}
 6001|       |
 6002|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 6003|    945|	switch (card->type) {
  ------------------
  |  Branch (6003:10): [True: 771, False: 174]
  ------------------
 6004|    771|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6004:2): [True: 771, False: 174]
  ------------------
 6005|    771|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6005:2): [True: 0, False: 945]
  ------------------
 6006|    771|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|    771|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (6006:7): [True: 0, False: 771]
  ------------------
 6007|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6008|      0|		}
 6009|       |
 6010|       |#ifdef ENABLE_PIV_SM
 6011|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 6012|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 6013|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6014|       |		}
 6015|       |#endif
 6016|    771|		break;
 6017|    945|	}
 6018|       |
 6019|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6020|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6021|       |
 6022|       |	/*
 6023|       |	 * Set card_issues flags based card->type and version numbers if available.
 6024|       |	 *
 6025|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 6026|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 6027|       |	 * access to all the different devices or versions of the devices.
 6028|       |	 * Vendor and user input is welcome on any compliance issues.
 6029|       |	 *
 6030|       |	 * For the Yubico devices The assumption is also made that if a bug is
 6031|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 6032|       |	 *
 6033|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 6034|       |	 * may be set earlier or later then in the following code.
 6035|       |	 */
 6036|       |
 6037|    945|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    945|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6038|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6039|    945|	switch (card->type) {
 6040|     68|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (6040:2): [True: 68, False: 877]
  ------------------
 6041|     68|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  603|     68|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 6042|     68|				     CI_VERIFY_630X |
  ------------------
  |  |  591|     68|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 6043|     68|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|     68|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6044|     68|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  596|     68|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6045|     68|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  601|     68|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 6046|     68|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6046:7): [True: 56, False: 12]
  ------------------
 6047|     56|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|     56|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6048|     68|		break;
 6049|       |
 6050|      1|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (6050:2): [True: 1, False: 944]
  ------------------
 6051|       |		/* also supports using yubico-piv-tool */
 6052|      1|		priv->card_issues |= CI_ENFORCES_EC_HASH_EQ_KEYSIZE |
  ------------------
  |  |  605|      1|#define CI_ENFORCES_EC_HASH_EQ_KEYSIZE	    0x00001000U /* Applet enforces hash size == EC field size for ECDSA. Windows issue */
  ------------------
 6053|      1|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|      1|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6054|      1|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  596|      1|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6055|      1|		break;
 6056|       |
 6057|     67|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (6057:2): [True: 67, False: 878]
  ------------------
 6058|     68|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (6058:2): [True: 1, False: 944]
  ------------------
 6059|     70|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (6059:2): [True: 2, False: 943]
  ------------------
 6060|     70|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|     70|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6061|     70|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  596|     70|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6062|     70|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6062:7): [True: 49, False: 21]
  ------------------
 6063|     49|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|     49|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6064|     70|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (6064:7): [True: 13, False: 57]
  ------------------
 6065|     13|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  611|     13|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  614|     13|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  615|     13|#define AI_X25519			    0x00200000U
  ------------------
 6066|     70|		break;
 6067|       |
 6068|     18|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (6068:2): [True: 18, False: 927]
  ------------------
 6069|     18|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|     18|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6070|     18|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (6070:7): [True: 10, False: 8]
  ------------------
 6071|     10|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  611|     10|#define AI_RSA_4096			    0x00000008U
  ------------------
 6072|     18|		break;
 6073|       |
 6074|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (6074:2): [True: 0, False: 945]
  ------------------
 6075|      2|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (6075:2): [True: 2, False: 943]
  ------------------
 6076|      3|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (6076:2): [True: 1, False: 944]
  ------------------
 6077|      3|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (6077:2): [True: 0, False: 945]
  ------------------
 6078|      3|		priv->card_issues |= 0; /* could add others here */
 6079|      3|		break;
 6080|       |
 6081|    771|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6081:2): [True: 771, False: 174]
  ------------------
 6082|    772|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (6082:2): [True: 1, False: 944]
  ------------------
 6083|    773|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (6083:2): [True: 1, False: 944]
  ------------------
 6084|    773|		priv->card_issues |= 0; /* could add others here */
 6085|    773|		break;
 6086|       |
 6087|     10|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (6087:2): [True: 10, False: 935]
  ------------------
 6088|     10|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (6088:2): [True: 0, False: 945]
  ------------------
 6089|     10|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (6089:2): [True: 0, False: 945]
  ------------------
 6090|     10|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|     10|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6091|     10|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  598|     10|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6092|     10|				     CI_NO_RANDOM |
  ------------------
  |  |  594|     10|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6093|     10|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|     10|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6094|     10|		break;
 6095|       |
 6096|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6096:2): [True: 0, False: 945]
  ------------------
 6097|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6098|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6099|      0|		break;
 6100|       |
 6101|      2|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (6101:2): [True: 2, False: 943]
  ------------------
 6102|      2|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      2|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6103|      2|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  598|      2|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6104|      2|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  594|      2|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6105|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 6106|      2|		break;
 6107|       |
 6108|      0|	default:
  ------------------
  |  Branch (6108:2): [True: 0, False: 945]
  ------------------
 6109|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6110|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6111|       |		/* opensc.conf may have it wrong, continue anyway */
 6112|      0|		sc_log(card->ctx, "Unknown PIV card->type %d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6113|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 6114|    945|	}
 6115|    945|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    945|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6116|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6117|       |
 6118|    945|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  597|    945|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
              	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  382|    935|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (6118:6): [True: 935, False: 10]
  |  Branch (6118:53): [True: 896, False: 39]
  ------------------
 6119|       |		/*
 6120|       |		 * We now know PIV AID is active, test DISCOVERY object again
 6121|       |		 * Some PIV don't support DISCOVERY and return
 6122|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 6123|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 6124|       |		 * to test for active AID.
 6125|       |		 */
 6126|    896|		r2 = piv_find_discovery(card);
 6127|       |
 6128|    896|		if (r2 < 0) {
  ------------------
  |  Branch (6128:7): [True: 892, False: 4]
  ------------------
 6129|    892|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|    892|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 6130|    892|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    892|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 6131|    892|		}
 6132|    896|	}
 6133|       |
 6134|    945|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    945|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6135|    945|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6136|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 6137|    945|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    945|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    945|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    945|	int _ret = r; \
  |  |  |  |  155|    945|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 945, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    945|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 945]
  |  |  |  |  ------------------
  |  |  |  |  157|    945|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    945|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    945|	return _ret; \
  |  |  |  |  163|    945|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6138|       |
 6139|  4.79k|err:
 6140|  4.79k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH failed card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  4.79k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6141|  4.79k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6142|       |	/* don't match. Does not have a PIV applet. */
 6143|  4.79k|	piv_finish(card);
 6144|  4.79k|	card->type = saved_type;
 6145|  4.79k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.79k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.79k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.79k|	int _ret = r; \
  |  |  |  |  155|  4.79k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.79k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.79k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.79k|	return _ret; \
  |  |  |  |  163|  4.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6146|  4.79k|}
card-piv.c:piv_find_discovery:
 5276|  1.20k|{
 5277|  1.20k|	int r = 0;
 5278|  1.20k|	size_t rbuflen;
 5279|  1.20k|	u8 *rbuf = NULL;
 5280|  1.20k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.20k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5281|       |
 5282|  1.20k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.20k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.20k]
  |  |  ------------------
  ------------------
 5283|       |
 5284|       |	/*
 5285|       |	 * During piv_card_reader_lock_obtained,
 5286|       |	 * we use the discovery object to test if card present, and
 5287|       |	 * if PIV AID is active.
 5288|       |	 */
 5289|  1.20k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  1.20k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5289:6): [True: 0, False: 1.20k]
  ------------------
 5290|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5291|      0|		goto end;
 5292|      0|	}
 5293|       |
 5294|       |	/* If not valid: read, test,  cache */
 5295|  1.20k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|  1.20k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5295:6): [True: 1.15k, False: 46]
  ------------------
 5296|  1.15k|		r = piv_process_discovery(card);
 5297|  1.15k|	} else {
 5298|       |		/* if already in cache,force read */
 5299|     46|		rbuflen = 1;
 5300|     46|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5301|       |		/* if same response as last, no need to parse */
 5302|     46|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5302:7): [True: 0, False: 46]
  |  Branch (5302:17): [True: 0, False: 0]
  ------------------
 5303|      0|			goto end;
 5304|       |
 5305|     46|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5305:7): [True: 28, False: 18]
  |  Branch (5305:17): [True: 20, False: 8]
  ------------------
 5306|     20|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5306:5): [True: 20, False: 0]
  ------------------
 5307|     20|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5307:5): [True: 14, False: 6]
  ------------------
 5308|     14|			goto end;
 5309|     14|		}
 5310|       |		/* This should not happen  bad card */
 5311|     32|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5312|     32|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     32|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5313|     32|		goto end;
 5314|     46|	}
 5315|       |
 5316|  1.20k|end:
 5317|  1.20k|	free(rbuf);
 5318|  1.20k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.20k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.20k|	int _ret = r; \
  |  |  |  |  155|  1.20k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.18k, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.14k, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.18k|	} else { \
  |  |  |  |  159|     14|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     14|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     14|	} \
  |  |  |  |  162|  1.20k|	return _ret; \
  |  |  |  |  163|  1.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5319|  1.20k|}
card-piv.c:piv_process_discovery:
 5169|  1.15k|{
 5170|  1.15k|	int r;
 5171|  1.15k|	u8 *rbuf = NULL;
 5172|  1.15k|	size_t rbuflen = 0;
 5173|       |
 5174|  1.15k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5175|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5176|  1.15k|	if (r < 0)
  ------------------
  |  Branch (5176:6): [True: 1.06k, False: 87]
  ------------------
 5177|  1.06k|		goto err;
 5178|       |
 5179|       |	/* the object is now cached, see what we have */
 5180|     87|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5181|       |
 5182|  1.15k|err:
 5183|  1.15k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.15k|	int _ret = r; \
  |  |  |  |  155|  1.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.15k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.11k, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.15k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.15k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.15k|	return _ret; \
  |  |  |  |  163|  1.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5184|  1.15k|}
card-piv.c:piv_get_cached_data:
 3214|  10.0k|{
 3215|       |
 3216|  10.0k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  10.0k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3217|  10.0k|	int r;
 3218|  10.0k|	u8 *rbuf = NULL;
 3219|  10.0k|	size_t rbuflen;
 3220|       |
 3221|  10.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.0k]
  |  |  ------------------
  ------------------
 3222|       |
 3223|  10.0k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3223:6): [True: 0, False: 10.0k]
  |  Branch (3223:21): [True: 0, False: 10.0k]
  ------------------
 3224|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3225|       |
 3226|  10.0k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  10.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3227|       |
 3228|       |	/* see if we have it cached */
 3229|  10.0k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  10.0k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3229:6): [True: 614, False: 9.47k]
  ------------------
 3230|       |
 3231|    614|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   71|    614|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3232|    614|				enumtag,
 3233|    614|				priv->obj_cache[enumtag].obj_data,
 3234|    614|				priv->obj_cache[enumtag].obj_len,
 3235|    614|				priv->obj_cache[enumtag].internal_obj_data,
 3236|    614|				priv->obj_cache[enumtag].internal_obj_len);
 3237|       |
 3238|    614|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3238:7): [True: 0, False: 614]
  ------------------
 3239|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3240|      0|			sc_log(card->ctx, "#%d found but len=0", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3241|      0|			goto err;
 3242|      0|		}
 3243|    614|		*buf = priv->obj_cache[enumtag].obj_data;
 3244|    614|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3245|    614|		r = (int)*buf_len;
 3246|    614|		goto ok;
 3247|    614|	}
 3248|       |
 3249|       |	/*
 3250|       |	 * If we know it can not be on the card  i.e. History object
 3251|       |	 * has been read, and we know what other certs may or
 3252|       |	 * may not be on the card. We can avoid extra overhead
 3253|       |	 * Also used if object on card was not parsable
 3254|       |	 */
 3255|       |
 3256|  9.47k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  9.47k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3256:6): [True: 0, False: 9.47k]
  ------------------
 3257|      0|		sc_log(card->ctx, "no_obj #%d", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3258|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3259|      0|		goto err;
 3260|      0|	}
 3261|       |
 3262|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3263|  9.47k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  9.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3264|  9.47k|	rbuflen = 1;
 3265|  9.47k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3266|  9.47k|	if (r > 0) {
  ------------------
  |  Branch (3266:6): [True: 1.16k, False: 8.31k]
  ------------------
 3267|  1.16k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.16k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3268|  1.16k|		priv->obj_cache[enumtag].obj_len = r;
 3269|  1.16k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3270|  1.16k|		*buf = rbuf;
 3271|  1.16k|		*buf_len = r;
 3272|       |
 3273|  1.16k|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3274|  1.16k|				enumtag,
 3275|  1.16k|				priv->obj_cache[enumtag].obj_data,
 3276|  1.16k|				priv->obj_cache[enumtag].obj_len,
 3277|  1.16k|				priv->obj_cache[enumtag].internal_obj_data,
 3278|  1.16k|				priv->obj_cache[enumtag].internal_obj_len);
 3279|       |
 3280|  8.31k|	} else {
 3281|  8.31k|		free(rbuf);
 3282|  8.31k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  8.31k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3282:7): [True: 0, False: 8.31k]
  |  Branch (3282:17): [True: 861, False: 7.44k]
  ------------------
 3283|    861|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    861|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3284|    861|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|    861|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3285|    861|			priv->obj_cache[enumtag].obj_len = 0;
 3286|  7.44k|		} else {
 3287|  7.44k|			goto err;
 3288|  7.44k|		}
 3289|  8.31k|	}
 3290|  2.64k|ok:
 3291|       |
 3292|  10.0k|err:
 3293|  10.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  10.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.0k|	int _ret = r; \
  |  |  |  |  155|  10.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.31k, False: 1.78k]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.31k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.31k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.31k|	} else { \
  |  |  |  |  159|  1.78k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.78k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.78k|	} \
  |  |  |  |  162|  10.0k|	return _ret; \
  |  |  |  |  163|  10.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3294|  10.0k|}
card-piv.c:piv_parse_discovery:
 5113|     87|{
 5114|     87|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     87|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5115|     87|	int r = 0;
 5116|     87|	const u8 *body;
 5117|     87|	size_t bodylen;
 5118|     87|	const u8 *aid;
 5119|     87|	size_t aidlen;
 5120|     87|	const u8 *pinp;
 5121|     87|	size_t pinplen;
 5122|     87|	unsigned int cla_out, tag_out;
 5123|       |
 5124|     87|	if (rbuflen != 0) {
  ------------------
  |  Branch (5124:6): [True: 87, False: 0]
  ------------------
 5125|     87|		body = rbuf;
 5126|     87|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    174|#define SC_SUCCESS				0
  ------------------
  |  Branch (5126:7): [True: 0, False: 87]
  ------------------
 5127|     87|				body == NULL ||
  ------------------
  |  Branch (5127:5): [True: 0, False: 87]
  ------------------
 5128|     87|				bodylen == 0 ||
  ------------------
  |  Branch (5128:5): [True: 1, False: 86]
  ------------------
 5129|     86|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5129:5): [True: 0, False: 86]
  ------------------
 5130|      1|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5131|      1|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5132|      1|			goto err;
 5133|      1|		}
 5134|       |
 5135|     86|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   71|     86|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5136|     86|				cla_out, tag_out, body, bodylen);
 5137|     86|		aidlen = 0;
 5138|     86|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5139|     86|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5139:7): [True: 11, False: 75]
  |  Branch (5139:22): [True: 2, False: 73]
  ------------------
 5140|     73|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5140:5): [True: 30, False: 43]
  ------------------
 5141|     43|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   71|     43|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5142|     43|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     43|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 5143|     43|			goto err;
 5144|     43|		}
 5145|     43|		if (aid_only == 0) {
  ------------------
  |  Branch (5145:7): [True: 43, False: 0]
  ------------------
 5146|     43|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5147|     43|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5147:8): [True: 11, False: 32]
  |  Branch (5147:16): [True: 10, False: 1]
  ------------------
 5148|     10|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|     10|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5149|     10|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5150|     10|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5151|     10|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     10|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     10|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     10|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     10|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5151:9): [True: 4, False: 6]
  ------------------
 5152|      4|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|      4|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5152:7): [True: 2, False: 2]
  ------------------
 5153|      2|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5154|      2|					priv->pin_preference = 0x00;
 5155|      2|				}
 5156|     10|			}
 5157|     43|		}
 5158|     43|		r = SC_SUCCESS;
  ------------------
  |  |   28|     43|#define SC_SUCCESS				0
  ------------------
 5159|     43|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|     43|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5160|     43|	}
 5161|       |
 5162|     87|err:
 5163|     87|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     87|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     87|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     87|	int _ret = r; \
  |  |  |  |  155|     87|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 87, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     87|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 44, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|     87|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     87|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     87|	return _ret; \
  |  |  |  |  163|     87|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5164|     87|}
card-piv.c:piv_get_data:
 3104|  9.52k|{
 3105|  9.52k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  9.52k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3106|  9.52k|	u8 *p;
 3107|  9.52k|	u8 *tbuf;
 3108|  9.52k|	int r = 0;
 3109|  9.52k|	u8 tagbuf[8];
 3110|  9.52k|	size_t tag_len;
 3111|  9.52k|	int alloc_buf = 0;
 3112|       |
 3113|  9.52k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.52k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.52k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.52k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.52k]
  |  |  ------------------
  ------------------
 3114|       |
 3115|  9.52k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  9.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3116|       |
 3117|  9.52k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3118|  9.52k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  9.52k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3118:6): [True: 0, False: 9.52k]
  ------------------
 3119|      0|		sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3120|      0|		return r;
 3121|      0|	}
 3122|       |
 3123|  9.52k|	tag_len = piv_objects[enumtag].tag_len;
 3124|       |
 3125|  9.52k|	p = tagbuf;
 3126|  9.52k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3127|  9.52k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  9.52k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3127:6): [True: 0, False: 9.52k]
  ------------------
 3128|      0|		sc_log(card->ctx, "Failed to encode ASN1 tag");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3129|      0|		goto err;
 3130|      0|	}
 3131|       |
 3132|  9.52k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3132:6): [True: 9.52k, False: 0]
  |  Branch (3132:23): [True: 9.52k, False: 0]
  ------------------
 3133|  9.52k|		*buf_len = priv->max_object_size; /* will allocate below */
 3134|  9.52k|		alloc_buf = 1;
 3135|  9.52k|	}
 3136|       |
 3137|  9.52k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  9.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3138|  9.52k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3138:6): [True: 9.52k, False: 0]
  |  Branch (3138:22): [True: 9.52k, False: 0]
  ------------------
 3139|  9.52k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  9.52k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3139:7): [True: 0, False: 9.52k]
  ------------------
 3140|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3141|      0|			goto err;
 3142|      0|		}
 3143|  9.52k|		*buf = malloc(*buf_len);
 3144|  9.52k|		if (*buf == NULL) {
  ------------------
  |  Branch (3144:7): [True: 0, False: 9.52k]
  ------------------
 3145|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3146|      0|			goto err;
 3147|      0|		}
 3148|  9.52k|	}
 3149|       |
 3150|       |#ifdef ENABLE_PIV_SM
 3151|       |	/*
 3152|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3153|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3154|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3155|       |	 * i.e. no interference from other applications
 3156|       |	 */
 3157|       |	sc_log(card->ctx, "enumtag:%d sm_ctx.sm_mode:%d piv_objects[enumtag].flags:0x%8.8x sm_flags:0x%8.8lx it_flags:0x%8.8x",
 3158|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3159|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3160|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3161|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3162|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3163|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3164|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3165|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3166|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3167|       |	}
 3168|       |
 3169|       |#endif /* ENABLE_PIV_SM */
 3170|  9.52k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3171|  9.52k|	if (r > 0) {
  ------------------
  |  Branch (3171:6): [True: 1.76k, False: 7.76k]
  ------------------
 3172|  1.76k|		int r_tag;
 3173|  1.76k|		unsigned int cla_out, tag_out;
 3174|  1.76k|		size_t bodylen = 0;
 3175|  1.76k|		const u8 *body = *buf;
 3176|  1.76k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3177|  1.76k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  3.52k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3177:7): [True: 269, False: 1.49k]
  |  Branch (3177:30): [True: 85, False: 1.40k]
  ------------------
 3178|  1.40k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3178:5): [True: 211, False: 1.19k]
  ------------------
 3179|    565|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|    565|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3180|    565|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    565|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3181|    565|			goto err;
 3182|    565|		}
 3183|  1.19k|		*buf_len = (body - *buf) + bodylen;
 3184|  7.76k|	} else if (r == 0) {
  ------------------
  |  Branch (3184:13): [True: 252, False: 7.51k]
  ------------------
 3185|    252|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    252|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3186|    252|		goto err;
 3187|  7.51k|	} else {
 3188|  7.51k|		goto err;
 3189|  7.51k|	}
 3190|       |
 3191|  1.19k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3191:6): [True: 1.19k, False: 0]
  |  Branch (3191:19): [True: 1.19k, False: 0]
  ------------------
 3192|  1.19k|		tbuf = malloc(r);
 3193|  1.19k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3193:7): [True: 0, False: 1.19k]
  ------------------
 3194|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3195|      0|			goto err;
 3196|      0|		}
 3197|  1.19k|		memcpy(tbuf, *buf, r);
 3198|  1.19k|		free(*buf);
 3199|  1.19k|		alloc_buf = 0;
 3200|  1.19k|		*buf = tbuf;
 3201|  1.19k|	}
 3202|       |
 3203|  9.52k|err:
 3204|  9.52k|	if (alloc_buf) {
  ------------------
  |  Branch (3204:6): [True: 8.32k, False: 1.19k]
  ------------------
 3205|  8.32k|		free(*buf);
 3206|  8.32k|		*buf = NULL;
 3207|  8.32k|	}
 3208|  9.52k|	sc_unlock(card);
 3209|  9.52k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  9.52k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.52k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.52k|	int _ret = r; \
  |  |  |  |  155|  9.52k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.32k, False: 1.19k]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.32k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.32k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.32k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.32k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.32k|	} else { \
  |  |  |  |  159|  1.19k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.19k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.19k|	} \
  |  |  |  |  162|  9.52k|	return _ret; \
  |  |  |  |  163|  9.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3210|  9.52k|}
card-piv.c:piv_general_io:
 1803|  18.8k|{
 1804|  18.8k|	int r, cse;
 1805|  18.8k|	sc_apdu_t apdu;
 1806|       |
 1807|  18.8k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  18.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  18.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  18.8k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 18.8k]
  |  |  ------------------
  ------------------
 1808|       |
 1809|  18.8k|	r = sc_lock(card);
 1810|  18.8k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  18.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1810:6): [True: 0, False: 18.8k]
  ------------------
 1811|  18.8k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|       |
 1813|  18.8k|	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  294|  9.57k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  292|  9.25k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (1813:8): [True: 18.8k, False: 0]
  |  Branch (1813:19): [True: 9.57k, False: 9.25k]
  ------------------
 1814|  18.8k|			(sendbuf ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_1);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              			(sendbuf ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_1);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (1814:5): [True: 0, False: 0]
  ------------------
 1815|       |
 1816|  18.8k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
 1817|  18.8k|	if (sendbuflen > 255) {
  ------------------
  |  Branch (1817:6): [True: 4, False: 18.8k]
  ------------------
 1818|      4|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      4|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1819|       |#ifdef ENABLE_PIV_SM
 1820|       |		if (card->sm_ctx.sm_mode != SM_MODE_NONE) {
 1821|       |			/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1822|       |			apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1823|       |		}
 1824|       |#endif
 1825|      4|	}
 1826|  18.8k|	apdu.lc = sendbuflen;
 1827|  18.8k|	apdu.datalen = sendbuflen;
 1828|  18.8k|	apdu.data = sendbuf;
 1829|       |
 1830|  18.8k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1830:6): [True: 18.8k, False: 0]
  |  Branch (1830:17): [True: 18.8k, False: 0]
  ------------------
 1831|  18.8k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1831:13): [True: 18.8k, False: 0]
  ------------------
 1832|  18.8k|		apdu.resplen = recvbuflen;
 1833|  18.8k|	} else {
 1834|      0|		apdu.le = 0;
 1835|      0|		apdu.resplen = 0;
 1836|      0|	}
 1837|  18.8k|	apdu.resp = recvbuf;
 1838|       |
 1839|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1840|  18.8k|	r = sc_transmit_apdu(card, &apdu);
 1841|       |
 1842|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1843|  18.8k|	if (r < 0) {
  ------------------
  |  Branch (1843:6): [True: 127, False: 18.6k]
  ------------------
 1844|    127|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1845|    127|		goto err;
 1846|    127|	}
 1847|       |
 1848|  18.6k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1848:6): [True: 88, False: 18.6k]
  |  Branch (1848:26): [True: 37, False: 51]
  ------------------
 1849|     37|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     37|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1850|  18.6k|	else
 1851|  18.6k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1852|       |
 1853|  18.6k|	if (r < 0) {
  ------------------
  |  Branch (1853:6): [True: 15.8k, False: 2.86k]
  ------------------
 1854|  15.8k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  15.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1855|  15.8k|		goto err;
 1856|  15.8k|	}
 1857|       |
 1858|  2.86k|	r = (int)apdu.resplen;
 1859|       |
 1860|  18.8k|err:
 1861|  18.8k|	sc_unlock(card);
 1862|  18.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  18.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.8k|	int _ret = r; \
  |  |  |  |  155|  18.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.3k, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  15.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.9k, False: 398]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.3k|	} else { \
  |  |  |  |  159|  2.46k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.46k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.46k|	} \
  |  |  |  |  162|  18.8k|	return _ret; \
  |  |  |  |  163|  18.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1863|  18.8k|}
card-piv.c:piv_obj_cache_free_entry:
 5573|   345k|{
 5574|   345k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|   345k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5575|       |
 5576|   345k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5576:6): [True: 1.16k, False: 344k]
  ------------------
 5577|  1.16k|		free(priv->obj_cache[enumtag].obj_data);
 5578|   345k|	priv->obj_cache[enumtag].obj_data = NULL;
 5579|   345k|	priv->obj_cache[enumtag].obj_len = 0;
 5580|       |
 5581|   345k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5581:6): [True: 614, False: 344k]
  ------------------
 5582|    614|		free(priv->obj_cache[enumtag].internal_obj_data);
 5583|   345k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5584|   345k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5585|   345k|	priv->obj_cache[enumtag].flags = flags;
 5586|       |
 5587|   345k|	return SC_SUCCESS;
  ------------------
  |  |   28|   345k|#define SC_SUCCESS				0
  ------------------
 5588|   345k|}
card-piv.c:piv_find_aid:
 2915|  5.70k|{
 2916|  5.70k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  5.70k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2917|  5.70k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2918|  5.70k|	int r, i, j;
 2919|  5.70k|	const u8 *tag;
 2920|  5.70k|	size_t taglen;
 2921|  5.70k|	const u8 *nextac;
 2922|  5.70k|	const u8 *next80;
 2923|  5.70k|	const u8 *pix;
 2924|  5.70k|	size_t pixlen;
 2925|  5.70k|	const u8 *al_label;
 2926|  5.70k|	size_t al_labellen;
 2927|  5.70k|	const u8 *actag; /* Cipher Suite */
 2928|  5.70k|	size_t actaglen;
 2929|  5.70k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2930|  5.70k|	size_t csailen;
 2931|  5.70k|	size_t resplen = sizeof(rbuf);
 2932|       |#ifdef ENABLE_PIV_SM
 2933|       |	int found_csai = 0;
 2934|       |#endif
 2935|       |
 2936|  5.70k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.70k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.70k]
  |  |  ------------------
  ------------------
 2937|       |
 2938|       |	/* first  see if the default application will return a template
 2939|       |	 * that we know about.
 2940|       |	 */
 2941|       |
 2942|  5.70k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2943|  5.70k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2943:6): [True: 0, False: 5.70k]
  |  Branch (2943:15): [True: 0, False: 0]
  |  Branch (2943:38): [True: 0, False: 0]
  |  Branch (2943:70): [True: 0, False: 0]
  ------------------
 2944|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2945|       |		/* no need to parse again, same as last time */
 2946|      0|	}
 2947|  5.70k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2947:6): [True: 1.07k, False: 4.62k]
  |  Branch (2947:16): [True: 1.01k, False: 61]
  ------------------
 2948|  1.01k|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2949|  1.01k|		if (tag != NULL) {
  ------------------
  |  Branch (2949:7): [True: 968, False: 50]
  ------------------
 2950|    968|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|    968|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2951|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2952|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2953|       |			 * where xx is the SM csID either 27 or 2E.
 2954|       |			 * Some vendors may include entries for supported Algorithms even when
 2955|       |			 * not required. We will use these if possible
 2956|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2957|       |			 */
 2958|    968|			nextac = tag;
 2959|  1.04k|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2959:11): [True: 79, False: 968]
  ------------------
 2960|  1.04k|						0xAC, &actaglen)) != NULL) {
 2961|     79|				nextac = actag + actaglen;
 2962|       |
 2963|     79|				next80 = actag;
 2964|    212|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2964:12): [True: 133, False: 79]
  ------------------
 2965|    212|							0x80, &csailen)) != NULL) {
 2966|    133|					next80 = csai + csailen;
 2967|    133|					if (csailen == 1) {
  ------------------
  |  Branch (2967:10): [True: 38, False: 95]
  ------------------
 2968|     38|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   71|     38|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2969|     38|						j = piv_ai_map_find_by_id(card, *csai);
 2970|     38|						if (j >= 0) {
  ------------------
  |  Branch (2970:11): [True: 18, False: 20]
  ------------------
 2971|     18|							priv->alg_ids |= ai_map[j].ai_flag;
 2972|     18|							continue;
 2973|     18|						}
 2974|       |#ifdef ENABLE_PIV_SM
 2975|       |						/* check if id is NIST SM */
 2976|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2977|       |							if (*csai != css[i].id)
 2978|       |								continue;
 2979|       |							if (found_csai) {
 2980|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2981|       |							} else {
 2982|       |								priv->cs = &css[i];
 2983|       |								priv->csID = *csai;
 2984|       |								found_csai++;
 2985|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2986|       |							}
 2987|       |						}
 2988|       |#endif /* ENABLE_PIV_SM */
 2989|     38|					}
 2990|    133|				}
 2991|     79|			}
 2992|       |
 2993|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2994|    968|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2995|    968|			if (al_label != NULL) {
  ------------------
  |  Branch (2995:8): [True: 19, False: 949]
  ------------------
 2996|     19|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|     19|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     19|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2997|     19|				free(priv->al_label);
 2998|     19|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2998:9): [True: 0, False: 19]
  ------------------
 2999|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3000|      0|				}
 3001|     19|				memcpy(priv->al_label, al_label, al_labellen);
 3002|     19|				priv->al_labellen = (int)al_labellen;
 3003|     19|			}
 3004|       |
 3005|    968|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 3006|    968|			if (pix != NULL) {
  ------------------
  |  Branch (3006:8): [True: 933, False: 35]
  ------------------
 3007|    933|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    933|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3008|       |
 3009|       |				/* early cards returned full AID, rather then just the pix */
 3010|    991|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (3010:17): [True: 965, False: 26]
  ------------------
 3011|    965|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (3011:11): [True: 949, False: 16]
  ------------------
 3012|    949|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (3012:12): [True: 794, False: 155]
  ------------------
 3013|    171|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3013:10): [True: 151, False: 20]
  |  Branch (3013:45): [True: 113, False: 38]
  ------------------
 3014|    907|													     piv_aids[i].len_short) == 0))) {
 3015|    907|						free(priv->aid_der.value); /* free previous value if any */
 3016|    907|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3016:11): [True: 0, False: 907]
  ------------------
 3017|      0|							LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3018|      0|						}
 3019|    907|						memcpy(priv->aid_der.value, rbuf, resplen);
 3020|    907|						priv->aid_der.len = resplen;
 3021|    907|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    907|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    907|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    907|	int _ret = r; \
  |  |  |  |  155|    907|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 901, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  156|    901|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 901]
  |  |  |  |  ------------------
  |  |  |  |  157|    901|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    901|	} else { \
  |  |  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      6|	} \
  |  |  |  |  162|    907|	return _ret; \
  |  |  |  |  163|    907|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3022|    907|					}
 3023|    965|				}
 3024|    933|			}
 3025|    968|		}
 3026|  1.01k|	}
 3027|       |
 3028|  4.80k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  4.80k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.80k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.80k|	int _ret = r; \
  |  |  |  |  155|  4.80k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.80k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.80k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.80k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.80k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.80k|	return _ret; \
  |  |  |  |  163|  4.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3029|  4.80k|}
card-piv.c:piv_ai_map_find_by_id:
 2898|     38|{
 2899|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2900|     38|	int i;
 2901|       |
 2902|    246|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2902:14): [True: 226, False: 20]
  ------------------
 2903|    226|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2903:7): [True: 18, False: 208]
  ------------------
 2904|     18|			return i;
 2905|    226|	}
 2906|     20|	return -1;
 2907|     38|}
card-piv.c:piv_process_ccc:
 5257|    785|{
 5258|    785|	int r = 0;
 5259|    785|	u8 *rbuf = NULL;
 5260|    785|	size_t rbuflen = 0;
 5261|       |
 5262|    785|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    785|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    785|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    785|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 785]
  |  |  ------------------
  ------------------
 5263|    785|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5264|       |
 5265|    785|	if (r < 0)
  ------------------
  |  Branch (5265:6): [True: 702, False: 83]
  ------------------
 5266|    702|		goto err;
 5267|       |
 5268|       |	/* the object is now cached, see what we have */
 5269|     83|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5270|    785|err:
 5271|    785|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    785|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    785|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    785|	int _ret = r; \
  |  |  |  |  155|    785|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 785, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    785|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    774|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 774, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|    785|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    785|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    785|	return _ret; \
  |  |  |  |  163|    785|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5272|    785|}
card-piv.c:piv_parse_ccc:
 5193|     83|{
 5194|     83|	int r = 0;
 5195|     83|	const u8 *body;
 5196|     83|	size_t bodylen;
 5197|     83|	unsigned int cla_out, tag_out;
 5198|       |
 5199|     83|	u8 tag;
 5200|     83|	const u8 *end;
 5201|     83|	size_t len;
 5202|       |
 5203|     83|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     83|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5204|       |
 5205|     83|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     83|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     83|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     83|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 83]
  |  |  ------------------
  ------------------
 5206|       |
 5207|     83|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5207:6): [True: 0, False: 83]
  |  Branch (5207:22): [True: 0, False: 83]
  ------------------
 5208|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 5209|      0|		goto err;
 5210|      0|	}
 5211|       |
 5212|       |	/* Outer layer is a DER tlv */
 5213|     83|	body = rbuf;
 5214|     83|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    166|#define SC_SUCCESS				0
  ------------------
  |  Branch (5214:6): [True: 0, False: 83]
  ------------------
 5215|     83|			body == NULL ||
  ------------------
  |  Branch (5215:4): [True: 0, False: 83]
  ------------------
 5216|     83|			bodylen == 0 ||
  ------------------
  |  Branch (5216:4): [True: 2, False: 81]
  ------------------
 5217|     81|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5217:4): [True: 0, False: 81]
  ------------------
 5218|      2|		sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5219|      2|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5220|      2|		goto err;
 5221|      2|	}
 5222|       |
 5223|     81|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     81|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5224|       |
 5225|       |	/* CCC  entries are simple tlv */
 5226|     81|	end = body + bodylen;
 5227|  8.10k|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5227:9): [True: 8.09k, False: 11]
  ------------------
 5228|  8.09k|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5229|  8.09k|		if (r < 0)
  ------------------
  |  Branch (5229:7): [True: 70, False: 8.02k]
  ------------------
 5230|     70|			goto err;
 5231|  8.02k|		switch (tag) {
  ------------------
  |  Branch (5231:11): [True: 732, False: 7.28k]
  ------------------
 5232|    315|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|    315|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5232:3): [True: 315, False: 7.70k]
  ------------------
 5233|    315|			if (len == 0x15) {
  ------------------
  |  Branch (5233:8): [True: 191, False: 124]
  ------------------
 5234|    191|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5234:9): [True: 18, False: 173]
  ------------------
 5235|     18|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|     18|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5236|    173|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5236:14): [True: 61, False: 112]
  ------------------
 5237|     61|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|     61|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5238|    191|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5238:9): [True: 30, False: 161]
  ------------------
 5239|     30|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|     30|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5240|    191|			}
 5241|    315|			break;
 5242|    417|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|    417|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5242:3): [True: 417, False: 7.60k]
  ------------------
 5243|    417|			if (len == 0x10) {
  ------------------
  |  Branch (5243:8): [True: 102, False: 315]
  ------------------
 5244|    102|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5244:9): [True: 73, False: 29]
  ------------------
 5245|     73|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|     73|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5246|    102|			}
 5247|    417|			break;
 5248|  8.02k|		}
 5249|  8.02k|	}
 5250|       |
 5251|     83|err:
 5252|     83|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     83|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     83|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     83|	int _ret = r; \
  |  |  |  |  155|     83|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 83, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     72|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 72, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|     83|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     83|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     83|	return _ret; \
  |  |  |  |  163|     83|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5253|     83|}
card-piv.c:piv_init:
 6150|    945|{
 6151|    945|	int r = 0;
 6152|    945|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|    945|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6153|    945|	unsigned long flags;
 6154|    945|	unsigned long flags_eddsa;
 6155|    945|	unsigned long flags_xeddsa;
 6156|    945|	unsigned long ext_flags;
 6157|       |
 6158|    945|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    945|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    945|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    945|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 945]
  |  |  ------------------
  ------------------
 6159|       |
 6160|    945|	r = sc_lock(card); /* hold until match or init is complete */
 6161|    945|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|    945|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    945|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    945|	int _ret = (r); \
  |  |  |  |  168|    945|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 945]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    945|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 945]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6162|       |
 6163|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6164|    945|	if (priv == NULL) {
  ------------------
  |  Branch (6164:6): [True: 0, False: 945]
  ------------------
 6165|      0|		r = piv_match_card_continued(card);
 6166|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  447|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6167|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (6167:7): [True: 0, False: 0]
  |  Branch (6167:16): [True: 0, False: 0]
  ------------------
 6168|      0|			sc_log(card->ctx, "piv_match_card_continued failed card->type:%d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6169|      0|			sc_unlock(card);
 6170|      0|			piv_finish(card);
 6171|       |			/* tell sc_connect_card to try other driver */
 6172|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6173|      0|		}
 6174|      0|	}
 6175|       |
 6176|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 6177|    945|	piv_load_options(card);
 6178|       |
 6179|    945|	priv->pstate = PIV_STATE_INIT;
 6180|       |
 6181|    945|	sc_log(card->ctx, "Max send = %zu recv = %zu card->type:%d, CI:%08x AI:%08x",
  ------------------
  |  |   71|    945|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6182|    945|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6183|    945|	card->cla = 0x00;
 6184|    945|	if (card->name == NULL)
  ------------------
  |  Branch (6184:6): [True: 945, False: 0]
  ------------------
 6185|    945|		card->name = card->driver->name;
 6186|       |
 6187|    945|	priv->enumtag = piv_aids[0].enumtag;
 6188|       |
 6189|       |	/* PKCS#11 may try to generate session keys, and get confused
 6190|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 6191|       |	 * piv-tool can still do this, just don't tell PKCS#11
 6192|       |	 */
 6193|       |
 6194|    945|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    945|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6195|       |
 6196|    945|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6196:6): [True: 0, False: 945]
  ------------------
 6197|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6198|      0|	}
 6199|       |
 6200|    945|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  608|    945|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6200:6): [True: 944, False: 1]
  ------------------
 6201|    944|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6202|       |
 6203|    945|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  609|    945|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6203:6): [True: 944, False: 1]
  ------------------
 6204|    944|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6205|       |
 6206|    945|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  610|    945|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6206:6): [True: 943, False: 2]
  ------------------
 6207|    943|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6208|       |
 6209|    945|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  611|    945|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6209:6): [True: 23, False: 922]
  ------------------
 6210|     23|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6211|       |
 6212|    945|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  604|    945|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6212:6): [True: 945, False: 0]
  ------------------
 6213|    945|		int i;
 6214|    945|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    945|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    945|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    945|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    945|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 6215|    945|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    945|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    945|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 6216|    945|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|    945|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6217|    945|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  189|    945|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|    945|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 6218|       |
 6219|  4.72k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6219:15): [True: 3.78k, False: 945]
  ------------------
 6220|  3.78k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  3.78k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6220:8): [True: 1.89k, False: 1.89k]
  ------------------
 6221|  1.89k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  603|  3.78k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6221:11): [True: 136, False: 1.75k]
  |  Branch (6221:46): [True: 68, False: 68]
  ------------------
 6222|  1.82k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6223|  1.89k|			}
 6224|       |
 6225|  1.89k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  614|  3.78k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|     28|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6225:13): [True: 28, False: 1.86k]
  |  Branch (6225:41): [True: 14, False: 14]
  ------------------
 6226|     14|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6227|       |
 6228|  1.87k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  615|  3.75k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     15|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6228:13): [True: 15, False: 1.86k]
  |  Branch (6228:42): [True: 14, False: 1]
  ------------------
 6229|     14|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6230|  3.78k|		}
 6231|    945|	}
 6232|       |
 6233|    945|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  594|    945|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6233:6): [True: 933, False: 12]
  ------------------
 6234|    933|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    933|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6235|       |
 6236|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6237|    945|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    945|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6238|       |
 6239|       |	/*
 6240|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6241|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6242|       |	 */
 6243|       |
 6244|       |#ifdef ENABLE_PIV_SM
 6245|       |	/*
 6246|       |	 * 800-73-4
 6247|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6248|       |	 */
 6249|       |	if (priv->csID && priv->cs != NULL) {
 6250|       |		/*
 6251|       |		 * Main point in SM and VCI is to allow contactless access
 6252|       |		 */
 6253|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6254|       |
 6255|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6256|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6257|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6258|       |			r = SC_SUCCESS; /* Users choice */
 6259|       |
 6260|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6261|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6262|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6263|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6264|       |
 6265|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6266|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6267|       |				(priv->pairing_code[0] == 0x00)) {
 6268|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6269|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6270|       |
 6271|       |		} else {
 6272|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6273|       |			r = piv_sm_open(card);
 6274|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6275|       |		}
 6276|       |
 6277|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6278|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6279|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6280|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6281|       |		}
 6282|       |
 6283|       |		/* user has wrong or no required pairing code */
 6284|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6285|       |			LOG_FUNC_RETURN(card->ctx, r);
 6286|       |
 6287|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6288|       |	}
 6289|       |#endif /* ENABLE_PIV_SM */
 6290|       |
 6291|       |	/*
 6292|       |	 * 800-73-3 cards may have a history object
 6293|       |	 * We want to process it now as this has information on what
 6294|       |	 * keys and certs. "piv like" cards may or may not have history
 6295|       |	 */
 6296|    945|	piv_process_history(card);
 6297|       |
 6298|    945|	priv->pstate = PIV_STATE_NORMAL;
 6299|    945|	sc_unlock(card);
 6300|    945|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    945|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    945|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    945|	int _ret = r; \
  |  |  |  |  155|    945|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 945, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    945|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 945]
  |  |  |  |  ------------------
  |  |  |  |  157|    945|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    945|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    945|	return _ret; \
  |  |  |  |  163|    945|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6301|    945|}
card-piv.c:piv_load_options:
 1695|    945|{
 1696|    945|	int r;
 1697|    945|	size_t i, j;
 1698|    945|	scconf_block **found_blocks, *block;
 1699|       |
 1700|       |#ifdef ENABLE_PIV_SM
 1701|       |	piv_private_data_t *priv = PIV_DATA(card);
 1702|       |	const char *option = NULL;
 1703|       |	int piv_pairing_code_found = 0;
 1704|       |	int piv_use_sm_found = 0;
 1705|       |
 1706|       |	/* pairing code is 8 decimal digits and is card specific */
 1707|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1708|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1709|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1710|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1711|       |			piv_pairing_code_found = 1;
 1712|       |		}
 1713|       |	}
 1714|       |
 1715|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1716|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1717|       |		if (!strcmp(option, "never")) {
 1718|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1719|       |			piv_use_sm_found = 1;
 1720|       |		} else if (!strcmp(option, "always")) {
 1721|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1722|       |			piv_use_sm_found = 1;
 1723|       |		} else {
 1724|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1725|       |		}
 1726|       |	}
 1727|       |#endif
 1728|       |
 1729|  1.89k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1729:14): [True: 945, False: 945]
  ------------------
 1730|    945|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1731|    945|				"card_driver", "PIV-II");
 1732|    945|		if (!found_blocks)
  ------------------
  |  Branch (1732:7): [True: 0, False: 945]
  ------------------
 1733|      0|			continue;
 1734|       |
 1735|    945|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1735:40): [True: 0, False: 945]
  ------------------
 1736|       |
 1737|       |#ifdef ENABLE_PIV_SM
 1738|       |			/*
 1739|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1740|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1741|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1742|       |			 * this security risk
 1743|       |			 * always - Use even for contact interface.
 1744|       |			 * PINS, crypto and reading of object will not show up in logs
 1745|       |			 * or over network.
 1746|       |			 */
 1747|       |
 1748|       |			if (piv_use_sm_found == 0) {
 1749|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1750|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1751|       |				if (!strcmp(option, "default")) {
 1752|       |					/* no new flags */
 1753|       |				} else if (!strcmp(option, "never")) {
 1754|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1755|       |				} else if (!strcmp(option, "always")) {
 1756|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1757|       |				} else {
 1758|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1759|       |				}
 1760|       |			}
 1761|       |
 1762|       |			/* This is really a card specific value and should not be in the conf file */
 1763|       |			if (piv_pairing_code_found == 0) {
 1764|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1765|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1766|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1767|       |				}
 1768|       |			}
 1769|       |#endif
 1770|      0|		}
 1771|    945|		free(found_blocks);
 1772|    945|	}
 1773|    945|	r = SC_SUCCESS;
  ------------------
  |  |   28|    945|#define SC_SUCCESS				0
  ------------------
 1774|    945|	return r;
 1775|    945|}
card-piv.c:piv_process_history:
 5329|    945|{
 5330|    945|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|    945|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5331|    945|	int r;
 5332|    945|	int i, tmplen, tmplen2, tmplen3;
 5333|    945|	int enumtag;
 5334|    945|	u8 *rbuf = NULL;
 5335|    945|	size_t rbuflen = 0;
 5336|    945|	const u8 *body;
 5337|    945|	size_t bodylen;
 5338|    945|	const u8 *num;
 5339|    945|	size_t numlen;
 5340|    945|	const u8 *url = NULL;
 5341|    945|	size_t urllen;
 5342|    945|	u8 *ocfhfbuf = NULL;
 5343|    945|	unsigned int cla_out, tag_out;
 5344|    945|	size_t ocfhflen;
 5345|    945|	const u8 *seq;
 5346|    945|	const u8 *seqtag;
 5347|    945|	size_t seqlen;
 5348|    945|	const u8 *keyref;
 5349|    945|	size_t keyreflen;
 5350|    945|	const u8 *cert;
 5351|    945|	size_t certlen;
 5352|    945|	size_t certobjlen, i2;
 5353|    945|	u8 *certobj;
 5354|    945|	u8 *cp;
 5355|       |
 5356|    945|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    945|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    945|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    945|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 945]
  |  |  ------------------
  ------------------
 5357|       |
 5358|    945|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5359|    945|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    945|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5359:6): [True: 123, False: 822]
  ------------------
 5360|    123|		r = 0; /* OK if not found */
 5361|    945|	if (r <= 0) {
  ------------------
  |  Branch (5361:6): [True: 790, False: 155]
  ------------------
 5362|    790|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    790|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5363|    790|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5364|    790|	}
 5365|       |
 5366|       |	/* the object is now cached, see what we have */
 5367|    155|	if (rbuflen != 0) {
  ------------------
  |  Branch (5367:6): [True: 155, False: 0]
  ------------------
 5368|    155|		body = rbuf;
 5369|    155|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    310|#define SC_SUCCESS				0
  ------------------
  |  Branch (5369:7): [True: 0, False: 155]
  ------------------
 5370|    155|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5370:5): [True: 0, False: 155]
  ------------------
 5371|      0|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5372|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5373|      0|			goto err;
 5374|      0|		}
 5375|       |
 5376|    155|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5376:7): [True: 155, False: 0]
  |  Branch (5376:23): [True: 151, False: 4]
  ------------------
 5377|    151|			numlen = 0;
 5378|    151|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5379|    151|			if (num) {
  ------------------
  |  Branch (5379:8): [True: 60, False: 91]
  ------------------
 5380|     60|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5380:9): [True: 1, False: 59]
  |  Branch (5380:24): [True: 2, False: 57]
  ------------------
 5381|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5382|      3|					goto err;
 5383|      3|				}
 5384|       |
 5385|     57|				priv->keysWithOnCardCerts = *num;
 5386|     57|			}
 5387|       |
 5388|    148|			numlen = 0;
 5389|    148|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5390|    148|			if (num) {
  ------------------
  |  Branch (5390:8): [True: 3, False: 145]
  ------------------
 5391|      3|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5391:9): [True: 1, False: 2]
  |  Branch (5391:24): [True: 1, False: 1]
  ------------------
 5392|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5393|      2|					goto err;
 5394|      2|				}
 5395|       |
 5396|      1|				priv->keysWithOffCardCerts = *num;
 5397|      1|			}
 5398|       |
 5399|    146|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5400|    146|			if (url) {
  ------------------
  |  Branch (5400:8): [True: 77, False: 69]
  ------------------
 5401|     77|				if (urllen > 118) {
  ------------------
  |  Branch (5401:9): [True: 1, False: 76]
  ------------------
 5402|      1|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5403|      1|					goto err;
 5404|      1|				}
 5405|     76|				priv->offCardCertURL = calloc(1, urllen + 1);
 5406|     76|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5406:9): [True: 0, False: 76]
  ------------------
 5407|     76|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5408|     76|				memcpy(priv->offCardCertURL, url, urllen);
 5409|     76|			}
 5410|    146|		} else {
 5411|      4|			sc_log(card->ctx, "Problem with History object\n");
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5412|      4|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
 5413|      4|			goto err;
 5414|      4|		}
 5415|    155|	}
 5416|    145|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    290|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 76, False: 69]
  |  |  ------------------
  ------------------
 5417|    145|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5418|    145|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5419|       |
 5420|       |	/* now mark what objects are on the card */
 5421|  1.11k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5421:14): [True: 972, False: 145]
  ------------------
 5422|    972|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|  1.11k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5423|       |
 5424|       |	/*
 5425|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5426|       |	 * we will read in and add the certs to the cache as listed on
 5427|       |	 * the card. some of the certs may be on the card as well.
 5428|       |	 *
 5429|       |	 * Get file name from url. verify that the filename is valid
 5430|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5431|       |	 * in the directory used for the  PKCS15 cache
 5432|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5433|       |	 */
 5434|       |
 5435|    145|	r = 0;
 5436|    145|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5436:6): [True: 76, False: 69]
  ------------------
 5437|     76|		char *fp;
 5438|     76|		char filename[PATH_MAX];
 5439|       |
 5440|     76|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5440:7): [True: 73, False: 3]
  ------------------
 5441|     73|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     73|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5442|     73|			goto err;
 5443|     73|		}
 5444|       |		/* find the last /  so we have the filename part */
 5445|      3|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5446|      3|		if (fp == NULL) {
  ------------------
  |  Branch (5446:7): [True: 1, False: 2]
  ------------------
 5447|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5448|      1|			goto err;
 5449|      1|		}
 5450|      2|		fp++;
 5451|      2|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5451:7): [True: 2, False: 0]
  ------------------
 5452|      2|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5453|      2|			goto err;
 5454|      2|		}
 5455|      0|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5455:15): [True: 0, False: 0]
  ------------------
 5456|      0|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5456:8): [True: 0, False: 0]
  ------------------
 5457|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5458|      0|				goto err;
 5459|      0|			}
 5460|      0|		}
 5461|       |
 5462|       |		/* Use the same directory as used for other OpenSC cached items */
 5463|      0|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5464|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5464:7): [True: 0, False: 0]
  ------------------
 5465|      0|			goto err;
 5466|       |#ifdef _WIN32
 5467|       |		strlcat(filename, "\\", PATH_MAX);
 5468|       |#else
 5469|      0|		strlcat(filename, "/", PATH_MAX);
 5470|      0|#endif
 5471|      0|		strlcat(filename, fp, PATH_MAX);
 5472|       |
 5473|      0|		r = piv_read_obj_from_file(card, filename,
 5474|      0|				&ocfhfbuf, &ocfhflen);
 5475|      0|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5475:7): [True: 0, False: 0]
  ------------------
 5476|      0|			r = 0;
 5477|      0|			goto err;
 5478|      0|		}
 5479|       |
 5480|       |		/*
 5481|       |		 * Its a seq of seq of a key ref and cert
 5482|       |		 */
 5483|       |
 5484|      0|		body = ocfhfbuf;
 5485|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5485:7): [True: 0, False: 0]
  ------------------
 5486|      0|				body == NULL ||
  ------------------
  |  Branch (5486:5): [True: 0, False: 0]
  ------------------
 5487|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5487:5): [True: 0, False: 0]
  ------------------
 5488|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5488:5): [True: 0, False: 0]
  ------------------
 5489|      0|			sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5490|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5491|      0|			goto err;
 5492|      0|		}
 5493|      0|		seq = body;
 5494|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5494:10): [True: 0, False: 0]
  ------------------
 5495|      0|			seqtag = seq;
 5496|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5496:8): [True: 0, False: 0]
  ------------------
 5497|      0|					seq == 0 ||
  ------------------
  |  Branch (5497:6): [True: 0, False: 0]
  ------------------
 5498|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5498:6): [True: 0, False: 0]
  ------------------
 5499|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5499:6): [True: 0, False: 0]
  ------------------
 5500|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5501|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5502|      0|				goto err;
 5503|      0|			}
 5504|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5505|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5505:8): [True: 0, False: 0]
  |  Branch (5505:19): [True: 0, False: 0]
  ------------------
 5506|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5506:7): [True: 0, False: 0]
  |  Branch (5506:25): [True: 0, False: 0]
  ------------------
 5507|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5508|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5509|      0|				goto err;
 5510|      0|			}
 5511|      0|			cert = keyref + keyreflen;
 5512|      0|			certlen = seqlen - (cert - seq);
 5513|       |
 5514|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5515|       |			/* now add the cert like another object */
 5516|       |
 5517|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5517:8): [True: 0, False: 0]
  ------------------
 5518|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5518:6): [True: 0, False: 0]
  ------------------
 5519|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5519:6): [True: 0, False: 0]
  ------------------
 5520|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5521|      0|				goto err;
 5522|      0|			}
 5523|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5524|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5525|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5525:8): [True: 0, False: 0]
  ------------------
 5526|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5527|      0|				goto err;
 5528|      0|			}
 5529|       |
 5530|      0|			certobjlen = tmplen;
 5531|      0|			certobj = malloc(certobjlen);
 5532|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5532:8): [True: 0, False: 0]
  ------------------
 5533|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5534|      0|				goto err;
 5535|      0|			}
 5536|      0|			cp = certobj;
 5537|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5537:8): [True: 0, False: 0]
  ------------------
 5538|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5538:6): [True: 0, False: 0]
  ------------------
 5539|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5539:6): [True: 0, False: 0]
  ------------------
 5540|      0|				goto err;
 5541|      0|			}
 5542|      0|			*cp++ = 0x00;
 5543|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5544|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5544:8): [True: 0, False: 0]
  ------------------
 5545|      0|				goto err;
 5546|      0|			}
 5547|       |
 5548|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5549|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5550|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5551|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5552|       |
 5553|      0|			r = piv_cache_internal_data(card, enumtag);
 5554|      0|			sc_log(card->ctx, "got internal r=%d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5555|       |
 5556|      0|			sc_log(card->ctx, "Added from off card file #%d %p:%zu 0x%02X",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5557|      0|					enumtag,
 5558|      0|					priv->obj_cache[enumtag].obj_data,
 5559|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5560|       |
 5561|      0|			bodylen -= (seqlen + seq - seqtag);
 5562|      0|			seq += seqlen;
 5563|      0|		}
 5564|      0|	}
 5565|    945|err:
 5566|    945|	if (ocfhfbuf)
  ------------------
  |  Branch (5566:6): [True: 0, False: 945]
  ------------------
 5567|      0|		free(ocfhfbuf);
 5568|    945|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    945|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    945|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    945|	int _ret = r; \
  |  |  |  |  155|    945|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 945, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    945|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    749|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 749, False: 196]
  |  |  |  |  ------------------
  |  |  |  |  157|    945|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    945|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    945|	return _ret; \
  |  |  |  |  163|    945|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5569|    945|}
card-piv.c:piv_cache_internal_data:
 3298|  1.39k|{
 3299|  1.39k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.39k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3300|  1.39k|	const u8 *tag;
 3301|  1.39k|	const u8 *body;
 3302|  1.39k|	size_t taglen;
 3303|  1.39k|	size_t bodylen;
 3304|  1.39k|	int compressed = 0;
 3305|  1.39k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.39k|#define SC_SUCCESS				0
  ------------------
 3306|       |#ifdef ENABLE_PIV_SM
 3307|       |	u8 *cvc_start = NULL;
 3308|       |	size_t cvc_len = 0;
 3309|       |#endif
 3310|       |
 3311|       |	/* if already cached */
 3312|  1.39k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3312:6): [True: 614, False: 783]
  |  Branch (3312:52): [True: 614, False: 0]
  ------------------
 3313|    614|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   71|    614|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3314|    614|				enumtag,
 3315|    614|				priv->obj_cache[enumtag].internal_obj_data,
 3316|    614|				priv->obj_cache[enumtag].internal_obj_len);
 3317|    614|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    614|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    614|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    614|	int _ret = r; \
  |  |  |  |  155|    614|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 614, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    614|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 614]
  |  |  |  |  ------------------
  |  |  |  |  157|    614|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    614|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    614|	return _ret; \
  |  |  |  |  163|    614|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3318|    614|	}
 3319|       |
 3320|    783|	body = sc_asn1_find_tag(card->ctx,
 3321|    783|			priv->obj_cache[enumtag].obj_data,
 3322|    783|			priv->obj_cache[enumtag].obj_len,
 3323|    783|			0x53, &bodylen);
 3324|       |
 3325|    783|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3325:6): [True: 0, False: 783]
  |  Branch (3325:22): [True: 0, False: 783]
  ------------------
 3326|    783|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3327|       |
 3328|       |	/* get the certificate out */
 3329|    783|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  653|    783|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3329:6): [True: 783, False: 0]
  ------------------
 3330|       |
 3331|    783|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3332|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3333|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3334|    783|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3334:7): [True: 220, False: 563]
  |  Branch (3334:14): [True: 210, False: 10]
  |  Branch (3334:29): [True: 15, False: 195]
  |  Branch (3334:48): [True: 11, False: 184]
  ------------------
 3335|     26|			compressed = 1;
 3336|       |
 3337|       |#ifdef ENABLE_PIV_SM
 3338|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3339|       |#endif
 3340|       |
 3341|    783|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3342|    783|		if (tag == NULL)
  ------------------
  |  Branch (3342:7): [True: 159, False: 624]
  ------------------
 3343|    783|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    159|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    159|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    159|	int _ret = r; \
  |  |  |  |  155|    159|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    159|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    159|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    159|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    159|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    159|	return _ret; \
  |  |  |  |  163|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3344|       |
 3345|    624|		if (taglen == 0)
  ------------------
  |  Branch (3345:7): [True: 10, False: 614]
  ------------------
 3346|    624|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3347|       |
 3348|    614|		if (compressed) {
  ------------------
  |  Branch (3348:7): [True: 6, False: 608]
  ------------------
 3349|      6|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|      6|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3350|      6|		}
 3351|       |		/* internal certificate remains compressed */
 3352|    614|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3352:7): [True: 0, False: 614]
  ------------------
 3353|    614|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3354|       |
 3355|    614|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3356|    614|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3357|       |
 3358|       |#ifdef ENABLE_PIV_SM
 3359|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3360|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3361|       |			/* cvc if present should be at cvc_start.
 3362|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3363|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3364|       |			 * as the size of (L) depends on the length of value
 3365|       |			 */
 3366|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3367|       |					cvc_start &&
 3368|       |					cvc_start < tag &&
 3369|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3370|       |				cvc_len = tag - cvc_start + taglen;
 3371|       |				/* decode the intermediate CVC */
 3372|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3373|       |				if (r < 0) {
 3374|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3375|       |				}
 3376|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3377|       |			}
 3378|       |		}
 3379|       |#endif /* ENABLE_PIV_SM */
 3380|       |
 3381|       |		/* convert pub key to internal */
 3382|    614|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3382:13): [True: 0, False: 0]
  ------------------
 3383|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3384|      0|		if (tag == NULL)
  ------------------
  |  Branch (3384:7): [True: 0, False: 0]
  ------------------
 3385|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3386|       |
 3387|      0|		if (taglen == 0)
  ------------------
  |  Branch (3387:7): [True: 0, False: 0]
  ------------------
 3388|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3389|       |
 3390|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3390:7): [True: 0, False: 0]
  ------------------
 3391|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3392|       |
 3393|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3394|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3395|      0|	} else {
 3396|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3397|      0|	}
 3398|       |
 3399|    614|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   71|    614|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3400|    614|			enumtag,
 3401|    614|			priv->obj_cache[enumtag].internal_obj_data,
 3402|    614|			priv->obj_cache[enumtag].internal_obj_len);
 3403|       |
 3404|    614|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    614|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    614|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    614|	int _ret = r; \
  |  |  |  |  155|    614|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 614, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    614|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 614]
  |  |  |  |  ------------------
  |  |  |  |  157|    614|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    614|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    614|	return _ret; \
  |  |  |  |  163|    614|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3405|    614|}
card-piv.c:piv_finish:
 5592|  10.5k|{
 5593|  10.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  10.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5594|  10.5k|	int i;
 5595|       |
 5596|  10.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
 5597|  10.5k|	if (priv) {
  ------------------
  |  Branch (5597:6): [True: 5.73k, False: 4.79k]
  ------------------
 5598|  5.73k|		if (priv->context_specific) {
  ------------------
  |  Branch (5598:7): [True: 2, False: 5.73k]
  ------------------
 5599|      2|			sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5600|      2|			priv->context_specific = 0;
 5601|      2|			sc_unlock(card);
 5602|      2|		}
 5603|  5.73k|		free(priv->aid_der.value);
 5604|  5.73k|		free(priv->al_label);
 5605|  5.73k|		if (priv->w_buf)
  ------------------
  |  Branch (5605:7): [True: 0, False: 5.73k]
  ------------------
 5606|      0|			free(priv->w_buf);
 5607|  5.73k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5607:7): [True: 76, False: 5.66k]
  ------------------
 5608|     76|			free(priv->offCardCertURL);
 5609|   349k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5609:15): [True: 344k, False: 5.73k]
  ------------------
 5610|   344k|			piv_obj_cache_free_entry(card, i, 0);
 5611|   344k|		}
 5612|   154k|		for (i = 0; i < PIV_NUM_YK_SLOT_INFO; i++) {
  ------------------
  |  |  389|   154k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (5612:15): [True: 149k, False: 5.73k]
  ------------------
 5613|   149k|			free(priv->yk_slot_info[i].pubkey.value);
 5614|   149k|		}
 5615|       |#ifdef ENABLE_PIV_SM
 5616|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5617|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5618|       |		piv_clear_sm_session(&priv->sm_session);
 5619|       |#endif /* ENABLE_PIV_SM */
 5620|       |
 5621|  5.73k|		free(priv);
 5622|       |		card->drv_data = NULL; /* priv */
 5623|  5.73k|	}
 5624|  10.5k|	return 0;
 5625|  10.5k|}
card-piv.c:piv_select_file:
 5026|  8.22k|{
 5027|  8.22k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  8.22k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5028|  8.22k|	int r;
 5029|  8.22k|	int i;
 5030|  8.22k|	const u8 *path;
 5031|  8.22k|	size_t pathlen;
 5032|  8.22k|	sc_file_t *file = NULL;
 5033|  8.22k|	u8 *rbuf = NULL;
 5034|  8.22k|	size_t rbuflen = 0;
 5035|       |
 5036|  8.22k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  8.22k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.22k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.22k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.22k]
  |  |  ------------------
  ------------------
 5037|       |
 5038|  8.22k|	path = in_path->value;
 5039|  8.22k|	pathlen = in_path->len;
 5040|       |
 5041|       |	/* only support single EF in current application */
 5042|       |	/*
 5043|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 5044|       |	 * select_file and read_binary. The emulation adds path emulated structures
 5045|       |	 * so piv_select_file will find it.
 5046|       |	 * there is no dir. Only direct access to emulated files
 5047|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 5048|       |	 */
 5049|       |
 5050|  8.22k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (5050:6): [True: 2.54k, False: 5.68k]
  ------------------
 5051|  2.54k|		if (pathlen > 2) {
  ------------------
  |  Branch (5051:7): [True: 2.54k, False: 0]
  ------------------
 5052|  2.54k|			path += 2;
 5053|  2.54k|			pathlen -= 2;
 5054|  2.54k|		}
 5055|  2.54k|	}
 5056|       |
 5057|  8.22k|	i = piv_find_obj_by_containerid(card, path);
 5058|       |
 5059|  8.22k|	if (i < 0)
  ------------------
  |  Branch (5059:6): [True: 2.57k, False: 5.65k]
  ------------------
 5060|  8.22k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  2.57k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.57k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.57k|	int _ret = r; \
  |  |  |  |  155|  2.57k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.57k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.57k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.57k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.57k|	return _ret; \
  |  |  |  |  163|  2.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5061|       |
 5062|       |	/*
 5063|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 5064|       |	 * with cece added to path to request only the cert from the cert obj
 5065|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 5066|       |	 */
 5067|  5.65k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (5067:28): [True: 5.65k, False: 0]
  |  Branch (5067:44): [True: 5.65k, False: 0]
  |  Branch (5067:63): [True: 5.65k, False: 0]
  ------------------
 5068|       |
 5069|  5.65k|	priv->selected_obj = i;
 5070|  5.65k|	priv->rwb_state = -1;
 5071|       |
 5072|       |	/* make it look like the file was found. */
 5073|       |	/* We don't want to read it now  unless we need the length */
 5074|       |
 5075|  5.65k|	if (file_out) {
  ------------------
  |  Branch (5075:6): [True: 5.65k, False: 0]
  ------------------
 5076|       |		/* we need to read it now, to get length into cache */
 5077|  5.65k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 5078|       |
 5079|  5.65k|		if (r < 0)
  ------------------
  |  Branch (5079:7): [True: 4.87k, False: 783]
  ------------------
 5080|  5.65k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  4.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.87k|	int _ret = r; \
  |  |  |  |  155|  4.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.87k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.87k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.87k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.87k|	return _ret; \
  |  |  |  |  163|  4.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5081|       |
 5082|       |		/* get the cert or the pub key out and into the cache too */
 5083|    783|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (5083:7): [True: 783, False: 0]
  |  Branch (5083:33): [True: 0, False: 0]
  ------------------
 5084|    783|			r = piv_cache_internal_data(card, i);
 5085|    783|			if (r < 0)
  ------------------
  |  Branch (5085:8): [True: 169, False: 614]
  ------------------
 5086|    783|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    169|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    169|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    169|	int _ret = r; \
  |  |  |  |  155|    169|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 169, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    169|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    169|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 169, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    169|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    169|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    169|	return _ret; \
  |  |  |  |  163|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5087|    783|		}
 5088|       |
 5089|    614|		file = sc_file_new();
 5090|    614|		if (file == NULL)
  ------------------
  |  Branch (5090:7): [True: 0, False: 614]
  ------------------
 5091|    614|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5092|       |
 5093|    614|		file->path = *in_path;
 5094|       |		/* this could be like the FCI */
 5095|    614|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    614|#define SC_FILE_TYPE_DF			0x04
  ------------------
 5096|    614|		file->shareable = 0;
 5097|    614|		file->ef_structure = 0;
 5098|    614|		if (priv->return_only_cert)
  ------------------
  |  Branch (5098:7): [True: 614, False: 0]
  ------------------
 5099|    614|			file->size = priv->obj_cache[i].internal_obj_len;
 5100|      0|		else
 5101|      0|			file->size = priv->obj_cache[i].obj_len;
 5102|       |
 5103|    614|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 5104|       |
 5105|    614|		*file_out = file;
 5106|    614|	}
 5107|       |
 5108|    614|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    614|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    614|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    614|	int _ret = r; \
  |  |  |  |  155|    614|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 614, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    614|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 614]
  |  |  |  |  ------------------
  |  |  |  |  157|    614|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    614|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    614|	return _ret; \
  |  |  |  |  163|    614|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5109|    614|}
card-piv.c:piv_find_obj_by_containerid:
 1779|  66.3k|{
 1780|  66.3k|	int i;
 1781|       |
 1782|  66.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  66.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  66.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  66.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  66.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 66.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1783|  66.3k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  66.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1784|       |
 1785|  1.40M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1785:14): [True: 1.39M, False: 3.50k]
  ------------------
 1786|  1.39M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1786:7): [True: 566k, False: 831k]
  |  Branch (1786:50): [True: 62.8k, False: 503k]
  ------------------
 1787|  1.39M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  62.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  62.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  62.8k|	int _ret = r; \
  |  |  |  |  155|  62.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 937, False: 61.8k]
  |  |  |  |  ------------------
  |  |  |  |  156|    937|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 937]
  |  |  |  |  ------------------
  |  |  |  |  157|    937|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  61.8k|	} else { \
  |  |  |  |  159|  61.8k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  61.8k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  61.8k|	} \
  |  |  |  |  162|  62.8k|	return _ret; \
  |  |  |  |  163|  62.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1788|  1.39M|	}
 1789|       |
 1790|  3.50k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  3.50k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.50k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.50k|	int _ret = r; \
  |  |  |  |  155|  3.50k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.50k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.50k|	return _ret; \
  |  |  |  |  163|  3.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1791|  3.50k|}
card-piv.c:piv_read_binary:
 3414|  2.66k|{
 3415|  2.66k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.66k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3416|  2.66k|	int enumtag;
 3417|  2.66k|	int r;
 3418|  2.66k|	u8 *rbuf = NULL;
 3419|  2.66k|	size_t rbuflen = 0;
 3420|  2.66k|	const u8 *body;
 3421|  2.66k|	size_t bodylen;
 3422|       |
 3423|  2.66k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.66k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.66k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.66k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.66k]
  |  |  ------------------
  ------------------
 3424|  2.66k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3424:6): [True: 0, False: 2.66k]
  ------------------
 3425|  2.66k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3426|  2.66k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3427|       |
 3428|  2.66k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3428:6): [True: 614, False: 2.04k]
  ------------------
 3429|    614|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3430|       |
 3431|    614|		if (r >= 0) {
  ------------------
  |  Branch (3431:7): [True: 614, False: 0]
  ------------------
 3432|       |			/* an object with no data will be considered not found */
 3433|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3434|    614|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3434:8): [True: 0, False: 614]
  |  Branch (3434:17): [True: 0, False: 614]
  |  Branch (3434:37): [True: 614, False: 0]
  |  Branch (3434:65): [True: 0, False: 614]
  ------------------
 3435|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3436|      0|				goto err;
 3437|      0|			}
 3438|       |
 3439|    614|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3440|    614|			if (body == NULL) {
  ------------------
  |  Branch (3440:8): [True: 0, False: 614]
  ------------------
 3441|       |				/* if missing, assume its the body */
 3442|       |				/* DEE bug in the beta card */
 3443|      0|				sc_log(card->ctx, " ***** tag 0x53 MISSING");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3444|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3445|      0|				goto err;
 3446|      0|			}
 3447|    614|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3447:8): [True: 0, False: 614]
  ------------------
 3448|      0|				sc_log(card->ctx, " ***** tag length > then data: %zu>%zu+%zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3449|      0|						bodylen, body - rbuf, rbuflen);
 3450|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3451|      0|				goto err;
 3452|      0|			}
 3453|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3454|    614|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3454:8): [True: 614, False: 0]
  |  Branch (3454:34): [True: 0, False: 0]
  ------------------
 3455|    614|				r = piv_cache_internal_data(card, enumtag);
 3456|    614|				if (r < 0)
  ------------------
  |  Branch (3456:9): [True: 0, False: 614]
  ------------------
 3457|      0|					goto err;
 3458|    614|			}
 3459|    614|		}
 3460|    614|		priv->rwb_state = 0;
 3461|    614|	}
 3462|       |
 3463|  2.66k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3463:6): [True: 2.66k, False: 0]
  |  Branch (3463:32): [True: 0, False: 0]
  ------------------
 3464|  2.66k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3465|  2.66k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3466|  2.66k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|  2.66k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3466:7): [True: 27, False: 2.63k]
  |  Branch (3466:70): [True: 27, False: 0]
  ------------------
 3467|     27|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     27|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3468|     27|		}
 3469|  2.66k|	} else {
 3470|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3471|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3472|      0|	}
 3473|       |	/* rbuf rbuflen has pointer and length to cached data */
 3474|       |
 3475|  2.66k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3475:6): [True: 0, False: 2.66k]
  ------------------
 3476|      0|		count = rbuflen - idx;
 3477|  2.66k|	if (count <= 0) {
  ------------------
  |  Branch (3477:6): [True: 0, False: 2.66k]
  ------------------
 3478|      0|		r = 0;
 3479|      0|		priv->rwb_state = 1;
 3480|  2.66k|	} else {
 3481|  2.66k|		memcpy(buf, rbuf + idx, count);
 3482|  2.66k|		r = (int)count;
 3483|  2.66k|	}
 3484|       |
 3485|  2.66k|err:
 3486|  2.66k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.66k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.66k|	int _ret = r; \
  |  |  |  |  155|  2.66k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 2.66k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.66k|	} else { \
  |  |  |  |  159|  2.66k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.66k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.66k|	} \
  |  |  |  |  162|  2.66k|	return _ret; \
  |  |  |  |  163|  2.66k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3487|  2.66k|}
card-piv.c:piv_set_security_env:
 4761|     51|{
 4762|     51|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     51|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4763|     51|	int r = 0;
 4764|       |
 4765|     51|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     51|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     51|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     51|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 51]
  |  |  ------------------
  ------------------
 4766|       |
 4767|     51|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|     51|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4768|     51|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4769|     51|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4770|       |
 4771|     51|	priv->operation = env->operation;
 4772|     51|	priv->algorithm = env->algorithm;
 4773|       |
 4774|     51|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|     51|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4774:6): [True: 9, False: 42]
  ------------------
 4775|      9|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4776|     42|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|     42|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4776:13): [True: 42, False: 0]
  ------------------
 4777|     42|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|     42|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4777:7): [True: 42, False: 0]
  ------------------
 4778|     42|			switch (env->algorithm_ref) {
 4779|     42|			case 256:
  ------------------
  |  Branch (4779:4): [True: 42, False: 0]
  ------------------
 4780|     42|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4781|     42|				priv->key_size = 256;
 4782|     42|				break;
 4783|      0|			case 384:
  ------------------
  |  Branch (4783:4): [True: 0, False: 42]
  ------------------
 4784|      0|				priv->alg_id = 0x14;
 4785|      0|				priv->key_size = 384;
 4786|      0|				break;
 4787|      0|			default:
  ------------------
  |  Branch (4787:4): [True: 0, False: 42]
  ------------------
 4788|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4789|     42|			}
 4790|     42|		} else
 4791|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4792|     42|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4792:13): [True: 0, False: 0]
  ------------------
 4793|      0|		priv->alg_id = 0xE0;
 4794|      0|		priv->key_size = 255;
 4795|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4795:13): [True: 0, False: 0]
  ------------------
 4796|      0|		priv->alg_id = 0xE1;
 4797|      0|		priv->key_size = 255;
 4798|      0|	} else
 4799|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4800|     51|	priv->key_ref = env->key_ref[0];
 4801|       |
 4802|     51|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 51]
  |  |  |  |  ------------------
  |  |  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4803|     51|}
card-piv.c:piv_compute_signature:
 4931|     43|{
 4932|     43|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     43|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4933|     43|	int r;
 4934|     43|	u8 *ecdata = NULL;
 4935|     43|	size_t ecdatalen = 0;
 4936|     43|	size_t ecpadlen = 0;
 4937|     43|	size_t nLen;
 4938|     43|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4939|       |
 4940|     43|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     43|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     43|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     43|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 43]
  |  |  ------------------
  ------------------
 4941|       |
 4942|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4943|       |	 * Which may have leading 00 to force a positive integer
 4944|       |	 * But PKCS11 just wants 2* field_length in bytes
 4945|       |	 * So we have to strip out the integers
 4946|       |	 * and pad on left if too short.
 4947|       |	 */
 4948|       |
 4949|     43|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4949:6): [True: 42, False: 1]
  |  Branch (4949:30): [True: 0, False: 1]
  ------------------
 4950|     42|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|     42|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4951|       |
 4952|       |		/* One applet is known to enforce the hash size
 4953|       |		 * must match the field_length in bytes. But Windows
 4954|       |		 * may try ECDSA without a hash when offline
 4955|       |		 * So we will pad input to hash size.
 4956|       |		 */
 4957|     42|		if (priv->card_issues & CI_ENFORCES_EC_HASH_EQ_KEYSIZE &&
  ------------------
  |  |  605|     84|#define CI_ENFORCES_EC_HASH_EQ_KEYSIZE	    0x00001000U /* Applet enforces hash size == EC field size for ECDSA. Windows issue */
  ------------------
  |  Branch (4957:7): [True: 0, False: 42]
  ------------------
 4958|      0|				!strcmp(card->ctx->app_name, "cardmod") &&
  ------------------
  |  Branch (4958:5): [True: 0, False: 0]
  ------------------
 4959|      0|				(datalen < nLen)) {
  ------------------
  |  Branch (4959:5): [True: 0, False: 0]
  ------------------
 4960|      0|			ecpadlen = nLen - datalen;
 4961|     42|		} else {
 4962|     42|			ecpadlen = 0;
 4963|     42|		}
 4964|       |
 4965|     42|		ecdatalen = datalen + ecpadlen;
 4966|     42|		ecdata = calloc(ecdatalen, sizeof(u8));
 4967|     42|		if (ecdata == NULL) {
  ------------------
  |  Branch (4967:7): [True: 0, False: 42]
  ------------------
 4968|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 4969|      0|			goto err;
 4970|      0|		}
 4971|     42|		memcpy(ecdata + ecpadlen, data, datalen);
 4972|       |
 4973|     42|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4973:7): [True: 0, False: 42]
  ------------------
 4974|      0|			sc_log(card->ctx, " output too small for EC signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4975|      0|					outlen, 2 * nLen);
 4976|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4977|      0|			goto err;
 4978|      0|		}
 4979|       |
 4980|     42|		r = piv_validate_general_authentication(card, ecdata, ecdatalen, rbuf, sizeof rbuf);
 4981|     42|		if (r < 0)
  ------------------
  |  Branch (4981:7): [True: 25, False: 17]
  ------------------
 4982|     25|			goto err;
 4983|       |
 4984|     17|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4985|       |		/* Yubikey 5.7.x supports ED25519 */
 4986|     17|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4986:13): [True: 0, False: 1]
  ------------------
 4987|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4988|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4988:7): [True: 0, False: 0]
  ------------------
 4989|      0|			sc_log(card->ctx, " output too small for ED signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4990|      0|					outlen, nLen);
 4991|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4992|      0|			goto err;
 4993|      0|		}
 4994|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4995|       |
 4996|      1|	} else { /* RSA is all set */
 4997|      1|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4998|      1|	}
 4999|       |
 5000|     43|err:
 5001|     43|	free(ecdata);
 5002|     43|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     43|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     43|	int _ret = r; \
  |  |  155|     43|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 39, False: 4]
  |  |  ------------------
  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 39, False: 0]
  |  |  ------------------
  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     39|	} else { \
  |  |  159|      4|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      4|			"returning with: %d\n", _ret); \
  |  |  161|      4|	} \
  |  |  162|     43|	return _ret; \
  |  |  163|     43|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5003|     43|}
card-piv.c:piv_validate_general_authentication:
 4834|     51|{
 4835|     51|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     51|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4836|     51|	int r, tmplen, tmplen2;
 4837|     51|	u8 *p;
 4838|     51|	const unsigned char *p2;
 4839|     51|	size_t taglen;
 4840|     51|	size_t bodylen;
 4841|     51|	unsigned int cla, tag;
 4842|     51|	unsigned int real_alg_id, op_tag;
 4843|       |
 4844|     51|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4845|     51|	size_t sbuflen = sizeof(sbuf);
 4846|     51|	u8 rbuf[4096];
 4847|       |
 4848|     51|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     51|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     51|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     51|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 51]
  |  |  ------------------
  ------------------
 4849|       |
 4850|       |	/* should assume large send data */
 4851|     51|	p = sbuf;
 4852|     51|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4853|     51|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4854|     51|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4854:6): [True: 0, False: 51]
  |  Branch (4854:21): [True: 0, False: 51]
  ------------------
 4855|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4856|      0|	}
 4857|     51|	tmplen += tmplen2;
 4858|     51|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|    102|#define SC_SUCCESS				0
  ------------------
  |  Branch (4858:6): [True: 0, False: 51]
  ------------------
 4859|     51|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  |  Branch (4859:4): [True: 0, False: 51]
  ------------------
 4860|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4861|      0|	}
 4862|     51|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   50|    102|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4862:6): [True: 0, False: 51]
  |  Branch (4862:53): [True: 0, False: 0]
  |  Branch (4862:91): [True: 0, False: 0]
  ------------------
 4863|      0|		op_tag = 0x85;
 4864|     51|	} else {
 4865|     51|		op_tag = 0x81;
 4866|     51|	}
 4867|     51|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4868|     51|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  |  Branch (4868:6): [True: 0, False: 51]
  ------------------
 4869|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4870|      0|	}
 4871|       |
 4872|       |	/*
 4873|       |	 * alg_id=06 is a place holder for all RSA keys.
 4874|       |	 * Derive the real alg_id based on the size of the
 4875|       |	 * the data, as we are always using raw mode.
 4876|       |	 * Non RSA keys needs some work in this area.
 4877|       |	 */
 4878|       |
 4879|     51|	real_alg_id = priv->alg_id;
 4880|     51|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4880:6): [True: 9, False: 42]
  ------------------
 4881|      9|		switch (datalen) {
 4882|      0|		case 128:
  ------------------
  |  Branch (4882:3): [True: 0, False: 9]
  ------------------
 4883|      0|			real_alg_id = 0x06;
 4884|      0|			break;
 4885|      4|		case 256:
  ------------------
  |  Branch (4885:3): [True: 4, False: 5]
  ------------------
 4886|      4|			real_alg_id = 0x07;
 4887|      4|			break;
 4888|      0|		case 384:
  ------------------
  |  Branch (4888:3): [True: 0, False: 9]
  ------------------
 4889|      0|			real_alg_id = 0x05;
 4890|      0|			break;
 4891|      0|		case 512:
  ------------------
  |  Branch (4891:3): [True: 0, False: 9]
  ------------------
 4892|      0|			real_alg_id = 0x16;
 4893|      0|			break;
 4894|      5|		default:
  ------------------
  |  Branch (4894:3): [True: 5, False: 4]
  ------------------
 4895|      5|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      5|	int _ret = r; \
  |  |  155|      5|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  ------------------
  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  ------------------
  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      5|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      5|	return _ret; \
  |  |  163|      5|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4896|      9|		}
 4897|      9|	}
 4898|       |	/* EC and ED alg_id was already set */
 4899|       |
 4900|     46|	piv_yk_notify_touch_policy(card, priv->key_ref);
 4901|     46|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4902|     46|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4903|     46|	if (r < 0)
  ------------------
  |  Branch (4903:6): [True: 24, False: 22]
  ------------------
 4904|     24|		goto err;
 4905|       |
 4906|     22|	p2 = rbuf;
 4907|     22|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4908|     22|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4908:6): [True: 1, False: 21]
  |  Branch (4908:20): [True: 1, False: 20]
  |  Branch (4908:29): [True: 1, False: 19]
  |  Branch (4908:45): [True: 2, False: 17]
  ------------------
 4909|      5|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4910|      5|	}
 4911|       |
 4912|     17|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4913|     17|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4913:6): [True: 1, False: 16]
  |  Branch (4913:20): [True: 1, False: 15]
  |  Branch (4913:29): [True: 1, False: 14]
  |  Branch (4913:44): [True: 1, False: 13]
  ------------------
 4914|      4|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x82");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4915|      4|	}
 4916|       |
 4917|     13|	if (taglen > outlen) {
  ------------------
  |  Branch (4917:6): [True: 0, False: 13]
  ------------------
 4918|      0|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "data read longer then buffer");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4919|      0|	}
 4920|       |
 4921|     13|	memcpy(out, p2, taglen);
 4922|     13|	r = (int)taglen;
 4923|       |
 4924|     46|err:
 4925|     46|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     46|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     46|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     46|	int _ret = r; \
  |  |  |  |  155|     46|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 33, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  156|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|     33|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     33|	} else { \
  |  |  |  |  159|     13|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     13|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     13|	} \
  |  |  |  |  162|     46|	return _ret; \
  |  |  |  |  163|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4926|     46|}
card-piv.c:piv_yk_notify_touch_policy:
 4815|     46|{
 4816|     46|	u8 touch_policy;
 4817|     46|	const char *title = "Touch your Yubikey to continue";
 4818|       |
 4819|     46|	piv_yk_get_metadata(card, key_ref, NULL, &touch_policy, NULL);
 4820|     46|	switch (touch_policy) {
  ------------------
  |  Branch (4820:10): [True: 2, False: 44]
  ------------------
 4821|      1|	case 0x02:
  ------------------
  |  Branch (4821:2): [True: 1, False: 45]
  ------------------
 4822|      1|		sc_notify(title, "Touching the token is required for unlocking the key");
 4823|      1|		break;
 4824|      1|	case 0x03:
  ------------------
  |  Branch (4824:2): [True: 1, False: 45]
  ------------------
 4825|      1|		sc_notify(title, "Touching the token is required unlocking the key (needed again after 15 seconds)");
 4826|      1|		break;
 4827|     46|	}
 4828|     46|}
card-piv.c:piv_yk_get_metadata:
 4549|  22.2k|{
 4550|  22.2k|	u8 resp[3072]; /* Should be enough to fit ML-DSA-87 key */
 4551|  22.2k|	int resplen = 0;
 4552|  22.2k|	size_t i;
 4553|  22.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  22.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4554|  22.2k|	int rc;
 4555|       |
 4556|       |	/* initialize with the default behaviour */
 4557|  22.2k|	if (pin_policy)
  ------------------
  |  Branch (4557:6): [True: 581, False: 21.6k]
  ------------------
 4558|    581|		*pin_policy = 0x00; /* i.e. use NIST defined */
 4559|  22.2k|	if (touch_policy)
  ------------------
  |  Branch (4559:6): [True: 46, False: 22.1k]
  ------------------
 4560|     46|		*touch_policy = 0x00;
 4561|  22.2k|	if (info) {
  ------------------
  |  Branch (4561:6): [True: 21.5k, False: 627]
  ------------------
 4562|  21.5k|		info->algorithm = 0;
 4563|  21.5k|		info->pubkey.value = NULL;
 4564|  21.5k|		info->pubkey.len = 0;
 4565|  21.5k|	}
 4566|       |
 4567|  22.2k|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4567:6): [True: 12.9k, False: 9.27k]
  ------------------
 4568|  12.9k|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4568:7): [True: 2.56k, False: 10.3k]
  ------------------
 4569|  2.56k|			sc_log(card->ctx, "Yubikey's Get metadata extension not available");
  ------------------
  |  |   71|  2.56k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4570|  12.9k|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  12.9k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4571|  12.9k|	}
 4572|       |
 4573|  22.0k|	for (i = 0; i < (PIV_NUM_YK_SLOT_INFO - 1); i++) {
  ------------------
  |  |  389|  22.0k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (4573:14): [True: 22.0k, False: 0]
  ------------------
 4574|  22.0k|		if (priv->yk_slot_info[i].slot == 0x00)
  ------------------
  |  Branch (4574:7): [True: 9.25k, False: 12.8k]
  ------------------
 4575|       |			/* reached the last initialized entry */
 4576|  9.25k|			break;
 4577|       |
 4578|  12.8k|		if (priv->yk_slot_info[i].slot == slot) {
  ------------------
  |  Branch (4578:7): [True: 23, False: 12.8k]
  ------------------
 4579|       |			/* metadata already initialized */
 4580|     23|			if (priv->yk_slot_info[i].invalid)
  ------------------
  |  Branch (4580:8): [True: 17, False: 6]
  ------------------
 4581|       |				/* already failed don't try again */
 4582|     17|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     17|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4583|      6|			break;
 4584|     23|		}
 4585|  12.8k|	}
 4586|       |
 4587|  9.25k|	if (priv->yk_slot_info[i].slot == 0x00) {
  ------------------
  |  Branch (4587:6): [True: 9.25k, False: 6]
  ------------------
 4588|       |		/* initialize this entry */
 4589|  9.25k|		rc = piv_general_io(card, 0xF7, 0x00, slot, NULL, 0, resp, sizeof(resp));
 4590|       |
 4591|  9.25k|		if (rc >= 0) { /* set defaults */
  ------------------
  |  Branch (4591:7): [True: 824, False: 8.42k]
  ------------------
 4592|    824|			priv->yk_slot_info[i].slot = slot;
 4593|    824|		}
 4594|       |
 4595|  9.25k|		if (rc > 2) { /* at least 1 TLV */
  ------------------
  |  Branch (4595:7): [True: 550, False: 8.70k]
  ------------------
 4596|    550|			resplen = rc;
 4597|    550|			rc = piv_yk_metadata_get_policy(card->ctx, resp, resplen,
 4598|    550|					&priv->yk_slot_info[i].policy, &priv->yk_slot_info[i].touch);
 4599|    550|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    550|#define SC_SUCCESS				0
  ------------------
  |  Branch (4599:8): [True: 28, False: 522]
  ------------------
 4600|     28|				sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4601|     28|						slot, priv->yk_slot_info[i].policy, priv->yk_slot_info[i].touch);
 4602|     28|			}
 4603|    550|			rc = piv_yk_metadata_get_pubkey_info(card->ctx, resp, resplen, &priv->yk_slot_info[i]);
 4604|    550|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    550|#define SC_SUCCESS				0
  ------------------
  |  Branch (4604:8): [True: 173, False: 377]
  ------------------
 4605|    173|				sc_log(card->ctx, "Public key for slot 0x%02X: present", slot);
  ------------------
  |  |   71|    173|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4606|    173|			}
 4607|  8.70k|		} else {
 4608|  8.70k|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   71|  8.70k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4609|  8.70k|			priv->yk_slot_info[i].invalid = 1;
 4610|  8.70k|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  8.70k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4611|  8.70k|		}
 4612|  9.25k|	} else if (priv->yk_slot_info[i].slot != slot) {
  ------------------
  |  Branch (4612:13): [True: 0, False: 6]
  ------------------
 4613|      0|		sc_log(card->ctx, "No free slot found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4614|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4615|      0|	}
 4616|       |
 4617|    556|	if (pin_policy)
  ------------------
  |  Branch (4617:6): [True: 19, False: 537]
  ------------------
 4618|     19|		*pin_policy = priv->yk_slot_info[i].policy;
 4619|    556|	if (touch_policy)
  ------------------
  |  Branch (4619:6): [True: 4, False: 552]
  ------------------
 4620|      4|		*touch_policy = priv->yk_slot_info[i].touch;
 4621|    556|	if (info) {
  ------------------
  |  Branch (4621:6): [True: 533, False: 23]
  ------------------
 4622|    533|		info->algorithm = priv->yk_slot_info[i].algorithm;
 4623|    533|		info->pubkey.value = priv->yk_slot_info[i].pubkey.value;
 4624|    533|		info->pubkey.len = priv->yk_slot_info[i].pubkey.len;
 4625|    533|	}
 4626|       |
 4627|    556|	return SC_SUCCESS;
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
 4628|  9.25k|}
card-piv.c:piv_yk_metadata_get_policy:
 4502|    550|{
 4503|    550|	size_t policylen;
 4504|    550|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4505|    550|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4505:6): [True: 149, False: 401]
  |  Branch (4505:16): [True: 28, False: 121]
  ------------------
 4506|     28|		*pin = policy[0];
 4507|     28|		*touch = policy[1];
 4508|     28|		return SC_SUCCESS;
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
 4509|    522|	} else {
 4510|    522|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   71|    522|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4511|    522|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    522|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4512|    522|	}
 4513|    550|}
card-piv.c:piv_yk_metadata_get_pubkey_info:
 4517|    550|{
 4518|    550|	size_t tag_len = 0;
 4519|    550|	const u8 *pk = NULL;
 4520|       |
 4521|       |	/*  Tag 0x01: Algorithm/type of key */
 4522|    550|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x01, &tag_len);
 4523|    550|	if (pk && tag_len == 1) {
  ------------------
  |  Branch (4523:6): [True: 236, False: 314]
  |  Branch (4523:12): [True: 203, False: 33]
  ------------------
 4524|    203|		info->algorithm = pk[0];
 4525|    347|	} else {
 4526|    347|		sc_log(ctx, "Yubikey algorithm not found");
  ------------------
  |  |   71|    347|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4527|    347|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    347|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4528|    347|	}
 4529|       |
 4530|       |	/*  Tag 0x04: Public key */
 4531|    203|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x04, &tag_len);
 4532|    203|	if (pk && tag_len > 0) {
  ------------------
  |  Branch (4532:6): [True: 180, False: 23]
  |  Branch (4532:12): [True: 173, False: 7]
  ------------------
 4533|    173|		info->pubkey.value = malloc(tag_len);
 4534|    173|		if (info->pubkey.value == NULL) {
  ------------------
  |  Branch (4534:7): [True: 0, False: 173]
  ------------------
 4535|      0|			return SC_ERROR_MEMORY_FAILURE;
  ------------------
  |  |   57|      0|#define SC_ERROR_MEMORY_FAILURE			-1207
  ------------------
 4536|      0|		}
 4537|    173|		memcpy(info->pubkey.value, pk, tag_len);
 4538|    173|		info->pubkey.len = tag_len;
 4539|    173|	} else {
 4540|     30|		sc_log(ctx, "Yubikey public key not found");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4541|     30|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     30|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4542|     30|	}
 4543|       |
 4544|    173|	return SC_SUCCESS;
  ------------------
  |  |   28|    173|#define SC_SUCCESS				0
  ------------------
 4545|    203|}
card-piv.c:piv_decipher:
 5007|      8|{
 5008|      8|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      8|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  ------------------
  ------------------
 5009|       |
 5010|      8|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      8|	int _ret = r; \
  |  |  155|      8|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 7, False: 1]
  |  |  ------------------
  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 6, False: 1]
  |  |  ------------------
  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      7|	} else { \
  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  161|      1|	} \
  |  |  162|      8|	return _ret; \
  |  |  163|      8|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5011|      8|}
card-piv.c:piv_check_sw:
 6305|  25.5k|{
 6306|  25.5k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6307|       |
 6308|  25.5k|	int r;
 6309|       |#ifdef ENABLE_PIV_SM
 6310|       |	int i;
 6311|       |#endif
 6312|  25.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  25.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6313|       |
 6314|  25.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  25.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  25.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  25.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 25.5k]
  |  |  ------------------
  ------------------
 6315|       |
 6316|       |	/* may be called before piv_init has allocated priv */
 6317|  25.5k|	if (priv) {
  ------------------
  |  Branch (6317:6): [True: 25.5k, False: 0]
  ------------------
 6318|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6319|       |
 6320|  25.5k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6320:7): [True: 44, False: 25.5k]
  ------------------
 6321|     44|			priv->pin_cmd_verify_sw1 = sw1;
 6322|     44|			priv->pin_cmd_verify_sw2 = sw2;
 6323|  25.5k|		} else {
 6324|       |			/* a command has completed and it is not verify
 6325|       |			 * If we are in a context_specific sequence, unlock
 6326|       |			 * This just decrements the extra lock count
 6327|       |			 */
 6328|  25.5k|			if (priv->context_specific) {
  ------------------
  |  Branch (6328:8): [True: 2, False: 25.5k]
  ------------------
 6329|      2|				sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6330|      2|				priv->context_specific = 0;
 6331|      2|				sc_unlock(card);
 6332|      2|			}
 6333|  25.5k|		}
 6334|       |
 6335|  25.5k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  591|  25.5k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6335:7): [True: 1.06k, False: 24.5k]
  ------------------
 6336|       |
 6337|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6338|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6339|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6340|       |			 */
 6341|  1.06k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6341:8): [True: 28, False: 1.03k]
  |  Branch (6341:32): [True: 2, False: 26]
  ------------------
 6342|      2|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6343|      2|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6343:9): [True: 1, False: 1]
  ------------------
 6344|      1|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6345|      1|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6346|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6347|      1|				}
 6348|      2|			}
 6349|  1.06k|		}
 6350|  25.5k|	}
 6351|       |#ifdef ENABLE_PIV_SM
 6352|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6353|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6354|       |	/* we stashed the sw1 and sw2 above for verify */
 6355|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6356|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6357|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6358|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6359|       |			return piv_sm_errors[i].errorno;
 6360|       |		}
 6361|       |	}
 6362|       |#endif
 6363|  25.5k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6364|  25.5k|	return r;
 6365|  25.5k|}
card-piv.c:piv_card_ctl:
 4654|  82.1k|{
 4655|  82.1k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  82.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4656|  82.1k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4657|       |
 4658|  82.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  82.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  82.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  82.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  82.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 82.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4659|       |
 4660|  82.1k|	if (priv == NULL) {
  ------------------
  |  Branch (4660:6): [True: 0, False: 82.1k]
  ------------------
 4661|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4662|      0|	}
 4663|  82.1k|	switch (cmd) {
  ------------------
  |  Branch (4663:10): [True: 82.1k, False: 0]
  ------------------
 4664|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4664:2): [True: 0, False: 82.1k]
  ------------------
 4665|      0|		opts = (u8 *)ptr;
 4666|      0|		switch (*opts) {
  ------------------
  |  Branch (4666:11): [True: 0, False: 0]
  ------------------
 4667|      0|		case 'A':
  ------------------
  |  Branch (4667:3): [True: 0, False: 0]
  ------------------
 4668|      0|			return piv_general_external_authenticate(card,
 4669|      0|					*(opts + 1), *(opts + 2));
 4670|      0|			break;
 4671|      0|		case 'M':
  ------------------
  |  Branch (4671:3): [True: 0, False: 0]
  ------------------
 4672|      0|			return piv_general_mutual_authenticate(card,
 4673|      0|					*(opts + 1), *(opts + 2));
 4674|      0|			break;
 4675|      0|		}
 4676|      0|		break;
 4677|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4677:2): [True: 0, False: 82.1k]
  ------------------
 4678|      0|		return piv_generate_key(card,
 4679|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4680|      0|		break;
 4681|    937|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4681:2): [True: 937, False: 81.1k]
  ------------------
 4682|    937|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4683|      0|		break;
 4684|    937|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4684:2): [True: 937, False: 81.1k]
  ------------------
 4685|    937|		return piv_get_pin_preference(card, ptr);
 4686|      0|		break;
 4687|  58.0k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4687:2): [True: 58.0k, False: 24.0k]
  ------------------
 4688|  58.0k|		return piv_is_object_present(card, ptr);
 4689|      0|		break;
 4690|    581|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4690:2): [True: 581, False: 81.5k]
  ------------------
 4691|    581|		return piv_yk_pin_policy(card, ptr);
 4692|      0|		break;
 4693|  21.5k|	case SC_CARDCTL_PIV_YK_GET_PUBKEY_INFO:
  ------------------
  |  Branch (4693:2): [True: 21.5k, False: 60.5k]
  ------------------
 4694|  21.5k|		return piv_yk_get_pubkey(card, ptr);
 4695|      0|		break;
 4696|  82.1k|	}
 4697|       |
 4698|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4699|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4382|    937|{
 4383|    937|	int r;
 4384|    937|	int i;
 4385|    937|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4386|    937|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4387|    937|	u8 *rbuf = NULL;
 4388|    937|	const u8 *body;
 4389|    937|	const u8 *fascn;
 4390|    937|	const u8 *guid;
 4391|    937|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4392|       |
 4393|    937|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    937|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    937|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    937|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 937]
  |  |  ------------------
  ------------------
 4394|    937|	if (card->serialnr.len) {
  ------------------
  |  Branch (4394:6): [True: 0, False: 937]
  ------------------
 4395|      0|		*serial = card->serialnr;
 4396|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4397|      0|	}
 4398|       |
 4399|       |	/*
 4400|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4401|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4402|       |	 * based on RFC 4122. If GUID present and not zero
 4403|       |	 * we will use the GUID as the serial number.
 4404|       |	 */
 4405|       |
 4406|    937|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4407|    937|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|    937|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    937|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    937|	int _ret = (r); \
  |  |  |  |  168|    937|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 876, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  169|    876|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    876|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    876|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    876|		return _ret; \
  |  |  |  |  172|    876|	} \
  |  |  |  |  173|    937|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4408|       |
 4409|     61|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     61|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4410|     61|	if (rbuflen != 0) {
  ------------------
  |  Branch (4410:6): [True: 61, False: 0]
  ------------------
 4411|     61|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4412|     61|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4412:7): [True: 61, False: 0]
  |  Branch (4412:23): [True: 56, False: 5]
  |  Branch (4412:39): [True: 56, False: 0]
  ------------------
 4413|     56|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4414|       |
 4415|     56|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4415:8): [True: 24, False: 32]
  |  Branch (4415:17): [True: 21, False: 3]
  ------------------
 4416|    546|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4416:17): [True: 525, False: 21]
  ------------------
 4417|    525|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4417:14): [True: 376, False: 149]
  |  Branch (4417:23): [True: 20, False: 129]
  ------------------
 4418|    525|				}
 4419|     21|			}
 4420|       |
 4421|     56|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4422|       |
 4423|     56|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4423:8): [True: 9, False: 47]
  |  Branch (4423:16): [True: 8, False: 1]
  ------------------
 4424|    136|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4424:17): [True: 128, False: 8]
  ------------------
 4425|    128|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4426|    128|				}
 4427|      8|			}
 4428|     56|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   71|     56|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4429|     56|					fascn, fascnlen, guid, guidlen, gbits);
 4430|       |
 4431|     56|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4431:8): [True: 24, False: 32]
  |  Branch (4431:17): [True: 21, False: 3]
  |  Branch (4431:35): [True: 20, False: 1]
  ------------------
 4432|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4433|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4434|     20|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4434:11): [True: 7, False: 13]
  |  Branch (4434:20): [True: 6, False: 1]
  |  Branch (4434:40): [True: 5, False: 1]
  ------------------
 4435|     19|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4435:11): [True: 2, False: 3]
  |  Branch (4435:31): [True: 1, False: 1]
  ------------------
 4436|       |					/* fascnlen is 25 */
 4437|     19|					serial->len = fascnlen;
 4438|     19|					memcpy(serial->value, fascn, serial->len);
 4439|     19|					r = SC_SUCCESS;
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
 4440|     19|					gbits = 0; /* set to skip using guid below */
 4441|     19|				}
 4442|     20|			}
 4443|     56|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4443:8): [True: 9, False: 47]
  |  Branch (4443:16): [True: 8, False: 1]
  |  Branch (4443:33): [True: 2, False: 6]
  ------------------
 4444|      2|				serial->len = guidlen;
 4445|      2|				memcpy(serial->value, guid, serial->len);
 4446|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4447|      2|			}
 4448|     56|		}
 4449|     61|	}
 4450|       |
 4451|     61|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4451:6): [True: 41, False: 20]
  |  Branch (4451:20): [True: 40, False: 1]
  ------------------
 4452|     40|		serial->len = 16;
 4453|     40|		memset(serial->value, 0x00, serial->len);
 4454|     40|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     40|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4455|     40|	}
 4456|       |
 4457|     61|	card->serialnr = *serial;
 4458|     61|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     61|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     61|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     61|	int _ret = r; \
  |  |  |  |  155|     61|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 40, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  157|     61|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     61|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     61|	return _ret; \
  |  |  |  |  163|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4459|     61|}
card-piv.c:piv_get_pin_preference:
 4493|    937|{
 4494|    937|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|    937|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4495|       |
 4496|    937|	*pin_ref = priv->pin_preference;
 4497|    937|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    937|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    937|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    937|	int _ret = r; \
  |  |  |  |  155|    937|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 937, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    937|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 937]
  |  |  |  |  ------------------
  |  |  |  |  157|    937|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    937|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    937|	return _ret; \
  |  |  |  |  163|    937|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4498|    937|}
card-piv.c:piv_is_object_present:
 4474|  58.0k|{
 4475|  58.0k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  58.0k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4476|  58.0k|	int r = 0;
 4477|  58.0k|	int enumtag;
 4478|       |
 4479|  58.0k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4480|  58.0k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  57.1k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4480:6): [True: 57.1k, False: 937]
  |  Branch (4480:22): [True: 37.2k, False: 19.9k]
  ------------------
 4481|  37.2k|		r = 1;
 4482|       |
 4483|  58.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  58.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  58.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  58.0k|	int _ret = r; \
  |  |  |  |  155|  58.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20.8k, False: 37.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  20.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20.8k]
  |  |  |  |  ------------------
  |  |  |  |  157|  20.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  37.2k|	} else { \
  |  |  |  |  159|  37.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  37.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  37.2k|	} \
  |  |  |  |  162|  58.0k|	return _ret; \
  |  |  |  |  163|  58.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4484|  58.0k|}
card-piv.c:piv_yk_pin_policy:
 4632|    581|{
 4633|    581|	u8 slot = *ptr;
 4634|    581|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL, NULL));
  ------------------
  |  |  164|    581|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    581|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    581|	int _ret = r; \
  |  |  |  |  155|    581|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 581, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    581|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    562|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 562, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  157|    581|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    581|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    581|	return _ret; \
  |  |  |  |  163|    581|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4635|    581|}
card-piv.c:piv_yk_get_pubkey:
 4639|  21.5k|{
 4640|  21.5k|	int rc;
 4641|  21.5k|	u8 slot = info->slot;
 4642|       |
 4643|  21.5k|	rc = piv_yk_get_metadata(card, slot, NULL, NULL, info);
 4644|  21.5k|	LOG_TEST_RET(card->ctx, rc, "piv_yk_get_metadata failed");
  ------------------
  |  |  174|  21.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  21.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  21.5k|	int _ret = (r); \
  |  |  |  |  168|  21.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21.0k, False: 533]
  |  |  |  |  ------------------
  |  |  |  |  169|  21.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  21.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  21.0k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  21.0k|		return _ret; \
  |  |  |  |  172|  21.0k|	} \
  |  |  |  |  173|  21.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 533]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4645|    533|	if (info->pubkey.value == NULL || info->pubkey.len == 0 || info->algorithm == 0) {
  ------------------
  |  Branch (4645:6): [True: 360, False: 173]
  |  Branch (4645:36): [True: 0, False: 173]
  |  Branch (4645:61): [True: 10, False: 163]
  ------------------
 4646|    370|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    370|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    370|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    370|	int _ret = r; \
  |  |  |  |  155|    370|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 370, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    370|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    370|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 370, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    370|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    370|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    370|	return _ret; \
  |  |  |  |  163|    370|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4647|    370|	}
 4648|       |
 4649|    163|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    163|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    163|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    163|	int _ret = r; \
  |  |  |  |  155|    163|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 163, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    163|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 163]
  |  |  |  |  ------------------
  |  |  |  |  157|    163|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    163|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    163|	return _ret; \
  |  |  |  |  163|    163|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4650|    163|}
card-piv.c:piv_pin_cmd:
 6438|     34|{
 6439|     34|	int r = 0;
 6440|     34|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     34|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6441|       |
 6442|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6443|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6444|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6445|       |	 */
 6446|     34|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6447|       |
 6448|     34|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     34|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     34|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     34|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 34]
  |  |  ------------------
  ------------------
 6449|     34|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|     34|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6450|     34|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|     34|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6450:6): [True: 0, False: 34]
  ------------------
 6451|      0|		size_t i = 0;
 6452|      0|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6452:7): [True: 0, False: 0]
  ------------------
 6453|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6454|      0|		}
 6455|      0|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6455:15): [True: 0, False: 0]
  ------------------
 6456|      0|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6456:8): [True: 0, False: 0]
  ------------------
 6457|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6458|      0|			}
 6459|      0|		}
 6460|      0|	}
 6461|       |
 6462|     34|	priv->pin_cmd_verify_sw1 = 0x00U;
 6463|       |
 6464|     34|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|     34|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6464:6): [True: 0, False: 34]
  ------------------
 6465|      0|		data->pin1.logged_in = priv->logged_in;
 6466|      0|		data->pin1.tries_left = priv->tries_left;
 6467|       |
 6468|       |		/*
 6469|       |		 * If called to check on the login state for a context specific login
 6470|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6471|       |		 */
 6472|      0|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|      0|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6472:7): [True: 0, False: 0]
  ------------------
 6473|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6474|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6475|      0|		}
 6476|       |
 6477|      0|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6477:7): [True: 0, False: 0]
  ------------------
 6478|       |			/* Avoid status requests when the user is logged in to handle NIST
 6479|       |			 * 800-73-4 Part 2:
 6480|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6481|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6482|       |			 * PIN or OCC data must be submitted and verified every time
 6483|       |			 * immediately before a digital signature key operation.  This
 6484|       |			 * ensures cardholder participation every time the private key is
 6485|       |			 * used for digital signature generation */
 6486|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6487|      0|		}
 6488|      0|	}
 6489|       |
 6490|       |	/*
 6491|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6492|       |	 * to avoid any interference from other applications.
 6493|       |	 * Sc_unlock will be called at a later time after the next card command
 6494|       |	 * that should be a crypto operation. If its not then it is a error by the
 6495|       |	 * calling application.
 6496|       |	 */
 6497|     34|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|     68|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|     34|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6497:6): [True: 34, False: 0]
  |  Branch (6497:40): [True: 10, False: 24]
  ------------------
 6498|     10|		priv->context_specific = 1;
 6499|     10|		sc_log(card->ctx, "Starting CONTEXT_SPECIFIC verify");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6500|     10|		r = sc_lock(card);
 6501|     10|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  |  Branch (6501:7): [True: 0, False: 10]
  ------------------
 6502|      0|			sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6503|      0|			return r;
 6504|      0|		}
 6505|     10|	}
 6506|       |
 6507|     34|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6508|     34|	r = iso_drv->ops->pin_cmd(card, data);
 6509|     34|	priv->pin_cmd_verify = 0;
 6510|       |
 6511|       |	/* tell user verify not supported on contactless without VCI */
 6512|     34|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6512:6): [True: 3, False: 31]
  |  Branch (6512:42): [True: 1, False: 2]
  ------------------
 6513|      1|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|     35|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6513:4): [True: 0, False: 1]
  ------------------
 6514|      0|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6514:4): [True: 0, False: 0]
  ------------------
 6515|      0|		sc_log(card->ctx, "Token does not support pin verify over contacless reader");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6516|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6517|      0|	}
 6518|       |
 6519|       |	/* if verify failed, release the lock */
 6520|     34|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|     68|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6520:6): [True: 34, False: 0]
  |  Branch (6520:40): [True: 24, False: 10]
  |  Branch (6520:49): [True: 6, False: 18]
  ------------------
 6521|      6|		sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC");
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6522|      6|		priv->context_specific = 0;
 6523|      6|		sc_unlock(card);
 6524|      6|	}
 6525|       |
 6526|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6527|     34|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  600|     68|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6527:6): [True: 23, False: 11]
  |  Branch (6527:53): [True: 10, False: 13]
  ------------------
 6528|     10|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6529|     10|		piv_find_aid(card);
 6530|       |
 6531|     10|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6532|     10|		r = iso_drv->ops->pin_cmd(card, data);
 6533|     10|		priv->pin_cmd_verify = 0;
 6534|     10|	}
 6535|       |
 6536|       |	/* If verify worked, we are logged_in */
 6537|     34|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|     34|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6537:6): [True: 34, False: 0]
  ------------------
 6538|     34|		if (r >= 0)
  ------------------
  |  Branch (6538:7): [True: 14, False: 20]
  ------------------
 6539|     14|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     14|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6540|     20|		else
 6541|     20|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     20|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6542|     34|	}
 6543|       |
 6544|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6545|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6546|       |
 6547|     34|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|     34|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6547:6): [True: 0, False: 34]
  ------------------
 6548|      0|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  595|      0|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6548:7): [True: 0, False: 0]
  ------------------
 6549|      0|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6550|      0|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6551|      0|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  592|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6551:14): [True: 0, False: 0]
  ------------------
 6552|      0|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6552:5): [True: 0, False: 0]
  ------------------
 6553|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6554|      0|			r = piv_check_protected_objects(card);
 6555|      0|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6555:8): [True: 0, False: 0]
  ------------------
 6556|      0|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6557|      0|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6557:13): [True: 0, False: 0]
  ------------------
 6558|      0|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  595|      0|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6558:9): [True: 0, False: 0]
  ------------------
 6559|       |
 6560|      0|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6561|      0|				} else {
 6562|      0|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6563|      0|				}
 6564|      0|				r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 6565|      0|			}
 6566|      0|		}
 6567|      0|		priv->logged_in = data->pin1.logged_in;
 6568|      0|		priv->tries_left = data->pin1.tries_left;
 6569|      0|	}
 6570|       |
 6571|     34|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|     34|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6572|     34|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6573|     34|}
card-piv.c:piv_card_reader_lock_obtained:
 6612|  7.69k|{
 6613|  7.69k|	int r = 0;
 6614|  7.69k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6615|  7.69k|	size_t templen = sizeof(temp);
 6616|  7.69k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  447|  7.69k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6617|       |
 6618|  7.69k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.69k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.69k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.69k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.69k]
  |  |  ------------------
  ------------------
 6619|       |
 6620|       |	/* We have a PCSC transaction and sc_lock */
 6621|  7.69k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6621:6): [True: 5.73k, False: 1.95k]
  |  Branch (6621:22): [True: 945, False: 1.01k]
  ------------------
 6622|  6.68k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  13.3k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:103): [True: 945, False: 5.73k]
  |  |  ------------------
  ------------------
 6623|  6.68k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6624|  6.68k|		r = 0; /* do nothing, piv_match will take care of it */
 6625|  6.68k|		goto err;
 6626|  6.68k|	}
 6627|       |
 6628|  1.01k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  1.01k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6629|       |
 6630|       |	/* make sure our application is active */
 6631|       |
 6632|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6633|       |	/* If not try selecting AID */
 6634|       |
 6635|       |	/* but if card does not support DISCOVERY object we can not use it */
 6636|  1.01k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  597|  1.01k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6636:6): [True: 966, False: 46]
  ------------------
 6637|    966|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    966|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6638|    966|	} else {
 6639|     46|		r = piv_find_discovery(card);
 6640|       |#ifdef ENABLE_PIV_SM
 6641|       |		/*
 6642|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6643|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6644|       |		 * Discovery object can be read with contact or contactless
 6645|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6646|       |		 * sm.c will close the SM connectrion, and set defer
 6647|       |		 */
 6648|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6649|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6650|       |			piv_sm_open(card);
 6651|       |			r = piv_find_discovery(card);
 6652|       |		}
 6653|       |#endif /* ENABLE_PIV_SM */
 6654|     46|	}
 6655|       |
 6656|  1.01k|	if (r < 0) {
  ------------------
  |  Branch (6656:6): [True: 998, False: 14]
  ------------------
 6657|    998|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  598|    998|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6657:7): [True: 0, False: 998]
  |  Branch (6657:24): [True: 985, False: 13]
  ------------------
 6658|    985|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6659|    985|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    985|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6660|    985|		} else {
 6661|     13|			r = 0; /* can't do anything with this card, hope there was no interference */
 6662|     13|		}
 6663|    998|	}
 6664|       |
 6665|  1.01k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6665:6): [True: 763, False: 249]
  ------------------
 6666|    763|		goto err;
 6667|       |
 6668|    249|	if (was_reset > 0)
  ------------------
  |  Branch (6668:6): [True: 0, False: 249]
  ------------------
 6669|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6670|       |
 6671|    249|	r = 0;
 6672|       |
 6673|  7.69k|err:
 6674|  7.69k|	if (priv)
  ------------------
  |  Branch (6674:6): [True: 1.95k, False: 5.73k]
  ------------------
 6675|  1.95k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  1.95k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6676|  7.69k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.69k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.69k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.69k|	int _ret = r; \
  |  |  |  |  155|  7.69k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.69k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.69k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    763|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 763, False: 6.93k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.69k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.69k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.69k|	return _ret; \
  |  |  |  |  163|  7.69k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6677|  7.69k|}

sc_get_rtecp_driver:
  868|  15.2k|{
  869|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (869:6): [True: 1, False: 15.2k]
  ------------------
  870|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  871|  15.2k|	rtecp_ops = *iso_ops;
  872|       |
  873|  15.2k|	rtecp_ops.match_card = rtecp_match_card;
  874|  15.2k|	rtecp_ops.init = rtecp_init;
  875|       |	/* read_binary */
  876|  15.2k|	rtecp_ops.write_binary = NULL;
  877|       |	/* update_binary */
  878|  15.2k|	rtecp_ops.read_record = NULL;
  879|  15.2k|	rtecp_ops.write_record = NULL;
  880|  15.2k|	rtecp_ops.append_record = NULL;
  881|  15.2k|	rtecp_ops.update_record = NULL;
  882|  15.2k|	rtecp_ops.select_file = rtecp_select_file;
  883|       |	/* get_response */
  884|       |	/* get_challenge */
  885|  15.2k|	rtecp_ops.verify = rtecp_verify;
  886|  15.2k|	rtecp_ops.logout = rtecp_logout;
  887|       |	/* restore_security_env */
  888|  15.2k|	rtecp_ops.set_security_env = rtecp_set_security_env;
  889|  15.2k|	rtecp_ops.decipher = rtecp_decipher;
  890|  15.2k|	rtecp_ops.compute_signature = rtecp_compute_signature;
  891|  15.2k|	rtecp_ops.change_reference_data = rtecp_change_reference_data;
  892|  15.2k|	rtecp_ops.reset_retry_counter = rtecp_reset_retry_counter;
  893|  15.2k|	rtecp_ops.create_file = rtecp_create_file;
  894|       |	/* delete_file */
  895|  15.2k|	rtecp_ops.list_files = rtecp_list_files;
  896|       |	/* check_sw */
  897|  15.2k|	rtecp_ops.card_ctl = rtecp_card_ctl;
  898|       |	/* process_fci */
  899|  15.2k|	rtecp_ops.construct_fci = rtecp_construct_fci;
  900|       |	rtecp_ops.pin_cmd = NULL;
  901|  15.2k|	return &rtecp_drv;
  902|  15.2k|}
card-rtecp.c:rtecp_match_card:
   73|  9.04k|{
   74|  9.04k|	int i = -1;
   75|  9.04k|	i = _sc_match_atr(card, rtecp_atrs, &card->type);
   76|  9.04k|	if (i >= 0) {
  ------------------
  |  Branch (76:6): [True: 55, False: 8.98k]
  ------------------
   77|     55|		card->name = rtecp_atrs[i].name;
   78|     55|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|     55|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     55|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     55|	int _ret = r; \
  |  |  |  |  155|     55|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     55|	} else { \
  |  |  |  |  159|     55|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     55|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     55|	} \
  |  |  |  |  162|     55|	return _ret; \
  |  |  |  |  163|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   79|     55|	}
   80|  8.98k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  8.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.98k|	int _ret = r; \
  |  |  |  |  155|  8.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.98k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 8.98k]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.98k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.98k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.98k|	return _ret; \
  |  |  |  |  163|  8.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   81|  8.98k|}
card-rtecp.c:rtecp_init:
   84|     55|{
   85|     55|	sc_algorithm_info_t info;
   86|     55|	unsigned long flags;
   87|       |
   88|     55|	if (!card || !card->ctx)
  ------------------
  |  Branch (88:6): [True: 0, False: 55]
  |  Branch (88:15): [True: 0, False: 55]
  ------------------
   89|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|       |
   91|     55|	card->cla = 0;
   92|       |
   93|     55|	if (card->type == SC_CARD_TYPE_RUTOKEN_LITE
  ------------------
  |  Branch (93:6): [True: 0, False: 55]
  ------------------
   94|     55|			|| card->type == SC_CARD_TYPE_RUTOKEN_LITE_SC)
  ------------------
  |  Branch (94:7): [True: 1, False: 54]
  ------------------
   95|      1|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   96|       |
   97|     54|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     54|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
   98|       |
   99|     54|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|     54|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|     54|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  100|     54|		| SC_ALGORITHM_RSA_PAD_NONE | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  104|     54|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
              		| SC_ALGORITHM_RSA_PAD_NONE | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     54|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  101|       |
  102|     54|	_sc_card_add_rsa_alg(card, 256, flags, 0);
  103|     54|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  104|     54|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  105|     54|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  106|     54|	_sc_card_add_rsa_alg(card, 1280, flags, 0);
  107|     54|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  108|     54|	_sc_card_add_rsa_alg(card, 1792, flags, 0);
  109|     54|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  110|     54|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  111|       |
  112|     54|	memset(&info, 0, sizeof(info));
  113|     54|	info.algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|     54|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  114|     54|	info.key_length = 256;
  115|     54|	info.flags = SC_ALGORITHM_GOSTR3410_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  156|     54|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
              	info.flags = SC_ALGORITHM_GOSTR3410_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|     54|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  116|     54|		| SC_ALGORITHM_GOSTR3410_HASH_NONE;
  ------------------
  |  |  157|     54|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  156|     54|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
  117|     54|	_sc_card_add_algorithm(card, &info);
  118|       |
  119|     54|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     54|	int _ret = r; \
  |  |  155|     54|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  ------------------
  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 54]
  |  |  ------------------
  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     54|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     54|	return _ret; \
  |  |  163|     54|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  120|     54|}
card-rtecp.c:rtecp_select_file:
  285|    274|{
  286|    274|	sc_file_t *file = NULL;
  287|    274|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    274|#define SC_SUCCESS				0
  ------------------
  288|       |
  289|    274|	if (!card || !card->ctx || !in_path)
  ------------------
  |  Branch (289:6): [True: 0, False: 274]
  |  Branch (289:15): [True: 0, False: 274]
  |  Branch (289:29): [True: 0, False: 274]
  ------------------
  290|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  291|       |
  292|    274|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    274|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    274|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    274|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 274]
  |  |  ------------------
  ------------------
  293|       |
  294|    274|	switch (in_path->type)
  ------------------
  |  Branch (294:10): [True: 102, False: 172]
  ------------------
  295|    274|	{
  296|    102|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    102|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (296:2): [True: 102, False: 172]
  ------------------
  297|    102|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    102|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (297:2): [True: 0, False: 274]
  ------------------
  298|    102|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    102|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (298:2): [True: 0, False: 274]
  ------------------
  299|    102|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|    102|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    102|	int _ret = r; \
  |  |  155|    102|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 102, False: 0]
  |  |  ------------------
  |  |  156|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    102|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 102, False: 0]
  |  |  ------------------
  |  |  157|    102|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    102|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    102|	return _ret; \
  |  |  163|    102|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  300|    274|	}
  301|       |
  302|       |	// Card Rutoken ECP SC T0 doesn't support SELECT FILE without return a file info.
  303|       |	// So here we request a file and then assign/free it depending on file_out.
  304|    172|	r = iso_ops->select_file(card, in_path, &file);
  305|    172|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    172|#define SC_SUCCESS				0
  ------------------
  |  Branch (305:6): [True: 96, False: 76]
  ------------------
  306|     96|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     96|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     96|	int _ret = r; \
  |  |  155|     96|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 96, False: 0]
  |  |  ------------------
  |  |  156|     96|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 96, False: 0]
  |  |  ------------------
  |  |  157|     96|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     96|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     96|	return _ret; \
  |  |  163|     96|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  307|       |
  308|     76|	if (file->sec_attr && file->sec_attr_len == SC_RTECP_SEC_ATTR_SIZE)
  ------------------
  |  |  781|     70|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (308:6): [True: 70, False: 6]
  |  Branch (308:24): [True: 60, False: 10]
  ------------------
  309|     60|		set_acl_from_sec_attr(card, file);
  310|     16|	else
  311|     16|	{
  312|     16|		sc_file_free(file);
  313|     16|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     16|	int _ret = r; \
  |  |  155|     16|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  ------------------
  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 16, False: 0]
  |  |  ------------------
  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     16|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     16|	return _ret; \
  |  |  163|     16|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  314|     16|	}
  315|       |
  316|     60|	if (file_out)
  ------------------
  |  Branch (316:6): [True: 45, False: 15]
  ------------------
  317|     45|		*file_out = file;
  318|     15|	else
  319|     15|		sc_file_free(file);
  320|       |
  321|     60|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     60|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     60|	int _ret = r; \
  |  |  155|     60|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 60, False: 0]
  |  |  ------------------
  |  |  156|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 60]
  |  |  ------------------
  |  |  157|     60|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     60|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     60|	return _ret; \
  |  |  163|     60|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  322|     60|}
card-rtecp.c:set_acl_from_sec_attr:
  167|     60|{
  168|     60|	unsigned int method;
  169|     60|	unsigned long key_ref;
  170|       |
  171|     60|	if (!card || !card->ctx || !file || !file->sec_attr
  ------------------
  |  Branch (171:6): [True: 0, False: 60]
  |  Branch (171:15): [True: 0, False: 60]
  |  Branch (171:29): [True: 0, False: 60]
  |  Branch (171:38): [True: 0, False: 60]
  ------------------
  172|     60|		|| file->sec_attr_len != SC_RTECP_SEC_ATTR_SIZE
  ------------------
  |  |  781|    120|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (172:6): [True: 0, False: 60]
  ------------------
  173|      0|		|| 1 + 6 >= SC_RTECP_SEC_ATTR_SIZE)
  ------------------
  |  |  781|      0|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (173:6): [Folded, False: 0]
  ------------------
  174|      0|	{
  175|      0|		return;
  176|      0|	}
  177|       |
  178|     60|	sc_file_add_acl_entry(file, SC_AC_OP_SELECT, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  166|     60|#define SC_AC_OP_SELECT			0
  ------------------
              	sc_file_add_acl_entry(file, SC_AC_OP_SELECT, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     60|#define SC_AC_NONE			0x00000000
  ------------------
              	sc_file_add_acl_entry(file, SC_AC_OP_SELECT, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     60|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  179|     60|	if (file->sec_attr[0] & 0x40) /* if AccessMode.6 */
  ------------------
  |  Branch (179:6): [True: 47, False: 13]
  ------------------
  180|     47|	{
  181|     47|		method = sec_attr_to_method(file->sec_attr[1 + 6]);
  182|     47|		key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 6]);
  183|     47|		sc_log(card->ctx,
  ------------------
  |  |   71|     47|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  184|     47|			"SC_AC_OP_DELETE %i %lu\n",
  185|     47|			(int)method, key_ref);
  186|     47|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|     47|#define SC_AC_OP_DELETE			2
  ------------------
  187|     47|	}
  188|     60|	if (file->sec_attr[0] & 0x01) /* if AccessMode.0 */
  ------------------
  |  Branch (188:6): [True: 46, False: 14]
  ------------------
  189|     46|	{
  190|     46|		method = sec_attr_to_method(file->sec_attr[1 + 0]);
  191|     46|		key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 0]);
  192|     46|		sc_log(card->ctx,
  ------------------
  |  |   71|     92|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:110): [True: 1, False: 45]
  |  |  ------------------
  ------------------
  193|     46|			(file->type == SC_FILE_TYPE_DF) ?
  194|     46|				"SC_AC_OP_CREATE %i %lu\n"
  195|     46|				: "SC_AC_OP_READ %i %lu\n",
  196|     46|			(int)method, key_ref);
  197|     46|		sc_file_add_acl_entry(file, (file->type == SC_FILE_TYPE_DF) ?
  ------------------
  |  |  214|     46|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (197:31): [True: 1, False: 45]
  ------------------
  198|     45|				SC_AC_OP_CREATE : SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  169|      1|#define SC_AC_OP_CREATE			3
  ------------------
              				SC_AC_OP_CREATE : SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|     91|#define SC_AC_OP_READ			22
  ------------------
  199|     46|	}
  200|     60|	if (file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|     60|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (200:6): [True: 1, False: 59]
  ------------------
  201|      1|	{
  202|      1|		sc_file_add_acl_entry(file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|      1|#define SC_AC_OP_LIST_FILES		6
  ------------------
  203|      1|				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|      1|#define SC_AC_NONE			0x00000000
  ------------------
              				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|      1|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  204|      1|	}
  205|     59|	else
  206|     59|		if (file->sec_attr[0] & 0x02) /* if AccessMode.1 */
  ------------------
  |  Branch (206:7): [True: 44, False: 15]
  ------------------
  207|     44|		{
  208|     44|			method = sec_attr_to_method(file->sec_attr[1 + 1]);
  209|     44|			key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 1]);
  210|     44|			sc_log(card->ctx,
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  211|     44|				"SC_AC_OP_UPDATE %i %lu\n",
  212|     44|				(int)method, key_ref);
  213|     44|			sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|     44|#define SC_AC_OP_UPDATE			23
  ------------------
  214|     44|			sc_log(card->ctx,
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  215|     44|				"SC_AC_OP_WRITE %i %lu\n",
  216|     44|				(int)method, key_ref);
  217|     44|			sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|     44|#define SC_AC_OP_WRITE			24
  ------------------
  218|     44|		}
  219|     60|}
card-rtecp.c:sec_attr_to_method:
  139|    137|{
  140|    137|	if (attr == 0xFF)
  ------------------
  |  Branch (140:6): [True: 28, False: 109]
  ------------------
  141|     28|		return SC_AC_NEVER;
  ------------------
  |  |  163|     28|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  142|    109|	else if (attr == 0)
  ------------------
  |  Branch (142:11): [True: 40, False: 69]
  ------------------
  143|     40|		return SC_AC_NONE;
  ------------------
  |  |  150|     40|#define SC_AC_NONE			0x00000000
  ------------------
  144|     69|	else if (attr & 0x03)
  ------------------
  |  Branch (144:11): [True: 50, False: 19]
  ------------------
  145|     50|		return SC_AC_CHV;
  ------------------
  |  |  151|     50|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  146|     19|	else
  147|     19|		return SC_AC_UNKNOWN;
  ------------------
  |  |  162|     19|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  148|    137|}
card-rtecp.c:sec_attr_to_key_ref:
  151|    137|{
  152|    137|	if (attr == 1 || attr == 2)
  ------------------
  |  Branch (152:6): [True: 21, False: 116]
  |  Branch (152:19): [True: 11, False: 105]
  ------------------
  153|     32|		return attr;
  154|    105|	return 0;
  155|    137|}

sc_get_rutoken_driver:
 1320|  15.2k|{
 1321|  15.2k|	return get_rutoken_driver();
 1322|  15.2k|}
card-rutoken.c:get_rutoken_driver:
 1281|  15.2k|{
 1282|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1282:6): [True: 1, False: 15.2k]
  ------------------
 1283|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1284|  15.2k|	rutoken_ops = *iso_ops;
 1285|       |
 1286|  15.2k|	rutoken_ops.match_card = rutoken_match_card;
 1287|  15.2k|	rutoken_ops.init = rutoken_init;
 1288|  15.2k|	rutoken_ops.finish = rutoken_finish;
 1289|       |	/* read_binary */
 1290|  15.2k|	rutoken_ops.write_binary = NULL;
 1291|       |	/* update_binary */
 1292|  15.2k|	rutoken_ops.read_record = NULL;
 1293|  15.2k|	rutoken_ops.write_record = NULL;
 1294|  15.2k|	rutoken_ops.append_record = NULL;
 1295|  15.2k|	rutoken_ops.update_record = NULL;
 1296|  15.2k|	rutoken_ops.select_file = rutoken_select_file;
 1297|  15.2k|	rutoken_ops.get_response = NULL;
 1298|  15.2k|	rutoken_ops.get_challenge = rutoken_get_challenge;
 1299|  15.2k|	rutoken_ops.verify = rutoken_verify;
 1300|  15.2k|	rutoken_ops.logout = rutoken_logout;
 1301|  15.2k|	rutoken_ops.restore_security_env = rutoken_restore_security_env;
 1302|  15.2k|	rutoken_ops.set_security_env = rutoken_set_security_env;
 1303|  15.2k|	rutoken_ops.decipher = NULL;
 1304|  15.2k|	rutoken_ops.compute_signature = rutoken_compute_signature;
 1305|  15.2k|	rutoken_ops.change_reference_data = rutoken_change_reference_data;
 1306|  15.2k|	rutoken_ops.reset_retry_counter = rutoken_reset_retry_counter;
 1307|  15.2k|	rutoken_ops.create_file = rutoken_create_file;
 1308|  15.2k|	rutoken_ops.delete_file = rutoken_delete_file;
 1309|  15.2k|	rutoken_ops.list_files = rutoken_list_files;
 1310|  15.2k|	rutoken_ops.check_sw = rutoken_check_sw;
 1311|  15.2k|	rutoken_ops.card_ctl = rutoken_card_ctl;
 1312|  15.2k|	rutoken_ops.process_fci = rutoken_process_fci;
 1313|  15.2k|	rutoken_ops.construct_fci = rutoken_construct_fci;
 1314|  15.2k|	rutoken_ops.pin_cmd = NULL;
 1315|       |
 1316|  15.2k|	return &rutoken_drv;
 1317|  15.2k|}
card-rutoken.c:rutoken_match_card:
  103|  9.15k|{
  104|  9.15k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.15k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.15k]
  |  |  ------------------
  ------------------
  105|  9.15k|	if (_sc_match_atr(card, rutoken_atrs, &card->type) >= 0)
  ------------------
  |  Branch (105:6): [True: 114, False: 9.04k]
  ------------------
  106|    114|	{
  107|    114|		sc_log(card->ctx,  "ATR recognized as Rutoken\n");
  ------------------
  |  |   71|    114|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  108|    114|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    114|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    114|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    114|	int _ret = r; \
  |  |  |  |  155|    114|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    114|	} else { \
  |  |  |  |  159|    114|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    114|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    114|	} \
  |  |  |  |  162|    114|	return _ret; \
  |  |  |  |  163|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|    114|	}
  110|  9.04k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  9.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.04k|	int _ret = r; \
  |  |  |  |  155|  9.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9.04k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.04k|	return _ret; \
  |  |  |  |  163|  9.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  111|  9.04k|}
card-rutoken.c:rutoken_init:
  127|    114|{
  128|    114|	int ret;
  129|       |
  130|    114|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    114|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    114|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    114|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 114]
  |  |  ------------------
  ------------------
  131|       |	/* &rutoken_atrs[1] : { uaToken S ATR, NULL ATR } */
  132|    114|	if (_sc_match_atr(card, &rutoken_atrs[1], &card->type) >= 0)
  ------------------
  |  Branch (132:6): [True: 113, False: 1]
  ------------------
  133|    113|		ret = token_init(card, "uaToken S card");
  134|      1|	else
  135|      1|		ret = token_init(card, "Rutoken S card");
  136|       |
  137|    114|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|    114|#define SC_SUCCESS				0
  ------------------
  |  Branch (137:6): [True: 0, False: 114]
  ------------------
  138|      0|		ret = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  139|      0|	}
  140|    114|	LOG_FUNC_RETURN(card->ctx, ret);
  ------------------
  |  |  164|    114|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    114|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    114|	int _ret = r; \
  |  |  |  |  155|    114|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 114, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    114|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  157|    114|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    114|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    114|	return _ret; \
  |  |  |  |  163|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|    114|}
card-rutoken.c:token_init:
  114|    114|{
  115|    114|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    114|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    114|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    114|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    114|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 114]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  116|       |
  117|    114|	card->name = card_name;
  118|    114|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    114|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  119|    114|	card->drv_data = calloc(1, sizeof(auth_senv_t));
  120|    114|	if (card->drv_data == NULL)
  ------------------
  |  Branch (120:6): [True: 0, False: 114]
  ------------------
  121|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  122|       |
  123|    114|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    114|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    114|	int _ret = r; \
  |  |  155|    114|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 114, False: 0]
  |  |  ------------------
  |  |  156|    114|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 114]
  |  |  ------------------
  |  |  157|    114|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    114|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    114|	return _ret; \
  |  |  163|    114|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  124|    114|}
card-rutoken.c:rutoken_finish:
   94|    114|{
   95|    114|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    114|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    114|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    114|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 114]
  |  |  ------------------
  ------------------
   96|    114|	if (!card->drv_data)
  ------------------
  |  Branch (96:6): [True: 0, False: 114]
  ------------------
   97|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   98|    114|	free(card->drv_data);
   99|    114|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    114|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    114|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    114|	int _ret = r; \
  |  |  |  |  155|    114|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 114, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    114|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  157|    114|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    114|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    114|	return _ret; \
  |  |  |  |  163|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  100|    114|}
card-rutoken.c:rutoken_select_file:
  363|    515|{
  364|    515|	sc_apdu_t apdu;
  365|    515|	u8 buf[SC_MAX_APDU_BUFFER_SIZE], pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  366|    515|	sc_file_t *file = NULL;
  367|    515|	size_t pathlen;
  368|    515|	int ret;
  369|       |
  370|    515|	if (!card || !card->ctx)
  ------------------
  |  Branch (370:6): [True: 0, False: 515]
  |  Branch (370:15): [True: 0, False: 515]
  ------------------
  371|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  372|    515|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    515|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    515|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    515|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 515]
  |  |  ------------------
  ------------------
  373|       |
  374|    515|	if (in_path == NULL || sizeof(pathbuf) < in_path->len)
  ------------------
  |  Branch (374:6): [True: 0, False: 515]
  |  Branch (374:25): [True: 0, False: 515]
  ------------------
  375|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  376|    515|	memcpy(path, in_path->value, in_path->len);
  377|    515|	pathlen = in_path->len;
  378|       |
  379|       |	/* p2 = 0; first record, return FCP */
  380|    515|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|    515|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  381|    515|	switch (in_path->type)
  382|    515|	{
  383|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (383:2): [True: 0, False: 515]
  ------------------
  384|      0|		if (pathlen != 2)
  ------------------
  |  Branch (384:7): [True: 0, False: 0]
  ------------------
  385|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|      0|		break;
  387|    308|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    308|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (387:2): [True: 308, False: 207]
  ------------------
  388|    308|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (388:7): [True: 308, False: 0]
  |  Branch (388:23): [True: 287, False: 21]
  ------------------
  389|    287|		{
  390|    287|			if (pathlen == 2)
  ------------------
  |  Branch (390:8): [True: 1, False: 286]
  ------------------
  391|      1|				break; /* only 3F00 supplied */
  392|    286|			path += 2;
  393|    286|			pathlen -= 2;
  394|    286|		}
  395|    307|		apdu.p1 = 0x08;
  396|    307|		break;
  397|    207|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    207|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (397:2): [True: 207, False: 308]
  ------------------
  398|    207|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    207|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (398:2): [True: 0, False: 515]
  ------------------
  399|    207|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    207|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (399:2): [True: 0, False: 515]
  ------------------
  400|    207|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    207|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    207|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    207|	int _ret = r; \
  |  |  |  |  155|    207|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    207|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    207|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    207|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    207|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    207|	return _ret; \
  |  |  |  |  163|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  401|      0|	default:
  ------------------
  |  Branch (401:2): [True: 0, False: 515]
  ------------------
  402|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  403|    515|	}
  404|    308|	swap_pair(path, pathlen);
  405|    308|	apdu.lc = pathlen;
  406|    308|	apdu.data = path;
  407|    308|	apdu.datalen = pathlen;
  408|       |
  409|    308|	apdu.resp = buf;
  410|    308|	apdu.resplen = sizeof(buf);
  411|    308|	apdu.le = 256;
  412|       |
  413|    308|	ret = sc_transmit_apdu(card, &apdu);
  414|    308|	LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
  ------------------
  |  |  174|    308|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    308|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    308|	int _ret = (r); \
  |  |  |  |  168|    308|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 300]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|    308|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|    300|	if (file_out == NULL)
  ------------------
  |  Branch (415:6): [True: 100, False: 200]
  ------------------
  416|    100|	{
  417|    100|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (417:7): [True: 0, False: 100]
  ------------------
  418|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 0);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  419|    100|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    100|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    100|	int _ret = r; \
  |  |  155|    100|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 100, False: 0]
  |  |  ------------------
  |  |  156|    100|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     82|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 82, False: 18]
  |  |  ------------------
  |  |  157|    100|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    100|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    100|	return _ret; \
  |  |  163|    100|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  420|    100|	}
  421|    200|	ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
  422|    200|	LOG_TEST_RET(card->ctx, ret, "");
  ------------------
  |  |  174|    200|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    200|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    200|	int _ret = (r); \
  |  |  |  |  168|    200|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 100, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  169|    100|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    100|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    100|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    100|		return _ret; \
  |  |  |  |  172|    100|	} \
  |  |  |  |  173|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  423|       |
  424|    100|	if (apdu.resplen > 0 && apdu.resp[0] != 0x62) /* Tag 0x62 - FCP */
  ------------------
  |  Branch (424:6): [True: 92, False: 8]
  |  Branch (424:26): [True: 7, False: 85]
  ------------------
  425|    100|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|       |
  427|     93|	file = sc_file_new();
  428|     93|	if (file == NULL)
  ------------------
  |  Branch (428:6): [True: 0, False: 93]
  ------------------
  429|     93|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  430|     93|	file->path = *in_path;
  431|     93|	if (card->ops->process_fci == NULL)
  ------------------
  |  Branch (431:6): [True: 0, False: 93]
  ------------------
  432|      0|	{
  433|      0|		sc_file_free(file);
  434|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  435|      0|	}
  436|     93|	if (apdu.resplen > 1  &&  apdu.resplen >= (size_t)apdu.resp[1] + 2)
  ------------------
  |  Branch (436:6): [True: 84, False: 9]
  |  Branch (436:28): [True: 80, False: 4]
  ------------------
  437|     80|	{
  438|     80|		ret = card->ops->process_fci(card, file, apdu.resp+2, apdu.resp[1]);
  439|     80|	}
  440|     93|	if (file->sec_attr && file->sec_attr_len == sizeof(sc_SecAttrV2_t))
  ------------------
  |  Branch (440:6): [True: 71, False: 22]
  |  Branch (440:24): [True: 66, False: 5]
  ------------------
  441|     66|		set_acl_from_sec_attr(card, file);
  442|     27|	else
  443|     27|		ret = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     27|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  444|     93|	if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     93|#define SC_SUCCESS				0
  ------------------
  |  Branch (444:6): [True: 27, False: 66]
  ------------------
  445|     27|		sc_file_free(file);
  446|     66|	else
  447|     66|	{
  448|     66|		*file_out = file;
  449|     66|	}
  450|     93|	LOG_FUNC_RETURN(card->ctx, ret);
  ------------------
  |  |  164|     93|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     93|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     93|	int _ret = r; \
  |  |  |  |  155|     93|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 66]
  |  |  |  |  ------------------
  |  |  |  |  157|     93|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     93|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     93|	return _ret; \
  |  |  |  |  163|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  451|     93|}
card-rutoken.c:swap_pair:
  216|    308|{
  217|    308|	size_t i;
  218|    308|	u8 tmp;
  219|       |
  220|    666|	for (i = 0; i + 1 < len; i += 2)
  ------------------
  |  Branch (220:14): [True: 358, False: 308]
  ------------------
  221|    358|	{
  222|    358|		tmp = buf[i];
  223|    358|		buf[i] = buf[i + 1];
  224|    358|		buf[i + 1] = tmp;
  225|    358|	}
  226|    308|}
card-rutoken.c:set_acl_from_sec_attr:
  311|     66|{
  312|     66|	if (file->sec_attr  &&  file->sec_attr_len == sizeof(sc_SecAttrV2_t))
  ------------------
  |  Branch (312:6): [True: 66, False: 0]
  |  Branch (312:26): [True: 66, False: 0]
  ------------------
  313|     66|	{
  314|     66|		sc_file_add_acl_entry(file, SC_AC_OP_SELECT,
  ------------------
  |  |  166|     66|#define SC_AC_OP_SELECT			0
  ------------------
  315|     66|				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     66|#define SC_AC_NONE			0x00000000
  ------------------
              				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     66|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  316|     66|		if (file->sec_attr[0] & 0x40) /* if AccessMode.6 */
  ------------------
  |  Branch (316:7): [True: 17, False: 49]
  ------------------
  317|     17|		{
  318|     17|			sc_log(card->ctx,  "SC_AC_OP_DELETE %i %i",
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  319|     17|					(int)(*(int8_t*)&file->sec_attr[1 +6]),
  320|     17|					file->sec_attr[1+7 +6*4]);
  321|     17|			sc_file_add_acl_entry(file, SC_AC_OP_DELETE,
  ------------------
  |  |  168|     17|#define SC_AC_OP_DELETE			2
  ------------------
  322|     17|					(int)(*(int8_t*)&file->sec_attr[1 +6]),
  323|     17|					file->sec_attr[1+7 +6*4]);
  324|     17|		}
  325|     66|		if (file->sec_attr[0] & 0x01) /* if AccessMode.0 */
  ------------------
  |  Branch (325:7): [True: 18, False: 48]
  ------------------
  326|     18|		{
  327|     18|			sc_log(card->ctx,  (file->type == SC_FILE_TYPE_DF) ?
  ------------------
  |  |   71|     36|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:110): [True: 1, False: 17]
  |  |  ------------------
  ------------------
  328|     18|					"SC_AC_OP_CREATE %i %i" : "SC_AC_OP_READ %i %i",
  329|     18|					(int)(*(int8_t*)&file->sec_attr[1 +0]),
  330|     18|					file->sec_attr[1+7 +0*4]);
  331|     18|			sc_file_add_acl_entry(file,
  332|     18|					(file->type == SC_FILE_TYPE_DF) ?
  ------------------
  |  |  214|     18|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (332:6): [True: 1, False: 17]
  ------------------
  333|     17|					SC_AC_OP_CREATE : SC_AC_OP_READ,
  ------------------
  |  |  169|      1|#define SC_AC_OP_CREATE			3
  ------------------
              					SC_AC_OP_CREATE : SC_AC_OP_READ,
  ------------------
  |  |  188|     35|#define SC_AC_OP_READ			22
  ------------------
  334|     18|					(int)(*(int8_t*)&file->sec_attr[1 +0]),
  335|     18|					file->sec_attr[1+7 +0*4]);
  336|     18|		}
  337|     66|		if (file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|     66|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (337:7): [True: 1, False: 65]
  ------------------
  338|      1|		{
  339|      1|			sc_file_add_acl_entry(file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|      1|#define SC_AC_OP_LIST_FILES		6
  ------------------
  340|      1|					SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|      1|#define SC_AC_NONE			0x00000000
  ------------------
              					SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|      1|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  341|      1|		}
  342|     65|		else
  343|     65|			if (file->sec_attr[0] & 0x02) /* if AccessMode.1 */
  ------------------
  |  Branch (343:8): [True: 39, False: 26]
  ------------------
  344|     39|			{
  345|     39|				sc_log(card->ctx,  "SC_AC_OP_UPDATE %i %i",
  ------------------
  |  |   71|     39|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  346|     39|						(int)(*(int8_t*)&file->sec_attr[1 +1]),
  347|     39|						file->sec_attr[1+7 +1*4]);
  348|     39|				sc_file_add_acl_entry(file, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|     39|#define SC_AC_OP_UPDATE			23
  ------------------
  349|     39|						(int)(*(int8_t*)&file->sec_attr[1 +1]),
  350|     39|						file->sec_attr[1+7 +1*4]);
  351|     39|				sc_log(card->ctx,  "SC_AC_OP_WRITE %i %i",
  ------------------
  |  |   71|     39|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  352|     39|						(int)(*(int8_t*)&file->sec_attr[1 +1]),
  353|     39|						file->sec_attr[1+7 +1*4]);
  354|     39|				sc_file_add_acl_entry(file, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     39|#define SC_AC_OP_WRITE			24
  ------------------
  355|     39|						(int)(*(int8_t*)&file->sec_attr[1 +1]),
  356|     39|						file->sec_attr[1+7 +1*4]);
  357|     39|			}
  358|     66|	}
  359|     66|}
card-rutoken.c:rutoken_check_sw:
  200|    592|{
  201|    592|	size_t i;
  202|       |
  203|  22.4k|	for (i = 0; i < sizeof(rutoken_errors)/sizeof(rutoken_errors[0]); ++i) {
  ------------------
  |  Branch (203:14): [True: 22.3k, False: 37]
  ------------------
  204|  22.3k|		if (rutoken_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (204:7): [True: 555, False: 21.8k]
  ------------------
  205|    555|			if ( rutoken_errors[i].errorstr )
  ------------------
  |  Branch (205:9): [True: 184, False: 371]
  ------------------
  206|    184|				sc_log(card->ctx,  "%s\n", rutoken_errors[i].errorstr);
  ------------------
  |  |   71|    184|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  207|    555|			sc_log(card->ctx,  "sw1 = %x, sw2 = %x", sw1, sw2);
  ------------------
  |  |   71|    555|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  208|    555|			return rutoken_errors[i].errorno;
  209|    555|		}
  210|  22.3k|	}
  211|     37|	sc_log(card->ctx,  "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  212|     37|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     37|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  213|    592|}
card-rutoken.c:rutoken_process_fci:
  455|     80|{
  456|     80|	size_t taglen;
  457|     80|	int ret;
  458|     80|	const unsigned char *tag;
  459|       |
  460|     80|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     80|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     80|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     80|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 80]
  |  |  ------------------
  ------------------
  461|     80|	ret = iso_ops->process_fci(card, file, buf, buflen);
  462|     80|	if (ret == SC_SUCCESS)
  ------------------
  |  |   28|     80|#define SC_SUCCESS				0
  ------------------
  |  Branch (462:6): [True: 80, False: 0]
  ------------------
  463|     80|	{
  464|       |		/* Rutoken S returns buffers in little-endian. */
  465|       |		/* Set correct file id. */
  466|     80|		file->id = ((file->id & 0xFF) << 8) | ((file->id >> 8) & 0xFF);
  467|     80|		sc_log(card->ctx,  "  file identifier: 0x%04X", file->id);
  ------------------
  |  |   71|     80|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  468|       |		/* Determine file size. */
  469|     80|		tag = sc_asn1_find_tag(card->ctx, buf, buflen, 0x80, &taglen);
  470|       |		/* Rutoken S always returns 2 bytes. */
  471|     80|		if (tag != NULL && taglen == 2)
  ------------------
  |  Branch (471:7): [True: 45, False: 35]
  |  Branch (471:22): [True: 40, False: 5]
  ------------------
  472|     40|		{
  473|     40|			file->size = (tag[1] << 8) | tag[0];
  474|     40|			sc_log(card->ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  475|     40|		}
  476|     80|	}
  477|     80|	LOG_FUNC_RETURN(card->ctx, ret);
  ------------------
  |  |  164|     80|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     80|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     80|	int _ret = r; \
  |  |  |  |  155|     80|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 80, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     80|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 80]
  |  |  |  |  ------------------
  |  |  |  |  157|     80|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     80|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     80|	return _ret; \
  |  |  |  |  163|     80|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|     80|}

sc_get_sc_hsm_driver:
 2003|  15.2k|{
 2004|  15.2k|	return sc_get_driver();
 2005|  15.2k|}
card-sc-hsm.c:sc_get_driver:
 1967|  15.2k|{
 1968|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1969|       |
 1970|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1970:6): [True: 1, False: 15.2k]
  ------------------
 1971|      1|		iso_ops = iso_drv->ops;
 1972|       |
 1973|  15.2k|	sc_hsm_ops                   = *iso_drv->ops;
 1974|  15.2k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1975|  15.2k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1976|  15.2k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1977|  15.2k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1978|  15.2k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1979|  15.2k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1980|  15.2k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1981|  15.2k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1982|  15.2k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1983|  15.2k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1984|  15.2k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1985|  15.2k|	sc_hsm_ops.init              = sc_hsm_init;
 1986|  15.2k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1987|  15.2k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1988|  15.2k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1989|  15.2k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1990|       |
 1991|       |	/* no record oriented file services */
 1992|  15.2k|	sc_hsm_ops.read_record       = NULL;
 1993|  15.2k|	sc_hsm_ops.write_record      = NULL;
 1994|  15.2k|	sc_hsm_ops.append_record     = NULL;
 1995|  15.2k|	sc_hsm_ops.update_record     = NULL;
 1996|       |
 1997|  15.2k|	return &sc_hsm_drv;
 1998|  15.2k|}
card-sc-hsm.c:sc_hsm_match_card:
  267|  6.18k|{
  268|  6.18k|	sc_path_t path;
  269|  6.18k|	int i, r, type = 0;
  270|  6.18k|	sc_file_t *file = NULL;
  271|       |
  272|  6.18k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  273|  6.18k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (273:6): [True: 120, False: 6.06k]
  |  Branch (273:16): [True: 119, False: 1]
  ------------------
  274|    119|		card->type = type;
  275|    119|		return 1;
  276|    119|	}
  277|       |
  278|  6.06k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  6.06k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  279|  6.06k|	r = sc_hsm_select_file(card, &path, &file);
  280|  6.06k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.06k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.06k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.06k|	int _ret = (r); \
  |  |  |  |  168|  6.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.76k, False: 304]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.76k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.76k|		return _ret; \
  |  |  |  |  172|  5.76k|	} \
  |  |  |  |  173|  6.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 304]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|       |
  282|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  283|    304|	if (file != NULL) {
  ------------------
  |  Branch (283:6): [True: 304, False: 0]
  ------------------
  284|    304|		size_t sz = file->prop_attr_len;
  285|    304|		sc_file_free(file);
  286|    304|		if (sz < 2) {
  ------------------
  |  Branch (286:7): [True: 302, False: 2]
  ------------------
  287|    302|			return 0;
  288|    302|		}
  289|    304|	}
  290|       |
  291|      2|	if (type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (291:6): [True: 0, False: 2]
  ------------------
  292|      0|		card->type = SC_CARD_TYPE_SC_HSM_SOC;
  293|      2|	} else {
  294|      2|		card->type = SC_CARD_TYPE_SC_HSM;
  295|      2|	}
  296|       |
  297|      2|	return 1;
  298|    304|}
card-sc-hsm.c:sc_hsm_select_file:
  247|  6.70k|{
  248|  6.70k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  249|  6.70k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  149|  7.12k|{
  150|  7.12k|	int rv;
  151|  7.12k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  152|  7.12k|	sc_file_t *file = NULL;
  153|  7.12k|	sc_path_t cpath;
  154|  7.12k|	size_t card_max_recv_size = card->max_recv_size;
  155|  7.12k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  156|       |
  157|  7.12k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (157:6): [True: 302, False: 6.82k]
  ------------------
  158|    302|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  159|    302|		sc_file_free(file);
  160|    302|		return rv;
  161|    302|	}
  162|       |
  163|  6.82k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  6.82k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (163:6): [True: 75, False: 6.75k]
  |  Branch (163:49): [True: 0, False: 75]
  ------------------
  164|       |		// Split applet selection and file selection into two separate calls
  165|      0|		cpath = *in_path;
  166|      0|		cpath.len = 0;
  167|      0|		cpath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  168|      0|		rv = sc_hsm_select_file_ex(card, &cpath, forceselect, NULL);
  169|      0|		LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|       |
  171|      0|		if (in_path->len) {
  ------------------
  |  Branch (171:7): [True: 0, False: 0]
  ------------------
  172|      0|			cpath = *in_path;
  173|      0|			cpath.aid.len = 0;
  174|      0|			rv = sc_hsm_select_file_ex(card, &cpath, forceselect, file_out);
  175|      0|		}
  176|      0|		return rv;
  177|      0|	}
  178|       |
  179|       |	// Prevent selection of applet unless this is the first time, selection is forced or the device is not authenticated
  180|  6.82k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  13.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (180:6): [True: 6.43k, False: 390]
  ------------------
  181|    390|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    780|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (181:8): [True: 315, False: 75]
  ------------------
  182|    315|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (182:8): [True: 0, False: 315]
  ------------------
  183|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (183:8): [True: 0, False: 0]
  ------------------
  184|    390|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    780|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:8): [True: 315, False: 75]
  ------------------
  185|    315|				&& in_path->len == 0
  ------------------
  |  Branch (185:8): [True: 0, False: 315]
  ------------------
  186|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  6.43k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (187:8): [True: 0, False: 0]
  ------------------
  188|  6.43k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (188:7): [True: 6.06k, False: 370]
  |  Branch (188:16): [True: 270, False: 100]
  |  Branch (188:41): [True: 0, False: 100]
  ------------------
  189|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  190|  6.33k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|  6.33k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  191|  6.33k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  192|  6.33k|			card->max_recv_size = card_max_recv_size;
  193|  6.33k|			card->reader->max_recv_size = reader_max_recv_size;
  194|  6.33k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.33k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.33k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.33k|	int _ret = (r); \
  |  |  |  |  168|  6.33k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.94k, False: 392]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.94k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.94k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.94k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.94k|		return _ret; \
  |  |  |  |  172|  5.94k|	} \
  |  |  |  |  173|  6.33k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 392]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    392|			if (priv) {
  ------------------
  |  Branch (196:8): [True: 88, False: 304]
  ------------------
  197|     88|				sc_file_free(priv->dffcp);
  198|       |				// Cache the FCP returned when selecting the applet
  199|     88|				sc_file_dup(&priv->dffcp, *file_out);
  200|     88|			}
  201|    392|		} else {
  202|    100|			sc_file_dup(file_out, priv->dffcp);
  203|    100|			rv = SC_SUCCESS;
  ------------------
  |  |   28|    100|#define SC_SUCCESS				0
  ------------------
  204|    100|		}
  205|    492|		return rv;
  206|  6.43k|	}
  207|       |
  208|    390|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (208:6): [True: 390, False: 0]
  |  Branch (208:29): [True: 258, False: 132]
  |  Branch (208:60): [True: 249, False: 9]
  ------------------
  209|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  210|    249|		if (in_path->len == 2) {
  ------------------
  |  Branch (210:7): [True: 0, False: 249]
  ------------------
  211|      0|			file = sc_file_new();
  212|      0|			if (file == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 0]
  ------------------
  213|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|      0|			file->path = *in_path;
  215|      0|			file->id = 0x3F00;
  216|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  217|      0|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  218|       |
  219|      0|			*file_out = file;
  220|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  221|    249|		} else {
  222|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  223|    249|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    249|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  224|    249|			sc_path_t truncated;
  225|    249|			memcpy(&truncated, in_path, sizeof truncated);
  226|    249|			truncated.len = in_path->len - 2;
  227|    249|			memcpy(truncated.value, in_path->value+2, truncated.len);
  228|    249|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  229|    249|			card->max_recv_size = card_max_recv_size;
  230|    249|			card->reader->max_recv_size = reader_max_recv_size;
  231|    249|			return rv;
  232|    249|		}
  233|    249|	}
  234|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  235|    141|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    141|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  236|    141|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  237|    141|	card->max_recv_size = card_max_recv_size;
  238|    141|	card->reader->max_recv_size = reader_max_recv_size;
  239|    141|	return rv;
  240|    390|}
card-sc-hsm.c:sc_hsm_read_binary:
  799|    510|{
  800|    510|	sc_context_t *ctx = card->ctx;
  801|    510|	sc_apdu_t apdu;
  802|    510|	u8 cmdbuff[4];
  803|    510|	int r;
  804|       |
  805|    510|	if (idx > 0xffff) {
  ------------------
  |  Branch (805:6): [True: 0, False: 510]
  ------------------
  806|      0|		sc_log(ctx,  "invalid EF offset: 0x%X > 0xFFFF", idx);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  807|      0|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  808|      0|	}
  809|       |
  810|    510|	cmdbuff[0] = 0x54;
  811|    510|	cmdbuff[1] = 0x02;
  812|    510|	cmdbuff[2] = (idx >> 8) & 0xFF;
  813|    510|	cmdbuff[3] = idx & 0xFF;
  814|       |
  815|    510|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (815:6): [True: 0, False: 510]
  ------------------
  816|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  817|    510|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    510|#define SC_APDU_CASE_4			0x24
  ------------------
  818|    510|	apdu.data = cmdbuff;
  819|    510|	apdu.datalen = 4;
  820|    510|	apdu.lc = 4;
  821|    510|	apdu.le = count;
  822|    510|	apdu.resplen = count;
  823|    510|	apdu.resp = buf;
  824|       |
  825|    510|	r = sc_transmit_apdu(card, &apdu);
  826|    510|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    510|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    510|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    510|	int _ret = (r); \
  |  |  |  |  168|    510|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 500]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    510|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 500]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    500|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  829|    500|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    500|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (829:6): [True: 305, False: 195]
  ------------------
  830|    305|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    305|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    305|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    305|	int _ret = (r); \
  |  |  |  |  168|    305|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 59, False: 246]
  |  |  |  |  ------------------
  |  |  |  |  169|     59|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     59|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     59|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     59|		return _ret; \
  |  |  |  |  172|     59|	} \
  |  |  |  |  173|    305|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 246]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|    305|	}
  832|       |
  833|    441|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    441|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    441|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    441|	int _ret = r; \
  |  |  |  |  155|    441|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19, False: 422]
  |  |  |  |  ------------------
  |  |  |  |  156|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  157|     19|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    422|	} else { \
  |  |  |  |  159|    422|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    422|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    422|	} \
  |  |  |  |  162|    441|	return _ret; \
  |  |  |  |  163|    441|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    441|}
card-sc-hsm.c:sc_hsm_init:
 1802|    121|{
 1803|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1804|       |	char expanded_val[PATH_MAX];
 1805|       |	size_t expanded_len = PATH_MAX;
 1806|       |#endif
 1807|    121|	int flags,ext_flags;
 1808|    121|	sc_file_t *file = NULL;
 1809|    121|	sc_path_t path;
 1810|    121|	sc_hsm_private_data_t *priv = NULL;
 1811|       |
 1812|    121|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    121|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    121|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    121|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    121|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 121]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1813|       |
 1814|    121|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    121|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  107|    121|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|    121|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1815|    121|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  134|    121|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  138|    121|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  139|    121|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  140|    121|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1816|    121|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  146|    121|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  147|    121|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  148|    121|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1817|       |
 1818|    121|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1819|    121|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1820|    121|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1821|    121|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1822|    121|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1823|       |
 1824|    121|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|    121|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1825|    121|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|    121|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1826|    121|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|    121|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    121|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1827|    121|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  176|    121|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    121|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1828|    121|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  177|    121|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|    121|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1829|    121|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  178|    121|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    121|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1830|    121|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  179|    121|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|    121|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1831|    121|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  180|    121|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|    121|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1832|    121|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    121|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1833|       |
 1834|    121|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  198|    121|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1835|    121|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  200|    121|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1836|    121|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  201|    121|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1837|    121|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  202|    121|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1838|    121|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    121|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1839|    121|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1840|    121|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1841|    121|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1842|    121|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1843|    121|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1844|    121|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1845|    121|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1846|       |
 1847|    121|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    121|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|    121|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    121|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1848|       |
 1849|       |	// APDU Size limits
 1850|       |	//   JCOP 2.4.1r3           1462
 1851|       |	//   JCOP 2.4.2r3           1454
 1852|       |	//   JCOP 3                 1232
 1853|       |	//   JCOP 4                 1454
 1854|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1855|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1856|       |	//
 1857|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1858|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1859|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1860|       |	// class 3 APDU
 1861|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1862|       |
 1863|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1864|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1865|    121|	card->max_send_size = 1232 - 9;
 1866|       |	// Assume that card supports sending with extended length APDU and without limit
 1867|    121|	card->max_recv_size = 0;
 1868|       |
 1869|    121|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1869:6): [True: 0, False: 121]
  ------------------
 1870|    121|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1870:7): [True: 119, False: 2]
  ------------------
 1871|    119|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1872|    119|	} else {
 1873|       |		// Adjust to the limits set by the reader
 1874|      2|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1874:7): [True: 2, False: 0]
  ------------------
 1875|      2|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1875:8): [True: 2, False: 0]
  ------------------
 1876|      2|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1877|       |
 1878|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1879|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1880|      0|		}
 1881|       |
 1882|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1882:7): [True: 0, False: 0]
  ------------------
 1883|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1883:8): [True: 0, False: 0]
  ------------------
 1884|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1885|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1886|      0|		}
 1887|      0|	}
 1888|       |
 1889|    119|	priv = card->drv_data;
 1890|    119|	if (!priv) {
  ------------------
  |  Branch (1890:6): [True: 119, False: 0]
  ------------------
 1891|    119|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1892|    119|		if (!priv)
  ------------------
  |  Branch (1892:7): [True: 0, False: 119]
  ------------------
 1893|    119|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1894|    119|		card->drv_data = priv;
 1895|    119|	}
 1896|       |
 1897|    119|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    119|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1898|    119|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    238|#define SC_SUCCESS				0
  ------------------
  |  Branch (1898:6): [True: 57, False: 62]
  ------------------
 1899|     57|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1899:7): [True: 57, False: 0]
  |  Branch (1899:15): [True: 5, False: 52]
  |  Branch (1899:34): [True: 4, False: 1]
  ------------------
 1900|      4|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1901|      4|		u8 type = 0xFF;
 1902|      4|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1903|      4|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1904|      4|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1905|      4|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1906|      4|		char *p = "SmartCard-HSM";
 1907|      4|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1907:7): [True: 3, False: 1]
  ------------------
 1908|      3|			type = file->prop_attr[file->prop_attr_len - 3];
 1909|      3|		}
 1910|      4|		switch (type) {
 1911|      1|			case 0x00:
  ------------------
  |  Branch (1911:4): [True: 1, False: 3]
  ------------------
 1912|      1|				p = p00;
 1913|      1|				break;
 1914|      1|			case 0x01:
  ------------------
  |  Branch (1914:4): [True: 1, False: 3]
  ------------------
 1915|      1|				p = p01;
 1916|      1|				break;
 1917|      2|			default:
  ------------------
  |  Branch (1917:4): [True: 2, False: 2]
  ------------------
 1918|      2|				break;
 1919|      4|		}
 1920|      4|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1921|      4|		card->name = card_name;
 1922|       |
 1923|      4|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1923:7): [True: 2, False: 2]
  ------------------
 1924|      2|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  563|      2|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1925|      2|		}
 1926|      4|	}
 1927|    119|	sc_file_free(file);
 1928|       |
 1929|    119|	priv->EF_C_DevAut = NULL;
 1930|    119|	priv->EF_C_DevAut_len = 0;
 1931|       |
 1932|    119|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1933|    119|	EAC_init();
 1934|       |#ifdef _WIN32
 1935|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1936|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1937|       |		EAC_set_cvc_default_dir(expanded_val);
 1938|       |#else
 1939|    119|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    119|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1940|    119|#endif
 1941|    119|#endif
 1942|       |
 1943|    119|	return 0;
 1944|    119|}
card-sc-hsm.c:sc_hsm_finish:
 1949|    119|{
 1950|    119|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1951|    119|#ifdef ENABLE_SM
 1952|    119|	sc_sm_stop(card);
 1953|    119|#endif
 1954|    119|	if (priv) {
  ------------------
  |  Branch (1954:6): [True: 119, False: 0]
  ------------------
 1955|    119|		free(priv->serialno);
 1956|    119|		sc_file_free(priv->dffcp);
 1957|    119|		free(priv->EF_C_DevAut);
 1958|    119|	}
 1959|    119|	free(priv);
 1960|       |
 1961|    119|	return SC_SUCCESS;
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
 1962|    119|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1773|     18|{
 1774|     18|	switch (cmd) {
  ------------------
  |  Branch (1774:10): [True: 18, False: 0]
  ------------------
 1775|     18|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1775:2): [True: 18, False: 0]
  ------------------
 1776|     18|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1777|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1777:2): [True: 0, False: 18]
  ------------------
 1778|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1779|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1779:2): [True: 0, False: 18]
  ------------------
 1780|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1781|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1781:2): [True: 0, False: 18]
  ------------------
 1782|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1783|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1783:2): [True: 0, False: 18]
  ------------------
 1784|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1785|      0|	case SC_CARDCTL_SC_HSM_MANAGE_KEY_DOMAIN:
  ------------------
  |  Branch (1785:2): [True: 0, False: 18]
  ------------------
 1786|      0|		return sc_hsm_manage_key_domain(card, (sc_cardctl_sc_hsm_key_domain_t *)ptr);
 1787|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1787:2): [True: 0, False: 18]
  ------------------
 1788|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1789|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1789:2): [True: 0, False: 18]
  ------------------
 1790|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1791|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1791:2): [True: 0, False: 18]
  ------------------
 1792|      0|		return sc_hsm_register_public_key(card, ptr);
 1793|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1793:2): [True: 0, False: 18]
  ------------------
 1794|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1795|     18|	}
 1796|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1797|     18|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1195|     18|{
 1196|     18|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1197|       |
 1198|     18|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     18|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     18|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     18|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     18|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|       |
 1200|     18|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1200:6): [True: 18, False: 0]
  |  Branch (1200:25): [True: 0, False: 18]
  ------------------
 1201|       |		/* sc-hsm initializes the serial number via its PKCS#15 layer.
 1202|       |		 * Create and destroy a dummy card to get this initialized.  Only do
 1203|       |		 * this for `opensc-tool --serial` to avoid unnecessary card commands
 1204|       |		 * in all other cases. */
 1205|      0|		sc_pkcs15_card_t *p15card = NULL;
 1206|      0|		(void)sc_pkcs15_bind(card, NULL, &p15card);
 1207|      0|		sc_pkcs15_unbind(p15card);
 1208|      0|	}
 1209|       |
 1210|     18|	if (!priv->serialno) {
  ------------------
  |  Branch (1210:6): [True: 18, False: 0]
  ------------------
 1211|     18|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|     18|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1212|     18|	}
 1213|       |
 1214|      0|	serial->len = strlen(priv->serialno);
 1215|      0|	if (serial->len > sizeof(serial->value))
  ------------------
  |  Branch (1215:6): [True: 0, False: 0]
  ------------------
 1216|      0|		serial->len = sizeof(serial->value);
 1217|       |
 1218|      0|	memcpy(serial->value, priv->serialno, serial->len);
 1219|       |
 1220|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1221|      0|}
card-sc-hsm.c:sc_hsm_pin_cmd:
  620|     26|{
  621|     26|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|     26|	sc_apdu_t apdu;
  623|     26|	u8 cmdbuff[16];
  624|     26|#ifdef ENABLE_SM
  625|     26|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|     26|#endif
  627|     26|	int r;
  628|     26|	int cmd = data->cmd;
  629|     26|	size_t pin2_len = data->pin2.len;
  630|       |
  631|     26|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|     26|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 26]
  ------------------
  632|       |		/* First, perform a standard VERIFY */
  633|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  634|       |		/* we assign pin2.len to 0 early on so that in case of an error we are
  635|       |		 * not exiting with an undefined session PIN */
  636|      0|		data->pin2.len = 0;
  637|      0|	}
  638|       |
  639|     26|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     26|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 26]
  ------------------
  640|      0|		   	&& (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (640:10): [True: 0, False: 0]
  ------------------
  641|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (641:10): [True: 0, False: 0]
  ------------------
  642|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (642:8): [True: 0, False: 0]
  |  Branch (642:28): [True: 0, False: 0]
  ------------------
  643|      0|		return sc_hsm_soc_change(card, data);
  644|     26|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     26|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 26]
  ------------------
  645|      0|		   	&& (data->cmd == SC_PIN_CMD_UNBLOCK)
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (645:10): [True: 0, False: 0]
  ------------------
  646|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (646:10): [True: 0, False: 0]
  ------------------
  647|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (647:8): [True: 0, False: 0]
  |  Branch (647:28): [True: 0, False: 0]
  ------------------
  648|      0|		return sc_hsm_soc_unblock(card, data);
  649|      0|	}
  650|       |
  651|     26|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|     26|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 26]
  ------------------
  655|     26|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 26, False: 0]
  ------------------
  656|      0|				|| card->reader->uid.len || cmd == SC_PIN_CMD_GET_SESSION_PIN)
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (656:8): [True: 0, False: 0]
  |  Branch (656:33): [True: 0, False: 0]
  ------------------
  657|     26|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  418|     26|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 8, False: 18]
  ------------------
  658|      8|		struct sc_pin_cmd_data check_sm_pin_data;
  659|      8|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|      8|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      8|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|      8|		check_sm_pin_data.pin_type = data->pin_type;
  662|      8|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|      8|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|      8|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|      8|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      8|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 8]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  668|      0|		}
  669|      8|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|     16|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|      8|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 8]
  |  Branch (669:46): [True: 8, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|      8|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|      8|					sc_hsm_perform_chip_authentication(card),
  673|      8|					"Could not perform chip authentication");
  674|      8|		}
  675|      8|	}
  676|     18|#endif
  677|       |
  678|     18|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     18|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 18]
  ------------------
  679|      0|			&& (data->cmd == SC_PIN_CMD_VERIFY)
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (679:7): [True: 0, False: 0]
  ------------------
  680|      0|			&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (680:7): [True: 0, False: 0]
  ------------------
  681|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (681:8): [True: 0, False: 0]
  |  Branch (681:28): [True: 0, False: 0]
  ------------------
  682|      0|		r = sc_hsm_soc_biomatch(card, data);
  683|     18|	} else {
  684|     18|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  415|     18|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 18]
  |  Branch (684:43): [True: 0, False: 0]
  ------------------
  685|      0|			if (data->pin1.len != 16)
  ------------------
  |  Branch (685:8): [True: 0, False: 0]
  ------------------
  686|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  687|       |
  688|       |			// Save SO PIN for later use in sc_hsm_init_pin()
  689|      0|			r = sc_hsm_encode_sopin(data->pin1.data, priv->sopin);
  690|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|       |
  692|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  693|      0|		}
  694|       |
  695|     18|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  416|     18|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 18]
  |  Branch (695:43): [True: 0, False: 0]
  ------------------
  696|      0|			if ((data->pin1.len != 16) || (data->pin2.len != 16))
  ------------------
  |  Branch (696:8): [True: 0, False: 0]
  |  Branch (696:34): [True: 0, False: 0]
  ------------------
  697|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  698|       |
  699|      0|			r = sc_hsm_encode_sopin(data->pin1.data, cmdbuff);
  700|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  701|       |
  702|      0|			r = sc_hsm_encode_sopin(data->pin2.data, cmdbuff + 8);
  703|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  704|       |
  705|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 0x00, data->pin_reference);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  706|      0|			apdu.data = cmdbuff;
  707|      0|			apdu.datalen = sizeof(cmdbuff);
  708|      0|			apdu.lc = 16;
  709|      0|			apdu.resplen = 0;
  710|      0|			data->apdu = &apdu;
  711|      0|		}
  712|       |
  713|     18|#ifdef ENABLE_SM
  714|     18|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     18|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 18, False: 0]
  ------------------
  715|     18|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|     18|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 18]
  ------------------
  716|       |			/* JCOP's SM accelerator is incapable of using case 1 APDU in SM */
  717|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x20, 0x00, data->pin_reference);
  ------------------
  |  |  301|      0|#define SC_APDU_CASE_2			0x22
  ------------------
  718|      0|			apdu.resp = rbuf;
  719|      0|			apdu.resplen = sizeof rbuf;
  720|      0|			data->apdu = &apdu;
  721|      0|		}
  722|     18|#endif
  723|       |
  724|     18|		data->pin1.offset = 5;
  725|     18|		data->pin2.offset = 5;
  726|       |
  727|     18|		r = (*iso_ops->pin_cmd)(card, data);
  728|     18|		data->apdu = NULL;
  729|     18|	}
  730|     18|	LOG_TEST_RET(card->ctx, r, "Verification failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|     10|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|     10|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (732:6): [True: 0, False: 10]
  ------------------
  733|       |		/* reset data->cmd to its original value */
  734|      0|		data->cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  735|      0|		if (data->pin_reference == 0x81) {
  ------------------
  |  Branch (735:7): [True: 0, False: 0]
  ------------------
  736|      0|			u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  737|      0|#ifdef ENABLE_SM
  738|      0|			if (card->sm_ctx.sm_mode != SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (738:8): [True: 0, False: 0]
  ------------------
  739|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  740|      0|						"Session PIN generation only supported in SM");
  741|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|      0|			}
  743|       |#else
  744|       |			sc_log(card->ctx,
  745|       |					"Session PIN generation only supported in SM");
  746|       |			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  747|       |#endif
  748|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x5A, 0x01, data->pin_reference);
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  749|      0|			apdu.cla = 0x80;
  750|      0|			apdu.resp = recvbuf;
  751|      0|			apdu.resplen = sizeof recvbuf;
  752|      0|			apdu.le = 0;
  753|      0|			if (sc_transmit_apdu(card, &apdu) != SC_SUCCESS
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (753:8): [True: 0, False: 0]
  ------------------
  754|      0|					|| sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (754:9): [True: 0, False: 0]
  ------------------
  755|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  756|      0|						"Generating session PIN failed");
  757|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|      0|			}
  759|      0|			if (data->pin2.data && pin2_len > 0) {
  ------------------
  |  Branch (759:8): [True: 0, False: 0]
  |  Branch (759:27): [True: 0, False: 0]
  ------------------
  760|      0|				if (pin2_len >= apdu.resplen) {
  ------------------
  |  Branch (760:9): [True: 0, False: 0]
  ------------------
  761|      0|					memcpy((unsigned char *) data->pin2.data, apdu.resp,
  762|      0|							apdu.resplen);
  763|      0|					data->pin2.len = apdu.resplen;
  764|      0|				} else {
  765|      0|					sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  766|      0|							"Buffer too small for session PIN");
  767|      0|				}
  768|      0|			}
  769|      0|		} else {
  770|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  771|      0|					"Session PIN not supported for this PIN (0x%02X)",
  772|      0|					data->pin_reference);
  773|      0|		}
  774|      0|	}
  775|     10|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|     10|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  492|      8|{
  493|      8|	int r, protocol;
  494|      8|	sc_path_t path;
  495|      8|	u8 all_certs[1024];
  496|      8|	EAC_CTX *ctx = NULL;
  497|      8|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  498|      8|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  499|      8|	BUF_MEM *comp_pub_key = NULL;
  500|      8|	sc_cvc_t cvc_device, cvc_issuer;
  501|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  502|      8|	sc_pkcs15_card_t p15card;
  503|      8|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  504|       |	/* we know that sc_pkcs15emu_sc_hsm_decode_cvc does not require anything
  505|       |	 * else to be initialized than p15card->card */
  506|      8|	p15card.card = card;
  507|       |
  508|      8|	memset(&cvc_device, 0, sizeof(cvc_device));
  509|      8|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  510|       |
  511|       |
  512|      8|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (512:6): [True: 0, False: 8]
  |  Branch (512:27): [True: 0, False: 0]
  ------------------
  513|      0|		all_certs_len = priv->EF_C_DevAut_len;
  514|      0|		cert = priv->EF_C_DevAut;
  515|      8|	} else {
  516|       |		/* get issuer and device certificate from the card */
  517|      8|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|      8|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  518|      8|		if (r < 0)
  ------------------
  |  Branch (518:7): [True: 0, False: 8]
  ------------------
  519|      0|			goto err;
  520|      8|		r = sc_select_file(card, &path, NULL);
  521|      8|		if (r < 0)
  ------------------
  |  Branch (521:7): [True: 5, False: 3]
  ------------------
  522|      5|			goto err;
  523|      3|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  524|      3|		if (r < 0)
  ------------------
  |  Branch (524:7): [True: 1, False: 2]
  ------------------
  525|      1|			goto err;
  526|      2|		if (r == 0) {
  ------------------
  |  Branch (526:7): [True: 1, False: 1]
  ------------------
  527|      1|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  528|      1|			goto err;
  529|      1|		}
  530|       |
  531|      1|		all_certs_len = r;
  532|       |
  533|       |		/* save EF_C_DevAut for further use */
  534|      1|		cert = realloc(priv->EF_C_DevAut, all_certs_len);
  535|      1|		if (cert) {
  ------------------
  |  Branch (535:7): [True: 1, False: 0]
  ------------------
  536|      1|			memcpy((unsigned char *) cert, all_certs, all_certs_len);
  537|      1|			priv->EF_C_DevAut = (unsigned char *) cert;
  538|      1|			priv->EF_C_DevAut_len = all_certs_len;
  539|      1|		}
  540|       |
  541|      1|		cert = all_certs;
  542|      1|	}
  543|      1|	left = all_certs_len;
  544|       |
  545|      1|	device_cert = cert;
  546|      1|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_device);
  547|      1|	if (r < 0)
  ------------------
  |  Branch (547:6): [True: 1, False: 0]
  ------------------
  548|      1|		goto err;
  549|      0|	device_cert_len = all_certs_len - left;
  550|       |
  551|      0|	issuer_cert = cert;
  552|      0|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_issuer);
  553|      0|	if (r < 0)
  ------------------
  |  Branch (553:6): [True: 0, False: 0]
  ------------------
  554|      0|		goto err;
  555|      0|	issuer_cert_len = all_certs_len - device_cert_len - left;
  556|       |
  557|      0|	ctx = EAC_CTX_new();
  558|      0|	if (!ctx) {
  ------------------
  |  Branch (558:6): [True: 0, False: 0]
  ------------------
  559|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  560|      0|		goto err;
  561|      0|	}
  562|       |
  563|       |	/* FIXME set flags with opensc.conf */
  564|      0|	TA_disable_checks(ctx);
  565|      0|	CA_disable_passive_authentication(ctx);
  566|       |
  567|       |	/* check all CVCs given of the document's pki */
  568|      0|	if (!TA_STEP2_import_certificate(ctx, issuer_cert, issuer_cert_len)
  ------------------
  |  Branch (568:6): [True: 0, False: 0]
  ------------------
  569|      0|			|| !TA_STEP2_import_certificate(ctx, device_cert, device_cert_len)) {
  ------------------
  |  Branch (569:7): [True: 0, False: 0]
  ------------------
  570|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  571|      0|		goto err;
  572|      0|	}
  573|       |
  574|       |	/* XXX on older JCOPs only NID_id_CA_ECDH_3DES_CBC_CBC may be
  575|       |	 * supported. The card does not export its capabilities. We hardcode
  576|       |	 * NID_id_CA_ECDH_AES_CBC_CMAC_128 here, because we don't have the older
  577|       |	 * cards in production. */
  578|      0|	protocol = NID_id_CA_ECDH_AES_CBC_CMAC_128;
  579|       |
  580|       |	/* initialize CA domain parameter with the document's public key */
  581|      0|	if (!EAC_CTX_init_ca(ctx, protocol, 8)) {
  ------------------
  |  Branch (581:6): [True: 0, False: 0]
  ------------------
  582|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  583|      0|		goto err;
  584|      0|	}
  585|      0|	EVP_PKEY_free(ctx->ca_ctx->ka_ctx->key);
  586|      0|	if (!EVP_PKEY_up_ref(ctx->ta_ctx->pub_key)) {
  ------------------
  |  Branch (586:6): [True: 0, False: 0]
  ------------------
  587|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  588|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  589|      0|		goto err;
  590|      0|	}
  591|      0|	ctx->ca_ctx->ka_ctx->key = ctx->ta_ctx->pub_key;
  592|       |
  593|       |	/* generate keys for CA */
  594|      0|	comp_pub_key = TA_STEP3_generate_ephemeral_key(ctx);
  595|      0|	r = perform_chip_authentication_ex(card, ctx,
  596|      0|			cvc_device.publicPoint, cvc_device.publicPointlen);
  597|       |
  598|      8|err:
  599|      8|	if (r < 0)
  ------------------
  |  Branch (599:6): [True: 8, False: 0]
  ------------------
  600|      8|		EAC_CTX_clear_free(ctx);
  601|      8|	if (comp_pub_key)
  ------------------
  |  Branch (601:6): [True: 0, False: 8]
  ------------------
  602|      0|		BUF_MEM_free(comp_pub_key);
  603|      8|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  604|      8|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  605|       |
  606|      8|	return r;
  607|      0|}

sc_get_setcos_driver:
 1136|  15.2k|{
 1137|  15.2k|	return sc_get_driver();
 1138|  15.2k|}
card-setcos.c:sc_get_driver:
 1116|  15.2k|{
 1117|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1118|       |
 1119|  15.2k|	setcos_ops = *iso_drv->ops;
 1120|  15.2k|	setcos_ops.match_card = setcos_match_card;
 1121|  15.2k|	setcos_ops.init = setcos_init;
 1122|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1122:6): [True: 1, False: 15.2k]
  ------------------
 1123|      1|		iso_ops = iso_drv->ops;
 1124|  15.2k|	setcos_ops.create_file = setcos_create_file;
 1125|  15.2k|	setcos_ops.set_security_env = setcos_set_security_env;
 1126|  15.2k|	setcos_ops.select_file = setcos_select_file;
 1127|  15.2k|	setcos_ops.list_files = setcos_list_files;
 1128|  15.2k|	setcos_ops.process_fci = setcos_process_fci;
 1129|  15.2k|	setcos_ops.construct_fci = setcos_construct_fci;
 1130|  15.2k|	setcos_ops.card_ctl = setcos_card_ctl;
 1131|       |
 1132|  15.2k|	return &setcos_drv;
 1133|  15.2k|}
card-setcos.c:setcos_match_card:
   83|  6.06k|{
   84|  6.06k|	sc_apdu_t apdu;
   85|  6.06k|	u8 buf[6];
   86|  6.06k|	int i;
   87|       |
   88|  6.06k|	i = _sc_match_atr(card, setcos_atrs, &card->type);
   89|  6.06k|	if (i < 0) {
  ------------------
  |  Branch (89:6): [True: 6.05k, False: 15]
  ------------------
   90|  6.05k|		if (match_hist_bytes(card, "FISE", 0)) {
  ------------------
  |  Branch (90:7): [True: 66, False: 5.98k]
  ------------------
   91|     66|			card->type = SC_CARD_TYPE_SETCOS_GENERIC;
   92|     66|			return 1;
   93|     66|		}
   94|       |		/* Check if it's a EID2.x applet by reading the version info */
   95|  5.98k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  292|  5.98k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   96|  5.98k|		apdu.cla = 0x00;
   97|  5.98k|		apdu.resp = buf;
   98|  5.98k|		apdu.resplen = 5;
   99|  5.98k|		apdu.le = 5;
  100|  5.98k|		i = sc_transmit_apdu(card, &apdu);
  101|  5.98k|		if (i == 0 && apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && apdu.resplen == 5) {
  ------------------
  |  Branch (101:7): [True: 5.55k, False: 432]
  |  Branch (101:17): [True: 328, False: 5.22k]
  |  Branch (101:37): [True: 316, False: 12]
  |  Branch (101:57): [True: 265, False: 51]
  ------------------
  102|    265|			if (memcmp(buf, "v2.0", 4) == 0)
  ------------------
  |  Branch (102:8): [True: 150, False: 115]
  ------------------
  103|    150|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_0;
  104|    115|			else if (memcmp(buf, "v2.1", 4) == 0)
  ------------------
  |  Branch (104:13): [True: 98, False: 17]
  ------------------
  105|     98|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_1;
  106|     17|			else {
  107|     17|				buf[sizeof(buf) - 1] = '\0';
  108|     17|				sc_log(card->ctx,  "SetCOS EID applet %s is not supported", (char *) buf);
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  109|     17|				return 0;
  110|     17|			}
  111|    248|			return 1;
  112|    265|		}
  113|       |
  114|  5.71k|		return 0;
  115|  5.98k|	}
  116|     15|	card->flags = setcos_atrs[i].flags;
  117|     15|	return 1;
  118|  6.06k|}
card-setcos.c:match_hist_bytes:
   64|  6.05k|{
   65|  6.05k|	const char *src = (const char *) card->reader->atr_info.hist_bytes;
   66|  6.05k|	size_t srclen = card->reader->atr_info.hist_bytes_len;
   67|  6.05k|	size_t offset = 0;
   68|       |
   69|  6.05k|	if (len == 0)
  ------------------
  |  Branch (69:6): [True: 6.05k, False: 0]
  ------------------
   70|  6.05k|		len = strlen(str);
   71|  6.05k|	if (srclen < len)
  ------------------
  |  Branch (71:6): [True: 4.96k, False: 1.08k]
  ------------------
   72|  4.96k|		return 0;
   73|  6.68k|	while (srclen - offset > len) {
  ------------------
  |  Branch (73:9): [True: 5.65k, False: 1.02k]
  ------------------
   74|  5.65k|		if (memcmp(src + offset, str, len) == 0) {
  ------------------
  |  Branch (74:7): [True: 66, False: 5.59k]
  ------------------
   75|     66|			return 1;
   76|     66|		}
   77|  5.59k|		offset++;
   78|  5.59k|	}
   79|  1.02k|	return 0;
   80|  1.08k|}
card-setcos.c:setcos_init:
  133|    329|{
  134|    329|	card->name = "SetCOS";
  135|       |
  136|       |	/* Handle unknown or forced cards */
  137|    329|	if (card->type < 0) {
  ------------------
  |  Branch (137:6): [True: 0, False: 329]
  ------------------
  138|      0|		card->type = SC_CARD_TYPE_SETCOS_GENERIC;
  139|      0|	}
  140|       |
  141|    329|	switch (card->type) {
  142|      8|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (142:2): [True: 8, False: 321]
  ------------------
  143|      8|		card->cla = 0x00;
  144|      8|		select_pkcs15_app(card);
  145|      8|		if (card->flags & SC_CARD_FLAG_RNG)
  ------------------
  |  |  536|      8|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  |  Branch (145:7): [True: 0, False: 8]
  ------------------
  146|      0|			card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|      0|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  147|      8|		break;
  148|      6|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (148:2): [True: 6, False: 323]
  ------------------
  149|    156|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (149:2): [True: 150, False: 179]
  ------------------
  150|    254|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (150:2): [True: 98, False: 231]
  ------------------
  151|    254|		card->cla = 0x00;
  152|    254|		card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    254|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  153|    254|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    254|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  154|    254|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    254|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  155|    254|		break;
  156|     67|	default:
  ------------------
  |  Branch (156:2): [True: 67, False: 262]
  ------------------
  157|       |		/* XXX: Get SetCOS version */
  158|     67|		card->cla = 0x80;	/* SetCOS 4.3.x */
  159|       |		/* State that we have an RNG */
  160|     67|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     67|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  161|     67|		break;
  162|    329|	}
  163|       |
  164|    329|	switch (card->type) {
  ------------------
  |  Branch (164:10): [True: 263, False: 66]
  ------------------
  165|      1|	case SC_CARD_TYPE_SETCOS_PKI: {
  ------------------
  |  Branch (165:2): [True: 1, False: 328]
  ------------------
  166|      1|		unsigned long flags;
  167|       |
  168|      1|		flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  102|      1|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              		flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  169|      1|		flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  133|      1|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              		flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      1|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  170|       |
  171|      1|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  172|      1|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  173|      1|	} break;
  174|      6|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (174:2): [True: 6, False: 323]
  ------------------
  175|     14|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (175:2): [True: 8, False: 321]
  ------------------
  176|    164|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (176:2): [True: 150, False: 179]
  ------------------
  177|    262|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (177:2): [True: 98, False: 231]
  ------------------
  178|    262|		{
  179|    262|			unsigned long flags;
  180|       |
  181|    262|			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  102|    262|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    262|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    262|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    262|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  182|    262|			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  133|    262|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|    262|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  183|    262|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    262|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  184|       |
  185|    262|			_sc_card_add_rsa_alg(card, 512, flags, 0);
  186|    262|			_sc_card_add_rsa_alg(card, 768, flags, 0);
  187|    262|			_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|    262|			_sc_card_add_rsa_alg(card, 2048, flags, 0);
  189|    262|		}
  190|    262|		break;
  191|    329|	}
  192|    329|	return 0;
  193|    329|}
card-setcos.c:select_pkcs15_app:
  121|      8|{
  122|      8|	sc_path_t app;
  123|      8|	int r;
  124|       |
  125|       |	/* Regular PKCS#15 AID */
  126|      8|	sc_format_path("A000000063504B43532D3135", &app);
  127|      8|	app.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      8|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  128|       |	r = sc_select_file(card, &app, NULL);
  129|      8|	return r;
  130|      8|}
card-setcos.c:setcos_select_file:
  901|  1.63k|{
  902|  1.63k|	int r;
  903|       |
  904|  1.63k|	r = iso_ops->select_file(card, in_path, file);
  905|  1.63k|	if (r)
  ------------------
  |  Branch (905:6): [True: 1.16k, False: 470]
  ------------------
  906|  1.16k|		return r;
  907|    470|	if (file != NULL) {
  ------------------
  |  Branch (907:6): [True: 355, False: 115]
  ------------------
  908|    355|		if (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (908:7): [True: 10, False: 345]
  ------------------
  909|    345|		    card->type == SC_CARD_TYPE_SETCOS_NIDEL ||
  ------------------
  |  Branch (909:7): [True: 11, False: 334]
  ------------------
  910|    334|		    SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|    334|#define SETCOS_IS_EID_APPLET(card) ((card)->type == SC_CARD_TYPE_SETCOS_EID_V2_0 || (card)->type == SC_CARD_TYPE_SETCOS_EID_V2_1)
  |  |  ------------------
  |  |  |  Branch (46:37): [True: 162, False: 172]
  |  |  |  Branch (46:85): [True: 107, False: 65]
  |  |  ------------------
  ------------------
  911|    290|			parse_sec_attr_44(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  912|     65|		else
  913|     65|			parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  914|    355|	}
  915|    470|	return 0;
  916|  1.63k|}
card-setcos.c:parse_sec_attr_44:
  746|    290|{
  747|       |	/* OpenSc Operation values for each command operation-type */
  748|    290|	const int df_idx[8] = {	 /* byte 1 = OpenSC type of AC Bit0,  byte 2 = OpenSC type of AC Bit1 ...*/
  749|    290|		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  168|    290|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    290|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    290|#define SC_AC_OP_CREATE			3
  ------------------
  750|    290|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    290|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    290|#define SC_AC_OP_REHABILITATE		4
  ------------------
  751|    290|		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  167|    290|#define SC_AC_OP_LOCK			1
  ------------------
              		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  168|    290|#define SC_AC_OP_DELETE			2
  ------------------
  752|    290|	const int ef_idx[8] = {
  753|    290|		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|    290|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|    290|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|    290|#define SC_AC_OP_WRITE			24
  ------------------
  754|    290|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    290|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    290|#define SC_AC_OP_REHABILITATE		4
  ------------------
  755|    290|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    290|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    290|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  756|    290|	const int efi_idx[8] = { /* internal EF used for RSA keys */
  757|    290|		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  188|    290|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  202|    290|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    290|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|    290|#define SC_AC_OP_UPDATE			23
  ------------------
  758|    290|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    290|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    290|#define SC_AC_OP_REHABILITATE		4
  ------------------
  759|    290|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    290|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    290|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  760|       |
  761|    290|	u8		bValue;
  762|    290|	int		i;
  763|    290|	int		iKeyRef = 0;
  764|    290|	int		iMethod;
  765|    290|	int		iPinCount;
  766|    290|	int		iOffset = 0;
  767|    290|	int		iOperation;
  768|    290|	const int*	p_idx;
  769|       |
  770|       |	/* Check all sub-AC definitions within the total AC */
  771|  1.66k|	while (len > 1 && (size_t)iOffset < len) {	/* minimum length = 2 */
  ------------------
  |  Branch (771:9): [True: 1.48k, False: 176]
  |  Branch (771:20): [True: 1.39k, False: 89]
  ------------------
  772|  1.39k|		size_t iACLen   = buf[iOffset] & 0x0F;
  773|  1.39k|		if (iACLen >= len)
  ------------------
  |  Branch (773:7): [True: 14, False: 1.38k]
  ------------------
  774|     14|			break;
  775|       |
  776|  1.38k|		iMethod = SC_AC_NONE;		/* default no authentication required */
  ------------------
  |  |  150|  1.38k|#define SC_AC_NONE			0x00000000
  ------------------
  777|       |
  778|  1.38k|		if (buf[iOffset] & 0X80) { /* AC in adaptive coding */
  ------------------
  |  Branch (778:7): [True: 484, False: 900]
  ------------------
  779|       |			/* Evaluates only the command-byte, not the optional P1/P2/Option bytes */
  780|    484|			size_t	iParmLen = 1;			/* command-byte is always present */
  781|    484|			size_t	iKeyLen  = 0;			/* Encryption key is optional */
  782|       |
  783|    484|			if (buf[iOffset]   & 0x20) iKeyLen++;
  ------------------
  |  Branch (783:8): [True: 273, False: 211]
  ------------------
  784|    484|			if (buf[iOffset+1] & 0x40) iParmLen++;
  ------------------
  |  Branch (784:8): [True: 241, False: 243]
  ------------------
  785|    484|			if (buf[iOffset+1] & 0x20) iParmLen++;
  ------------------
  |  Branch (785:8): [True: 221, False: 263]
  ------------------
  786|    484|			if (buf[iOffset+1] & 0x10) iParmLen++;
  ------------------
  |  Branch (786:8): [True: 211, False: 273]
  ------------------
  787|    484|			if (buf[iOffset+1] & 0x08) iParmLen++;
  ------------------
  |  Branch (787:8): [True: 72, False: 412]
  ------------------
  788|       |
  789|       |			/* Get KeyNumber if available */
  790|    484|			if(iKeyLen) {
  ------------------
  |  Branch (790:7): [True: 273, False: 211]
  ------------------
  791|    273|				int iSC;
  792|    273|				if (len < 1 + iACLen)
  ------------------
  |  Branch (792:9): [True: 0, False: 273]
  ------------------
  793|      0|					break;
  794|    273|				iSC = buf[iOffset+iACLen];
  795|       |
  796|    273|				switch( (iSC>>5) & 0x03 ){
  ------------------
  |  Branch (796:13): [True: 273, False: 0]
  ------------------
  797|     46|				case 0:
  ------------------
  |  Branch (797:5): [True: 46, False: 227]
  ------------------
  798|     46|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     46|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  799|     46|					break;
  800|     86|				case 1:
  ------------------
  |  Branch (800:5): [True: 86, False: 187]
  ------------------
  801|     86|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|     86|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  802|     86|					break;
  803|     20|				case 2:
  ------------------
  |  Branch (803:5): [True: 20, False: 253]
  ------------------
  804|    141|				case 3:
  ------------------
  |  Branch (804:5): [True: 121, False: 152]
  ------------------
  805|    141|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    141|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  806|    141|					break;
  807|    273|				}
  808|    273|				iKeyRef = iSC & 0x1F;			/* get key number */
  809|    273|			}
  810|       |
  811|       |			/* Get PinNumber if available */
  812|    484|			if (iACLen > (1+iParmLen+iKeyLen)) {  /* check via total length if pin is present */
  ------------------
  |  Branch (812:8): [True: 63, False: 421]
  ------------------
  813|     63|				if (len < 1+1+1+(size_t)iParmLen)
  ------------------
  |  Branch (813:9): [True: 0, False: 63]
  ------------------
  814|      0|					break;
  815|     63|				iKeyRef = buf[iOffset+1+1+iParmLen];  /* PTL + AM-header + parameter-bytes */
  816|     63|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     63|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  817|     63|			}
  818|       |
  819|       |			/* Convert SETCOS command to OpenSC command group */
  820|    484|			if (len < 1+2)
  ------------------
  |  Branch (820:8): [True: 11, False: 473]
  ------------------
  821|     11|				break;
  822|    473|			switch(buf[iOffset+2]){
  823|     18|			case 0x2A:			/* crypto operation */
  ------------------
  |  Branch (823:4): [True: 18, False: 455]
  ------------------
  824|     18|				iOperation = SC_AC_OP_CRYPTO;
  ------------------
  |  |  173|     18|#define SC_AC_OP_CRYPTO			7
  ------------------
  825|     18|				break;
  826|     18|			case 0x46:			/* key-generation operation */
  ------------------
  |  Branch (826:4): [True: 18, False: 455]
  ------------------
  827|     18|				iOperation = SC_AC_OP_UPDATE;
  ------------------
  |  |  189|     18|#define SC_AC_OP_UPDATE			23
  ------------------
  828|     18|				break;
  829|    437|			default:
  ------------------
  |  Branch (829:4): [True: 437, False: 36]
  ------------------
  830|    437|				iOperation = SC_AC_OP_SELECT;
  ------------------
  |  |  166|    437|#define SC_AC_OP_SELECT			0
  ------------------
  831|    437|				break;
  832|    473|			}
  833|    473|			sc_file_add_acl_entry(file, iOperation, iMethod, iKeyRef);
  834|    473|		}
  835|    900|		else { /* AC in simple coding */
  836|       |			   /* Initial AC is treated as an operational AC */
  837|       |
  838|       |			/* Get specific Cmd groups for specified file-type */
  839|    900|			switch (file->type) {
  840|    104|			case SC_FILE_TYPE_DF:            /* DF */
  ------------------
  |  |  214|    104|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (840:4): [True: 104, False: 796]
  ------------------
  841|    104|				p_idx = df_idx;
  842|    104|				break;
  843|     67|			case SC_FILE_TYPE_INTERNAL_EF:   /* EF for RSA keys */
  ------------------
  |  |  215|     67|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (843:4): [True: 67, False: 833]
  ------------------
  844|     67|				p_idx = efi_idx;
  845|     67|				break;
  846|    729|			default:                         /* EF */
  ------------------
  |  Branch (846:4): [True: 729, False: 171]
  ------------------
  847|    729|				p_idx = ef_idx;
  848|    729|				break;
  849|    900|			}
  850|       |
  851|       |			/* Encryption key present ? */
  852|    900|			iPinCount = iACLen > 0 ? (int)iACLen - 1 : 0;
  ------------------
  |  Branch (852:16): [True: 299, False: 601]
  ------------------
  853|       |
  854|    900|			if (buf[iOffset] & 0x20) {
  ------------------
  |  Branch (854:8): [True: 557, False: 343]
  ------------------
  855|    557|				int iSC;
  856|    557|				if (len < 1 + (size_t)iACLen)
  ------------------
  |  Branch (856:9): [True: 0, False: 557]
  ------------------
  857|      0|					break;
  858|    557|				iSC = buf[iOffset + iACLen];
  859|       |
  860|    557|				switch( (iSC>>5) & 0x03 ) {
  ------------------
  |  Branch (860:13): [True: 557, False: 0]
  ------------------
  861|     88|				case 0:
  ------------------
  |  Branch (861:5): [True: 88, False: 469]
  ------------------
  862|     88|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     88|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  863|     88|					break;
  864|    121|				case 1:
  ------------------
  |  Branch (864:5): [True: 121, False: 436]
  ------------------
  865|    121|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|    121|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  866|    121|					break;
  867|     42|				case 2:
  ------------------
  |  Branch (867:5): [True: 42, False: 515]
  ------------------
  868|    348|				case 3:
  ------------------
  |  Branch (868:5): [True: 306, False: 251]
  ------------------
  869|    348|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    348|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  870|    348|					break;
  871|    557|				}
  872|    557|				iKeyRef = iSC & 0x1F;			/* get key number */
  873|       |
  874|    557|				iPinCount--;				/* one byte used for keyReference  */
  875|    557|			}
  876|       |
  877|       |			/* Pin present ? */
  878|    900|			if ( iPinCount > 0 ) {
  ------------------
  |  Branch (878:9): [True: 101, False: 799]
  ------------------
  879|    101|				if (len < 1 + 2)
  ------------------
  |  Branch (879:9): [True: 0, False: 101]
  ------------------
  880|      0|					break;
  881|    101|				iKeyRef = buf[iOffset + 2];	/* pin ref */
  882|    101|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|    101|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  883|    101|			}
  884|       |
  885|       |			/* Add AC for each command-operationType into OpenSc structure */
  886|    900|			bValue = buf[iOffset + 1];
  887|  8.10k|			for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (887:16): [True: 7.20k, False: 900]
  ------------------
  888|  7.20k|				if((bValue & 1) && (p_idx[i] >= 0))
  ------------------
  |  Branch (888:8): [True: 2.00k, False: 5.19k]
  |  Branch (888:24): [True: 1.51k, False: 496]
  ------------------
  889|  1.51k|					sc_file_add_acl_entry(file, p_idx[i], iMethod, iKeyRef);
  890|  7.20k|				bValue >>= 1;
  891|  7.20k|			}
  892|    900|		}
  893|       |		/* Current field treated, get next AC sub-field */
  894|  1.37k|		iOffset += iACLen +1;		/* AC + PTL-byte */
  895|  1.37k|		len     -= iACLen +1;
  896|  1.37k|	}
  897|    290|}
card-setcos.c:parse_sec_attr:
  718|     65|{
  719|     65|	int i;
  720|     65|	int idx[6];
  721|       |
  722|     65|	if (len < 6)
  ------------------
  |  Branch (722:6): [True: 20, False: 45]
  ------------------
  723|     20|		return;
  724|     45|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|     45|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (724:6): [True: 10, False: 35]
  ------------------
  725|     10|		const int df_idx[6] = {
  726|     10|			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  166|     10|#define SC_AC_OP_SELECT			0
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  167|     10|#define SC_AC_OP_LOCK			1
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  168|     10|#define SC_AC_OP_DELETE			2
  ------------------
  727|     10|			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  169|     10|#define SC_AC_OP_CREATE			3
  ------------------
              			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     10|#define SC_AC_OP_REHABILITATE		4
  ------------------
  728|     10|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|     10|#define SC_AC_OP_INVALIDATE		5
  ------------------
  729|     10|		};
  730|     70|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (730:15): [True: 60, False: 10]
  ------------------
  731|     60|			idx[i] = df_idx[i];
  732|     35|	} else {
  733|     35|		const int ef_idx[6] = {
  734|     35|			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|     35|#define SC_AC_OP_READ			22
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|     35|#define SC_AC_OP_UPDATE			23
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     35|#define SC_AC_OP_WRITE			24
  ------------------
  735|     35|			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  202|     35|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     35|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     35|#define SC_AC_OP_REHABILITATE		4
  ------------------
  736|     35|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|     35|#define SC_AC_OP_INVALIDATE		5
  ------------------
  737|     35|		};
  738|    245|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (738:15): [True: 210, False: 35]
  ------------------
  739|    210|			idx[i] = ef_idx[i];
  740|     35|	}
  741|    315|	for (i = 0; i < 6; i++)
  ------------------
  |  Branch (741:14): [True: 270, False: 45]
  ------------------
  742|    270|		add_acl_entry(file, idx[i], buf[i]);
  743|     45|}
card-setcos.c:add_acl_entry:
  689|    270|{
  690|    270|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    270|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  691|       |
  692|    270|	switch (byte >> 4) {
  693|     46|	case 0:
  ------------------
  |  Branch (693:2): [True: 46, False: 224]
  ------------------
  694|     46|		method = SC_AC_NONE;
  ------------------
  |  |  150|     46|#define SC_AC_NONE			0x00000000
  ------------------
  695|     46|		break;
  696|     29|	case 1:
  ------------------
  |  Branch (696:2): [True: 29, False: 241]
  ------------------
  697|     29|		method = SC_AC_CHV;
  ------------------
  |  |  151|     29|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  698|     29|		key_ref = 1;
  699|     29|		break;
  700|     68|	case 2:
  ------------------
  |  Branch (700:2): [True: 68, False: 202]
  ------------------
  701|     68|		method = SC_AC_CHV;
  ------------------
  |  |  151|     68|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  702|     68|		key_ref = 2;
  703|     68|		break;
  704|     26|	case 4:
  ------------------
  |  Branch (704:2): [True: 26, False: 244]
  ------------------
  705|     26|		method = SC_AC_TERM;
  ------------------
  |  |  152|     26|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  706|     26|		break;
  707|     33|	case 15:
  ------------------
  |  Branch (707:2): [True: 33, False: 237]
  ------------------
  708|     33|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     33|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  709|     33|		break;
  710|     68|	default:
  ------------------
  |  Branch (710:2): [True: 68, False: 202]
  ------------------
  711|     68|		method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     68|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  712|     68|		break;
  713|    270|	}
  714|    270|	sc_file_add_acl_entry(file, op, method, key_ref);
  715|    270|}
card-setcos.c:setcos_process_fci:
  942|    349|{
  943|    349|	int r = iso_ops->process_fci(card, file, buf, buflen);
  944|       |
  945|       |	/* SetCOS 4.4: RSA key file is an internal EF but it's
  946|       |	 * file descriptor doesn't seem to follow ISO7816. */
  947|    349|	if (r >= 0 && (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (947:6): [True: 349, False: 0]
  |  Branch (947:17): [True: 10, False: 339]
  ------------------
  948|    339|	               SETCOS_IS_EID_APPLET(card))) {
  ------------------
  |  |   46|    339|#define SETCOS_IS_EID_APPLET(card) ((card)->type == SC_CARD_TYPE_SETCOS_EID_V2_0 || (card)->type == SC_CARD_TYPE_SETCOS_EID_V2_1)
  |  |  ------------------
  |  |  |  Branch (46:37): [True: 162, False: 177]
  |  |  |  Branch (46:85): [True: 105, False: 72]
  |  |  ------------------
  ------------------
  949|    277|		const u8 *tag;
  950|    277|		size_t taglen = 1;
  951|    277|		tag = (u8 *) sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &taglen);
  952|    277|		if (tag != NULL && taglen == 1 && *tag == 0x11)
  ------------------
  |  Branch (952:7): [True: 74, False: 203]
  |  Branch (952:22): [True: 65, False: 9]
  |  Branch (952:37): [True: 7, False: 58]
  ------------------
  953|      7|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      7|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  954|    277|	}
  955|       |
  956|    349|	return r;
  957|    349|}
card-setcos.c:setcos_card_ctl:
 1092|     14|{
 1093|     14|	if (card->type != SC_CARD_TYPE_SETCOS_44 && !SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|     13|#define SETCOS_IS_EID_APPLET(card) ((card)->type == SC_CARD_TYPE_SETCOS_EID_V2_0 || (card)->type == SC_CARD_TYPE_SETCOS_EID_V2_1)
  |  |  ------------------
  |  |  |  Branch (46:37): [True: 2, False: 11]
  |  |  |  Branch (46:85): [True: 6, False: 5]
  |  |  ------------------
  ------------------
  |  Branch (1093:6): [True: 13, False: 1]
  ------------------
 1094|      5|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      5|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1095|       |
 1096|      9|	switch(cmd) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 9]
  ------------------
 1097|      0|	case SC_CARDCTL_SETCOS_PUTDATA:
  ------------------
  |  Branch (1097:2): [True: 0, False: 9]
  ------------------
 1098|      0|		return setcos_putdata(card,
 1099|      0|				(struct sc_cardctl_setcos_data_obj*) ptr);
 1100|      0|		break;
 1101|      0|	case SC_CARDCTL_SETCOS_GETDATA:
  ------------------
  |  Branch (1101:2): [True: 0, False: 9]
  ------------------
 1102|      0|		return setcos_getdata(card,
 1103|      0|				(struct sc_cardctl_setcos_data_obj*) ptr);
 1104|      0|		break;
 1105|      0|	case SC_CARDCTL_SETCOS_GENERATE_STORE_KEY:
  ------------------
  |  Branch (1105:2): [True: 0, False: 9]
  ------------------
 1106|      0|		return setcos_generate_store_key(card,
 1107|      0|				(struct sc_cardctl_setcos_gen_store_key_info *) ptr);
 1108|      0|	case SC_CARDCTL_SETCOS_ACTIVATE_FILE:
  ------------------
  |  Branch (1108:2): [True: 0, False: 9]
  ------------------
 1109|      0|		return setcos_activate_file(card);
 1110|      9|	}
 1111|       |
 1112|      9|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      9|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1113|      9|}

sc_get_skeid_driver:
  179|  15.2k|{
  180|  15.2k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 15.2k]
  ------------------
  181|  15.2k|	skeid_ops = *iso_ops;
  182|  15.2k|	skeid_ops.match_card = skeid_match_card;
  183|  15.2k|	skeid_ops.init = skeid_init;
  184|  15.2k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  15.2k|	skeid_ops.logout = skeid_logout;
  186|  15.2k|	return &skeid_drv;
  187|  15.2k|}
card-skeid.c:skeid_match_card:
   73|  14.7k|{
   74|  14.7k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|     79|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 14.7k, False: 79]
  |  Branch (74:58): [True: 67, False: 12]
  ------------------
   75|  14.7k|		return 0;
   76|       |
   77|     12|	sc_log(card->ctx,  "Slovak eID card v3 (CardOS 5.4)");
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   78|       |
   79|     12|	return 1;
   80|  14.7k|}
card-skeid.c:skeid_known_url:
   53|     79|{
   54|     79|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|     79|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|     79|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|     79|	sc_path_t url_path;
   59|       |
   60|     79|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     79|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|     79|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|     79|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|     79|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|    158|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 42, False: 37]
  ------------------
   65|     42|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     42|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|    121|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 25, False: 17]
  ------------------
   66|     25|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|     25|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 12, False: 13]
  ------------------
   67|     12|		r = SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|     79|	return r;
   70|     79|}
card-skeid.c:skeid_init:
  108|     12|{
  109|     12|	const unsigned long flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|     12|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     12|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     12|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	const unsigned long flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     12|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  110|     12|	const size_t data_field_length = 437;
  111|     12|	int r;
  112|       |
  113|     12|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     12|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  ------------------
  ------------------
  114|       |
  115|     12|	card->name = "Slovak eID (CardOS)";
  116|     12|	card->type = SC_CARD_TYPE_SKEID_V3;
  117|     12|	card->cla = 0x00;
  118|       |
  119|     12|	r = skeid_get_serialnr(card);
  120|     12|	LOG_TEST_RET(card->ctx, r, "Error reading serial number.");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|      6|	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|      6|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|      6|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  123|       |
  124|      6|	card->max_send_size = data_field_length - 6;
  125|       |#ifdef _WIN32
  126|       |	/* see card-cardos.c */
  127|       |	if (card->reader->max_send_size == 255 && card->reader->max_recv_size == 256) {
  128|       |		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "resetting reader to use data_field_length");
  129|       |		card->reader->max_send_size = data_field_length - 6;
  130|       |		card->reader->max_recv_size = data_field_length - 3;
  131|       |	}
  132|       |#endif
  133|       |
  134|      6|	card->max_send_size = sc_get_max_send_size(card); /* see card-cardos.c */
  135|      6|	card->max_recv_size = data_field_length - 2;
  136|      6|	card->max_recv_size = sc_get_max_recv_size(card);
  137|       |
  138|      6|	r = _sc_card_add_rsa_alg(card, 3072, flags, 0);
  139|       |
  140|      6|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|      6|}
card-skeid.c:skeid_get_serialnr:
   83|     12|{
   84|     12|	int r;
   85|     12|	sc_apdu_t apdu;
   86|     12|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
   87|       |
   88|     12|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     12|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   89|     12|	apdu.resp = rbuf;
   90|     12|	apdu.resplen = sizeof(rbuf);
   91|     12|	apdu.le = 256;
   92|     12|	r = sc_transmit_apdu(card, &apdu);
   93|     12|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|     10|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (94:6): [True: 1, False: 9]
  |  Branch (94:26): [True: 1, False: 8]
  ------------------
   95|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
   96|      8|	if (apdu.resplen == 8) {
  ------------------
  |  Branch (96:6): [True: 6, False: 2]
  ------------------
   97|       |		/* cache serial number */
   98|      6|		memcpy(card->serialnr.value, rbuf, 8);
   99|      6|		card->serialnr.len = 8;
  100|      6|	} else {
  101|      2|		sc_log(card->ctx, "unexpected response to GET DATA serial number");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  103|      2|	}
  104|      6|	return SC_SUCCESS;
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  105|      8|}

sc_get_srbeid_driver:
  305|  15.2k|{
  306|       |	/* Save ISO ops for delegation, then override what we handle. */
  307|  15.2k|	iso_ops = sc_get_iso7816_driver()->ops;
  308|  15.2k|	srbeid_ops = *iso_ops;
  309|  15.2k|	srbeid_ops.match_card = srbeid_match_card;
  310|  15.2k|	srbeid_ops.init = srbeid_init;
  311|  15.2k|	srbeid_ops.select_file = srbeid_select_file;
  312|  15.2k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  313|  15.2k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  314|  15.2k|	srbeid_ops.decipher = srbeid_decipher;
  315|       |
  316|  15.2k|	return &srbeid_drv;
  317|  15.2k|}
card-srbeid.c:srbeid_match_card:
   72|  7.38k|{
   73|  7.38k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  7.38k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|      0|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 0, False: 7.38k]
  |  Branch (74:16): [True: 0, False: 0]
  ------------------
   75|      0|		card->name = srbeid_atrs[i].name;
   76|      0|		return 1;
   77|      0|	}
   78|  7.38k|	return 0;
   79|  7.38k|}

sc_get_starcos_driver:
 2120|  15.2k|{
 2121|  15.2k|	return sc_get_driver();
 2122|  15.2k|}
card-starcos.c:sc_get_driver:
 2095|  15.2k|{
 2096|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2097|  15.2k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2097:6): [True: 1, False: 15.2k]
  ------------------
 2098|      1|		iso_ops = iso_drv->ops;
 2099|       |
 2100|  15.2k|	starcos_ops = *iso_drv->ops;
 2101|  15.2k|	starcos_ops.match_card = starcos_match_card;
 2102|  15.2k|	starcos_ops.init   = starcos_init;
 2103|  15.2k|	starcos_ops.finish = starcos_finish;
 2104|  15.2k|	starcos_ops.select_file = starcos_select_file;
 2105|  15.2k|	starcos_ops.get_challenge = starcos_get_challenge;
 2106|  15.2k|	starcos_ops.check_sw    = starcos_check_sw;
 2107|  15.2k|	starcos_ops.create_file = starcos_create_file;
 2108|  15.2k|	starcos_ops.delete_file = NULL;
 2109|  15.2k|	starcos_ops.set_security_env  = starcos_set_security_env;
 2110|  15.2k|	starcos_ops.compute_signature = starcos_compute_signature;
 2111|  15.2k|	starcos_ops.decipher = starcos_decipher;
 2112|  15.2k|	starcos_ops.card_ctl    = starcos_card_ctl;
 2113|  15.2k|	starcos_ops.logout      = starcos_logout;
 2114|  15.2k|	starcos_ops.pin_cmd     = starcos_pin_cmd;
 2115|       |
 2116|  15.2k|	return &starcos_drv;
 2117|  15.2k|}
card-starcos.c:starcos_match_card:
  125|  13.6k|{
  126|  13.6k|	int i;
  127|       |
  128|  13.6k|	i = _sc_match_atr(card, starcos_atrs, &card->type);
  129|  13.6k|	if (i < 0)
  ------------------
  |  Branch (129:6): [True: 12.7k, False: 891]
  ------------------
  130|  12.7k|		return 0;
  131|    891|	return 1;
  132|  13.6k|}
card-starcos.c:starcos_init:
  359|    891|{
  360|    891|	unsigned int flags;
  361|    891|	starcos_ex_data *ex_data;
  362|       |
  363|    891|	ex_data = calloc(1, sizeof(starcos_ex_data));
  364|    891|	if (ex_data == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 891]
  ------------------
  365|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  366|       |
  367|    891|	card->name = "STARCOS";
  368|    891|	card->cla  = 0x00;
  369|    891|	card->drv_data = (void *)ex_data;
  370|    891|	ex_data->pin_encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    891|#define PIN_ENCODING_DETERMINE	0
  ------------------
  371|       |
  372|    891|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    891|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    891|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    891|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  373|    891|		| SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|    891|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  374|    891|		| SC_ALGORITHM_RSA_PAD_ISO9796
  ------------------
  |  |  106|    891|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  375|    891|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|    891|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  376|    891|		| SC_ALGORITHM_RSA_HASH_SHA1
  ------------------
  |  |  134|    891|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  377|    891|		| SC_ALGORITHM_RSA_HASH_MD5
  ------------------
  |  |  135|    891|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  378|    891|		| SC_ALGORITHM_RSA_HASH_RIPEMD160
  ------------------
  |  |  137|    891|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  379|    891|		| SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  136|    891|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  380|       |
  381|    891|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    891|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  382|       |
  383|    891|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.78k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    891|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 556, False: 335]
  |  |  |  |  |  Branch (119:65): [True: 0, False: 335]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    335|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 109, False: 226]
  |  |  |  |  |  Branch (120:65): [True: 13, False: 213]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    678|		flags |= SC_CARD_FLAG_RNG
  ------------------
  |  |  536|    678|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  386|    678|			| SC_ALGORITHM_RSA_HASH_SHA224
  ------------------
  |  |  141|    678|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  387|    678|			| SC_ALGORITHM_RSA_HASH_SHA256
  ------------------
  |  |  138|    678|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  388|    678|			| SC_ALGORITHM_RSA_HASH_SHA384
  ------------------
  |  |  139|    678|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  389|    678|			| SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  140|    678|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  390|    678|			| SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|    678|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  391|       |
  392|    678|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  393|    678|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  394|    678|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  395|    678|		_sc_card_add_rsa_alg(card,1728, flags, 0x10001);
  396|    678|		_sc_card_add_rsa_alg(card,1976, flags, 0x10001);
  397|    678|		_sc_card_add_rsa_alg(card,2048, flags, 0x10001);
  398|    678|		if ( IS_V34(card) ) {
  ------------------
  |  |  119|    678|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  ------------------
  |  |  |  Branch (119:22): [True: 556, False: 122]
  |  |  |  Branch (119:65): [True: 0, False: 122]
  |  |  ------------------
  ------------------
  399|    556|			card->name = "STARCOS 3.4";
  400|    556|			card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    556|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  401|    556|		} else {
  402|    122|			card->name = "STARCOS 3.5";
  403|    122|			_sc_card_add_rsa_alg(card,3072, flags, 0x10001);
  404|    122|		}
  405|    678|		card->max_send_size = 255;
  406|    678|		card->max_recv_size = 256;
  407|    678|	} else {
  408|    213|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  409|    213|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  410|    213|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  411|       |
  412|       |		/* we need read_binary&friends with max 128 bytes per read */
  413|    213|		card->max_send_size = 128;
  414|    213|		card->max_recv_size = 128;
  415|    213|	}
  416|       |
  417|    891|	if (sc_parse_ef_atr(card) == SC_SUCCESS) {
  ------------------
  |  |   28|    891|#define SC_SUCCESS				0
  ------------------
  |  Branch (417:6): [True: 88, False: 803]
  ------------------
  418|     88|		size_t max_recv_size = 0;
  419|     88|		size_t max_send_size = 0;
  420|       |
  421|       |		/* Add max. length values from IAS/ECC specific issuer data */
  422|     88|		if ( card->ef_atr->issuer_data_len >= 4 ) {
  ------------------
  |  Branch (422:8): [True: 26, False: 62]
  ------------------
  423|     26|			max_recv_size = bebytes2ushort(card->ef_atr->issuer_data);
  424|     26|			max_send_size = bebytes2ushort(card->ef_atr->issuer_data + 2);
  425|     26|		}
  426|       |		/* which could be overridden with ISO7816 EF.ATR options, if present */
  427|     88|		if (card->ef_atr->max_response_apdu > 0) {
  ------------------
  |  Branch (427:7): [True: 9, False: 79]
  ------------------
  428|      9|			max_recv_size = card->ef_atr->max_response_apdu;
  429|      9|		}
  430|     88|		if (card->ef_atr->max_command_apdu > 0) {
  ------------------
  |  Branch (430:7): [True: 9, False: 79]
  ------------------
  431|      9|			max_send_size = card->ef_atr->max_command_apdu;
  432|      9|		}
  433|       |
  434|     88|		if ( max_send_size > 256 && max_recv_size > 256 ) {
  ------------------
  |  Branch (434:8): [True: 31, False: 57]
  |  Branch (434:31): [True: 18, False: 13]
  ------------------
  435|     18|			size_t max_recv_size_prev = card->max_recv_size;
  436|     18|			size_t max_send_size_prev = card->max_send_size;
  437|       |			/* allow SC_CARD_CAP_APDU_EXT independent of ef_atr->caps, see IAS/ECC issuer data above */
  438|     18|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     18|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  439|       |			/* the received data should not exceed max_recv_size including the sw1/sw2 */
  440|     18|			card->max_recv_size = max_recv_size - 2;
  441|       |			/* the sent APDU should not exceed max_send_size including the 4 bytes of the APDU and 2 * 3 bytes Lc/Le */
  442|     18|			card->max_send_size = max_send_size - 10;
  443|       |			/* probe reader for extended APDU support */
  444|     18|			if ( starcos_probe_reader_for_ext_apdu(card) ) {
  ------------------
  |  Branch (444:9): [True: 2, False: 16]
  ------------------
  445|      2|				sc_log(card->ctx, "Successfully probed extended APDU, enabling extended APDU with max send/recv %d/%d",
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  446|      2|					(int)card->max_send_size, (int)card->max_recv_size);
  447|     16|			} else {
  448|     16|				card->caps &= ~(SC_CARD_CAP_APDU_EXT);
  ------------------
  |  |  547|     16|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  449|     16|				card->max_recv_size = max_recv_size_prev;
  450|     16|				card->max_send_size = max_send_size_prev;
  451|     16|				sc_log(card->ctx, "Ext APDU probing failed, the actual reader does not support ext APDU");
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  452|     16|			}
  453|     18|		}
  454|     88|	}
  455|       |
  456|    891|	if ( ex_data->pin_encoding == PIN_ENCODING_DETERMINE ) {
  ------------------
  |  |   96|    891|#define PIN_ENCODING_DETERMINE	0
  ------------------
  |  Branch (456:7): [True: 891, False: 0]
  ------------------
  457|       |		// about to determine PIN encoding
  458|    891|		ex_data->pin_encoding = starcos_determine_pin_encoding(card);
  459|    891|	}
  460|       |
  461|    891|	if ( card->type == SC_CARD_TYPE_STARCOS_V3_4 && starcos_has_esign_app(card) ) {
  ------------------
  |  Branch (461:7): [True: 556, False: 335]
  |  Branch (461:50): [True: 76, False: 480]
  ------------------
  462|     76|		card->type = SC_CARD_TYPE_STARCOS_V3_4_ESIGN;
  463|     76|		sc_log(card->ctx, "Card has eSign app, card type changed to %d", card->type);
  ------------------
  |  |   71|     76|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|     76|	}
  465|       |
  466|    891|	return 0;
  467|    891|}
card-starcos.c:starcos_probe_reader_for_ext_apdu:
  301|     18|static int starcos_probe_reader_for_ext_apdu(sc_card_t * card) {
  302|     18|	sc_apdu_t apdu;
  303|     18|	int rv;
  304|       |	/* try to read STARCOS3X_PROBE_APDU_LENGTH bytes */
  305|     18|	u8 data[STARCOS3X_PROBE_APDU_LENGTH];
  306|       |
  307|       |	/* Get Data: Get Chip Serial Number */
  308|     18|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_EXT, 0xCA, 0x9F, 0x6C);
  ------------------
  |  |  297|     18|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|     18|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     18|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  309|     18|	apdu.cla = 0xA0;
  310|     18|	apdu.resp = data;
  311|     18|	apdu.resplen = sizeof(data);
  312|     18|	apdu.le = apdu.resplen;
  313|     18|	rv = sc_transmit_apdu(card, &apdu);
  314|     18|	LOG_TEST_RET(card->ctx, rv, "Failed to send Get Data ext. APDU");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|     17|	return (apdu.sw1 == 0x90 && apdu.sw2 == 0x00);
  ------------------
  |  Branch (315:10): [True: 2, False: 15]
  |  Branch (315:30): [True: 1, False: 1]
  ------------------
  316|     18|}
card-starcos.c:starcos_determine_pin_encoding:
  269|    891|{
  270|    891|	unsigned int pin_format = PIN_FORMAT_DEFAULT;
  ------------------
  |  |  107|    891|#define PIN_FORMAT_DEFAULT		PIN_FORMAT_F2
  |  |  ------------------
  |  |  |  |  101|    891|#define PIN_FORMAT_F2			0x12
  |  |  ------------------
  ------------------
  271|    891|	unsigned int encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    891|#define PIN_ENCODING_DETERMINE	0
  ------------------
  272|       |
  273|    891|	if ( IS_V34(card) ) {
  ------------------
  |  |  119|    891|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  ------------------
  |  |  |  Branch (119:22): [True: 556, False: 335]
  |  |  |  Branch (119:65): [True: 0, False: 335]
  |  |  ------------------
  ------------------
  274|    556|		starcos_determine_pin_format34(card, &pin_format);
  275|    556|	} else if ( IS_V35(card) ) {
  ------------------
  |  |  120|    335|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  ------------------
  |  |  |  Branch (120:22): [True: 109, False: 226]
  |  |  |  Branch (120:65): [True: 13, False: 213]
  |  |  ------------------
  ------------------
  276|    122|		starcos_determine_pin_format35(card, &pin_format);
  277|    122|	}
  278|       |
  279|    891|	switch (pin_format) {
  ------------------
  |  Branch (279:10): [True: 888, False: 3]
  ------------------
  280|      1|	case PIN_FORMAT_PW_ASCII:
  ------------------
  |  |  105|      1|#define PIN_FORMAT_PW_ASCII		0x21
  ------------------
  |  Branch (280:2): [True: 1, False: 890]
  ------------------
  281|      2|	case PIN_FORMAT_ASCII:
  ------------------
  |  |  104|      2|#define PIN_FORMAT_ASCII		0x14
  ------------------
  |  Branch (281:2): [True: 1, False: 890]
  ------------------
  282|      2|		encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      2|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  283|      2|		break;
  284|      1|	case PIN_FORMAT_BCD:
  ------------------
  |  |  103|      1|#define PIN_FORMAT_BCD			0x13
  ------------------
  |  Branch (284:2): [True: 1, False: 890]
  ------------------
  285|      1|		encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      1|#define SC_PIN_ENCODING_BCD	1
  ------------------
  286|      1|		break;
  287|      1|	case PIN_FORMAT_F1:
  ------------------
  |  |  100|      1|#define PIN_FORMAT_F1			0x11
  ------------------
  |  Branch (287:2): [True: 1, False: 890]
  ------------------
  288|    885|	case PIN_FORMAT_F2:
  ------------------
  |  |  101|    885|#define PIN_FORMAT_F2			0x12
  ------------------
  |  Branch (288:2): [True: 884, False: 7]
  ------------------
  289|    885|		encoding = SC_PIN_ENCODING_GLP;
  ------------------
  |  |  427|    885|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  290|    885|		break;
  291|    891|	}
  292|       |
  293|    891|	sc_log(card->ctx, "Determined PIN encoding: %d", encoding);
  ------------------
  |  |   71|    891|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  294|    891|	return encoding;
  295|    891|}
card-starcos.c:starcos_determine_pin_format34:
  189|    556|{
  190|    556|	struct sc_context *ctx = card->ctx;
  191|    556|	struct sc_path path;
  192|    556|	struct sc_file *file;
  193|    556|	unsigned char buf[256];
  194|    556|	int rv;
  195|    556|	int retval = SC_SUCCESS;
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
  196|    556|	int rec_no=1;
  197|       |
  198|    556|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    556|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    556|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    556|	sc_format_path(starcos_ef_pwdd, &path);
  201|    556|	rv = sc_select_file(card, &path, &file);
  202|    556|	LOG_TEST_RET(ctx, rv, "Cannot select EF.PWDD file");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 475, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|    475|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    475|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    475|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    475|		return _ret; \
  |  |  |  |  172|    475|	} \
  |  |  |  |  173|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|       |
  204|     81|	if ( (rv = sc_read_record(card, rec_no, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1298|     81|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (204:7): [True: 23, False: 58]
  ------------------
  205|     23|		starcos_ctrl_ref_template ctrl_ref_template;
  206|     23|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  207|     23|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  208|     23|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
  |  Branch (208:8): [True: 5, False: 18]
  ------------------
  209|      5|			*pin_format = ctrl_ref_template.transmission_format;
  210|      5|			sc_log(ctx, "Determined StarCOS 3.4 PIN format: 0x%x", *pin_format);
  ------------------
  |  |   71|      5|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  211|     18|		} else {
  212|     18|			sc_log(ctx, "Failed to parse record %d of EF.PWD, err=%d", rec_no, rv);
  ------------------
  |  |   71|     18|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  213|     18|			retval = rv;
  214|     18|		}
  215|     58|	} else {
  216|     58|		sc_log(ctx, "Failed to read record %d of EF.PWDD, err=%d", rec_no, rv);
  ------------------
  |  |   71|     58|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  217|     58|		retval = rv;
  218|     58|	}
  219|       |
  220|     81|	sc_file_free(file);
  221|     81|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  164|     81|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     81|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     81|	int _ret = r; \
  |  |  |  |  155|     81|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     73|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 73, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     81|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|     81|}
card-starcos.c:starcos_parse_supported_sec_mechanisms:
  158|  1.87k|{
  159|  1.87k|	struct sc_context *ctx = card->ctx;
  160|  1.87k|	const unsigned char *supported_sec_mechanisms_tag = NULL;
  161|  1.87k|	size_t taglen;
  162|       |
  163|  1.87k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.87k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.87k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.87k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.87k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|  1.87k|	supported_sec_mechanisms_tag = sc_asn1_find_tag(ctx, buf, buflen, TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag, &taglen);
  ------------------
  |  |  146|  1.87k|#define TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag		0x7B
  ------------------
  166|  1.87k|	if (supported_sec_mechanisms_tag != NULL && taglen >= 1)   {
  ------------------
  |  Branch (166:6): [True: 1.33k, False: 538]
  |  Branch (166:46): [True: 1.04k, False: 289]
  ------------------
  167|  1.04k|		const unsigned char *tx_fmt_tag = NULL;
  168|  1.04k|		const unsigned char *ctrl_ref_template_tag = NULL;
  169|  1.04k|		size_t supported_sec_mechanisms_taglen = taglen;
  170|       |
  171|       |		// control-reference template is either included in the supported security mechanisms tag or it can be the CRT tag itself (EF.PWDD)
  172|  1.04k|		ctrl_ref_template_tag = sc_asn1_find_tag(ctx, supported_sec_mechanisms_tag, taglen, TAG_STARCOS3X_CTRL_REF_TEMPLATE, &taglen);
  ------------------
  |  |  147|  1.04k|#define TAG_STARCOS3X_CTRL_REF_TEMPLATE				0xA4
  ------------------
  173|  1.04k|		if ( ctrl_ref_template_tag == NULL || taglen == 0 ) {
  ------------------
  |  Branch (173:8): [True: 637, False: 410]
  |  Branch (173:41): [True: 399, False: 11]
  ------------------
  174|  1.03k|			ctrl_ref_template_tag = supported_sec_mechanisms_tag;
  175|  1.03k|			taglen = supported_sec_mechanisms_taglen;
  176|  1.03k|		}
  177|       |
  178|  1.04k|		tx_fmt_tag = sc_asn1_find_tag(ctx, ctrl_ref_template_tag, taglen, TAG_STARCOS3X_TRANSMISSION_FORMAT, &taglen);
  ------------------
  |  |  148|  1.04k|#define TAG_STARCOS3X_TRANSMISSION_FORMAT			0x89
  ------------------
  179|  1.04k|		if ( tx_fmt_tag != NULL && taglen >= 1 ) {
  ------------------
  |  Branch (179:8): [True: 8, False: 1.03k]
  |  Branch (179:30): [True: 7, False: 1]
  ------------------
  180|      7|			ctrl_ref_template->transmission_format = *(tx_fmt_tag + 0);
  181|      7|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|      7|		}
  183|  1.04k|	}
  184|       |
  185|  1.86k|	LOG_FUNC_RETURN(ctx, SC_ERROR_TEMPLATE_NOT_FOUND);
  ------------------
  |  |  164|  1.86k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.86k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.86k|	int _ret = r; \
  |  |  |  |  155|  1.86k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.86k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.86k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.86k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.86k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.86k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.86k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.86k|	return _ret; \
  |  |  |  |  163|  1.86k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  186|  1.86k|}
card-starcos.c:starcos_determine_pin_format35:
  225|    122|{
  226|    122|	struct sc_context *ctx = card->ctx;
  227|    122|	struct sc_path path;
  228|    122|	struct sc_file *file;
  229|    122|	unsigned char buf[256];
  230|    122|	int rv;
  231|    122|	int retval = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|    122|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  232|    122|	int rec_no=1;
  233|    122|	starcos_ctrl_ref_template ctrl_ref_template;
  234|       |
  235|    122|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    122|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    122|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    122|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    122|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|    122|	sc_format_path(starcos_ef_keyd, &path);
  238|    122|	rv = sc_select_file(card, &path, &file);
  239|    122|	LOG_TEST_RET(ctx, rv, "Cannot select EF.KEYD file");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|       |
  241|  4.39k|	while ( (rv = sc_read_record(card, rec_no++, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1298|  4.39k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (241:10): [True: 4.30k, False: 92]
  ------------------
  242|  4.30k|		if ( buf[0] != TAG_STARCOS35_PIN_REFERENCE ) continue;
  ------------------
  |  |  145|  4.30k|#define TAG_STARCOS35_PIN_REFERENCE					0x88
  ------------------
  |  Branch (242:8): [True: 2.45k, False: 1.85k]
  ------------------
  243|       |
  244|  1.85k|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  245|  1.85k|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  246|  1.85k|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|  1.85k|#define SC_SUCCESS				0
  ------------------
  |  Branch (246:8): [True: 2, False: 1.84k]
  ------------------
  247|      2|			*pin_format = ctrl_ref_template.transmission_format;
  248|      2|			sc_log(ctx, "Determined StarCOS 3.5 PIN format: 0x%x", *pin_format);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  249|      2|			retval = rv;
  250|       |			// assuming that all PINs and PUKs have the same transmission format
  251|      2|			break;
  252|  1.84k|		} else {
  253|  1.84k|			sc_log(ctx, "Failed to parse record %d of EF.KEYD, err=%d", rec_no-1, rv);
  ------------------
  |  |   71|  1.84k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  254|  1.84k|			retval = rv;
  255|  1.84k|		}
  256|  1.85k|	}
  257|       |
  258|     94|	sc_file_free(file);
  259|     94|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  164|     94|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     94|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     94|	int _ret = r; \
  |  |  |  |  155|     94|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 94, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     94|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     92|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 92, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|     94|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     94|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     94|	return _ret; \
  |  |  |  |  163|     94|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|     94|}
card-starcos.c:starcos_has_esign_app:
  339|    556|static int starcos_has_esign_app(sc_card_t * card) {
  340|    556|	static const char * starcos_esign_aid = "A0:00:00:02:45:53:69:67:6E";
  341|    556|	int rv;
  342|       |
  343|    556|	rv = starcos_select_mf(card);
  344|    556|	if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:7): [True: 551, False: 5]
  ------------------
  345|    551|		u8 aid[SC_MAX_PATH_SIZE];
  346|    551|		size_t len = sizeof(aid);
  347|       |
  348|    551|		rv = sc_hex_to_bin(starcos_esign_aid, aid, &len);
  349|    551|		LOG_TEST_RET(card->ctx, rv, "Failed to convert eSing AID");
  ------------------
  |  |  174|    551|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    551|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    551|	int _ret = (r); \
  |  |  |  |  168|    551|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 551]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    551|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 551]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  350|    551|		rv = starcos_select_aid(card, aid, len, NULL);
  351|    551|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    551|#define SC_SUCCESS				0
  ------------------
  |  Branch (351:8): [True: 76, False: 475]
  ------------------
  352|     76|			starcos_select_mf(card);
  353|     76|		}
  354|    551|	}
  355|    556|	return ( rv == SC_SUCCESS );
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
  356|    556|}
card-starcos.c:starcos_select_mf:
  318|    632|static int starcos_select_mf(sc_card_t * card) {
  319|    632|	sc_apdu_t apdu;
  320|    632|	const u8 mf_buf[2] = {0x3f, 0x00};
  321|       |
  322|    632|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    632|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  323|    632|	apdu.le = 0;
  324|    632|	apdu.lc = 2;
  325|    632|	apdu.data    = mf_buf;
  326|    632|	apdu.datalen = 2;
  327|    632|	apdu.resplen = 0;
  328|       |
  329|    632|	return sc_transmit_apdu(card, &apdu);
  330|    632|}
card-starcos.c:starcos_select_aid:
  745|  2.35k|{
  746|  2.35k|	sc_apdu_t apdu;
  747|  2.35k|	int r;
  748|  2.35k|	size_t i = 0;
  749|       |
  750|  2.35k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x04, 0x0C);
  ------------------
  |  |  293|  2.35k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  751|  2.35k|	apdu.lc = len;
  752|  2.35k|	apdu.data = (u8*)aid;
  753|  2.35k|	apdu.datalen = len;
  754|  2.35k|	apdu.resplen = 0;
  755|  2.35k|	apdu.le = 0;
  756|  2.35k|	r = sc_transmit_apdu(card, &apdu);
  757|  2.35k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.35k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.35k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.35k|	int _ret = (r); \
  |  |  |  |  168|  2.35k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 2.34k]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.34k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|       |
  759|       |	/* check return value */
  760|  2.34k|	if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61 )
  ------------------
  |  Branch (760:8): [True: 366, False: 1.97k]
  |  Branch (760:28): [True: 330, False: 36]
  |  Branch (760:49): [True: 2.01k, False: 0]
  ------------------
  761|  2.01k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  2.01k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.01k|	int _ret = r; \
  |  |  155|  2.01k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.01k, False: 0]
  |  |  ------------------
  |  |  156|  2.01k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  2.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.01k, False: 0]
  |  |  ------------------
  |  |  157|  2.01k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.01k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.01k|	return _ret; \
  |  |  163|  2.01k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  762|       |
  763|    330|	if (file_out) {
  ------------------
  |  Branch (763:6): [True: 0, False: 330]
  ------------------
  764|      0|		sc_file_t *file = sc_file_new();
  765|      0|		if (!file)
  ------------------
  |  Branch (765:7): [True: 0, False: 0]
  ------------------
  766|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  768|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  769|      0|		file->path.len = 0;
  770|      0|		file->size = 0;
  771|       |		/* AID */
  772|      0|		for (i = 0; i < len; i++)
  ------------------
  |  Branch (772:15): [True: 0, False: 0]
  ------------------
  773|      0|			file->name[i] = aid[i];
  774|      0|		file->namelen = len;
  775|      0|		file->id = 0x0000;
  776|      0|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  777|       |
  778|      0|		*file_out = file;
  779|      0|	}
  780|    330|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    330|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    330|	int _ret = r; \
  |  |  155|    330|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 330, False: 0]
  |  |  ------------------
  |  |  156|    330|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 330]
  |  |  ------------------
  |  |  157|    330|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    330|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    330|	return _ret; \
  |  |  163|    330|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  781|    330|}
card-starcos.c:starcos_finish:
  470|    891|{
  471|    891|	if (card->drv_data)
  ------------------
  |  Branch (471:6): [True: 891, False: 0]
  ------------------
  472|    891|		free((starcos_ex_data *)card->drv_data);
  473|    891|	return 0;
  474|    891|}
card-starcos.c:starcos_select_file:
  913|  6.75k|{
  914|  6.75k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  915|  6.75k|	int    r, pathtype;
  916|  6.75k|	size_t i, pathlen;
  917|       |
  918|  6.75k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.75k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.75k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.75k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.75k]
  |  |  ------------------
  ------------------
  919|       |
  920|  6.75k|	if ( in_path->len > sizeof(pathbuf) ) {
  ------------------
  |  Branch (920:7): [True: 0, False: 6.75k]
  ------------------
  921|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  922|      0|	}
  923|  6.75k|	memcpy(path, in_path->value, in_path->len);
  924|  6.75k|	pathlen = in_path->len;
  925|  6.75k|	pathtype = in_path->type;
  926|       |
  927|  6.75k|	if (in_path->aid.len) {
  ------------------
  |  Branch (927:6): [True: 57, False: 6.69k]
  ------------------
  928|     57|		if (!pathlen) {
  ------------------
  |  Branch (928:7): [True: 0, False: 57]
  ------------------
  929|      0|			if ( in_path->aid.len > sizeof(pathbuf) ) {
  ------------------
  |  Branch (929:9): [True: 0, False: 0]
  ------------------
  930|      0|				SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  931|      0|			}
  932|      0|			memcpy(path, in_path->aid.value, in_path->aid.len);
  933|      0|			pathlen = in_path->aid.len;
  934|      0|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  935|     57|		} else {
  936|     57|			r = starcos_select_aid(card, in_path->aid.value, in_path->aid.len, NULL);
  937|     57|			LOG_TEST_RET(card->ctx, r, "Could not select AID!");
  ------------------
  |  |  174|     57|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     57|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     57|	int _ret = (r); \
  |  |  |  |  168|     57|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 51, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     51|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     51|		return _ret; \
  |  |  |  |  172|     51|	} \
  |  |  |  |  173|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  938|       |
  939|      6|			if (pathtype == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|      6|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (939:8): [True: 0, False: 6]
  ------------------
  940|      0|				pathtype = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  941|      0|			}
  942|      6|		}
  943|     57|	}
  944|       |
  945|  6.70k|	if (pathtype == SC_PATH_TYPE_FILE_ID)
  ------------------
  |  |  117|  6.70k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (945:6): [True: 0, False: 6.70k]
  ------------------
  946|      0|	{	/* SELECT EF/DF with ID */
  947|       |		/* Select with 2byte File-ID */
  948|      0|		if (pathlen != 2)
  ------------------
  |  Branch (948:7): [True: 0, False: 0]
  ------------------
  949|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  950|      0|		r = starcos_select_fid(card, path[0],
  951|      0|				path[1], path[0] == 0x3F && path[1] == 0x00 ? NULL : file_out, 1);
  ------------------
  |  Branch (951:14): [True: 0, False: 0]
  |  Branch (951:33): [True: 0, False: 0]
  ------------------
  952|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  953|      0|	}
  954|  6.70k|	else if (pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  6.70k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (954:11): [True: 1.74k, False: 4.95k]
  ------------------
  955|  1.74k|	{	/* SELECT DF with AID */
  956|       |		/* Select with 1-16byte Application-ID */
  957|  1.74k|		r = starcos_select_aid(card, pathbuf, pathlen, file_out);
  958|  1.74k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.74k|	int _ret = r; \
  |  |  155|  1.74k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.74k, False: 0]
  |  |  ------------------
  |  |  156|  1.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.49k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.49k, False: 248]
  |  |  ------------------
  |  |  157|  1.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.74k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.74k|	return _ret; \
  |  |  163|  1.74k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  959|  1.74k|	}
  960|  4.95k|	else if (pathtype == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  4.95k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (960:11): [True: 4.95k, False: 0]
  ------------------
  961|  4.95k|	{
  962|  4.95k|		u8 n_pathbuf[SC_MAX_PATH_SIZE];
  963|       |
  964|       |		/* Select with path (sequence of File-IDs) */
  965|       |		/* Starcos (S 2.1 and SPK 2.3) only supports one
  966|       |		 * level of subdirectories, therefore a path is
  967|       |		 * at most 3 FID long (the last one being the FID
  968|       |		 * of a EF) => pathlen must be even and less than 6
  969|       |		 */
  970|  4.95k|		if (pathlen%2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (970:7): [True: 0, False: 4.95k]
  |  Branch (970:25): [True: 1, False: 4.95k]
  |  Branch (970:40): [True: 0, False: 4.95k]
  ------------------
  971|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  972|       |		/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  973|  4.95k|		if (pathlen == 6 && ( path[0] != 0x3f || path[1] != 0x00 ))
  ------------------
  |  Branch (973:7): [True: 310, False: 4.64k]
  |  Branch (973:25): [True: 1, False: 309]
  |  Branch (973:44): [True: 1, False: 308]
  ------------------
  974|      2|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      2|	int _ret = r; \
  |  |  155|      2|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  ------------------
  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  ------------------
  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      2|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      2|	return _ret; \
  |  |  163|      2|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  975|       |
  976|  4.95k|		if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  9.90k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  4.95k|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 2.69k, False: 2.25k]
  |  |  |  |  |  Branch (119:65): [True: 354, False: 1.90k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  1.90k|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 529, False: 1.37k]
  |  |  |  |  |  Branch (120:65): [True: 78, False: 1.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  977|       |			/* unify path (the first FID should be MF) */
  978|  3.65k|			if (path[0] != 0x3f || path[1] != 0x00)
  ------------------
  |  Branch (978:8): [True: 166, False: 3.49k]
  |  Branch (978:27): [True: 0, False: 3.49k]
  ------------------
  979|    166|			{
  980|    166|				n_pathbuf[0] = 0x3f;
  981|    166|				n_pathbuf[1] = 0x00;
  982|    166|				memcpy(n_pathbuf+2, path, pathlen);
  983|    166|				path = n_pathbuf;
  984|    166|				pathlen += 2;
  985|    166|			}
  986|  3.65k|		}
  987|       |
  988|  6.27k|		for ( i=0; i<pathlen-2; i+=2 )
  ------------------
  |  Branch (988:14): [True: 5.05k, False: 1.21k]
  ------------------
  989|  5.05k|		{
  990|  5.05k|			r = starcos_select_fid(card, path[i], path[i+1], NULL, 0);
  991|  5.05k|			LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|  5.05k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.05k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.05k|	int _ret = (r); \
  |  |  |  |  168|  5.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.74k, False: 1.31k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.74k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.74k|		return _ret; \
  |  |  |  |  172|  3.74k|	} \
  |  |  |  |  173|  5.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.31k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|  5.05k|		}
  993|  1.21k|		r = starcos_select_fid(card, path[pathlen-2], path[pathlen-1], file_out, 1);
  994|  1.21k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.21k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.21k|	int _ret = r; \
  |  |  155|  1.21k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.21k, False: 0]
  |  |  ------------------
  |  |  156|  1.21k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    407|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 407, False: 807]
  |  |  ------------------
  |  |  157|  1.21k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.21k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.21k|	return _ret; \
  |  |  163|  1.21k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  995|  1.21k|	}
  996|      0|	else
  997|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  998|  6.70k|}
card-starcos.c:starcos_select_fid:
  786|  6.27k|{
  787|  6.27k|	sc_apdu_t apdu;
  788|  6.27k|	u8 data[] = {id_hi & 0xff, id_lo & 0xff};
  789|  6.27k|	u8 resp[SC_MAX_APDU_BUFFER_SIZE];
  790|  6.27k|	int bIsDF = 0, r;
  791|  6.27k|	int isFCP = 0;
  792|  6.27k|	int isMF = 0;
  793|       |
  794|       |	/* request FCI to distinguish between EFs and DFs */
  795|  6.27k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  6.27k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  796|  6.27k|	apdu.p2   = 0x00;
  797|  6.27k|	apdu.resp = (u8*)resp;
  798|  6.27k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  6.27k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  799|  6.27k|	apdu.le = 256;
  800|  6.27k|	apdu.lc = 2;
  801|  6.27k|	apdu.data = (u8*)data;
  802|  6.27k|	apdu.datalen = 2;
  803|       |
  804|  6.27k|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  12.5k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  6.27k|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 3.31k, False: 2.95k]
  |  |  |  |  |  Branch (119:65): [True: 518, False: 2.43k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  2.43k|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 657, False: 1.78k]
  |  |  |  |  |  Branch (120:65): [True: 107, False: 1.67k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|  4.60k|		if (id_hi == 0x3f && id_lo == 0x0) {
  ------------------
  |  Branch (805:7): [True: 3.65k, False: 942]
  |  Branch (805:24): [True: 3.65k, False: 0]
  ------------------
  806|  3.65k|			apdu.p1 = 0x0;
  807|  3.65k|			apdu.p2 = 0x0C;
  808|  3.65k|			apdu.le = 0;
  809|  3.65k|			apdu.resplen = 0;
  810|  3.65k|			apdu.resp = NULL;
  811|  3.65k|			apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  3.65k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  812|  3.65k|			isMF = 1;
  813|  3.65k|		} else if (file_out || is_file) {
  ------------------
  |  Branch (813:14): [True: 798, False: 144]
  |  Branch (813:26): [True: 91, False: 53]
  ------------------
  814|       |			// last component (i.e. file or path)
  815|    889|			apdu.p1 = 0x2;
  816|    889|			apdu.p2 = 0x4;
  817|    889|		} else {
  818|       |			// path component
  819|     53|			apdu.p1 = 0x1;
  820|     53|			apdu.p2 = 0x0;
  821|     53|		}
  822|  4.60k|	}
  823|       |
  824|  6.27k|	r = sc_transmit_apdu(card, &apdu);
  825|  6.27k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.27k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.27k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.27k|	int _ret = (r); \
  |  |  |  |  168|  6.27k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 6.24k]
  |  |  |  |  ------------------
  |  |  |  |  169|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     27|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     27|		return _ret; \
  |  |  |  |  172|     27|	} \
  |  |  |  |  173|  6.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.24k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  826|       |
  827|  6.24k|	if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
  ------------------
  |  Branch (827:6): [True: 1.72k, False: 4.52k]
  |  Branch (827:25): [True: 38, False: 1.68k]
  |  Branch (827:45): [True: 21, False: 17]
  ------------------
  828|       |		/* no FCI => we have a DF (see comment in process_fci()) */
  829|     21|		bIsDF = 1;
  830|     21|		apdu.p2 = 0x0C;
  831|     21|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     21|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  832|     21|		apdu.resplen = 0;
  833|     21|		apdu.le = 0;
  834|     21|		r = sc_transmit_apdu(card, &apdu);
  835|     21|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|     21|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     21|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     21|	int _ret = (r); \
  |  |  |  |  168|     21|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  836|  6.22k|	} else if ((IS_V3x(card))
  ------------------
  |  |  121|  6.22k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  6.22k|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 3.29k, False: 2.92k]
  |  |  |  |  |  Branch (119:65): [True: 516, False: 2.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  2.41k|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 656, False: 1.75k]
  |  |  |  |  |  Branch (120:65): [True: 106, False: 1.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  837|  4.57k|			&& apdu.p2 == 0x4 && apdu.sw1 == 0x6a && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (837:7): [True: 884, False: 3.69k]
  |  Branch (837:25): [True: 186, False: 698]
  |  Branch (837:45): [True: 167, False: 19]
  ------------------
  838|       |		/* not a file, could be a path */
  839|    167|		bIsDF = 1;
  840|    167|		apdu.p1 = 0x1;
  841|    167|		apdu.p2 = 0x0;
  842|    167|		apdu.resplen = sizeof(resp);
  843|    167|		apdu.le = 256;
  844|    167|		apdu.lc = 2;
  845|    167|		r = sc_transmit_apdu(card, &apdu);
  846|    167|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|    167|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    167|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    167|	int _ret = (r); \
  |  |  |  |  168|    167|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 152]
  |  |  |  |  ------------------
  |  |  |  |  169|     15|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     15|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     15|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     15|		return _ret; \
  |  |  |  |  172|     15|	} \
  |  |  |  |  173|    167|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 152]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  847|  6.05k|	} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && !isMF)) {
  ------------------
  |  Branch (847:13): [True: 0, False: 6.05k]
  |  Branch (847:34): [True: 2.31k, False: 3.74k]
  |  Branch (847:54): [True: 2.22k, False: 91]
  |  Branch (847:74): [True: 1.31k, False: 909]
  ------------------
  848|       |		/* SELECT returned some data (possible FCI) =>
  849|       |		 * try a READ BINARY to see if a EF is selected */
  850|  1.31k|		sc_apdu_t apdu2;
  851|  1.31k|		u8 resp2[2];
  852|  1.31k|		sc_format_apdu(card, &apdu2, SC_APDU_CASE_2_SHORT, 0xB0, 0, 0);
  ------------------
  |  |  292|  1.31k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  853|  1.31k|		apdu2.resp = (u8*)resp2;
  854|  1.31k|		apdu2.resplen = 2;
  855|  1.31k|		apdu2.le = 1;
  856|  1.31k|		apdu2.lc = 0;
  857|  1.31k|		r = sc_transmit_apdu(card, &apdu2);
  858|  1.31k|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.31k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.31k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.31k|	int _ret = (r); \
  |  |  |  |  168|  1.31k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 1.30k]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|  1.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|  1.30k|		if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86) {
  ------------------
  |  Branch (859:7): [True: 157, False: 1.14k]
  |  Branch (859:28): [True: 129, False: 28]
  ------------------
  860|       |			/* no current EF is selected => we have a DF */
  861|    129|			bIsDF = 1;
  862|  1.17k|		} else {
  863|  1.17k|			isFCP = 1;
  864|  1.17k|		}
  865|  1.30k|	}
  866|       |
  867|  6.20k|	if (apdu.sw1 != 0x61 && (apdu.sw1 != 0x90 || apdu.sw2 != 0x00))
  ------------------
  |  Branch (867:6): [True: 6.20k, False: 0]
  |  Branch (867:27): [True: 3.75k, False: 2.44k]
  |  Branch (867:47): [True: 95, False: 2.35k]
  ------------------
  868|  3.85k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  3.85k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.85k|	int _ret = r; \
  |  |  155|  3.85k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.85k, False: 0]
  |  |  ------------------
  |  |  156|  3.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  3.85k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.85k, False: 0]
  |  |  ------------------
  |  |  157|  3.85k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.85k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  3.85k|	return _ret; \
  |  |  163|  3.85k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  869|       |
  870|  2.35k|	if (file_out) {
  ------------------
  |  Branch (870:6): [True: 827, False: 1.52k]
  ------------------
  871|    827|		sc_file_t *file = sc_file_new();
  872|    827|		if (!file)
  ------------------
  |  Branch (872:7): [True: 0, False: 827]
  ------------------
  873|    827|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  874|    827|		file->id = (id_hi << 8) + id_lo;
  875|       |
  876|    827|		if (bIsDF || isMF) {
  ------------------
  |  Branch (876:7): [True: 243, False: 584]
  |  Branch (876:16): [True: 0, False: 584]
  ------------------
  877|       |			/* we have a DF */
  878|    243|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    243|#define SC_FILE_TYPE_DF			0x04
  ------------------
  879|    243|			file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    243|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  880|    243|			file->size = 0;
  881|    243|			file->namelen = 0;
  882|    243|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    243|#define SC_FILE_MAGIC			0x14426950
  ------------------
  883|    243|			*file_out = file;
  884|    584|		} else {
  885|       |			/* ok, assume we have a EF */
  886|    584|			if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.16k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    584|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 349, False: 235]
  |  |  |  |  |  Branch (119:65): [True: 35, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    200|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 18, False: 182]
  |  |  |  |  |  Branch (120:65): [True: 21, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  887|    423|				if (isFCP) {
  ------------------
  |  Branch (887:9): [True: 423, False: 0]
  ------------------
  888|    423|					r = process_fcp_v3_4(card->ctx, file, apdu.resp,
  889|    423|							apdu.resplen);
  890|    423|				} else {
  891|      0|					r = process_fci_v3_4(card->ctx, file, apdu.resp,
  892|      0|							apdu.resplen);
  893|      0|				}
  894|    423|			} else {
  895|    161|				r = process_fci(card->ctx, file, apdu.resp,
  896|    161|						apdu.resplen);
  897|    161|			}
  898|    584|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    584|#define SC_SUCCESS				0
  ------------------
  |  Branch (898:8): [True: 228, False: 356]
  ------------------
  899|    228|				sc_file_free(file);
  900|    228|				return r;
  901|    228|			}
  902|       |
  903|    356|			*file_out = file;
  904|    356|		}
  905|    827|	}
  906|       |
  907|  2.12k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|  2.12k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.12k|	int _ret = r; \
  |  |  155|  2.12k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.12k, False: 0]
  |  |  ------------------
  |  |  156|  2.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 2.12k]
  |  |  ------------------
  |  |  157|  2.12k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.12k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.12k|	return _ret; \
  |  |  163|  2.12k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  908|  2.12k|}
card-starcos.c:process_fcp_v3_4:
  605|    423|{
  606|    423|	size_t taglen, len = buflen;
  607|    423|	const u8 *tag = NULL, *p;
  608|       |
  609|    423|	sc_log(ctx, "processing %zu FCP bytes\n", buflen);
  ------------------
  |  |   71|    423|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  610|       |
  611|    423|	if (buflen < 2)
  ------------------
  |  Branch (611:6): [True: 71, False: 352]
  ------------------
  612|     71|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     71|#define SC_ERROR_INTERNAL			-1400
  ------------------
  613|    352|	if (buf[0] != 0x62)
  ------------------
  |  Branch (613:6): [True: 41, False: 311]
  ------------------
  614|     41|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     41|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  615|    311|	len = (size_t)buf[1];
  616|    311|	if (buflen - 2 < len)
  ------------------
  |  Branch (616:6): [True: 13, False: 298]
  ------------------
  617|     13|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     13|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  618|    298|	p = buf + 2;
  619|       |
  620|    298|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  621|    298|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (621:6): [True: 31, False: 267]
  |  Branch (621:21): [True: 16, False: 15]
  ------------------
  622|     16|		int bytes = (tag[0] << 8) + tag[1];
  623|     16|		sc_log(ctx,
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  624|     16|			"  bytes in file: %d\n", bytes);
  625|     16|		file->size = bytes;
  626|     16|	}
  627|       |
  628|    298|	tag = sc_asn1_find_tag(ctx, p, len, 0xc5, &taglen);
  629|    298|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (629:6): [True: 36, False: 262]
  |  Branch (629:21): [True: 17, False: 19]
  ------------------
  630|     17|		int bytes = (tag[0] << 8) + tag[1];
  631|     17|		sc_log(ctx,
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  632|     17|			"  bytes in file 2: %d\n", bytes);
  633|     17|		file->size = bytes;
  634|     17|	}
  635|       |
  636|    298|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  637|    298|	if (tag != NULL) {
  ------------------
  |  Branch (637:6): [True: 82, False: 216]
  ------------------
  638|     82|		const char *type = "unknown";
  639|     82|		const char *structure = "unknown";
  640|       |
  641|     82|		if (taglen >= 1) {
  ------------------
  |  Branch (641:7): [True: 72, False: 10]
  ------------------
  642|     72|			unsigned char byte = tag[0];
  643|     72|			if (byte & 0x40) {
  ------------------
  |  Branch (643:8): [True: 17, False: 55]
  ------------------
  644|     17|				file->shareable = 1;
  645|     17|			}
  646|     72|			if (byte == 0x38) {
  ------------------
  |  Branch (646:8): [True: 11, False: 61]
  ------------------
  647|     11|				type = "DF";
  648|     11|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     11|#define SC_FILE_TYPE_DF			0x04
  ------------------
  649|     11|				file->shareable = 1;
  650|     11|			}
  651|     72|			switch (byte & 7) {
  652|     15|			case 1:
  ------------------
  |  Branch (652:4): [True: 15, False: 57]
  ------------------
  653|       |				/* transparent EF */
  654|     15|				type = "working EF";
  655|     15|				structure = "transparent";
  656|     15|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     15|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  657|     15|				file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     15|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  658|     15|				break;
  659|     10|			case 2:
  ------------------
  |  Branch (659:4): [True: 10, False: 62]
  ------------------
  660|       |				/* linear fixed EF */
  661|     10|				type = "working EF";
  662|     10|				structure = "linear fixed";
  663|     10|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     10|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  664|     10|				file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     10|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  665|     10|				break;
  666|     12|			case 4:
  ------------------
  |  Branch (666:4): [True: 12, False: 60]
  ------------------
  667|       |				/* linear variable EF */
  668|     12|				type = "working EF";
  669|     12|				structure = "linear variable";
  670|     12|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     12|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  671|     12|				file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|     12|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  672|     12|				break;
  673|     11|			case 6:
  ------------------
  |  Branch (673:4): [True: 11, False: 61]
  ------------------
  674|       |				/* cyclic EF */
  675|     11|				type = "working EF";
  676|     11|				structure = "cyclic";
  677|     11|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     11|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  678|     11|				file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|     11|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  679|     11|				break;
  680|     24|			default:
  ------------------
  |  Branch (680:4): [True: 24, False: 48]
  ------------------
  681|       |				/* use defaults from above */
  682|     24|				break;
  683|     72|			}
  684|     72|		}
  685|     82|		sc_log(ctx,
  ------------------
  |  |   71|     82|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  686|     82|			"  type: %s\n", type);
  687|     82|		sc_log(ctx,
  ------------------
  |  |   71|     82|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  688|     82|			"  EF structure: %s\n", structure);
  689|     82|		if (taglen >= 2) {
  ------------------
  |  Branch (689:7): [True: 69, False: 13]
  ------------------
  690|     69|			if (tag[1] != 0x41 || taglen != 5) {
  ------------------
  |  Branch (690:8): [True: 41, False: 28]
  |  Branch (690:26): [True: 21, False: 7]
  ------------------
  691|     62|				SC_FUNC_RETURN(ctx, 2,SC_ERROR_INVALID_DATA);
  ------------------
  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     62|	int _ret = r; \
  |  |  155|     62|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  ------------------
  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     62|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 62, False: 0]
  |  |  ------------------
  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     62|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     62|	return _ret; \
  |  |  163|     62|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  692|     62|			}
  693|       |			/* formatted EF */
  694|      7|			file->record_length = (tag[2] << 8) + tag[3];
  695|      7|			file->record_count = tag[4];
  696|      7|			sc_log(ctx, "  rec_len: %zu  rec_cnt: %zu", file->record_length, file->record_count);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  697|      7|		}
  698|     82|	}
  699|       |
  700|    236|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
  701|    236|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (701:6): [True: 36, False: 200]
  |  Branch (701:21): [True: 12, False: 24]
  ------------------
  702|     12|		file->id = (tag[0] << 8) | tag[1];
  703|     12|		sc_log(ctx,  "  file identifier: 0x%02X%02X\n",
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  704|     12|			tag[0], tag[1]);
  705|     12|	}
  706|       |
  707|    236|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
  708|    236|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (708:6): [True: 32, False: 204]
  |  Branch (708:21): [True: 22, False: 10]
  |  Branch (708:35): [True: 12, False: 10]
  ------------------
  709|     12|		memcpy(file->name, tag, taglen);
  710|     12|		file->namelen = taglen;
  711|     12|		sc_log(ctx,  "  filename %s",
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  712|     12|			sc_dump_hex(file->name, file->namelen));
  713|     12|	}
  714|       |
  715|    236|	tag = sc_asn1_find_tag(ctx, p, len, 0x8a, &taglen);
  716|    236|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (716:6): [True: 67, False: 169]
  |  Branch (716:21): [True: 56, False: 11]
  ------------------
  717|     56|		char* status = "unknown";
  718|     56|		switch (tag[0]) {
  719|     10|		case 1:
  ------------------
  |  Branch (719:3): [True: 10, False: 46]
  ------------------
  720|     10|			status = "creation";
  721|     10|			file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     10|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  722|     10|			break;
  723|     10|		case 5:
  ------------------
  |  Branch (723:3): [True: 10, False: 46]
  ------------------
  724|     10|			status = "operational active";
  725|     10|			file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     10|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  726|     10|			break;
  727|     10|		case 12:
  ------------------
  |  Branch (727:3): [True: 10, False: 46]
  ------------------
  728|     20|		case 13:
  ------------------
  |  Branch (728:3): [True: 10, False: 46]
  ------------------
  729|     20|			status = "creation";
  730|     20|			file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     20|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  731|     20|			break;
  732|     16|		default:
  ------------------
  |  Branch (732:3): [True: 16, False: 40]
  ------------------
  733|     16|			break;
  734|     56|		}
  735|     56|		sc_log(ctx,  "  file status: %s\n", status);
  ------------------
  |  |   71|     56|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  736|     56|	}
  737|       |
  738|    236|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    236|#define SC_FILE_MAGIC			0x14426950
  ------------------
  739|    236|	return SC_SUCCESS;
  ------------------
  |  |   28|    236|#define SC_SUCCESS				0
  ------------------
  740|    236|}
card-starcos.c:process_fci:
  478|    161|{
  479|       |	/* NOTE: According to the Starcos S 2.1 manual it's possible
  480|       |	 *       that a SELECT DF returns as a FCI arbitrary data which
  481|       |	 *       is stored in a object file (in the corresponding DF)
  482|       |	 *       with the tag 0x6f.
  483|       |	 */
  484|       |
  485|    161|	size_t taglen, len = buflen;
  486|    161|	const u8 *tag = NULL, *p;
  487|       |
  488|    161|	sc_log(ctx,  "processing FCI bytes\n");
  ------------------
  |  |   71|    161|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  489|       |
  490|    161|	if (buflen < 2)
  ------------------
  |  Branch (490:6): [True: 19, False: 142]
  ------------------
  491|     19|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     19|#define SC_ERROR_INTERNAL			-1400
  ------------------
  492|    142|	if (buf[0] != 0x6f)
  ------------------
  |  Branch (492:6): [True: 19, False: 123]
  ------------------
  493|     19|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     19|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  494|    123|	len = (size_t)buf[1];
  495|    123|	if (buflen - 2 < len)
  ------------------
  |  Branch (495:6): [True: 3, False: 120]
  ------------------
  496|      3|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  497|    120|	p = buf + 2;
  498|       |
  499|       |	/* defaults */
  500|    120|	file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    120|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  501|    120|	file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    120|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  502|    120|	file->shareable = 0;
  503|    120|	file->record_length = 0;
  504|    120|	file->size = 0;
  505|       |
  506|    120|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  507|    120|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (507:6): [True: 13, False: 107]
  |  Branch (507:21): [True: 10, False: 3]
  ------------------
  508|     10|		int bytes = (tag[0] << 8) + tag[1];
  509|     10|		sc_log(ctx,
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  510|     10|			"  bytes in file: %d\n", bytes);
  511|     10|		file->size = bytes;
  512|     10|	}
  513|       |
  514|    120|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  515|    120|	if (tag != NULL) {
  ------------------
  |  Branch (515:6): [True: 73, False: 47]
  ------------------
  516|     73|		const char *type = "unknown";
  517|     73|		const char *structure = "unknown";
  518|       |
  519|     73|		if (taglen == 1 && tag[0] == 0x01) {
  ------------------
  |  Branch (519:7): [True: 28, False: 45]
  |  Branch (519:22): [True: 10, False: 18]
  ------------------
  520|       |			/* transparent EF */
  521|     10|			type = "working EF";
  522|     10|			structure = "transparent";
  523|     10|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     10|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  524|     10|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     10|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  525|     63|		} else if (taglen == 1 && tag[0] == 0x11) {
  ------------------
  |  Branch (525:14): [True: 18, False: 45]
  |  Branch (525:29): [True: 10, False: 8]
  ------------------
  526|       |			/* object EF */
  527|     10|			type = "working EF";
  528|     10|			structure = "object";
  529|     10|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     10|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  530|     10|			file->ef_structure = SC_FILE_EF_TRANSPARENT; /* TODO */
  ------------------
  |  |  221|     10|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  531|     53|		} else if (taglen == 3 && tag[1] == 0x21) {
  ------------------
  |  Branch (531:14): [True: 44, False: 9]
  |  Branch (531:29): [True: 27, False: 17]
  ------------------
  532|     27|			type = "working EF";
  533|     27|			file->record_length = tag[2];
  534|     27|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     27|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  535|       |			/* linear fixed, cyclic or compute */
  536|     27|			switch ( tag[0] )
  537|     27|			{
  538|     10|				case 0x02:
  ------------------
  |  Branch (538:5): [True: 10, False: 17]
  ------------------
  539|     10|					structure = "linear fixed";
  540|     10|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     10|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  541|     10|					break;
  542|     10|				case 0x07:
  ------------------
  |  Branch (542:5): [True: 10, False: 17]
  ------------------
  543|     10|					structure = "cyclic";
  544|     10|					file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|     10|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  545|     10|					break;
  546|      1|				case 0x17:
  ------------------
  |  Branch (546:5): [True: 1, False: 26]
  ------------------
  547|      1|					structure = "compute";
  548|      1|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      1|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  549|      1|					break;
  550|      6|				default:
  ------------------
  |  Branch (550:5): [True: 6, False: 21]
  ------------------
  551|      6|					structure = "unknown";
  552|      6|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      6|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  553|      6|					file->record_length = 0;
  554|      6|					break;
  555|     27|			}
  556|     27|		}
  557|       |
  558|     73|		sc_log(ctx,
  ------------------
  |  |   71|     73|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  559|     73|			"  type: %s\n", type);
  560|     73|		sc_log(ctx,
  ------------------
  |  |   71|     73|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  561|     73|			"  EF structure: %s\n", structure);
  562|     73|	}
  563|    120|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    120|#define SC_FILE_MAGIC			0x14426950
  ------------------
  564|       |
  565|    120|	return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  566|    120|}
card-starcos.c:starcos_check_sw:
 1941|  15.5k|{
 1942|  15.5k|	const int err_count = sizeof(starcos_errors)/sizeof(starcos_errors[0]);
 1943|  15.5k|	int i;
 1944|       |
 1945|  15.5k|	sc_log(card->ctx,
  ------------------
  |  |   71|  15.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1946|  15.5k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
 1947|       |
 1948|  15.5k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (1948:6): [True: 8.21k, False: 7.32k]
  |  Branch (1948:21): [True: 7.85k, False: 358]
  ------------------
 1949|  7.85k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.85k|#define SC_SUCCESS				0
  ------------------
 1950|  7.68k|	if (sw1 == 0x63 && (sw2 & ~0x0fU) == 0xc0 )
  ------------------
  |  Branch (1950:6): [True: 40, False: 7.64k]
  |  Branch (1950:21): [True: 19, False: 21]
  ------------------
 1951|     19|	{
 1952|     19|		sc_log(card->ctx,  "Verification failed (remaining tries: %d)\n",
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1953|     19|		(sw2 & 0x0f));
 1954|     19|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     19|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 1955|     19|	}
 1956|       |
 1957|       |	/* check starcos error messages */
 1958|   114k|	for (i = 0; i < err_count; i++)
  ------------------
  |  Branch (1958:14): [True: 106k, False: 7.59k]
  ------------------
 1959|   106k|		if (starcos_errors[i].SWs == ((sw1 << 8) | sw2))
  ------------------
  |  Branch (1959:7): [True: 68, False: 106k]
  ------------------
 1960|     68|		{
 1961|     68|			sc_log(card->ctx,  "%s\n", starcos_errors[i].errorstr);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1962|     68|			return starcos_errors[i].errorno;
 1963|     68|		}
 1964|       |
 1965|       |	/* iso error */
 1966|  7.59k|	return iso_ops->check_sw(card, sw1, sw2);
 1967|  7.66k|}
card-starcos.c:starcos_set_security_env:
 1538|     43|{
 1539|     43|	u8              *p, *pp;
 1540|     43|	int              r, operation = env->operation;
 1541|     43|	sc_apdu_t   apdu;
 1542|     43|	u8               sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1543|     43|	starcos_ex_data *ex_data = (starcos_ex_data *)card->drv_data;
 1544|       |
 1545|     43|	p     = sbuf;
 1546|       |
 1547|     43|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|     86|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     43|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 20, False: 23]
  |  |  |  |  |  Branch (119:65): [True: 9, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     14|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 0, False: 14]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1548|     29|		u8 algorithm_supported = (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) ||
  ------------------
  |  |  111|     29|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     29|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     29|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1548:28): [True: 28, False: 1]
  ------------------
 1549|      1|								(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS);
  ------------------
  |  |  107|      1|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1549:9): [True: 0, False: 1]
  ------------------
 1550|     29|		if (!algorithm_supported ||
  ------------------
  |  Branch (1550:7): [True: 1, False: 28]
  ------------------
 1551|     28|			!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   58|     28|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1551:4): [True: 0, False: 28]
  |  Branch (1551:50): [True: 0, False: 28]
  ------------------
 1552|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1553|      1|		}
 1554|       |
 1555|       |		/* Tag '84' (length 1) denotes key name or key reference */
 1556|     28|		*p++ = 0x84;
 1557|     28|		*p++ = 0x01;
 1558|     28|		if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|     28|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1558:7): [True: 0, False: 28]
  ------------------
 1559|      0|			*p++ = *env->key_ref | 0x80;
 1560|     28|		} else {
 1561|     28|			*p++ = *env->key_ref;
 1562|     28|		}
 1563|       |
 1564|     28|		switch (operation) {
 1565|     16|			case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     16|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1565:4): [True: 16, False: 12]
  ------------------
 1566|     16|				sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB6);
  ------------------
  |  |  293|     16|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1567|       |
 1568|       |				/* algorithm / cipher selector? */
 1569|       |				/* algorithm: 13.23 PKCS#1 signature with RSA (standard) */
 1570|       |				/* algorithm: 13.33.30 PKCS#1-PSS signature with SHA-256 */
 1571|     16|				*p++ = 0x89;
 1572|     16|				if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  107|     16|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1572:9): [True: 0, False: 16]
  ------------------
 1573|      0|					*p++ = 0x03;
 1574|      0|					*p++ = 0x13;
 1575|      0|					*p++ = 0x33;
 1576|      0|					*p++ = 0x30;
 1577|     16|				} else {
 1578|       |					// fall back, RSA PKCS1 Padding
 1579|     16|					*p++ = 0x02;
 1580|     16|					*p++ = 0x13;
 1581|     16|					*p++ = 0x23;
 1582|     16|				}
 1583|     16|				break;
 1584|       |
 1585|     12|			case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     12|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1585:4): [True: 12, False: 16]
  ------------------
 1586|     12|				sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|     12|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1587|       |
 1588|       |				/* algorithm / cipher selector? */
 1589|       |				/* algorithm: 11.3  Encipherment RSA (standard) */
 1590|       |				/* algorithm: 11.31 Encipherment RSA (standard) with PKCS#1 padding */
 1591|       |				/* algorithm: 11.32 Encipherment RSA OAEP padding */
 1592|     12|				*p++ = 0x89;
 1593|     12|				*p++ = 0x02;
 1594|     12|				*p++ = 0x11;
 1595|     12|				if ( IS_V34(card) )
  ------------------
  |  |  119|     12|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  ------------------
  |  |  |  Branch (119:22): [True: 9, False: 3]
  |  |  |  Branch (119:65): [True: 3, False: 0]
  |  |  ------------------
  ------------------
 1596|     12|					*p++ = 0x30;
 1597|      0|				else
 1598|      0|					*p++ = 0x31;
 1599|     12|				break;
 1600|       |
 1601|      0|			default:
  ------------------
  |  Branch (1601:4): [True: 0, False: 28]
  ------------------
 1602|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1603|      0|						"not supported for STARCOS 3.4 cards");
 1604|      0|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1605|     28|		}
 1606|       |
 1607|     28|		apdu.data    = sbuf;
 1608|     28|		apdu.datalen = p - sbuf;
 1609|     28|		apdu.lc      = p - sbuf;
 1610|     28|		apdu.le      = 0;
 1611|     28|		r = sc_transmit_apdu(card, &apdu);
 1612|     28|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     28|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     28|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     28|	int _ret = (r); \
  |  |  |  |  168|     28|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|     28|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1613:7): [True: 4, False: 24]
  |  Branch (1613:27): [True: 0, False: 24]
  ------------------
 1614|      4|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      4|	int _ret = r; \
  |  |  155|      4|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  ------------------
  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  ------------------
  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      4|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      4|	return _ret; \
  |  |  163|      4|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1615|       |
 1616|     24|		if ((operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |   48|     48|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
              		if ((operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|     13|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1616:8): [True: 13, False: 11]
  |  Branch (1616:46): [True: 0, False: 13]
  ------------------
 1617|     24|			|| (operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |   47|     48|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
              			|| (operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  110|     11|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1617:8): [True: 11, False: 13]
  |  Branch (1617:50): [True: 0, False: 11]
  ------------------
 1618|       |			// input data will be already padded
 1619|      0|			ex_data->fix_digestInfo = 0;
 1620|     24|		} else {
 1621|     24|			ex_data->fix_digestInfo = env->algorithm_flags;
 1622|     24|		}
 1623|     24|		ex_data->sec_ops        = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|     24|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
 1624|     24|		return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
 1625|     28|	}
 1626|       |
 1627|       |	/* copy key reference, if present */
 1628|     14|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|     14|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1628:6): [True: 14, False: 0]
  ------------------
 1629|     14|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|     14|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1629:7): [True: 0, False: 14]
  ------------------
 1630|      0|			*p++ = 0x83;
 1631|     14|		else
 1632|     14|			*p++ = 0x84;
 1633|     14|		*p++ = env->key_ref_len;
 1634|     14|		memcpy(p, env->key_ref, env->key_ref_len);
 1635|     14|		p += env->key_ref_len;
 1636|     14|	}
 1637|     14|	pp = p;
 1638|     14|	if (operation == SC_SEC_OPERATION_DECIPHER){
  ------------------
  |  |   47|     14|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1638:6): [True: 14, False: 0]
  ------------------
 1639|     14|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  110|     14|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1639:7): [True: 13, False: 1]
  ------------------
 1640|     13|			*p++ = 0x80;
 1641|     13|			*p++ = 0x01;
 1642|     13|			*p++ = 0x02;
 1643|     13|		} else
 1644|      1|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1645|     13|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x81,
  ------------------
  |  |  293|     13|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1646|     13|		               0xb8);
 1647|     13|		apdu.data    = sbuf;
 1648|     13|		apdu.datalen = p - sbuf;
 1649|     13|		apdu.lc      = p - sbuf;
 1650|     13|		apdu.le      = 0;
 1651|     13|		r = sc_transmit_apdu(card, &apdu);
 1652|     13|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|     12|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1653:7): [True: 3, False: 9]
  |  Branch (1653:27): [True: 1, False: 8]
  ------------------
 1654|      4|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      4|	int _ret = r; \
  |  |  155|      4|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  ------------------
  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  ------------------
  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      4|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      4|	return _ret; \
  |  |  163|      4|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1655|      8|		return SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 1656|     12|	}
 1657|       |	/* try COMPUTE SIGNATURE */
 1658|      0|	if (operation == SC_SEC_OPERATION_SIGN && (
  ------------------
  |  |   48|      0|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1658:6): [True: 0, False: 0]
  ------------------
 1659|      0|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 ||
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1659:6): [True: 0, False: 0]
  ------------------
 1660|      0|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_ISO9796)) {
  ------------------
  |  |  106|      0|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  |  Branch (1660:6): [True: 0, False: 0]
  ------------------
 1661|      0|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|      0|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1661:7): [True: 0, False: 0]
  ------------------
 1662|      0|			*p++ = 0x80;
 1663|      0|			*p++ = 0x01;
 1664|      0|			*p++ = env->algorithm_ref & 0xFF;
 1665|      0|		} else if (env->flags & SC_SEC_ENV_ALG_PRESENT &&
  ------------------
  |  |   60|      0|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (1665:14): [True: 0, False: 0]
  ------------------
 1666|      0|		            env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1666:15): [True: 0, False: 0]
  ------------------
 1667|       |			/* set the method to use based on the algorithm_flags */
 1668|      0|			*p++ = 0x80;
 1669|      0|			*p++ = 0x01;
 1670|      0|			if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01) {
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1670:8): [True: 0, False: 0]
  ------------------
 1671|      0|				if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1)
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1671:9): [True: 0, False: 0]
  ------------------
 1672|      0|					*p++ = 0x12;
 1673|      0|				else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_RIPEMD160)
  ------------------
  |  |  137|      0|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  |  Branch (1673:14): [True: 0, False: 0]
  ------------------
 1674|      0|					*p++ = 0x22;
 1675|      0|				else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_MD5)
  ------------------
  |  |  135|      0|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  |  Branch (1675:14): [True: 0, False: 0]
  ------------------
 1676|      0|					*p++ = 0x32;
 1677|      0|				else {
 1678|       |					/* can't use COMPUTE SIGNATURE =>
 1679|       |					 * try INTERNAL AUTHENTICATE */
 1680|      0|					p = pp;
 1681|      0|					operation = SC_SEC_OPERATION_AUTHENTICATE;
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
 1682|      0|					goto try_authenticate;
 1683|      0|				}
 1684|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_ISO9796) {
  ------------------
  |  |  106|      0|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  |  Branch (1684:15): [True: 0, False: 0]
  ------------------
 1685|      0|				if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1)
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1685:9): [True: 0, False: 0]
  ------------------
 1686|      0|					*p++ = 0x11;
 1687|      0|				else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_RIPEMD160)
  ------------------
  |  |  137|      0|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  |  Branch (1687:14): [True: 0, False: 0]
  ------------------
 1688|      0|					*p++ = 0x21;
 1689|      0|				else
 1690|      0|					return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1691|      0|			} else
 1692|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1693|      0|		}
 1694|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xb6);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1695|      0|		apdu.data    = sbuf;
 1696|      0|		apdu.datalen = p - sbuf;
 1697|      0|		apdu.lc      = p - sbuf;
 1698|      0|		apdu.le      = 0;
 1699|       |		/* we don't know whether to use
 1700|       |		 * COMPUTE SIGNATURE or INTERNAL AUTHENTICATE */
 1701|      0|		r = sc_transmit_apdu(card, &apdu);
 1702|      0|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|      0|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1703:7): [True: 0, False: 0]
  |  Branch (1703:27): [True: 0, False: 0]
  ------------------
 1704|      0|			ex_data->fix_digestInfo = 0;
 1705|      0|			ex_data->sec_ops        = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|      0|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
 1706|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1707|      0|		}
 1708|       |		/* reset pointer */
 1709|      0|		p = pp;
 1710|       |		/* doesn't work => try next op */
 1711|      0|		operation = SC_SEC_OPERATION_AUTHENTICATE;
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
 1712|      0|	}
 1713|      0|try_authenticate:
 1714|       |	/* try INTERNAL AUTHENTICATE */
 1715|      0|	if (operation == SC_SEC_OPERATION_AUTHENTICATE &&
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1715:6): [True: 0, False: 0]
  ------------------
 1716|      0|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1716:6): [True: 0, False: 0]
  ------------------
 1717|      0|		*p++ = 0x80;
 1718|      0|		*p++ = 0x01;
 1719|      0|		*p++ = 0x01;
 1720|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1721|      0|		               0xa4);
 1722|      0|		apdu.data    = sbuf;
 1723|      0|		apdu.datalen = p - sbuf;
 1724|      0|		apdu.lc      = p - sbuf;
 1725|      0|		apdu.le      = 0;
 1726|      0|		r = sc_transmit_apdu(card, &apdu);
 1727|      0|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1728|      0|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1728:7): [True: 0, False: 0]
  |  Branch (1728:27): [True: 0, False: 0]
  ------------------
 1729|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1730|      0|		ex_data->fix_digestInfo = env->algorithm_flags;
 1731|      0|		ex_data->sec_ops        = SC_SEC_OPERATION_AUTHENTICATE;
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
 1732|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1733|      0|	}
 1734|       |
 1735|      0|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1736|      0|}
card-starcos.c:starcos_compute_signature:
 1741|     13|{
 1742|     13|	int r;
 1743|     13|	sc_apdu_t apdu;
 1744|     13|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1745|     13|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1746|     13|	starcos_ex_data *ex_data = (starcos_ex_data *)card->drv_data;
 1747|       |
 1748|     13|	if (datalen > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|     13|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1748:6): [True: 0, False: 13]
  ------------------
 1749|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1750|       |
 1751|     13|	if (ex_data->sec_ops == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   48|     13|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1751:6): [True: 13, False: 0]
  ------------------
 1752|       |		/* compute signature with the COMPUTE SIGNATURE command */
 1753|       |
 1754|     13|		if ( IS_V3x(card) ) {
  ------------------
  |  |  121|     26|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     13|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 7, False: 6]
  |  |  |  |  |  Branch (119:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|      0|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 0, False: 0]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1755|     13|			size_t tmp_len;
 1756|       |
 1757|     13|			sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A,
  ------------------
  |  |  303|     13|#define SC_APDU_CASE_4			0x24
  ------------------
 1758|     13|					   0x9E, 0x9A);
 1759|     13|			apdu.resp = out;
 1760|     13|			apdu.resplen = outlen;
 1761|     13|			apdu.le = outlen;
 1762|     13|			if (ex_data->fix_digestInfo) {
  ------------------
  |  Branch (1762:8): [True: 13, False: 0]
  ------------------
 1763|       |				// need to pad data
 1764|     13|				unsigned int flags = ex_data->fix_digestInfo & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     13|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
 1765|     13|				if (flags == 0x00) {
  ------------------
  |  Branch (1765:9): [True: 0, False: 13]
  ------------------
 1766|      0|					flags = SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1767|      0|				}
 1768|     13|				tmp_len = sizeof(sbuf);
 1769|     13|				if (ex_data->fix_digestInfo & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  107|     13|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1769:9): [True: 0, False: 13]
  ------------------
 1770|      0|					r = sc_pkcs1_strip_digest_info_prefix(NULL, data, datalen, sbuf, &tmp_len);
 1771|     13|				} else {
 1772|     13|					r = sc_pkcs1_encode(card->ctx, flags, data, datalen, sbuf, &tmp_len, sizeof(sbuf)*8, NULL);
 1773|     13|				}
 1774|     13|				LOG_TEST_RET(card->ctx, r, "sc_pkcs1_encode failed");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1775|     13|			} else {
 1776|      0|				memcpy(sbuf, data, datalen);
 1777|      0|				tmp_len = datalen;
 1778|      0|			}
 1779|       |
 1780|      0|			apdu.data = sbuf;
 1781|      0|			apdu.datalen = tmp_len;
 1782|      0|			apdu.lc = tmp_len;
 1783|       |
 1784|      0|			r = sc_transmit_apdu(card, &apdu);
 1785|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1786|      0|		} else {
 1787|       |			/* set the hash value     */
 1788|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2A,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1789|      0|					   0x90, 0x81);
 1790|      0|			apdu.resp = rbuf;
 1791|      0|			apdu.resplen = sizeof(rbuf);
 1792|      0|			apdu.le = 0;
 1793|      0|			memcpy(sbuf, data, datalen);
 1794|      0|			apdu.data = sbuf;
 1795|      0|			apdu.lc = datalen;
 1796|      0|			apdu.datalen = datalen;
 1797|      0|			r = sc_transmit_apdu(card, &apdu);
 1798|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1799|      0|			if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1799:8): [True: 0, False: 0]
  |  Branch (1799:28): [True: 0, False: 0]
  ------------------
 1800|      0|				SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1801|      0|						   sc_check_sw(card, apdu.sw1, apdu.sw2));
 1802|       |
 1803|       |			/* call COMPUTE SIGNATURE */
 1804|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x2A,
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1805|      0|					   0x9E, 0x9A);
 1806|      0|			apdu.resp = rbuf;
 1807|      0|			apdu.resplen = sizeof(rbuf);
 1808|      0|			apdu.le = 256;
 1809|       |
 1810|      0|			apdu.lc = 0;
 1811|      0|			apdu.datalen = 0;
 1812|      0|			r = sc_transmit_apdu(card, &apdu);
 1813|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1814|      0|		}
 1815|      0|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1815:7): [True: 0, False: 0]
  |  Branch (1815:27): [True: 0, False: 0]
  ------------------
 1816|      0|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1816:17): [True: 0, False: 0]
  ------------------
 1817|      0|			if ( out != apdu.resp ) {
  ------------------
  |  Branch (1817:9): [True: 0, False: 0]
  ------------------
 1818|      0|				memcpy(out, apdu.resp, len);
 1819|      0|			}
 1820|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1821|      0|		}
 1822|      0|	} else if (ex_data->sec_ops == SC_SEC_OPERATION_AUTHENTICATE) {
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1822:13): [True: 0, False: 0]
  ------------------
 1823|      0|		size_t tmp_len;
 1824|      0|		CHECK_NOT_SUPPORTED_V3_4(card);
  ------------------
  |  |  110|      0|	do { \
  |  |  111|      0|		if ((card)->type == SC_CARD_TYPE_STARCOS_V3_4) { \
  |  |  ------------------
  |  |  |  Branch (111:7): [True: 0, False: 0]
  |  |  ------------------
  |  |  112|      0|			sc_log((card)->ctx,  \
  |  |  ------------------
  |  |  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  113|      0|				"not supported for STARCOS 3.4 cards"); \
  |  |  114|      0|			return SC_ERROR_NOT_SUPPORTED; \
  |  |  ------------------
  |  |  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  |  |  ------------------
  |  |  115|      0|		} \
  |  |  116|      0|	} while (0);
  |  |  ------------------
  |  |  |  Branch (116:11): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1825|       |		/* call INTERNAL AUTHENTICATE */
 1826|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x88, 0x10, 0x00);
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1827|       |		/* fix/create DigestInfo structure (if necessary) */
 1828|      0|		if (ex_data->fix_digestInfo) {
  ------------------
  |  Branch (1828:7): [True: 0, False: 0]
  ------------------
 1829|      0|			unsigned int flags = ex_data->fix_digestInfo & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|      0|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
 1830|      0|			if (flags == 0x0)
  ------------------
  |  Branch (1830:8): [True: 0, False: 0]
  ------------------
 1831|       |				/* XXX: assume no hash is wanted */
 1832|      0|				flags = SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1833|      0|			tmp_len = sizeof(sbuf);
 1834|      0|			r = sc_pkcs1_encode(card->ctx, flags, data, datalen,
 1835|      0|					sbuf, &tmp_len, sizeof(sbuf)*8, NULL);
 1836|      0|			if (r < 0)
  ------------------
  |  Branch (1836:8): [True: 0, False: 0]
  ------------------
 1837|      0|				return r;
 1838|      0|		} else {
 1839|      0|			memcpy(sbuf, data, datalen);
 1840|      0|			tmp_len = datalen;
 1841|      0|		}
 1842|      0|		apdu.lc = tmp_len;
 1843|      0|		apdu.data = sbuf;
 1844|      0|		apdu.datalen = tmp_len;
 1845|      0|		apdu.resp = rbuf;
 1846|      0|		apdu.resplen = sizeof(rbuf);
 1847|      0|		apdu.le = 256;
 1848|      0|		r = sc_transmit_apdu(card, &apdu);
 1849|      0|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1850|      0|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1850:7): [True: 0, False: 0]
  |  Branch (1850:27): [True: 0, False: 0]
  ------------------
 1851|      0|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1851:17): [True: 0, False: 0]
  ------------------
 1852|       |
 1853|      0|			memcpy(out, apdu.resp, len);
 1854|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1855|      0|		}
 1856|      0|	} else
 1857|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1858|       |
 1859|       |	/* clear old state */
 1860|      0|	ex_data->sec_ops = 0;
 1861|      0|	ex_data->fix_digestInfo = 0;
 1862|       |
 1863|      0|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1864|      0|}
card-starcos.c:starcos_decipher:
 1869|     19|{
 1870|     19|	int r;
 1871|     19|	size_t card_max_send_size = card->max_send_size;
 1872|     19|	size_t reader_max_send_size = card->reader->max_send_size;
 1873|     19|	size_t card_max_recv_size = card->max_recv_size;
 1874|     19|	size_t reader_max_recv_size = card->reader->max_recv_size;
 1875|       |
 1876|     19|	if (sc_get_max_send_size(card) < crgram_len + 1) {
  ------------------
  |  Branch (1876:6): [True: 1, False: 18]
  ------------------
 1877|       |		/* Starcos doesn't support chaining for PSO:DEC, so we just _hope_
 1878|       |		 * that both, the reader and the card are able to send enough data.
 1879|       |		 * (data is prefixed with 1 byte padding content indicator) */
 1880|      1|		card->max_send_size = crgram_len + 1;
 1881|      1|		card->reader->max_send_size = crgram_len + 1;
 1882|      1|	}
 1883|       |
 1884|     19|	if (sc_get_max_recv_size(card) < outlen) {
  ------------------
  |  Branch (1884:6): [True: 19, False: 0]
  ------------------
 1885|       |		/* Starcos doesn't support get response for PSO:DEC, so we just _hope_
 1886|       |		 * that both, the reader and the card are able to receive enough data.
 1887|       |		 */
 1888|     19|		if (0 == (card->caps & SC_CARD_CAP_APDU_EXT)
  ------------------
  |  |  547|     19|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (1888:7): [True: 19, False: 0]
  ------------------
 1889|     19|				&& outlen > 256) {
  ------------------
  |  Branch (1889:8): [True: 19, False: 0]
  ------------------
 1890|     19|			card->max_recv_size = 256;
 1891|     19|			card->reader->max_recv_size = 256;
 1892|     19|		} else {
 1893|      0|			card->max_recv_size = outlen;
 1894|      0|			card->reader->max_recv_size = outlen;
 1895|      0|		}
 1896|     19|	}
 1897|       |
 1898|     19|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|     38|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     19|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 8, False: 11]
  |  |  |  |  |  Branch (119:65): [True: 3, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|      8|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 0, False: 8]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1899|     11|		sc_apdu_t apdu;
 1900|       |
 1901|     11|		u8 *sbuf = malloc(crgram_len + 1);
 1902|     11|		if (sbuf == NULL)
  ------------------
  |  Branch (1902:7): [True: 0, False: 11]
  ------------------
 1903|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1904|       |
 1905|     11|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     11|#define SC_APDU_CASE_4			0x24
  ------------------
 1906|     11|		apdu.resp    = out;
 1907|     11|		apdu.resplen = outlen;
 1908|     11|		apdu.le      = outlen;
 1909|       |
 1910|     11|		sbuf[0] = 0x81;
 1911|     11|		memcpy(sbuf + 1, crgram, crgram_len);
 1912|     11|		apdu.data = sbuf;
 1913|     11|		apdu.lc = crgram_len + 1;
 1914|     11|		apdu.datalen = crgram_len + 1;
 1915|       |
 1916|     11|		r = sc_transmit_apdu(card, &apdu);
 1917|     11|		sc_mem_clear(sbuf, crgram_len + 1);
 1918|       |
 1919|     11|		free(sbuf);
 1920|       |
 1921|     11|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1922|       |
 1923|      0|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1923:7): [True: 0, False: 0]
  |  Branch (1923:27): [True: 0, False: 0]
  ------------------
 1924|      0|			r = (int)apdu.resplen;
 1925|      0|		else
 1926|      0|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1927|      8|	} else {
 1928|      8|		r = iso_ops->decipher(card, crgram, crgram_len, out, outlen);
 1929|      8|	}
 1930|       |
 1931|       |	/* reset whatever we've modified above */
 1932|      8|	card->max_send_size = card_max_send_size;
 1933|      8|	card->reader->max_send_size = reader_max_send_size;
 1934|      8|	card->max_recv_size = card_max_recv_size;
 1935|      8|	card->reader->max_recv_size = reader_max_recv_size;
 1936|       |
 1937|      8|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1938|      8|}
card-starcos.c:starcos_card_ctl:
 2016|    165|{
 2017|    165|	sc_starcos_create_data *tmp;
 2018|       |
 2019|    165|	switch (cmd)
 2020|    165|	{
 2021|      0|	case SC_CARDCTL_STARCOS_CREATE_FILE:
  ------------------
  |  Branch (2021:2): [True: 0, False: 165]
  ------------------
 2022|      0|		tmp = (sc_starcos_create_data *) ptr;
 2023|      0|		if (tmp->type == SC_STARCOS_MF_DATA)
  ------------------
  |  |  375|      0|#define	SC_STARCOS_MF_DATA	0x01
  ------------------
  |  Branch (2023:7): [True: 0, False: 0]
  ------------------
 2024|      0|			return starcos_create_mf(card, tmp);
 2025|      0|		else if (tmp->type == SC_STARCOS_DF_DATA)
  ------------------
  |  |  376|      0|#define SC_STARCOS_DF_DATA	0x02
  ------------------
  |  Branch (2025:12): [True: 0, False: 0]
  ------------------
 2026|      0|			return starcos_create_df(card, tmp);
 2027|      0|		else if (tmp->type == SC_STARCOS_EF_DATA)
  ------------------
  |  |  377|      0|#define SC_STARCOS_EF_DATA	0x04
  ------------------
  |  Branch (2027:12): [True: 0, False: 0]
  ------------------
 2028|      0|			return starcos_create_ef(card, tmp);
 2029|      0|		else
 2030|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2031|      0|	case SC_CARDCTL_STARCOS_CREATE_END:
  ------------------
  |  Branch (2031:2): [True: 0, False: 165]
  ------------------
 2032|      0|		return starcos_create_end(card, (sc_file_t *)ptr);
 2033|      0|	case SC_CARDCTL_STARCOS_WRITE_KEY:
  ------------------
  |  Branch (2033:2): [True: 0, False: 165]
  ------------------
 2034|      0|		return starcos_write_key(card, (sc_starcos_wkey_data *)ptr);
 2035|      0|	case SC_CARDCTL_STARCOS_GENERATE_KEY:
  ------------------
  |  Branch (2035:2): [True: 0, False: 165]
  ------------------
 2036|      0|		return starcos_gen_key(card, (sc_starcos_gen_key_data *)ptr);
 2037|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (2037:2): [True: 0, False: 165]
  ------------------
 2038|      0|		return starcos_erase_card(card);
 2039|    165|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2039:2): [True: 165, False: 0]
  ------------------
 2040|    165|		return starcos_get_serialnr(card, (sc_serial_number_t *)ptr);
 2041|      0|	default:
  ------------------
  |  Branch (2041:2): [True: 0, False: 165]
  ------------------
 2042|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2043|    165|	}
 2044|    165|}
card-starcos.c:starcos_get_serialnr:
 1970|    165|{
 1971|    165|	int r;
 1972|    165|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1973|    165|	sc_apdu_t apdu;
 1974|       |
 1975|    165|	if (!serial)
  ------------------
  |  Branch (1975:6): [True: 0, False: 165]
  ------------------
 1976|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1977|       |
 1978|       |	/* see if we have cached serial number */
 1979|    165|	if (card->serialnr.len) {
  ------------------
  |  Branch (1979:6): [True: 2, False: 163]
  ------------------
 1980|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1981|      2|		return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 1982|      2|	}
 1983|       |
 1984|    163|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    326|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    163|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 48, False: 115]
  |  |  |  |  |  Branch (119:65): [True: 34, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     81|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 1, False: 80]
  |  |  |  |  |  Branch (120:65): [True: 1, False: 79]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1985|     84|		card->serialnr.len = SC_MAX_SERIALNR;
  ------------------
  |  |  372|     84|#define SC_MAX_SERIALNR         32
  ------------------
 1986|     84|		r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
 1987|     84|		if (r < 0) {
  ------------------
  |  Branch (1987:7): [True: 82, False: 2]
  ------------------
 1988|     82|			card->serialnr.len = 0;
 1989|     82|			return r;
 1990|     82|		}
 1991|     84|	} else {
 1992|       |		/* get serial number via GET CARD DATA */
 1993|     79|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xf6, 0x00, 0x00);
  ------------------
  |  |  292|     79|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1994|     79|		apdu.cla |= 0x80;
 1995|     79|		apdu.resp = rbuf;
 1996|     79|		apdu.resplen = sizeof(rbuf);
 1997|     79|		apdu.le   = 256;
 1998|     79|		apdu.lc   = 0;
 1999|     79|		apdu.datalen = 0;
 2000|     79|		r = sc_transmit_apdu(card, &apdu);
 2001|     79|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     79|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     79|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     79|	int _ret = (r); \
  |  |  |  |  168|     79|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 76]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     79|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2002|     76|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (2002:7): [True: 10, False: 66]
  |  Branch (2002:27): [True: 7, False: 59]
  ------------------
 2003|     17|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     17|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2004|       |		/* cache serial number */
 2005|     59|		memcpy(card->serialnr.value, apdu.resp, MIN(apdu.resplen, SC_MAX_SERIALNR));
  ------------------
  |  |   69|     59|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 55, False: 4]
  |  |  ------------------
  ------------------
 2006|     59|		card->serialnr.len = MIN(apdu.resplen, SC_MAX_SERIALNR);
  ------------------
  |  |   69|     59|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 55, False: 4]
  |  |  ------------------
  ------------------
 2007|     59|	}
 2008|       |
 2009|       |	/* copy and return serial number */
 2010|     61|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2011|       |
 2012|     61|	return SC_SUCCESS;
  ------------------
  |  |   28|     61|#define SC_SUCCESS				0
  ------------------
 2013|    163|}
card-starcos.c:starcos_pin_cmd:
 2081|    125|{
 2082|    125|	int r;
 2083|       |
 2084|    125|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    125|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    125|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    125|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    125|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 125]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2085|    125|	starcos_ex_data * ex_data = (starcos_ex_data*)card->drv_data;
 2086|    125|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    250|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    125|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 64, False: 61]
  |  |  |  |  |  Branch (119:65): [True: 30, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     31|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 1, False: 30]
  |  |  |  |  |  Branch (120:65): [True: 1, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2087|     96|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     96|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2088|     96|		data->pin1.encoding = ex_data->pin_encoding;
 2089|     96|	}
 2090|    125|	r = iso_ops->pin_cmd(card, data);
 2091|    125|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    125|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    125|	int _ret = r; \
  |  |  155|    125|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 125, False: 0]
  |  |  ------------------
  |  |  156|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     59|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 59, False: 66]
  |  |  ------------------
  |  |  157|    125|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    125|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    125|	return _ret; \
  |  |  163|    125|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2092|    125|}

sc_get_tcos_driver:
  720|  15.2k|{
  721|  15.2k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  722|       |
  723|  15.2k|	if (iso_ops == NULL) iso_ops = iso_drv->ops;
  ------------------
  |  Branch (723:6): [True: 1, False: 15.2k]
  ------------------
  724|  15.2k|	tcos_ops = *iso_drv->ops;
  725|       |
  726|  15.2k|	tcos_ops.match_card           = tcos_match_card;
  727|  15.2k|	tcos_ops.init                 = tcos_init;
  728|  15.2k|	tcos_ops.finish               = tcos_finish;
  729|  15.2k|	tcos_ops.create_file          = tcos_create_file;
  730|  15.2k|	tcos_ops.set_security_env     = tcos_set_security_env;
  731|  15.2k|	tcos_ops.select_file          = tcos_select_file;
  732|  15.2k|	tcos_ops.list_files           = tcos_list_files;
  733|  15.2k|	tcos_ops.delete_file          = tcos_delete_file;
  734|  15.2k|	tcos_ops.compute_signature    = tcos_compute_signature;
  735|  15.2k|	tcos_ops.decipher             = tcos_decipher;
  736|  15.2k|	tcos_ops.restore_security_env = tcos_restore_security_env;
  737|  15.2k|	tcos_ops.card_ctl             = tcos_card_ctl;
  738|       |
  739|  15.2k|	return &tcos_drv;
  740|  15.2k|}
card-tcos.c:tcos_match_card:
   77|  12.7k|{
   78|  12.7k|	int i;
   79|       |
   80|  12.7k|	i = _sc_match_atr(card, tcos_atrs, &card->type);
   81|  12.7k|	if (i < 0)
  ------------------
  |  Branch (81:6): [True: 12.0k, False: 714]
  ------------------
   82|  12.0k|		return 0;
   83|    714|	return 1;
   84|  12.7k|}
card-tcos.c:tcos_init:
   88|    714|{
   89|    714|	unsigned long flags;
   90|       |
   91|    714|	tcos_data *data = malloc(sizeof(tcos_data));
   92|    714|	if (!data) return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  |  Branch (92:6): [True: 0, False: 714]
  ------------------
   93|       |
   94|    714|	card->name = "TCOS";
   95|    714|	card->drv_data = (void *)data;
   96|    714|	card->cla = 0x00;
   97|       |
   98|    714|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    714|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   99|    714|	flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    714|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    714|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    714|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  100|    714|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    714|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  101|       |
  102|    714|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  103|    714|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  104|    714|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  105|       |
  106|    714|	if (card->type == SC_CARD_TYPE_TCOS_V3) {
  ------------------
  |  Branch (106:6): [True: 0, False: 714]
  ------------------
  107|      0|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      0|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  108|      0|		_sc_card_add_rsa_alg(card, 1280, flags, 0);
  109|      0|		_sc_card_add_rsa_alg(card, 1536, flags, 0);
  110|      0|		_sc_card_add_rsa_alg(card, 1792, flags, 0);
  111|      0|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  112|      0|	}
  113|       |
  114|    714|	return 0;
  115|    714|}
card-tcos.c:tcos_finish:
   70|    714|{
   71|    714|	free(card->drv_data);
   72|    714|	return 0;
   73|    714|}
card-tcos.c:tcos_select_file:
  336|  6.96k|{
  337|  6.96k|	sc_context_t *ctx;
  338|  6.96k|	sc_apdu_t apdu;
  339|  6.96k|	sc_file_t *file=NULL;
  340|  6.96k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE], pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  341|  6.96k|	int r;
  342|  6.96k|	size_t pathlen;
  343|       |
  344|  6.96k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (344:6): [True: 0, False: 6.96k]
  |  Branch (344:22): [True: 0, False: 6.96k]
  ------------------
  345|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  346|  6.96k|	ctx=card->ctx;
  347|  6.96k|	memcpy(path, in_path->value, in_path->len);
  348|  6.96k|	pathlen = in_path->len;
  349|       |
  350|  6.96k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0x04);
  ------------------
  |  |  294|  6.96k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  351|       |
  352|  6.96k|	switch (in_path->type) {
  353|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (353:2): [True: 0, False: 6.96k]
  ------------------
  354|      0|		if (pathlen != 2) return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  |  Branch (354:7): [True: 0, False: 0]
  ------------------
  355|       |		/* fall through */
  356|      0|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (356:2): [True: 0, False: 6.96k]
  ------------------
  357|      0|		apdu.p1 = 9;
  358|      0|		break;
  359|  1.62k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  1.62k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (359:2): [True: 1.62k, False: 5.34k]
  ------------------
  360|  1.62k|		apdu.p1 = 4;
  361|  1.62k|		break;
  362|  5.34k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  5.34k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (362:2): [True: 5.34k, False: 1.62k]
  ------------------
  363|  5.34k|		apdu.p1 = 8;
  364|  5.34k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) path += 2, pathlen -= 2;
  ------------------
  |  Branch (364:7): [True: 5.34k, False: 0]
  |  Branch (364:23): [True: 2.87k, False: 2.46k]
  ------------------
  365|  5.34k|		if (pathlen == 0) apdu.p1 = 0;
  ------------------
  |  Branch (365:7): [True: 0, False: 5.34k]
  ------------------
  366|  5.34k|		break;
  367|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (367:2): [True: 0, False: 6.96k]
  ------------------
  368|      0|		apdu.p1 = 3;
  369|      0|		pathlen = 0;
  370|      0|		break;
  371|      0|	default:
  ------------------
  |  Branch (371:2): [True: 0, False: 6.96k]
  ------------------
  372|      0|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  373|  6.96k|	}
  374|  6.96k|	if( pathlen == 0 ) apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (374:6): [True: 0, False: 6.96k]
  ------------------
  375|       |
  376|  6.96k|	apdu.lc = pathlen;
  377|  6.96k|	apdu.data = path;
  378|  6.96k|	apdu.datalen = pathlen;
  379|       |
  380|  6.96k|	if (file_out != NULL) {
  ------------------
  |  Branch (380:6): [True: 3.55k, False: 3.40k]
  ------------------
  381|  3.55k|		apdu.resp = buf;
  382|  3.55k|		apdu.resplen = sizeof(buf);
  383|  3.55k|		apdu.le = 256;
  384|  3.55k|	} else {
  385|  3.40k|		apdu.resplen = 0;
  386|  3.40k|		apdu.le = 0;
  387|  3.40k|		apdu.p2 = 0x0C;
  388|  3.40k|		apdu.cse = (pathlen == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (pathlen == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  6.81k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (388:14): [True: 0, False: 3.40k]
  ------------------
  389|  3.40k|	}
  390|       |
  391|  6.96k|	r = sc_transmit_apdu(card, &apdu);
  392|  6.96k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.96k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.96k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.96k|	int _ret = (r); \
  |  |  |  |  168|  6.96k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 6.94k]
  |  |  |  |  ------------------
  |  |  |  |  169|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     22|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     22|		return _ret; \
  |  |  |  |  172|     22|	} \
  |  |  |  |  173|  6.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.94k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  393|  6.94k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  394|  6.94k|	if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  5.97k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  5.97k|	int _ret = r; \
  |  |  155|  5.97k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5.97k, False: 0]
  |  |  ------------------
  |  |  156|  5.97k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  5.67k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5.67k, False: 307]
  |  |  ------------------
  |  |  157|  5.97k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.97k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  5.97k|	return _ret; \
  |  |  163|  5.97k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (394:6): [True: 5.67k, False: 1.26k]
  |  Branch (394:11): [True: 307, False: 962]
  ------------------
  395|       |
  396|    962|	if (apdu.resplen < 1 || apdu.resp[0] != 0x62) {
  ------------------
  |  Branch (396:6): [True: 36, False: 926]
  |  Branch (396:26): [True: 57, False: 869]
  ------------------
  397|     93|		sc_log(ctx, "received invalid template %02X\n", apdu.resp[0]);
  ------------------
  |  |   71|     93|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  398|     93|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  153|     93|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     93|	int _ret = r; \
  |  |  155|     93|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 93, False: 0]
  |  |  ------------------
  |  |  156|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     93|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 93, False: 0]
  |  |  ------------------
  |  |  157|     93|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     93|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     93|	return _ret; \
  |  |  163|     93|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  399|     93|	}
  400|       |
  401|    869|	file = sc_file_new();
  402|    869|	if (file == NULL) LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (402:6): [True: 0, False: 869]
  ------------------
  403|    869|	*file_out = file;
  404|    869|	file->path = *in_path;
  405|       |
  406|    869|	iso_ops->process_fci(card, file, apdu.resp, apdu.resplen);
  407|       |
  408|    869|	parse_sec_attr(card, file, file->sec_attr, file->sec_attr_len);
  409|       |
  410|    869|	return 0;
  411|    869|}
card-tcos.c:parse_sec_attr:
  271|    869|{
  272|    869|	unsigned int op;
  273|       |
  274|       |	/* list directory is not covered by ACLs - so always add an entry */
  275|    869|	sc_file_add_acl_entry (file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|    869|#define SC_AC_OP_LIST_FILES		6
  ------------------
  276|    869|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    869|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    869|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  277|       |	/* FIXME: check for what LOCK is used */
  278|    869|	sc_file_add_acl_entry (file, SC_AC_OP_LOCK,
  ------------------
  |  |  167|    869|#define SC_AC_OP_LOCK			1
  ------------------
  279|    869|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    869|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    869|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  280|  2.85k|	for (; len >= 6; len -= 6, buf += 6) {
  ------------------
  |  Branch (280:9): [True: 1.98k, False: 869]
  ------------------
  281|       |		/* FIXME: temporary hacks */
  282|  1.98k|		if (!memcmp(buf, "\xa4\x00\x00\x00\xff\xff", 6)) {/* select */
  ------------------
  |  Branch (282:7): [True: 19, False: 1.96k]
  ------------------
  283|     19|			sc_file_add_acl_entry (file, SC_AC_OP_SELECT,
  ------------------
  |  |  166|     19|#define SC_AC_OP_SELECT			0
  ------------------
  284|     19|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     19|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     19|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  285|  1.96k|		} else if (!memcmp(buf, "\xb0\x00\x00\x00\xff\xff", 6)) {/*read*/
  ------------------
  |  Branch (285:14): [True: 19, False: 1.94k]
  ------------------
  286|     19|			sc_file_add_acl_entry (file, SC_AC_OP_READ,
  ------------------
  |  |  188|     19|#define SC_AC_OP_READ			22
  ------------------
  287|     19|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     19|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     19|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  288|  1.94k|		} else if (!memcmp(buf, "\xd6\x00\x00\x00\xff\xff", 6)) {/*upd*/
  ------------------
  |  Branch (288:14): [True: 34, False: 1.91k]
  ------------------
  289|     34|			sc_file_add_acl_entry (file, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|     34|#define SC_AC_OP_UPDATE			23
  ------------------
  290|     34|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     34|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     34|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  291|  1.91k|		} else if (!memcmp(buf, "\x60\x00\x00\x00\xff\xff", 6)) {/*adm */
  ------------------
  |  Branch (291:14): [True: 36, False: 1.87k]
  ------------------
  292|     36|			sc_file_add_acl_entry (file, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     36|#define SC_AC_OP_WRITE			24
  ------------------
  293|     36|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     36|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     36|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  294|     36|			sc_file_add_acl_entry (file, SC_AC_OP_CREATE,
  ------------------
  |  |  169|     36|#define SC_AC_OP_CREATE			3
  ------------------
  295|     36|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     36|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     36|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  296|     36|			sc_file_add_acl_entry (file, SC_AC_OP_INVALIDATE,
  ------------------
  |  |  171|     36|#define SC_AC_OP_INVALIDATE		5
  ------------------
  297|     36|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     36|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     36|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  298|     36|			sc_file_add_acl_entry (file, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     36|#define SC_AC_OP_REHABILITATE		4
  ------------------
  299|     36|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     36|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     36|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  300|  1.87k|		} else {
  301|       |			/* the first byte tells use the command or the
  302|       |			   command group.  We have to mask bit 0
  303|       |			   because this one distinguish between AND/OR
  304|       |			   combination of PINs*/
  305|  1.87k|			op = map_operations (buf[0]);
  306|  1.87k|			if (op == (unsigned int)-1) {
  ------------------
  |  Branch (306:8): [True: 253, False: 1.62k]
  ------------------
  307|    253|				sc_log(card->ctx,
  ------------------
  |  |   71|    253|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  308|    253|					"Unknown security command byte %02x\n",
  309|    253|					buf[0]);
  310|    253|				continue;
  311|    253|			}
  312|  1.62k|			if (!buf[1])
  ------------------
  |  Branch (312:8): [True: 215, False: 1.41k]
  ------------------
  313|    215|				sc_file_add_acl_entry (file, op,
  314|    215|                                                       SC_AC_NONE,
  ------------------
  |  |  150|    215|#define SC_AC_NONE			0x00000000
  ------------------
  315|    215|                                                       SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    215|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  316|  1.41k|			else
  317|  1.41k|				sc_file_add_acl_entry (file, op,
  318|  1.41k|                                                       SC_AC_CHV, buf[1]);
  ------------------
  |  |  151|  1.41k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  319|       |
  320|  1.62k|			if (!buf[2] && !buf[3])
  ------------------
  |  Branch (320:8): [True: 208, False: 1.41k]
  |  Branch (320:19): [True: 105, False: 103]
  ------------------
  321|    105|				sc_file_add_acl_entry (file, op,
  322|    105|                                                       SC_AC_NONE,
  ------------------
  |  |  150|    105|#define SC_AC_NONE			0x00000000
  ------------------
  323|    105|                                                       SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    105|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  324|  1.52k|			else
  325|  1.52k|				sc_file_add_acl_entry (file, op,
  326|  1.52k|                                                       SC_AC_TERM,
  ------------------
  |  |  152|  1.52k|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  327|  1.52k|                                                       (buf[2]<<8)|buf[3]);
  328|  1.62k|		}
  329|  1.98k|	}
  330|    869|}
card-tcos.c:map_operations:
  236|  1.87k|{
  237|  1.87k|	unsigned int op = (unsigned int)-1;
  238|       |
  239|  1.87k|	switch ( (commandbyte & 0xfe) ) {
  ------------------
  |  Branch (239:11): [True: 1.62k, False: 253]
  ------------------
  240|     69|		case 0xe2: /* append record */   op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|     69|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (240:3): [True: 69, False: 1.80k]
  ------------------
  241|     69|		case 0x24: /* change password */ op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|     69|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (241:3): [True: 69, False: 1.80k]
  ------------------
  242|     68|		case 0xe0: /* create */          op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     68|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (242:3): [True: 68, False: 1.81k]
  ------------------
  243|     66|		case 0xe4: /* delete */          op = SC_AC_OP_DELETE; break;
  ------------------
  |  |  168|     66|#define SC_AC_OP_DELETE			2
  ------------------
  |  Branch (243:3): [True: 66, False: 1.81k]
  ------------------
  244|     68|		case 0xe8: /* exclude sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     68|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (244:3): [True: 68, False: 1.81k]
  ------------------
  245|     83|		case 0x82: /* external auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     83|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (245:3): [True: 83, False: 1.79k]
  ------------------
  246|     74|		case 0xe6: /* include sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     74|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (246:3): [True: 74, False: 1.80k]
  ------------------
  247|     72|		case 0x88: /* internal auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     72|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (247:3): [True: 72, False: 1.80k]
  ------------------
  248|    125|		case 0x04: /* invalidate */      op = SC_AC_OP_INVALIDATE; break;
  ------------------
  |  |  171|    125|#define SC_AC_OP_INVALIDATE		5
  ------------------
  |  Branch (248:3): [True: 125, False: 1.75k]
  ------------------
  249|     73|		case 0x2a: /* perform sec. op */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     73|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (249:3): [True: 73, False: 1.80k]
  ------------------
  250|     73|		case 0xb0: /* read binary */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     73|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (250:3): [True: 73, False: 1.80k]
  ------------------
  251|     68|		case 0xb2: /* read record */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     68|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (251:3): [True: 68, False: 1.81k]
  ------------------
  252|     74|		case 0x44: /* rehabilitate */    op = SC_AC_OP_REHABILITATE; break;
  ------------------
  |  |  170|     74|#define SC_AC_OP_REHABILITATE		4
  ------------------
  |  Branch (252:3): [True: 74, False: 1.80k]
  ------------------
  253|     69|		case 0xa4: /* select */          op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     69|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (253:3): [True: 69, False: 1.80k]
  ------------------
  254|     95|		case 0xee: /* set permanent */   op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     95|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (254:3): [True: 95, False: 1.78k]
  ------------------
  255|    155|		case 0x2c: /* unblock password */op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|    155|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (255:3): [True: 155, False: 1.72k]
  ------------------
  256|     71|		case 0xd6: /* update binary */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     71|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (256:3): [True: 71, False: 1.80k]
  ------------------
  257|     76|		case 0xdc: /* update record */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     76|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (257:3): [True: 76, False: 1.80k]
  ------------------
  258|     78|		case 0x20: /* verify password */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     78|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (258:3): [True: 78, False: 1.80k]
  ------------------
  259|     99|		case 0x60: /* admin group */     op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     99|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (259:3): [True: 99, False: 1.77k]
  ------------------
  260|  1.87k|	}
  261|  1.87k|	return op;
  262|  1.87k|}
card-tcos.c:tcos_card_ctl:
  708|    725|{
  709|    725|	switch (cmd) {
  ------------------
  |  Branch (709:10): [True: 725, False: 0]
  ------------------
  710|      0|	case SC_CARDCTL_TCOS_SETPERM:
  ------------------
  |  Branch (710:2): [True: 0, False: 725]
  ------------------
  711|      0|		return tcos_setperm(card, !!ptr);
  712|    725|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (712:2): [True: 725, False: 0]
  ------------------
  713|    725|		return tcos_get_serialnr(card, (sc_serial_number_t *)ptr);
  714|    725|	}
  715|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  716|    725|}
card-tcos.c:tcos_get_serialnr:
  681|    725|{
  682|    725|	int r;
  683|       |
  684|    725|	if (!serial)
  ------------------
  |  Branch (684:6): [True: 0, False: 725]
  ------------------
  685|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  686|       |
  687|       |	/* see if we have cached serial number */
  688|    725|	if (card->serialnr.len) {
  ------------------
  |  Branch (688:6): [True: 1, False: 724]
  ------------------
  689|      1|		memcpy(serial, &card->serialnr, sizeof(*serial));
  690|      1|		return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  691|      1|	}
  692|       |
  693|    724|	card->serialnr.len = sizeof card->serialnr.value;
  694|    724|	r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
  695|    724|	if (r < 0) {
  ------------------
  |  Branch (695:6): [True: 488, False: 236]
  ------------------
  696|    488|		card->serialnr.len = 0;
  697|    488|		return r;
  698|    488|	}
  699|       |
  700|       |	/* copy and return serial number */
  701|    236|	memcpy(serial, &card->serialnr, sizeof(*serial));
  702|       |
  703|    236|	return SC_SUCCESS;
  ------------------
  |  |   28|    236|#define SC_SUCCESS				0
  ------------------
  704|    724|}

sc_check_sw:
   44|   394k|{
   45|   394k|	if (card == NULL)
  ------------------
  |  Branch (45:6): [True: 0, False: 394k]
  ------------------
   46|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   47|   394k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (47:6): [True: 0, False: 394k]
  ------------------
   48|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   49|   394k|	return card->ops->check_sw(card, sw1, sw2);
   50|   394k|}
sc_format_apdu:
   54|   443k|{
   55|   443k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (55:6): [True: 0, False: 443k]
  |  Branch (55:22): [True: 0, False: 443k]
  ------------------
   56|      0|		return;
   57|      0|	}
   58|   443k|	memset(apdu, 0, sizeof(*apdu));
   59|   443k|	apdu->cla = (u8) card->cla;
   60|   443k|	apdu->cse = cse;
   61|   443k|	apdu->ins = (u8) ins;
   62|   443k|	apdu->p1 = (u8) p1;
   63|   443k|	apdu->p2 = (u8) p2;
   64|   443k|}
sc_format_apdu_cse_lc_le:
   67|  3.05k|{
   68|       |	/* TODO calculating the APDU case, Lc and Le should actually only be
   69|       |	 * done in sc_apdu2bytes, but to gradually change OpenSC we start here. */
   70|       |	/* Let sc_detect_apdu_cse set short or extended  and test for chaining */
   71|       |
   72|  3.05k|	if (!apdu)
  ------------------
  |  Branch (72:6): [True: 0, False: 3.05k]
  ------------------
   73|      0|		return;
   74|  3.05k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  6.10k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (74:6): [True: 0, False: 3.05k]
  ------------------
   75|  3.05k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  3.05k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (75:7): [True: 0, False: 3.05k]
  ------------------
   76|       |		/* extended length  or data chaining and/or get response */
   77|      0|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|      0|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (77:7): [True: 0, False: 0]
  ------------------
   78|      0|			apdu->lc = apdu->datalen;
   79|      0|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|      0|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (79:7): [True: 0, False: 0]
  ------------------
   80|      0|			apdu->le = apdu->resplen;
   81|      0|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (81:7): [True: 0, False: 0]
  |  Branch (81:24): [True: 0, False: 0]
  ------------------
   82|      0|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|      0|#define SC_APDU_CASE_2			0x22
  ------------------
   83|      0|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (83:7): [True: 0, False: 0]
  |  Branch (83:25): [True: 0, False: 0]
  ------------------
   84|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   85|      0|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (85:7): [True: 0, False: 0]
  |  Branch (85:24): [True: 0, False: 0]
  ------------------
   86|      0|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|      0|#define SC_APDU_CASE_4			0x24
  ------------------
   87|  3.05k|	} else {
   88|       |		/* short length */
   89|  3.05k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  3.05k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (89:7): [True: 3.05k, False: 0]
  ------------------
   90|  3.05k|			apdu->lc = apdu->datalen;
   91|  3.05k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  3.05k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (91:7): [True: 3.05k, False: 0]
  ------------------
   92|  3.05k|			apdu->le = apdu->resplen;
   93|  3.05k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (93:7): [True: 2.74k, False: 308]
  |  Branch (93:25): [True: 3, False: 2.74k]
  ------------------
   94|      3|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      3|#define SC_APDU_CASE_1			0x01
  ------------------
   95|  3.05k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (95:7): [True: 308, False: 2.74k]
  |  Branch (95:24): [True: 9, False: 299]
  ------------------
   96|      9|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      9|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   97|  3.05k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (97:7): [True: 2.74k, False: 308]
  |  Branch (97:25): [True: 2.74k, False: 3]
  ------------------
   98|  2.74k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.74k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
   99|  3.05k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (99:7): [True: 308, False: 2.74k]
  |  Branch (99:24): [True: 299, False: 9]
  ------------------
  100|    299|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|    299|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  101|  3.05k|	}
  102|  3.05k|}
sc_format_apdu_ex:
  108|  3.05k|{
  109|  3.05k|	if (!apdu) {
  ------------------
  |  Branch (109:6): [True: 0, False: 3.05k]
  ------------------
  110|      0|		return;
  111|      0|	}
  112|       |
  113|  3.05k|	memset(apdu, 0, sizeof(*apdu));
  114|  3.05k|	apdu->cla = cla;
  115|  3.05k|	apdu->ins = ins;
  116|  3.05k|	apdu->p1 = p1;
  117|  3.05k|	apdu->p2 = p2;
  118|  3.05k|	apdu->resp = resp;
  119|  3.05k|	apdu->resplen = resplen;
  120|  3.05k|	apdu->data = data;
  121|  3.05k|	apdu->datalen = datalen;
  122|  3.05k|	sc_format_apdu_cse_lc_le(apdu);
  123|  3.05k|}
sc_get_max_recv_size:
  187|   253k|{
  188|   253k|	size_t max_recv_size;
  189|   253k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (189:6): [True: 0, False: 253k]
  |  Branch (189:22): [True: 0, False: 253k]
  ------------------
  190|      0|		return 0;
  191|      0|	}
  192|   253k|	max_recv_size = card->max_recv_size;
  193|       |
  194|       |	/* initialize max_recv_size to a meaningful value */
  195|   253k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  547|   253k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (195:6): [True: 14.4k, False: 239k]
  ------------------
  196|  14.4k|		if (!max_recv_size)
  ------------------
  |  Branch (196:7): [True: 3.47k, False: 11.0k]
  ------------------
  197|  3.47k|			max_recv_size = 65536;
  198|   239k|	} else {
  199|   239k|		if (!max_recv_size)
  ------------------
  |  Branch (199:7): [True: 149k, False: 89.8k]
  ------------------
  200|   149k|			max_recv_size = 256;
  201|   239k|	}
  202|       |
  203|       |	/*  Override card limitations with reader limitations. */
  204|   253k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (204:6): [True: 7.38k, False: 246k]
  ------------------
  205|  7.38k|			&& (card->reader->max_recv_size < card->max_recv_size))
  ------------------
  |  Branch (205:7): [True: 0, False: 7.38k]
  ------------------
  206|      0|		max_recv_size = card->reader->max_recv_size;
  207|       |
  208|   253k|	return max_recv_size;
  209|   253k|}
sc_get_max_send_size:
  212|  46.1k|{
  213|  46.1k|	size_t max_send_size;
  214|       |
  215|  46.1k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (215:6): [True: 0, False: 46.1k]
  |  Branch (215:22): [True: 0, False: 46.1k]
  ------------------
  216|      0|		return 0;
  217|      0|	}
  218|       |
  219|  46.1k|	max_send_size = card->max_send_size;
  220|       |
  221|       |	/* initialize max_send_size to a meaningful value */
  222|  46.1k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  547|  92.2k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (222:6): [True: 6.07k, False: 40.0k]
  ------------------
  223|  6.07k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  352|  6.07k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (223:7): [True: 6.07k, False: 0]
  ------------------
  224|  6.07k|		if (!max_send_size)
  ------------------
  |  Branch (224:7): [True: 1.18k, False: 4.89k]
  ------------------
  225|  1.18k|			max_send_size = 65535;
  226|  40.0k|	} else {
  227|  40.0k|		if (!max_send_size)
  ------------------
  |  Branch (227:7): [True: 9.54k, False: 30.4k]
  ------------------
  228|  9.54k|			max_send_size = 255;
  229|  40.0k|	}
  230|       |
  231|       |	/*  Override card limitations with reader limitations. */
  232|  46.1k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (232:6): [True: 1, False: 46.1k]
  ------------------
  233|      1|			&& (card->reader->max_send_size < card->max_send_size))
  ------------------
  |  Branch (233:7): [True: 0, False: 1]
  ------------------
  234|      0|		max_send_size = card->reader->max_send_size;
  235|       |
  236|  46.1k|	return max_send_size;
  237|  46.1k|}
sc_connect_card:
  240|  15.2k|{
  241|  15.2k|	sc_card_t *card;
  242|  15.2k|	sc_context_t *ctx;
  243|  15.2k|	struct sc_card_driver *driver;
  244|  15.2k|	int i, r = 0, idx, connected = 0;
  245|       |
  246|  15.2k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (246:6): [True: 0, False: 15.2k]
  |  Branch (246:26): [True: 0, False: 15.2k]
  ------------------
  247|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  248|  15.2k|	ctx = reader->ctx;
  249|  15.2k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.2k]
  |  |  ------------------
  ------------------
  250|  15.2k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (250:6): [True: 0, False: 15.2k]
  ------------------
  251|  15.2k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|       |
  253|  15.2k|	card = sc_card_new(ctx);
  254|  15.2k|	if (card == NULL)
  ------------------
  |  Branch (254:6): [True: 0, False: 15.2k]
  ------------------
  255|  15.2k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|  15.2k|	r = reader->ops->connect(reader);
  257|  15.2k|	if (r)
  ------------------
  |  Branch (257:6): [True: 0, False: 15.2k]
  ------------------
  258|      0|		goto err;
  259|       |
  260|  15.2k|	connected = 1;
  261|  15.2k|	card->reader = reader;
  262|  15.2k|	card->ctx = ctx;
  263|       |
  264|  15.2k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  372|  15.2k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (264:6): [True: 0, False: 15.2k]
  ------------------
  265|      0|		sc_detect_escape_cmds(reader);
  266|       |
  267|  15.2k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  268|  15.2k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  269|       |
  270|  15.2k|	_sc_parse_atr(reader);
  271|       |
  272|       |	/* See if the ATR matches any ATR specified in the config file */
  273|  15.2k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (273:6): [True: 15.2k, False: 0]
  ------------------
  274|  15.2k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  275|   717k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (275:15): [True: 701k, False: 15.2k]
  ------------------
  276|   701k|			driver = ctx->card_drivers[i];
  277|       |
  278|   701k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (278:8): [True: 701k, False: 0]
  ------------------
  279|   701k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (279:8): [True: 0, False: 0]
  ------------------
  280|   701k|				driver = NULL;
  281|   701k|				continue;
  282|   701k|			}
  283|      0|			sc_log(ctx, "trying driver '%s'", driver->short_name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  284|      0|			idx = _sc_match_atr(card, driver->atr_map, NULL);
  285|      0|			if (idx >= 0) {
  ------------------
  |  Branch (285:8): [True: 0, False: 0]
  ------------------
  286|      0|				struct sc_atr_table *src = &driver->atr_map[idx];
  287|       |
  288|      0|				sc_log(ctx, "matched driver '%s'", driver->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  289|       |				/* It's up to card driver to notice these correctly */
  290|      0|				card->name = src->name;
  291|      0|				card->type = src->type;
  292|      0|				card->flags = src->flags;
  293|      0|				break;
  294|      0|			}
  295|      0|			driver = NULL;
  296|      0|		}
  297|  15.2k|	}
  298|       |
  299|  15.2k|	if (driver != NULL) {
  ------------------
  |  Branch (299:6): [True: 0, False: 15.2k]
  ------------------
  300|       |		/* Forced driver, or matched via ATR mapping from config file */
  301|      0|		card->driver = driver;
  302|       |
  303|      0|		memcpy(card->ops, card->driver->ops, sizeof(struct sc_card_operations));
  304|      0|		if (card->ops->match_card != NULL)
  ------------------
  |  Branch (304:7): [True: 0, False: 0]
  ------------------
  305|      0|			if (card->ops->match_card(card) != 1)
  ------------------
  |  Branch (305:8): [True: 0, False: 0]
  ------------------
  306|      0|				sc_log(ctx, "driver '%s' match_card() failed: %s (will continue anyway)", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  307|       |
  308|      0|		if (card->ops->init != NULL) {
  ------------------
  |  Branch (308:7): [True: 0, False: 0]
  ------------------
  309|      0|			r = card->ops->init(card);
  310|      0|			if (r) {
  ------------------
  |  Branch (310:8): [True: 0, False: 0]
  ------------------
  311|      0|				sc_log(ctx, "driver '%s' init() failed: %s", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  312|      0|				goto err;
  313|      0|			}
  314|      0|		}
  315|      0|	}
  316|  15.2k|	else {
  317|  15.2k|		sc_card_t uninitialized = *card;
  318|  15.2k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  319|   394k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (319:15): [True: 392k, False: 2.46k]
  ------------------
  320|       |			/* FIXME If we had a clean API description, we'd probably get a
  321|       |			 * cleaner implementation of the driver's match_card and init,
  322|       |			 * which should normally *not* modify the card object if
  323|       |			 * unsuccessful. However, after years of relentless hacking, reality
  324|       |			 * is different: The card object is changed in virtually every card
  325|       |			 * driver so in order to prevent unwanted interaction, we reset the
  326|       |			 * card object here and hope that the card driver at least doesn't
  327|       |			 * allocate any internal resources that need to be freed. If we
  328|       |			 * had more time, we should refactor the existing code to not
  329|       |			 * modify sc_card_t until complete success (possibly by combining
  330|       |			 * `match_card()` and `init()`) */
  331|   392k|			*card = uninitialized;
  332|       |
  333|   392k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  334|   392k|			const struct sc_card_operations *ops = drv->ops;
  335|       |
  336|   392k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   392k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  337|   392k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (337:8): [True: 0, False: 392k]
  |  Branch (337:23): [True: 0, False: 392k]
  ------------------
  338|      0|				continue;
  339|      0|			}
  340|   392k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  860|   392k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (340:13): [True: 392k, False: 0]
  ------------------
  341|   392k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (341:12): [True: 2.46k, False: 389k]
  ------------------
  342|  2.46k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.46k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  343|  2.46k|				continue;
  344|  2.46k|			}
  345|       |
  346|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  347|   389k|			*card->ops = *ops;
  348|   389k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (348:8): [True: 376k, False: 13.6k]
  ------------------
  349|   376k|				continue;
  350|  13.6k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  13.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  351|  13.6k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  352|  13.6k|			card->driver = drv;
  353|  13.6k|			r = ops->init(card);
  354|  13.6k|			if (r) {
  ------------------
  |  Branch (354:8): [True: 1.65k, False: 12.0k]
  ------------------
  355|  1.65k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   71|  1.65k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  356|  1.65k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.65k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (356:9): [True: 885, False: 766]
  ------------------
  357|    885|					card->driver = NULL;
  358|    885|					continue;
  359|    885|				}
  360|    766|				goto err;
  361|  1.65k|			}
  362|  12.0k|			break;
  363|  13.6k|		}
  364|  15.2k|	}
  365|  14.4k|	if (card->driver == NULL) {
  ------------------
  |  Branch (365:6): [True: 2.46k, False: 12.0k]
  ------------------
  366|  2.46k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.46k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  367|  2.46k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.46k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  368|  2.46k|		goto err;
  369|  2.46k|	}
  370|  12.0k|	if (card->name == NULL)
  ------------------
  |  Branch (370:6): [True: 2.62k, False: 9.40k]
  ------------------
  371|  2.62k|		card->name = card->driver->name;
  372|       |
  373|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  374|  12.0k|	card->max_recv_size = sc_get_max_recv_size(card);
  375|  12.0k|	card->max_send_size = sc_get_max_send_size(card);
  376|       |
  377|  12.0k|	sc_log(ctx, "card info name:'%s', type:%i, flags:0x%lX, max_send/recv_size:%zu/%zu",
  ------------------
  |  |   71|  12.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  378|  12.0k|			card->name, card->type, card->flags, card->max_send_size, card->max_recv_size);
  379|       |
  380|  12.0k|#ifdef ENABLE_SM
  381|       |	/* Check, if secure messaging module present. */
  382|  12.0k|	r = sc_card_sm_check(card);
  383|  12.0k|	if (r)   {
  ------------------
  |  Branch (383:6): [True: 0, False: 12.0k]
  ------------------
  384|      0|		sc_log(ctx, "cannot load secure messaging module");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  385|      0|		goto err;
  386|      0|	}
  387|  12.0k|#endif
  388|  12.0k|	*card_out = card;
  389|       |
  390|  12.0k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.0k|	int _ret = r; \
  |  |  |  |  155|  12.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.0k|	return _ret; \
  |  |  |  |  163|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|  3.23k|err:
  392|  3.23k|	if (connected)
  ------------------
  |  Branch (392:6): [True: 3.23k, False: 0]
  ------------------
  393|  3.23k|		reader->ops->disconnect(reader);
  394|  3.23k|	if (card != NULL)
  ------------------
  |  Branch (394:6): [True: 3.23k, False: 0]
  ------------------
  395|  3.23k|		sc_card_free(card);
  396|  3.23k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  3.23k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.23k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.23k|	int _ret = r; \
  |  |  |  |  155|  3.23k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.23k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.23k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.23k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.23k|	return _ret; \
  |  |  |  |  163|  3.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  397|  3.23k|}
sc_disconnect_card:
  400|  12.0k|{
  401|  12.0k|	sc_context_t *ctx;
  402|       |
  403|  12.0k|	if (!card)
  ------------------
  |  Branch (403:6): [True: 0, False: 12.0k]
  ------------------
  404|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  405|       |
  406|  12.0k|	ctx = card->ctx;
  407|  12.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  408|       |
  409|  12.0k|	if (card->ops->finish) {
  ------------------
  |  Branch (409:6): [True: 11.2k, False: 737]
  ------------------
  410|  11.2k|		int r = card->ops->finish(card);
  411|  11.2k|		if (r)
  ------------------
  |  Branch (411:7): [True: 528, False: 10.7k]
  ------------------
  412|    528|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|    528|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  413|  11.2k|	}
  414|       |
  415|  12.0k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (415:6): [True: 12.0k, False: 0]
  ------------------
  416|  12.0k|		int r = card->reader->ops->disconnect(card->reader);
  417|  12.0k|		if (r)
  ------------------
  |  Branch (417:7): [True: 0, False: 12.0k]
  ------------------
  418|      0|			sc_log(ctx, "disconnect() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  419|  12.0k|	}
  420|       |
  421|  12.0k|#ifdef ENABLE_SM
  422|       |	/* release SM related resources */
  423|  12.0k|	sc_card_sm_unload(card);
  424|  12.0k|#endif
  425|       |
  426|  12.0k|	sc_card_free(card);
  427|  12.0k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.0k|	int _ret = r; \
  |  |  |  |  155|  12.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.0k|	return _ret; \
  |  |  |  |  163|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  428|  12.0k|}
sc_lock:
  455|   524k|{
  456|   524k|	int r = 0, r2 = 0;
  457|   524k|	int was_reset = 0;
  458|   524k|	int reader_lock_obtained  = 0;
  459|       |
  460|   524k|	if (card == NULL)
  ------------------
  |  Branch (460:6): [True: 0, False: 524k]
  ------------------
  461|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  462|       |
  463|   524k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   524k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   524k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   524k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   524k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 524k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|       |
  465|   524k|	r = sc_mutex_lock(card->ctx, card->mutex);
  466|   524k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   524k|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 0, False: 524k]
  ------------------
  467|      0|		return r;
  468|   524k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (468:6): [True: 289k, False: 235k]
  ------------------
  469|   289k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (469:7): [True: 289k, False: 0]
  ------------------
  470|   289k|			r = card->reader->ops->lock(card->reader);
  471|   289k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   579k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   289k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (471:11): [True: 0, False: 289k]
  |  Branch (471:39): [True: 0, False: 289k]
  ------------------
  472|      0|				if (was_reset++ > 4) /* TODO retry a few times */
  ------------------
  |  Branch (472:9): [True: 0, False: 0]
  ------------------
  473|      0|					break;
  474|      0|				r = card->reader->ops->lock(card->reader);
  475|      0|			}
  476|   289k|			if (r == 0)
  ------------------
  |  Branch (476:8): [True: 289k, False: 0]
  ------------------
  477|   289k|				reader_lock_obtained = 1;
  478|   289k|		}
  479|   289k|	}
  480|   524k|	if (r == 0)
  ------------------
  |  Branch (480:6): [True: 524k, False: 0]
  ------------------
  481|   524k|		card->lock_count++;
  482|       |
  483|   524k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  484|   524k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   524k|#define SC_SUCCESS				0
  ------------------
  |  Branch (484:6): [True: 0, False: 524k]
  ------------------
  485|      0|		sc_log(card->ctx, "unable to release card->mutex lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  486|      0|		r = r != SC_SUCCESS ? r : r2;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (486:7): [True: 0, False: 0]
  ------------------
  487|      0|	}
  488|       |
  489|   524k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (489:6): [True: 524k, False: 0]
  |  Branch (489:16): [True: 0, False: 524k]
  ------------------
  490|      0|#ifdef ENABLE_SM
  491|      0|		if (card->sm_ctx.ops.open)
  ------------------
  |  Branch (491:7): [True: 0, False: 0]
  ------------------
  492|      0|			card->sm_ctx.ops.open(card);
  493|      0|#endif
  494|      0|	}
  495|       |
  496|       |	/* give card driver a chance to do something when reader lock first obtained */
  497|   524k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (497:6): [True: 524k, False: 0]
  |  Branch (497:16): [True: 289k, False: 235k]
  |  Branch (497:46): [True: 91.0k, False: 198k]
  ------------------
  498|  91.0k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  91.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (498:7): [True: 763, False: 90.2k]
  ------------------
  499|    763|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   71|    763|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  500|  91.0k|	}
  501|       |
  502|   524k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   524k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   524k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   524k|	int _ret = r; \
  |  |  |  |  155|   524k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   524k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 524k]
  |  |  |  |  ------------------
  |  |  |  |  157|   524k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   524k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   524k|	return _ret; \
  |  |  |  |  163|   524k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  503|   524k|}
sc_unlock:
  506|   524k|{
  507|   524k|	int r, r2;
  508|       |
  509|   524k|	if (!card)
  ------------------
  |  Branch (509:6): [True: 0, False: 524k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|       |
  512|   524k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   524k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   524k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   524k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   524k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 524k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|       |
  514|   524k|	r = sc_mutex_lock(card->ctx, card->mutex);
  515|   524k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   524k|#define SC_SUCCESS				0
  ------------------
  |  Branch (515:6): [True: 0, False: 524k]
  ------------------
  516|   524k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|       |
  518|   524k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (518:6): [True: 0, False: 524k]
  ------------------
  519|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      0|	}
  521|   524k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (521:6): [True: 289k, False: 235k]
  ------------------
  522|       |		/* release reader lock */
  523|   289k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (523:7): [True: 289k, False: 0]
  ------------------
  524|   289k|			r = card->reader->ops->unlock(card->reader);
  525|   289k|	}
  526|   524k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  527|   524k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   524k|#define SC_SUCCESS				0
  ------------------
  |  Branch (527:6): [True: 0, False: 524k]
  ------------------
  528|      0|		sc_log(card->ctx, "unable to release lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  529|      0|		r = (r == SC_SUCCESS) ? r2 : r;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (529:7): [True: 0, False: 0]
  ------------------
  530|      0|	}
  531|       |
  532|   524k|	return r;
  533|   524k|}
sc_read_binary:
  603|  9.33k|{
  604|  9.33k|	size_t max_le = sc_get_max_recv_size(card);
  605|  9.33k|	size_t todo = count;
  606|  9.33k|	int r;
  607|       |
  608|  9.33k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (608:6): [True: 0, False: 9.33k]
  |  Branch (608:22): [True: 0, False: 9.33k]
  |  Branch (608:43): [True: 0, False: 9.33k]
  ------------------
  609|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  610|      0|	}
  611|  9.33k|	sc_log(card->ctx, "called; %zu bytes at index %d", count, idx);
  ------------------
  |  |   71|  9.33k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  612|  9.33k|	if (count == 0)
  ------------------
  |  Branch (612:6): [True: 441, False: 8.89k]
  ------------------
  613|  9.33k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    441|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    441|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    441|	int _ret = r; \
  |  |  |  |  155|    441|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 441, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    441|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 441]
  |  |  |  |  ------------------
  |  |  |  |  157|    441|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    441|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    441|	return _ret; \
  |  |  |  |  163|    441|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  614|       |
  615|  8.89k|#ifdef ENABLE_SM
  616|  8.89k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (616:6): [True: 322, False: 8.57k]
  ------------------
  617|    322|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  618|    322|		if (r)
  ------------------
  |  Branch (618:7): [True: 262, False: 60]
  ------------------
  619|    322|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    262|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    262|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    262|	int _ret = r; \
  |  |  |  |  155|    262|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 262, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    262|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    262|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 262, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    262|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    262|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    262|	return _ret; \
  |  |  |  |  163|    262|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  620|    322|	}
  621|  8.63k|#endif
  622|       |
  623|  8.63k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (623:6): [True: 0, False: 8.63k]
  ------------------
  624|  8.63k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|       |
  626|       |	/* lock the card now to avoid deselection of the file */
  627|  8.63k|	r = sc_lock(card);
  628|  8.63k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  8.63k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.63k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.63k|	int _ret = (r); \
  |  |  |  |  168|  8.63k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 8.63k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  8.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  629|       |
  630|  36.0k|	while (todo > 0) {
  ------------------
  |  Branch (630:9): [True: 33.1k, False: 2.86k]
  ------------------
  631|  33.1k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   69|  33.1k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 10.0k, False: 23.0k]
  |  |  ------------------
  ------------------
  632|       |
  633|  33.1k|		r = card->ops->read_binary(card, idx, buf, chunk, flags);
  634|  33.1k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  31.7k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (634:7): [True: 1.41k, False: 31.7k]
  |  Branch (634:17): [True: 111, False: 31.6k]
  ------------------
  635|  1.52k|			break;
  636|  31.6k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (636:7): [True: 4.24k, False: 27.3k]
  |  Branch (636:16): [True: 2.57k, False: 1.66k]
  ------------------
  637|       |			/* the last command failed, but previous ones succeeded.
  638|       |			 * Let's just return what we've successfully read. */
  639|  2.57k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  640|  2.57k|			break;
  641|  2.57k|		}
  642|  29.0k|		if (r < 0) {
  ------------------
  |  Branch (642:7): [True: 1.66k, False: 27.3k]
  ------------------
  643|  1.66k|			sc_unlock(card);
  644|  1.66k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.66k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.66k|	int _ret = r; \
  |  |  |  |  155|  1.66k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.66k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.66k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.66k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.66k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.66k|	return _ret; \
  |  |  |  |  163|  1.66k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|  1.66k|		}
  646|  27.3k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (646:7): [True: 0, False: 27.3k]
  |  Branch (646:40): [True: 0, False: 27.3k]
  ------------------
  647|       |			/* `idx + r` or `todo - r` would overflow */
  648|      0|			sc_unlock(card);
  649|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|      0|		}
  651|       |
  652|  27.3k|		todo -= (size_t) r;
  653|  27.3k|		buf  += (size_t) r;
  654|  27.3k|		idx  += (size_t) r;
  655|  27.3k|	}
  656|       |
  657|  6.96k|	sc_unlock(card);
  658|       |
  659|  6.96k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  6.96k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.96k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.96k|	int _ret = r; \
  |  |  |  |  155|  6.96k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 633, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |  156|    633|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 633]
  |  |  |  |  ------------------
  |  |  |  |  157|    633|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.33k|	} else { \
  |  |  |  |  159|  6.33k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  6.33k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  6.33k|	} \
  |  |  |  |  162|  6.96k|	return _ret; \
  |  |  |  |  163|  6.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  660|  6.96k|}
sc_select_file:
  809|  86.5k|{
  810|  86.5k|	int r;
  811|  86.5k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  812|       |
  813|  86.5k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (813:6): [True: 0, False: 86.5k]
  |  Branch (813:22): [True: 0, False: 86.5k]
  ------------------
  814|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  815|      0|	}
  816|       |
  817|  86.5k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  818|  86.5k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  86.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (818:6): [True: 280, False: 86.3k]
  ------------------
  819|    280|		pbuf[0] = '\0';
  820|       |
  821|       |	/* FIXME We should be a bit less strict and let the upper layers do
  822|       |	 * the initialization (including reuse of existing file objects). We
  823|       |	 * implemented this here because we are lazy. */
  824|  86.5k|	if (file != NULL)
  ------------------
  |  Branch (824:6): [True: 46.9k, False: 39.6k]
  ------------------
  825|  46.9k|		*file = NULL;
  826|       |
  827|  86.5k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|  86.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  828|  86.5k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  86.5k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (828:6): [True: 0, False: 86.5k]
  ------------------
  829|  86.5k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|       |
  831|  86.5k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|  86.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (831:6): [True: 61.0k, False: 25.5k]
  ------------------
  832|       |		/* Perform a sanity check */
  833|  61.0k|		size_t i;
  834|       |
  835|  61.0k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (835:7): [True: 119, False: 60.9k]
  ------------------
  836|  61.0k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    119|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    119|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    119|	int _ret = r; \
  |  |  |  |  155|    119|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 119, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    119|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    119|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 119, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    119|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    119|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    119|	return _ret; \
  |  |  |  |  163|    119|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  837|       |
  838|   184k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (838:15): [True: 124k, False: 60.9k]
  ------------------
  839|   124k|			u8 p1 = in_path->value[2*i],
  840|   124k|			   p2 = in_path->value[2*i+1];
  841|       |
  842|   124k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (842:9): [True: 47.7k, False: 76.2k]
  |  Branch (842:23): [True: 47.6k, False: 158]
  |  Branch (842:38): [True: 10, False: 47.6k]
  ------------------
  843|   124k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|   124k|		}
  845|  60.9k|	}
  846|  86.4k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (846:6): [True: 0, False: 86.4k]
  ------------------
  847|  86.4k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  848|  86.4k|	r = card->ops->select_file(card, in_path, file);
  849|  86.4k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|  86.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  86.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  86.4k|	int _ret = (r); \
  |  |  |  |  168|  86.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67.5k, False: 18.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|  67.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  67.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  67.5k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  67.5k|		return _ret; \
  |  |  |  |  172|  67.5k|	} \
  |  |  |  |  173|  86.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  850|       |
  851|  18.8k|	if (file) {
  ------------------
  |  Branch (851:6): [True: 12.0k, False: 6.85k]
  ------------------
  852|  12.0k|		if (*file)
  ------------------
  |  Branch (852:7): [True: 12.0k, False: 37]
  ------------------
  853|       |			/* Remember file path */
  854|  12.0k|			(*file)->path = *in_path;
  855|     37|		else
  856|       |			/* FIXME We should be a bit less strict and let the upper layers do
  857|       |			 * the error checking. We implemented this here because we are
  858|       |			 * lazy.  */
  859|     37|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     37|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  860|  12.0k|	}
  861|       |
  862|  18.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  18.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.8k|	int _ret = r; \
  |  |  |  |  155|  18.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     37|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 37, False: 18.8k]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  18.8k|	return _ret; \
  |  |  |  |  163|  18.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  863|  18.8k|}
sc_get_data:
  867|  6.27k|{
  868|  6.27k|	int	r;
  869|       |
  870|  6.27k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  6.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  871|  6.27k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (871:6): [True: 0, False: 6.27k]
  ------------------
  872|  6.27k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  873|  6.27k|	r = card->ops->get_data(card, tag, buf, len);
  874|       |
  875|  6.27k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.27k|	int _ret = r; \
  |  |  |  |  155|  6.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.49k, False: 1.78k]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.49k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.93k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.93k, False: 564]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.49k|	} else { \
  |  |  |  |  159|  1.78k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.78k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.78k|	} \
  |  |  |  |  162|  6.27k|	return _ret; \
  |  |  |  |  163|  6.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  876|  6.27k|}
sc_read_record:
  931|  10.7k|{
  932|  10.7k|	size_t max_le = sc_get_max_recv_size(card);
  933|  10.7k|	size_t todo = count;
  934|  10.7k|	int r;
  935|       |
  936|  10.7k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (936:6): [True: 0, False: 10.7k]
  |  Branch (936:22): [True: 0, False: 10.7k]
  |  Branch (936:43): [True: 0, False: 10.7k]
  ------------------
  937|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  938|      0|	}
  939|  10.7k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  10.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  940|  10.7k|	if (count == 0)
  ------------------
  |  Branch (940:6): [True: 3.68k, False: 7.06k]
  ------------------
  941|  10.7k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.68k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.68k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.68k|	int _ret = r; \
  |  |  |  |  155|  3.68k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.68k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.68k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.68k|	return _ret; \
  |  |  |  |  163|  3.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  942|       |
  943|  7.06k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (943:6): [True: 21, False: 7.04k]
  ------------------
  944|  7.06k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  945|       |
  946|       |	/* lock the card now to avoid deselection of the file */
  947|  7.04k|	r = sc_lock(card);
  948|  7.04k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  7.04k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.04k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.04k|	int _ret = (r); \
  |  |  |  |  168|  7.04k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7.04k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  7.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|       |
  950|  14.1k|	while (todo > 0) {
  ------------------
  |  Branch (950:9): [True: 13.8k, False: 380]
  ------------------
  951|  13.8k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   69|  13.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 6.04k, False: 7.77k]
  |  |  ------------------
  ------------------
  952|       |
  953|  13.8k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  954|  13.8k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  13.6k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (954:7): [True: 210, False: 13.6k]
  |  Branch (954:17): [True: 539, False: 13.0k]
  ------------------
  955|    749|			break;
  956|  13.0k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (956:7): [True: 5.91k, False: 7.15k]
  |  Branch (956:16): [True: 5.17k, False: 744]
  ------------------
  957|       |			/* the last command failed, but previous ones succeeded.
  958|       |			 * Let's just return what we've successfully read. */
  959|  5.17k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  5.17k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  960|  5.17k|			break;
  961|  5.17k|		}
  962|  7.89k|		if (r < 0) {
  ------------------
  |  Branch (962:7): [True: 744, False: 7.15k]
  ------------------
  963|    744|			sc_unlock(card);
  964|    744|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    744|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    744|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    744|	int _ret = r; \
  |  |  |  |  155|    744|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 744, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    744|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    744|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 744, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    744|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    744|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    744|	return _ret; \
  |  |  |  |  163|    744|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  965|    744|		}
  966|  7.15k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (966:7): [True: 0, False: 7.15k]
  |  Branch (966:40): [True: 0, False: 7.15k]
  ------------------
  967|       |			/* `idx + r` or `todo - r` would overflow */
  968|      0|			sc_unlock(card);
  969|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|      0|		}
  971|       |
  972|  7.15k|		todo -= (size_t) r;
  973|  7.15k|		buf  += (size_t) r;
  974|  7.15k|		idx  += (size_t) r;
  975|  7.15k|	}
  976|       |
  977|  6.29k|	sc_unlock(card);
  978|       |
  979|  6.29k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  6.29k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.29k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.29k|	int _ret = r; \
  |  |  |  |  155|  6.29k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 6.06k]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.06k|	} else { \
  |  |  |  |  159|  6.06k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  6.06k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  6.06k|	} \
  |  |  |  |  162|  6.29k|	return _ret; \
  |  |  |  |  163|  6.29k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  980|  6.29k|}
sc_card_ctl:
 1090|   125k|{
 1091|   125k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|   125k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1092|       |
 1093|   125k|	if (card == NULL) {
  ------------------
  |  Branch (1093:6): [True: 0, False: 125k]
  ------------------
 1094|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1095|      0|	}
 1096|   125k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|   125k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1097|       |
 1098|   125k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1098:6): [True: 125k, False: 172]
  ------------------
 1099|   125k|		r = card->ops->card_ctl(card, cmd, args);
 1100|       |
 1101|       |	/* suppress "not supported" error messages */
 1102|   125k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|   125k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1102:6): [True: 22.1k, False: 103k]
  ------------------
 1103|  22.1k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  22.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1104|  22.1k|		return r;
 1105|  22.1k|	}
 1106|   103k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   103k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   103k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   103k|	int _ret = r; \
  |  |  |  |  155|   103k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 66.0k, False: 37.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|  66.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  24.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 24.5k, False: 41.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  66.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  66.0k|	} else { \
  |  |  |  |  159|  37.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  37.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  37.2k|	} \
  |  |  |  |  162|   103k|	return _ret; \
  |  |  |  |  163|   103k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|   103k|}
_sc_card_add_algorithm:
 1110|  45.6k|{
 1111|  45.6k|	sc_algorithm_info_t *p;
 1112|       |
 1113|  45.6k|	if (info == NULL) {
  ------------------
  |  Branch (1113:6): [True: 0, False: 45.6k]
  ------------------
 1114|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1115|      0|	}
 1116|  45.6k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1117|  45.6k|	if (!p) {
  ------------------
  |  Branch (1117:6): [True: 0, False: 45.6k]
  ------------------
 1118|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1119|      0|	}
 1120|  45.6k|	card->algorithms = p;
 1121|  45.6k|	p += card->algorithm_count;
 1122|  45.6k|	card->algorithm_count++;
 1123|  45.6k|	*p = *info;
 1124|  45.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  45.6k|#define SC_SUCCESS				0
  ------------------
 1125|  45.6k|}
_sc_card_add_symmetric_alg:
 1129|    133|{
 1130|    133|	sc_algorithm_info_t info;
 1131|       |
 1132|    133|	memset(&info, 0, sizeof(info));
 1133|    133|	info.algorithm = algorithm;
 1134|    133|	info.key_length = key_length;
 1135|    133|	info.flags = flags;
 1136|       |
 1137|    133|	return _sc_card_add_algorithm(card, &info);
 1138|    133|}
_sc_card_add_ec_alg:
 1175|  7.79k|{
 1176|  7.79k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1177|  7.79k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   70|  7.79k|#define SC_ALGORITHM_EC		2
  ------------------
 1178|  7.79k|}
_sc_card_add_eddsa_alg:
 1183|    247|{
 1184|       |	/* For simplicity, share the ec union with the curve information */
 1185|    247|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1186|    247|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   72|    247|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1187|    247|}
_sc_card_add_xeddsa_alg:
 1192|    815|{
 1193|       |	/* For simplicity, share the ec union with the curve information */
 1194|    815|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1195|    815|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   73|    815|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1196|    815|}
sc_card_find_alg:
 1200|    721|{
 1201|    721|	int i;
 1202|       |
 1203|  2.18k|	for (i = 0; i < card->algorithm_count; i++) {
  ------------------
  |  Branch (1203:14): [True: 1.92k, False: 258]
  ------------------
 1204|  1.92k|		sc_algorithm_info_t *info = &card->algorithms[i];
 1205|       |
 1206|  1.92k|		if (param && (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|    596|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1206:7): [True: 298, False: 1.62k]
  |  Branch (1206:17): [True: 92, False: 206]
  ------------------
 1207|    206|			info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|    504|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1207:4): [True: 72, False: 134]
  ------------------
 1208|    226|			info->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|    134|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1208:4): [True: 62, False: 72]
  ------------------
 1209|    226|			if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id))
  ------------------
  |  Branch (1209:8): [True: 20, False: 206]
  ------------------
 1210|     20|				return info;
 1211|  1.69k|		} else if (info->algorithm != algorithm) {
  ------------------
  |  Branch (1211:14): [True: 258, False: 1.43k]
  ------------------
 1212|    258|			continue;
 1213|  1.43k|		} else if (info->key_length == key_length)
  ------------------
  |  Branch (1213:14): [True: 443, False: 996]
  ------------------
 1214|    443|			return info;
 1215|  1.92k|	}
 1216|    258|	return NULL;
 1217|    721|}
sc_card_find_ec_alg:
 1221|    204|{
 1222|    204|	return sc_card_find_alg(card, SC_ALGORITHM_EC, key_length, curve_name);
  ------------------
  |  |   70|    204|#define SC_ALGORITHM_EC		2
  ------------------
 1223|    204|}
sc_card_find_eddsa_alg:
 1227|    102|{
 1228|    102|	return sc_card_find_alg(card, SC_ALGORITHM_EDDSA, key_length, curve_name);
  ------------------
  |  |   72|    102|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1229|    102|}
sc_card_find_xeddsa_alg:
 1233|      1|{
 1234|      1|	return sc_card_find_alg(card, SC_ALGORITHM_XEDDSA, key_length, curve_name);
  ------------------
  |  |   73|      1|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1235|      1|}
_sc_card_add_rsa_alg:
 1239|  36.5k|{
 1240|  36.5k|	sc_algorithm_info_t info;
 1241|       |
 1242|  36.5k|	memset(&info, 0, sizeof(info));
 1243|  36.5k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  36.5k|#define SC_ALGORITHM_RSA		0
  ------------------
 1244|  36.5k|	info.key_length = key_length;
 1245|  36.5k|	info.flags = flags;
 1246|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1247|  36.5k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  102|  36.5k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  36.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  102|  36.5k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1247:6): [True: 4.25k, False: 32.3k]
  ------------------
 1248|  4.25k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|  4.25k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1248:7): [True: 0, False: 4.25k]
  ------------------
 1249|      0|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
 1250|  4.25k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  110|  4.25k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1250:7): [True: 4.25k, False: 0]
  ------------------
 1251|  4.25k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  4.25k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1252|  4.25k|	}
 1253|  36.5k|	info.u._rsa.exponent = exponent;
 1254|       |
 1255|  36.5k|	return _sc_card_add_algorithm(card, &info);
 1256|  36.5k|}
sc_card_find_rsa_alg:
 1259|    413|{
 1260|    413|	return sc_card_find_alg(card, SC_ALGORITHM_RSA, key_length, NULL);
  ------------------
  |  |   69|    413|#define SC_ALGORITHM_RSA		0
  ------------------
 1261|    413|}
sc_card_find_gostr3410_alg:
 1264|      1|{
 1265|      1|	return sc_card_find_alg(card, SC_ALGORITHM_GOSTR3410, key_length, NULL);
  ------------------
  |  |   71|      1|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
 1266|      1|}
_sc_match_atr:
 1332|   336k|{
 1333|   336k|	int res;
 1334|       |
 1335|   336k|	if (card == NULL)
  ------------------
  |  Branch (1335:6): [True: 0, False: 336k]
  ------------------
 1336|      0|		return -1;
 1337|   336k|	res = match_atr_table(card->ctx, table, &card->atr);
 1338|   336k|	if (res < 0)
  ------------------
  |  Branch (1338:6): [True: 327k, False: 9.48k]
  ------------------
 1339|   327k|		return res;
 1340|  9.48k|	if (type_out != NULL)
  ------------------
  |  Branch (1340:6): [True: 9.10k, False: 380]
  ------------------
 1341|  9.10k|		*type_out = table[res].type;
 1342|  9.48k|	return res;
 1343|   336k|}
_sc_match_atr_block:
 1346|  12.0k|{
 1347|  12.0k|	struct sc_card_driver *drv;
 1348|  12.0k|	struct sc_atr_table *table;
 1349|  12.0k|	int res;
 1350|       |
 1351|  12.0k|	if (ctx == NULL)
  ------------------
  |  Branch (1351:6): [True: 0, False: 12.0k]
  ------------------
 1352|      0|		return NULL;
 1353|  12.0k|	if (driver) {
  ------------------
  |  Branch (1353:6): [True: 12.0k, False: 0]
  ------------------
 1354|  12.0k|		drv = driver;
 1355|  12.0k|		table = drv->atr_map;
 1356|  12.0k|		res = match_atr_table(ctx, table, atr);
 1357|  12.0k|		if (res < 0)
  ------------------
  |  Branch (1357:7): [True: 12.0k, False: 0]
  ------------------
 1358|  12.0k|			return NULL;
 1359|      0|		return table[res].card_atr;
 1360|  12.0k|	} else {
 1361|      0|		unsigned int i;
 1362|       |
 1363|      0|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (1363:15): [True: 0, False: 0]
  ------------------
 1364|      0|			drv = ctx->card_drivers[i];
 1365|      0|			table = drv->atr_map;
 1366|      0|			res = match_atr_table(ctx, table, atr);
 1367|      0|			if (res < 0)
  ------------------
  |  Branch (1367:8): [True: 0, False: 0]
  ------------------
 1368|      0|				continue;
 1369|      0|			return table[res].card_atr;
 1370|      0|		}
 1371|      0|	}
 1372|      0|	return NULL;
 1373|  12.0k|}
sc_get_conf_block:
 1444|  41.8k|{
 1445|  41.8k|	int i;
 1446|  41.8k|	scconf_block *conf_block = NULL;
 1447|       |
 1448|  83.7k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1448:14): [True: 41.8k, False: 41.8k]
  ------------------
 1449|  41.8k|		scconf_block **blocks;
 1450|       |
 1451|  41.8k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1452|  41.8k|		if (blocks != NULL) {
  ------------------
  |  Branch (1452:7): [True: 41.8k, False: 0]
  ------------------
 1453|  41.8k|			conf_block = blocks[0];
 1454|  41.8k|			free(blocks);
 1455|  41.8k|		}
 1456|  41.8k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1456:7): [True: 0, False: 41.8k]
  |  Branch (1456:29): [True: 0, False: 0]
  ------------------
 1457|      0|			break;
 1458|  41.8k|	}
 1459|  41.8k|	return conf_block;
 1460|  41.8k|}
sc_clear_ec_params:
 1464|  8.85k|{
 1465|  8.85k|	if (ecp) {
  ------------------
  |  Branch (1465:6): [True: 8.85k, False: 0]
  ------------------
 1466|  8.85k|		free(ecp->named_curve);
 1467|  8.85k|		free(ecp->der.value);
 1468|  8.85k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1469|  8.85k|	}
 1470|  8.85k|	return;
 1471|  8.85k|}
card.c:sc_card_new:
  126|  15.2k|{
  127|  15.2k|	sc_card_t *card;
  128|       |
  129|  15.2k|	if (ctx == NULL)
  ------------------
  |  Branch (129:6): [True: 0, False: 15.2k]
  ------------------
  130|      0|		return NULL;
  131|       |
  132|  15.2k|	card = calloc(1, sizeof(struct sc_card));
  133|  15.2k|	if (card == NULL)
  ------------------
  |  Branch (133:6): [True: 0, False: 15.2k]
  ------------------
  134|      0|		return NULL;
  135|  15.2k|	card->ops = malloc(sizeof(struct sc_card_operations));
  136|  15.2k|	if (card->ops == NULL) {
  ------------------
  |  Branch (136:6): [True: 0, False: 15.2k]
  ------------------
  137|      0|		free(card);
  138|      0|		return NULL;
  139|      0|	}
  140|       |
  141|  15.2k|	card->ctx = ctx;
  142|  15.2k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (142:6): [True: 0, False: 15.2k]
  ------------------
  143|      0|		free(card->ops);
  144|      0|		free(card);
  145|      0|		return NULL;
  146|      0|	}
  147|       |
  148|  15.2k|	card->type = -1;
  149|  15.2k|	card->app_count = -1;
  150|       |
  151|  15.2k|	return card;
  152|  15.2k|}
card.c:sc_card_free:
  155|  15.2k|{
  156|  15.2k|	sc_free_apps(card);
  157|  15.2k|	sc_free_ef_atr(card);
  158|       |
  159|  15.2k|	free(card->ops);
  160|       |
  161|  15.2k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (161:6): [True: 11.0k, False: 4.25k]
  ------------------
  162|  11.0k|		int i;
  163|  56.6k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (163:13): [True: 45.6k, False: 11.0k]
  ------------------
  164|  45.6k|			struct sc_algorithm_info *info = (card->algorithms + i);
  165|  45.6k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|  91.2k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (165:8): [True: 7.79k, False: 37.8k]
  ------------------
  166|  37.8k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|  83.4k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (166:6): [True: 247, False: 37.5k]
  ------------------
  167|  37.5k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|  37.5k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (167:6): [True: 815, False: 36.7k]
  ------------------
  168|  8.85k|				sc_clear_ec_params(&info->u._ec.params);
  169|  8.85k|			}
  170|  45.6k|		}
  171|  11.0k|		free(card->algorithms);
  172|       |
  173|  11.0k|		card->algorithms = NULL;
  174|  11.0k|		card->algorithm_count = 0;
  175|  11.0k|	}
  176|       |
  177|  15.2k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (177:6): [True: 0, False: 15.2k]
  ------------------
  178|      0|		int r = sc_mutex_destroy(card->ctx, card->mutex);
  179|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (179:7): [True: 0, False: 0]
  ------------------
  180|      0|			sc_log(card->ctx, "unable to destroy mutex");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  181|      0|	}
  182|  15.2k|	sc_mem_clear(card, sizeof(*card));
  183|  15.2k|	free(card);
  184|  15.2k|}
card.c:_sc_card_add_ec_alg_int:
 1145|  8.85k|{
 1146|  8.85k|	sc_algorithm_info_t info;
 1147|  8.85k|	int r;
 1148|       |
 1149|  8.85k|	memset(&info, 0, sizeof(info));
 1150|  8.85k|	sc_init_oid(&info.u._ec.params.id);
 1151|       |
 1152|  8.85k|	info.algorithm = algorithm;
 1153|  8.85k|	info.key_length = key_length;
 1154|  8.85k|	info.flags = flags;
 1155|       |
 1156|  8.85k|	info.u._ec.ext_flags = ext_flags;
 1157|  8.85k|	if (curve_oid) {
  ------------------
  |  Branch (1157:6): [True: 5.08k, False: 3.77k]
  ------------------
 1158|  5.08k|		info.u._ec.params.id = *curve_oid;
 1159|  5.08k|		r = sc_encode_oid(card->ctx, &info.u._ec.params.id, &info.u._ec.params.der.value, &info.u._ec.params.der.len);
 1160|  5.08k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  5.08k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.08k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.08k|	int _ret = (r); \
  |  |  |  |  178|  5.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 5.08k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  5.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 5.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1161|  5.08k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1162|  5.08k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  5.08k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.08k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.08k|	int _ret = (r); \
  |  |  |  |  178|  5.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 5.08k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  5.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 5.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1163|  5.08k|	}
 1164|       |
 1165|  8.85k|	r = _sc_card_add_algorithm(card, &info);
 1166|  8.85k|	return r;
 1167|      0|err:
 1168|      0|	sc_clear_ec_params(&info.u._ec.params);
 1169|      0|	return r;
 1170|  8.85k|}
card.c:match_atr_table:
 1269|   348k|{
 1270|   348k|	u8 *card_atr_bin;
 1271|   348k|	size_t card_atr_bin_len;
 1272|   348k|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1273|   348k|	size_t card_atr_hex_len;
 1274|   348k|	unsigned int i = 0;
 1275|       |
 1276|   348k|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1276:6): [True: 0, False: 348k]
  |  Branch (1276:21): [True: 12.0k, False: 336k]
  |  Branch (1276:38): [True: 0, False: 336k]
  ------------------
 1277|  12.0k|		return -1;
 1278|   336k|	card_atr_bin = atr->value;
 1279|   336k|	card_atr_bin_len = atr->len;
 1280|   336k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1281|   336k|	card_atr_hex_len = strlen(card_atr_hex);
 1282|       |
 1283|   336k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   336k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1284|       |
 1285|  2.84M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1285:14): [True: 2.52M, False: 327k]
  ------------------
 1286|  2.52M|		const char *tatr = table[i].atr;
 1287|  2.52M|		const char *matr = table[i].atrmask;
 1288|  2.52M|		size_t tatr_len = strlen(tatr);
 1289|  2.52M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1290|  2.52M|		size_t mbin_len, tbin_len, s, matr_len;
 1291|  2.52M|		size_t fix_hex_len = card_atr_hex_len;
 1292|  2.52M|		size_t fix_bin_len = card_atr_bin_len;
 1293|       |
 1294|  2.52M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.52M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1295|       |
 1296|  2.52M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1296:7): [True: 2.45M, False: 63.4k]
  ------------------
 1297|  2.45M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.45M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1298|  2.45M|			continue;
 1299|  2.45M|		}
 1300|  63.4k|		if (matr != NULL) {
  ------------------
  |  Branch (1300:7): [True: 17.2k, False: 46.2k]
  ------------------
 1301|  17.2k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  17.2k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1302|       |
 1303|  17.2k|			matr_len = strlen(matr);
 1304|  17.2k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1304:8): [True: 0, False: 17.2k]
  ------------------
 1305|      0|				continue;
 1306|  17.2k|			tbin_len = sizeof(tbin);
 1307|  17.2k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1308|  17.2k|			mbin_len = sizeof(mbin);
 1309|  17.2k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1310|  17.2k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1310:8): [True: 0, False: 17.2k]
  ------------------
 1311|      0|				sc_debug(ctx, SC_LOG_DEBUG_MATCH, "length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1312|      0|				continue;
 1313|      0|			}
 1314|   337k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1314:16): [True: 320k, False: 17.2k]
  ------------------
 1315|       |				/* reduce tatr with mask */
 1316|   320k|				tbin[s] = (tbin[s] & mbin[s]);
 1317|       |				/* create copy of card_atr_bin masked) */
 1318|   320k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1319|   320k|			}
 1320|  17.2k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1320:8): [True: 13.0k, False: 4.15k]
  ------------------
 1321|  13.0k|				continue;
 1322|  46.2k|		} else {
 1323|  46.2k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1323:8): [True: 40.9k, False: 5.33k]
  ------------------
 1324|  40.9k|				continue;
 1325|  46.2k|		}
 1326|  9.48k|		return i;
 1327|  63.4k|	}
 1328|   327k|	return -1;
 1329|   336k|}
card.c:sc_card_sm_unload:
 1510|  12.0k|{
 1511|  12.0k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1511:6): [True: 0, False: 12.0k]
  ------------------
 1512|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1513|       |
 1514|  12.0k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1514:6): [True: 0, False: 12.0k]
  ------------------
 1515|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1516|       |	card->sm_ctx.module.handle = NULL;
 1517|  12.0k|	return 0;
 1518|  12.0k|}
card.c:sc_card_sm_check:
 1613|  12.0k|{
 1614|  12.0k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1615|  12.0k|	struct sc_context *ctx = card->ctx;
 1616|  12.0k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1617|  12.0k|	int rv, ii;
 1618|       |#ifdef _WIN32
 1619|       |	char temp_path[PATH_MAX];
 1620|       |	size_t temp_len = PATH_MAX - 1;
 1621|       |	char expanded_val[PATH_MAX];
 1622|       |	DWORD expanded_len = PATH_MAX;
 1623|       |#endif
 1624|       |
 1625|  12.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1626|       |
 1627|       |	/* get the name of card specific SM configuration section */
 1628|  12.0k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1629|  12.0k|	if (atrblock == NULL)
  ------------------
  |  Branch (1629:6): [True: 12.0k, False: 0]
  ------------------
 1630|  12.0k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.0k|	int _ret = r; \
  |  |  |  |  155|  12.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.0k|	return _ret; \
  |  |  |  |  163|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1631|      0|	sm = scconf_get_str(atrblock, "secure_messaging", NULL);
 1632|      0|	if (!sm)
  ------------------
  |  Branch (1632:6): [True: 0, False: 0]
  ------------------
 1633|      0|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1634|       |
 1635|       |	/* get SM configuration section by the name */
 1636|      0|	sc_log(ctx, "secure_messaging configuration block '%s'", sm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1637|      0|        for (ii = 0; ctx->conf_blocks[ii]; ii++) {
  ------------------
  |  Branch (1637:22): [True: 0, False: 0]
  ------------------
 1638|      0|		scconf_block **blocks;
 1639|       |
 1640|      0|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[ii], "secure_messaging", sm);
 1641|      0|		if (blocks) {
  ------------------
  |  Branch (1641:7): [True: 0, False: 0]
  ------------------
 1642|      0|			sm_conf_block = blocks[0];
 1643|      0|			free(blocks);
 1644|      0|		}
 1645|      0|		if (sm_conf_block != NULL)
  ------------------
  |  Branch (1645:7): [True: 0, False: 0]
  ------------------
 1646|      0|			break;
 1647|      0|	}
 1648|       |
 1649|      0|	if (!sm_conf_block)
  ------------------
  |  Branch (1649:6): [True: 0, False: 0]
  ------------------
 1650|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "SM configuration block not preset");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1651|       |
 1652|       |	/* check if an external SM module has to be used */
 1653|       |#ifdef _WIN32
 1654|       |	rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
 1655|       |			temp_path, &temp_len);
 1656|       |	if (rv == SC_SUCCESS) {
 1657|       |		temp_path[temp_len] = '\0';
 1658|       |		module_path = temp_path;
 1659|       |	}
 1660|       |	expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len);
 1661|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1662|       |		module_path = expanded_val;
 1663|       |#else
 1664|      0|	module_path = scconf_get_str(sm_conf_block, "module_path", DEFAULT_SM_MODULE_PATH);
 1665|      0|#endif
 1666|      0|	module_name = scconf_get_str(sm_conf_block, "module_name", DEFAULT_SM_MODULE);
 1667|      0|	sc_log(ctx, "SM module '%s' in  '%s'", module_name, module_path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1668|      0|	if (!module_name)
  ------------------
  |  Branch (1668:6): [True: 0, False: 0]
  ------------------
 1669|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "Invalid SM configuration: module not defined");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1670|       |
 1671|      0|	rv = sc_card_sm_load(card, module_path, module_name);
 1672|      0|	LOG_TEST_RET(ctx, rv, "Failed to load SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1673|       |
 1674|      0|	strlcpy(card->sm_ctx.module.filename, module_name, sizeof(card->sm_ctx.module.filename));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1675|      0|	strlcpy(card->sm_ctx.config_section, sm, sizeof(card->sm_ctx.config_section));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1676|       |
 1677|       |	/* allocate resources for the external SM module */
 1678|      0|	if (card->sm_ctx.module.ops.module_init)   {
  ------------------
  |  Branch (1678:6): [True: 0, False: 0]
  ------------------
 1679|      0|		module_data = scconf_get_str(sm_conf_block, "module_data", NULL);
 1680|       |
 1681|      0|		rv = card->sm_ctx.module.ops.module_init(ctx, module_data);
 1682|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1683|      0|	}
 1684|       |
 1685|       |	/* initialize SM session in the case of 'APDU TRANSMIT' SM mode */
 1686|      0|	sm_mode = scconf_get_str(sm_conf_block, "mode", NULL);
 1687|      0|	if (sm_mode && !strcasecmp("Transmit", sm_mode))   {
  ------------------
  |  Branch (1687:6): [True: 0, False: 0]
  |  Branch (1687:17): [True: 0, False: 0]
  ------------------
 1688|      0|		if (!card->sm_ctx.ops.open || !card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (1688:7): [True: 0, False: 0]
  |  Branch (1688:33): [True: 0, False: 0]
  |  Branch (1688:66): [True: 0, False: 0]
  ------------------
 1689|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "'Transmit' SM asked but not supported by card driver");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1690|       |
 1691|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1692|      0|		rv = card->sm_ctx.ops.open(card);
 1693|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1694|      0|	}
 1695|       |
 1696|      0|	sc_log(ctx, "SM mode:%X", card->sm_ctx.sm_mode);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1697|      0|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, rv);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1698|      0|}

sc_decompress_alloc:
  254|    316|{
  255|    316|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (255:6): [True: 0, False: 316]
  |  Branch (255:20): [True: 0, False: 316]
  ------------------
  256|      0|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      0|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  257|      0|	}
  258|       |
  259|    316|	if (method == COMPRESSION_AUTO) {
  ------------------
  |  |   26|    316|#define COMPRESSION_AUTO	0
  ------------------
  |  Branch (259:6): [True: 316, False: 0]
  ------------------
  260|    316|		method = detect_method(in, inLen);
  261|    316|		if (method == COMPRESSION_UNKNOWN) {
  ------------------
  |  |   29|    316|#define COMPRESSION_UNKNOWN (-1)
  ------------------
  |  Branch (261:7): [True: 138, False: 178]
  ------------------
  262|    138|			return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|    138|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  263|    138|		}
  264|    316|	}
  265|       |
  266|    178|	switch (method) {
  267|    177|	case COMPRESSION_ZLIB:
  ------------------
  |  |   27|    177|#define COMPRESSION_ZLIB	1
  ------------------
  |  Branch (267:2): [True: 177, False: 1]
  ------------------
  268|    177|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 0);
  269|      1|	case COMPRESSION_GZIP:
  ------------------
  |  |   28|      1|#define COMPRESSION_GZIP	2
  ------------------
  |  Branch (269:2): [True: 1, False: 177]
  ------------------
  270|      1|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 1);
  271|      0|	default:
  ------------------
  |  Branch (271:2): [True: 0, False: 178]
  ------------------
  272|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  273|    178|	}
  274|    178|}
compression.c:zerr_to_opensc:
   34|    178|static int zerr_to_opensc(int err) {
   35|    178|	switch(err) {
   36|      0|	case Z_OK:
  ------------------
  |  Branch (36:2): [True: 0, False: 178]
  ------------------
   37|     68|	case Z_STREAM_END:
  ------------------
  |  Branch (37:2): [True: 68, False: 110]
  ------------------
   38|     68|		return SC_SUCCESS;
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
   39|      1|	case Z_UNKNOWN:
  ------------------
  |  Branch (39:2): [True: 1, False: 177]
  ------------------
   40|      1|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      1|#define SC_ERROR_UNKNOWN			-1900
  ------------------
   41|     88|	case Z_DATA_ERROR:
  ------------------
  |  Branch (41:2): [True: 88, False: 90]
  ------------------
   42|    109|	case Z_BUF_ERROR:
  ------------------
  |  Branch (42:2): [True: 21, False: 157]
  ------------------
   43|    109|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|    109|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   44|      0|	case Z_MEM_ERROR:
  ------------------
  |  Branch (44:2): [True: 0, False: 178]
  ------------------
   45|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
   46|      0|	case Z_VERSION_ERROR:
  ------------------
  |  Branch (46:2): [True: 0, False: 178]
  ------------------
   47|      0|	case Z_STREAM_ERROR:
  ------------------
  |  Branch (47:2): [True: 0, False: 178]
  ------------------
   48|       |	/* case Z_NEED_DICT: */
   49|      0|	default:
  ------------------
  |  Branch (49:2): [True: 0, False: 178]
  ------------------
   50|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   51|    178|	}
   52|    178|}
compression.c:detect_method:
   53|    316|static int detect_method(const u8* in, size_t inLen) {
   54|    316|	if (in != NULL && inLen > 1) {
  ------------------
  |  Branch (54:6): [True: 316, False: 0]
  |  Branch (54:20): [True: 261, False: 55]
  ------------------
   55|    261|		if (in[0] == 0x1f && in[1] == 0x8b)
  ------------------
  |  Branch (55:7): [True: 14, False: 247]
  |  Branch (55:24): [True: 1, False: 13]
  ------------------
   56|      1|			return COMPRESSION_GZIP;
  ------------------
  |  |   28|      1|#define COMPRESSION_GZIP	2
  ------------------
   57|       |		/*
   58|       |		 * A zlib stream has the following structure:
   59|       |		 *   0   1
   60|       |		 * +---+---+
   61|       |		 * |CMF|FLG|   (more-->)
   62|       |		 * +---+---+
   63|       |		 *
   64|       |		 * FLG (FLaGs)
   65|       |		 * 	This flag byte is divided as follows:
   66|       |		 *
   67|       |		 * 	bits 0 to 4  FCHECK  (check bits for CMF and FLG)
   68|       |		 * 	bit  5       FDICT   (preset dictionary)
   69|       |		 * 	bits 6 to 7  FLEVEL  (compression level)
   70|       |		 *
   71|       |		 * 	The FCHECK value must be such that CMF and FLG, when viewed as
   72|       |		 * 	a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
   73|       |		 * 	is a multiple of 31.
   74|       |		 */
   75|    260|		if ((((uint16_t) in[0])*256 + in[1]) % 31 == 0)
  ------------------
  |  Branch (75:7): [True: 177, False: 83]
  ------------------
   76|    177|			return COMPRESSION_ZLIB;
  ------------------
  |  |   27|    177|#define COMPRESSION_ZLIB	1
  ------------------
   77|    260|	}
   78|    138|	return COMPRESSION_UNKNOWN;
  ------------------
  |  |   29|    138|#define COMPRESSION_UNKNOWN (-1)
  ------------------
   79|    316|}
compression.c:sc_decompress_zlib_alloc:
  185|    178|static int sc_decompress_zlib_alloc(u8** out, size_t* outLen, const u8* in, size_t inLen, int gzip) {
  186|       |	/* Since uncompress does not offer a way to make it uncompress gzip... manually set it up */
  187|    178|	z_stream gz;
  188|    178|	int err;
  189|    178|	int window_size = 15;
  190|    178|	const size_t startSize = inLen < 1024 ? 2048 : inLen * 2;
  ------------------
  |  Branch (190:27): [True: 137, False: 41]
  ------------------
  191|    178|	const size_t blockSize = inLen < 1024 ? 512 : inLen / 2;
  ------------------
  |  Branch (191:27): [True: 137, False: 41]
  ------------------
  192|    178|	size_t bufferSize = startSize;
  193|    178|	if (gzip)
  ------------------
  |  Branch (193:6): [True: 1, False: 177]
  ------------------
  194|      1|		window_size += 0x20;
  195|    178|	memset(&gz, 0, sizeof(gz));
  196|       |
  197|    178|	if (!out || !outLen)
  ------------------
  |  Branch (197:6): [True: 0, False: 178]
  |  Branch (197:14): [True: 0, False: 178]
  ------------------
  198|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  199|       |
  200|    178|	gz.next_in = (u8*)in;
  201|    178|	gz.avail_in = (unsigned)inLen;
  202|       |
  203|    178|	err = inflateInit2(&gz, window_size);
  204|    178|	if (err != Z_OK)
  ------------------
  |  Branch (204:6): [True: 0, False: 178]
  ------------------
  205|      0|		return zerr_to_opensc(err);
  206|       |
  207|    178|	*outLen = 0;
  208|       |
  209|    250|	while (1) {
  ------------------
  |  Branch (209:9): [True: 250, Folded]
  ------------------
  210|       |		/* Setup buffer... */
  211|    250|		size_t num;
  212|    250|		u8* buf = realloc(*out, bufferSize);
  213|    250|		if (!buf) {
  ------------------
  |  Branch (213:7): [True: 0, False: 250]
  ------------------
  214|      0|			free(*out);
  215|      0|			*out = NULL;
  216|      0|			inflateEnd(&gz);
  217|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  218|      0|		}
  219|    250|		*out = buf;
  220|    250|		gz.next_out = buf + *outLen;
  221|    250|		gz.avail_out = (unsigned)(bufferSize - *outLen);
  222|       |
  223|    250|		err = inflate(&gz, Z_FULL_FLUSH);
  224|    250|		if (err != Z_STREAM_END && err != Z_OK) {
  ------------------
  |  Branch (224:7): [True: 182, False: 68]
  |  Branch (224:30): [True: 110, False: 72]
  ------------------
  225|    110|			free(*out);
  226|    110|			*out = NULL;
  227|    110|			break;
  228|    110|		}
  229|    140|		num = *outLen + gz.avail_out;
  230|    140|		if (bufferSize > num) {
  ------------------
  |  Branch (230:7): [True: 139, False: 1]
  ------------------
  231|    139|			*outLen += bufferSize - num;
  232|    139|			bufferSize += bufferSize - num + blockSize;
  233|    139|		}
  234|    140|		if (err == Z_STREAM_END) {
  ------------------
  |  Branch (234:7): [True: 68, False: 72]
  ------------------
  235|     68|			if (*outLen > 0) {
  ------------------
  |  Branch (235:8): [True: 68, False: 0]
  ------------------
  236|       |				/* Shrink it down, if it fails, just use old data */
  237|     68|				buf = realloc(buf, *outLen);
  238|     68|				if (buf) {
  ------------------
  |  Branch (238:9): [True: 68, False: 0]
  ------------------
  239|     68|					*out = buf;
  240|     68|				}
  241|     68|			} else {
  242|      0|				free(*out);
  243|      0|				*out = NULL;
  244|      0|				err = Z_DATA_ERROR;
  245|      0|			}
  246|     68|			break;
  247|     68|		}
  248|    140|	}
  249|    178|	inflateEnd(&gz);
  250|    178|	return zerr_to_opensc(err);
  251|    178|}

_sc_delete_reader:
   85|  15.2k|{
   86|  15.2k|	if (reader == NULL) {
  ------------------
  |  Branch (86:6): [True: 0, False: 15.2k]
  ------------------
   87|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   88|      0|	}
   89|  15.2k|	if (reader->ops->release)
  ------------------
  |  Branch (89:6): [True: 15.2k, False: 0]
  ------------------
   90|  15.2k|			reader->ops->release(reader);
   91|  15.2k|	free(reader->name);
   92|  15.2k|	free(reader->vendor);
   93|  15.2k|	list_delete(&ctx->readers, reader);
   94|  15.2k|	free(reader);
   95|  15.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
   96|  15.2k|}
sc_ctx_detect_readers:
  785|  15.2k|{
  786|  15.2k|	int r = 0;
  787|  15.2k|	const struct sc_reader_driver *drv = ctx->reader_driver;
  788|       |
  789|  15.2k|	sc_mutex_lock(ctx, ctx->mutex);
  790|       |
  791|  15.2k|	if (drv->ops->detect_readers != NULL)
  ------------------
  |  Branch (791:6): [True: 0, False: 15.2k]
  ------------------
  792|      0|		r = drv->ops->detect_readers(ctx);
  793|       |
  794|  15.2k|	sc_mutex_unlock(ctx, ctx->mutex);
  795|       |
  796|  15.2k|	return r;
  797|  15.2k|}
sc_ctx_get_reader:
  800|  15.2k|{
  801|  15.2k|	return list_get_at(&ctx->readers, i);
  802|  15.2k|}
sc_context_create:
  949|  15.2k|{
  950|  15.2k|	sc_context_t		*ctx;
  951|  15.2k|	struct _sc_ctx_options	opts;
  952|  15.2k|	int			r;
  953|  15.2k|	char			*driver;
  954|       |
  955|  15.2k|	if (ctx_out == NULL || parm == NULL)
  ------------------
  |  Branch (955:6): [True: 0, False: 15.2k]
  |  Branch (955:25): [True: 0, False: 15.2k]
  ------------------
  956|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  957|       |
  958|  15.2k|	ctx = calloc(1, sizeof(sc_context_t));
  959|  15.2k|	if (ctx == NULL)
  ------------------
  |  Branch (959:6): [True: 0, False: 15.2k]
  ------------------
  960|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  961|  15.2k|	memset(&opts, 0, sizeof(opts));
  962|       |
  963|       |	/* set the application name if set in the parameter options */
  964|  15.2k|	if (parm->app_name != NULL)
  ------------------
  |  Branch (964:6): [True: 15.2k, False: 0]
  ------------------
  965|  15.2k|		ctx->app_name = strdup(parm->app_name);
  966|      0|	else
  967|      0|		ctx->app_name = strdup("default");
  968|  15.2k|	if (ctx->app_name == NULL) {
  ------------------
  |  Branch (968:6): [True: 0, False: 15.2k]
  ------------------
  969|      0|		sc_release_context(ctx);
  970|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  971|      0|	}
  972|       |
  973|  15.2k|	ctx->exe_path = get_exe_path();
  974|  15.2k|	if (ctx->exe_path == NULL) {
  ------------------
  |  Branch (974:6): [True: 0, False: 15.2k]
  ------------------
  975|      0|		sc_release_context(ctx);
  976|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  977|      0|	}
  978|       |
  979|  15.2k|	ctx->flags = parm->flags;
  980|  15.2k|	set_defaults(ctx, &opts);
  981|       |
  982|  15.2k|	if (0 != list_init(&ctx->readers)) {
  ------------------
  |  Branch (982:6): [True: 0, False: 15.2k]
  ------------------
  983|      0|		del_drvs(&opts);
  984|      0|		sc_release_context(ctx);
  985|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  986|      0|	}
  987|  15.2k|	list_attributes_seeker(&ctx->readers, reader_list_seeker);
  988|       |	/* set thread context and create mutex object (if specified) */
  989|  15.2k|	if (parm->thread_ctx != NULL)
  ------------------
  |  Branch (989:6): [True: 0, False: 15.2k]
  ------------------
  990|      0|		ctx->thread_ctx = parm->thread_ctx;
  991|  15.2k|	r = sc_mutex_create(ctx, &ctx->mutex);
  992|  15.2k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (992:6): [True: 0, False: 15.2k]
  ------------------
  993|      0|		del_drvs(&opts);
  994|      0|		sc_release_context(ctx);
  995|      0|		return r;
  996|      0|	}
  997|       |
  998|       |#if defined(ENABLE_OPENSSL) && defined(OPENSSL_SECURE_MALLOC_SIZE) && !defined(LIBRESSL_VERSION_NUMBER)
  999|       |	if (!CRYPTO_secure_malloc_initialized()) {
 1000|       |		CRYPTO_secure_malloc_init(OPENSSL_SECURE_MALLOC_SIZE, OPENSSL_SECURE_MALLOC_SIZE/8);
 1001|       |	}
 1002|       |#endif
 1003|       |
 1004|  15.2k|	process_config_file(ctx, &opts);
 1005|       |
 1006|       |	/* overwrite with caller's parameters if explicitly given */
 1007|  15.2k|	if (parm->debug) {
  ------------------
  |  Branch (1007:6): [True: 225, False: 15.0k]
  ------------------
 1008|    225|		ctx->debug = parm->debug;
 1009|    225|	}
 1010|  15.2k|	if (parm->debug_file) {
  ------------------
  |  Branch (1010:6): [True: 225, False: 15.0k]
  ------------------
 1011|    225|		if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (1011:7): [True: 225, False: 0]
  |  Branch (1011:27): [True: 0, False: 225]
  |  Branch (1011:56): [True: 0, False: 0]
  ------------------
 1012|      0|			fclose(ctx->debug_file);
 1013|    225|		ctx->debug_file = parm->debug_file;
 1014|    225|	}
 1015|       |
 1016|  15.2k|	sc_log(ctx, "==================================="); /* first thing in the log */
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1017|  15.2k|	sc_log(ctx, "OpenSC version: %s", sc_get_version());
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1018|  15.2k|	sc_log(ctx, "Configured for %s (%s)", ctx->app_name, ctx->exe_path);
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1019|       |
 1020|       |#ifdef USE_OPENSSL3_LIBCTX
 1021|       |	r = sc_openssl3_init(ctx);
 1022|       |	if (r != SC_SUCCESS) {
 1023|       |		del_drvs(&opts);
 1024|       |		sc_release_context(ctx);
 1025|       |		return r;
 1026|       |	}
 1027|       |#endif
 1028|       |
 1029|       |#ifdef ENABLE_PCSC
 1030|       |	ctx->reader_driver = sc_get_pcsc_driver();
 1031|       |#elif defined(ENABLE_CRYPTOTOKENKIT)
 1032|       |	ctx->reader_driver = sc_get_cryptotokenkit_driver();
 1033|       |#elif defined(ENABLE_CTAPI)
 1034|       |	ctx->reader_driver = sc_get_ctapi_driver();
 1035|       |#elif defined(ENABLE_OPENCT)
 1036|       |	ctx->reader_driver = sc_get_openct_driver();
 1037|       |#else
 1038|       |	ctx->reader_driver = sc_get_empty_driver();
 1039|       |#endif
 1040|       |
 1041|  15.2k|	r = ctx->reader_driver->ops->init(ctx);
 1042|  15.2k|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1042:6): [True: 0, False: 15.2k]
  ------------------
 1043|      0|		del_drvs(&opts);
 1044|      0|		sc_release_context(ctx);
 1045|      0|		return r;
 1046|      0|	}
 1047|       |
 1048|  15.2k|	driver = getenv("OPENSC_DRIVER");
 1049|  15.2k|	if (driver) {
  ------------------
  |  Branch (1049:6): [True: 0, False: 15.2k]
  ------------------
 1050|      0|		scconf_list *list = NULL;
 1051|      0|		scconf_list_add(&list, driver);
 1052|      0|		set_drivers(&opts, list);
 1053|      0|		scconf_list_destroy(list);
 1054|      0|	}
 1055|       |
 1056|  15.2k|	load_card_drivers(ctx, &opts);
 1057|  15.2k|	load_card_atrs(ctx);
 1058|       |
 1059|  15.2k|	del_drvs(&opts);
 1060|  15.2k|	sc_ctx_detect_readers(ctx);
 1061|  15.2k|	*ctx_out = ctx;
 1062|       |
 1063|  15.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
 1064|  15.2k|}
sc_release_context:
 1097|  15.2k|{
 1098|  15.2k|	unsigned int i;
 1099|       |
 1100|  15.2k|	if (ctx == NULL) {
  ------------------
  |  Branch (1100:6): [True: 0, False: 15.2k]
  ------------------
 1101|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1102|      0|	}
 1103|  15.2k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.2k]
  |  |  ------------------
  ------------------
 1104|  30.5k|	while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (1104:9): [True: 15.2k, False: 15.2k]
  ------------------
 1105|  15.2k|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
 1106|  15.2k|		_sc_delete_reader(ctx, rdr);
 1107|  15.2k|	}
 1108|       |
 1109|  15.2k|	if (ctx->reader_driver != NULL && ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (1109:6): [True: 15.2k, False: 0]
  |  Branch (1109:36): [True: 0, False: 15.2k]
  ------------------
 1110|      0|		ctx->reader_driver->ops->finish(ctx);
 1111|       |
 1112|   717k|	for (i = 0; ctx->card_drivers[i]; i++) {
  ------------------
  |  Branch (1112:14): [True: 701k, False: 15.2k]
  ------------------
 1113|   701k|		struct sc_card_driver *drv = ctx->card_drivers[i];
 1114|       |
 1115|   701k|		if (drv->atr_map)
  ------------------
  |  Branch (1115:7): [True: 0, False: 701k]
  ------------------
 1116|      0|			_sc_free_atr(ctx, drv);
 1117|   701k|		if (drv->dll)
  ------------------
  |  Branch (1117:7): [True: 0, False: 701k]
  ------------------
 1118|      0|			sc_dlclose(drv->dll);
 1119|   701k|	}
 1120|       |#ifdef USE_OPENSSL3_LIBCTX
 1121|       |	sc_openssl3_deinit(ctx);
 1122|       |#endif
 1123|  15.2k|	if (ctx->preferred_language != NULL)
  ------------------
  |  Branch (1123:6): [True: 0, False: 15.2k]
  ------------------
 1124|      0|		free(ctx->preferred_language);
 1125|  15.2k|	if (ctx->mutex != NULL) {
  ------------------
  |  Branch (1125:6): [True: 0, False: 15.2k]
  ------------------
 1126|      0|		int r = sc_mutex_destroy(ctx, ctx->mutex);
 1127|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1127:7): [True: 0, False: 0]
  ------------------
 1128|      0|			sc_log(ctx, "unable to destroy mutex");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1129|      0|			return r;
 1130|      0|		}
 1131|      0|	}
 1132|  15.2k|	if (ctx->conf != NULL)
  ------------------
  |  Branch (1132:6): [True: 15.2k, False: 0]
  ------------------
 1133|  15.2k|		scconf_free(ctx->conf);
 1134|  15.2k|	if (ctx->debug_file && (ctx->debug_file != stdout && ctx->debug_file != stderr))
  ------------------
  |  Branch (1134:6): [True: 15.2k, False: 0]
  |  Branch (1134:26): [True: 15.0k, False: 225]
  |  Branch (1134:55): [True: 0, False: 15.0k]
  ------------------
 1135|      0|		fclose(ctx->debug_file);
 1136|  15.2k|	free(ctx->debug_filename);
 1137|  15.2k|	free(ctx->app_name);
 1138|  15.2k|	free(ctx->exe_path);
 1139|  15.2k|	list_destroy(&ctx->readers);
 1140|  15.2k|	sc_mem_clear(ctx, sizeof(*ctx));
 1141|  15.2k|	free(ctx);
 1142|  15.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
 1143|  15.2k|}
ctx.c:load_card_atrs:
  633|  15.2k|{
  634|  15.2k|	struct sc_card_driver *driver;
  635|  15.2k|	scconf_block **blocks;
  636|  15.2k|	int i, j, k;
  637|       |
  638|  30.5k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (638:14): [True: 15.2k, False: 15.2k]
  ------------------
  639|  15.2k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "card_atr", NULL);
  640|  15.2k|		if (!blocks)
  ------------------
  |  Branch (640:7): [True: 0, False: 15.2k]
  ------------------
  641|      0|			continue;
  642|  15.2k|		for (j = 0; blocks[j] != NULL; j++) {
  ------------------
  |  Branch (642:15): [True: 0, False: 15.2k]
  ------------------
  643|      0|			scconf_block *b = blocks[j];
  644|      0|			char *atr = b->name->data;
  645|      0|			const scconf_list *list;
  646|      0|			struct sc_atr_table t;
  647|      0|			const char *dname;
  648|       |
  649|      0|			driver = NULL;
  650|       |
  651|      0|			if (strlen(atr) < 4)
  ------------------
  |  Branch (651:8): [True: 0, False: 0]
  ------------------
  652|      0|				continue;
  653|       |
  654|       |			/* The interesting part. If there's no card
  655|       |			 * driver assigned for the ATR, add it to
  656|       |			 * the default driver. This will reduce the
  657|       |			 * amount of code required to process things
  658|       |			 * related to card_atr blocks in situations,
  659|       |			 * where the code is not exactly related to
  660|       |			 * card driver settings, but for example
  661|       |			 * forcing a protocol at the reader driver.
  662|       |			 */
  663|      0|			dname = scconf_get_str(b, "driver", "default");
  664|       |
  665|       |			/* Find the card driver structure according to dname */
  666|      0|			for (k = 0; ctx->card_drivers[k] != NULL; k++) {
  ------------------
  |  Branch (666:16): [True: 0, False: 0]
  ------------------
  667|      0|				driver = ctx->card_drivers[k];
  668|      0|				if (!strcmp(dname, driver->short_name))
  ------------------
  |  Branch (668:9): [True: 0, False: 0]
  ------------------
  669|      0|					break;
  670|      0|				driver = NULL;
  671|      0|			}
  672|       |
  673|      0|			if (!driver)
  ------------------
  |  Branch (673:8): [True: 0, False: 0]
  ------------------
  674|      0|				continue;
  675|       |
  676|      0|			memset(&t, 0, sizeof(struct sc_atr_table));
  677|      0|			t.atr = atr;
  678|      0|			t.atrmask = (char *) scconf_get_str(b, "atrmask", NULL);
  679|      0|			t.name = (char *) scconf_get_str(b, "name", NULL);
  680|      0|			t.type = scconf_get_int(b, "type", SC_CARD_TYPE_UNKNOWN);
  681|      0|			list = scconf_find_list(b, "flags");
  682|      0|			while (list != NULL) {
  ------------------
  |  Branch (682:11): [True: 0, False: 0]
  ------------------
  683|      0|				unsigned int flags = 0;
  684|       |
  685|      0|				if (!list->data) {
  ------------------
  |  Branch (685:9): [True: 0, False: 0]
  ------------------
  686|      0|					list = list->next;
  687|      0|					continue;
  688|      0|				}
  689|       |
  690|      0|				if (!strcmp(list->data, "rng"))
  ------------------
  |  Branch (690:9): [True: 0, False: 0]
  ------------------
  691|      0|					flags = SC_CARD_FLAG_RNG;
  ------------------
  |  |  536|      0|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  692|      0|				else if (!strcmp(list->data, "keep_alive"))
  ------------------
  |  Branch (692:14): [True: 0, False: 0]
  ------------------
  693|      0|					flags = SC_CARD_FLAG_KEEP_ALIVE;
  ------------------
  |  |  537|      0|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  694|      0|				else if (sscanf(list->data, "%x", &flags) != 1)
  ------------------
  |  Branch (694:14): [True: 0, False: 0]
  ------------------
  695|      0|					flags = 0;
  696|       |
  697|      0|				t.flags |= flags;
  698|      0|				list = list->next;
  699|      0|			}
  700|      0|			t.card_atr = b;
  701|      0|			_sc_add_atr(ctx, driver, &t);
  702|      0|		}
  703|  15.2k|		free(blocks);
  704|  15.2k|	}
  705|  15.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  706|  15.2k|}
ctx.c:get_exe_path:
  914|  15.2k|{
  915|       |	/* Find the executable's path which runs this code.
  916|       |	 * See https://github.com/gpakosz/whereami/ for
  917|       |	 * potentially more platforms */
  918|  15.2k|	char exe_path[PATH_MAX] = "unknown executable path";
  919|  15.2k|	int path_found = 0;
  920|       |
  921|       |#if   defined(_WIN32)
  922|       |	if (0 < GetModuleFileNameA(NULL, exe_path, sizeof exe_path))
  923|       |		path_found = 1;
  924|       |#elif defined(__APPLE__)
  925|       |	if (0 < proc_pidpath(getpid(), exe_path, sizeof exe_path))
  926|       |		path_found = 1;
  927|       |#elif defined(__linux__) || defined(__CYGWIN__)
  928|  15.2k|	if (NULL != realpath("/proc/self/exe", exe_path))
  ------------------
  |  Branch (928:6): [True: 15.2k, False: 0]
  ------------------
  929|  15.2k|		path_found = 1;
  930|  15.2k|#endif
  931|       |
  932|       |#if defined(HAVE_GETPROGNAME)
  933|       |	if (!path_found) {
  934|       |		/* getprogname is unreliable and typically only returns the basename.
  935|       |		 * However, this should be enough for our purposes */
  936|       |		const char *prog = getprogname();
  937|       |		if (prog)
  938|       |			strlcpy(exe_path, prog, sizeof exe_path);
  939|       |	}
  940|       |#else
  941|       |	/* avoid warning "set but not used" */
  942|  15.2k|	(void) path_found;
  943|  15.2k|#endif
  944|       |
  945|  15.2k|	return strdup(exe_path);
  946|  15.2k|}
ctx.c:set_defaults:
  325|  15.2k|{
  326|  15.2k|	ctx->debug = 0;
  327|  15.2k|	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (327:6): [True: 0, False: 15.2k]
  |  Branch (327:26): [True: 0, False: 0]
  |  Branch (327:55): [True: 0, False: 0]
  ------------------
  328|      0|		fclose(ctx->debug_file);
  329|  15.2k|	ctx->debug_file = stderr;
  330|  15.2k|	ctx->flags = 0;
  331|       |	ctx->forced_driver = NULL;
  332|  15.2k|	add_internal_drvs(opts);
  333|  15.2k|}
ctx.c:add_internal_drvs:
  299|  30.5k|{
  300|  30.5k|	const struct _sc_driver_entry *lst;
  301|  30.5k|	int i;
  302|       |
  303|  30.5k|	lst = internal_card_drivers;
  304|  30.5k|	i = 0;
  305|  1.28M|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (305:9): [True: 1.25M, False: 30.5k]
  ------------------
  306|  1.25M|		add_drv(opts, lst[i].name);
  307|  1.25M|		i++;
  308|  1.25M|	}
  309|  30.5k|}
ctx.c:add_drv:
  281|  1.32M|{
  282|  1.32M|	struct _sc_driver_entry *lst;
  283|  1.32M|	int *cp, max, i;
  284|       |
  285|  1.32M|	lst = opts->cdrv;
  286|  1.32M|	cp = &opts->ccount;
  287|  1.32M|	max = SC_MAX_CARD_DRIVERS;
  ------------------
  |  |   31|  1.32M|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  288|  1.32M|	if (*cp == max) /* No space for more drivers... */
  ------------------
  |  Branch (288:6): [True: 0, False: 1.32M]
  ------------------
  289|      0|		return;
  290|  29.6M|	for (i = 0; i < *cp; i++)
  ------------------
  |  Branch (290:14): [True: 28.3M, False: 1.32M]
  ------------------
  291|  28.3M|		if (strcmp(name, lst[i].name) == 0)
  ------------------
  |  Branch (291:7): [True: 0, False: 28.3M]
  ------------------
  292|      0|			return;
  293|  1.32M|	lst[*cp].name = strdup(name);
  294|       |
  295|  1.32M|	*cp = *cp + 1;
  296|  1.32M|}
ctx.c:del_drvs:
  267|  30.5k|{
  268|  30.5k|	struct _sc_driver_entry *lst;
  269|  30.5k|	int *cp, i;
  270|       |
  271|  30.5k|	lst = opts->cdrv;
  272|  30.5k|	cp = &opts->ccount;
  273|       |
  274|  1.35M|	for (i = 0; i < *cp; i++) {
  ------------------
  |  Branch (274:14): [True: 1.32M, False: 30.5k]
  ------------------
  275|  1.32M|		free((void *)lst[i].name);
  276|  1.32M|	}
  277|  30.5k|	*cp = 0;
  278|  30.5k|}
ctx.c:process_config_file:
  709|  15.2k|{
  710|  15.2k|	int i, r, count = 0;
  711|  15.2k|	scconf_block **blocks;
  712|  15.2k|	const char *conf_path = NULL;
  713|  15.2k|	const char *debug = NULL;
  714|       |#ifdef _WIN32
  715|       |	char temp_path[PATH_MAX];
  716|       |	size_t temp_len;
  717|       |#endif
  718|       |
  719|       |	/* Takes effect even when no config around */
  720|  15.2k|	debug = getenv("OPENSC_DEBUG");
  721|  15.2k|	if (debug)
  ------------------
  |  Branch (721:6): [True: 0, False: 15.2k]
  ------------------
  722|      0|		ctx->debug = atoi(debug);
  723|       |
  724|  15.2k|	memset(ctx->conf_blocks, 0, sizeof(ctx->conf_blocks));
  725|       |#ifdef _WIN32
  726|       |	temp_len = PATH_MAX-1;
  727|       |	r = sc_ctx_win32_get_config_value("OPENSC_CONF", "ConfigFile", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
  728|       |			temp_path, &temp_len);
  729|       |	if (r)   {
  730|       |		sc_log(ctx, "process_config_file doesn't find opensc config file. Please set the registry key.");
  731|       |		return;
  732|       |	}
  733|       |	temp_path[temp_len] = '\0';
  734|       |	conf_path = temp_path;
  735|       |#else
  736|  15.2k|	conf_path = getenv("OPENSC_CONF");
  737|  15.2k|	if (!conf_path)
  ------------------
  |  Branch (737:6): [True: 15.2k, False: 0]
  ------------------
  738|  15.2k|		conf_path = OPENSC_CONF_PATH;
  739|  15.2k|#endif
  740|  15.2k|	ctx->conf = scconf_new(conf_path);
  741|  15.2k|	if (ctx->conf == NULL)
  ------------------
  |  Branch (741:6): [True: 0, False: 15.2k]
  ------------------
  742|      0|		return;
  743|  15.2k|	r = scconf_parse(ctx->conf);
  744|  15.2k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  745|  15.2k|#ifdef OPENSC_CONFIG_STRING
  746|       |	/* Parse the string if config file didn't exist */
  747|  15.2k|	if (r < 0)
  ------------------
  |  Branch (747:6): [True: 15.2k, False: 0]
  ------------------
  748|  15.2k|		r = scconf_parse_string(ctx->conf, OPENSC_CONFIG_STRING);
  ------------------
  |  |  744|  15.2k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  ------------------
  749|  15.2k|#endif
  750|  15.2k|	if (r < 1) {
  ------------------
  |  Branch (750:6): [True: 0, False: 15.2k]
  ------------------
  751|       |		/* A negative return value means the config file isn't
  752|       |		 * there, which is not an error. Nevertheless log this
  753|       |		 * fact. */
  754|      0|		if (r < 0)
  ------------------
  |  Branch (754:7): [True: 0, False: 0]
  ------------------
  755|      0|			sc_log(ctx, "scconf_parse failed: %s", ctx->conf->errmsg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  756|      0|		else
  757|      0|			sc_log(ctx, "scconf_parse failed: %s", ctx->conf->errmsg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  758|      0|		scconf_free(ctx->conf);
  759|      0|		ctx->conf = NULL;
  760|      0|		return;
  761|      0|	}
  762|       |	/* needs to be after the log file is known */
  763|  15.2k|	sc_log(ctx, "Used configuration file '%s'", conf_path);
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  764|  15.2k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->exe_path);
  765|  15.2k|	if (blocks && blocks[0])
  ------------------
  |  Branch (765:6): [True: 15.2k, False: 0]
  |  Branch (765:16): [True: 0, False: 15.2k]
  ------------------
  766|      0|		ctx->conf_blocks[count++] = blocks[0];
  767|  15.2k|	free(blocks);
  768|  15.2k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
  769|  15.2k|	if (blocks && blocks[0])
  ------------------
  |  Branch (769:6): [True: 15.2k, False: 0]
  |  Branch (769:16): [True: 0, False: 15.2k]
  ------------------
  770|      0|		ctx->conf_blocks[count++] = blocks[0];
  771|  15.2k|	free(blocks);
  772|  15.2k|	if (strcmp(ctx->app_name, "default") != 0) {
  ------------------
  |  Branch (772:6): [True: 15.2k, False: 0]
  ------------------
  773|  15.2k|		blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
  774|  15.2k|		if (blocks && blocks[0])
  ------------------
  |  Branch (774:7): [True: 15.2k, False: 0]
  |  Branch (774:17): [True: 15.2k, False: 0]
  ------------------
  775|  15.2k|			ctx->conf_blocks[count] = blocks[0];
  776|  15.2k|		free(blocks);
  777|  15.2k|	}
  778|       |	/* Above we add 3 blocks at most, but conf_blocks has 4 elements,
  779|       |	 * so at least one is NULL */
  780|  30.5k|	for (i = 0; ctx->conf_blocks[i]; i++)
  ------------------
  |  Branch (780:14): [True: 15.2k, False: 15.2k]
  ------------------
  781|  15.2k|		load_parameters(ctx, ctx->conf_blocks[i], opts);
  782|  15.2k|}
ctx.c:load_parameters:
  388|  15.2k|{
  389|  15.2k|	int err = 0;
  390|  15.2k|	const scconf_list *list;
  391|  15.2k|	const char *val;
  392|  15.2k|	int debug;
  393|  15.2k|	const char *disable_hw_pkcs1_padding;
  394|       |#ifdef _WIN32
  395|       |	char expanded_val[PATH_MAX];
  396|       |	DWORD expanded_len;
  397|       |#endif
  398|       |
  399|  15.2k|	debug = scconf_get_int(block, "debug", ctx->debug);
  400|  15.2k|	if (debug > ctx->debug)
  ------------------
  |  Branch (400:6): [True: 0, False: 15.2k]
  ------------------
  401|      0|		ctx->debug = debug;
  402|       |
  403|  15.2k|	val = scconf_get_str(block, "debug_file", NULL);
  404|  15.2k|	if (val)   {
  ------------------
  |  Branch (404:6): [True: 0, False: 15.2k]
  ------------------
  405|       |#ifdef _WIN32
  406|       |		expanded_len = PATH_MAX;
  407|       |		expanded_len = ExpandEnvironmentStringsA(val, expanded_val, expanded_len);
  408|       |		if (0 < expanded_len && expanded_len < sizeof expanded_val)
  409|       |			val = expanded_val;
  410|       |#endif
  411|      0|		sc_ctx_log_to_file(ctx, val);
  412|      0|	}
  413|  15.2k|	else if (ctx->debug)   {
  ------------------
  |  Branch (413:11): [True: 0, False: 15.2k]
  ------------------
  414|      0|		sc_ctx_log_to_file(ctx, NULL);
  415|      0|	}
  416|       |
  417|  15.2k|	if (scconf_get_bool (block, "disable_popups",
  ------------------
  |  Branch (417:6): [True: 0, False: 15.2k]
  ------------------
  418|  15.2k|				ctx->flags & SC_CTX_FLAG_DISABLE_POPUPS))
  ------------------
  |  |  861|  15.2k|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  419|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_POPUPS;
  ------------------
  |  |  861|      0|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  420|       |
  421|  15.2k|	if (scconf_get_bool (block, "disable_colors",
  ------------------
  |  Branch (421:6): [True: 0, False: 15.2k]
  ------------------
  422|  15.2k|				ctx->flags & SC_CTX_FLAG_DISABLE_COLORS))
  ------------------
  |  |  862|  15.2k|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  423|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_COLORS;
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  424|       |
  425|  15.2k|	if (scconf_get_bool (block, "enable_default_driver",
  ------------------
  |  Branch (425:6): [True: 0, False: 15.2k]
  ------------------
  426|  15.2k|				ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER))
  ------------------
  |  |  860|  15.2k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  427|      0|		ctx->flags |= SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER;
  ------------------
  |  |  860|      0|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  428|       |
  429|  15.2k|	list = scconf_find_list(block, "card_drivers");
  430|  15.2k|	set_drivers(opts, list);
  431|       |
  432|       |	/* Disable PKCS#1 v1.5 type 2 (for decryption) depadding on card by default */
  433|  15.2k|	disable_hw_pkcs1_padding = "decipher";
  434|  15.2k|	ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  15.2k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  435|  15.2k|	disable_hw_pkcs1_padding = scconf_get_str(block, "disable_hw_pkcs1_padding", disable_hw_pkcs1_padding);
  436|  15.2k|	if (0 == strcmp(disable_hw_pkcs1_padding, "no")) {
  ------------------
  |  Branch (436:6): [True: 0, False: 15.2k]
  ------------------
  437|      0|		ctx->disable_hw_pkcs1_padding = 0;
  438|  15.2k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "sign")) {
  ------------------
  |  Branch (438:13): [True: 0, False: 15.2k]
  ------------------
  439|      0|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  440|  15.2k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "decipher")) {
  ------------------
  |  Branch (440:13): [True: 15.2k, False: 0]
  ------------------
  441|  15.2k|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  15.2k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  442|  15.2k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "both")) {
  ------------------
  |  Branch (442:13): [True: 0, False: 0]
  ------------------
  443|      0|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  444|      0|	}
  445|       |
  446|       |#ifdef USE_OPENSSL3_LIBCTX
  447|       |	val = scconf_get_str(block, "openssl_config", NULL);
  448|       |	if (val != NULL) {
  449|       |		ctx->openssl_config = strdup(val);
  450|       |	}
  451|       |#endif
  452|       |
  453|  15.2k|	return err;
  454|  15.2k|}
ctx.c:set_drivers:
  371|  15.2k|{
  372|  15.2k|	const char *s_internal = "internal", *s_old = "old";
  373|  15.2k|	if (list != NULL)
  ------------------
  |  Branch (373:6): [True: 15.2k, False: 0]
  ------------------
  374|  15.2k|		del_drvs(opts);
  375|  45.7k|	while (list != NULL) {
  ------------------
  |  Branch (375:9): [True: 30.5k, False: 15.2k]
  ------------------
  376|  30.5k|		if (strcmp(list->data, s_internal) == 0)
  ------------------
  |  Branch (376:7): [True: 15.2k, False: 15.2k]
  ------------------
  377|  15.2k|			add_internal_drvs(opts);
  378|  15.2k|		else if (strcmp(list->data, s_old) == 0)
  ------------------
  |  Branch (378:12): [True: 15.2k, False: 0]
  ------------------
  379|  15.2k|			add_old_drvs(opts);
  380|      0|		else
  381|      0|			add_drv(opts, list->data);
  382|  30.5k|		list = list->next;
  383|  30.5k|	}
  384|  15.2k|}
ctx.c:add_old_drvs:
  312|  15.2k|{
  313|  15.2k|	const struct _sc_driver_entry *lst;
  314|  15.2k|	int i;
  315|       |
  316|  15.2k|	lst = old_card_drivers;
  317|  15.2k|	i = 0;
  318|  91.5k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (318:9): [True: 76.3k, False: 15.2k]
  ------------------
  319|  76.3k|		add_drv(opts, lst[i].name);
  320|  76.3k|		i++;
  321|  76.3k|	}
  322|  15.2k|}
ctx.c:load_card_drivers:
  567|  15.2k|{
  568|  15.2k|	const struct _sc_driver_entry *ent;
  569|  15.2k|	int drv_count;
  570|  15.2k|	int i;
  571|       |
  572|  15.2k|	for (drv_count = 0; ctx->card_drivers[drv_count] != NULL; drv_count++)
  ------------------
  |  Branch (572:22): [True: 0, False: 15.2k]
  ------------------
  573|      0|		;
  574|       |
  575|   717k|	for (i = 0; i < opts->ccount; i++) {
  ------------------
  |  Branch (575:14): [True: 701k, False: 15.2k]
  ------------------
  576|   701k|		struct sc_card_driver *(*func)(void) = NULL;
  577|   701k|		struct sc_card_driver *(**tfunc)(void) = &func;
  578|   701k|		void *dll = NULL;
  579|   701k|		int  j;
  580|       |
  581|   701k|		if (drv_count >= SC_MAX_CARD_DRIVERS - 1)   {
  ------------------
  |  |   31|   701k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  |  Branch (581:7): [True: 0, False: 701k]
  ------------------
  582|      0|			sc_log(ctx, "Not more then %i card drivers allowed.", SC_MAX_CARD_DRIVERS);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  582|      0|			sc_log(ctx, "Not more then %i card drivers allowed.", SC_MAX_CARD_DRIVERS);
  |  |  |  |  ------------------
  |  |  |  |  |  |   31|      0|#define SC_MAX_CARD_DRIVERS		48
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|      0|			break;
  584|      0|		}
  585|       |
  586|   701k|		ent = &opts->cdrv[i];
  587|  16.3M|		for (j = 0; internal_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (587:15): [True: 16.2M, False: 76.3k]
  ------------------
  588|  16.2M|			if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (588:8): [True: 625k, False: 15.6M]
  ------------------
  589|   625k|				func = (struct sc_card_driver *(*)(void)) internal_card_drivers[j].func;
  590|   625k|				break;
  591|   625k|			}
  592|  16.2M|		}
  593|   701k|		if (func == NULL) {
  ------------------
  |  Branch (593:7): [True: 76.3k, False: 625k]
  ------------------
  594|   228k|			for (j = 0; old_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (594:16): [True: 228k, False: 0]
  ------------------
  595|   228k|				if (strcmp(ent->name, old_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (595:9): [True: 76.3k, False: 152k]
  ------------------
  596|  76.3k|					func = (struct sc_card_driver *(*)(void)) old_card_drivers[j].func;
  597|  76.3k|					break;
  598|  76.3k|				}
  599|   228k|			}
  600|  76.3k|		}
  601|       |		/* if not initialized assume external module */
  602|   701k|		if (func == NULL)
  ------------------
  |  Branch (602:7): [True: 0, False: 701k]
  ------------------
  603|      0|			*(void **)(tfunc) = load_dynamic_driver(ctx, &dll, ent->name);
  604|       |		/* if still null, assume driver not found */
  605|   701k|		if (func == NULL) {
  ------------------
  |  Branch (605:7): [True: 0, False: 701k]
  ------------------
  606|      0|			sc_log(ctx, "Unable to load '%s'.", ent->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  607|      0|			if (dll)
  ------------------
  |  Branch (607:8): [True: 0, False: 0]
  ------------------
  608|      0|				sc_dlclose(dll);
  609|      0|			continue;
  610|      0|		}
  611|       |
  612|   701k|		ctx->card_drivers[drv_count] = func();
  613|   701k|		if (ctx->card_drivers[drv_count] == NULL) {
  ------------------
  |  Branch (613:7): [True: 0, False: 701k]
  ------------------
  614|      0|			sc_log(ctx, "Driver '%s' not available.", ent->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  615|      0|			continue;
  616|      0|		}
  617|       |
  618|   701k|		ctx->card_drivers[drv_count]->dll = dll;
  619|   701k|		ctx->card_drivers[drv_count]->atr_map = NULL;
  620|   701k|		ctx->card_drivers[drv_count]->natrs = 0;
  621|       |
  622|   701k|		load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
  623|       |
  624|       |		/* Ensure that the list is always terminated by NULL */
  625|   701k|		ctx->card_drivers[drv_count + 1] = NULL;
  626|       |
  627|   701k|		drv_count++;
  628|   701k|	}
  629|  15.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  630|  15.2k|}
ctx.c:load_card_driver_options:
  546|   701k|{
  547|   701k|	scconf_block **blocks, *blk;
  548|   701k|	int i;
  549|       |
  550|  1.40M|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (550:14): [True: 701k, False: 701k]
  ------------------
  551|   701k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  552|   701k|				"card_driver", driver->short_name);
  553|   701k|		if (!blocks)
  ------------------
  |  Branch (553:7): [True: 0, False: 701k]
  ------------------
  554|      0|			continue;
  555|   701k|		blk = blocks[0];
  556|   701k|		free(blocks);
  557|       |
  558|   701k|		if (blk == NULL)
  ------------------
  |  Branch (558:7): [True: 701k, False: 0]
  ------------------
  559|   701k|			continue;
  560|       |
  561|       |		/* no options at the moment */
  562|   701k|	}
  563|   701k|	return SC_SUCCESS;
  ------------------
  |  |   28|   701k|#define SC_SUCCESS				0
  ------------------
  564|   701k|}

dnie_get_cwa_provider:
 1287|    569|{
 1288|       |
 1289|    569|	cwa_provider_t *res = cwa_get_default_provider(card);
 1290|    569|	if (!res)
  ------------------
  |  Branch (1290:6): [True: 0, False: 569]
  ------------------
 1291|      0|		return NULL;
 1292|       |
 1293|       |	/* set up proper data */
 1294|       |
 1295|       |	/* pre and post operations */
 1296|    569|	res->cwa_create_pre_ops = dnie_create_pre_ops;
 1297|       |
 1298|       |	/* Get ICC intermediate CA  path */
 1299|    569|	res->cwa_get_icc_intermediate_ca_cert = dnie_get_icc_intermediate_ca_cert;
 1300|       |	/* Get ICC certificate path */
 1301|    569|	res->cwa_get_icc_cert = dnie_get_icc_cert;
 1302|       |
 1303|       |	/* Obtain RSA public key from RootCA */
 1304|    569|	res->cwa_get_root_ca_pubkey = dnie_get_root_ca_pubkey;
 1305|       |	/* Obtain RSA IFD private key */
 1306|    569|	res->cwa_get_ifd_privkey = dnie_get_ifd_privkey;
 1307|       |
 1308|       |	/* Retrieve CVC intermediate CA certificate and length */
 1309|    569|	res->cwa_get_cvc_ca_cert = dnie_get_cvc_ca_cert;
 1310|       |	/* Retrieve CVC IFD certificate and length */
 1311|    569|	res->cwa_get_cvc_ifd_cert = dnie_get_cvc_ifd_cert;
 1312|       |
 1313|       |	/* Get public key references for Root CA to validate intermediate CA cert */
 1314|    569|	res->cwa_get_root_ca_pubkey_ref = dnie_get_root_ca_pubkey_ref;
 1315|       |
 1316|       |	/* Get public key reference for IFD intermediate CA certificate */
 1317|    569|	res->cwa_get_intermediate_ca_pubkey_ref = dnie_get_intermediate_ca_pubkey_ref;
 1318|       |
 1319|       |	/* Get public key reference for IFD CVC certificate */
 1320|    569|	res->cwa_get_ifd_pubkey_ref = dnie_get_ifd_pubkey_ref;
 1321|       |
 1322|       |	/* Get ICC private key reference */
 1323|    569|	res->cwa_get_icc_privkey_ref = dnie_get_icc_privkey_ref;
 1324|       |
 1325|       |	/* Get IFD Serial Number */
 1326|    569|	res->cwa_get_sn_ifd = dnie_get_sn_ifd;
 1327|       |
 1328|       |	/* Get ICC Serial Number */
 1329|    569|	res->cwa_get_sn_icc = dnie_get_sn_icc;
 1330|       |
 1331|    569|	return res;
 1332|    569|}
dnie_format_apdu:
 1372|  5.38k|{
 1373|  5.38k|	sc_format_apdu(card, apdu, cse, ins, p1, p2);
 1374|  5.38k|	apdu->le = le;
 1375|  5.38k|	apdu->lc = lc;
 1376|  5.38k|	if (resp != NULL) {
  ------------------
  |  Branch (1376:6): [True: 5.38k, False: 0]
  ------------------
 1377|  5.38k|		apdu->resp = resp;
 1378|  5.38k|		apdu->resplen = resplen;
 1379|  5.38k|	}
 1380|  5.38k|	if (data != NULL) {
  ------------------
  |  Branch (1380:6): [True: 5.01k, False: 372]
  ------------------
 1381|  5.01k|		apdu->data = data;
 1382|  5.01k|		apdu->datalen = datalen;
 1383|  5.01k|	}
 1384|  5.38k|}

cwa_create_secure_channel:
 1097|  1.10k|{
 1098|  1.10k|	u8 *cert = NULL;
 1099|  1.10k|	size_t certlen;
 1100|       |
 1101|  1.10k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
 1102|  1.10k|	char *msg = "Success";
 1103|       |
 1104|       |	/* data to get and parse certificates */
 1105|  1.10k|	X509 *icc_cert = NULL;
 1106|  1.10k|	X509 *ca_cert = NULL;
 1107|  1.10k|	EVP_PKEY *icc_pubkey = NULL;
 1108|  1.10k|	EVP_PKEY *ifd_privkey = NULL;
 1109|  1.10k|	sc_context_t *ctx = NULL;
 1110|  1.10k|	struct sm_cwa_session * sm = &card->sm_ctx.info.session.cwa;
 1111|  1.10k|	u8 sig[128];
 1112|       |
 1113|       |	/* several buffer and buffer pointers */
 1114|  1.10k|	u8 *buffer = NULL;
 1115|  1.10k|	size_t bufferlen;
 1116|  1.10k|	u8 *tlv = NULL;		/* buffer to compose TLV messages */
 1117|  1.10k|	size_t tlvlen = 0;
 1118|  1.10k|	u8 rndbuf[16]; /* 8 RND.IFD + 8 SN.IFD */
 1119|       |
 1120|       |	/* preliminary checks */
 1121|  1.10k|	if (!card || !card->ctx )
  ------------------
  |  Branch (1121:6): [True: 0, False: 1.10k]
  |  Branch (1121:15): [True: 0, False: 1.10k]
  ------------------
 1122|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1123|  1.10k|	if (!provider)
  ------------------
  |  Branch (1123:6): [True: 0, False: 1.10k]
  ------------------
 1124|      0|		return SC_ERROR_SM_NOT_INITIALIZED;
  ------------------
  |  |  120|      0|#define SC_ERROR_SM_NOT_INITIALIZED		-1605
  ------------------
 1125|       |	/* commodity vars */
 1126|  1.10k|	ctx = card->ctx;
 1127|       |
 1128|  1.10k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.10k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.10k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.10k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.10k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|       |
 1130|       |	/* check requested initialization method */
 1131|  1.10k|	switch (flag) {
 1132|  1.10k|	case CWA_SM_OFF:	/* disable SM */
  ------------------
  |  |   31|  1.10k|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  |  Branch (1132:2): [True: 1.10k, False: 0]
  ------------------
 1133|  1.10k|		card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|  1.10k|#define SM_MODE_NONE		0x0
  ------------------
 1134|  1.10k|		sc_log(ctx, "Setting CWA SM status to none");
  ------------------
  |  |   71|  1.10k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1135|       |		/* request the Master File to provoke an SM error and close the channel */
 1136|  1.10k|		res = sc_select_file(card, sc_get_mf_path(), NULL);
 1137|  1.10k|		if (res == SC_ERROR_SM)
  ------------------
  |  |  115|  1.10k|#define SC_ERROR_SM				-1600
  ------------------
  |  Branch (1137:7): [True: 18, False: 1.08k]
  ------------------
 1138|     18|			res = SC_SUCCESS;
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
 1139|  1.10k|		LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|  1.10k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.10k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.10k|	int _ret = r; \
  |  |  |  |  155|  1.10k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.10k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.10k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    561|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 561, False: 544]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.10k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.10k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.10k|	return _ret; \
  |  |  |  |  163|  1.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1140|      0|	case CWA_SM_ON:	/* force sm initialization process */
  ------------------
  |  |   32|      0|#define CWA_SM_ON         0x01	/** Enable SM channel */
  ------------------
  |  Branch (1140:2): [True: 0, False: 1.10k]
  ------------------
 1141|      0|		sc_log(ctx, "CWA SM initialization requested");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1142|      0|		break;
 1143|      0|	default:
  ------------------
  |  Branch (1143:2): [True: 0, False: 1.10k]
  ------------------
 1144|      0|		sc_log(ctx, "Invalid provided SM initialization flag");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1145|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|  1.10k|	}
 1147|       |
 1148|       |	/* OK: lets start process */
 1149|       |
 1150|       |	/* call provider pre-operation method */
 1151|      0|	sc_log(ctx, "CreateSecureChannel pre-operations");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1152|      0|	if (provider->cwa_create_pre_ops) {
  ------------------
  |  Branch (1152:6): [True: 0, False: 0]
  ------------------
 1153|      0|		res = provider->cwa_create_pre_ops(card, provider);
 1154|      0|		if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1154:7): [True: 0, False: 0]
  ------------------
 1155|      0|			msg = "Create SM: provider pre_ops() failed";
 1156|      0|			sc_log(ctx, "%s", msg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1157|      0|			goto csc_end;
 1158|      0|		}
 1159|      0|	}
 1160|       |
 1161|       |	/* retrieve icc serial number */
 1162|      0|	sc_log(ctx, "Retrieve ICC serial number");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1163|      0|	if (provider->cwa_get_sn_icc) {
  ------------------
  |  Branch (1163:6): [True: 0, False: 0]
  ------------------
 1164|      0|		res = provider->cwa_get_sn_icc(card);
 1165|      0|		if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1165:7): [True: 0, False: 0]
  ------------------
 1166|      0|			msg = "Retrieve ICC failed";
 1167|      0|			sc_log(ctx, "%s", msg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1168|      0|			goto csc_end;
 1169|      0|		}
 1170|      0|	} else {
 1171|      0|		msg = "Don't know how to obtain ICC serial number";
 1172|      0|		sc_log(ctx, "%s", msg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1173|      0|		res = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1174|      0|		goto csc_end;
 1175|      0|	}
 1176|       |
 1177|       |	/*
 1178|       |	 * Notice that this code inverts ICC and IFD certificate standard
 1179|       |	 * checking sequence.
 1180|       |	 */
 1181|       |
 1182|       |	/* Read Intermediate CA from card */
 1183|      0|	if (!provider->cwa_get_icc_intermediate_ca_cert) {
  ------------------
  |  Branch (1183:6): [True: 0, False: 0]
  ------------------
 1184|      0|		sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1185|      0|		       "Step 8.4.1.6: Skip Retrieving ICC intermediate CA");
 1186|      0|		ca_cert = NULL;
 1187|      0|	} else {
 1188|      0|		sc_log(ctx, "Step 8.4.1.7: Retrieving ICC intermediate CA");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1189|      0|		res =
 1190|      0|		    provider->cwa_get_icc_intermediate_ca_cert(card, &ca_cert);
 1191|      0|		if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1191:7): [True: 0, False: 0]
  ------------------
 1192|      0|			msg =
 1193|      0|			    "Cannot get ICC intermediate CA certificate from provider";
 1194|      0|			goto csc_end;
 1195|      0|		}
 1196|      0|	}
 1197|       |
 1198|       |	/* Read ICC certificate from card */
 1199|      0|	sc_log(ctx, "Step 8.4.1.8: Retrieve ICC certificate");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1200|      0|	res = provider->cwa_get_icc_cert(card, &icc_cert);
 1201|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1201:6): [True: 0, False: 0]
  ------------------
 1202|      0|		msg = "Cannot get ICC certificate from provider";
 1203|      0|		goto csc_end;
 1204|      0|	}
 1205|       |
 1206|       |	/* Verify icc Card certificate chain */
 1207|       |	/* Notice that Some implementations doesn't verify cert chain
 1208|       |	 * but simply verifies that icc_cert is a valid certificate */
 1209|      0|	if (ca_cert) {
  ------------------
  |  Branch (1209:6): [True: 0, False: 0]
  ------------------
 1210|      0|		sc_log(ctx, "Verifying ICC certificate chain");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1211|      0|		res =
 1212|      0|		    cwa_verify_icc_certificates(card, provider, ca_cert,
 1213|      0|						icc_cert);
 1214|      0|		if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1214:7): [True: 0, False: 0]
  ------------------
 1215|      0|			res = SC_ERROR_SM_AUTHENTICATION_FAILED;
  ------------------
  |  |  121|      0|#define SC_ERROR_SM_AUTHENTICATION_FAILED	-1606
  ------------------
 1216|      0|			msg = "Icc Certificates verification failed";
 1217|      0|			goto csc_end;
 1218|      0|		}
 1219|      0|	} else {
 1220|      0|		sc_log(ctx, "Cannot verify Certificate chain. skip step");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1221|      0|	}
 1222|       |
 1223|       |	/* Extract public key from ICC certificate */
 1224|      0|	if (!(icc_pubkey = X509_get_pubkey(icc_cert))) {
  ------------------
  |  Branch (1224:6): [True: 0, False: 0]
  ------------------
 1225|      0|		res = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1226|      0|		sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1227|      0|		msg = "Cannot extract public key from ICC certificate";
 1228|      0|		goto csc_end;
 1229|      0|	}
 1230|       |
 1231|       |	/* Select Root CA in card for ifd certificate verification */
 1232|      0|	sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1233|      0|	       "Step 8.4.1.2: Select Root CA in card for IFD cert verification");
 1234|      0|	res = provider->cwa_get_root_ca_pubkey_ref(card, &buffer, &bufferlen);
 1235|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1235:6): [True: 0, False: 0]
  ------------------
 1236|      0|		msg = "Cannot get Root CA key reference from provider";
 1237|      0|		goto csc_end;
 1238|      0|	}
 1239|      0|	tlvlen = 0;
 1240|      0|	tlv = calloc(10 + bufferlen, sizeof(u8));
 1241|      0|	if (!tlv) {
  ------------------
  |  Branch (1241:6): [True: 0, False: 0]
  ------------------
 1242|      0|		msg = "calloc error";
 1243|      0|		res = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1244|      0|		goto csc_end;
 1245|      0|	}
 1246|      0|	res = cwa_compose_tlv(card, 0x83, bufferlen, buffer, &tlv, &tlvlen);
 1247|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1247:6): [True: 0, False: 0]
  ------------------
 1248|      0|		msg = "Cannot compose tlv for setting Root CA key reference";
 1249|      0|		goto csc_end;
 1250|      0|	}
 1251|      0|	res = cwa_set_security_env(card, 0x81, 0xB6, tlv, tlvlen);
 1252|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1252:6): [True: 0, False: 0]
  ------------------
 1253|      0|		msg = "Select Root CA key ref failed";
 1254|      0|		goto csc_end;
 1255|      0|	}
 1256|       |
 1257|       |	/* Send IFD intermediate CA in CVC format C_CV_CA */
 1258|      0|	sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1259|      0|	       "Step 8.4.1.3: Send CVC IFD intermediate CA Cert for ICC verification");
 1260|      0|	res = provider->cwa_get_cvc_ca_cert(card, &cert, &certlen);
 1261|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1261:6): [True: 0, False: 0]
  ------------------
 1262|      0|		msg = "Get CVC CA cert from provider failed";
 1263|      0|		goto csc_end;
 1264|      0|	}
 1265|      0|	res = cwa_verify_cvc_certificate(card, cert, certlen);
 1266|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1266:6): [True: 0, False: 0]
  ------------------
 1267|      0|		msg = "Verify CVC CA failed";
 1268|      0|		goto csc_end;
 1269|      0|	}
 1270|       |
 1271|       |	/* select public key reference for sent IFD intermediate CA certificate */
 1272|      0|	sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1273|      0|	       "Step 8.4.1.4: Select Intermediate CA pubkey ref for ICC verification");
 1274|      0|	res =
 1275|      0|	    provider->cwa_get_intermediate_ca_pubkey_ref(card, &buffer,
 1276|      0|							 &bufferlen);
 1277|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1277:6): [True: 0, False: 0]
  ------------------
 1278|      0|		msg = "Cannot get intermediate CA key reference from provider";
 1279|      0|		goto csc_end;
 1280|      0|	}
 1281|      0|	tlvlen = 0;
 1282|      0|	free(tlv);
 1283|      0|	tlv = calloc(10 + bufferlen, sizeof(u8));
 1284|      0|	if (!tlv) {
  ------------------
  |  Branch (1284:6): [True: 0, False: 0]
  ------------------
 1285|      0|		msg = "calloc error";
 1286|      0|		res = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1287|      0|		goto csc_end;
 1288|      0|	}
 1289|      0|	res = cwa_compose_tlv(card, 0x83, bufferlen, buffer, &tlv, &tlvlen);
 1290|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1290:6): [True: 0, False: 0]
  ------------------
 1291|      0|		msg =
 1292|      0|		    "Cannot compose tlv for setting intermediate CA key reference";
 1293|      0|		goto csc_end;
 1294|      0|	}
 1295|      0|	res = cwa_set_security_env(card, 0x81, 0xB6, tlv, tlvlen);
 1296|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1296:6): [True: 0, False: 0]
  ------------------
 1297|      0|		msg = "Select CVC CA pubk failed";
 1298|      0|		goto csc_end;
 1299|      0|	}
 1300|       |
 1301|       |	/* Send IFD certificate in CVC format C_CV_IFD */
 1302|      0|	sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1303|      0|	       "Step 8.4.1.5: Send CVC IFD Certificate for ICC verification");
 1304|      0|	res = provider->cwa_get_cvc_ifd_cert(card, &cert, &certlen);
 1305|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1305:6): [True: 0, False: 0]
  ------------------
 1306|      0|		msg = "Get CVC IFD cert from provider failed";
 1307|      0|		goto csc_end;
 1308|      0|	}
 1309|      0|	res = cwa_verify_cvc_certificate(card, cert, certlen);
 1310|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1310:6): [True: 0, False: 0]
  ------------------
 1311|      0|		msg = "Verify CVC IFD failed";
 1312|      0|		goto csc_end;
 1313|      0|	}
 1314|       |
 1315|       |	/* remember that this code changes IFD and ICC Cert verification steps */
 1316|       |
 1317|       |	/* select public key of ifd certificate and icc private key */
 1318|      0|	sc_log(ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1319|      0|	       "Step 8.4.1.9: Send IFD pubk and ICC privk key references for Internal Auth");
 1320|      0|	res = provider->cwa_get_ifd_pubkey_ref(card, &buffer, &bufferlen);
 1321|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1321:6): [True: 0, False: 0]
  ------------------
 1322|      0|		msg = "Cannot get ifd public key reference from provider";
 1323|      0|		goto csc_end;
 1324|      0|	}
 1325|      0|	tlvlen = 0;
 1326|      0|	free(tlv);
 1327|      0|	tlv = calloc(10 + bufferlen, sizeof(u8));
 1328|      0|	if (!tlv) {
  ------------------
  |  Branch (1328:6): [True: 0, False: 0]
  ------------------
 1329|      0|		msg = "calloc error";
 1330|      0|		res = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1331|      0|		goto csc_end;
 1332|      0|	}
 1333|      0|	res = cwa_compose_tlv(card, 0x83, bufferlen, buffer, &tlv, &tlvlen);
 1334|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1334:6): [True: 0, False: 0]
  ------------------
 1335|      0|		msg = "Cannot compose tlv for setting ifd pubkey reference";
 1336|      0|		goto csc_end;
 1337|      0|	}
 1338|      0|	res = provider->cwa_get_icc_privkey_ref(card, &buffer, &bufferlen);
 1339|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1339:6): [True: 0, False: 0]
  ------------------
 1340|      0|		msg = "Cannot get icc private key reference from provider";
 1341|      0|		goto csc_end;
 1342|      0|	}
 1343|       |	/* add this tlv to old one; do not call calloc */
 1344|      0|	res = cwa_compose_tlv(card, 0x84, bufferlen, buffer, &tlv, &tlvlen);
 1345|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1345:6): [True: 0, False: 0]
  ------------------
 1346|      0|		msg = "Cannot compose tlv for setting ifd pubkey reference";
 1347|      0|		goto csc_end;
 1348|      0|	}
 1349|       |
 1350|      0|	res = cwa_set_security_env(card, 0xC1, 0xA4, tlv, tlvlen);
 1351|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1351:6): [True: 0, False: 0]
  ------------------
 1352|      0|		msg = "Select CVC IFD pubk failed";
 1353|      0|		goto csc_end;
 1354|      0|	}
 1355|       |
 1356|       |	/* Internal (Card) authentication (let the card verify sent ifd certs)
 1357|       |	   SN.IFD equals 8 lsb bytes of ifd.pubk ref according cwa14890 sec 8.4.1 */
 1358|      0|	sc_log(ctx, "Step 8.4.1.10: Perform Internal authentication");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1359|      0|	res = provider->cwa_get_sn_ifd(card);
 1360|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1360:6): [True: 0, False: 0]
  ------------------
 1361|      0|		msg = "Cannot get ifd serial number from provider";
 1362|      0|		goto csc_end;
 1363|      0|	}
 1364|       |	/* generate 8 random bytes */
 1365|      0|	if (RAND_bytes(sm->ifd.rnd, 8) != 1) {
  ------------------
  |  Branch (1365:6): [True: 0, False: 0]
  ------------------
 1366|      0|		msg = "Cannot generate random data";
 1367|      0|		res = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1368|      0|		goto csc_end;
 1369|      0|	}
 1370|      0|	memcpy(rndbuf, sm->ifd.rnd, 8);	/* insert RND.IFD into rndbuf */
 1371|      0|	memcpy(rndbuf + 8, sm->ifd.sn, 8);	/* insert SN.IFD into rndbuf */
 1372|      0|	res = cwa_internal_auth(card, sig, 128, rndbuf, 16);
 1373|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1373:6): [True: 0, False: 0]
  ------------------
 1374|      0|		msg = "Internal auth cmd failed";
 1375|      0|		goto csc_end;
 1376|      0|	}
 1377|       |
 1378|       |	/* retrieve ifd private key from provider */
 1379|      0|	res = provider->cwa_get_ifd_privkey(card, &ifd_privkey);
 1380|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1380:6): [True: 0, False: 0]
  ------------------
 1381|      0|		msg = "Cannot retrieve IFD private key from provider";
 1382|      0|		res = SC_ERROR_SM_NO_SESSION_KEYS;
  ------------------
  |  |  118|      0|#define SC_ERROR_SM_NO_SESSION_KEYS		-1603
  ------------------
 1383|      0|		goto csc_end;
 1384|      0|	}
 1385|       |
 1386|       |	/* verify received signature */
 1387|      0|	sc_log(ctx, "Verify Internal Auth command response");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1388|      0|	res = cwa_verify_internal_auth(card, icc_pubkey,	/* evaluated icc public key */
 1389|      0|				       ifd_privkey,	/* evaluated from DGP's Manual Annex 3 Data */
 1390|      0|				       rndbuf,	/* RND.IFD || SN.IFD */
 1391|      0|				       16,	/* rndbuf length; should be 16 */
 1392|      0|				       sig, 128
 1393|      0|	    );
 1394|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1394:6): [True: 0, False: 0]
  ------------------
 1395|      0|		msg = "Internal Auth Verify failed";
 1396|      0|		goto csc_end;
 1397|      0|	}
 1398|       |
 1399|       |	/* get challenge: retrieve 8 random bytes from card */
 1400|      0|	sc_log(ctx, "Step 8.4.1.11: Prepare External Auth: Get Challenge");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1401|      0|	res = sc_get_challenge(card, sm->icc.rnd, sizeof(sm->icc.rnd));
 1402|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1402:6): [True: 0, False: 0]
  ------------------
 1403|      0|		msg = "Get Challenge failed";
 1404|      0|		goto csc_end;
 1405|      0|	}
 1406|       |
 1407|       |	/* compose signature data for external auth */
 1408|      0|	res = cwa_prepare_external_auth(card, icc_pubkey, ifd_privkey, sig, 128);
 1409|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1409:6): [True: 0, False: 0]
  ------------------
 1410|      0|		msg = "Prepare external auth failed";
 1411|      0|		goto csc_end;
 1412|      0|	}
 1413|       |
 1414|       |	/* External (IFD)  authentication */
 1415|      0|	sc_log(ctx, "Step 8.4.1.12: Perform External (IFD) Authentication");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1416|      0|	res = cwa_external_auth(card, sig, 128);
 1417|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1417:6): [True: 0, False: 0]
  ------------------
 1418|      0|		msg = "External auth cmd failed";
 1419|      0|		goto csc_end;
 1420|      0|	}
 1421|       |
 1422|       |	/* Session key generation */
 1423|      0|	sc_log(ctx, "Step 8.4.2: Compute Session Keys");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1424|      0|	res = cwa_compute_session_keys(card);
 1425|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1425:6): [True: 0, False: 0]
  ------------------
 1426|      0|		msg = "Session Key generation failed";
 1427|      0|		goto csc_end;
 1428|      0|	}
 1429|       |
 1430|       |	/* call provider post-operation method */
 1431|      0|	sc_log(ctx, "CreateSecureChannel post-operations");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1432|      0|	if (provider->cwa_create_post_ops) {
  ------------------
  |  Branch (1432:6): [True: 0, False: 0]
  ------------------
 1433|      0|		res = provider->cwa_create_post_ops(card, provider);
 1434|      0|		if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1434:7): [True: 0, False: 0]
  ------------------
 1435|      0|			sc_log(ctx, "Create SM: provider post_ops() failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1436|      0|			goto csc_end;
 1437|      0|		}
 1438|      0|	}
 1439|       |
 1440|       |	/* arriving here means ok: cleanup */
 1441|      0|	res = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1442|      0| csc_end:
 1443|      0|	free(tlv);
 1444|      0|	X509_free(icc_cert);
 1445|      0|	X509_free(ca_cert);
 1446|      0|	EVP_PKEY_free(icc_pubkey);
 1447|      0|	EVP_PKEY_free(ifd_privkey);
 1448|       |	/* setup SM state according result */
 1449|      0|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1449:6): [True: 0, False: 0]
  ------------------
 1450|      0|		sc_log(ctx, "%s", msg);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1451|      0|		card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|      0|#define SM_MODE_NONE		0x0
  ------------------
 1452|      0|	} else {
 1453|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1454|      0|	}
 1455|      0|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1456|      0|}
cwa_get_default_provider:
 2168|    569|{
 2169|    569|	cwa_provider_t *res = NULL;
 2170|    569|	if (!card || !card->ctx)
  ------------------
  |  Branch (2170:6): [True: 0, False: 569]
  |  Branch (2170:15): [True: 0, False: 569]
  ------------------
 2171|      0|		return NULL;
 2172|    569|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    569|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    569|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    569|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    569|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 569]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2173|    569|	res = calloc(1, sizeof(cwa_provider_t));
 2174|    569|	if (!res) {
  ------------------
  |  Branch (2174:6): [True: 0, False: 569]
  ------------------
 2175|      0|		sc_log(card->ctx, "Cannot allocate space for cwa_provider");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2176|      0|		return NULL;
 2177|      0|	}
 2178|    569|	memcpy(res, &default_cwa_provider, sizeof(cwa_provider_t));
 2179|    569|	return res;
 2180|    569|}

sc_enum_apps:
  162|  11.9k|{
  163|  11.9k|	struct sc_context *ctx = card->ctx;
  164|  11.9k|	sc_path_t path;
  165|  11.9k|	int ef_structure;
  166|  11.9k|	size_t file_size, jj;
  167|  11.9k|	int r, ii, idx;
  168|  11.9k|	struct sc_file *ef_dir = NULL;
  169|       |
  170|  11.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  171|       |
  172|  11.9k|	sc_free_apps(card);
  173|  11.9k|	card->app_count = 0;
  174|       |
  175|  11.9k|	sc_format_path("3F002F00", &path);
  176|  11.9k|	r = sc_select_file(card, &path, &ef_dir);
  177|  11.9k|	if (r < 0)
  ------------------
  |  Branch (177:6): [True: 9.28k, False: 2.62k]
  ------------------
  178|  9.28k|		sc_file_free(ef_dir);
  179|  11.9k|	LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
  ------------------
  |  |  174|  11.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  11.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  11.9k|	int _ret = (r); \
  |  |  |  |  168|  11.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9.28k, False: 2.62k]
  |  |  |  |  ------------------
  |  |  |  |  169|  9.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.28k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  9.28k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  9.28k|		return _ret; \
  |  |  |  |  172|  9.28k|	} \
  |  |  |  |  173|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.62k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  180|       |
  181|  2.62k|	if (ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
  ------------------
  |  |  216|  2.62k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (181:6): [True: 1.21k, False: 1.40k]
  ------------------
  182|  1.21k|		sc_file_free(ef_dir);
  183|  1.21k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "EF(DIR) is not a working EF.");
  ------------------
  |  |  174|  1.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.21k|	int _ret = (r); \
  |  |  |  |  168|  1.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.21k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.21k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.21k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.21k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.21k|		return _ret; \
  |  |  |  |  172|  1.21k|	} \
  |  |  |  |  173|  1.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|  1.21k|	}
  185|       |
  186|  1.40k|	ef_structure = ef_dir->ef_structure;
  187|  1.40k|	file_size = ef_dir->size;
  188|  1.40k|	sc_file_free(ef_dir);
  189|  1.40k|	if (ef_structure == SC_FILE_EF_TRANSPARENT) {
  ------------------
  |  |  221|  1.40k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (189:6): [True: 862, False: 542]
  ------------------
  190|    862|		u8 *buf = NULL, *p;
  191|    862|		size_t bufsize;
  192|       |
  193|    862|		if (file_size == 0)
  ------------------
  |  Branch (193:7): [True: 30, False: 832]
  ------------------
  194|    862|			LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|    832|		if (file_size > MAX_FILE_SIZE)
  ------------------
  |  |  220|    832|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (195:7): [True: 21, False: 811]
  ------------------
  196|    832|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  197|       |
  198|    811|		buf = malloc(file_size);
  199|    811|		if (buf == NULL)
  ------------------
  |  Branch (199:7): [True: 0, False: 811]
  ------------------
  200|    811|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|    811|		p = buf;
  202|    811|		r = sc_read_binary(card, 0, buf, file_size, 0);
  203|    811|		if (r < 0) {
  ------------------
  |  Branch (203:7): [True: 301, False: 510]
  ------------------
  204|    301|			free(buf);
  205|    301|			LOG_TEST_RET(ctx, r, "sc_read_binary() failed");
  ------------------
  |  |  174|    301|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    301|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    301|	int _ret = (r); \
  |  |  |  |  168|    301|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 301, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    301|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    301|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    301|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    301|		return _ret; \
  |  |  |  |  172|    301|	} \
  |  |  |  |  173|    301|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|    301|		}
  207|    510|		bufsize = r;
  208|    852|		while (bufsize > 0) {
  ------------------
  |  Branch (208:10): [True: 640, False: 212]
  ------------------
  209|    640|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    640|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (209:8): [True: 1, False: 639]
  ------------------
  210|      1|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  211|      1|				break;
  212|      1|			}
  213|    639|			r = parse_dir_record(card, &p, &bufsize, -1);
  214|    639|			if (r)
  ------------------
  |  Branch (214:8): [True: 297, False: 342]
  ------------------
  215|    297|				break;
  216|    639|		}
  217|    510|		if (buf)
  ------------------
  |  Branch (217:7): [True: 510, False: 0]
  ------------------
  218|    510|			free(buf);
  219|       |
  220|    510|	}
  221|    542|	else {	/* record structure */
  222|    542|		unsigned char buf[256], *p;
  223|    542|		unsigned int rec_nr;
  224|    542|		size_t rec_size;
  225|       |
  226|       |		/* Arbitrary set '16' as maximal number of records to check out:
  227|       |		 * to avoid endless loop because of some incomplete cards/drivers */
  228|  1.71k|		for (rec_nr = 1; rec_nr < 16; rec_nr++) {
  ------------------
  |  Branch (228:20): [True: 1.70k, False: 12]
  ------------------
  229|  1.70k|			r = sc_read_record(card, rec_nr, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  1.70k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  230|  1.70k|			if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.70k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (230:8): [True: 1, False: 1.70k]
  ------------------
  231|      1|				break;
  232|  1.70k|			LOG_TEST_RET(ctx, r, "read_record() failed");
  ------------------
  |  |  174|  1.70k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.70k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.70k|	int _ret = (r); \
  |  |  |  |  168|  1.70k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 528, False: 1.17k]
  |  |  |  |  ------------------
  |  |  |  |  169|    528|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    528|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    528|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    528|		return _ret; \
  |  |  |  |  172|    528|	} \
  |  |  |  |  173|  1.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|       |
  234|  1.17k|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|  1.17k|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (234:8): [True: 1, False: 1.17k]
  ------------------
  235|      1|				sc_log(ctx, "Too many applications on card");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  236|      1|				break;
  237|      1|			}
  238|       |
  239|  1.17k|			rec_size = r;
  240|  1.17k|			p = buf;
  241|  1.17k|			parse_dir_record(card, &p, &rec_size, (int)rec_nr);
  242|  1.17k|		}
  243|    542|	}
  244|       |
  245|       |	/* Move known PKCS#15 applications to the head of the list */
  246|    877|	for (ii=0, idx=0; ii<card->app_count; ii++)   {
  ------------------
  |  Branch (246:20): [True: 353, False: 524]
  ------------------
  247|  3.14k|		for (jj=0; jj < sizeof(apps)/sizeof(apps[0]); jj++) {
  ------------------
  |  Branch (247:14): [True: 2.80k, False: 340]
  ------------------
  248|  2.80k|			if (apps[jj].aid_len != card->app[ii]->aid.len)
  ------------------
  |  Branch (248:8): [True: 2.68k, False: 121]
  ------------------
  249|  2.68k|				continue;
  250|    121|			if (memcmp(apps[jj].aid, card->app[ii]->aid.value, apps[jj].aid_len))
  ------------------
  |  Branch (250:8): [True: 108, False: 13]
  ------------------
  251|    108|				continue;
  252|     13|			break;
  253|    121|		}
  254|       |
  255|    353|		if (ii != idx && jj < sizeof(apps)/sizeof(apps[0]))   {
  ------------------
  |  Branch (255:7): [True: 106, False: 247]
  |  Branch (255:20): [True: 10, False: 96]
  ------------------
  256|     10|			struct sc_app_info *tmp = card->app[idx];
  257|       |
  258|     10|			card->app[idx] = card->app[ii];
  259|     10|			card->app[ii] = tmp;
  260|     10|			idx++;
  261|     10|		}
  262|    353|	}
  263|       |
  264|    524|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    524|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    524|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    524|	int _ret = r; \
  |  |  |  |  155|    524|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    524|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    524|	return _ret; \
  |  |  |  |  163|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  265|    524|}
sc_free_apps:
  268|  27.1k|{
  269|  27.1k|	int	i;
  270|       |
  271|  27.7k|	for (i = 0; i < card->app_count; i++) {
  ------------------
  |  Branch (271:14): [True: 597, False: 27.1k]
  ------------------
  272|    597|		free(card->app[i]->label);
  273|    597|		free(card->app[i]->ddo.value);
  274|    597|		free(card->app[i]);
  275|    597|	}
  276|  27.1k|	card->app_count = -1;
  277|  27.1k|}
dir.c:parse_dir_record:
   64|  1.81k|{
   65|  1.81k|	struct sc_context *ctx = card->ctx;
   66|  1.81k|	struct sc_asn1_entry asn1_dirrecord[5], asn1_dir[2];
   67|  1.81k|	scconf_block *conf_block = NULL;
   68|  1.81k|	sc_app_info_t *app = NULL;
   69|  1.81k|	struct sc_aid aid;
   70|  1.81k|	u8 label[128], path[128], ddo[128];
   71|  1.81k|	size_t label_len = sizeof(label) - 1, path_len = sizeof(path), ddo_len = sizeof(ddo);
   72|  1.81k|	int r;
   73|       |
   74|  1.81k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.81k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.81k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.81k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.81k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|  1.81k|	aid.len = sizeof(aid.value);
   76|       |
   77|  1.81k|	memset(label, 0, sizeof(label));
   78|  1.81k|	sc_copy_asn1_entry(c_asn1_dirrecord, asn1_dirrecord);
   79|  1.81k|	sc_copy_asn1_entry(c_asn1_dir, asn1_dir);
   80|  1.81k|	sc_format_asn1_entry(asn1_dir + 0, asn1_dirrecord, NULL, 0);
   81|  1.81k|	sc_format_asn1_entry(asn1_dirrecord + 0, aid.value, &aid.len, 0);
   82|  1.81k|	sc_format_asn1_entry(asn1_dirrecord + 1, label, &label_len, 0);
   83|  1.81k|	sc_format_asn1_entry(asn1_dirrecord + 2, path, &path_len, 0);
   84|  1.81k|	sc_format_asn1_entry(asn1_dirrecord + 3, ddo, &ddo_len, 0);
   85|       |
   86|  1.81k|	r = sc_asn1_decode(ctx, asn1_dir, *buf, *buflen, (const u8 **) buf, buflen);
   87|  1.81k|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  1.81k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (87:6): [True: 125, False: 1.68k]
  ------------------
   88|  1.81k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    125|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    125|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    125|	int _ret = r; \
  |  |  |  |  155|    125|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 125, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    125|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 125, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    125|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    125|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    125|	return _ret; \
  |  |  |  |  163|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  1.68k|	LOG_TEST_RET(ctx, r, "EF(DIR) parsing failed");
  ------------------
  |  |  174|  1.68k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.68k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.68k|	int _ret = (r); \
  |  |  |  |  168|  1.68k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.08k, False: 598]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.08k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.08k|		return _ret; \
  |  |  |  |  172|  1.08k|	} \
  |  |  |  |  173|  1.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 598]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|       |
   91|    598|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
   92|    598|	if (conf_block)   {
  ------------------
  |  Branch (92:6): [True: 0, False: 598]
  ------------------
   93|      0|		scconf_block **blocks = NULL;
   94|      0|		char aid_str[SC_MAX_AID_STRING_SIZE];
   95|      0|		int ignore_app = 0;
   96|       |
   97|      0|		sc_bin_to_hex(aid.value, aid.len, aid_str, sizeof(aid_str), 0);
   98|      0|		blocks = scconf_find_blocks(card->ctx->conf, conf_block, "application", aid_str);
   99|      0|		if (blocks)   {
  ------------------
  |  Branch (99:7): [True: 0, False: 0]
  ------------------
  100|      0|			ignore_app = (blocks[0] && scconf_get_bool(blocks[0], "disable", 0));
  ------------------
  |  Branch (100:18): [True: 0, False: 0]
  |  Branch (100:31): [True: 0, False: 0]
  ------------------
  101|      0|			free(blocks);
  102|      0|		 }
  103|       |
  104|      0|		if (ignore_app)   {
  ------------------
  |  Branch (104:7): [True: 0, False: 0]
  ------------------
  105|      0|			sc_log(ctx, "Application '%s' ignored", aid_str);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  106|      0|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|      0|		}
  108|      0|	}
  109|       |
  110|    598|	app = calloc(1, sizeof(struct sc_app_info));
  111|    598|	if (app == NULL)
  ------------------
  |  Branch (111:6): [True: 0, False: 598]
  ------------------
  112|    598|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  113|       |
  114|    598|	memcpy(&app->aid, &aid, sizeof(struct sc_aid));
  115|       |
  116|    598|	if (asn1_dirrecord[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    598|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (116:6): [True: 16, False: 582]
  ------------------
  117|     16|		app->label = strdup((char *) label);
  118|    582|	else
  119|    582|		app->label = NULL;
  120|       |
  121|    598|	if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT && path_len > 0) {
  ------------------
  |  |  147|  1.19k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (121:6): [True: 220, False: 378]
  |  Branch (121:51): [True: 200, False: 20]
  ------------------
  122|       |		/* application path present: ignore AID */
  123|    200|		if (path_len > SC_MAX_PATH_SIZE) {
  ------------------
  |  |   47|    200|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (123:7): [True: 1, False: 199]
  ------------------
  124|      1|			free(app->label);
  125|      1|			free(app);
  126|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Application path is too long.");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  127|      1|		}
  128|    199|		memcpy(app->path.value, path, path_len);
  129|    199|		app->path.len = path_len;
  130|    199|		app->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    199|#define SC_PATH_TYPE_PATH		2
  ------------------
  131|    199|	}
  132|    398|	else {
  133|       |		/* application path not present: use AID as application path */
  134|    398|		memcpy(app->path.value, aid.value, aid.len);
  135|    398|		app->path.len = aid.len;
  136|    398|		app->path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    398|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  137|    398|	}
  138|       |
  139|    597|	if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    597|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (139:6): [True: 78, False: 519]
  ------------------
  140|     78|		app->ddo.value = malloc(ddo_len);
  141|     78|		if (app->ddo.value == NULL) {
  ------------------
  |  Branch (141:7): [True: 0, False: 78]
  ------------------
  142|      0|			free(app->label);
  143|      0|			free(app);
  144|      0|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate DDO value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  145|      0|		}
  146|     78|		memcpy(app->ddo.value, ddo, ddo_len);
  147|     78|		app->ddo.len = ddo_len;
  148|    519|	} else {
  149|    519|		app->ddo.value = NULL;
  150|    519|		app->ddo.len = 0;
  151|    519|	}
  152|       |
  153|    597|	app->rec_nr = rec_nr;
  154|    597|	card->app[card->app_count] = app;
  155|    597|	card->app_count++;
  156|       |
  157|    597|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    597|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    597|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    597|	int _ret = r; \
  |  |  |  |  155|    597|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 597, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    597|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 597]
  |  |  |  |  ------------------
  |  |  |  |  157|    597|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    597|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    597|	return _ret; \
  |  |  |  |  163|    597|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|    597|}

sc_parse_ef_atr:
  134|  1.29k|{
  135|  1.29k|	struct sc_context *ctx = card->ctx;
  136|  1.29k|	struct sc_path path;
  137|  1.29k|	struct sc_file *file = NULL;
  138|  1.29k|	int rv;
  139|  1.29k|	unsigned char *buf = NULL;
  140|  1.29k|	size_t size;
  141|  1.29k|	size_t off = 0;
  142|       |
  143|  1.29k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.29k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.29k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|       |
  145|  1.29k|	sc_format_path("3F002F01", &path);
  146|  1.29k|	rv = sc_select_file(card, &path, &file);
  147|  1.29k|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot select EF(ATR) file");
  ------------------
  |  |  184|  1.29k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.29k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.29k|	int _ret = (r); \
  |  |  |  |  178|  1.29k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 763, False: 535]
  |  |  |  |  ------------------
  |  |  |  |  179|    763|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    763|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    763|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    763|		goto err; \
  |  |  |  |  182|    763|	} \
  |  |  |  |  183|  1.29k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 535]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|       |
  149|    535|	if (file->size) {
  ------------------
  |  Branch (149:6): [True: 110, False: 425]
  ------------------
  150|    110|		size = file->size;
  151|    425|	} else {
  152|    425|		size = 1024;
  153|    425|	}
  154|    535|	buf = malloc(size);
  155|    535|	if (!buf) {
  ------------------
  |  Branch (155:6): [True: 0, False: 535]
  ------------------
  156|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  157|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Memory allocation error");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|      0|	}
  159|    535|	rv = sc_read_binary(card, 0, buf, size, 0);
  160|    535|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot read EF(ATR) file");
  ------------------
  |  |  184|    535|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    535|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    535|	int _ret = (r); \
  |  |  |  |  178|    535|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 216, False: 319]
  |  |  |  |  ------------------
  |  |  |  |  179|    216|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    216|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    216|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    216|		goto err; \
  |  |  |  |  182|    216|	} \
  |  |  |  |  183|    535|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 319]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|       |
  162|       |	/* Workaround: Some cards seem to have a buggy storage of the EF.ATR */
  163|    319|	if ((card->type == SC_CARD_TYPE_IASECC_CPX) ||
  ------------------
  |  Branch (163:6): [True: 119, False: 200]
  ------------------
  164|    200|	    (card->type == SC_CARD_TYPE_IASECC_CPXCL)) {
  ------------------
  |  Branch (164:6): [True: 0, False: 200]
  ------------------
  165|       |		/* Let's keep the first byte */
  166|    119|		if ((rv > 1) &&
  ------------------
  |  Branch (166:7): [True: 111, False: 8]
  ------------------
  167|    111|		    (buf[0] == ISO7816_II_CATEGORY_TLV))
  ------------------
  |  |   28|    111|#define ISO7816_II_CATEGORY_TLV		0x80
  ------------------
  |  Branch (167:7): [True: 3, False: 108]
  ------------------
  168|      3|			off++;
  169|    119|	}
  170|    319|	rv = sc_parse_ef_atr_content(card, buf + off, rv - off);
  171|    319|	LOG_TEST_GOTO_ERR(ctx, rv, "EF(ATR) parse error");
  ------------------
  |  |  184|    319|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    319|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    319|	int _ret = (r); \
  |  |  |  |  178|    319|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 27, False: 292]
  |  |  |  |  ------------------
  |  |  |  |  179|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     27|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     27|		goto err; \
  |  |  |  |  182|     27|	} \
  |  |  |  |  183|    319|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 292]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  172|       |
  173|    292|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    292|#define SC_SUCCESS				0
  ------------------
  174|       |
  175|  1.29k|err:
  176|  1.29k|	sc_file_free(file);
  177|  1.29k|	free(buf);
  178|  1.29k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.29k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.29k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.29k|	int _ret = r; \
  |  |  |  |  155|  1.29k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.29k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.29k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.00k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.00k, False: 292]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.29k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.29k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.29k|	return _ret; \
  |  |  |  |  163|  1.29k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  179|  1.29k|}
sc_free_ef_atr:
  182|  15.2k|{
  183|  15.2k|	if (card->ef_atr)
  ------------------
  |  Branch (183:6): [True: 942, False: 14.3k]
  ------------------
  184|    942|		free(card->ef_atr);
  185|       |	card->ef_atr = NULL;
  186|  15.2k|}
ef-atr.c:sc_parse_ef_atr_content:
   35|    319|{
   36|    319|	struct sc_context *ctx = card->ctx;
   37|    319|	const unsigned char *tag = NULL;
   38|    319|	size_t taglen;
   39|    319|	struct sc_ef_atr ef_atr;
   40|       |
   41|    319|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    319|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    319|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    319|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    319|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 319]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   42|       |
   43|    319|	memset(&ef_atr, 0, sizeof(struct sc_ef_atr));
   44|       |
   45|    319|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_CARD_SERVICE, &taglen);
  ------------------
  |  |   31|    319|#define ISO7816_TAG_II_CARD_SERVICE		0x43
  ------------------
   46|    319|	if (tag && taglen >= 1)   {
  ------------------
  |  Branch (46:6): [True: 5, False: 314]
  |  Branch (46:13): [True: 4, False: 1]
  ------------------
   47|      4|		ef_atr.card_service = *tag;
   48|      4|		sc_log(ctx, "EF.ATR: card service 0x%X", ef_atr.card_service);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   49|      4|	}
   50|       |
   51|    319|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_PRE_ISSUING, &taglen);
  ------------------
  |  |   34|    319|#define ISO7816_TAG_II_PRE_ISSUING		0x46
  ------------------
   52|    319|	if (tag) {
  ------------------
  |  Branch (52:6): [True: 66, False: 253]
  ------------------
   53|     66|		size_t len = taglen > sizeof(ef_atr.pre_issuing) ? sizeof(ef_atr.pre_issuing) : taglen;
  ------------------
  |  Branch (53:16): [True: 45, False: 21]
  ------------------
   54|       |
   55|     66|		memcpy(ef_atr.pre_issuing, tag, len);
   56|     66|		ef_atr.pre_issuing_len = len;
   57|       |
   58|     66|		sc_log(ctx, "EF.ATR: Pre-Issuing data '%s'", sc_dump_hex(ef_atr.pre_issuing, ef_atr.pre_issuing_len));
  ------------------
  |  |   71|     66|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   59|     66|	}
   60|       |
   61|    319|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_CARD_CAPABILITIES, &taglen);
  ------------------
  |  |   35|    319|#define ISO7816_TAG_II_CARD_CAPABILITIES	0x47
  ------------------
   62|    319|	if (tag && taglen >= 3) {
  ------------------
  |  Branch (62:6): [True: 13, False: 306]
  |  Branch (62:13): [True: 12, False: 1]
  ------------------
   63|     12|		ef_atr.df_selection =  *(tag + 0);
   64|     12|		ef_atr.unit_size = *(tag + 1);
   65|     12|		ef_atr.card_capabilities = *(tag + 2);
   66|     12|		sc_log(ctx, "EF.ATR: DF selection %X, unit_size %zX, card caps %X",
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   67|     12|				ef_atr.df_selection, ef_atr.unit_size, ef_atr.card_capabilities);
   68|     12|	}
   69|       |
   70|    319|	if (ef_atr.card_capabilities & ISO7816_CAP_EXTENDED_LENGTH_INFO) {
  ------------------
  |  |   45|    319|#define ISO7816_CAP_EXTENDED_LENGTH_INFO	0x20
  ------------------
  |  Branch (70:6): [True: 12, False: 307]
  ------------------
   71|       |		/* Extended Length Information in EF.ATR/INFO */
   72|     12|		tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_EXTENDED_LENGTH, &taglen);
  ------------------
  |  |   41|     12|#define ISO7816_TAG_II_EXTENDED_LENGTH		0x7F66
  ------------------
   73|     12|		if (tag && taglen >= 8) {
  ------------------
  |  Branch (73:7): [True: 10, False: 2]
  |  Branch (73:14): [True: 9, False: 1]
  ------------------
   74|       |			/* The command- and response-APDU size limitations are defined by
   75|       |			 * two integers, each nested in a DO'02'.
   76|       |			 * We skip parsing the nested DOs and jump directly to the numbers */
   77|      9|			ef_atr.max_command_apdu = bebytes2ushort(tag + 2);
   78|      9|			ef_atr.max_response_apdu = bebytes2ushort(tag + 6);
   79|      9|			sc_log(ctx, "EF.ATR: Biggest command APDU %zu bytes, response APDU %zu",
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   80|      9|					ef_atr.max_command_apdu, ef_atr.max_response_apdu);
   81|      9|		}
   82|     12|	}
   83|       |
   84|    319|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_AID, &taglen);
  ------------------
  |  |   36|    319|#define ISO7816_TAG_II_AID			0x4F
  ------------------
   85|    319|	if (tag) {
  ------------------
  |  Branch (85:6): [True: 7, False: 312]
  ------------------
   86|      7|		if (taglen > sizeof(ef_atr.aid.value))
  ------------------
  |  Branch (86:7): [True: 1, False: 6]
  ------------------
   87|      7|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid MF AID size");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|      6|		memcpy(ef_atr.aid.value, tag, taglen);
   89|      6|		ef_atr.aid.len = taglen;
   90|      6|		sc_log(ctx, "EF.ATR: AID '%s'", sc_dump_hex(ef_atr.aid.value, ef_atr.aid.len));
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   91|      6|	}
   92|       |
   93|       |	/* IAS/ECC specific issuer data: contains the max send/recv buffer sizes in plain and SM modes */
   94|    318|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_TAG_II_IO_BUFFER_SIZES, &taglen);
  ------------------
  |  |   48|    318|#define IASECC_TAG_II_IO_BUFFER_SIZES		0xE0
  ------------------
   95|    318|	if (tag) {
  ------------------
  |  Branch (95:6): [True: 91, False: 227]
  ------------------
   96|     91|		size_t len = taglen > sizeof(ef_atr.issuer_data) ? sizeof(ef_atr.issuer_data) : taglen;
  ------------------
  |  Branch (96:16): [True: 46, False: 45]
  ------------------
   97|       |
   98|     91|		memcpy(ef_atr.issuer_data, tag, len);
   99|     91|		ef_atr.issuer_data_len = len;
  100|       |
  101|     91|		sc_log(ctx, "EF.ATR: Issuer data '%s'", sc_dump_hex(ef_atr.issuer_data, ef_atr.issuer_data_len));
  ------------------
  |  |   71|     91|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|     91|	}
  103|       |
  104|    318|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_ALLOCATION_SCHEME, &taglen);
  ------------------
  |  |   37|    318|#define ISO7816_TAG_II_ALLOCATION_SCHEME        0x78
  ------------------
  105|    318|	if (tag)   {
  ------------------
  |  Branch (105:6): [True: 53, False: 265]
  ------------------
  106|     53|		sc_log(ctx, "EF.ATR: DER encoded OID %s", sc_dump_hex(tag, taglen));
  ------------------
  |  |   71|     53|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  107|     53|		tag = sc_asn1_find_tag(ctx, tag, taglen, SC_ASN1_TAG_OBJECT, &taglen);
  ------------------
  |  |  200|     53|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  108|     53|		if (tag)   {
  ------------------
  |  Branch (108:7): [True: 41, False: 12]
  ------------------
  109|     41|			sc_log(ctx, "EF.ATR: OID %s", sc_dump_hex(tag, taglen));
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  110|     41|			if(sc_asn1_decode_object_id(tag, taglen, &ef_atr.allocation_oid))
  ------------------
  |  Branch (110:7): [True: 26, False: 15]
  ------------------
  111|     41|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|     26|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     26|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     26|	int _ret = r; \
  |  |  |  |  155|     26|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     26|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     26|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  112|     41|		}
  113|     53|	}
  114|       |
  115|    292|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_STATUS_SW, &taglen);
  ------------------
  |  |   39|    292|#define ISO7816_TAG_II_STATUS_SW		0x82
  ------------------
  116|    292|	if (tag && taglen == 2)   {
  ------------------
  |  Branch (116:6): [True: 8, False: 284]
  |  Branch (116:13): [True: 4, False: 4]
  ------------------
  117|      4|		ef_atr.status = *(tag + 0) * 0x100 + *(tag + 1);
  118|      4|		sc_log(ctx, "EF.ATR: status word 0x%X", ef_atr.status);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  119|      4|	}
  120|       |
  121|    292|	if (!card->ef_atr)
  ------------------
  |  Branch (121:6): [True: 290, False: 2]
  ------------------
  122|    290|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  123|       |
  124|    292|	if (!card->ef_atr)
  ------------------
  |  Branch (124:6): [True: 0, False: 292]
  ------------------
  125|    292|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  126|       |
  127|    292|	memcpy(card->ef_atr, &ef_atr, sizeof(struct sc_ef_atr));
  128|       |
  129|    292|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    292|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    292|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    292|	int _ret = r; \
  |  |  |  |  155|    292|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 292, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    292|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 292]
  |  |  |  |  ------------------
  |  |  |  |  157|    292|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    292|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    292|	return _ret; \
  |  |  |  |  163|    292|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  130|    292|}

sc_parse_ef_gdo:
   92|    808|{
   93|    808|	struct sc_context *ctx;
   94|    808|	struct sc_path path;
   95|    808|	struct sc_file *file;
   96|    808|	unsigned char *gdo = NULL;
   97|    808|	size_t gdo_len = 0;
   98|    808|	int r;
   99|       |
  100|    808|	if (!card)
  ------------------
  |  Branch (100:6): [True: 0, False: 808]
  ------------------
  101|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  102|       |
  103|    808|	ctx = card->ctx;
  104|       |
  105|    808|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    808|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    808|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    808|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    808|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 808]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|       |
  107|    808|	sc_format_path("3F002F02", &path);
  108|    808|	r = sc_select_file(card, &path, &file);
  109|    808|	LOG_TEST_GOTO_ERR(ctx, r, "Cannot select EF(GDO) file");
  ------------------
  |  |  184|    808|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    808|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    808|	int _ret = (r); \
  |  |  |  |  178|    808|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 553, False: 255]
  |  |  |  |  ------------------
  |  |  |  |  179|    553|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    553|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    553|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    553|		goto err; \
  |  |  |  |  182|    553|	} \
  |  |  |  |  183|    808|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|       |
  111|    255|	if (file->size) {
  ------------------
  |  Branch (111:6): [True: 3, False: 252]
  ------------------
  112|      3|		gdo_len = file->size;
  113|    252|	} else {
  114|    252|		gdo_len = 64;
  115|    252|	}
  116|    255|	gdo = malloc(gdo_len);
  117|    255|	if (!gdo) {
  ------------------
  |  Branch (117:6): [True: 0, False: 255]
  ------------------
  118|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  119|      0|		goto err;
  120|      0|	}
  121|       |
  122|    255|	r = sc_read_binary(card, 0, gdo, gdo_len, 0);
  123|    255|	LOG_TEST_GOTO_ERR(ctx, r, "Cannot read EF(GDO) file");
  ------------------
  |  |  184|    255|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    255|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    255|	int _ret = (r); \
  |  |  |  |  178|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 14, False: 241]
  |  |  |  |  ------------------
  |  |  |  |  179|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     14|		goto err; \
  |  |  |  |  182|     14|	} \
  |  |  |  |  183|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 241]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|       |
  125|    241|	r = sc_parse_ef_gdo_content(gdo, r, iccsn, iccsn_len, chn, chn_len);
  126|       |
  127|    808|err:
  128|    808|	sc_file_free(file);
  129|    808|	free(gdo);
  130|       |
  131|    808|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    808|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    808|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    808|	int _ret = r; \
  |  |  |  |  155|    808|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 808, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    808|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    570|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 570, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    808|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    808|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    808|	return _ret; \
  |  |  |  |  163|    808|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  132|    808|}
ef-gdo.c:sc_parse_ef_gdo_content:
   33|    241|{
   34|    241|	int r = SC_SUCCESS, iccsn_found = 0, chn_found = 0;
  ------------------
  |  |   28|    241|#define SC_SUCCESS				0
  ------------------
   35|    241|	const unsigned char *p = gdo;
   36|    241|	size_t left = gdo_len;
   37|       |
   38|    535|	while (left >= 2) {
  ------------------
  |  Branch (38:9): [True: 314, False: 221]
  ------------------
   39|    314|		unsigned int cla, tag;
   40|    314|		size_t tag_len;
   41|       |
   42|    314|		r = sc_asn1_read_tag(&p, left, &cla, &tag, &tag_len);
   43|    314|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    314|#define SC_SUCCESS				0
  ------------------
  |  Branch (43:7): [True: 11, False: 303]
  ------------------
   44|     11|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|     11|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (44:8): [True: 8, False: 3]
  ------------------
   45|       |				/* not enough data */
   46|      8|				r = SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
   47|      8|			}
   48|     11|			break;
   49|     11|		}
   50|    303|		if (p == NULL) {
  ------------------
  |  Branch (50:7): [True: 9, False: 294]
  ------------------
   51|       |			/* done parsing */
   52|      9|			break;
   53|      9|		}
   54|       |
   55|    294|		if (cla == SC_ASN1_TAG_APPLICATION) {
  ------------------
  |  |  186|    294|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (55:7): [True: 205, False: 89]
  ------------------
   56|    205|			switch (tag) {
  ------------------
  |  Branch (56:12): [True: 113, False: 92]
  ------------------
   57|     71|				case 0x1A:
  ------------------
  |  Branch (57:5): [True: 71, False: 134]
  ------------------
   58|     71|					iccsn_found = 1;
   59|     71|					if (iccsn && iccsn_len) {
  ------------------
  |  Branch (59:10): [True: 71, False: 0]
  |  Branch (59:19): [True: 71, False: 0]
  ------------------
   60|     71|						memcpy(iccsn, p, MIN(tag_len, *iccsn_len));
  ------------------
  |  |   69|     71|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 23, False: 48]
  |  |  ------------------
  ------------------
   61|     71|						*iccsn_len = MIN(tag_len, *iccsn_len);
  ------------------
  |  |   69|     71|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 23, False: 48]
  |  |  ------------------
  ------------------
   62|     71|					}
   63|     71|					break;
   64|     42|				case 0x1F20:
  ------------------
  |  Branch (64:5): [True: 42, False: 163]
  ------------------
   65|     42|					chn_found = 1;
   66|     42|					if (chn && chn_len) {
  ------------------
  |  Branch (66:10): [True: 0, False: 42]
  |  Branch (66:17): [True: 0, False: 0]
  ------------------
   67|      0|						memcpy(chn, p, MIN(tag_len, *chn_len));
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   68|      0|						*chn_len = MIN(tag_len, *chn_len);
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   69|      0|					}
   70|     42|					break;
   71|    205|			}
   72|    205|		}
   73|       |
   74|    294|		p += tag_len;
   75|    294|		left = gdo_len - (p - gdo);
   76|    294|	}
   77|       |
   78|    241|	if (!iccsn_found && iccsn_len)
  ------------------
  |  Branch (78:6): [True: 224, False: 17]
  |  Branch (78:22): [True: 224, False: 0]
  ------------------
   79|    224|		*iccsn_len = 0;
   80|    241|	if (!chn_found && chn_len)
  ------------------
  |  Branch (80:6): [True: 231, False: 10]
  |  Branch (80:20): [True: 0, False: 231]
  ------------------
   81|      0|		*chn_len = 0;
   82|       |
   83|    241|	return r;
   84|    241|}

sc_strerror:
   32|  2.63M|{
   33|  2.63M|	unsigned int error_index = 0;
   34|  2.63M|	const char *rdr_errors[] = {
   35|  2.63M|		"Generic reader error",
   36|  2.63M|		"No readers found",
   37|  2.63M|		"UNUSED",
   38|  2.63M|		"UNUSED",
   39|  2.63M|		"Card not present",
   40|  2.63M|		"Card removed",
   41|  2.63M|		"Card reset",
   42|  2.63M|		"Transmit failed",
   43|  2.63M|		"Timed out while waiting for user input",
   44|  2.63M|		"Input operation cancelled by user",
   45|  2.63M|		"The two PINs did not match",
   46|  2.63M|		"Message too long (keypad)",
   47|  2.63M|		"Timeout while waiting for event from card reader",
   48|  2.63M|		"Unresponsive card (correctly inserted?)",
   49|  2.63M|		"Reader detached",
   50|  2.63M|		"Reader reattached",
   51|  2.63M|		"Reader in use by another application"
   52|  2.63M|	};
   53|  2.63M|	const unsigned int rdr_base = -SC_ERROR_READER;
  ------------------
  |  |   31|  2.63M|#define SC_ERROR_READER				-1100
  ------------------
   54|       |
   55|  2.63M|	const char *card_errors[] = {
   56|  2.63M|		"Card command failed",
   57|  2.63M|		"File not found",
   58|  2.63M|		"Record not found",
   59|  2.63M|		"Unsupported CLA byte in APDU",
   60|  2.63M|		"Unsupported INS byte in APDU",
   61|  2.63M|		"Incorrect parameters in APDU",
   62|  2.63M|		"Wrong length",
   63|  2.63M|		"Card memory failure",
   64|  2.63M|		"Card does not support the requested operation",
   65|  2.63M|		"Not allowed",
   66|  2.63M|		"Card is invalid or cannot be handled",
   67|  2.63M|		"Security status not satisfied",
   68|  2.63M|		"Authentication method blocked",
   69|  2.63M|		"Unknown data received from card",
   70|  2.63M|		"PIN code or key incorrect",
   71|  2.63M|		"File already exists",
   72|  2.63M|		"Data object not found",
   73|  2.63M|		"Not enough memory on card",
   74|  2.63M|		"Part of returned data may be corrupted",
   75|  2.63M|		"End of file/record reached before reading Le bytes",
   76|  2.63M|		"Reference data not usable"
   77|  2.63M|	};
   78|  2.63M|	const unsigned int card_base = -SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  2.63M|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
   79|       |
   80|  2.63M|	const char *arg_errors[] = {
   81|  2.63M|		"Invalid arguments",
   82|  2.63M|		"UNUSED",
   83|  2.63M|		"UNUSED",
   84|  2.63M|		"Buffer too small",
   85|  2.63M|		"Invalid PIN length",
   86|  2.63M|		"Invalid data",
   87|  2.63M|	};
   88|  2.63M|	const unsigned int arg_base = -SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.63M|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   89|       |
   90|  2.63M|	const char *int_errors[] = {
   91|  2.63M|		"Internal error",
   92|  2.63M|		"Invalid ASN.1 object",
   93|  2.63M|		"Required ASN.1 object not found",
   94|  2.63M|		"Premature end of ASN.1 stream",
   95|  2.63M|		"Out of memory",
   96|  2.63M|		"Too many objects",
   97|  2.63M|		"Object not valid",
   98|  2.63M|		"Requested object not found",
   99|  2.63M|		"Not supported",
  100|  2.63M|		"Passphrase required",
  101|  2.63M|		"Inconsistent configuration",
  102|  2.63M|		"Decryption failed",
  103|  2.63M|		"Wrong padding",
  104|  2.63M|		"Unsupported card",
  105|  2.63M|		"Unable to load external module",
  106|  2.63M|		"EF offset too large",
  107|  2.63M|		"Not implemented",
  108|  2.63M|		"Invalid Simple TLV object",
  109|  2.63M|		"Premature end of Simple TLV stream",
  110|  2.63M|	};
  111|  2.63M|	const unsigned int int_base = -SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.63M|#define SC_ERROR_INTERNAL			-1400
  ------------------
  112|       |
  113|  2.63M|	const char *p15i_errors[] = {
  114|  2.63M|		"Generic PKCS#15 initialization error",
  115|  2.63M|		"Syntax error",
  116|  2.63M|		"Inconsistent or incomplete PKCS#15 profile",
  117|  2.63M|		"Key length/algorithm not supported by card",
  118|  2.63M|		"No default (transport) key available",
  119|  2.63M|		"Non unique object ID",
  120|  2.63M|		"Unable to load key and certificate(s) from file",
  121|  2.63M|		"UNUSED",
  122|  2.63M|		"File template not found",
  123|  2.63M|		"Invalid PIN reference",
  124|  2.63M|		"File too small",
  125|  2.63M|	};
  126|  2.63M|	const unsigned int p15i_base = -SC_ERROR_PKCS15INIT;
  ------------------
  |  |  102|  2.63M|#define SC_ERROR_PKCS15INIT			-1500
  ------------------
  127|       |
  128|  2.63M|	const char *sm_errors[] = {
  129|  2.63M|		"Generic Secure Messaging error",
  130|  2.63M|		"Data enciphering error",
  131|  2.63M|		"Invalid secure messaging level",
  132|  2.63M|		"No session keys",
  133|  2.63M|		"Invalid session keys",
  134|  2.63M|		"Secure Messaging not initialized",
  135|  2.63M|		"Cannot authenticate card",
  136|  2.63M|		"Random generation error",
  137|  2.63M|		"Secure messaging keyset not found",
  138|  2.63M|		"IFD data missing",
  139|  2.63M|		"SM not applied",
  140|  2.63M|		"SM session already active",
  141|  2.63M|		"Invalid checksum"
  142|  2.63M|	};
  143|  2.63M|	const unsigned int sm_base = -SC_ERROR_SM;
  ------------------
  |  |  115|  2.63M|#define SC_ERROR_SM				-1600
  ------------------
  144|       |
  145|  2.63M|	const char *misc_errors[] = {
  146|  2.63M|		"Unknown error",
  147|  2.63M|		"PKCS#15 compatible smart card not found",
  148|  2.63M|	};
  149|  2.63M|	const unsigned int misc_base = -SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|  2.63M|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  150|       |
  151|  2.63M|	const char *no_errors = "Success";
  152|  2.63M|	const char **errors = NULL;
  153|  2.63M|	unsigned int count = 0, err_base = 0;
  154|       |
  155|  2.63M|	if (!error)
  ------------------
  |  Branch (155:6): [True: 1.87M, False: 764k]
  ------------------
  156|  1.87M|		return no_errors;
  157|   764k|	error_index = error < 0 ? (unsigned)(-(long long int)error) : (unsigned)error;
  ------------------
  |  Branch (157:16): [True: 764k, False: 0]
  ------------------
  158|       |
  159|   764k|	if (error_index >= misc_base) {
  ------------------
  |  Branch (159:6): [True: 466, False: 763k]
  ------------------
  160|    466|		errors = misc_errors;
  161|    466|		count = DIM(misc_errors);
  ------------------
  |  |   29|    466|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  162|    466|		err_base = misc_base;
  163|   763k|	} else if (error_index >= sm_base) {
  ------------------
  |  Branch (163:13): [True: 266, False: 763k]
  ------------------
  164|    266|		errors = sm_errors;
  165|    266|		count = DIM(sm_errors);
  ------------------
  |  |   29|    266|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  166|    266|		err_base = sm_base;
  167|   763k|	} else if (error_index >= p15i_base) {
  ------------------
  |  Branch (167:13): [True: 1.94k, False: 761k]
  ------------------
  168|  1.94k|		errors = p15i_errors;
  169|  1.94k|		count = DIM(p15i_errors);
  ------------------
  |  |   29|  1.94k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  170|  1.94k|		err_base = p15i_base;
  171|   761k|	} else if (error_index >= int_base) {
  ------------------
  |  Branch (171:13): [True: 143k, False: 618k]
  ------------------
  172|   143k|		errors = int_errors;
  173|   143k|		count = DIM(int_errors);
  ------------------
  |  |   29|   143k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  174|   143k|		err_base = int_base;
  175|   618k|	} else if (error_index >= arg_base) {
  ------------------
  |  Branch (175:13): [True: 19.2k, False: 598k]
  ------------------
  176|  19.2k|		errors = arg_errors;
  177|  19.2k|		count = DIM(arg_errors);
  ------------------
  |  |   29|  19.2k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  178|  19.2k|		err_base = arg_base;
  179|   598k|	} else if (error_index >= card_base) {
  ------------------
  |  Branch (179:13): [True: 595k, False: 3.70k]
  ------------------
  180|   595k|		errors = card_errors;
  181|   595k|		count = DIM(card_errors);
  ------------------
  |  |   29|   595k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  182|   595k|		err_base = card_base;
  183|   595k|	} else if (error_index >= rdr_base) {
  ------------------
  |  Branch (183:13): [True: 0, False: 3.70k]
  ------------------
  184|      0|		errors = rdr_errors;
  185|      0|		count = DIM(rdr_errors);
  ------------------
  |  |   29|      0|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  186|      0|		err_base = rdr_base;
  187|      0|	}
  188|   764k|	error_index -= err_base;
  189|   764k|	if (error_index >= count)
  ------------------
  |  Branch (189:6): [True: 3.70k, False: 760k]
  ------------------
  190|  3.70k|		return misc_errors[0];
  191|   760k|	return errors[error_index];
  192|   764k|}

gp_select_aid:
   50|  1.61k|{
   51|  1.61k|	int rv;
   52|  1.61k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.61k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.61k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.61k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.61k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.61k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|  1.61k|	rv = iso7816_select_aid(card, aid->value, aid->len, NULL, NULL);
   54|  1.61k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  1.61k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.61k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.61k|	int _ret = r; \
  |  |  |  |  155|  1.61k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.61k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    157|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 157, False: 1.45k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.61k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.61k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.61k|	return _ret; \
  |  |  |  |  163|  1.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   55|  1.61k|}
gp_select_card_manager:
   60|  1.48k|{
   61|  1.48k|	int rv;
   62|       |
   63|  1.48k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.48k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.48k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.48k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.48k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.48k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   64|  1.48k|	rv = gp_select_aid(card, &gp_card_manager);
   65|  1.48k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  1.48k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.48k|	int _ret = r; \
  |  |  |  |  155|  1.48k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.48k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     90|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 90, False: 1.39k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.48k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.48k|	return _ret; \
  |  |  |  |  163|  1.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   66|  1.48k|}
gp_select_isd_rid:
   71|     62|{
   72|     62|	int rv;
   73|       |
   74|     62|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     62|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     62|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     62|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     62|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|     62|	rv = gp_select_aid(card, &gp_isd_rid);
   76|     62|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     62|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   77|     62|}
gp_get_cplc_data:
   82|    612|{
   83|    612|	size_t len = sizeof(global_platform_cplc_data_t);
   84|    612|	u8 *receive_buf = (u8 *)cplc_data;
   85|    612|	struct sc_apdu apdu;
   86|    612|	int rc;
   87|       |
   88|    612|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, ISO7816_INS_GET_DATA, 0x9f, 0x7f);
  ------------------
  |  |  292|    612|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
              	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, ISO7816_INS_GET_DATA, 0x9f, 0x7f);
  ------------------
  |  |   34|    612|#define ISO7816_INS_GET_DATA    0xca
  ------------------
   89|    612|	apdu.cla = GLOBAL_PLATFORM_CLASS;
  ------------------
  |  |   31|    612|#define GLOBAL_PLATFORM_CLASS   0x80
  ------------------
   90|    612|	apdu.resp = receive_buf;
   91|    612|	apdu.resplen = len;
   92|    612|	apdu.le = len;
   93|       |
   94|    612|	rc = sc_transmit_apdu(card, &apdu);
   95|    612|	if (rc < 0)
  ------------------
  |  Branch (95:6): [True: 2, False: 610]
  ------------------
   96|    612|		LOG_FUNC_RETURN(card->ctx, rc);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   97|       |
   98|    610|	rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
   99|    610|	if (rc < 0)
  ------------------
  |  Branch (99:6): [True: 6, False: 604]
  ------------------
  100|    610|		LOG_FUNC_RETURN(card->ctx, rc);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|       |
  102|       |	/* We expect this will fill the whole structure in the argument.
  103|       |	 * If we got something else, report error */
  104|    604|	if ((size_t)apdu.resplen < sizeof(global_platform_cplc_data_t)) {
  ------------------
  |  Branch (104:6): [True: 2, False: 602]
  ------------------
  105|      2|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|      2|	}
  107|    602|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    602|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    602|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    602|	int _ret = r; \
  |  |  |  |  155|    602|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 602]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    602|	} else { \
  |  |  |  |  159|    602|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    602|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    602|	} \
  |  |  |  |  162|    602|	return _ret; \
  |  |  |  |  163|    602|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  108|    602|}

iasecc_sdo_free_fields:
  150|    446|{
  151|    446|	if (sdo == NULL) {
  ------------------
  |  Branch (151:6): [True: 0, False: 446]
  ------------------
  152|      0|		return;
  153|      0|	}
  154|       |
  155|    446|	free(sdo->docp.tries_maximum.value);
  156|    446|	free(sdo->docp.tries_remaining.value);
  157|    446|	free(sdo->docp.usage_remaining.value);
  158|    446|	free(sdo->docp.non_repudiation.value);
  159|    446|	free(sdo->docp.acls_contact.value);
  160|    446|	free(sdo->docp.acls_contactless.value);
  161|    446|	free(sdo->docp.size.value);
  162|    446|	free(sdo->docp.name.value);
  163|    446|	free(sdo->docp.issuer_data.value);
  164|       |
  165|    446|	if (sdo->sdo_class == IASECC_SDO_CLASS_RSA_PUBLIC)   {
  ------------------
  |  |  101|    446|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (165:6): [True: 0, False: 446]
  ------------------
  166|      0|		free(sdo->data.pub_key.n.value);
  167|      0|		free(sdo->data.pub_key.e.value);
  168|      0|		free(sdo->data.pub_key.compulsory.value);
  169|      0|		free(sdo->data.pub_key.chr.value);
  170|      0|		free(sdo->data.pub_key.cha.value);
  171|      0|	}
  172|    446|	else if (sdo->sdo_class == IASECC_SDO_CLASS_RSA_PRIVATE)   {
  ------------------
  |  |  100|    446|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (172:11): [True: 0, False: 446]
  ------------------
  173|      0|		free(sdo->data.prv_key.p.value);
  174|      0|		free(sdo->data.prv_key.q.value);
  175|      0|		free(sdo->data.prv_key.iqmp.value);
  176|      0|		free(sdo->data.prv_key.dmp1.value);
  177|      0|		free(sdo->data.prv_key.dmq1.value);
  178|      0|		free(sdo->data.prv_key.compulsory.value);
  179|      0|	}
  180|    446|	else if (sdo->sdo_class == IASECC_SDO_CLASS_CHV)   {
  ------------------
  |  |   98|    446|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (180:11): [True: 172, False: 274]
  ------------------
  181|    172|		free(sdo->data.chv.size_max.value);
  182|    172|		free(sdo->data.chv.size_min.value);
  183|    172|		free(sdo->data.chv.value.value);
  184|    172|	}
  185|       |	/* invalidate all the other members too */
  186|    446|	memset(sdo, 0, sizeof(struct iasecc_sdo));
  187|    446|}
iasecc_se_get_crt:
  254|     32|{
  255|     32|	struct sc_context *ctx = card->ctx;
  256|     32|	int ii;
  257|       |
  258|     32|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     32|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     32|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     32|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     32|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|     32|	if (!se || !crt)
  ------------------
  |  Branch (259:6): [True: 0, False: 32]
  |  Branch (259:13): [True: 0, False: 32]
  ------------------
  260|     32|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  261|     32|	sc_log(ctx, "CRT search template: %X:%X:%X, refs %X:%X:...",
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  262|     32|			crt->tag, crt->algo, crt->usage, crt->refs[0], crt->refs[1]);
  263|       |
  264|    304|	for (ii=0; ii<SC_MAX_CRTS_IN_SE && se->crts[ii].tag; ii++)   {
  ------------------
  |  |   50|    608|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (264:13): [True: 293, False: 11]
  |  Branch (264:37): [True: 272, False: 21]
  ------------------
  265|    272|		if (crt->tag != se->crts[ii].tag)
  ------------------
  |  Branch (265:7): [True: 251, False: 21]
  ------------------
  266|    251|			continue;
  267|     21|		if (crt->algo && crt->algo != se->crts[ii].algo)
  ------------------
  |  Branch (267:7): [True: 0, False: 21]
  |  Branch (267:20): [True: 0, False: 0]
  ------------------
  268|      0|			continue;
  269|     21|		if (crt->usage && crt->usage != se->crts[ii].usage)
  ------------------
  |  Branch (269:7): [True: 21, False: 0]
  |  Branch (269:21): [True: 21, False: 0]
  ------------------
  270|     21|			continue;
  271|      0|		if (crt->refs[0] && crt->refs[0] != se->crts[ii].refs[0])
  ------------------
  |  Branch (271:7): [True: 0, False: 0]
  |  Branch (271:23): [True: 0, False: 0]
  ------------------
  272|      0|			continue;
  273|       |
  274|      0|		memcpy(crt, &se->crts[ii], sizeof(*crt));
  275|       |
  276|      0|		sc_log(ctx, "iasecc_se_get_crt() found CRT with refs %X:%X:...",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  277|      0|				se->crts[ii].refs[0], se->crts[ii].refs[1]);
  278|      0|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|      0|	}
  280|       |
  281|     32|	sc_log(ctx, "iasecc_se_get_crt() CRT is not found");
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  282|     32|	return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     32|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  283|     32|}
iasecc_se_parse:
  317|    205|{
  318|    205|	struct sc_context *ctx = card->ctx;
  319|    205|	size_t size, offs;
  320|    205|	int size_size;
  321|    205|	int rv;
  322|       |
  323|    205|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    205|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    205|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    205|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    205|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 205]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|    205|	sc_log(ctx, "data_len %zu", data_len);
  ------------------
  |  |   71|    205|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  325|       |
  326|    205|	if (data_len < 1)
  ------------------
  |  Branch (326:6): [True: 13, False: 192]
  ------------------
  327|    205|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  328|       |
  329|    192|	if (*data == IASECC_SDO_TEMPLATE_TAG)   {
  ------------------
  |  |   29|    192|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
  |  Branch (329:6): [True: 60, False: 132]
  ------------------
  330|     60|		size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  331|     60|		LOG_TEST_RET(ctx, size_size, "parse error: invalid size data of IASECC_SDO_TEMPLATE");
  ------------------
  |  |  174|     60|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     60|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     60|	int _ret = (r); \
  |  |  |  |  168|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  332|       |
  333|     49|		if (data_len < size + size_size + 1)
  ------------------
  |  Branch (333:7): [True: 14, False: 35]
  ------------------
  334|     49|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|       |
  336|     35|		data += size_size + 1;
  337|     35|		data_len = size;
  338|     35|		sc_log(ctx, "IASECC_SDO_TEMPLATE: size %zu, size_size %d", size, size_size);
  ------------------
  |  |   71|     35|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  339|       |
  340|     35|		if (data_len < 3)
  ------------------
  |  Branch (340:7): [True: 13, False: 22]
  ------------------
  341|     35|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|       |
  343|     22|		if (*data != IASECC_SDO_TAG_HEADER)
  ------------------
  |  |   27|     22|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
  |  Branch (343:7): [True: 10, False: 12]
  ------------------
  344|     22|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|       |
  346|     12|		if ((*(data + 1) & 0x7F) != IASECC_SDO_CLASS_SE)
  ------------------
  |  |  102|     12|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (346:7): [True: 7, False: 5]
  ------------------
  347|     12|			 LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  348|       |
  349|      5|		size_size = iasecc_parse_size(data + 3, data_len - 3, &size);
  350|      5|		LOG_TEST_RET(ctx, size_size, "parse error: invalid SDO SE data size");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|       |
  352|      4|		if (data_len != size + size_size + 3)
  ------------------
  |  Branch (352:7): [True: 1, False: 3]
  ------------------
  353|      4|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: invalid SDO SE data size");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  354|       |
  355|      3|		data += 3 + size_size;
  356|      3|		data_len = size;
  357|      3|		sc_log(ctx, "IASECC_SDO_TEMPLATE SE: size %zu, size_size %d", size, size_size);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  358|      3|	}
  359|       |
  360|    135|	if (*data != IASECC_SDO_CLASS_SE)   {
  ------------------
  |  |  102|    135|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (360:6): [True: 17, False: 118]
  ------------------
  361|     17|		sc_log(ctx, "Invalid SE tag 0x%X; data length %zu", *data, data_len);
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  362|     17|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     17|	}
  364|       |
  365|    118|	size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  366|    118|	LOG_TEST_RET(ctx, size_size, "parse error: invalid size data");
  ------------------
  |  |  174|    118|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    118|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    118|	int _ret = (r); \
  |  |  |  |  168|    118|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    118|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  367|       |
  368|    108|	if (data_len != size + size_size + 1)
  ------------------
  |  Branch (368:6): [True: 12, False: 96]
  ------------------
  369|    108|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: invalid SE data size");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|       |
  371|     96|	offs = 1 + size_size;
  372|  1.08k|	for (; offs < data_len;)   {
  ------------------
  |  Branch (372:9): [True: 1.06k, False: 28]
  ------------------
  373|  1.06k|		rv = iasecc_crt_parse(card, data + offs, data_len - offs, se);
  374|  1.06k|		LOG_TEST_RET(ctx, rv, "parse error: invalid SE data");
  ------------------
  |  |  174|  1.06k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.06k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.06k|	int _ret = (r); \
  |  |  |  |  168|  1.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 68, False: 993]
  |  |  |  |  ------------------
  |  |  |  |  169|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     68|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     68|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     68|		return _ret; \
  |  |  |  |  172|     68|	} \
  |  |  |  |  173|  1.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 993]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  375|       |
  376|    993|		offs += rv;
  377|    993|	}
  378|       |
  379|     28|	if (offs != data_len)
  ------------------
  |  Branch (379:6): [True: 0, False: 28]
  ------------------
  380|     28|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: not totally parsed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|       |
  382|     28|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|     28|}
iasecc_sdo_parse:
  755|    223|{
  756|    223|	struct sc_context *ctx = card->ctx;
  757|    223|	size_t size, offs;
  758|    223|	int size_size;
  759|    223|	int rv;
  760|       |
  761|    223|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    223|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    223|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    223|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    223|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 223]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|       |
  763|    223|	if (data == NULL || data_len < 2)
  ------------------
  |  Branch (763:6): [True: 0, False: 223]
  |  Branch (763:22): [True: 1, False: 222]
  ------------------
  764|    223|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  765|       |
  766|    222|	if (*data == IASECC_SDO_TEMPLATE_TAG)   {
  ------------------
  |  |   29|    222|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
  |  Branch (766:6): [True: 27, False: 195]
  ------------------
  767|     27|		size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  768|     27|		LOG_TEST_RET(ctx, size_size, "parse error: invalid size data of IASECC_SDO_TEMPLATE");
  ------------------
  |  |  174|     27|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     27|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     27|	int _ret = (r); \
  |  |  |  |  168|     27|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  769|       |
  770|     23|		if (data_len < (size_t)(size_size + 1)) {
  ------------------
  |  Branch (770:7): [True: 0, False: 23]
  ------------------
  771|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|      0|		}
  773|     23|		data += size_size + 1;
  774|     23|		data_len -= (size_size + 1);
  775|     23|		if (size > data_len) {
  ------------------
  |  Branch (775:7): [True: 17, False: 6]
  ------------------
  776|     17|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  777|     17|		}
  778|      6|		data_len = size;
  779|      6|		sc_log(ctx, "IASECC_SDO_TEMPLATE: size %zu, size_size %d", size, size_size);
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  780|      6|	}
  781|       |
  782|    201|	if (data_len < 4 || *data != IASECC_SDO_TAG_HEADER)
  ------------------
  |  |   27|    198|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
  |  Branch (782:6): [True: 3, False: 198]
  |  Branch (782:22): [True: 10, False: 188]
  ------------------
  783|    201|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  784|       |
  785|    188|	if (sdo->sdo_class != (*(data + 1) & 0x7F))
  ------------------
  |  Branch (785:6): [True: 1, False: 187]
  ------------------
  786|    188|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  787|       |
  788|    187|	if (sdo->sdo_ref != (*(data + 2) & 0x3F))
  ------------------
  |  Branch (788:6): [True: 2, False: 185]
  ------------------
  789|    187|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  790|       |
  791|    185|	size_size = iasecc_parse_size(data + 3, data_len - 3, &size);
  792|    185|	LOG_TEST_RET(ctx, size_size, "parse error: invalid size data");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  793|       |
  794|    184|	if (data_len != size + size_size + 3)
  ------------------
  |  Branch (794:6): [True: 11, False: 173]
  ------------------
  795|    184|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: invalid SDO data size");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  796|       |
  797|    173|	sc_log(ctx, "sz %zu, sz_size %d", size, size_size);
  ------------------
  |  |   71|    173|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  798|       |
  799|    173|	offs = 3 + size_size;
  800|    449|	for (; offs < data_len;)   {
  ------------------
  |  Branch (800:9): [True: 446, False: 3]
  ------------------
  801|    446|		rv = iasecc_sdo_parse_data(card, data + offs, data_len - offs, sdo);
  802|    446|		if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    446|#define SC_SUCCESS				0
  ------------------
  |  Branch (802:7): [True: 446, False: 0]
  ------------------
  803|    446|			iasecc_sdo_free_fields(card, sdo);
  804|    446|			LOG_TEST_RET(ctx, rv, "parse error: invalid SDO data");
  ------------------
  |  |  174|    446|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    446|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    446|	int _ret = (r); \
  |  |  |  |  168|    446|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 170, False: 276]
  |  |  |  |  ------------------
  |  |  |  |  169|    170|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    170|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    170|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    170|		return _ret; \
  |  |  |  |  172|    170|	} \
  |  |  |  |  173|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 276]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|    446|		}
  806|       |
  807|    276|		offs += rv;
  808|    276|	}
  809|       |
  810|      3|	if (offs != data_len)
  ------------------
  |  Branch (810:6): [True: 0, False: 3]
  ------------------
  811|      3|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: not totally parsed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  812|       |
  813|      3|	sc_log(ctx, "docp.acls_contact.size %zu, docp.size.size %zu",
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  814|      3|			sdo->docp.acls_contact.size, sdo->docp.size.size);
  815|       |
  816|      3|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  817|      3|}
iasecc_docp_copy:
 1327|     32|{
 1328|     32|	int rv;
 1329|       |
 1330|     32|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     32|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     32|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     32|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     32|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1331|     32|	if (!in || !out)
  ------------------
  |  Branch (1331:6): [True: 0, False: 32]
  |  Branch (1331:13): [True: 0, False: 32]
  ------------------
 1332|     32|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1333|       |
 1334|     32|	memset(out, 0, sizeof(struct iasecc_sdo_docp));
 1335|       |
 1336|     32|	rv = iasecc_tlv_copy(ctx, &in->name, &out->name);
 1337|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1338|       |
 1339|     32|	rv = iasecc_tlv_copy(ctx, &in->tries_maximum, &out->tries_maximum);
 1340|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|       |
 1342|     32|	rv = iasecc_tlv_copy(ctx, &in->tries_remaining, &out->tries_remaining);
 1343|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1344|       |
 1345|     32|	rv = iasecc_tlv_copy(ctx, &in->usage_maximum, &out->usage_maximum);
 1346|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1347|       |
 1348|     32|	rv = iasecc_tlv_copy(ctx, &in->usage_remaining, &out->usage_remaining);
 1349|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1350|       |
 1351|     32|	rv = iasecc_tlv_copy(ctx, &in->non_repudiation, &out->non_repudiation);
 1352|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1353|       |
 1354|     32|	rv = iasecc_tlv_copy(ctx, &in->size, &out->size);
 1355|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1356|       |
 1357|     32|	rv = iasecc_tlv_copy(ctx, &in->acls_contact, &out->acls_contact);
 1358|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1359|       |
 1360|     32|	rv = iasecc_tlv_copy(ctx, &in->acls_contactless, &out->acls_contactless);
 1361|     32|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1362|       |
 1363|     32|	out->amb = in->amb;
 1364|     32|	memcpy(out->scbs, in->scbs, sizeof(out->scbs));
 1365|       |
 1366|     32|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1367|     32|}
iasecc-sdo.c:iasecc_parse_acls:
   44|    181|{
   45|    181|	struct sc_context *ctx = card->ctx;
   46|    181|	struct iasecc_extended_tlv *acls = &docp->acls_contact;
   47|    181|	int ii;
   48|    181|	size_t offs;
   49|    181|	unsigned char mask = 0x40;
   50|       |
   51|    181|	if (flags)
  ------------------
  |  Branch (51:6): [True: 0, False: 181]
  ------------------
   52|      0|		acls = &docp->acls_contactless;
   53|       |
   54|    181|	if (!acls->size)
  ------------------
  |  Branch (54:6): [True: 5, False: 176]
  ------------------
   55|    181|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   56|       |
   57|    176|	docp->amb = *(acls->value + 0);
   58|    176|	memset(docp->scbs, 0xFF, sizeof(docp->scbs));
   59|  1.38k|	for (ii=0, offs = 1; ii<7; ii++, mask >>= 1)
  ------------------
  |  Branch (59:23): [True: 1.21k, False: 171]
  ------------------
   60|  1.21k|		if (mask & docp->amb) {
  ------------------
  |  Branch (60:7): [True: 314, False: 896]
  ------------------
   61|    314|			if (offs >= acls->size) {
  ------------------
  |  Branch (61:8): [True: 5, False: 309]
  ------------------
   62|      5|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|      5|			}
   64|    309|			docp->scbs[ii] = *(acls->value + offs++);
   65|    309|		}
   66|       |
   67|    171|	sc_log(ctx, "iasecc_parse_docp() SCBs %02X:%02X:%02X:%02X:%02X:%02X:%02X",
  ------------------
  |  |   71|    171|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   68|    171|			docp->scbs[0],docp->scbs[1],docp->scbs[2],docp->scbs[3],
   69|    171|			docp->scbs[4],docp->scbs[5],docp->scbs[6]);
   70|    171|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    171|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    171|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    171|	int _ret = r; \
  |  |  |  |  155|    171|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 171, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    171|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  157|    171|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    171|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    171|	return _ret; \
  |  |  |  |  163|    171|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   71|    171|}
iasecc-sdo.c:iasecc_crt_parse:
  200|  1.06k|{
  201|  1.06k|	struct sc_context *ctx = card->ctx;
  202|  1.06k|	struct sc_crt crt;
  203|  1.06k|	int ii, offs, len, parsed_len = -1;
  204|       |
  205|  1.06k|	sc_log(ctx, "iasecc_crt_parse(0x%X) called", *data);
  ------------------
  |  |   71|  1.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  206|       |
  207|  1.06k|	if (data_len < 2)
  ------------------
  |  Branch (207:6): [True: 9, False: 1.05k]
  ------------------
  208|  1.06k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  209|       |
  210|  1.05k|	memset(&crt, 0, sizeof(crt));
  211|  1.05k|	crt.tag = *(data + 0);
  212|  1.05k|	len = *(data + 1);
  213|       |
  214|  1.18k|	for(offs = 2; offs < len + 2; offs += 3)   {
  ------------------
  |  Branch (214:16): [True: 180, False: 1.00k]
  ------------------
  215|    180|		if ((size_t) offs + 2 >= data_len)
  ------------------
  |  Branch (215:7): [True: 17, False: 163]
  ------------------
  216|    180|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|    163|		sc_log(ctx, "iasecc_crt_parse(0x%X) CRT %X -> %X", *data, *(data + offs), *(data + offs + 2));
  ------------------
  |  |   71|    163|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  218|    163|		if (*(data + offs) == IASECC_CRT_TAG_USAGE)   {
  ------------------
  |  |  111|    163|#define IASECC_CRT_TAG_USAGE		0x95
  ------------------
  |  Branch (218:7): [True: 76, False: 87]
  ------------------
  219|     76|			crt.usage = *(data + offs + 2);
  220|     76|		}
  221|     87|		else if (*(data + offs) == IASECC_CRT_TAG_REFERENCE)   {
  ------------------
  |  |  112|     87|#define IASECC_CRT_TAG_REFERENCE	0x83
  ------------------
  |  Branch (221:12): [True: 51, False: 36]
  ------------------
  222|     51|			int nn_refs = sizeof(crt.refs) / sizeof(crt.refs[0]);
  223|       |
  224|    176|			for (ii=0; ii<nn_refs && crt.refs[ii]; ii++)
  ------------------
  |  Branch (224:15): [True: 175, False: 1]
  |  Branch (224:29): [True: 125, False: 50]
  ------------------
  225|    125|				;
  226|     51|			if (ii == nn_refs)
  ------------------
  |  Branch (226:8): [True: 1, False: 50]
  ------------------
  227|     51|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  228|       |
  229|     50|			crt.refs[ii] = *(data + offs + 2);
  230|     50|		}
  231|     36|		else if (*(data + offs) == IASECC_CRT_TAG_ALGO)   {
  ------------------
  |  |  113|     36|#define IASECC_CRT_TAG_ALGO		0x80
  ------------------
  |  Branch (231:12): [True: 6, False: 30]
  ------------------
  232|      6|			crt.algo = *(data + offs + 2);
  233|      6|		}
  234|     30|		else   {
  235|     30|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|     30|		}
  237|    163|	}
  238|       |
  239|  6.30k|	for (ii=0; ii<SC_MAX_CRTS_IN_SE; ii++)
  ------------------
  |  |   50|  6.30k|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (239:13): [True: 6.29k, False: 11]
  ------------------
  240|  6.29k|		if (!se->crts[ii].tag)
  ------------------
  |  Branch (240:7): [True: 993, False: 5.30k]
  ------------------
  241|    993|			break;
  242|       |
  243|  1.00k|	if (ii==SC_MAX_CRTS_IN_SE)
  ------------------
  |  |   50|  1.00k|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (243:6): [True: 11, False: 993]
  ------------------
  244|  1.00k|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "iasecc_crt_parse() error: too much CRTs in SE");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  245|       |
  246|    993|	memcpy(&se->crts[ii], &crt, sizeof(crt));
  247|    993|	parsed_len = len + 2;
  248|    993|	LOG_FUNC_RETURN(ctx, parsed_len);
  ------------------
  |  |  164|    993|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    993|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    993|	int _ret = r; \
  |  |  |  |  155|    993|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 993]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    993|	} else { \
  |  |  |  |  159|    993|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    993|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    993|	} \
  |  |  |  |  162|    993|	return _ret; \
  |  |  |  |  163|    993|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  249|    993|}
iasecc-sdo.c:iasecc_parse_size:
  388|  1.75k|{
  389|  1.75k|	if (data_len > 0 && *data < 0x80) {
  ------------------
  |  Branch (389:6): [True: 1.74k, False: 10]
  |  Branch (389:22): [True: 1.55k, False: 193]
  ------------------
  390|  1.55k|		*out = *data;
  391|  1.55k|		return 1;
  392|  1.55k|	}
  393|    203|	else if (data_len > 1 && *data == 0x81) {
  ------------------
  |  Branch (393:11): [True: 188, False: 15]
  |  Branch (393:27): [True: 103, False: 85]
  ------------------
  394|    103|		*out = *(data + 1);
  395|    103|		return 2;
  396|    103|	}
  397|    100|	else if (data_len > 2 && *data == 0x82) {
  ------------------
  |  Branch (397:11): [True: 83, False: 17]
  |  Branch (397:27): [True: 52, False: 31]
  ------------------
  398|     52|		*out = *(data + 1) * 0x100 + *(data + 2);
  399|     52|		return 3;
  400|     52|	}
  401|       |
  402|     48|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     48|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  403|  1.75k|}
iasecc-sdo.c:iasecc_sdo_parse_data:
  667|    446|{
  668|    446|	struct sc_context *ctx = card->ctx;
  669|    446|	struct iasecc_extended_tlv tlv;
  670|    446|	int tlv_size, rv;
  671|       |
  672|    446|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    446|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    446|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    446|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    446|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 446]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  673|    446|	sc_log(ctx, "iasecc_sdo_parse_data() class %X; ref %X", sdo->sdo_class, sdo->sdo_ref);
  ------------------
  |  |   71|    446|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  674|       |
  675|    446|	tlv_size = iasecc_parse_get_tlv(card, data, data_len, &tlv);
  676|    446|	LOG_TEST_RET(ctx, tlv_size, "parse error: get TLV");
  ------------------
  |  |  174|    446|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    446|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    446|	int _ret = (r); \
  |  |  |  |  168|    446|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 430]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 430]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|       |
  678|    430|	sc_log(ctx, "iasecc_sdo_parse_data() tlv.tag 0x%X", tlv.tag);
  ------------------
  |  |   71|    430|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  679|    430|	if (tlv.tag == IASECC_DOCP_TAG)   {
  ------------------
  |  |   31|    430|#define IASECC_DOCP_TAG				0xA0
  ------------------
  |  Branch (679:6): [True: 158, False: 272]
  ------------------
  680|    158|		sc_log(ctx, "iasecc_sdo_parse_data() parse IASECC_DOCP_TAG: 0x%X; size %zu",
  ------------------
  |  |   71|    158|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  681|    158|				tlv.tag, tlv.size);
  682|    158|		rv = iasecc_parse_docp(card, tlv.value, tlv.size, sdo);
  683|    158|		sc_log(ctx, "iasecc_sdo_parse_data() parsed IASECC_DOCP_TAG rv %i", rv);
  ------------------
  |  |   71|    158|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  684|    158|		free(tlv.value);
  685|    158|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse DOCP");
  ------------------
  |  |  174|    158|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    158|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    158|	int _ret = (r); \
  |  |  |  |  168|    158|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 72, False: 86]
  |  |  |  |  ------------------
  |  |  |  |  169|     72|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     72|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     72|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     72|		return _ret; \
  |  |  |  |  172|     72|	} \
  |  |  |  |  173|    158|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 86]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  686|    158|	}
  687|    272|	else if (tlv.tag == IASECC_DOCP_TAG_NON_REPUDIATION)   {
  ------------------
  |  |   37|    272|#define IASECC_DOCP_TAG_NON_REPUDIATION 		0x9E
  ------------------
  |  Branch (687:11): [True: 28, False: 244]
  ------------------
  688|     28|		free(sdo->docp.non_repudiation.value);
  689|     28|		sdo->docp.non_repudiation = tlv;
  690|     28|	}
  691|    244|	else if (tlv.tag == IASECC_DOCP_TAG_USAGE_REMAINING)   {
  ------------------
  |  |   36|    244|#define IASECC_DOCP_TAG_USAGE_REMAINING		0x9D
  ------------------
  |  Branch (691:11): [True: 45, False: 199]
  ------------------
  692|     45|		free(sdo->docp.usage_remaining.value);
  693|     45|		sdo->docp.usage_remaining = tlv;
  694|     45|	}
  695|    199|	else if (tlv.tag == IASECC_DOCP_TAG_TRIES_MAXIMUM)   {
  ------------------
  |  |   33|    199|#define IASECC_DOCP_TAG_TRIES_MAXIMUM		0x9A
  ------------------
  |  Branch (695:11): [True: 43, False: 156]
  ------------------
  696|     43|		free(sdo->docp.tries_maximum.value);
  697|     43|		sdo->docp.tries_maximum = tlv;
  698|     43|	}
  699|    156|	else if (tlv.tag == IASECC_DOCP_TAG_TRIES_REMAINING)   {
  ------------------
  |  |   34|    156|#define IASECC_DOCP_TAG_TRIES_REMAINING		0x9B
  ------------------
  |  Branch (699:11): [True: 71, False: 85]
  ------------------
  700|     71|		free(sdo->docp.tries_remaining.value);
  701|     71|		sdo->docp.tries_remaining = tlv;
  702|     71|	}
  703|     85|	else if (tlv.tag == IASECC_SDO_CHV_TAG)   {
  ------------------
  |  |   63|     85|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (703:11): [True: 37, False: 48]
  ------------------
  704|     37|		if (sdo->sdo_class != IASECC_SDO_CLASS_CHV) {
  ------------------
  |  |   98|     37|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (704:7): [True: 1, False: 36]
  ------------------
  705|      1|			free(tlv.value);
  706|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: IASECC_SDO_CHV_TAG tag in non User CHV SDO");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  707|      1|		}
  708|       |
  709|     36|		rv = iasecc_parse_chv(card, tlv.value, tlv.size, &sdo->data.chv);
  710|     36|		free(tlv.value);
  711|     36|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse SDO CHV data");
  ------------------
  |  |  174|     36|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     36|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     36|	int _ret = (r); \
  |  |  |  |  168|     36|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     33|		return _ret; \
  |  |  |  |  172|     33|	} \
  |  |  |  |  173|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|     36|	}
  713|     48|	else if (tlv.tag == IASECC_SDO_PUBKEY_TAG)   {
  ------------------
  |  |   76|     48|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
  |  Branch (713:11): [True: 1, False: 47]
  ------------------
  714|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_RSA_PUBLIC) {
  ------------------
  |  |  101|      1|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (714:7): [True: 1, False: 0]
  ------------------
  715|      1|			free(tlv.value);
  716|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: SDO_PUBLIC_KEY tag in non PUBLIC_KEY SDO");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  717|      1|		}
  718|       |
  719|      0|		rv = iasecc_parse_pubkey(card, tlv.value, tlv.size, &sdo->data.pub_key);
  720|      0|		free(tlv.value);
  721|      0|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse SDO PUBLIC KEY data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  722|      0|	}
  723|     47|	else if (tlv.tag == IASECC_SDO_PRVKEY_TAG)   {
  ------------------
  |  |   68|     47|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (723:11): [True: 1, False: 46]
  ------------------
  724|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_RSA_PRIVATE) {
  ------------------
  |  |  100|      1|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (724:7): [True: 1, False: 0]
  ------------------
  725|      1|			free(tlv.value);
  726|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: SDO_PRIVATE_KEY tag in non PRIVATE_KEY SDO");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|      1|		}
  728|       |
  729|      0|		rv = iasecc_parse_prvkey(card, tlv.value, tlv.size, &sdo->data.prv_key);
  730|      0|		free(tlv.value);
  731|      0|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse SDO PRIVATE KEY data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  732|      0|	}
  733|     46|	else if (tlv.tag == IASECC_SDO_KEYSET_TAG)   {
  ------------------
  |  |   83|     46|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
  |  Branch (733:11): [True: 1, False: 45]
  ------------------
  734|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_KEYSET) {
  ------------------
  |  |   99|      1|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (734:7): [True: 1, False: 0]
  ------------------
  735|      1|			free(tlv.value);
  736|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: SDO_KEYSET tag in non KEYSET SDO");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|      1|		}
  738|       |
  739|      0|		rv = iasecc_parse_keyset(card, tlv.value, tlv.size, &sdo->data.keyset);
  740|      0|		free(tlv.value);
  741|      0|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse SDO KEYSET data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|      0|	}
  743|     45|	else   {
  744|     45|		sc_log(ctx, "iasecc_sdo_parse_data() non supported tag 0x%X", tlv.tag);
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  745|     45|		free(tlv.value);
  746|     45|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|     45|	}
  748|       |
  749|    276|	return tlv_size;
  750|    430|}
iasecc-sdo.c:iasecc_parse_get_tlv:
  408|  1.36k|{
  409|  1.36k|	struct sc_context *ctx = card->ctx;
  410|  1.36k|	int size_len, tag_len;
  411|       |
  412|  1.36k|	memset(tlv, 0, sizeof(*tlv));
  413|  1.36k|	sc_log(ctx, "iasecc_parse_get_tlv() called for tag 0x%X", *data);
  ------------------
  |  |   71|  1.36k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  414|  1.36k|	if (data_len < 1)
  ------------------
  |  Branch (414:6): [True: 0, False: 1.36k]
  ------------------
  415|  1.36k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|  1.36k|	if ((*data == 0x7F) || (*data == 0x5F))   {
  ------------------
  |  Branch (416:6): [True: 72, False: 1.29k]
  |  Branch (416:25): [True: 3, False: 1.28k]
  ------------------
  417|     75|		if (data_len < 2)
  ------------------
  |  Branch (417:7): [True: 1, False: 74]
  ------------------
  418|     75|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  419|     74|		tlv->tag = *data * 0x100 + *(data + 1);
  420|     74|		tag_len = 2;
  421|     74|	}
  422|  1.28k|	else   {
  423|  1.28k|		tlv->tag = *data;
  424|  1.28k|		tag_len = 1;
  425|  1.28k|	}
  426|       |
  427|  1.36k|	sc_log(ctx, "iasecc_parse_get_tlv() tlv->tag 0x%X", tlv->tag);
  ------------------
  |  |   71|  1.36k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  428|  1.36k|	size_len = iasecc_parse_size(data + tag_len, data_len - tag_len, &tlv->size);
  429|  1.36k|	LOG_TEST_RET(ctx, size_len, "parse error: invalid size data");
  ------------------
  |  |  174|  1.36k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.36k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.36k|	int _ret = (r); \
  |  |  |  |  168|  1.36k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 1.34k]
  |  |  |  |  ------------------
  |  |  |  |  169|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     21|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     21|		return _ret; \
  |  |  |  |  172|     21|	} \
  |  |  |  |  173|  1.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.34k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  430|  1.34k|	if (tag_len + size_len + tlv->size > data_len) {
  ------------------
  |  Branch (430:6): [True: 32, False: 1.30k]
  ------------------
  431|     32|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|     32|	}
  433|       |
  434|  1.30k|	tlv->value = calloc(1, tlv->size);
  435|  1.30k|	if (!tlv->value)
  ------------------
  |  Branch (435:6): [True: 0, False: 1.30k]
  ------------------
  436|  1.30k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|  1.30k|	memcpy(tlv->value, data + size_len + tag_len, tlv->size);
  438|       |
  439|  1.30k|	tlv->on_card = 1;
  440|       |
  441|  1.30k|	sc_log(ctx, "iasecc_parse_get_tlv() parsed %zu bytes", tag_len + size_len + tlv->size);
  ------------------
  |  |   71|  1.30k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  442|  1.30k|	return (int)(tag_len + size_len + tlv->size);
  443|  1.30k|}
iasecc-sdo.c:iasecc_parse_docp:
  594|    257|{
  595|    257|	struct sc_context *ctx = card->ctx;
  596|    257|	size_t offs = 0;
  597|    257|	int rv;
  598|       |
  599|    257|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  600|    737|	while(offs < data_len)   {
  ------------------
  |  Branch (600:8): [True: 556, False: 181]
  ------------------
  601|    556|		struct iasecc_extended_tlv tlv;
  602|       |
  603|    556|		rv = iasecc_parse_get_tlv(card, data + offs, data_len - offs, &tlv);
  604|    556|		LOG_TEST_RET(ctx, rv, "iasecc_parse_get_tlv() get and parse TLV error");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 535]
  |  |  |  |  ------------------
  |  |  |  |  169|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     21|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     21|		return _ret; \
  |  |  |  |  172|     21|	} \
  |  |  |  |  173|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 535]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  605|       |
  606|    535|		sc_log(ctx, "iasecc_parse_docp() parse_get_tlv returned %i; tag %X; size %zu",
  ------------------
  |  |   71|    535|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  607|    535|				rv, tlv.tag, tlv.size);
  608|       |
  609|    535|		if (tlv.tag == IASECC_DOCP_TAG_ACLS)   {
  ------------------
  |  |   39|    535|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
  |  Branch (609:7): [True: 99, False: 436]
  ------------------
  610|     99|			int _rv = iasecc_parse_docp(card, tlv.value, tlv.size, sdo);
  611|     99|			free(tlv.value);
  612|     99|			LOG_TEST_RET(ctx, _rv, "parse error: cannot parse DOCP");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 85]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     99|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 85]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  613|     99|		}
  614|    436|		else if (tlv.tag == IASECC_DOCP_TAG_ACLS_CONTACT)   {
  ------------------
  |  |   40|    436|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
  |  Branch (614:12): [True: 127, False: 309]
  ------------------
  615|    127|			free(sdo->docp.acls_contact.value);
  616|    127|			sdo->docp.acls_contact = tlv;
  617|    127|		}
  618|    309|		else if (tlv.tag == IASECC_DOCP_TAG_ACLS_CONTACTLESS)   {
  ------------------
  |  |   41|    309|#define IASECC_DOCP_TAG_ACLS_CONTACTLESS	0x9C
  ------------------
  |  Branch (618:12): [True: 21, False: 288]
  ------------------
  619|     21|			free(sdo->docp.acls_contactless.value);
  620|     21|			sdo->docp.acls_contactless = tlv;
  621|     21|		}
  622|    288|		else if (tlv.tag == IASECC_DOCP_TAG_SIZE)   {
  ------------------
  |  |   38|    288|#define IASECC_DOCP_TAG_SIZE			0x80
  ------------------
  |  Branch (622:12): [True: 41, False: 247]
  ------------------
  623|     41|			free(sdo->docp.size.value);
  624|     41|			sdo->docp.size = tlv;
  625|     41|		}
  626|    247|		else if (tlv.tag == IASECC_DOCP_TAG_NAME)   {
  ------------------
  |  |   32|    247|#define IASECC_DOCP_TAG_NAME			0x84
  ------------------
  |  Branch (626:12): [True: 48, False: 199]
  ------------------
  627|     48|			free(sdo->docp.name.value);
  628|     48|			sdo->docp.name = tlv;
  629|     48|		}
  630|    199|		else if (tlv.tag == IASECC_DOCP_TAG_ISSUER_DATA)   {
  ------------------
  |  |   43|    199|#define IASECC_DOCP_TAG_ISSUER_DATA		0x85
  ------------------
  |  Branch (630:12): [True: 43, False: 156]
  ------------------
  631|     43|			free(sdo->docp.issuer_data.value);
  632|     43|			sdo->docp.issuer_data = tlv;
  633|     43|		}
  634|    156|		else if (tlv.tag == IASECC_DOCP_TAG_NON_REPUDIATION)   {
  ------------------
  |  |   37|    156|#define IASECC_DOCP_TAG_NON_REPUDIATION 		0x9E
  ------------------
  |  Branch (634:12): [True: 13, False: 143]
  ------------------
  635|     13|			free(sdo->docp.non_repudiation.value);
  636|     13|			sdo->docp.non_repudiation = tlv;
  637|     13|		}
  638|    143|		else if (tlv.tag == IASECC_DOCP_TAG_USAGE_REMAINING)   {
  ------------------
  |  |   36|    143|#define IASECC_DOCP_TAG_USAGE_REMAINING		0x9D
  ------------------
  |  Branch (638:12): [True: 35, False: 108]
  ------------------
  639|     35|			free(sdo->docp.usage_remaining.value);
  640|     35|			sdo->docp.usage_remaining = tlv;
  641|     35|		}
  642|    108|		else if (tlv.tag == IASECC_DOCP_TAG_TRIES_MAXIMUM)   {
  ------------------
  |  |   33|    108|#define IASECC_DOCP_TAG_TRIES_MAXIMUM		0x9A
  ------------------
  |  Branch (642:12): [True: 35, False: 73]
  ------------------
  643|     35|			free(sdo->docp.tries_maximum.value);
  644|     35|			sdo->docp.tries_maximum = tlv;
  645|     35|		}
  646|     73|		else if (tlv.tag == IASECC_DOCP_TAG_TRIES_REMAINING)   {
  ------------------
  |  |   34|     73|#define IASECC_DOCP_TAG_TRIES_REMAINING		0x9B
  ------------------
  |  Branch (646:12): [True: 32, False: 41]
  ------------------
  647|     32|			free(sdo->docp.tries_remaining.value);
  648|     32|			sdo->docp.tries_remaining = tlv;
  649|     32|		}
  650|     41|		else   {
  651|     41|			free(tlv.value);
  652|     41|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "iasecc_parse_get_tlv() parse error: non DOCP tag");
  ------------------
  |  |  174|     41|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     41|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     41|	int _ret = (r); \
  |  |  |  |  168|     41|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     41|		return _ret; \
  |  |  |  |  172|     41|	} \
  |  |  |  |  173|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  653|     41|		}
  654|       |
  655|    480|		offs += rv;
  656|    480|	}
  657|       |
  658|    181|	rv = iasecc_parse_acls(card, &sdo->docp, 0);
  659|    181|	LOG_TEST_RET(ctx, rv, "Cannot parse ACLs in DOCP");
  ------------------
  |  |  174|    181|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    181|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    181|	int _ret = (r); \
  |  |  |  |  168|    181|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 171]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  660|       |
  661|    171|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    171|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    171|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    171|	int _ret = r; \
  |  |  |  |  155|    171|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 171, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    171|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  157|    171|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    171|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    171|	return _ret; \
  |  |  |  |  163|    171|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  662|    171|}
iasecc-sdo.c:iasecc_parse_chv:
  448|     36|{
  449|     36|	struct sc_context *ctx = card->ctx;
  450|     36|	size_t offs = 0;
  451|     36|	int rv;
  452|       |
  453|     36|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     36|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     36|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     36|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     36|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  454|    364|	while(offs < data_len)   {
  ------------------
  |  Branch (454:8): [True: 361, False: 3]
  ------------------
  455|    361|		struct iasecc_extended_tlv tlv;
  456|       |
  457|    361|		rv = iasecc_parse_get_tlv(card, data + offs, data_len - offs, &tlv);
  458|    361|		LOG_TEST_RET(ctx, rv, "iasecc_parse_chv() get and parse TLV error");
  ------------------
  |  |  174|    361|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    361|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    361|	int _ret = (r); \
  |  |  |  |  168|    361|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 344]
  |  |  |  |  ------------------
  |  |  |  |  169|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     17|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     17|		return _ret; \
  |  |  |  |  172|     17|	} \
  |  |  |  |  173|    361|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 344]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|       |
  460|    344|		sc_log(ctx, "iasecc_parse_chv() get and parse TLV returned %i; tag %X; size %zu",
  ------------------
  |  |   71|    344|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  461|    344|				rv, tlv.tag, tlv.size);
  462|       |
  463|    344|		if (tlv.tag == IASECC_SDO_CHV_TAG_SIZE_MAX) {
  ------------------
  |  |   64|    344|#define IASECC_SDO_CHV_TAG_SIZE_MAX	0x80
  ------------------
  |  Branch (463:7): [True: 42, False: 302]
  ------------------
  464|     42|			free(chv->size_max.value);
  465|     42|			chv->size_max = tlv;
  466|    302|		} else if (tlv.tag == IASECC_SDO_CHV_TAG_SIZE_MIN) {
  ------------------
  |  |   65|    302|#define IASECC_SDO_CHV_TAG_SIZE_MIN	0x81
  ------------------
  |  Branch (466:14): [True: 209, False: 93]
  ------------------
  467|    209|			free(chv->size_min.value);
  468|    209|			chv->size_min = tlv;
  469|    209|		} else if (tlv.tag == IASECC_SDO_CHV_TAG_VALUE) {
  ------------------
  |  |   66|     93|#define IASECC_SDO_CHV_TAG_VALUE	0x82
  ------------------
  |  Branch (469:14): [True: 77, False: 16]
  ------------------
  470|     77|			free(chv->value.value);
  471|     77|			chv->value = tlv;
  472|     77|		} else {
  473|     16|			free(tlv.value);
  474|     16|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "parse error: non CHV SDO tag");
  ------------------
  |  |  174|     16|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     16|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     16|	int _ret = (r); \
  |  |  |  |  168|     16|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|     16|		}
  476|       |
  477|    328|		offs += rv;
  478|    328|	}
  479|       |
  480|      3|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|      3|}
iasecc-sdo.c:iasecc_tlv_copy:
 1304|    288|{
 1305|    288|	if (!in || !out)
  ------------------
  |  Branch (1305:6): [True: 0, False: 288]
  |  Branch (1305:13): [True: 0, False: 288]
  ------------------
 1306|    288|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1307|       |
 1308|    288|	memset(out, 0, sizeof(struct iasecc_extended_tlv));
 1309|    288|	out->tag = in->tag;
 1310|    288|	out->parent_tag = in->parent_tag;
 1311|    288|	out->on_card = in->on_card;
 1312|    288|	if (in->value && in->size)   {
  ------------------
  |  Branch (1312:6): [True: 0, False: 288]
  |  Branch (1312:19): [True: 0, False: 0]
  ------------------
 1313|      0|		out->value = calloc(1, in->size);
 1314|      0|		if (!out->value)
  ------------------
  |  Branch (1314:7): [True: 0, False: 0]
  ------------------
 1315|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1316|       |
 1317|      0|		memcpy(out->value, in->value, in->size);
 1318|      0|		out->size = in->size;
 1319|      0|	}
 1320|       |
 1321|    288|	return SC_SUCCESS;
  ------------------
  |  |   28|    288|#define SC_SUCCESS				0
  ------------------
 1322|    288|}

iasecc_sm_initialize:
  270|    255|{
  271|    255|	struct sc_context *ctx = card->ctx;
  272|    255|#ifdef ENABLE_SM
  273|    255|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    255|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    255|	struct sc_remote_data rdata;
  276|    255|	int rv;
  277|       |
  278|    255|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    255|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    255|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    255|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    255|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    255|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    255|#define strlcpy _strlcpy
  ------------------
  281|    255|	sm_info->cmd = cmd;
  282|    255|	sm_info->serialnr = card->serialnr;
  283|    255|	sm_info->card_type = card->type;
  284|    255|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    255|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    255|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    255|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 255, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    255|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    255|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    255|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    255|		return _ret; \
  |  |  |  |  172|    255|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|       |
  289|      0|	rv = sc_get_challenge(card, cwa_session->card_challenge, SM_SMALL_CHALLENGE_LEN);
  ------------------
  |  |   85|      0|#define SM_SMALL_CHALLENGE_LEN	8
  ------------------
  290|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() GET CHALLENGE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|      0|	sc_remote_data_init(&rdata);
  293|       |
  294|      0|	rv = sm_save_sc_context(card, sm_info);
  295|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() cannot save current context");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|       |
  297|      0|	if (!card->sm_ctx.module.ops.initialize)
  ------------------
  |  Branch (297:6): [True: 0, False: 0]
  ------------------
  298|      0|		LOG_TEST_RET(ctx, SC_ERROR_SM_NOT_INITIALIZED, "iasecc_sm_initialize() no SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      0|	rv = card->sm_ctx.module.ops.initialize(ctx, sm_info, &rdata);
  300|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() INITIALIZE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|       |
  302|       |
  303|      0|	if (rdata.length == 1)   {
  ------------------
  |  Branch (303:6): [True: 0, False: 0]
  ------------------
  304|      0|		rdata.data->flags |= SC_REMOTE_APDU_FLAG_RETURN_ANSWER;
  ------------------
  |  |  386|      0|#define SC_REMOTE_APDU_FLAG_RETURN_ANSWER	0x02
  ------------------
  305|      0|		rdata.data->apdu.flags &= ~SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|      0|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  306|      0|	}
  307|      0|	else   {
  308|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "TODO: SM init with more then one APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|      0|	}
  310|       |
  311|      0|	cwa_session->mdata_len = sizeof(cwa_session->mdata);
  312|      0|	rv = iasecc_sm_transmit_apdus (card, &rdata, cwa_session->mdata, &cwa_session->mdata_len);
  313|      0|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (313:6): [True: 0, False: 0]
  ------------------
  314|      0|		sc_log(ctx, "SM initialization failed, %i tries left", (rdata.data + rdata.length - 1)->apdu.sw2 & 0x0F);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() transmit APDUs failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|       |
  317|      0|	rdata.free(&rdata);
  318|       |
  319|      0|	sc_log(ctx, "MA data(len:%zu) '%s'", cwa_session->mdata_len,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|      0|			sc_dump_hex(cwa_session->mdata, cwa_session->mdata_len));
  321|      0|	if (cwa_session->mdata_len != 0x48)
  ------------------
  |  Branch (321:6): [True: 0, False: 0]
  ------------------
  322|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "iasecc_sm_initialize() invalid MUTUAL AUTHENTICATE result data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|       |#else
  326|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  327|       |	return SC_ERROR_NOT_SUPPORTED;
  328|       |#endif
  329|      0|}
iasecc_sm_read_binary:
  586|    255|{
  587|    255|	struct sc_context *ctx = card->ctx;
  588|    255|#ifdef ENABLE_SM
  589|    255|	struct sm_info *sm_info = &card->sm_ctx.info;
  590|    255|	struct sc_remote_data rdata;
  591|    255|	struct iasecc_sm_cmd_update_binary cmd_data;
  592|    255|	int rv;
  593|       |
  594|    255|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    255|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    255|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    255|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    255|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  595|    255|	sc_log(ctx, "SM read binary: acl:%X, offs:%zu, count:%zu", se_num, offs, count);
  ------------------
  |  |   71|    255|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  596|       |
  597|    255|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    255|#define SM_CMD_FILE_READ		0x201
  ------------------
  598|    255|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 255, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    255|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    255|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    255|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    255|		return _ret; \
  |  |  |  |  172|    255|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  599|       |
  600|      0|	cmd_data.offs = offs;
  601|      0|	cmd_data.count = count;
  602|      0|	sm_info->cmd_data = &cmd_data;
  603|       |
  604|      0|	sc_remote_data_init(&rdata);
  605|      0|	rv = iasecc_sm_cmd(card, &rdata);
  606|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM 'READ BINARY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  607|       |
  608|      0|	sc_log(ctx, "IAS/ECC decode answer() rdata length %i", rdata.length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  609|       |
  610|      0|	rv = sm_release (card, &rdata, buff, count);
  611|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM release failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|      0|	rdata.free(&rdata);
  614|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|       |#else
  616|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  617|       |	return SC_ERROR_NOT_SUPPORTED;
  618|       |#endif
  619|      0|}
iasecc-sm.c:iasecc_sm_se_mutual_authentication:
  222|    255|{
  223|    255|	struct sc_context *ctx = card->ctx;
  224|    255|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    255|	struct iasecc_se_info se;
  226|    255|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    255|	struct sc_apdu apdu;
  228|    255|	unsigned char sbuf[0x100];
  229|    255|	int rv, offs;
  230|       |
  231|    255|	memset(&se, 0, sizeof(se));
  232|       |
  233|    255|	se.reference = se_num;
  234|    255|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    255|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    255|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    255|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    255|	rv = iasecc_se_get_info(card, &se);
  238|    255|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 223, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|    223|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    223|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    223|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    223|		return _ret; \
  |  |  |  |  172|    223|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|     32|	rv = iasecc_se_get_crt(card, &se, crt);
  241|     32|	sc_file_free(se.df);
  242|     32|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|       |
  244|       |	/* MSE SET Mutual Authentication SK scheme */
  245|      0|	offs = 0;
  246|      0|	sbuf[offs++] = IASECC_CRT_TAG_ALGO;
  ------------------
  |  |  113|      0|#define IASECC_CRT_TAG_ALGO		0x80
  ------------------
  247|      0|	sbuf[offs++] = 0x01;
  248|      0|	sbuf[offs++] = crt->algo;
  249|      0|	sbuf[offs++] = IASECC_CRT_TAG_REFERENCE;
  ------------------
  |  |  112|      0|#define IASECC_CRT_TAG_REFERENCE	0x83
  ------------------
  250|      0|	sbuf[offs++] = 0x01;
  251|      0|	sbuf[offs++] = crt->refs[0];
  252|       |
  253|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xC1, 0xA4);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  254|      0|	apdu.data = sbuf;
  255|      0|	apdu.datalen = offs;
  256|      0|	apdu.lc = offs;
  257|       |
  258|      0|	rv = sc_transmit_apdu(card, &apdu);
  259|      0|	LOG_TEST_RET(ctx, rv, "SM set SE mutual auth.: APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|      0|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|      0|	LOG_TEST_RET(ctx, rv, "SM set SE mutual auth.: set SE error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  264|      0|}

iso7816_fixup_transceive_length:
   35|  33.2k|{
   36|  33.2k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (36:6): [True: 0, False: 33.2k]
  |  Branch (36:22): [True: 0, False: 33.2k]
  ------------------
   37|      0|		return;
   38|      0|	}
   39|       |
   40|  33.2k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (40:6): [True: 336, False: 32.9k]
  ------------------
   41|       |		/* The lower layers will automatically do chaining */
   42|    336|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    336|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   43|    336|	}
   44|       |
   45|  33.2k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (45:6): [True: 2.57k, False: 30.7k]
  ------------------
   46|       |		/* The lower layers will automatically do a GET RESPONSE, if possible.
   47|       |		 * All other workarounds must be carried out by the upper layers. */
   48|  2.57k|		apdu->le = sc_get_max_recv_size(card);
   49|  2.57k|	}
   50|  33.2k|}
encode_do_data:
  176|  6.69k|{
  177|  6.69k|	unsigned char offset_buffer[2];
  178|  6.69k|	size_t offset_buffer_len = sizeof offset_buffer;
  179|  6.69k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  180|  6.69k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  181|       |
  182|  6.69k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (182:6): [True: 0, False: 6.69k]
  ------------------
  183|  6.69k|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "Offset beyond 0xFFFF not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|  6.69k|	offset_buffer[0] = (u8) (idx >> 8);
  185|  6.69k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  186|  6.69k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  187|       |
  188|  6.69k|	if (data && data_len) {
  ------------------
  |  Branch (188:6): [True: 0, False: 6.69k]
  |  Branch (188:14): [True: 0, False: 0]
  ------------------
  189|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  190|  6.69k|	} else {
  191|  6.69k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  192|  6.69k|	}
  193|       |
  194|  6.69k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  6.69k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.69k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.69k|	int _ret = (r); \
  |  |  |  |  168|  6.69k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 6.69k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  6.69k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.69k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|  6.69k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  196|  6.69k|			"sc_asn1_encode() failed");
  197|       |
  198|  6.69k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.69k|#define SC_SUCCESS				0
  ------------------
  199|  6.69k|}
decode_do_data:
  204|  4.87k|{
  205|  4.87k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  206|  4.87k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  207|       |
  208|  4.87k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  209|  4.87k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  210|       |
  211|  4.87k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  4.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.87k|	int _ret = (r); \
  |  |  |  |  168|  4.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 213, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |  169|    213|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    213|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    213|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    213|		return _ret; \
  |  |  |  |  172|    213|	} \
  |  |  |  |  173|  4.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.66k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  212|  4.66k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  213|  4.66k|			"sc_asn1_decode() failed");
  214|       |
  215|  4.66k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  4.66k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (215:6): [True: 3.55k, False: 1.11k]
  ------------------
  216|  3.55k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  3.55k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  217|       |
  218|  1.11k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.11k|#define SC_SUCCESS				0
  ------------------
  219|  4.66k|}
iso7816_build_pin_apdu:
 1196|    861|{
 1197|    861|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1198|    861|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|    861|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1199|       |
 1200|    861|	switch (data->pin_type) {
 1201|    785|	case SC_AC_CHV:
  ------------------
  |  |  151|    785|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1201:2): [True: 785, False: 76]
  ------------------
 1202|       |		/* fall through */
 1203|    787|	case SC_AC_SESSION:
  ------------------
  |  |  159|    787|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1203:2): [True: 2, False: 859]
  ------------------
 1204|    800|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|    800|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1204:2): [True: 13, False: 848]
  ------------------
 1205|    800|		break;
 1206|     61|	default:
  ------------------
  |  Branch (1206:2): [True: 61, False: 800]
  ------------------
 1207|     61|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     61|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1208|    861|	}
 1209|       |
 1210|    800|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|    800|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1210:6): [True: 186, False: 614]
  ------------------
 1211|    186|		pad = 1;
 1212|    800|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|    800|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1212:6): [True: 0, False: 800]
  ------------------
 1213|      0|		use_pin_pad = 1;
 1214|       |
 1215|    800|	data->pin1.offset = 5;
 1216|       |
 1217|    800|	switch (data->cmd) {
 1218|    216|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|    216|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1218:2): [True: 216, False: 584]
  ------------------
 1219|    216|		ins = 0x20;
 1220|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1221|    216|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1221:7): [True: 0, False: 216]
  |  Branch (1221:30): [True: 0, False: 0]
  ------------------
 1222|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1223|    216|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1223:7): [True: 13, False: 203]
  ------------------
 1224|     13|			return r;
 1225|    203|		len = r;
 1226|    203|		break;
 1227|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1227:2): [True: 0, False: 800]
  ------------------
 1228|      0|		ins = 0x24;
 1229|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1229:7): [True: 0, False: 0]
  |  Branch (1229:31): [True: 0, False: 0]
  |  Branch (1229:46): [True: 0, False: 0]
  ------------------
 1230|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1230:8): [True: 0, False: 0]
  ------------------
 1231|      0|				return r;
 1232|      0|			len += r;
 1233|      0|		}
 1234|      0|		else {
 1235|       |			/* implicit test */
 1236|      0|			p1 = 1;
 1237|      0|		}
 1238|       |
 1239|      0|		data->pin2.offset = data->pin1.offset + len;
 1240|      0|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1240:7): [True: 0, False: 0]
  ------------------
 1241|      0|			return r;
 1242|       |		/* Special case - where provided the old PIN on the command line
 1243|       |		 * but expect the new one to be entered on the keypad.
 1244|       |		 */
 1245|      0|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1245:7): [True: 0, False: 0]
  |  Branch (1245:25): [True: 0, False: 0]
  ------------------
 1246|      0|			sc_log(card->ctx, "Special case - initial pin provided - but new pin asked on keypad");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1247|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1248|      0|		};
 1249|      0|		len += r;
 1250|      0|		break;
 1251|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1251:2): [True: 0, False: 800]
  ------------------
 1252|      0|		ins = 0x2C;
 1253|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1253:7): [True: 0, False: 0]
  |  Branch (1253:31): [True: 0, False: 0]
  |  Branch (1253:46): [True: 0, False: 0]
  ------------------
 1254|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1254:8): [True: 0, False: 0]
  ------------------
 1255|      0|				return r;
 1256|      0|			len += r;
 1257|      0|		} else {
 1258|      0|			p1 |= 0x02;
 1259|      0|		}
 1260|       |
 1261|      0|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1261:7): [True: 0, False: 0]
  |  Branch (1261:30): [True: 0, False: 0]
  ------------------
 1262|      0|			data->pin2.offset = data->pin1.offset + len;
 1263|      0|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1263:8): [True: 0, False: 0]
  ------------------
 1264|      0|				return r;
 1265|      0|			len += r;
 1266|      0|		} else {
 1267|      0|			p1 |= 0x01;
 1268|      0|		}
 1269|      0|		if (p1 == 0x03) {
  ------------------
  |  Branch (1269:7): [True: 0, False: 0]
  ------------------
 1270|       |			/* No data to send or to receive */
 1271|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1272|      0|		}
 1273|      0|		break;
 1274|    584|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    584|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1274:2): [True: 584, False: 216]
  ------------------
 1275|    584|		ins = 0x20;
 1276|       |		/* No data to send or to receive */
 1277|    584|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|    584|#define SC_APDU_CASE_1			0x01
  ------------------
 1278|    584|		break;
 1279|      0|	default:
  ------------------
  |  Branch (1279:2): [True: 0, False: 800]
  ------------------
 1280|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1281|    800|	}
 1282|       |
 1283|    787|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1284|    787|	apdu->lc = len;
 1285|    787|	apdu->datalen = len;
 1286|    787|	apdu->data = buf;
 1287|    787|	apdu->resplen = 0;
 1288|       |
 1289|    787|	return 0;
 1290|    800|}
iso7816_select_aid:
 1408|  13.9k|{
 1409|  13.9k|	struct sc_context *ctx = card->ctx;
 1410|  13.9k|	struct sc_apdu apdu;
 1411|  13.9k|	int rv;
 1412|       |
 1413|  13.9k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  13.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  13.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  13.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 13.9k]
  |  |  ------------------
  ------------------
 1414|       |
 1415|  13.9k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  6.56k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  294|  7.34k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1415:30): [True: 6.56k, False: 7.34k]
  |  Branch (1415:102): [True: 6.56k, False: 7.34k]
  ------------------
 1416|  13.9k|	apdu.lc = reqlen;
 1417|  13.9k|	apdu.data = req;
 1418|  13.9k|	apdu.datalen = reqlen;
 1419|  13.9k|	apdu.resp = resp;
 1420|  13.9k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1420:17): [True: 6.56k, False: 7.34k]
  ------------------
 1421|  13.9k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1421:12): [True: 6.56k, False: 7.34k]
  ------------------
 1422|       |
 1423|  13.9k|	rv = sc_transmit_apdu(card, &apdu);
 1424|  13.9k|	if (resplen)
  ------------------
  |  Branch (1424:6): [True: 7.34k, False: 6.56k]
  ------------------
 1425|  7.34k|		*resplen = apdu.resplen;
 1426|  13.9k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  13.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.9k|	int _ret = (r); \
  |  |  |  |  168|  13.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 118, False: 13.7k]
  |  |  |  |  ------------------
  |  |  |  |  169|    118|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    118|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    118|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    118|		return _ret; \
  |  |  |  |  172|    118|	} \
  |  |  |  |  173|  13.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1427|       |
 1428|  13.7k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1429|  13.7k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  13.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.7k|	int _ret = r; \
  |  |  |  |  155|  13.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.26k, False: 4.52k]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  13.7k|	return _ret; \
  |  |  |  |  163|  13.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|  13.7k|}
sc_get_iso7816_driver:
 1498|   541k|{
 1499|   541k|	return &iso_driver;
 1500|   541k|}
iso7816.c:no_match:
 1444|  7.44k|{
 1445|  7.44k|	return 0;
 1446|  7.44k|}
iso7816.c:iso7816_read_record:
  224|  13.3k|{
  225|  13.3k|	struct sc_apdu apdu;
  226|  13.3k|	int r;
  227|       |	/* XXX maybe use some bigger buffer */
  228|  13.3k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  229|  13.3k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  230|  13.3k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  231|       |
  232|  13.3k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (232:6): [True: 1, False: 13.3k]
  ------------------
  233|  13.3k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|       |
  235|  13.3k|	if (idx == 0) {
  ------------------
  |  Branch (235:6): [True: 6.66k, False: 6.69k]
  ------------------
  236|  6.66k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  6.66k|#define SC_APDU_CASE_2			0x22
  ------------------
  237|  6.66k|		apdu.le = count;
  238|  6.66k|		apdu.resplen = count;
  239|  6.66k|		apdu.resp = buf;
  240|  6.69k|	} else {
  241|  6.69k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  242|  6.69k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  6.69k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.69k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.69k|	int _ret = (r); \
  |  |  |  |  178|  6.69k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 6.69k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  6.69k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 6.69k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|       |
  244|  6.69k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  6.69k|#define SC_APDU_CASE_4			0x24
  ------------------
  245|  6.69k|		apdu.lc = encoded_data_len;
  246|  6.69k|		apdu.datalen = encoded_data_len;
  247|  6.69k|		apdu.data = encoded_data;
  248|  6.69k|		apdu.le = sizeof resp;
  249|  6.69k|		apdu.resplen = sizeof resp;
  250|  6.69k|		apdu.resp = resp;
  251|  6.69k|	}
  252|  13.3k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  13.3k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  253|  13.3k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  13.3k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (253:6): [True: 13.3k, False: 0]
  ------------------
  254|  13.3k|		apdu.p2 |= 0x04;
  255|       |
  256|  13.3k|	iso7816_fixup_transceive_length(card, &apdu);
  257|  13.3k|	r = sc_transmit_apdu(card, &apdu);
  258|  13.3k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  13.3k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.3k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.3k|	int _ret = (r); \
  |  |  |  |  178|  13.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 721, False: 12.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|    721|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    721|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    721|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    721|		goto err; \
  |  |  |  |  182|    721|	} \
  |  |  |  |  183|  13.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 12.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|  12.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  260|  12.6k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  12.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  12.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  12.6k|	int _ret = (r); \
  |  |  |  |  178|  12.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.81k, False: 10.8k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.81k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.81k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.81k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.81k|		goto err; \
  |  |  |  |  182|  1.81k|	} \
  |  |  |  |  183|  12.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  261|       |
  262|  10.8k|	if (idx == 0) {
  ------------------
  |  Branch (262:6): [True: 5.94k, False: 4.87k]
  ------------------
  263|  5.94k|		r = (int)apdu.resplen;
  264|  5.94k|	} else {
  265|  4.87k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  266|  4.87k|				&decoded_data, &decoded_data_len);
  267|  4.87k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  4.87k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.87k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.87k|	int _ret = (r); \
  |  |  |  |  178|  4.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.76k, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.76k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.76k|		goto err; \
  |  |  |  |  182|  3.76k|	} \
  |  |  |  |  183|  4.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.11k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|  1.11k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (268:7): [True: 1.02k, False: 83]
  ------------------
  269|  1.02k|			count = decoded_data_len;
  270|  1.02k|		}
  271|  1.11k|		memcpy(buf, decoded_data, count);
  272|  1.11k|		r = (int)count;
  273|  1.11k|	}
  274|       |
  275|  13.3k|err:
  276|  13.3k|	free(encoded_data);
  277|  13.3k|	free(decoded_data);
  278|  13.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  13.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.3k|	int _ret = r; \
  |  |  |  |  155|  13.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.47k, False: 6.88k]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.30k, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.88k|	} else { \
  |  |  |  |  159|  6.88k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  6.88k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  6.88k|	} \
  |  |  |  |  162|  13.3k|	return _ret; \
  |  |  |  |  163|  13.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|  13.3k|}
iso7816.c:iso7816_select_file:
  642|  47.6k|{
  643|  47.6k|	struct sc_context *ctx;
  644|  47.6k|	struct sc_apdu apdu;
  645|  47.6k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  646|  47.6k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  647|  47.6k|	int r, pathtype;
  648|  47.6k|	size_t pathlen;
  649|  47.6k|	int select_mf = 0;
  650|  47.6k|	struct sc_file *file = NULL;
  651|  47.6k|	const u8 *buffer;
  652|  47.6k|	size_t buffer_len;
  653|  47.6k|	unsigned int cla, tag;
  654|       |
  655|  47.6k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (655:6): [True: 0, False: 47.6k]
  |  Branch (655:22): [True: 0, False: 47.6k]
  ------------------
  656|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  657|      0|	}
  658|  47.6k|	ctx = card->ctx;
  659|  47.6k|	memcpy(path, in_path->value, in_path->len);
  660|  47.6k|	pathlen = in_path->len;
  661|  47.6k|	pathtype = in_path->type;
  662|       |
  663|  47.6k|	if (in_path->aid.len) {
  ------------------
  |  Branch (663:6): [True: 1.81k, False: 45.8k]
  ------------------
  664|  1.81k|		if (!pathlen) {
  ------------------
  |  Branch (664:7): [True: 1.60k, False: 210]
  ------------------
  665|  1.60k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  666|  1.60k|			pathlen = in_path->aid.len;
  667|  1.60k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.60k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  668|  1.60k|		} else {
  669|       |			/* First, select the application */
  670|    210|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    210|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  671|    210|			apdu.data = in_path->aid.value;
  672|    210|			apdu.datalen = in_path->aid.len;
  673|    210|			apdu.lc = in_path->aid.len;
  674|       |
  675|    210|			r = sc_transmit_apdu(card, &apdu);
  676|    210|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    210|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    210|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    210|	int _ret = (r); \
  |  |  |  |  168|    210|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 207]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|    210|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|    207|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  678|    207|			if (r)
  ------------------
  |  Branch (678:8): [True: 199, False: 8]
  ------------------
  679|    207|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    199|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    199|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    199|	int _ret = r; \
  |  |  |  |  155|    199|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 199, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    199|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    199|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 199, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    199|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    199|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    199|	return _ret; \
  |  |  |  |  163|    199|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  680|       |
  681|      8|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|     16|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (681:8): [True: 8, False: 0]
  ------------------
  682|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (682:9): [True: 0, False: 0]
  ------------------
  683|      8|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      8|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  684|      8|		}
  685|  1.81k|	}
  686|       |
  687|  47.4k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  47.4k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  688|       |
  689|  47.4k|	switch (pathtype) {
  690|  9.14k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  9.14k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (690:2): [True: 9.14k, False: 38.3k]
  ------------------
  691|  9.14k|		apdu.p1 = 0;
  692|  9.14k|		if (pathlen != 2)
  ------------------
  |  Branch (692:7): [True: 0, False: 9.14k]
  ------------------
  693|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  694|  9.14k|		break;
  695|  21.3k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  21.3k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (695:2): [True: 21.3k, False: 26.0k]
  ------------------
  696|  21.3k|		apdu.p1 = 4;
  697|  21.3k|		break;
  698|  16.8k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  16.8k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (698:2): [True: 16.8k, False: 30.6k]
  ------------------
  699|  16.8k|		apdu.p1 = 8;
  700|  16.8k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (700:7): [True: 16.7k, False: 45]
  |  Branch (700:23): [True: 12.7k, False: 4.05k]
  ------------------
  701|  12.7k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (701:8): [True: 3.40k, False: 9.31k]
  ------------------
  702|  3.40k|				select_mf = 1;
  703|  3.40k|				apdu.p1 = 0;
  704|  3.40k|				break;
  705|  3.40k|			}
  706|  9.31k|			path += 2;
  707|  9.31k|			pathlen -= 2;
  708|  9.31k|		}
  709|  13.4k|		break;
  710|  13.4k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|      8|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (710:2): [True: 8, False: 47.4k]
  ------------------
  711|      8|		apdu.p1 = 9;
  712|      8|		break;
  713|    102|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    102|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (713:2): [True: 102, False: 47.3k]
  ------------------
  714|    102|		apdu.p1 = 3;
  715|    102|		pathlen = 0;
  716|    102|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    102|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  717|    102|		break;
  718|      0|	default:
  ------------------
  |  Branch (718:2): [True: 0, False: 47.4k]
  ------------------
  719|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  720|  47.4k|	}
  721|  47.4k|	apdu.lc = pathlen;
  722|  47.4k|	apdu.data = path;
  723|  47.4k|	apdu.datalen = pathlen;
  724|       |
  725|  47.4k|	if (file_out != NULL) {
  ------------------
  |  Branch (725:6): [True: 30.5k, False: 16.8k]
  ------------------
  726|  30.5k|		apdu.p2 = 0;		/* first record, return FCI */
  727|  30.5k|		apdu.resp = buf;
  728|  30.5k|		apdu.resplen = sizeof(buf);
  729|  30.5k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (729:13): [True: 1.37k, False: 29.1k]
  ------------------
  730|  30.5k|	}
  731|  16.8k|	else {
  732|  16.8k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  733|  16.8k|		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  33.7k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (733:14): [True: 0, False: 16.8k]
  ------------------
  734|  16.8k|	}
  735|       |
  736|  47.4k|	r = sc_transmit_apdu(card, &apdu);
  737|  47.4k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  47.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  47.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  47.4k|	int _ret = (r); \
  |  |  |  |  168|  47.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 509, False: 46.9k]
  |  |  |  |  ------------------
  |  |  |  |  169|    509|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    509|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    509|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    509|		return _ret; \
  |  |  |  |  172|    509|	} \
  |  |  |  |  173|  47.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 46.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|  46.9k|	if (file_out == NULL) {
  ------------------
  |  Branch (738:6): [True: 16.8k, False: 30.0k]
  ------------------
  739|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  740|  16.8k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  741|  16.8k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (741:7): [True: 134, False: 16.7k]
  |  Branch (741:27): [True: 11, False: 123]
  ------------------
  742|     11|			apdu.p2 = 0x00;
  743|     11|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  |  Branch (743:8): [True: 10, False: 1]
  ------------------
  744|     10|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  745|     11|		}
  746|  16.8k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (746:7): [True: 0, False: 16.8k]
  ------------------
  747|  16.8k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  748|  16.8k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  16.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.8k|	int _ret = r; \
  |  |  |  |  155|  16.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.5k, False: 4.25k]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  16.8k|	return _ret; \
  |  |  |  |  163|  16.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|  16.8k|	}
  750|       |
  751|  30.0k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  752|  30.0k|	if (r)
  ------------------
  |  Branch (752:6): [True: 17.8k, False: 12.1k]
  ------------------
  753|  30.0k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  17.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.8k|	int _ret = r; \
  |  |  |  |  155|  17.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  17.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  17.8k|	return _ret; \
  |  |  |  |  163|  17.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|       |
  755|  12.1k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (755:6): [True: 12.1k, False: 0]
  |  Branch (755:18): [True: 2.62k, False: 9.56k]
  ------------------
  756|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  757|  2.62k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.07k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (757:7): [True: 547, False: 2.07k]
  |  Branch (757:20): [True: 1.77k, False: 302]
  ------------------
  758|  2.32k|			file = sc_file_new();
  759|  2.32k|			if (file == NULL)
  ------------------
  |  Branch (759:8): [True: 0, False: 2.32k]
  ------------------
  760|  2.32k|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  761|  2.32k|			file->path = *in_path;
  762|       |
  763|  2.32k|			*file_out = file;
  764|  2.32k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.32k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.32k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.32k|	int _ret = r; \
  |  |  |  |  155|  2.32k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.32k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.32k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.32k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.32k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.32k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.32k|	return _ret; \
  |  |  |  |  163|  2.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  765|  2.32k|		}
  766|  2.62k|	}
  767|       |
  768|  9.86k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (768:6): [True: 311, False: 9.55k]
  ------------------
  769|  9.86k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    311|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    311|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    311|	int _ret = r; \
  |  |  |  |  155|    311|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 311, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    311|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    311|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 311, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    311|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    311|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    311|	return _ret; \
  |  |  |  |  163|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  770|  9.55k|	switch (apdu.resp[0]) {
  771|  8.40k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  8.40k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (771:2): [True: 8.40k, False: 1.15k]
  ------------------
  772|  9.19k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  9.19k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (772:2): [True: 785, False: 8.77k]
  ------------------
  773|  9.19k|		file = sc_file_new();
  774|  9.19k|		if (file == NULL)
  ------------------
  |  Branch (774:7): [True: 0, False: 9.19k]
  ------------------
  775|  9.19k|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|  9.19k|		file->path = *in_path;
  777|  9.19k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (777:7): [True: 0, False: 9.19k]
  ------------------
  778|      0|			sc_file_free(file);
  779|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|      0|		}
  781|  9.19k|		buffer = apdu.resp;
  782|  9.19k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  783|  9.19k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  9.19k|#define SC_SUCCESS				0
  ------------------
  |  Branch (783:7): [True: 7.86k, False: 1.32k]
  ------------------
  784|  7.86k|			card->ops->process_fci(card, file, buffer, buffer_len);
  785|  9.19k|		*file_out = file;
  786|  9.19k|		break;
  787|    104|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (787:2): [True: 104, False: 9.45k]
  ------------------
  788|    104|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    104|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    104|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    104|	int _ret = r; \
  |  |  |  |  155|    104|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 104, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    104|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    104|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 104, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    104|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    104|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    104|	return _ret; \
  |  |  |  |  163|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|    261|	default:
  ------------------
  |  Branch (789:2): [True: 261, False: 9.29k]
  ------------------
  790|    261|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    261|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    261|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    261|	int _ret = r; \
  |  |  |  |  155|    261|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 261, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    261|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    261|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 261, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    261|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    261|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    261|	return _ret; \
  |  |  |  |  163|    261|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  791|  9.55k|	}
  792|       |
  793|  9.19k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.19k|#define SC_SUCCESS				0
  ------------------
  794|  9.55k|}
iso7816.c:iso7816_get_response:
  917|  20.5k|{
  918|  20.5k|	struct sc_apdu apdu = {0};
  919|  20.5k|	int r;
  920|  20.5k|	size_t rlen;
  921|       |
  922|       |	/* request at most max_recv_size bytes */
  923|  20.5k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (923:6): [True: 505, False: 20.0k]
  ------------------
  924|    505|		rlen = sc_get_max_recv_size(card);
  925|  20.0k|	else
  926|  20.0k|		rlen = *count;
  927|       |
  928|  20.5k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  20.5k|#define SC_APDU_CASE_2			0x22
  ------------------
  929|  20.5k|	apdu.le      = rlen;
  930|  20.5k|	apdu.resplen = rlen;
  931|  20.5k|	apdu.resp    = buf;
  932|       |	/* don't call GET RESPONSE recursively */
  933|  20.5k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  20.5k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  934|       |
  935|  20.5k|	r = sc_transmit_apdu(card, &apdu);
  936|  20.5k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  20.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  20.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  20.5k|	int _ret = (r); \
  |  |  |  |  168|  20.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 586, False: 19.9k]
  |  |  |  |  ------------------
  |  |  |  |  169|    586|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    586|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    586|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    586|		return _ret; \
  |  |  |  |  172|    586|	} \
  |  |  |  |  173|  20.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  937|       |
  938|  19.9k|	*count = apdu.resplen;
  939|       |
  940|  19.9k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (940:6): [True: 5.19k, False: 14.7k]
  ------------------
  941|  5.19k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  5.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.19k|	int _ret = r; \
  |  |  |  |  155|  5.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.19k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.19k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.30k, False: 2.89k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.19k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.19k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.19k|	return _ret; \
  |  |  |  |  163|  5.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  942|  5.19k|	}
  943|  14.7k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (943:6): [True: 6.61k, False: 8.17k]
  |  Branch (943:26): [True: 6.35k, False: 268]
  ------------------
  944|  6.35k|		r = 0;					/* no more data to read */
  945|  8.44k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (945:11): [True: 5.06k, False: 3.37k]
  ------------------
  946|  5.06k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (946:7): [True: 3.11k, False: 1.95k]
  ------------------
  947|  3.37k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (947:11): [True: 1.89k, False: 1.48k]
  |  Branch (947:31): [True: 1.80k, False: 88]
  ------------------
  948|  1.80k|		r = 0; /* Le not reached but file/record ended */
  949|  1.57k|	else
  950|  1.57k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  951|       |
  952|  14.7k|	return r;
  953|  19.9k|}
iso7816.c:iso7816_set_security_env:
  994|     79|{
  995|     79|	struct sc_apdu apdu;
  996|     79|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  997|     79|	u8 *p;
  998|     79|	int r, locked = 0;
  999|       |
 1000|     79|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (1000:6): [True: 0, False: 79]
  |  Branch (1000:22): [True: 0, False: 79]
  ------------------
 1001|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1002|      0|	}
 1003|     79|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|     79|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1004|     79|	switch (env->operation) {
 1005|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1005:2): [True: 0, False: 79]
  ------------------
 1006|      0|		apdu.p2 = 0xA4;
 1007|      0|		break;
 1008|     47|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     47|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1008:2): [True: 47, False: 32]
  ------------------
 1009|     47|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|     47|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1009:2): [True: 0, False: 79]
  ------------------
 1010|     47|		apdu.p2 = 0xB8;
 1011|     47|		break;
 1012|     32|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     32|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1012:2): [True: 32, False: 47]
  ------------------
 1013|     32|		apdu.p2 = 0xB6;
 1014|     32|		break;
 1015|      0|	default:
  ------------------
  |  Branch (1015:2): [True: 0, False: 79]
  ------------------
 1016|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1017|     79|	}
 1018|     79|	p = sbuf;
 1019|     79|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|     79|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1019:6): [True: 74, False: 5]
  ------------------
 1020|     74|		*p++ = 0x80;	/* algorithm reference */
 1021|     74|		*p++ = 0x01;
 1022|     74|		*p++ = env->algorithm_ref & 0xFF;
 1023|     74|	}
 1024|     79|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|     79|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1024:6): [True: 0, False: 79]
  ------------------
 1025|      0|		if (env->file_ref.len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (1025:7): [True: 0, False: 0]
  ------------------
 1026|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1027|      0|		if (sizeof(sbuf) - (p - sbuf) < env->file_ref.len + 2)
  ------------------
  |  Branch (1027:7): [True: 0, False: 0]
  ------------------
 1028|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1029|       |
 1030|      0|		*p++ = 0x81;
 1031|      0|		*p++ = (u8) env->file_ref.len;
 1032|      0|		memcpy(p, env->file_ref.value, env->file_ref.len);
 1033|      0|		p += env->file_ref.len;
 1034|      0|	}
 1035|     79|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|     79|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1035:6): [True: 77, False: 2]
  ------------------
 1036|     77|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1036:7): [True: 0, False: 77]
  ------------------
 1037|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1038|       |
 1039|     77|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|     77|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1039:7): [True: 0, False: 77]
  ------------------
 1040|      0|			*p++ = 0x83;
 1041|     77|		else
 1042|     77|			*p++ = 0x84;
 1043|     77|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|     77|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1043:7): [True: 0, False: 77]
  ------------------
 1044|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1045|     77|		*p++ = env->key_ref_len & 0xFF;
 1046|     77|		memcpy(p, env->key_ref, env->key_ref_len);
 1047|     77|		p += env->key_ref_len;
 1048|     77|	}
 1049|     79|	r = (int)(p - sbuf);
 1050|     79|	apdu.lc = r;
 1051|     79|	apdu.datalen = r;
 1052|     79|	apdu.data = sbuf;
 1053|     79|	if (se_num > 0) {
  ------------------
  |  Branch (1053:6): [True: 0, False: 79]
  ------------------
 1054|      0|		r = sc_lock(card);
 1055|      0|		LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1056|      0|		locked = 1;
 1057|      0|	}
 1058|     79|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1058:6): [True: 78, False: 1]
  ------------------
 1059|     78|		r = sc_transmit_apdu(card, &apdu);
 1060|     78|		if (r) {
  ------------------
  |  Branch (1060:7): [True: 0, False: 78]
  ------------------
 1061|      0|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1062|      0|			goto err;
 1063|      0|		}
 1064|     78|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1065|     78|		if (r) {
  ------------------
  |  Branch (1065:7): [True: 7, False: 71]
  ------------------
 1066|      7|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1067|      7|			goto err;
 1068|      7|		}
 1069|     78|	}
 1070|     72|	if (se_num <= 0) {
  ------------------
  |  Branch (1070:6): [True: 72, False: 0]
  ------------------
 1071|     72|		r = SC_SUCCESS;
  ------------------
  |  |   28|     72|#define SC_SUCCESS				0
  ------------------
 1072|     72|		goto err;
 1073|     72|	}
 1074|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1075|      0|	r = sc_transmit_apdu(card, &apdu);
 1076|      0|	sc_unlock(card);
 1077|      0|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1078|       |
 1079|      0|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
 1080|     79|err:
 1081|     79|	if (locked)
  ------------------
  |  Branch (1081:6): [True: 0, False: 79]
  ------------------
 1082|      0|		sc_unlock(card);
 1083|     79|	return r;
 1084|      0|}
iso7816.c:iso7816_decipher:
 1151|      8|{
 1152|      8|	int r;
 1153|      8|	struct sc_apdu apdu;
 1154|      8|	u8 *sbuf = NULL;
 1155|       |
 1156|      8|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1156:6): [True: 0, False: 8]
  |  Branch (1156:22): [True: 0, False: 8]
  |  Branch (1156:40): [True: 0, False: 8]
  ------------------
 1157|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1158|      0|	}
 1159|      8|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      8|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      8|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1160|      8|	sc_log(card->ctx, "ISO7816 decipher: in-len %zu, out-len %zu", crgram_len, outlen);
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1161|       |
 1162|      8|	sbuf = malloc(crgram_len + 1);
 1163|      8|	if (sbuf == NULL)
  ------------------
  |  Branch (1163:6): [True: 0, False: 8]
  ------------------
 1164|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1165|       |
 1166|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1167|       |	 * P1:  0x80  Resp: Plain value
 1168|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1169|      8|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|      8|#define SC_APDU_CASE_4			0x24
  ------------------
 1170|      8|	apdu.resp    = out;
 1171|      8|	apdu.resplen = outlen;
 1172|      8|	apdu.le      = outlen;
 1173|       |
 1174|      8|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1175|      8|	memcpy(sbuf + 1, crgram, crgram_len);
 1176|      8|	apdu.data = sbuf;
 1177|      8|	apdu.lc = crgram_len + 1;
 1178|      8|	apdu.datalen = crgram_len + 1;
 1179|       |
 1180|      8|	iso7816_fixup_transceive_length(card, &apdu);
 1181|      8|	r = sc_transmit_apdu(card, &apdu);
 1182|      8|	sc_mem_clear(sbuf, crgram_len + 1);
 1183|      8|	free(sbuf);
 1184|      8|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1185|       |
 1186|      6|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1186:6): [True: 3, False: 3]
  |  Branch (1186:26): [True: 2, False: 1]
  ------------------
 1187|      6|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1188|      4|	else
 1189|      6|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      6|}
iso7816.c:iso7816_check_sw:
  110|   354k|{
  111|   354k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  112|   354k|	int i;
  113|       |
  114|       |	/* Handle special cases here */
  115|   354k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (115:6): [True: 268, False: 354k]
  ------------------
  116|    268|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    268|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  117|    268|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    268|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  118|    268|	}
  119|   354k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (119:6): [True: 116k, False: 237k]
  |  Branch (119:21): [True: 114k, False: 2.10k]
  ------------------
  120|   114k|		return SC_SUCCESS;
  ------------------
  |  |   28|   114k|#define SC_SUCCESS				0
  ------------------
  121|   239k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (121:6): [True: 365, False: 239k]
  |  Branch (121:22): [True: 128, False: 237]
  ------------------
  122|    128|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|    128|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  123|    128|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    128|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  124|    128|	}
  125|  9.72M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (125:14): [True: 9.71M, False: 14.6k]
  ------------------
  126|  9.71M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (126:7): [True: 224k, False: 9.48M]
  ------------------
  127|   224k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   224k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  128|   224k|			return iso7816_errors[i].errorno;
  129|   224k|		}
  130|  9.71M|	}
  131|       |
  132|  14.6k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  14.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  133|  14.6k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  14.6k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  134|   239k|}
iso7816.c:iso7816_process_fci:
  635|  8.08k|{
  636|  8.08k|	return iso7816_process_fci_nested(card, file, buf, buflen, 0);
  637|  8.08k|}
iso7816.c:iso7816_process_fci_nested:
  432|  9.20k|{
  433|  9.20k|	struct sc_context *ctx = card->ctx;
  434|  9.20k|	const unsigned char *p, *end;
  435|  9.20k|	unsigned int cla = 0, tag = 0;
  436|  9.20k|	size_t length;
  437|       |
  438|  9.20k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.20k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  439|       |
  440|  9.20k|	for (p = buf, length = buflen, end = buf + buflen;
  441|  29.9k|			p < end;
  ------------------
  |  Branch (441:4): [True: 26.9k, False: 2.96k]
  ------------------
  442|  26.9k|			p += length, length = end - p) {
  443|       |
  444|  26.9k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  26.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (444:7): [True: 4.27k, False: 22.6k]
  ------------------
  445|  22.6k|				|| p == NULL) {
  ------------------
  |  Branch (445:8): [True: 1.96k, False: 20.7k]
  ------------------
  446|  6.23k|			break;
  447|  6.23k|		}
  448|  20.7k|		switch (cla | tag) {
  ------------------
  |  Branch (448:11): [True: 15.1k, False: 5.54k]
  ------------------
  449|  2.83k|			case 0x81:
  ------------------
  |  Branch (449:4): [True: 2.83k, False: 17.8k]
  ------------------
  450|  2.83k|				if (file->size != 0) {
  ------------------
  |  Branch (450:9): [True: 99, False: 2.73k]
  ------------------
  451|       |					/* don't overwrite existing file size excluding structural information */
  452|     99|					break;
  453|     99|				}
  454|       |				/* fall through */
  455|  4.41k|			case 0x80:
  ------------------
  |  Branch (455:4): [True: 1.67k, False: 19.0k]
  ------------------
  456|       |				/* determine the file size */
  457|  4.41k|				file->size = 0;
  458|  4.41k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (458:9): [True: 4.41k, False: 0]
  |  Branch (458:14): [True: 4.35k, False: 53]
  ------------------
  459|  4.35k|					size_t size = 0, i;
  460|  13.4k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (460:18): [True: 9.11k, False: 4.35k]
  ------------------
  461|  9.11k|						size <<= 8;
  462|  9.11k|						size |= p[i];
  463|  9.11k|					}
  464|  4.35k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  4.35k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (464:10): [True: 688, False: 3.67k]
  ------------------
  465|    688|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    688|#define MAX_FILE_SIZE 65535
  ------------------
  466|    688|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   71|    688|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  467|  3.67k|					} else {
  468|  3.67k|						file->size = size;
  469|  3.67k|					}
  470|  4.35k|				}
  471|       |
  472|  4.41k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  4.41k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  473|  4.41k|				break;
  474|       |
  475|  2.95k|			case 0x82:
  ------------------
  |  Branch (475:4): [True: 2.95k, False: 17.7k]
  ------------------
  476|  2.95k|				if (length > 0) {
  ------------------
  |  Branch (476:9): [True: 2.51k, False: 438]
  ------------------
  477|  2.51k|					unsigned char byte = p[0];
  478|  2.51k|					const char *type;
  479|       |
  480|  2.51k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (480:24): [True: 386, False: 2.12k]
  ------------------
  481|  2.51k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  5.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 386, False: 2.12k]
  |  |  ------------------
  ------------------
  482|  2.51k|					file->ef_structure = byte & 0x07;
  483|  2.51k|					switch ((byte >> 3) & 7) {
  484|  1.52k|						case 0:
  ------------------
  |  Branch (484:7): [True: 1.52k, False: 988]
  ------------------
  485|  1.52k|							type = "working EF";
  486|  1.52k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.52k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  487|  1.52k|							break;
  488|    115|						case 1:
  ------------------
  |  Branch (488:7): [True: 115, False: 2.39k]
  ------------------
  489|    115|							type = "internal EF";
  490|    115|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    115|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  491|    115|							break;
  492|    238|						case 7:
  ------------------
  |  Branch (492:7): [True: 238, False: 2.27k]
  ------------------
  493|    238|							type = "DF";
  494|    238|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    238|#define SC_FILE_TYPE_DF			0x04
  ------------------
  495|    238|							break;
  496|    635|						default:
  ------------------
  |  Branch (496:7): [True: 635, False: 1.87k]
  ------------------
  497|    635|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    635|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  498|    635|							type = "unknown";
  499|    635|							break;
  500|  2.51k|					}
  501|  2.51k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  2.51k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  502|  2.51k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  2.51k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|  2.51k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  2.51k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  504|       |
  505|       |					/* if possible, get additional information for non-DFs */
  506|  2.51k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.51k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (506:10): [True: 2.27k, False: 238]
  ------------------
  507|       |						/* max. record length for fixed- & variable-sized records */
  508|  2.27k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (508:11): [True: 552, False: 1.72k]
  |  Branch (508:25): [True: 399, False: 153]
  ------------------
  509|    399|							file->record_length = (length > 3)
  ------------------
  |  Branch (509:30): [True: 273, False: 126]
  ------------------
  510|    399|								? bebytes2ushort(p+2)
  511|    399|								: p[2];
  512|    399|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   71|    399|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  513|    399|						}
  514|       |
  515|       |						/* number of records */
  516|  2.27k|						if (length > 4) {
  ------------------
  |  Branch (516:11): [True: 268, False: 2.00k]
  ------------------
  517|    268|							file->record_count = (length > 5)
  ------------------
  |  Branch (517:29): [True: 85, False: 183]
  ------------------
  518|    268|								? bebytes2ushort(p+4)
  519|    268|								: p[4];
  520|    268|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   71|    268|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  521|    268|						}
  522|  2.27k|					}
  523|       |
  524|  2.51k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  2.51k|#define SC_SUCCESS				0
  ------------------
  |  Branch (524:10): [True: 0, False: 2.51k]
  ------------------
  525|      0|						sc_log(ctx, "Warning: Could not set file attributes");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  526|  2.51k|				}
  527|  2.95k|				break;
  528|       |
  529|  2.95k|			case 0x83:
  ------------------
  |  Branch (529:4): [True: 1.38k, False: 19.3k]
  ------------------
  530|  1.38k|				if (length == 2) {
  ------------------
  |  Branch (530:9): [True: 1.22k, False: 161]
  ------------------
  531|  1.22k|					file->id = (p[0] << 8) | p[1];
  532|  1.22k|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|  1.22k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  533|  1.22k|				}
  534|  1.38k|				break;
  535|       |
  536|    511|			case 0x84:
  ------------------
  |  Branch (536:4): [True: 511, False: 20.2k]
  ------------------
  537|    511|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (537:9): [True: 314, False: 197]
  |  Branch (537:23): [True: 294, False: 20]
  ------------------
  538|    294|					memcpy(file->name, p, length);
  539|    294|					file->namelen = length;
  540|       |
  541|    294|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    294|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    294|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  542|    294|					if (!file->type)
  ------------------
  |  Branch (542:10): [True: 96, False: 198]
  ------------------
  543|     96|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     96|#define SC_FILE_TYPE_DF			0x04
  ------------------
  544|    294|				}
  545|    511|				break;
  546|       |
  547|    546|			case 0x85:
  ------------------
  |  Branch (547:4): [True: 546, False: 20.1k]
  ------------------
  548|  1.33k|			case 0xA5:
  ------------------
  |  Branch (548:4): [True: 789, False: 19.9k]
  ------------------
  549|  1.33k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.33k|#define SC_SUCCESS				0
  ------------------
  |  Branch (549:9): [True: 0, False: 1.33k]
  ------------------
  550|      0|					sc_log(ctx, "Warning: Could not set proprietary file properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|      0|				}
  552|  1.33k|				break;
  553|       |
  554|  1.23k|			case 0x86:
  ------------------
  |  Branch (554:4): [True: 1.23k, False: 19.4k]
  ------------------
  555|  1.23k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.23k|#define SC_SUCCESS				0
  ------------------
  |  Branch (555:9): [True: 0, False: 1.23k]
  ------------------
  556|      0|					sc_log(ctx, "Warning: Could not set file security properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  557|      0|				}
  558|  1.23k|				break;
  559|       |
  560|    277|			case 0x88:
  ------------------
  |  Branch (560:4): [True: 277, False: 20.4k]
  ------------------
  561|    277|				if (length == 1) {
  ------------------
  |  Branch (561:9): [True: 68, False: 209]
  ------------------
  562|     68|					file->sid = *p;
  563|     68|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  564|     68|				}
  565|    277|				break;
  566|       |
  567|  1.86k|			case 0x8A:
  ------------------
  |  Branch (567:4): [True: 1.86k, False: 18.8k]
  ------------------
  568|  1.86k|				if (length == 1) {
  ------------------
  |  Branch (568:9): [True: 1.62k, False: 238]
  ------------------
  569|  1.62k|					switch (p[0]) {
  570|     68|						case 0:
  ------------------
  |  Branch (570:7): [True: 68, False: 1.55k]
  ------------------
  571|     68|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     68|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  572|     68|							break;
  573|     74|						case 1:
  ------------------
  |  Branch (573:7): [True: 74, False: 1.55k]
  ------------------
  574|     74|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     74|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  575|     74|							break;
  576|     67|						case 3:
  ------------------
  |  Branch (576:7): [True: 67, False: 1.55k]
  ------------------
  577|     67|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     67|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  578|     67|							break;
  579|    127|						case 4:
  ------------------
  |  Branch (579:7): [True: 127, False: 1.49k]
  ------------------
  580|    201|						case 6:
  ------------------
  |  Branch (580:7): [True: 74, False: 1.55k]
  ------------------
  581|    201|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    201|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  582|    201|							break;
  583|    396|						case 5:
  ------------------
  |  Branch (583:7): [True: 396, False: 1.22k]
  ------------------
  584|    474|						case 7:
  ------------------
  |  Branch (584:7): [True: 78, False: 1.54k]
  ------------------
  585|    474|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    474|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  586|    474|							break;
  587|     69|						case 12:
  ------------------
  |  Branch (587:7): [True: 69, False: 1.55k]
  ------------------
  588|    136|						case 13:
  ------------------
  |  Branch (588:7): [True: 67, False: 1.55k]
  ------------------
  589|    206|						case 14:
  ------------------
  |  Branch (589:7): [True: 70, False: 1.55k]
  ------------------
  590|    273|						case 15:
  ------------------
  |  Branch (590:7): [True: 67, False: 1.55k]
  ------------------
  591|    273|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    273|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  592|    273|							break;
  593|     67|						case 2:
  ------------------
  |  Branch (593:7): [True: 67, False: 1.55k]
  ------------------
  594|     67|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     67|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  595|     67|							break;
  596|     67|						case 8:
  ------------------
  |  Branch (596:7): [True: 67, False: 1.55k]
  ------------------
  597|     67|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     67|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  598|     67|							break;
  599|     67|						case 9:
  ------------------
  |  Branch (599:7): [True: 67, False: 1.55k]
  ------------------
  600|     67|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     67|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  601|     67|							break;
  602|     68|						case 10:
  ------------------
  |  Branch (602:7): [True: 68, False: 1.55k]
  ------------------
  603|     68|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     68|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  604|     68|							break;
  605|     85|						case 11:
  ------------------
  |  Branch (605:7): [True: 85, False: 1.54k]
  ------------------
  606|     85|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     85|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  607|     85|							break;
  608|    114|						default:
  ------------------
  |  Branch (608:7): [True: 114, False: 1.51k]
  ------------------
  609|    114|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|    114|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  610|  1.62k|					}
  611|  1.62k|				}
  612|  1.86k|				break;
  613|       |
  614|  1.86k|			case 0x62:
  ------------------
  |  Branch (614:4): [True: 736, False: 19.9k]
  ------------------
  615|    822|			case 0x64:
  ------------------
  |  Branch (615:4): [True: 86, False: 20.6k]
  ------------------
  616|  1.11k|			case 0x6F:
  ------------------
  |  Branch (616:4): [True: 291, False: 20.4k]
  ------------------
  617|       |				/* allow nested FCP/FMD/FCI templates */
  618|  1.11k|				if (depth >= ISO7816_MAX_FCI_TEMPLATE_NESTING) {
  ------------------
  |  |  427|  1.11k|#define ISO7816_MAX_FCI_TEMPLATE_NESTING 32
  ------------------
  |  Branch (618:9): [True: 0, False: 1.11k]
  ------------------
  619|      0|					sc_log(ctx, "FCP/FMD/FCI template nesting too deep, skipping");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  620|      0|					break;
  621|      0|				}
  622|  1.11k|				iso7816_process_fci_nested(card, file, p, length, depth + 1);
  623|  20.7k|		}
  624|  20.7k|	}
  625|       |
  626|  9.20k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|  9.20k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  627|       |
  628|  9.20k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.20k|#define SC_SUCCESS				0
  ------------------
  629|  9.20k|}
iso7816.c:iso7816_pin_cmd:
 1295|  1.01k|{
 1296|  1.01k|	struct sc_apdu local_apdu, *apdu;
 1297|  1.01k|	int r;
 1298|  1.01k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1299|       |
 1300|  1.01k|	data->pin1.tries_left = -1;
 1301|       |
 1302|       |	/* Many cards do support PIN status queries, but some cards don't and
 1303|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1304|       |	 * allow cards with this flag.  In future this may be reduced to a
 1305|       |	 * blocklist, subject to testing more cards. */
 1306|  1.01k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  2.02k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1306:6): [True: 796, False: 216]
  ------------------
 1307|    796|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|    796|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1307:6): [True: 151, False: 645]
  ------------------
 1308|    151|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    151|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1309|    151|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    151|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1310|    151|	}
 1311|       |
 1312|       |	/* See if we've been called from another card driver, which is
 1313|       |	 * passing an APDU to us (this allows to write card drivers
 1314|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1315|       |	 * special circumstances.
 1316|       |	 */
 1317|    861|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1317:6): [True: 861, False: 0]
  ------------------
 1318|    861|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1319|    861|		if (r < 0)
  ------------------
  |  Branch (1319:7): [True: 74, False: 787]
  ------------------
 1320|     74|			return r;
 1321|    787|		data->apdu = &local_apdu;
 1322|    787|	}
 1323|    787|	apdu = data->apdu;
 1324|       |
 1325|    787|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|    787|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1325:6): [True: 787, False: 0]
  |  Branch (1325:48): [True: 0, False: 0]
  ------------------
 1326|       |		/* Transmit the APDU to the card */
 1327|    787|		r = sc_transmit_apdu(card, apdu);
 1328|       |
 1329|       |		/* Clear the buffer - it may contain pins */
 1330|    787|		sc_mem_clear(sbuf, sizeof(sbuf));
 1331|    787|	}
 1332|      0|	else {
 1333|       |		/* Call the reader driver to collect
 1334|       |		 * the PIN and pass on the APDU to the card */
 1335|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1335:7): [True: 0, False: 0]
  ------------------
 1336|      0|			sc_log(card->ctx, "Card driver didn't set PIN offset");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1337|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1338|      0|		}
 1339|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1339:7): [True: 0, False: 0]
  |  Branch (1339:23): [True: 0, False: 0]
  |  Branch (1339:44): [True: 0, False: 0]
  ------------------
 1340|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1341|       |			/* sw1/sw2 filled in by reader driver */
 1342|      0|		}
 1343|      0|		else {
 1344|      0|			sc_log(card->ctx, "Card reader driver does not support "
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1345|      0|					"PIN entry through reader key pad");
 1346|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1347|      0|		}
 1348|      0|	}
 1349|       |
 1350|       |	/* Don't pass references to local variables up to the caller. */
 1351|    787|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1351:6): [True: 787, False: 0]
  ------------------
 1352|    787|		data->apdu = NULL;
 1353|       |
 1354|    787|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    787|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    787|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    787|	int _ret = (r); \
  |  |  |  |  168|    787|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 785]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|    787|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 785]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1355|    785|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1356|       |
 1357|    785|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    785|#define SC_SUCCESS				0
  ------------------
  |  Branch (1357:6): [True: 674, False: 111]
  ------------------
 1358|    674|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|    674|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1359|    674|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|    111|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1359:13): [True: 3, False: 108]
  ------------------
 1360|      3|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1361|      3|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      3|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1362|      3|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      3|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1362:7): [True: 1, False: 2]
  ------------------
 1363|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1364|    108|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|    108|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1364:13): [True: 2, False: 106]
  ------------------
 1365|      2|		data->pin1.tries_left = 0;
 1366|      2|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      2|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1367|      2|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      2|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1367:7): [True: 1, False: 1]
  ------------------
 1368|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1369|      2|	}
 1370|       |
 1371|    785|	return r;
 1372|    787|}
iso7816.c:iso7816_get_data:
 1376|    260|{
 1377|    260|	int                             r, cse;
 1378|    260|	struct sc_apdu                  apdu;
 1379|       |
 1380|    260|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    260|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    260|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    260|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 260]
  |  |  ------------------
  ------------------
 1381|       |
 1382|    260|	if (buf && len)
  ------------------
  |  Branch (1382:6): [True: 260, False: 0]
  |  Branch (1382:13): [True: 260, False: 0]
  ------------------
 1383|    260|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    260|#define SC_APDU_CASE_2			0x22
  ------------------
 1384|      0|	else
 1385|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1386|       |
 1387|    260|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1388|    260|	apdu.le = len;
 1389|    260|	apdu.resp = buf;
 1390|    260|	apdu.resplen = len;
 1391|    260|	r = sc_transmit_apdu(card, &apdu);
 1392|    260|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    260|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    260|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    260|	int _ret = (r); \
  |  |  |  |  168|    260|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 256]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|    260|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 256]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1393|       |
 1394|    256|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1395|    256|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    256|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    256|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    256|	int _ret = (r); \
  |  |  |  |  168|    256|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67, False: 189]
  |  |  |  |  ------------------
  |  |  |  |  169|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     67|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     67|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     67|		return _ret; \
  |  |  |  |  172|     67|	} \
  |  |  |  |  173|    256|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 189]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1396|       |
 1397|    189|	if (apdu.resplen > len)
  ------------------
  |  Branch (1397:6): [True: 0, False: 189]
  ------------------
 1398|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1399|    189|	else
 1400|    189|		r = (int)apdu.resplen;
 1401|       |
 1402|    189|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    189|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    189|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    189|	int _ret = r; \
  |  |  |  |  155|    189|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 40, False: 149]
  |  |  |  |  ------------------
  |  |  |  |  156|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  157|     40|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    149|	} else { \
  |  |  |  |  159|    149|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    149|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    149|	} \
  |  |  |  |  162|    189|	return _ret; \
  |  |  |  |  163|    189|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1403|    189|}
iso7816.c:iso7816_read_binary:
  139|  19.9k|{
  140|  19.9k|	struct sc_context *ctx = card->ctx;
  141|  19.9k|	struct sc_apdu apdu;
  142|  19.9k|	int r;
  143|       |
  144|  19.9k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (144:6): [True: 4, False: 19.9k]
  ------------------
  145|      4|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  146|      4|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      4|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  147|      4|	}
  148|       |
  149|  19.9k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  19.9k|#define SC_APDU_CASE_2			0x22
  ------------------
  150|  19.9k|	apdu.le = count;
  151|  19.9k|	apdu.resplen = count;
  152|  19.9k|	apdu.resp = buf;
  153|       |
  154|  19.9k|	iso7816_fixup_transceive_length(card, &apdu);
  155|  19.9k|	r = sc_transmit_apdu(card, &apdu);
  156|  19.9k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  19.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  19.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  19.9k|	int _ret = (r); \
  |  |  |  |  168|  19.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 251, False: 19.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    251|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    251|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    251|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    251|		return _ret; \
  |  |  |  |  172|    251|	} \
  |  |  |  |  173|  19.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|       |
  158|  19.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  159|  19.6k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  39.3k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  19.2k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (159:6): [True: 444, False: 19.2k]
  |  Branch (159:40): [True: 76, False: 19.1k]
  ------------------
  160|  19.6k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    520|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    520|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    520|	int _ret = r; \
  |  |  |  |  155|    520|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 475]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    475|	} else { \
  |  |  |  |  159|    475|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    475|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    475|	} \
  |  |  |  |  162|    520|	return _ret; \
  |  |  |  |  163|    520|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|  19.1k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  19.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  19.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  19.1k|	int _ret = (r); \
  |  |  |  |  168|  19.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.71k, False: 16.4k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.71k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.71k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.71k|		return _ret; \
  |  |  |  |  172|  2.71k|	} \
  |  |  |  |  173|  19.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|       |
  163|  16.4k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  16.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.4k|	int _ret = r; \
  |  |  |  |  155|  16.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 417, False: 16.0k]
  |  |  |  |  ------------------
  |  |  |  |  156|    417|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 417]
  |  |  |  |  ------------------
  |  |  |  |  157|    417|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.0k|	} else { \
  |  |  |  |  159|  16.0k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.0k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.0k|	} \
  |  |  |  |  162|  16.4k|	return _ret; \
  |  |  |  |  163|  16.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|  16.4k|}

sc_do_log:
   57|  13.1M|{
   58|  13.1M|	va_list ap;
   59|       |
   60|  13.1M|	va_start(ap, format);
   61|  13.1M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   62|       |	va_end(ap);
   63|  13.1M|}
sc_do_log_color:
   66|  2.61M|{
   67|  2.61M|	va_list ap;
   68|       |
   69|  2.61M|	va_start(ap, format);
   70|  2.61M|	sc_do_log_va(ctx, level, file, line, func, color, format, ap);
   71|       |	va_end(ap);
   72|  2.61M|}
sc_do_log_openssl:
   76|     10|{
   77|     10|	BIO *bio = NULL;
   78|     10|	int length, rc;
   79|     10|	char *buffer = NULL;
   80|       |
   81|     10|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (81:6): [True: 0, False: 10]
  ------------------
   82|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   83|      0|		goto end;
   84|      0|	}
   85|     10|	ERR_print_errors(bio);
   86|       |
   87|     10|	length = BIO_pending(bio);
   88|     10|	if (length <= 0) {
  ------------------
  |  Branch (88:6): [True: 0, False: 10]
  ------------------
   89|       |		/* no error? */
   90|      0|		goto end;
   91|      0|	}
   92|       |	/* trailing null byte */
   93|     10|	buffer = malloc(length + 1);
   94|     10|	if (buffer == NULL) {
  ------------------
  |  Branch (94:6): [True: 0, False: 10]
  ------------------
   95|      0|		sc_do_log(ctx, level, file, line, func, "No memory!");
   96|      0|		goto end;
   97|      0|	}
   98|     10|	rc = BIO_read(bio, buffer, length);
   99|     10|	buffer[length] = '\0';
  100|     10|	if (rc <= 0) {
  ------------------
  |  Branch (100:6): [True: 0, False: 10]
  ------------------
  101|      0|		sc_do_log(ctx, level, file, line, func, "Cannot read OpenSSL error");
  102|      0|		goto end;
  103|      0|	}
  104|       |
  105|     10|	sc_do_log(ctx, level, file, line, func, "OpenSSL error\n%s", buffer);
  106|     10|end:
  107|     10|	free(buffer);
  108|     10|	BIO_free(bio);
  109|     10|}
sc_color_fprintf:
  253|  1.12M|{
  254|  1.12M|	int r;
  255|  1.12M|	va_list ap;
  256|       |
  257|  1.12M|	va_start(ap, format);
  258|  1.12M|	r = sc_color_fprintf_va(colors, ctx, stream, format, ap);
  259|  1.12M|	va_end(ap);
  260|       |
  261|  1.12M|	return r;
  262|  1.12M|}
_sc_debug_hex:
  342|   325k|{
  343|   325k|	size_t blen;
  344|   325k|	char *buf;
  345|   325k|	const char *truncated = "";
  346|       |
  347|   325k|	if (len > SC_MAX_EXT_APDU_BUFFER_SIZE) {
  ------------------
  |  |   37|   325k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  |  Branch (347:6): [True: 0, False: 325k]
  ------------------
  348|      0|		len = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|      0|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  349|      0|		truncated = "truncated to ";
  350|      0|	}
  351|   325k|	blen = len * 5 + 128;
  352|       |
  353|   325k|	buf = malloc(blen);
  354|   325k|	if (buf == NULL)
  ------------------
  |  Branch (354:6): [True: 0, False: 325k]
  ------------------
  355|      0|		return;
  356|       |
  357|   325k|	sc_hex_dump(data, len, buf, blen);
  358|       |
  359|   325k|	if (label)
  ------------------
  |  Branch (359:6): [True: 325k, False: 0]
  ------------------
  360|   325k|		sc_do_log(ctx, type, file, line, func, "\n%s (%s%zu byte%s):\n%s",
  361|   325k|				label, truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (361:28): [True: 642, False: 325k]
  ------------------
  362|      0|	else
  363|      0|		sc_do_log(ctx, type, file, line, func, "%s%zu byte%s:\n%s",
  364|      0|				truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (364:21): [True: 0, False: 0]
  ------------------
  365|       |
  366|   325k|	free(buf);
  367|   325k|}
sc_hex_dump:
  370|   325k|{
  371|   325k|	char *p = buf;
  372|   325k|	size_t p_len = len;
  373|   325k|	int lines = 0;
  374|       |
  375|   325k|	if (buf == NULL || (in == NULL && count != 0)) {
  ------------------
  |  Branch (375:6): [True: 0, False: 325k]
  |  Branch (375:22): [True: 287, False: 325k]
  |  Branch (375:36): [True: 0, False: 287]
  ------------------
  376|      0|		return;
  377|      0|	}
  378|   325k|	buf[0] = 0;
  379|   325k|	if ((count * 5) > len)
  ------------------
  |  Branch (379:6): [True: 0, False: 325k]
  ------------------
  380|      0|		return;
  381|  2.76M|	while (count) {
  ------------------
  |  Branch (381:9): [True: 2.44M, False: 325k]
  ------------------
  382|  2.44M|		char ascbuf[17];
  383|  2.44M|		size_t i;
  384|       |
  385|  39.0M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (385:15): [True: 38.8M, False: 239k]
  |  Branch (385:28): [True: 36.6M, False: 2.20M]
  ------------------
  386|  36.6M|			sprintf(p, "%02X ", *in);
  387|  36.6M|			if (isprint(*in))
  ------------------
  |  Branch (387:8): [True: 24.5M, False: 12.1M]
  ------------------
  388|  24.5M|				ascbuf[i] = *in;
  389|  12.1M|			else
  390|  12.1M|				ascbuf[i] = '.';
  391|  36.6M|			p += 3;
  392|  36.6M|			p_len -= 3;
  393|  36.6M|			in++;
  394|  36.6M|		}
  395|  2.44M|		count -= i;
  396|  2.44M|		ascbuf[i] = 0;
  397|  3.38M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (397:10): [True: 1.07M, False: 2.30M]
  |  Branch (397:20): [True: 945k, False: 131k]
  ------------------
  398|   945k|			strlcat(p, "   ", p_len);
  399|   945k|			p += 3;
  400|   945k|			p_len -= 3;
  401|   945k|		}
  402|  2.44M|		snprintf(p, p_len, "%s\n", ascbuf);
  403|  2.44M|		p += strlen(ascbuf) + 1;
  404|  2.44M|		p_len -= strlen(ascbuf) - 1;
  405|  2.44M|		lines++;
  406|  2.44M|	}
  407|   325k|}
sc_dump_hex:
  411|   168k|{
  412|   168k|	static char dump_buf[0x1000];
  413|   168k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  414|   168k|	size_t offs = 0;
  415|       |
  416|   168k|	memset(dump_buf, 0, sizeof(dump_buf));
  417|   168k|	if (in == NULL)
  ------------------
  |  Branch (417:6): [True: 17, False: 168k]
  ------------------
  418|     17|		return dump_buf;
  419|       |
  420|   511k|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (420:13): [True: 342k, False: 168k]
  ------------------
  421|   342k|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (421:7): [True: 302k, False: 39.8k]
  |  Branch (421:13): [True: 5.02k, False: 297k]
  ------------------
  422|  5.02k|			if (!(ii%48))
  ------------------
  |  Branch (422:8): [True: 1.47k, False: 3.55k]
  ------------------
  423|  1.47k|				snprintf(dump_buf + offs, size - offs, "\n");
  424|  3.55k|			else
  425|  3.55k|				snprintf(dump_buf + offs, size - offs, " ");
  426|  5.02k|			offs = strlen(dump_buf);
  427|  5.02k|		}
  428|       |
  429|   342k|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  430|   342k|		offs += 2;
  431|       |
  432|   342k|		if (offs > size)
  ------------------
  |  Branch (432:7): [True: 5, False: 342k]
  ------------------
  433|      5|			break;
  434|   342k|	}
  435|       |
  436|   168k|	if (ii<count)
  ------------------
  |  Branch (436:6): [True: 5, False: 168k]
  ------------------
  437|      5|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  438|       |
  439|   168k|	return dump_buf;
  440|   168k|}
sc_dump_oid:
  444|  3.87k|{
  445|  3.87k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  446|  3.87k|        size_t ii;
  447|       |
  448|  3.87k|	memset(dump_buf, 0, sizeof(dump_buf));
  449|  3.87k|	if (oid)
  ------------------
  |  Branch (449:6): [True: 3.87k, False: 0]
  ------------------
  450|  22.7k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|  45.5k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (450:14): [True: 22.7k, False: 0]
  |  Branch (450:44): [True: 18.8k, False: 3.87k]
  ------------------
  451|  18.8k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (451:88): [True: 14.9k, False: 3.87k]
  ------------------
  452|       |
  453|  3.87k|	return dump_buf;
  454|  3.87k|}
log.c:sc_do_log_va:
  123|  15.8M|{
  124|       |#ifdef _WIN32
  125|       |	SYSTEMTIME st;
  126|       |#else
  127|  15.8M|	struct tm *tm;
  128|  15.8M|	struct timeval tv;
  129|  15.8M|	char time_string[40];
  130|  15.8M|#endif
  131|       |
  132|  15.8M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (132:6): [True: 0, False: 15.8M]
  |  Branch (132:14): [True: 15.6M, False: 174k]
  ------------------
  133|  15.6M|		return;
  134|       |
  135|       |#ifdef _WIN32
  136|       |	/* In Windows, file handles can not be shared between DLL-s, each DLL has a
  137|       |	 * separate file handle table. Make sure we always have a valid file
  138|       |	 * descriptor. */
  139|       |	if (sc_ctx_log_to_file(ctx, ctx->debug_filename) < 0)
  140|       |		return;
  141|       |#endif
  142|   174k|	if (ctx->debug_file == NULL)
  ------------------
  |  Branch (142:6): [True: 0, False: 174k]
  ------------------
  143|      0|		return;
  144|       |
  145|       |#ifdef _WIN32
  146|       |	GetLocalTime(&st);
  147|       |	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  148|       |			ctx, ctx->debug_file,
  149|       |			"P:%lu; T:%lu",
  150|       |			(unsigned long)GetCurrentProcessId(),
  151|       |			(unsigned long)GetCurrentThreadId());
  152|       |	sc_color_fprintf(SC_COLOR_FG_GREEN,
  153|       |			ctx, ctx->debug_file,
  154|       |			" %i-%02i-%02i %02i:%02i:%02i.%03i",
  155|       |			st.wYear, st.wMonth, st.wDay,
  156|       |			st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
  157|       |#else
  158|   174k|	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   45|   174k|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   56|   174k|#define SC_COLOR_BOLD			0x8080
  ------------------
  159|   174k|			ctx, ctx->debug_file,
  160|   174k|			"P:%lu; T:0x%lu",
  161|   174k|			(unsigned long)getpid(),
  162|   174k|			(unsigned long)pthread_self());
  163|   174k|	gettimeofday (&tv, NULL);
  164|   174k|	tm = localtime (&tv.tv_sec);
  165|   174k|	strftime (time_string, sizeof(time_string), "%H:%M:%S", tm);
  166|   174k|	sc_color_fprintf(SC_COLOR_FG_GREEN,
  ------------------
  |  |   45|   174k|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
  167|   174k|			ctx, ctx->debug_file,
  168|   174k|			" %s.%03ld",
  169|   174k|			time_string,
  170|   174k|			(long)tv.tv_usec / 1000);
  171|   174k|#endif
  172|       |
  173|   174k|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   174k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  174|   174k|			ctx, ctx->debug_file,
  175|   174k|			" [");
  176|   174k|	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   46|   174k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   56|   174k|#define SC_COLOR_BOLD			0x8080
  ------------------
  177|   174k|			ctx, ctx->debug_file,
  178|   174k|			"%s",
  179|   174k|			ctx->app_name);
  180|   174k|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   174k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  181|   174k|			ctx, ctx->debug_file,
  182|   174k|			"] ");
  183|       |
  184|   174k|	if (file != NULL) {
  ------------------
  |  Branch (184:6): [True: 174k, False: 0]
  ------------------
  185|   174k|		sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   174k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  186|   174k|				ctx, ctx->debug_file,
  187|   174k|				"%s:%d:%s: ",
  188|   174k|				file, line, func ? func : "");
  ------------------
  |  Branch (188:17): [True: 174k, False: 0]
  ------------------
  189|   174k|	}
  190|       |
  191|   174k|	sc_color_fprintf_va(color, ctx, ctx->debug_file, format, args);
  192|   174k|	if (strlen(format) == 0 || format[strlen(format) - 1] != '\n')
  ------------------
  |  Branch (192:6): [True: 0, False: 174k]
  |  Branch (192:29): [True: 73.5k, False: 101k]
  ------------------
  193|  73.5k|		sc_color_fprintf(color, ctx, ctx->debug_file, "\n");
  194|   174k|	fflush(ctx->debug_file);
  195|       |
  196|       |#ifdef _WIN32
  197|       |	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  198|       |		fclose(ctx->debug_file);
  199|       |	ctx->debug_file = NULL;
  200|       |#endif
  201|   174k|}
log.c:sc_color_fprintf_va:
  265|  1.29M|{
  266|  1.29M|	int r;
  267|       |#ifdef _WIN32
  268|       |	WORD old_attr = 0;
  269|       |	int fd = stream ? fileno(stream) : -1;
  270|       |	HANDLE handle = fd >= 0 ? (HANDLE) _get_osfhandle(fd) : INVALID_HANDLE_VALUE;
  271|       |#endif
  272|       |
  273|  1.29M|	if (!is_a_tty(stream))
  ------------------
  |  Branch (273:6): [True: 1.29M, False: 0]
  ------------------
  274|  1.29M|		colors = 0;
  275|       |
  276|  1.29M|	if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  |  Branch (276:6): [True: 0, False: 1.29M]
  |  Branch (276:17): [True: 0, False: 0]
  |  Branch (276:25): [True: 0, False: 0]
  ------------------
  277|       |#ifdef _WIN32
  278|       |		WORD attr = 0;
  279|       |		CONSOLE_SCREEN_BUFFER_INFO csbi;
  280|       |		GetConsoleScreenBufferInfo(handle, &csbi);
  281|       |		old_attr = csbi.wAttributes;
  282|       |#endif
  283|      0|		set_color(SC_COLOR_FG_RED,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  284|      0|				FOREGROUND_RED,
  285|      0|				"\x1b[31m");
  286|      0|		set_color(SC_COLOR_FG_GREEN,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  287|      0|				FOREGROUND_GREEN,
  288|      0|				"\x1b[32m");
  289|      0|		set_color(SC_COLOR_FG_YELLOW,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  290|      0|				FOREGROUND_GREEN|FOREGROUND_RED,
  291|      0|				"\x1b[33m");
  292|      0|		set_color(SC_COLOR_FG_BLUE,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  293|      0|				FOREGROUND_BLUE,
  294|      0|				"\x1b[34m");
  295|      0|		set_color(SC_COLOR_FG_MAGENTA,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  296|      0|				FOREGROUND_BLUE|FOREGROUND_RED,
  297|      0|				"\x1b[35m");
  298|      0|		set_color(SC_COLOR_FG_CYAN,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  299|      0|				FOREGROUND_BLUE|FOREGROUND_GREEN,
  300|      0|				"\x1b[36m");
  301|      0|		set_color(SC_COLOR_BG_RED,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  302|      0|				FOREGROUND_RED,
  303|      0|				"\x1b[41m");
  304|      0|		set_color(SC_COLOR_BG_GREEN,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  305|      0|				BACKGROUND_GREEN,
  306|      0|				"\x1b[42m");
  307|      0|		set_color(SC_COLOR_BG_YELLOW,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  308|      0|				BACKGROUND_GREEN|BACKGROUND_RED,
  309|      0|				"\x1b[43m");
  310|      0|		set_color(SC_COLOR_BG_BLUE,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  311|      0|				BACKGROUND_BLUE,
  312|      0|				"\x1b[44m");
  313|      0|		set_color(SC_COLOR_BG_MAGENTA,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  314|      0|				BACKGROUND_BLUE|BACKGROUND_RED,
  315|      0|				"\x1b[45m");
  316|      0|		set_color(SC_COLOR_BG_CYAN,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  317|      0|				BACKGROUND_BLUE|BACKGROUND_GREEN,
  318|      0|				"\x1b[46m");
  319|      0|		set_color(SC_COLOR_BOLD,
  ------------------
  |  |  249|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (249:11): [True: 0, False: 0]
  |  |  |  Branch (249:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  320|      0|				FOREGROUND_INTENSITY,
  321|      0|				"\x1b[1m");
  322|       |#ifdef _WIN32
  323|       |		SetConsoleTextAttribute(handle, attr);
  324|       |#endif
  325|      0|	}
  326|       |
  327|  1.29M|	r = vfprintf(stream, format, args);
  328|       |
  329|  1.29M|	if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  |  Branch (329:6): [True: 0, False: 1.29M]
  |  Branch (329:17): [True: 0, False: 0]
  |  Branch (329:25): [True: 0, False: 0]
  ------------------
  330|       |#ifdef _WIN32
  331|       |		SetConsoleTextAttribute(handle, old_attr);
  332|       |#else
  333|      0|		fprintf(stream, "\x1b[0m");
  334|      0|#endif
  335|      0|	}
  336|       |
  337|  1.29M|	return r;
  338|  1.29M|}
log.c:is_a_tty:
  227|  1.29M|{
  228|  1.29M|	if (fp != NULL) {
  ------------------
  |  Branch (228:6): [True: 1.29M, False: 0]
  ------------------
  229|  1.29M|		int fd = fileno(fp);
  230|  1.29M|		if (fd >= 0) {
  ------------------
  |  Branch (230:7): [True: 0, False: 1.29M]
  ------------------
  231|       |#ifdef _WIN32
  232|       |			HANDLE h = (HANDLE)_get_osfhandle(fd);
  233|       |			if (h != INVALID_HANDLE_VALUE) {
  234|       |				return GetFileType(h) == FILE_TYPE_CHAR;
  235|       |			}
  236|       |#else
  237|      0|			return isatty(fd);
  238|      0|#endif
  239|      0|		}
  240|  1.29M|	}
  241|  1.29M|	return 0;
  242|  1.29M|}

mscfs_new:
   44|    596|mscfs_t *mscfs_new(void) {
   45|    596|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   46|    596|	if (!fs)
  ------------------
  |  Branch (46:6): [True: 0, False: 596]
  ------------------
   47|      0|		return NULL;
   48|    596|	memset(fs, 0, sizeof(mscfs_t));
   49|    596|	memcpy(fs->currentPath, "\x3F\x00", 2);
   50|    596|	return fs;
   51|    596|}
mscfs_free:
   53|    596|void mscfs_free(mscfs_t *fs) {
   54|    596|	mscfs_clear_cache(fs);
   55|    596|	free(fs);
   56|    596|}
mscfs_clear_cache:
   58|  1.97k|void mscfs_clear_cache(mscfs_t* fs) {
   59|  1.97k|	if(!fs->cache.array) {
  ------------------
  |  Branch (59:5): [True: 1.62k, False: 346]
  ------------------
   60|  1.62k|		return;
   61|  1.62k|	}
   62|    346|	free(fs->cache.array);
   63|       |	fs->cache.array = NULL;
   64|    346|	fs->cache.totalSize = 0;
   65|    346|	fs->cache.size = 0;
   66|    346|}
mscfs_push_file:
   82|  29.2k|{
   83|  29.2k|	mscfs_cache_t *cache = &fs->cache;
   84|  29.2k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   80|  29.2k|#define MAX_FILES 10000
  ------------------
  |  Branch (84:6): [True: 1, False: 29.2k]
  ------------------
   85|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
   86|  29.2k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (86:5): [True: 346, False: 28.8k]
  |  Branch (86:22): [True: 217, False: 28.6k]
  ------------------
   87|    563|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   34|    563|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   88|    563|		mscfs_file_t *oldArray;
   89|    563|		cache->totalSize = length;
   90|    563|		oldArray = cache->array;
   91|    563|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   92|    563|		if(!cache->array)
  ------------------
  |  Branch (92:6): [True: 0, False: 563]
  ------------------
   93|      0|			return MSCFS_NO_MEMORY;
  ------------------
  |  |   31|      0|#define MSCFS_NO_MEMORY  	SC_ERROR_OUT_OF_MEMORY
  |  |  ------------------
  |  |  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  |  |  ------------------
  ------------------
   94|    563|		if(oldArray) {
  ------------------
  |  Branch (94:6): [True: 217, False: 346]
  ------------------
   95|    217|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   96|    217|			free(oldArray);
   97|    217|		}
   98|    563|	}
   99|  29.2k|	cache->array[cache->size] = *file;
  100|  29.2k|	cache->size++;
  101|  29.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  29.2k|#define SC_SUCCESS				0
  ------------------
  102|  29.2k|}
mscfs_update_cache:
  104|  1.37k|int mscfs_update_cache(mscfs_t* fs) {
  105|  1.37k|	mscfs_file_t file;
  106|  1.37k|	int r;
  107|  1.37k|	mscfs_clear_cache(fs);
  108|  1.37k|	r = fs->listFile(&file, 1, fs->udata);
  109|  1.37k|	if(r == 0)
  ------------------
  |  Branch (109:5): [True: 73, False: 1.30k]
  ------------------
  110|     73|		return 0;
  111|  1.30k|	else if(r < 0)
  ------------------
  |  Branch (111:10): [True: 919, False: 386]
  ------------------
  112|    919|		return r;
  113|  29.2k|	while(1) {
  ------------------
  |  Branch (113:8): [True: 29.2k, Folded]
  ------------------
  114|  29.2k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (114:6): [True: 29.2k, False: 71]
  ------------------
  115|       |			/* Check if its a directory in the root */
  116|  29.2k|			u8* oid = file.objectId.id;
  117|  29.2k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (117:7): [True: 10.0k, False: 19.2k]
  |  Branch (117:22): [True: 6.22k, False: 3.77k]
  ------------------
  118|  6.22k|				oid[2] = oid[0];
  119|  6.22k|				oid[3] = oid[1];
  120|  6.22k|				oid[0] = 0x3F;
  121|  6.22k|				oid[1] = 0x00;
  122|  6.22k|				file.ef = 0;
  123|  22.9k|			} else  {
  124|  22.9k|				file.ef = 1; /* File is a working elementary file */
  125|  22.9k|			}
  126|       |
  127|  29.2k|			r = mscfs_push_file(fs, &file);
  128|  29.2k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  29.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (128:8): [True: 1, False: 29.2k]
  ------------------
  129|      1|				return r;
  130|  29.2k|		}
  131|  29.2k|		r = fs->listFile(&file, 0, fs->udata);
  132|  29.2k|		if(r == 0)
  ------------------
  |  Branch (132:6): [True: 191, False: 29.0k]
  ------------------
  133|    191|			break;
  134|  29.0k|		else if(r < 0)
  ------------------
  |  Branch (134:11): [True: 194, False: 28.8k]
  ------------------
  135|    194|			return r;
  136|  29.2k|	}
  137|    191|	return fs->cache.size;
  138|    386|}
mscfs_check_cache:
  141|  3.45k|{
  142|  3.45k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.45k|#define SC_SUCCESS				0
  ------------------
  143|  3.45k|	if(!fs->cache.array) {
  ------------------
  |  Branch (143:5): [True: 1.37k, False: 2.07k]
  ------------------
  144|  1.37k|		r = mscfs_update_cache(fs);
  145|  1.37k|	}
  146|  3.45k|	return r;
  147|  3.45k|}
mscfs_lookup_path:
  150|  1.50k|{
  151|  1.50k|	u8* oid = objectId->id;
  152|  1.50k|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (152:6): [True: 627, False: 880]
  ------------------
  153|    627|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|    627|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    627|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  154|    880|	if(isDirectory) {
  ------------------
  |  Branch (154:5): [True: 0, False: 880]
  ------------------
  155|       |		/* Directory must be right next to root */
  156|      0|		if ((pathlen == 4 && 0 == memcmp(path, "\x3F\x00", 2)) ||
  ------------------
  |  Branch (156:8): [True: 0, False: 0]
  |  Branch (156:24): [True: 0, False: 0]
  ------------------
  157|      0|		    (pathlen == 2 && 0 == memcmp(fs->currentPath, "\x3F\x00", 2))) {
  ------------------
  |  Branch (157:8): [True: 0, False: 0]
  |  Branch (157:24): [True: 0, False: 0]
  ------------------
  158|      0|			oid[0] = path[pathlen - 2];
  159|      0|			oid[1] = path[pathlen - 1];
  160|      0|			oid[2] = oid[3] = 0;
  161|      0|		} else {
  162|      0|			return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  163|      0|		}
  164|      0|	}
  165|    880|	oid[0] = fs->currentPath[0];
  166|    880|	oid[1] = fs->currentPath[1];
  167|       |	/* Chop off the root in the path */
  168|    880|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (168:5): [True: 829, False: 51]
  |  Branch (168:20): [True: 791, False: 38]
  ------------------
  169|    791|		path += 2;
  170|    791|		pathlen -= 2;
  171|    791|		oid[0] = 0x3F;
  172|    791|		oid[1] = 0x00;
  173|    791|	}
  174|       |	/* Limit to a single directory */
  175|    880|	if(pathlen > 4)
  ------------------
  |  Branch (175:5): [True: 22, False: 858]
  ------------------
  176|     22|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|     22|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|     22|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  177|       |	/* Reset to root */
  178|    858|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (178:5): [True: 528, False: 330]
  |  Branch (178:21): [True: 1, False: 527]
  ------------------
  179|      1|		oid[0] = oid[2] = path[0];
  180|      1|		oid[1] = oid[3] = path[1];
  181|    857|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (181:12): [True: 527, False: 330]
  ------------------
  182|    527|		oid[2] = path[0];
  183|    527|		oid[3] = path[1];
  184|    527|	} else if(pathlen == 4) {
  ------------------
  |  Branch (184:12): [True: 329, False: 1]
  ------------------
  185|    329|		oid[0] = path[0];
  186|    329|		oid[1] = path[1];
  187|    329|		oid[2] = path[2];
  188|    329|		oid[3] = path[3];
  189|    329|	}
  190|       |
  191|    858|	return 0;
  192|    880|}
mscfs_check_selection:
  206|    389|{
  207|    389|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (207:5): [True: 0, False: 389]
  |  Branch (207:32): [True: 0, False: 0]
  ------------------
  208|      0|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  209|    389|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (209:5): [True: 0, False: 389]
  |  Branch (209:26): [True: 0, False: 0]
  |  Branch (209:53): [True: 0, False: 0]
  ------------------
  210|      0|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  211|    389|	return 0;
  212|    389|}
mscfs_loadFileInfo:
  215|  1.50k|{
  216|  1.50k|	msc_id fullPath = {{0, 0, 0, 0}};
  217|  1.50k|	int x, rc;
  218|  1.50k|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (218:6): [True: 0, False: 1.50k]
  |  Branch (218:20): [True: 0, False: 1.50k]
  |  Branch (218:36): [True: 0, False: 1.50k]
  ------------------
  219|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  220|  1.50k|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  221|  1.50k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  1.50k|#define SC_SUCCESS				0
  ------------------
  |  Branch (221:6): [True: 649, False: 858]
  ------------------
  222|    649|		return rc;
  223|    649|	}
  224|       |
  225|       |	/* Obtain file information while checking if it exists */
  226|    858|	rc = mscfs_check_cache(fs);
  227|    858|	if (rc < 0)
  ------------------
  |  Branch (227:6): [True: 27, False: 831]
  ------------------
  228|     27|		return rc;
  229|    831|	if(idx) *idx = -1;
  ------------------
  |  Branch (229:5): [True: 831, False: 0]
  ------------------
  230|  58.9k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (230:13): [True: 58.4k, False: 500]
  ------------------
  231|  58.4k|		*file_data = &fs->cache.array[x];
  232|  58.4k|		if (*file_data) {
  ------------------
  |  Branch (232:7): [True: 58.4k, False: 0]
  ------------------
  233|  58.4k|			msc_id objectId;
  234|  58.4k|			objectId = (*file_data)->objectId;
  235|  58.4k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (235:7): [True: 331, False: 58.1k]
  ------------------
  236|    331|				if (idx)
  ------------------
  |  Branch (236:9): [True: 331, False: 0]
  ------------------
  237|    331|					*idx = x;
  238|    331|				break;
  239|    331|			}
  240|  58.1k|			*file_data = NULL;
  241|  58.1k|		}
  242|  58.4k|	}
  243|    831|	if(*file_data == NULL && (0 == memcmp("\x3F\x00\x00\x00", fullPath.id, 4) || 0 == memcmp("\x3F\x00\x50\x15", fullPath.id, 4 ) || 0 == memcmp("\x3F\x00\x3F\x00", fullPath.id, 4))) {
  ------------------
  |  Branch (243:5): [True: 500, False: 331]
  |  Branch (243:28): [True: 11, False: 489]
  |  Branch (243:79): [True: 243, False: 246]
  |  Branch (243:131): [True: 1, False: 245]
  ------------------
  244|    255|		static mscfs_file_t ROOT_FILE;
  245|    255|		ROOT_FILE.ef = 0;
  246|    255|		ROOT_FILE.size = 0;
  247|       |		/* Faked Root ID */
  248|    255|		ROOT_FILE.objectId = rootId;
  249|       |
  250|    255|		ROOT_FILE.read = 0;
  251|    255|		ROOT_FILE.write = 0x02; /* User Pin access */
  252|    255|		ROOT_FILE.delete = 0x02;
  253|       |
  254|    255|		*file_data = &ROOT_FILE;
  255|    255|		if(idx) *idx = -2;
  ------------------
  |  Branch (255:6): [True: 255, False: 0]
  ------------------
  256|    576|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (256:12): [True: 245, False: 331]
  ------------------
  257|    245|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   33|    245|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    245|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  258|    245|	}
  259|       |
  260|    586|	return 0;
  261|    831|}
muscle-filesystem.c:mscfs_is_ignored:
   69|  29.2k|{
   70|  29.2k|	int ignored = 0;
   71|  29.2k|	const u8** ptr = ignoredFiles;
   72|  87.8k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (72:8): [True: 87.8k, False: 0]
  |  Branch (72:15): [True: 58.5k, False: 29.2k]
  |  Branch (72:23): [True: 58.5k, False: 3]
  ------------------
   73|  58.5k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (73:6): [True: 71, False: 58.4k]
  ------------------
   74|     71|			ignored = 1;
   75|  58.5k|		ptr++;
   76|  58.5k|	}
   77|  29.2k|	return ignored;
   78|  29.2k|}

msc_list_objects:
   37|  30.6k|int msc_list_objects(sc_card_t* card, u8 next, mscfs_file_t* file) {
   38|  30.6k|	sc_apdu_t apdu;
   39|  30.6k|	u8 fileData[14];
   40|  30.6k|	int r;
   41|       |
   42|  30.6k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x58, next, 0x00);
  ------------------
  |  |  301|  30.6k|#define SC_APDU_CASE_2			0x22
  ------------------
   43|  30.6k|	apdu.le = 14;
   44|  30.6k|	apdu.resplen = 14;
   45|  30.6k|	apdu.resp = fileData;
   46|  30.6k|	r = sc_transmit_apdu(card, &apdu);
   47|  30.6k|	if (r)
  ------------------
  |  Branch (47:6): [True: 29, False: 30.6k]
  ------------------
   48|     29|		return r;
   49|       |
   50|  30.6k|	if(apdu.sw1 == 0x9C && apdu.sw2 == 0x12) {
  ------------------
  |  Branch (50:5): [True: 175, False: 30.4k]
  |  Branch (50:25): [True: 23, False: 152]
  ------------------
   51|     23|		return 0;
   52|     23|	}
   53|  30.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   54|  30.6k|	if (r)
  ------------------
  |  Branch (54:6): [True: 1.05k, False: 29.5k]
  ------------------
   55|  1.05k|		return r;
   56|  29.5k|	if(apdu.resplen == 0) /* No more left */
  ------------------
  |  Branch (56:5): [True: 241, False: 29.3k]
  ------------------
   57|    241|		return 0;
   58|  29.3k|	if (apdu.resplen != 14) {
  ------------------
  |  Branch (58:6): [True: 27, False: 29.2k]
  ------------------
   59|     27|		sc_log(card->ctx, "expected 14 bytes, got %zu.\n", apdu.resplen);
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   60|     27|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     27|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   61|     27|	}
   62|  29.2k|	memcpy(file->objectId.id, fileData, 4);
   63|  29.2k|	file->size = bebytes2ulong(fileData + 4);
   64|  29.2k|	file->read = bebytes2ushort(fileData + 8);
   65|  29.2k|	file->write = bebytes2ushort(fileData + 10);
   66|  29.2k|	file->delete = bebytes2ushort(fileData + 12);
   67|       |
   68|  29.2k|	return 1;
   69|  29.3k|}
msc_partial_read_object:
   72|    389|{
   73|    389|	u8 buffer[9];
   74|    389|	sc_apdu_t apdu;
   75|    389|	int r;
   76|       |
   77|    389|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x56, 0x00, 0x00);
  ------------------
  |  |  294|    389|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
   78|       |
   79|    389|	sc_log(card->ctx, "READ: Offset: %x\tLength: %zu\n", offset, dataLength);
  ------------------
  |  |   71|    389|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   80|    389|	memcpy(buffer, objectId.id, 4);
   81|    389|	ulong2bebytes(buffer + 4, offset);
   82|    389|	buffer[8] = (u8)dataLength;
   83|    389|	apdu.data = buffer;
   84|    389|	apdu.datalen = 9;
   85|    389|	apdu.lc = 9;
   86|    389|	apdu.le = dataLength;
   87|    389|	apdu.resplen = dataLength;
   88|    389|	apdu.resp = data;
   89|    389|	r = sc_transmit_apdu(card, &apdu);
   90|    389|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    389|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    389|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    389|	int _ret = (r); \
  |  |  |  |  168|    389|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 380]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|    389|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 380]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|    380|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && dataLength <= apdu.resplen)
  ------------------
  |  Branch (91:6): [True: 299, False: 81]
  |  Branch (91:26): [True: 291, False: 8]
  |  Branch (91:46): [True: 288, False: 3]
  ------------------
   92|    288|		return (int)dataLength;
   93|     92|	if (apdu.sw1 == 0x9C) {
  ------------------
  |  Branch (93:6): [True: 8, False: 84]
  ------------------
   94|      8|		if (apdu.sw2 == 0x07) {
  ------------------
  |  Branch (94:7): [True: 1, False: 7]
  ------------------
   95|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   96|      7|		} else if (apdu.sw2 == 0x06) {
  ------------------
  |  Branch (96:14): [True: 1, False: 6]
  ------------------
   97|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_ALLOWED);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   98|      6|		} else if (apdu.sw2 == 0x0F) {
  ------------------
  |  Branch (98:14): [True: 1, False: 5]
  ------------------
   99|       |			/* GUESSED */
  100|      1|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      1|	int _ret = r; \
  |  |  155|      1|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  ------------------
  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  ------------------
  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      1|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      1|	return _ret; \
  |  |  163|      1|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  101|      1|		}
  102|      8|	}
  103|     89|	sc_log(card->ctx,
  ------------------
  |  |   71|     89|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  104|     89|		"got strange SWs: 0x%02X 0x%02X\n", apdu.sw1, apdu.sw2);
  105|     89|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  153|     89|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     89|	int _ret = r; \
  |  |  155|     89|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 89, False: 0]
  |  |  ------------------
  |  |  156|     89|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     89|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 89, False: 0]
  |  |  ------------------
  |  |  157|     89|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     89|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     89|	return _ret; \
  |  |  163|     89|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  106|     89|}
msc_read_object:
  109|    389|{
  110|    389|	int r = 0;
  111|    389|	unsigned int i;
  112|    389|	size_t max_read_unit = MSC_MAX_READ;
  ------------------
  |  |   35|    389|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 389, False: 0]
  |  |  ------------------
  ------------------
  113|       |
  114|    677|	for (i = 0; i < dataLength; i += r) {
  ------------------
  |  Branch (114:14): [True: 389, False: 288]
  ------------------
  115|    389|		r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit));
  ------------------
  |  |   69|    389|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 118, False: 271]
  |  |  ------------------
  ------------------
  116|    389|		LOG_TEST_RET(card->ctx, r, "Error in partial object read");
  ------------------
  |  |  174|    389|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    389|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    389|	int _ret = (r); \
  |  |  |  |  168|    389|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 101, False: 288]
  |  |  |  |  ------------------
  |  |  |  |  169|    101|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    101|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    101|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    101|		return _ret; \
  |  |  |  |  172|    101|	} \
  |  |  |  |  173|    389|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 288]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|    288|		if (r == 0)
  ------------------
  |  Branch (117:7): [True: 0, False: 288]
  ------------------
  118|      0|			break;
  119|    288|	}
  120|    288|	return (int)dataLength;
  121|    389|}
msc_select_applet:
  256|  6.78k|{
  257|  6.78k|	sc_apdu_t apdu;
  258|  6.78k|	int r;
  259|       |
  260|  6.78k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  6.78k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  261|  6.78k|	apdu.lc = appletIdLength;
  262|  6.78k|	apdu.data = appletId;
  263|  6.78k|	apdu.datalen = appletIdLength;
  264|  6.78k|	apdu.resplen = 0;
  265|  6.78k|	apdu.le = 0;
  266|       |
  267|  6.78k|	r = sc_transmit_apdu(card, &apdu);
  268|  6.78k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.78k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.78k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.78k|	int _ret = (r); \
  |  |  |  |  168|  6.78k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 45, False: 6.73k]
  |  |  |  |  ------------------
  |  |  |  |  169|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     45|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     45|		return _ret; \
  |  |  |  |  172|     45|	} \
  |  |  |  |  173|  6.78k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  6.73k|	if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (269:5): [True: 634, False: 6.10k]
  |  Branch (269:25): [True: 596, False: 38]
  ------------------
  270|    596|		return 1;
  271|       |
  272|  6.14k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  153|  6.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  6.14k|	int _ret = r; \
  |  |  155|  6.14k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 6.14k, False: 0]
  |  |  ------------------
  |  |  156|  6.14k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  6.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 6.14k, False: 0]
  |  |  ------------------
  |  |  157|  6.14k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  6.14k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  6.14k|	return _ret; \
  |  |  163|  6.14k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  273|  6.14k|}

sc_pkcs1_strip_02_padding_constant_time:
  154|     80|{
  155|     80|	unsigned int i = 0;
  156|     80|	u8 *msg, *msg_orig = NULL;
  157|     80|	unsigned int good, found_zero_byte, mask, tmp_outlen;
  158|     80|	unsigned int zero_index = 0, msg_index, mlen = -1, len = 0;
  159|     80|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     80|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     80|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     80|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     80|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 80]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|     80|	if (data == NULL || data_len <= 0 || data_len > n ||
  ------------------
  |  Branch (161:6): [True: 0, False: 80]
  |  Branch (161:22): [True: 4, False: 76]
  |  Branch (161:39): [True: 41, False: 35]
  ------------------
  162|     35|			n < SC_PKCS1_PADDING_MIN_SIZE || out_len == NULL)
  ------------------
  |  |   40|    115|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (162:4): [True: 0, False: 35]
  |  Branch (162:37): [True: 0, False: 35]
  ------------------
  163|     80|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|     35|	tmp_outlen = *out_len;
  166|     35|	msg = msg_orig = calloc(n, sizeof(u8));
  167|     35|	if (msg == NULL)
  ------------------
  |  Branch (167:6): [True: 0, False: 35]
  ------------------
  168|     35|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  169|       |
  170|       |	/*
  171|       |	 * We can not check length of input data straight away and still we need to read
  172|       |	 * from input even when the input is not as long as needed to keep the time constant.
  173|       |	 * If data has wrong size, it is padded by zeroes from left and the following checks
  174|       |	 * do not pass.
  175|       |	 */
  176|     35|	len = data_len;
  177|  8.61k|	for (data += len, msg += n, i = 0; i < n; i++) {
  ------------------
  |  Branch (177:37): [True: 8.57k, False: 35]
  ------------------
  178|  8.57k|		mask = ~constant_time_is_zero(len);
  179|  8.57k|		len -= 1 & mask;
  180|  8.57k|		data -= 1 & mask;
  181|  8.57k|		*--msg = *data & mask;
  182|  8.57k|	}
  183|       |	// check first byte to be 0x00
  184|     35|	good = constant_time_is_zero(msg[0]);
  185|       |	// check second byte to be 0x02
  186|     35|	good &= constant_time_eq(msg[1], 2);
  187|       |
  188|       |	// find zero byte after random data in padding
  189|     35|	found_zero_byte = 0;
  190|  8.54k|	for (i = 2; i < n; i++) {
  ------------------
  |  Branch (190:14): [True: 8.50k, False: 35]
  ------------------
  191|  8.50k|		unsigned int equals0 = constant_time_is_zero(msg[i]);
  192|  8.50k|		zero_index = constant_time_select(~found_zero_byte & equals0, i, zero_index);
  193|  8.50k|		found_zero_byte |= equals0;
  194|  8.50k|	}
  195|       |
  196|       |	// zero_index stands for index of last found zero
  197|     35|	good &= constant_time_ge(zero_index, 2 + 8);
  198|       |
  199|       |	// start of the actual message in data
  200|     35|	msg_index = zero_index + 1;
  201|       |
  202|       |	// length of message
  203|     35|	mlen = data_len - msg_index;
  204|       |
  205|       |	// check that message fits into out buffer
  206|     35|	good &= constant_time_ge(tmp_outlen, mlen);
  207|       |
  208|       |	// move the result in-place by |num|-SC_PKCS1_PADDING_MIN_SIZE-|mlen| bytes to the left.
  209|     35|	tmp_outlen = constant_time_select(constant_time_lt(n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen),
  ------------------
  |  |   40|     35|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  210|     35|			n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen);
  ------------------
  |  |   40|     35|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  211|    312|	for (msg_index = 1; msg_index < n - SC_PKCS1_PADDING_MIN_SIZE; msg_index <<= 1) {
  ------------------
  |  |   40|    312|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (211:22): [True: 277, False: 35]
  ------------------
  212|    277|		mask = ~constant_time_eq(msg_index & (n - SC_PKCS1_PADDING_MIN_SIZE - mlen), 0);
  ------------------
  |  |   40|    277|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  213|  56.9k|		for (i = SC_PKCS1_PADDING_MIN_SIZE; i < n - msg_index; i++)
  ------------------
  |  |   40|    277|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (213:39): [True: 56.6k, False: 277]
  ------------------
  214|  56.6k|			msg[i] = constant_time_select_8(mask, msg[i + msg_index], msg[i]);
  215|    277|	}
  216|       |	// move message into out buffer, if good
  217|  1.99k|	for (i = 0; i < tmp_outlen; i++) {
  ------------------
  |  Branch (217:14): [True: 1.96k, False: 35]
  ------------------
  218|  1.96k|		unsigned int msg_index;
  219|       |		// when out is longer than message in data, use some bogus index in msg
  220|  1.96k|		mask = good & constant_time_lt(i, mlen);
  221|  1.96k|		msg_index = constant_time_select(mask, i + SC_PKCS1_PADDING_MIN_SIZE, 0); // to now overflow msg buffer
  ------------------
  |  |   40|  1.96k|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  222|  1.96k|		out[i] = constant_time_select_8(mask, msg[msg_index], out[i]);
  223|  1.96k|	}
  224|       |
  225|     35|	*out_len = constant_time_select(good, mlen, *out_len);
  226|     35|	free(msg_orig);
  227|     35|	return constant_time_select(good, mlen, SC_ERROR_WRONG_PADDING);
  ------------------
  |  |   93|     35|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  228|     35|}
sc_pkcs1_encode:
  612|    101|{
  613|    101|	int    rv, i;
  614|    101|	size_t tmp_len = *out_len;
  615|    101|	const u8    *tmp = in;
  616|    101|	unsigned int hash_algo, pad_algo;
  617|    101|	size_t mod_len = BYTES4BITS(mod_bits);
  ------------------
  |  |  145|    101|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  618|    101|#ifdef ENABLE_OPENSSL
  619|    101|	size_t sLen;
  620|    101|	EVP_MD* md = NULL;
  621|    101|	unsigned int mgf1_hash;
  622|    101|#endif
  623|       |
  624|    101|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    101|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    101|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    101|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    101|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 101]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|       |
  626|    101|	hash_algo = flags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|    101|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  627|    101|	pad_algo  = flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|    101|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  628|    101|	if (pad_algo == 0)
  ------------------
  |  Branch (628:6): [True: 65, False: 36]
  ------------------
  629|     65|		pad_algo = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|     65|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  630|    101|	sc_log(ctx, "hash algorithm 0x%X, pad algorithm 0x%X", hash_algo, pad_algo);
  ------------------
  |  |   71|    101|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  631|       |
  632|    101|	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  109|    202|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  104|     65|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (632:7): [True: 36, False: 65]
  |  Branch (632:57): [True: 65, False: 0]
  ------------------
  633|    101|	    hash_algo != SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|    101|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (633:6): [True: 101, False: 0]
  ------------------
  634|    101|		i = sc_pkcs1_add_digest_info_prefix(hash_algo, in, in_len, out, &tmp_len);
  635|    101|		if (i != SC_SUCCESS) {
  ------------------
  |  |   28|    101|#define SC_SUCCESS				0
  ------------------
  |  Branch (635:7): [True: 21, False: 80]
  ------------------
  636|     21|			sc_log(ctx, "Unable to add digest info 0x%x", hash_algo);
  ------------------
  |  |   71|     21|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  637|     21|			LOG_FUNC_RETURN(ctx, i);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|     21|		}
  639|     80|		tmp = out;
  640|     80|	} else   {
  641|      0|		tmp_len = in_len;
  642|      0|	}
  643|       |
  644|     80|	switch(pad_algo) {
  645|     46|	case SC_ALGORITHM_RSA_PAD_NONE:
  ------------------
  |  |  104|     46|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (645:2): [True: 46, False: 34]
  ------------------
  646|       |		/* padding done by card => nothing to do */
  647|     46|		if (out != tmp)
  ------------------
  |  Branch (647:7): [True: 0, False: 46]
  ------------------
  648|      0|			memcpy(out, tmp, tmp_len);
  649|     46|		*out_len = tmp_len;
  650|     46|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     46|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     46|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     46|	int _ret = r; \
  |  |  |  |  155|     46|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 46, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  157|     46|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     46|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     46|	return _ret; \
  |  |  |  |  163|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|     34|	case SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01:
  ------------------
  |  |  109|     34|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (651:2): [True: 34, False: 46]
  ------------------
  652|       |		/* add pkcs1 bt01 padding */
  653|     34|		rv = sc_pkcs1_add_01_padding(tmp, tmp_len, out, out_len, mod_len);
  654|     34|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|      0|	case SC_ALGORITHM_RSA_PAD_PSS:
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (655:2): [True: 0, False: 80]
  ------------------
  656|       |		/* add PSS padding */
  657|      0|#ifdef ENABLE_OPENSSL
  658|      0|		mgf1_hash = flags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  659|      0|		if (hash_algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (659:7): [True: 0, False: 0]
  ------------------
  660|       |			/* this is generic RSA_PKCS1_PSS mechanism with hash
  661|       |			 * already done outside of the module. The parameters
  662|       |			 * were already checked so we need to adjust the hash
  663|       |			 * algorithm to do the padding with the correct hash
  664|       |			 * function.
  665|       |			 */
  666|      0|			hash_algo = hash_len2algo(tmp_len);
  667|      0|		}
  668|       |		/* sLen is by default same as hash length */
  669|      0|		if (!(md = hash_flag2md(ctx, hash_algo))) {
  ------------------
  |  Branch (669:7): [True: 0, False: 0]
  ------------------
  670|      0|			sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  671|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|      0|		}
  673|      0|		sLen = EVP_MD_size(md);
  674|      0|		sc_evp_md_free(md);
  675|       |		/* if application provide sLen, use it */
  676|      0|		if (pMechanism != NULL) {
  ------------------
  |  Branch (676:7): [True: 0, False: 0]
  ------------------
  677|      0|			CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
  678|      0|			CK_RSA_PKCS_PSS_PARAMS *pss_params;
  679|      0|			if (mech->pParameter && sizeof(CK_RSA_PKCS_PSS_PARAMS) == mech->ulParameterLen) {
  ------------------
  |  Branch (679:8): [True: 0, False: 0]
  |  Branch (679:28): [True: 0, False: 0]
  ------------------
  680|      0|				pss_params = mech->pParameter;
  681|      0|				sLen = pss_params->sLen;
  682|      0|			}
  683|      0|		}
  684|      0|		rv = sc_pkcs1_add_pss_padding(ctx, hash_algo, mgf1_hash,
  685|      0|		    tmp, tmp_len, out, out_len, mod_bits, sLen);
  686|       |#else
  687|       |		rv = SC_ERROR_NOT_SUPPORTED;
  688|       |#endif
  689|      0|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  690|      0|	default:
  ------------------
  |  Branch (690:2): [True: 0, False: 80]
  ------------------
  691|       |		/* We shouldn't be called with an unexpected padding type, we've already
  692|       |		 * returned SC_ERROR_NOT_SUPPORTED if the card can't be used. */
  693|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|     80|	}
  695|     80|}
sc_get_encoding_flags:
  700|    440|{
  701|    440|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    440|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    440|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    440|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    440|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 440]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|    440|	if (pflags == NULL || sflags == NULL)
  ------------------
  |  Branch (702:6): [True: 0, False: 440]
  |  Branch (702:24): [True: 0, False: 440]
  ------------------
  703|    440|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  704|       |
  705|    440|	sc_log(ctx, "iFlags 0x%lX, card capabilities 0x%lX", iflags, caps);
  ------------------
  |  |   71|    440|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  706|       |
  707|       |	/* For ECDSA and GOSTR, we don't do any padding or hashing ourselves, the
  708|       |	 * card has to support the requested operation.  Similarly, for RSA with
  709|       |	 * raw padding (raw RSA) and ISO9796, we require the card to do it for us.
  710|       |	 * Finally, for PKCS1 (v1.5 and PSS) and ASNI X9.31 we can apply the padding
  711|       |	 * ourselves if the card supports raw RSA. */
  712|       |
  713|       |	/* TODO: Could convert GOSTR3410_HASH_GOSTR3411 -> GOSTR3410_RAW and
  714|       |	 *       ECDSA_HASH_ -> ECDSA_RAW using OpenSSL (not much benefit though). */
  715|       |
  716|    440|	if ((caps & iflags) == iflags) {
  ------------------
  |  Branch (716:6): [True: 111, False: 329]
  ------------------
  717|       |		/* Card supports the signature operation we want to do, great, let's
  718|       |		 * go with it then. */
  719|    111|		*sflags = iflags;
  720|    111|		*pflags = 0;
  721|       |
  722|    329|	} else if ((caps & SC_ALGORITHM_RSA_PAD_PSS) &&
  ------------------
  |  |  107|    329|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (722:13): [True: 0, False: 329]
  ------------------
  723|      0|			(iflags & SC_ALGORITHM_RSA_PAD_PSS)) {
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (723:4): [True: 0, False: 0]
  ------------------
  724|      0|		*sflags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  725|      0|		*sflags |= iflags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  726|      0|		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  727|       |
  728|    329|	} else if ((caps & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|    329|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (728:13): [True: 203, False: 126]
  ------------------
  729|    203|				(iflags & SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    406|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    203|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    203|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (729:6): [True: 199, False: 4]
  ------------------
  730|      4|				|| iflags & SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  107|    207|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (730:8): [True: 0, False: 4]
  ------------------
  731|      4|#ifdef ENABLE_OPENSSL
  732|      4|				|| iflags & SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  108|    207|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (732:8): [True: 0, False: 4]
  ------------------
  733|      4|#endif
  734|    199|				|| iflags & SC_ALGORITHM_RSA_PAD_NONE)) {
  ------------------
  |  |  104|      4|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (734:8): [True: 0, False: 4]
  ------------------
  735|       |		/* Use the card's raw RSA capability on the padded input */
  736|    199|		*sflags = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|    199|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  737|    199|		*pflags = iflags;
  738|       |
  739|    199|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|    130|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|    130|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (739:13): [True: 128, False: 2]
  ------------------
  740|    128|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|    128|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (740:4): [True: 57, False: 71]
  ------------------
  741|       |		/* A corner case - the card can partially do PKCS1, if we prepend the
  742|       |		 * DigestInfo bit it will do the rest. */
  743|     57|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  109|     57|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     57|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  744|     57|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     57|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  745|       |
  746|     73|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  110|     73|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
              	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|     73|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (746:13): [True: 71, False: 2]
  ------------------
  747|     71|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  110|     71|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (747:4): [True: 68, False: 3]
  ------------------
  748|     68|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  110|     68|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
              		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     68|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  749|     68|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     68|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  750|       |
  751|     68|	} else if ((iflags & SC_ALGORITHM_AES) == SC_ALGORITHM_AES) { /* TODO: seems like this constant does not belong to the same set of flags used form asymmetric algos. Fix this! */
  ------------------
  |  |   79|      5|#define SC_ALGORITHM_AES		67
  ------------------
              	} else if ((iflags & SC_ALGORITHM_AES) == SC_ALGORITHM_AES) { /* TODO: seems like this constant does not belong to the same set of flags used form asymmetric algos. Fix this! */
  ------------------
  |  |   79|      5|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (751:13): [True: 0, False: 5]
  ------------------
  752|      0|		*sflags = 0;
  753|      0|		*pflags = 0;
  754|       |
  755|      5|	} else if ((iflags & SC_ALGORITHM_AES_FLAGS) > 0) {
  ------------------
  |  |  209|      5|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  |  Branch (755:13): [True: 0, False: 5]
  ------------------
  756|      0|		*sflags = iflags & SC_ALGORITHM_AES_FLAGS;
  ------------------
  |  |  209|      0|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  757|      0|		if (iflags & SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (757:7): [True: 0, False: 0]
  ------------------
  758|      0|			*pflags = SC_ALGORITHM_AES_CBC_PAD;
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  759|      0|		else
  760|      0|			*pflags = 0;
  761|       |
  762|      5|	} else {
  763|      5|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported algorithm");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  764|      5|	}
  765|       |
  766|    435|	sc_log(ctx, "pad flags 0x%lX, secure algorithm flags 0x%lX", *pflags, *sflags);
  ------------------
  |  |   71|    435|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  767|    435|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    435|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    435|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    435|	int _ret = r; \
  |  |  |  |  155|    435|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 435, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    435|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 435]
  |  |  |  |  ------------------
  |  |  |  |  157|    435|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    435|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    435|	return _ret; \
  |  |  |  |  163|    435|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  768|    435|}
padding.c:sc_pkcs1_add_digest_info_prefix:
  381|    101|{
  382|    101|	int i;
  383|       |
  384|    277|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (384:14): [True: 277, False: 0]
  ------------------
  385|    277|		if (algorithm == digest_info_prefix[i].algorithm) {
  ------------------
  |  Branch (385:7): [True: 101, False: 176]
  ------------------
  386|    101|			const u8 *hdr      = digest_info_prefix[i].hdr;
  387|    101|			size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  388|    101|			          hash_len = digest_info_prefix[i].hash_len;
  389|       |
  390|    101|			if (in_len != hash_len || *out_len < (hdr_len + hash_len))
  ------------------
  |  Branch (390:8): [True: 20, False: 81]
  |  Branch (390:30): [True: 1, False: 80]
  ------------------
  391|     21|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     21|#define SC_ERROR_INTERNAL			-1400
  ------------------
  392|       |
  393|     80|			memmove(out + hdr_len, in, hash_len);
  394|     80|			memmove(out, hdr, hdr_len);
  395|     80|			*out_len = hdr_len + hash_len;
  396|       |
  397|     80|			return SC_SUCCESS;
  ------------------
  |  |   28|     80|#define SC_SUCCESS				0
  ------------------
  398|    101|		}
  399|    277|	}
  400|       |
  401|      0|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  402|    101|}
padding.c:sc_pkcs1_add_01_padding:
   97|     34|{
   98|     34|	size_t i;
   99|       |
  100|     34|	if (*out_len < mod_length)
  ------------------
  |  Branch (100:6): [True: 0, False: 34]
  ------------------
  101|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  102|     34|	if (in_len + 11 > mod_length)
  ------------------
  |  Branch (102:6): [True: 0, False: 34]
  ------------------
  103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  104|     34|	i = mod_length - in_len;
  105|     34|	memmove(out + i, in, in_len);
  106|     34|	*out++ = 0x00;
  107|     34|	*out++ = 0x01;
  108|       |
  109|     34|	memset(out, 0xFF, i - 3);
  110|     34|	out += i - 3;
  111|     34|	*out = 0x00;
  112|       |
  113|     34|	*out_len = mod_length;
  114|     34|	return SC_SUCCESS;
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
  115|     34|}

sc_asn1_decode_algorithm_id:
  509|    934|{
  510|    934|	struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
  511|    934|	struct sc_asn1_entry asn1_alg_id[3];
  512|    934|	int r;
  513|       |
  514|    934|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    934|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    934|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    934|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    934|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 934]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|    934|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  516|    934|	sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
  517|       |
  518|    934|	memset(id, 0, sizeof(*id));
  519|    934|	r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
  520|    934|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
  ------------------
  |  |  174|    934|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    934|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    934|	int _ret = (r); \
  |  |  |  |  168|    934|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 920]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|    934|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 920]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|       |
  522|    920|        sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|    920|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|       |
  524|       |	/* See if we understand the algorithm, and if we do, check
  525|       |	 * whether we know how to decode any additional parameters */
  526|    920|	id->algorithm = (unsigned int ) -1;
  527|    920|	alg_info = sc_asn1_get_algorithm_info(id);
  528|    920|	if (alg_info != NULL) {
  ------------------
  |  Branch (528:6): [True: 511, False: 409]
  ------------------
  529|    511|		id->algorithm = alg_info->id;
  530|    511|		if (alg_info->decode) {
  ------------------
  |  Branch (530:7): [True: 214, False: 297]
  ------------------
  531|    214|			if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    214|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (531:8): [True: 10, False: 204]
  ------------------
  532|     10|				sc_log(ctx, "SC_ASN1_PRESENT was set, so invalid");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  533|     10|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|     10|			}
  535|    204|			r = alg_info->decode(ctx, &id->params, in, len, depth);
  536|    204|		}
  537|    511|	}
  538|       |
  539|    910|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    910|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    910|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    910|	int _ret = r; \
  |  |  |  |  155|    910|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 910, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    910|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 899]
  |  |  |  |  ------------------
  |  |  |  |  157|    910|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    910|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    910|	return _ret; \
  |  |  |  |  163|    910|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|    910|}
sc_asn1_encode_algorithm_id:
  546|    363|{
  547|    363|	struct sc_asn1_pkcs15_algorithm_info *alg_info;
  548|    363|	struct sc_algorithm_id temp_id;
  549|    363|	struct sc_asn1_entry asn1_alg_id[3];
  550|    363|	u8 *obj = NULL;
  551|    363|	size_t obj_len = 0;
  552|    363|	int r;
  553|    363|	u8 *tmp;
  554|       |
  555|    363|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    363|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    363|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|    363|        sc_log(ctx, "type of algorithm to encode: %lu", id->algorithm);
  ------------------
  |  |   71|    363|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  557|    363|	alg_info = sc_asn1_get_algorithm_info(id);
  558|    363|	if (alg_info == NULL) {
  ------------------
  |  Branch (558:6): [True: 0, False: 363]
  ------------------
  559|      0|		sc_log(ctx, "Cannot encode unknown algorithm %lu", id->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  560|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  561|      0|	}
  562|       |
  563|       |	/* Set the oid if not yet given */
  564|    363|	if (!sc_valid_oid(&id->oid)) {
  ------------------
  |  Branch (564:6): [True: 34, False: 329]
  ------------------
  565|     34|		temp_id = *id;
  566|     34|		temp_id.oid = alg_info->oid;
  567|     34|		id = &temp_id;
  568|     34|	}
  569|       |
  570|    363|        sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|    363|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  571|    363|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  572|    363|	sc_format_asn1_entry(asn1_alg_id + 0, (void *) &id->oid, NULL, 1);
  573|       |
  574|       |	/* no parameters, write NULL tag */
  575|       |	/* If it's EDDSA/XEDDSA, according to RFC8410, params
  576|       |	 * MUST be absent */
  577|       |	/* PKCS11 3.0 list them under ec_params */
  578|    363|	if (id->algorithm != SC_ALGORITHM_EDDSA &&
  ------------------
  |  |   72|    726|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (578:6): [True: 352, False: 11]
  ------------------
  579|    352|	    id->algorithm != SC_ALGORITHM_XEDDSA &&
  ------------------
  |  |   73|    715|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (579:6): [True: 340, False: 12]
  ------------------
  580|    340|	    (!id->params || !alg_info->encode))
  ------------------
  |  Branch (580:7): [True: 265, False: 75]
  |  Branch (580:22): [True: 0, False: 75]
  ------------------
  581|    265|		asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|    265|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  582|       |
  583|    363|	r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
  584|    363|	LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
  ------------------
  |  |  174|    363|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    363|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    363|	int _ret = (r); \
  |  |  |  |  168|    363|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 363]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    363|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 363]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|       |	/* Encode any parameters */
  587|    363|	if (id->params && alg_info->encode) {
  ------------------
  |  Branch (587:6): [True: 75, False: 288]
  |  Branch (587:20): [True: 75, False: 0]
  ------------------
  588|     75|		r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
  589|     75|		if (r < 0) {
  ------------------
  |  Branch (589:7): [True: 0, False: 75]
  ------------------
  590|      0|			if (obj)
  ------------------
  |  Branch (590:8): [True: 0, False: 0]
  ------------------
  591|      0|				free(obj);
  592|      0|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  593|      0|		}
  594|     75|	}
  595|       |
  596|    363|	if (obj_len) {
  ------------------
  |  Branch (596:6): [True: 75, False: 288]
  ------------------
  597|     75|		tmp = (u8 *) realloc(*buf, *len + obj_len);
  598|     75|		if (!tmp) {
  ------------------
  |  Branch (598:7): [True: 0, False: 75]
  ------------------
  599|      0|			free(*buf);
  600|      0|			*buf = NULL;
  601|      0|			free(obj);
  602|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  603|      0|		}
  604|     75|		*buf = tmp;
  605|     75|		memcpy(*buf + *len, obj, obj_len);
  606|     75|		*len += obj_len;
  607|     75|		free(obj);
  608|     75|	}
  609|       |
  610|    363|	sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
  ------------------
  |  |   71|    363|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  611|    363|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    363|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    363|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    363|	int _ret = r; \
  |  |  |  |  155|    363|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 363, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    363|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 363]
  |  |  |  |  ------------------
  |  |  |  |  157|    363|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    363|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    363|	return _ret; \
  |  |  |  |  163|    363|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|    363|}
sc_asn1_clear_algorithm_id:
  616|  1.32k|{
  617|  1.32k|	struct sc_asn1_pkcs15_algorithm_info *aip;
  618|       |
  619|  1.32k|	if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
  ------------------
  |  Branch (619:6): [True: 231, False: 1.09k]
  |  Branch (619:20): [True: 231, False: 0]
  |  Branch (619:62): [True: 231, False: 0]
  ------------------
  620|    231|		aip->free(id->params);
  621|       |		id->params = NULL;
  622|    231|	}
  623|  1.32k|}
pkcs15-algo.c:sc_asn1_get_algorithm_info:
  485|  1.51k|{
  486|  1.51k|	struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
  487|       |
  488|  18.3k|	for (aip = algorithm_table; aip->id >= 0; aip++)   {
  ------------------
  |  Branch (488:30): [True: 17.8k, False: 409]
  ------------------
  489|  17.8k|		if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
  ------------------
  |  Branch (489:7): [True: 12.0k, False: 5.79k]
  |  Branch (489:34): [True: 511, False: 11.5k]
  ------------------
  490|    511|			return aip;
  491|       |
  492|  17.3k|		if (aip->id == (int)id->algorithm)
  ------------------
  |  Branch (492:7): [True: 594, False: 16.7k]
  ------------------
  493|    594|			return aip;
  494|  17.3k|	}
  495|       |
  496|    409|	return NULL;
  497|  1.51k|}
pkcs15-algo.c:asn1_decode_ec_params:
  264|    204|{
  265|    204|	int r;
  266|    204|	struct sc_object_id curve;
  267|    204|	struct sc_asn1_entry asn1_ec_params[4];
  268|    204|	struct sc_ec_parameters *ecp;
  269|       |
  270|    204|	memset(&curve, 0, sizeof(curve));
  271|       |
  272|       |	/* We only want to copy the parms if they are a namedCurve
  273|       |	 * or ecParameters  nullParam aka implicityCA is not to be
  274|       |	 * used with PKCS#11 2.20 */
  275|    204|	sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
  276|    204|	sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
  277|       |
  278|       |	/* Some signature algorithms will not have any data */
  279|    204|	if (buflen == 0 || buf == NULL)
  ------------------
  |  Branch (279:6): [True: 37, False: 167]
  |  Branch (279:21): [True: 0, False: 167]
  ------------------
  280|     37|		return 0;
  281|       |
  282|    167|	r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
  283|       |	/* r = index in asn1_ec_params */
  284|    167|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
  ------------------
  |  |   70|    167|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|    167|	if (r < 0)
  ------------------
  |  Branch (285:6): [True: 11, False: 156]
  ------------------
  286|     11|		return r;
  287|       |
  288|    156|	ecp = calloc(1, sizeof(struct sc_ec_parameters));
  289|    156|	if (ecp == NULL)
  ------------------
  |  Branch (289:6): [True: 0, False: 156]
  ------------------
  290|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  291|       |
  292|    156|	if (r <= 1) {
  ------------------
  |  Branch (292:6): [True: 156, False: 0]
  ------------------
  293|    156|		ecp->der.value = malloc(buflen);
  294|    156|		if (ecp->der.value == NULL) {
  ------------------
  |  Branch (294:7): [True: 0, False: 156]
  ------------------
  295|      0|			free(ecp);
  296|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  297|      0|		}
  298|    156|		ecp->der.len = buflen;
  299|    156|		memcpy(ecp->der.value, buf, buflen);
  300|    156|	}
  301|      0|	else    {
  302|      0|		r = 0;
  303|      0|	}
  304|       |
  305|    156|	ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
  306|    156|	*paramp = ecp;
  307|    156|	return SC_SUCCESS;
  ------------------
  |  |   28|    156|#define SC_SUCCESS				0
  ------------------
  308|    156|};
pkcs15-algo.c:asn1_encode_ec_params:
  313|     75|{
  314|     75|	 struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  315|       |
  316|       |	/* Only handle named curves. They may be absent too */
  317|     75|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
  ------------------
  |  |   70|     75|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|     75|	*buf = NULL;
  319|     75|	*buflen = 0;
  320|     75|	if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
  ------------------
  |  Branch (320:6): [True: 75, False: 0]
  |  Branch (320:13): [True: 75, False: 0]
  |  Branch (320:31): [True: 75, False: 0]
  ------------------
  321|     75|		*buf = malloc(ecp->der.len);
  322|     75|		if (*buf == NULL)
  ------------------
  |  Branch (322:7): [True: 0, False: 75]
  ------------------
  323|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  324|       |
  325|     75|		memcpy(*buf, ecp->der.value, ecp->der.len);
  326|     75|		*buflen = ecp->der.len;
  327|     75|	}
  328|      0|	else   {
  329|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Not named curve");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  330|      0|	}
  331|       |
  332|     75|	return 0;
  333|     75|}
pkcs15-algo.c:asn1_free_ec_params:
  337|    231|{
  338|    231|	struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  339|       |
  340|    231|	if (ecp) {
  ------------------
  |  Branch (340:6): [True: 231, False: 0]
  ------------------
  341|    231|		if (ecp->der.value)
  ------------------
  |  Branch (341:7): [True: 231, False: 0]
  ------------------
  342|    231|			free(ecp->der.value);
  343|    231|		if (ecp->named_curve)
  ------------------
  |  Branch (343:7): [True: 0, False: 231]
  ------------------
  344|      0|			free(ecp->named_curve);
  345|    231|		free(ecp);
  346|    231|	}
  347|    231|}

sc_pkcs15emu_cac_init_ex:
  371|  10.5k|{
  372|  10.5k|	sc_card_t   *card = p15card->card;
  373|  10.5k|	sc_context_t    *ctx = card->ctx;
  374|       |
  375|  10.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  10.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|       |
  377|  10.5k|	if (cac_detect_card(p15card))
  ------------------
  |  Branch (377:6): [True: 9.59k, False: 952]
  ------------------
  378|  9.59k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.59k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  379|    952|	return sc_pkcs15emu_cac_init(p15card);
  380|  10.5k|}
pkcs15-cac.c:cac_detect_card:
   65|  10.5k|{
   66|  10.5k|	sc_card_t *card = p15card->card;
   67|       |
   68|  10.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
   69|  10.5k|	if (card->type < SC_CARD_TYPE_CAC_GENERIC
  ------------------
  |  Branch (69:6): [True: 8.98k, False: 1.56k]
  ------------------
   70|  1.56k|		|| card->type >= SC_CARD_TYPE_CAC_GENERIC+1000)
  ------------------
  |  Branch (70:6): [True: 611, False: 952]
  ------------------
   71|  9.59k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  9.59k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   72|    952|	return SC_SUCCESS;
  ------------------
  |  |   28|    952|#define SC_SUCCESS				0
  ------------------
   73|  10.5k|}
pkcs15-cac.c:sc_pkcs15emu_cac_init:
   89|    952|{
   90|    952|	static const pindata pins[] = {
   91|    952|		{ "1", "PIN", "", 0x00,
   92|    952|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    952|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
   93|    952|		  8, 4, 8,
   94|    952|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    952|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
   95|    952|		  SC_PKCS15_PIN_FLAG_INITIALIZED ,
  ------------------
  |  |   58|    952|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
   96|    952|		  -1, 0xFF,
   97|    952|		  SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|    952|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   98|    952|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   99|    952|	};
  100|       |	/* oid for key usage */
  101|    952|	static const struct sc_object_id usage_type = {{ 2, 5, 29, 15, -1 }};
  102|    952|	unsigned int usage;
  103|       |
  104|       |
  105|       |	/*
  106|       |	 * The size of the key or the algid is not really known
  107|       |	 * but can be derived from the certificates.
  108|       |	 * the cert, pubkey and privkey are a set.
  109|       |	 * Key usages bits taken from certificate key usage extension.
  110|       |	 */
  111|       |
  112|    952|	int    r, i;
  113|    952|	sc_card_t *card = p15card->card;
  114|    952|	sc_serial_number_t serial;
  115|    952|	char buf[SC_MAX_SERIALNR * 2 + 1];
  116|    952|	int count;
  117|    952|	char *token_name = NULL;
  118|       |
  119|       |
  120|    952|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    952|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    952|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    952|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 952]
  |  |  ------------------
  ------------------
  121|       |
  122|    952|	memset(&serial, 0, sizeof(serial));
  123|       |
  124|       |	/* could read this off card if needed */
  125|       |
  126|    952|	set_string(&p15card->tokeninfo->label, cac_get_name(card->type));
  127|    952|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   46|    952|#define MANU_ID		"Common Access Card"
  ------------------
  128|       |
  129|       |	/*
  130|       |	 * get serial number
  131|       |	 */
  132|    952|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  133|    952|	if (r < 0) {
  ------------------
  |  Branch (133:6): [True: 745, False: 207]
  ------------------
  134|    745|		sc_log(card->ctx, "sc_card_ctl rc=%d",r);
  ------------------
  |  |   71|    745|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  135|    745|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  136|    745|	} else {
  137|    207|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  138|    207|		set_string(&p15card->tokeninfo->serial_number, buf);
  139|    207|	}
  140|       |
  141|       |	/* set pins */
  142|       |	/* TODO we should not create PIN objects if it is not initialized
  143|       |	 * (opensc-tool -s 0020000000 returns 0x6A 0x88)
  144|       |	 */
  145|    952|	sc_log(card->ctx,  "CAC adding pins...");
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  146|  1.90k|	for (i = 0; pins[i].id; i++) {
  ------------------
  |  Branch (146:14): [True: 952, False: 952]
  ------------------
  147|    952|		struct sc_pkcs15_auth_info pin_info;
  148|    952|		struct sc_pkcs15_object   pin_obj;
  149|    952|		const char * label;
  150|       |
  151|    952|		memset(&pin_info, 0, sizeof(pin_info));
  152|    952|		memset(&pin_obj,  0, sizeof(pin_obj));
  153|       |
  154|    952|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    952|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  155|    952|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  156|    952|		pin_info.attrs.pin.reference     = pins[i].ref;
  157|    952|		pin_info.attrs.pin.flags         = pins[i].flags;
  158|    952|		pin_info.attrs.pin.type          = pins[i].type;
  159|    952|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  160|    952|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  161|    952|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  162|    952|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  163|    952|		sc_format_path(pins[i].path, &pin_info.path);
  164|    952|		pin_info.tries_left    = -1;
  165|       |
  166|    952|		label = pins[i].label;
  167|    952|		sc_log(card->ctx,  "CAC Adding pin %d label=%s",i, label);
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  168|    952|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    952|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  169|    952|		pin_obj.flags = pins[i].obj_flags;
  170|       |
  171|       |		/* get the ACA path in case it needs to be selected before PIN verify */
  172|    952|		r = sc_card_ctl(card, SC_CARDCTL_CAC_GET_ACA_PATH, &pin_info.path);
  173|    952|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get ACA path.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|    952|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  176|    952|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  177|    952|	}
  178|       |
  179|       |	/* set other objects */
  180|    952|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_INIT_GET_GENERIC_OBJECTS, &count);
  181|    952|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate generic objects.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|  1.84k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (183:14): [True: 892, False: 952]
  ------------------
  184|    892|		struct sc_pkcs15_data_info obj_info;
  185|    892|		struct sc_pkcs15_object    obj_obj;
  186|       |
  187|    892|		r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_GET_NEXT_GENERIC_OBJECT, &obj_info);
  188|    892|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next generic object.");
  ------------------
  |  |  184|    892|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    892|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    892|	int _ret = (r); \
  |  |  |  |  178|    892|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 892]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    892|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 892]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    892|		memset(&obj_obj, 0, sizeof(obj_obj));
  190|    892|		memcpy(obj_obj.label, obj_info.app_label, sizeof(obj_obj.label));
  191|       |
  192|    892|		r = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    892|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  193|    892|			&obj_obj, &obj_info);
  194|    892|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize generic object.");
  ------------------
  |  |  184|    892|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    892|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    892|	int _ret = (r); \
  |  |  |  |  178|    892|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 892]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    892|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 892]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|    892|	}
  196|    952|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_FINAL_GET_GENERIC_OBJECTS, &count);
  197|    952|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize generic objects.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|       |	/*
  200|       |	 * certs, pubkeys and priv keys are related and we assume
  201|       |	 * they are in order
  202|       |	 * We need to read the cert, get modulus and keylen
  203|       |	 * We use those for the pubkey, and priv key objects.
  204|       |	 */
  205|    952|	sc_log(card->ctx,  "CAC adding certs, pub and priv keys...");
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  206|    952|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_INIT_GET_CERT_OBJECTS, &count);
  207|    952|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate cert objects.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|  3.71k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (209:14): [True: 2.76k, False: 952]
  ------------------
  210|  2.76k|		struct sc_pkcs15_data_info obj_info;
  211|  2.76k|		struct sc_pkcs15_cert_info cert_info;
  212|  2.76k|		struct sc_pkcs15_pubkey_info pubkey_info;
  213|  2.76k|		struct sc_pkcs15_prkey_info prkey_info;
  214|  2.76k|		struct sc_pkcs15_object cert_obj;
  215|  2.76k|		struct sc_pkcs15_object pubkey_obj;
  216|  2.76k|		struct sc_pkcs15_object prkey_obj;
  217|  2.76k|		sc_pkcs15_der_t   cert_der;
  218|  2.76k|		sc_pkcs15_cert_t *cert_out = NULL;
  219|       |
  220|  2.76k|		r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_GET_NEXT_CERT_OBJECT, &obj_info);
  221|  2.76k|		LOG_TEST_RET(card->ctx, r, "Can not get next object");
  ------------------
  |  |  174|  2.76k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.76k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.76k|	int _ret = (r); \
  |  |  |  |  168|  2.76k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.76k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  2.76k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.76k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|       |
  223|  2.76k|		memset(&cert_info, 0, sizeof(cert_info));
  224|  2.76k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  225|  2.76k|		memset(&prkey_info, 0, sizeof(prkey_info));
  226|  2.76k|		memset(&cert_obj,  0, sizeof(cert_obj));
  227|  2.76k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  228|  2.76k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  229|       |
  230|  2.76k|		cert_info.id = obj_info.id;
  231|  2.76k|		pubkey_info.id = obj_info.id;
  232|  2.76k|		prkey_info.id = obj_info.id;
  233|  2.76k|		cert_info.path = obj_info.path;
  234|  2.76k|		prkey_info.path = obj_info.path;
  235|       |		/* Add 0x3f00 to the front of prkey_info.path to make sc_key_file happy */
  236|       |		/* only do this if our path.len is 1 or 2 */
  237|  2.76k|		if (prkey_info.path.len && prkey_info.path.len <= 2) {
  ------------------
  |  Branch (237:7): [True: 845, False: 1.91k]
  |  Branch (237:30): [True: 845, False: 0]
  ------------------
  238|    845|			prkey_info.path.value[2] = prkey_info.path.value[0];
  239|    845|			prkey_info.path.value[3] = prkey_info.path.value[1];
  240|    845|			prkey_info.path.value[0] = 0x3f;
  241|    845|			prkey_info.path.value[1] = 0x00;
  242|    845|			prkey_info.path.len += 2;
  243|    845|		}
  244|  2.76k|		pubkey_info.native        = 1;
  245|  2.76k|		pubkey_info.key_reference = ((int)obj_info.id.value[0]) << 8 | obj_info.id.value[1];
  246|  2.76k|		prkey_info.key_reference = ((int)obj_info.id.value[0]) << 8 | obj_info.id.value[1];
  247|  2.76k|		prkey_info.native        = 1;
  248|       |
  249|  2.76k|		memcpy(cert_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  250|  2.76k|		memcpy(pubkey_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  251|  2.76k|		memcpy(prkey_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  252|  2.76k|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  2.76k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  253|  2.76k|		sc_pkcs15_format_id(pins[0].id, &prkey_obj.auth_id);
  254|       |
  255|  2.76k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, 0);
  256|       |
  257|  2.76k|		if (r) {
  ------------------
  |  Branch (257:7): [True: 2.30k, False: 459]
  ------------------
  258|  2.30k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  2.30k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  259|  2.30k|			continue;
  260|  2.30k|		}
  261|    459|		cert_info.path.count = (int)cert_der.len;
  262|       |
  263|    459|		sc_log(card->ctx, "cert len=%zu, cert_info.path.count=%d r=%d",
  ------------------
  |  |   71|    459|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  264|    459|				cert_der.len, cert_info.path.count, r);
  265|    459|		sc_log_hex(card->ctx, "cert", cert_der.value, cert_der.len);
  ------------------
  |  |  129|    459|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    459|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|       |
  267|       |		/* cache it using the PKCS15 emulation objects */
  268|       |		/* as it does not change */
  269|    459|		if (cert_der.value) {
  ------------------
  |  Branch (269:7): [True: 228, False: 231]
  ------------------
  270|    228|			cert_info.value.value = cert_der.value;
  271|    228|			cert_info.value.len = cert_der.len;
  272|    228|			cert_info.path.len = 0; /* use in mem cert from now on */
  273|    228|		}
  274|       |
  275|       |		/* following will find the cached cert in cert_info */
  276|    459|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert_out);
  277|    459|		if (r < 0 || cert_out->key == NULL) {
  ------------------
  |  Branch (277:7): [True: 391, False: 68]
  |  Branch (277:16): [True: 0, False: 68]
  ------------------
  278|    391|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|    391|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  279|    391|			if (cert_out != NULL)
  ------------------
  |  Branch (279:8): [True: 0, False: 391]
  ------------------
  280|      0|				sc_pkcs15_free_certificate(cert_out);
  281|    391|			free(cert_info.value.value);
  282|    391|			continue;
  283|    391|		}
  284|       |
  285|     68|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  286|     68|		if (r < 0) {
  ------------------
  |  Branch (286:7): [True: 0, False: 68]
  ------------------
  287|      0|			sc_log(card->ctx,  " Failed to add cert obj r=%d",r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  288|      0|			sc_pkcs15_free_certificate(cert_out);
  289|      0|			free(cert_info.value.value);
  290|      0|			continue;
  291|      0|		}
  292|       |		/* set the token name to the name of the CN of the first certificate */
  293|     68|		if (!token_name) {
  ------------------
  |  Branch (293:7): [True: 66, False: 2]
  ------------------
  294|     66|			u8 * cn_name = NULL;
  295|     66|			size_t cn_len = 0;
  296|     66|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  297|     66|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  298|     66|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  299|     66|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     66|#define SC_SUCCESS				0
  ------------------
  |  Branch (299:8): [True: 66, False: 0]
  ------------------
  300|     66|				token_name = malloc (cn_len+1);
  301|     66|				if (!token_name) {
  ------------------
  |  Branch (301:9): [True: 0, False: 66]
  ------------------
  302|      0|					free(cn_name);
  303|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  304|      0|					goto fail;
  305|      0|				}
  306|     66|				memcpy(token_name, cn_name, cn_len);
  307|     66|				free(cn_name);
  308|     66|				token_name[cn_len] = 0;
  309|     66|				free(p15card->tokeninfo->label);
  310|     66|				p15card->tokeninfo->label = token_name;
  311|     66|			}
  312|     66|		}
  313|       |
  314|       |
  315|     68|		r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, cert_out->key, &pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
  316|     68|		if (r < 0)
  ------------------
  |  Branch (316:7): [True: 0, False: 68]
  ------------------
  317|      0|			goto fail;
  318|     68|		pubkey_obj.emulated = cert_out->key;
  319|       |
  320|     68|		r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out, &usage_type, &usage, NULL);
  321|     68|		if (r < 0) {
  ------------------
  |  Branch (321:7): [True: 59, False: 9]
  ------------------
  322|     59|			usage = SC_X509_DATA_ENCIPHERMENT|SC_X509_DIGITAL_SIGNATURE; /* basic default usage */
  ------------------
  |  |  617|     59|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
              			usage = SC_X509_DATA_ENCIPHERMENT|SC_X509_DIGITAL_SIGNATURE; /* basic default usage */
  ------------------
  |  |  614|     59|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  ------------------
  323|     59|		}
  324|     68|		sc_pkcs15_map_usage(usage, cert_out->key->algorithm, &pubkey_info.usage, &prkey_info.usage, 1);
  325|     68|		sc_log(card->ctx,   "cert %s: cert_usage=0x%x, pub_usage=0x%x priv_usage=0x%x\n",
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  326|     68|				sc_dump_hex(cert_info.id.value, cert_info.id.len),
  327|     68|				 usage, pubkey_info.usage, prkey_info.usage);
  328|     68|		if (cert_out->key->algorithm != SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|     68|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (328:7): [True: 0, False: 68]
  ------------------
  329|      0|			sc_log(card->ctx, "unsupported key.algorithm %lu", cert_out->key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  330|      0|			sc_pkcs15_free_certificate(cert_out);
  331|      0|			free(pubkey_info.direct.spki.value);
  332|      0|			continue;
  333|     68|		} else {
  334|     68|			pubkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  335|     68|			prkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  336|     68|			r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  337|     68|			sc_log(card->ctx,  "adding rsa public key r=%d usage=%x",r, pubkey_info.usage);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  338|     68|			if (r < 0) {
  ------------------
  |  Branch (338:8): [True: 0, False: 68]
  ------------------
  339|      0|				free(pubkey_info.direct.spki.value);
  340|      0|				goto fail;
  341|      0|			}
  342|     68|			pubkey_info.direct.spki.value = NULL; /* moved to the pubkey object on p15card  */
  343|     68|			pubkey_info.direct.spki.len = 0;
  344|     68|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  345|     68|			if (r < 0)
  ------------------
  |  Branch (345:8): [True: 0, False: 68]
  ------------------
  346|      0|				goto fail;
  347|     68|			sc_log(card->ctx,  "adding rsa private key r=%d usage=%x",r, prkey_info.usage);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  348|     68|		}
  349|       |
  350|     68|		cert_out->key = NULL;
  351|     68|fail:
  352|     68|		sc_pkcs15_free_certificate(cert_out);
  353|     68|		if (r < 0) {
  ------------------
  |  Branch (353:7): [True: 0, False: 68]
  ------------------
  354|      0|			(card->ops->card_ctl)(card, SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS, &count);
  355|      0|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add object.");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  356|      0|		}
  357|       |
  358|     68|	}
  359|    952|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS, &count);
  360|    952|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize cert objects.");
  ------------------
  |  |  184|    952|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    952|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    952|	int _ret = (r); \
  |  |  |  |  178|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|    952|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    952|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    952|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    952|	int _ret = r; \
  |  |  |  |  155|    952|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 952, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    952|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  157|    952|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    952|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    952|	return _ret; \
  |  |  |  |  163|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|       |
  364|      0|err:
  365|      0|	sc_pkcs15_card_clear(p15card);
  366|      0|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  367|      0|}
pkcs15-cac.c:cac_get_name:
   78|    952|{
   79|    952|    switch (type) {
   80|    176|    case SC_CARD_TYPE_CAC_I: return ("CAC I");
  ------------------
  |  Branch (80:5): [True: 176, False: 776]
  ------------------
   81|    439|    case SC_CARD_TYPE_CAC_II: return ("CAC II");
  ------------------
  |  Branch (81:5): [True: 439, False: 513]
  ------------------
   82|    337|    case SC_CARD_TYPE_CAC_ALT_HID: return ("CAC ALT HID");
  ------------------
  |  Branch (82:5): [True: 337, False: 615]
  ------------------
   83|      0|    default: break;
  ------------------
  |  Branch (83:5): [True: 0, False: 952]
  ------------------
   84|    952|    }
   85|      0|    return ("CAC");
   86|    952|}

sc_pkcs15_read_cached_file:
  134|  6.75k|{
  135|  6.75k|	char fname[PATH_MAX];
  136|  6.75k|	int rv;
  137|  6.75k|	FILE *f;
  138|  6.75k|	size_t count;
  139|  6.75k|	struct stat stbuf;
  140|  6.75k|	u8 *data = NULL;
  141|       |
  142|  6.75k|	if (path->len < 2)
  ------------------
  |  Branch (142:6): [True: 1.96k, False: 4.79k]
  ------------------
  143|  1.96k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.96k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  144|       |
  145|       |	/* Accept full path or FILE-ID path with AID */
  146|  4.79k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  4.79k|#define SC_PATH_TYPE_PATH		2
  ------------------
              	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  117|  6.37k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (146:6): [True: 3.18k, False: 1.60k]
  |  Branch (146:44): [True: 0, False: 3.18k]
  |  Branch (146:82): [True: 2.16k, False: 1.02k]
  ------------------
  147|  2.16k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.16k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  148|       |
  149|  2.62k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   71|  2.62k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  150|  2.62k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  151|  2.62k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  2.62k|#define SC_SUCCESS				0
  ------------------
  |  Branch (151:6): [True: 2.62k, False: 0]
  ------------------
  152|  2.62k|		return rv;
  153|      0|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  154|       |
  155|      0|	f = fopen(fname, "rb");
  156|      0|	if (!f)
  ------------------
  |  Branch (156:6): [True: 0, False: 0]
  ------------------
  157|      0|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  158|      0|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (158:6): [True: 0, False: 0]
  ------------------
  159|      0|		fclose(f);
  160|      0|		return  SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  161|      0|	}
  162|       |
  163|      0|	if (path->count < 0) {
  ------------------
  |  Branch (163:6): [True: 0, False: 0]
  ------------------
  164|      0|		count = stbuf.st_size;
  165|      0|	}
  166|      0|	else {
  167|      0|		count = path->count;
  168|      0|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (168:7): [True: 0, False: 0]
  ------------------
  169|      0|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  170|      0|			goto err;
  171|      0|		}
  172|       |
  173|      0|		if (0 != fseek(f, (long)path->index, SEEK_SET)) {
  ------------------
  |  Branch (173:7): [True: 0, False: 0]
  ------------------
  174|      0|			rv = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  175|      0|			goto err;
  176|      0|		}
  177|      0|	}
  178|       |
  179|      0|	if (*buf == NULL) {
  ------------------
  |  Branch (179:6): [True: 0, False: 0]
  ------------------
  180|      0|		if (count == 0) {
  ------------------
  |  Branch (180:7): [True: 0, False: 0]
  ------------------
  181|      0|			data = NULL;
  182|      0|		} else {
  183|      0|			data = malloc(count);
  184|      0|			if (data == NULL)   {
  ------------------
  |  Branch (184:8): [True: 0, False: 0]
  ------------------
  185|      0|				rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  186|      0|				goto err;
  187|      0|			}
  188|      0|		}
  189|      0|	}
  190|      0|	else {
  191|      0|		if (count > *bufsize) {
  ------------------
  |  Branch (191:7): [True: 0, False: 0]
  ------------------
  192|      0|			rv =  SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  193|      0|			goto err;
  194|      0|		}
  195|      0|		data = *buf;
  196|      0|	}
  197|       |
  198|      0|	if (count > 0 && count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (198:6): [True: 0, False: 0]
  |  Branch (198:19): [True: 0, False: 0]
  ------------------
  199|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  200|      0|		goto err;
  201|      0|	}
  202|      0|	*buf = data;
  203|      0|	*bufsize = count;
  204|       |
  205|      0|	rv = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  206|       |
  207|      0|err:
  208|      0|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (208:6): [True: 0, False: 0]
  ------------------
  209|      0|		if (data != *buf) {
  ------------------
  |  Branch (209:7): [True: 0, False: 0]
  ------------------
  210|      0|			free(data);
  211|      0|		}
  212|      0|	}
  213|       |
  214|      0|	fclose(f);
  215|      0|	return rv;
  216|      0|}
sc_pkcs15_cache_file:
  221|  1.21k|{
  222|  1.21k|	char fname[PATH_MAX];
  223|  1.21k|	int r;
  224|  1.21k|	long len;
  225|  1.21k|	FILE *f;
  226|  1.21k|	size_t c;
  227|       |
  228|  1.21k|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  229|  1.21k|	if (r != 0)
  ------------------
  |  Branch (229:6): [True: 1.21k, False: 0]
  ------------------
  230|  1.21k|		return r;
  231|       |
  232|      0|	f = fopen(fname, "ab");
  233|       |	/* If the open failed because the cache directory does
  234|       |	 * not exist, create it and a re-try the fopen() call.
  235|       |	 */
  236|      0|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (236:6): [True: 0, False: 0]
  |  Branch (236:19): [True: 0, False: 0]
  ------------------
  237|      0|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (237:7): [True: 0, False: 0]
  ------------------
  238|      0|			return r;
  239|      0|		f = fopen(fname, "ab");
  240|      0|	}
  241|      0|	if (f == NULL)
  ------------------
  |  Branch (241:6): [True: 0, False: 0]
  ------------------
  242|      0|		return 0;
  243|       |
  244|       |	/* we opened the file for appending so we should be at the end of file.
  245|       |	 * The ftell() will give use the length of the file */
  246|      0|	len = ftell(f);
  247|      0|	if (len > path->index) {
  ------------------
  |  Branch (247:6): [True: 0, False: 0]
  ------------------
  248|       |		/* override previous cache records on this location */
  249|      0|		r = fseek(f, path->index, SEEK_SET);
  250|      0|		if (r != 0) {
  ------------------
  |  Branch (250:7): [True: 0, False: 0]
  ------------------
  251|      0|			fclose(f);
  252|      0|			return 0;
  253|      0|		}
  254|      0|	} else if (path->index > len) {
  ------------------
  |  Branch (254:13): [True: 0, False: 0]
  ------------------
  255|       |		/* We miss some bytes so we will not cache this chunk */
  256|      0|		fclose(f);
  257|      0|		return 0;
  258|      0|	}
  259|       |
  260|      0|	c = fwrite(buf, 1, bufsize, f);
  261|      0|	fclose(f);
  262|      0|	if (c != bufsize) {
  ------------------
  |  Branch (262:6): [True: 0, False: 0]
  ------------------
  263|      0|		sc_log(p15card->card->ctx, "fwrite() wrote only %zu bytes", c);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  264|      0|		unlink(fname);
  265|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  266|      0|	}
  267|      0|	return 0;
  268|      0|}
pkcs15-cache.c:generate_cache_filename:
   63|  3.84k|{
   64|  3.84k|	char dir[PATH_MAX];
   65|  3.84k|	char *last_update = NULL;
   66|  3.84k|	char *serial_number = NULL;
   67|  3.84k|	int  r;
   68|  3.84k|	unsigned u;
   69|  3.84k|	size_t change_counter;
   70|       |
   71|  3.84k|	if (p15card == NULL || p15card->tokeninfo == NULL || p15card->card == NULL || p15card->card->ctx) {
  ------------------
  |  Branch (71:6): [True: 0, False: 3.84k]
  |  Branch (71:25): [True: 0, False: 3.84k]
  |  Branch (71:55): [True: 0, False: 3.84k]
  |  Branch (71:80): [True: 3.84k, False: 0]
  ------------------
   72|  3.84k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  3.84k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   73|  3.84k|	}
   74|       |
   75|      0|	serial_number = p15card->tokeninfo->serial_number;
   76|      0|	if (serial_number == NULL &&
  ------------------
  |  Branch (76:6): [True: 0, False: 0]
  ------------------
   77|      0|			(p15card->card->uid.len == 0 || p15card->card->uid.value[0] == RANDOM_UID_INDICATOR))
  ------------------
  |  |   40|      0|#define RANDOM_UID_INDICATOR 0x08
  ------------------
  |  Branch (77:5): [True: 0, False: 0]
  |  Branch (77:36): [True: 0, False: 0]
  ------------------
   78|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   79|       |
   80|      0|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (80:6): [True: 0, False: 0]
  ------------------
   81|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   82|      0|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   83|      0|	if (r)
  ------------------
  |  Branch (83:6): [True: 0, False: 0]
  ------------------
   84|      0|		return r;
   85|      0|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   86|       |
   87|      0|	last_update = sc_pkcs15_get_lastupdate(p15card);
   88|      0|	if (!last_update || !is_safe_cache_component(last_update))
  ------------------
  |  Branch (88:6): [True: 0, False: 0]
  |  Branch (88:22): [True: 0, False: 0]
  ------------------
   89|      0|		last_update = "NODATE";
   90|       |
   91|      0|	if (serial_number && is_safe_cache_component(serial_number)) {
  ------------------
  |  Branch (91:6): [True: 0, False: 0]
  |  Branch (91:23): [True: 0, False: 0]
  ------------------
   92|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   93|      0|				"%s_%s", serial_number, last_update);
   94|      0|	} else {
   95|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "uid-%s_%s",
   96|      0|				sc_dump_hex(p15card->card->uid.value, p15card->card->uid.len), last_update);
   97|      0|	}
   98|       |
   99|      0|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (99:6): [True: 0, False: 0]
  ------------------
  100|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%zu", change_counter);
  101|       |
  102|      0|	if (path->aid.len &&
  ------------------
  |  Branch (102:6): [True: 0, False: 0]
  ------------------
  103|      0|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|      0|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (103:4): [True: 0, False: 0]
  |  Branch (103:42): [True: 0, False: 0]
  ------------------
  104|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
  105|      0|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (105:15): [True: 0, False: 0]
  ------------------
  106|      0|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  107|      0|					"%02X",  path->aid.value[u]);
  108|      0|	}
  109|      0|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|      0|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (109:11): [True: 0, False: 0]
  ------------------
  110|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  111|      0|	}
  112|       |
  113|      0|	if (path->len)   {
  ------------------
  |  Branch (113:6): [True: 0, False: 0]
  ------------------
  114|      0|		size_t offs = 0;
  115|       |
  116|      0|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (116:7): [True: 0, False: 0]
  |  Branch (116:24): [True: 0, False: 0]
  ------------------
  117|      0|			offs = 2;
  118|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
  119|      0|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (119:15): [True: 0, False: 0]
  ------------------
  120|      0|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  121|      0|					"%02X",  path->value[u + offs]);
  122|      0|	}
  123|       |
  124|      0|	if (!buf)
  ------------------
  |  Branch (124:6): [True: 0, False: 0]
  ------------------
  125|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  126|      0|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  127|       |
  128|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  129|      0|}

sc_pkcs15emu_cardos_init_ex:
  173|  7.46k|{
  174|  7.46k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (174:6): [True: 7.09k, False: 369]
  ------------------
  175|  7.09k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.09k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  176|       |
  177|    369|	return sc_pkcs15emu_cardos_init(p15card, aid);
  178|  7.46k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  139|  7.46k|{
  140|  7.46k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (140:6): [True: 294, False: 7.17k]
  ------------------
  141|    294|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    294|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|       |
  143|  7.17k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (143:6): [True: 6.80k, False: 369]
  ------------------
  144|  6.80k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.80k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  145|       |
  146|    369|	return SC_SUCCESS;
  ------------------
  |  |   28|    369|#define SC_SUCCESS				0
  ------------------
  147|  7.17k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  152|    369|{
  153|    369|	sc_card_t *card = p15card->card;
  154|    369|	int r;
  155|       |
  156|    369|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    369|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    369|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    369|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    369|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 369]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|       |
  158|    369|	r = sc_pkcs15_bind_internal(p15card, aid);
  159|    369|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal failed");
  ------------------
  |  |  174|    369|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    369|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    369|	int _ret = (r); \
  |  |  |  |  168|    369|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 364, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|    364|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    364|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    364|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    364|		return _ret; \
  |  |  |  |  172|    364|	} \
  |  |  |  |  173|    369|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|       |	/* If card has created algorithms, return  */
  162|      5|	sc_log(card->ctx, " card->algorithms:%p card->algorithm_count:%d", card->algorithms, card->algorithm_count);
  ------------------
  |  |   71|      5|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  163|      5|	if (!card->algorithms && card->algorithm_count == 0) {
  ------------------
  |  Branch (163:6): [True: 4, False: 1]
  |  Branch (163:27): [True: 4, False: 0]
  ------------------
  164|      4|		r = cardos_fix_token_info(p15card);
  165|      4|	}
  166|       |
  167|      5|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|      5|}
pkcs15-cardos.c:cardos_fix_token_info:
   43|      4|{
   44|      4|	sc_card_t *card;
   45|      4|	struct sc_supported_algo_info (*saa)[SC_MAX_SUPPORTED_ALGORITHMS];
   46|      4|	struct sc_supported_algo_info *sa;
   47|      4|	struct sc_cardctl_cardos_pass_algo_flags *passed = NULL;
   48|      4|	int r = 0;
   49|      4|	int i;
   50|       |
   51|      4|	card = p15card->card;
   52|       |
   53|      4|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      4|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      4|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      4|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4]
  |  |  ------------------
  ------------------
   54|       |
   55|      4|	passed = calloc(1, sizeof(struct sc_cardctl_cardos_pass_algo_flags));
   56|      4|	if (!passed)
  ------------------
  |  Branch (56:6): [True: 0, False: 4]
  ------------------
   57|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ENOUGH_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|       |
   59|      4|	passed->pass = 1; /* get used_flags and card_flags from card */
   60|      4|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
   61|      4|	if (r < 0) {
  ------------------
  |  Branch (61:6): [True: 0, False: 4]
  ------------------
   62|      0|		free(passed);
   63|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   64|      0|	}
   65|       |
   66|      4|	saa = &(p15card->tokeninfo->supported_algos);
   67|       |
   68|      4|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Original Flags: 0x%8.8lx card->flags:0x%8.8lx", passed->used_flags, passed->card_flags);
  ------------------
  |  |   70|      4|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   69|       |
   70|      4|	if (passed->card_flags) { /* user forced the flags, use them */
  ------------------
  |  Branch (70:6): [True: 0, False: 4]
  ------------------
   71|      0|		passed->new_flags = passed->card_flags; /* from card_atr flags */
   72|      4|	} else {
   73|       |
   74|      4|		for (i = 0, sa = saa[0]; i < SC_MAX_SUPPORTED_ALGORITHMS; i++, sa++) {
  ------------------
  |  |   61|      4|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (74:28): [True: 4, False: 0]
  ------------------
   75|       |
   76|      4|			if (sa->reference == 0 && sa->mechanism == 0
  ------------------
  |  Branch (76:8): [True: 4, False: 0]
  |  Branch (76:30): [True: 4, False: 0]
  ------------------
   77|      4|					&& sa->operations == 0 && sa->algo_ref == 0)
  ------------------
  |  Branch (77:9): [True: 4, False: 0]
  |  Branch (77:32): [True: 4, False: 0]
  ------------------
   78|      4|				break;
   79|       |
   80|      0|			sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "supported_algos[%d] mechanism:0x%8.8x", i, sa->mechanism);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   81|      0|			switch(sa->mechanism) {
   82|      0|			case 0x01 :
  ------------------
  |  Branch (82:4): [True: 0, False: 0]
  ------------------
   83|       |				/*
   84|       |				 * Card appears to use lower 4 bits of reference as key, and upper
   85|       |				 * 4 bits as mech for card.
   86|       |				 * Also has a bug if mechanism = 1 (CKM_RSA_PKCS1) and reference 0x10 
   87|       |				 * bit is set mechanism should be 3 (CKM_RSA_X_509) 
   88|       |				 * correct the mechanism in tokenInfo
   89|       |				 */
   90|      0|				if (sa->reference & 0x10) {
  ------------------
  |  Branch (90:9): [True: 0, False: 0]
  ------------------
   91|      0|					sc_log(card->ctx, "Changing mechanism to CKM_RSA_X_509 based on reference");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   92|      0|					passed->new_flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   93|      0|						| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|      0|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
   94|      0|					sa->mechanism = 0x03;
   95|      0|				} else
   96|      0|				passed->new_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
   97|      0|				break;
   98|      0|			case 0x03 :
  ------------------
  |  Branch (98:4): [True: 0, False: 0]
  ------------------
   99|      0|				passed->new_flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  100|      0|					| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|      0|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  101|      0|				break;
  102|      0|			case 0x06 :
  ------------------
  |  Branch (102:4): [True: 0, False: 0]
  ------------------
  103|      0|				passed->new_flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  104|      0|				break;
  105|      0|			case 0x1041:
  ------------------
  |  Branch (105:4): [True: 0, False: 0]
  ------------------
  106|      0|				passed->ec_flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  107|       |				/* no old_ec_flags */
  108|       |				/* TODO turn on sizes from  ec curves OIDS */
  109|      0|				break;
  110|      0|			default:
  ------------------
  |  Branch (110:4): [True: 0, False: 0]
  ------------------
  111|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "UNKNOWN MECH: 0x%8.8x", sa->mechanism);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  112|      0|			}
  113|       |
  114|      0|			sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  115|      0|				passed->new_flags, passed->ec_flags);
  116|      0|		}
  117|       |
  118|      4|		if (passed->new_flags == 0) {
  ------------------
  |  Branch (118:7): [True: 4, False: 0]
  ------------------
  119|      4|			if (p15card->tokeninfo && p15card->tokeninfo->flags & SC_PKCS15_TOKEN_EID_COMPLIANT) {
  ------------------
  |  |  598|      4|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  |  Branch (119:8): [True: 4, False: 0]
  |  Branch (119:30): [True: 1, False: 3]
  ------------------
  120|      1|				sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "EID_COMPLIANT flag found");
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  121|      1|				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |   96|      1|#define SC_ALGORITHM_SPECIFIC_FLAGS	0x001FFFFF
  ------------------
              				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  122|      1|				passed->new_flags |= (passed->used_flags & SC_ALGORITHM_RSA_PAD_PSS);
  ------------------
  |  |  107|      1|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  123|      1|			} else
  124|      3|				passed->new_flags = passed->used_flags; /* from default cardos_init */
  125|      4|		}
  126|      4|	}
  127|       |
  128|      4|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"Final New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx", passed->new_flags, passed->ec_flags);
  ------------------
  |  |   70|      4|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|       |
  130|      4|	passed->pass = 2; /* tell card driver to use the new flags */
  131|      4|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
  132|       |
  133|      4|	free(passed);
  134|      4|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|      4|}

sc_pkcs15emu_cedulauy_init_ex:
  196|  9.11k|{
  197|  9.11k|	if (p15card->card->type != SC_CARD_TYPE_CEDULAUY)
  ------------------
  |  Branch (197:6): [True: 9.03k, False: 82]
  ------------------
  198|  9.03k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.03k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  199|       |
  200|     82|	return sc_pkcs15emu_cedulauy_init(p15card);
  201|  9.11k|}
pkcs15-cedulauy.c:sc_pkcs15emu_cedulauy_init:
   70|     82|{
   71|     82|	struct sc_context *ctx = p15card->card->ctx;
   72|     82|	struct sc_aid aid;
   73|     82|	int r;
   74|     82|	size_t i;
   75|       |
   76|     82|	struct sc_pkcs15_auth_info pin_info = {0};
   77|     82|	struct sc_pkcs15_object pin_obj = {0};
   78|     82|	struct sc_pkcs15_cert_info cert_info = {0};
   79|     82|	struct sc_pkcs15_object cert_obj = {0};
   80|     82|	struct sc_pkcs15_prkey_info prkey_info = {0};
   81|     82|	struct sc_pkcs15_object prkey_obj = {0};
   82|     82|	struct sc_pkcs15_cert *cert = NULL;
   83|     82|	struct sc_app_info *appinfo;
   84|       |
   85|     82|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     82|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     82|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     82|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     82|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   86|       |
   87|     82|	memcpy(aid.value, cedulauy_aid, sizeof cedulauy_aid);
   88|     82|	aid.len = sizeof cedulauy_aid;
   89|       |
   90|     82|	appinfo = calloc(1, sizeof(struct sc_app_info));
   91|     82|	if (appinfo == NULL) {
  ------------------
  |  Branch (91:6): [True: 0, False: 82]
  ------------------
   92|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|      0|	}
   94|     82|	appinfo->aid = aid;
   95|     82|	appinfo->ddo.aid = aid;
   96|     82|	p15card->app = appinfo;
   97|       |
   98|       |	/* Global PIN (reference 0x11, ASCII numeric, zero-padded to 12 bytes). */
   99|     82|	pin_info.auth_id.value[0] = CEDULAUY_OBJ_ID;
  ------------------
  |  |   52|     82|#define CEDULAUY_OBJ_ID	  0x01	 /* links cert <-> prkey */
  ------------------
  100|     82|	pin_info.auth_id.len = 1;
  101|     82|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     82|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  102|     82|	pin_info.attrs.pin.reference = CEDULAUY_PIN_REF;
  ------------------
  |  |   51|     82|#define CEDULAUY_PIN_REF  0x11	 /* Global PIN reference */
  ------------------
  103|     82|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   58|     82|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     82|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  104|     82|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     82|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  105|     82|	pin_info.attrs.pin.min_length = 4;
  106|     82|	pin_info.attrs.pin.stored_length = 12;
  107|     82|	pin_info.attrs.pin.max_length = 12;
  108|     82|	pin_info.attrs.pin.pad_char = 0x00;
  109|     82|	pin_info.tries_left = -1;
  110|     82|	pin_info.max_tries = -1;
  111|     82|	strlcpy(pin_obj.label, "PIN", sizeof pin_obj.label);
  ------------------
  |  |   43|     82|#define strlcpy _strlcpy
  ------------------
  112|     82|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  113|     82|	LOG_TEST_RET(ctx, r, "Cannot add Global PIN object");
  ------------------
  |  |  174|     82|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     82|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     82|	int _ret = (r); \
  |  |  |  |  168|     82|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|       |
  115|       |	/* Signing certificate (EF B001 under the IAS application). */
  116|     82|	sc_format_path("i" CEDULAUY_CERT_FID, &cert_info.path); /* 'i' => select by file ID */
  ------------------
  |  |   49|     82|#define CEDULAUY_CERT_FID "B001" /* signing certificate EF */
  ------------------
  117|     82|	cert_info.path.aid = aid;
  118|     82|	cert_info.id.value[0] = CEDULAUY_OBJ_ID;
  ------------------
  |  |   52|     82|#define CEDULAUY_OBJ_ID	  0x01	 /* links cert <-> prkey */
  ------------------
  119|     82|	cert_info.id.len = 1;
  120|     82|	strlcpy(cert_obj.label, "Certificado de Firma", sizeof cert_obj.label);
  ------------------
  |  |   43|     82|#define strlcpy _strlcpy
  ------------------
  121|     82|	r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  122|     82|	LOG_TEST_RET(ctx, r, "Cannot add signing certificate object");
  ------------------
  |  |  174|     82|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     82|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     82|	int _ret = (r); \
  |  |  |  |  168|     82|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|       |
  124|       |	/* Set the token label and serial number from the certificate, when
  125|       |	 * readable.  The serial number also keys the file cache. */
  126|     82|	if (sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert) == SC_SUCCESS) {
  ------------------
  |  |   28|     82|#define SC_SUCCESS				0
  ------------------
  |  Branch (126:6): [True: 0, False: 82]
  ------------------
  127|      0|		static const struct sc_object_id cn_oid = {
  128|      0|				{2, 5, 4, 3, -1}
  129|      0|		};
  130|      0|		u8 *cn = NULL;
  131|      0|		size_t cn_len = 0;
  132|      0|		const u8 *serial = cert->serial;
  133|      0|		size_t serial_len = cert->serial_len;
  134|       |
  135|      0|		sc_pkcs15_get_name_from_dn(ctx, cert->subject, cert->subject_len,
  136|      0|				&cn_oid, &cn, &cn_len);
  137|      0|		if (cn_len > 0) {
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			char *label = malloc(cn_len + 1);
  139|      0|			if (label) {
  ------------------
  |  Branch (139:8): [True: 0, False: 0]
  ------------------
  140|      0|				memcpy(label, cn, cn_len);
  141|      0|				label[cn_len] = '\0';
  142|      0|				free(p15card->tokeninfo->label);
  143|      0|				p15card->tokeninfo->label = label;
  144|      0|			}
  145|      0|		}
  146|      0|		free(cn);
  147|       |
  148|       |		/* strip the ASN.1 INTEGER header, if present */
  149|      0|		if (serial_len > 2 && serial[0] == 0x02 && serial[1] == serial_len - 2) {
  ------------------
  |  Branch (149:7): [True: 0, False: 0]
  |  Branch (149:25): [True: 0, False: 0]
  |  Branch (149:46): [True: 0, False: 0]
  ------------------
  150|      0|			serial += 2;
  151|      0|			serial_len -= 2;
  152|      0|		}
  153|      0|		if (serial_len > 0) {
  ------------------
  |  Branch (153:7): [True: 0, False: 0]
  ------------------
  154|      0|			char *sn = malloc(serial_len * 2 + 1);
  155|      0|			if (sn) {
  ------------------
  |  Branch (155:8): [True: 0, False: 0]
  ------------------
  156|      0|				sc_bin_to_hex(serial, serial_len, sn, serial_len * 2 + 1, 0);
  157|      0|				free(p15card->tokeninfo->serial_number);
  158|      0|				p15card->tokeninfo->serial_number = sn;
  159|      0|			}
  160|      0|		}
  161|       |
  162|      0|		sc_pkcs15_free_certificate(cert);
  163|      0|	}
  164|       |
  165|       |	/* Signing private key (reference 0x01, RSA 2048, PIN-protected). */
  166|     82|	prkey_info.id.value[0] = CEDULAUY_OBJ_ID;
  ------------------
  |  |   52|     82|#define CEDULAUY_OBJ_ID	  0x01	 /* links cert <-> prkey */
  ------------------
  167|     82|	prkey_info.id.len = 1;
  168|     82|	prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  307|     82|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|     82|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  169|     82|	prkey_info.native = 1;
  170|     82|	prkey_info.key_reference = CEDULAUY_KEY_REF;
  ------------------
  |  |   50|     82|#define CEDULAUY_KEY_REF  0x01	 /* signing private key reference */
  ------------------
  171|     82|	prkey_info.modulus_length = 2048;
  172|     82|	prkey_obj.auth_id.value[0] = CEDULAUY_OBJ_ID;
  ------------------
  |  |   52|     82|#define CEDULAUY_OBJ_ID	  0x01	 /* links cert <-> prkey */
  ------------------
  173|     82|	prkey_obj.auth_id.len = 1;
  174|     82|	prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     82|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  175|     82|	strlcpy(prkey_obj.label, "Clave de Firma", sizeof prkey_obj.label);
  ------------------
  |  |   43|     82|#define strlcpy _strlcpy
  ------------------
  176|     82|	r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  177|     82|	LOG_TEST_RET(ctx, r, "Cannot add signing private key object");
  ------------------
  |  |  174|     82|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     82|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     82|	int _ret = (r); \
  |  |  |  |  168|     82|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|       |
  179|       |	/* Public identity data objects (DF 7000), readable without PIN. */
  180|    410|	for (i = 0; i < sizeof cedulauy_data_files / sizeof cedulauy_data_files[0]; i++) {
  ------------------
  |  Branch (180:14): [True: 328, False: 82]
  ------------------
  181|    328|		struct sc_pkcs15_data_info dinfo = {0};
  182|    328|		struct sc_pkcs15_object dobj = {0};
  183|       |
  184|    328|		sc_format_path(cedulauy_data_files[i].path, &dinfo.path);
  185|    328|		strlcpy(dinfo.app_label, cedulauy_data_files[i].label, sizeof dinfo.app_label);
  ------------------
  |  |   43|    328|#define strlcpy _strlcpy
  ------------------
  186|    328|		strlcpy(dobj.label, cedulauy_data_files[i].label, sizeof dobj.label);
  ------------------
  |  |   43|    328|#define strlcpy _strlcpy
  ------------------
  187|    328|		r = sc_pkcs15emu_add_data_object(p15card, &dobj, &dinfo);
  188|    328|		LOG_TEST_RET(ctx, r, "Cannot add identity data object");
  ------------------
  |  |  174|    328|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    328|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    328|	int _ret = (r); \
  |  |  |  |  168|    328|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 328]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    328|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 328]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    328|	}
  190|       |
  191|     82|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     82|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     82|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     82|	int _ret = r; \
  |  |  |  |  155|     82|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 82, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     82|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  157|     82|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     82|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     82|	return _ret; \
  |  |  |  |  163|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|     82|}

sc_pkcs15_get_name_from_dn:
  157|    341|{
  158|    341|	const u8 *rdn = NULL;
  159|    341|	const u8 *next_ava = NULL;
  160|    341|	size_t rdn_len = 0;
  161|    341|	size_t next_ava_len = 0;
  162|    341|	int rv;
  163|       |
  164|    341|	rdn = sc_asn1_skip_tag(ctx, &dn, &dn_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &rdn_len);
  ------------------
  |  |  206|    341|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              	rdn = sc_asn1_skip_tag(ctx, &dn, &dn_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &rdn_len);
  ------------------
  |  |  141|    341|#define SC_ASN1_CONS			0x20000000
  ------------------
  165|    341|	if (rdn == NULL)
  ------------------
  |  Branch (165:6): [True: 0, False: 341]
  ------------------
  166|    341|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of Distinguished Name");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|       |
  168|  1.01k|	for (next_ava = rdn, next_ava_len = rdn_len; next_ava_len; ) {
  ------------------
  |  Branch (168:47): [True: 1.00k, False: 6]
  ------------------
  169|  1.00k|		const u8 *ava, *dummy, *oidp;
  170|  1.00k|		struct sc_object_id oid;
  171|  1.00k|		size_t ava_len = 0, dummy_len, oid_len = 0;
  172|       |
  173|       |		/* unwrap the set and point to the next ava */
  174|  1.00k|		ava = sc_asn1_skip_tag(ctx, &next_ava, &next_ava_len, SC_ASN1_TAG_SET | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  207|  1.00k|#define SC_ASN1_TAG_SET			17
  ------------------
              		ava = sc_asn1_skip_tag(ctx, &next_ava, &next_ava_len, SC_ASN1_TAG_SET | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  141|  1.00k|#define SC_ASN1_CONS			0x20000000
  ------------------
  175|  1.00k|		if (ava == NULL)
  ------------------
  |  Branch (175:7): [True: 181, False: 827]
  ------------------
  176|  1.00k|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|    181|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    181|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    181|	int _ret = (r); \
  |  |  |  |  168|    181|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 181, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    181|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    181|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    181|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    181|		return _ret; \
  |  |  |  |  172|    181|	} \
  |  |  |  |  173|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  177|       |
  178|       |		/* It would be nice to use sc_asn1_decode here to parse the entire AVA, but we are missing 1 critical
  179|       |		 *	function in the templates: the ability to accept any tag for value. This prevents us from just
  180|       |		 *	grabbing the value as is out of the template. AVA's can have tags of PRINTABLE_STRING,
  181|       |		 *	TELETEXSTRING, T61STRING or UTF8_STRING with PRINTABLE_STRING and UTF8_STRING being the most common.
  182|       |		 * The other feature that would be nice is returning a pointer to our requested data using the space
  183|       |		 *	of the parent (basically what this code is doing here), rather than allocating and copying.
  184|       |		 */
  185|       |
  186|       |		/* unwrap the sequence */
  187|    827|		dummy = ava; dummy_len = ava_len;
  188|    827|		ava = sc_asn1_skip_tag(ctx, &dummy, &dummy_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  206|    827|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		ava = sc_asn1_skip_tag(ctx, &dummy, &dummy_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  141|    827|#define SC_ASN1_CONS			0x20000000
  ------------------
  189|    827|		if (ava == NULL)
  ------------------
  |  Branch (189:7): [True: 40, False: 787]
  ------------------
  190|    827|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|     40|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     40|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     40|	int _ret = (r); \
  |  |  |  |  168|     40|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     40|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     40|		return _ret; \
  |  |  |  |  172|     40|	} \
  |  |  |  |  173|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  191|       |
  192|       |		/* unwrap the oid */
  193|    787|		oidp = sc_asn1_skip_tag(ctx, &ava, &ava_len, SC_ASN1_TAG_OBJECT, &oid_len);
  ------------------
  |  |  200|    787|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  194|    787|		if (ava == NULL || ava_len < 1)
  ------------------
  |  Branch (194:7): [True: 0, False: 787]
  |  Branch (194:22): [True: 10, False: 777]
  ------------------
  195|    787|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA OID");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|       |
  197|       |		/* Convert to OID */
  198|    777|		rv = sc_asn1_decode_object_id(oidp, oid_len, &oid);
  199|    777|		if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    777|#define SC_SUCCESS				0
  ------------------
  |  Branch (199:7): [True: 19, False: 758]
  ------------------
  200|    777|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA OID");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|    758|		if (sc_compare_oid(&oid, type) == 0)
  ------------------
  |  Branch (202:7): [True: 673, False: 85]
  ------------------
  203|    673|			continue;
  204|       |
  205|       |		/* Yes, then return the name */
  206|     85|		dummy = sc_asn1_skip_tag(ctx, &ava, &ava_len, ava[0] & SC_ASN1_TAG_PRIMITIVE, &dummy_len);
  ------------------
  |  |  191|     85|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  207|     85|		if (dummy == NULL)
  ------------------
  |  Branch (207:7): [True: 8, False: 77]
  ------------------
  208|     85|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA name");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  209|     77|		if (*name == NULL) {
  ------------------
  |  Branch (209:7): [True: 77, False: 0]
  ------------------
  210|     77|			*name = malloc(dummy_len);
  211|     77|			if (*name == NULL)
  ------------------
  |  Branch (211:8): [True: 0, False: 77]
  ------------------
  212|     77|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|     77|			*name_len = dummy_len;
  214|     77|		}
  215|       |
  216|     77|		*name_len = MIN(dummy_len, *name_len);
  ------------------
  |  |   69|     77|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 77]
  |  |  ------------------
  ------------------
  217|     77|		memcpy(*name, dummy, *name_len);
  218|     77|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     77|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     77|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     77|	int _ret = r; \
  |  |  |  |  155|     77|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 77, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     77|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 77]
  |  |  |  |  ------------------
  |  |  |  |  157|     77|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     77|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     77|	return _ret; \
  |  |  |  |  163|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  219|     77|	}
  220|       |
  221|      6|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      6|}
sc_pkcs15_get_extension:
  247|    357|{
  248|    357|	const u8 *ext = NULL;
  249|    357|	const u8 *next_ext = NULL;
  250|    357|	size_t ext_len = 0;
  251|    357|	size_t next_ext_len = 0;
  252|    357|	struct sc_object_id oid;
  253|    357|	u8 *val = NULL;
  254|    357|	size_t val_len = 0;
  255|    357|	int critical;
  256|    357|	int r;
  257|    357|	struct sc_asn1_entry asn1_cert_ext[] = {
  258|    357|		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  159|    357|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  200|    357|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  259|    357|		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  153|    357|#define SC_ASN1_BOOLEAN                 1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  195|    357|#define SC_ASN1_TAG_BOOLEAN		1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  148|    357|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  260|    357|		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  157|    357|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  198|    357|#define SC_ASN1_TAG_OCTET_STRING	4
  ------------------
              		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  149|    357|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  261|    357|		{ NULL, 0, 0, 0, NULL, NULL }
  262|    357|	};
  263|       |
  264|    357|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    357|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    357|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    357|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    357|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 357]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  265|       |
  266|    614|	for (next_ext = cert->extensions, next_ext_len = cert->extensions_len; next_ext_len; ) {
  ------------------
  |  Branch (266:73): [True: 407, False: 207]
  ------------------
  267|       |		/* unwrap the set and point to the next ava */
  268|    407|		ext = sc_asn1_skip_tag(ctx, &next_ext, &next_ext_len,
  269|    407|			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  206|    407|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  141|    407|#define SC_ASN1_CONS			0x20000000
  ------------------
  270|    407|		if (ext == NULL)
  ------------------
  |  Branch (270:7): [True: 26, False: 381]
  ------------------
  271|    407|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|     26|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     26|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     26|	int _ret = (r); \
  |  |  |  |  168|     26|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     26|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     26|		return _ret; \
  |  |  |  |  172|     26|	} \
  |  |  |  |  173|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|       |
  273|       |		/*
  274|       |		 * use the sc_asn1_decoder for clarity. NOTE it would be more efficient to do this by hand
  275|       |		 * so we avoid the many malloc/frees here, but one hopes that one day the asn1_decode will allow
  276|       |		 * a 'static pointer' flag that returns a const pointer to the actual asn1 space so we only need
  277|       |		 * to make a final copy of the extension value before we return */
  278|    381|		critical = 0;
  279|    381|		r = sc_asn1_decode(ctx, asn1_cert_ext, ext, ext_len, NULL, NULL);
  280|    381|		if (r < 0)
  ------------------
  |  Branch (280:7): [True: 16, False: 365]
  ------------------
  281|    381|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  282|       |
  283|       |		/* is it the RN we are looking for */
  284|    365|		if (sc_compare_oid(&oid, type) != 0) {
  ------------------
  |  Branch (284:7): [True: 108, False: 257]
  ------------------
  285|    108|			if (*ext_val == NULL) {
  ------------------
  |  Branch (285:8): [True: 108, False: 0]
  ------------------
  286|    108|				*ext_val = val;
  287|    108|				val = NULL;
  288|    108|				*ext_val_len = val_len;
  289|       |				/* do not free here -- return the allocated value to caller */
  290|    108|			}
  291|      0|			else {
  292|      0|				*ext_val_len = MIN(*ext_val_len, val_len);
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  293|      0|				if (val) {
  ------------------
  |  Branch (293:9): [True: 0, False: 0]
  ------------------
  294|      0|					memcpy(*ext_val, val, *ext_val_len);
  295|      0|					free(val);
  296|      0|				}
  297|      0|			}
  298|       |
  299|    108|			if (is_critical)
  ------------------
  |  Branch (299:8): [True: 0, False: 108]
  ------------------
  300|      0|				*is_critical = critical;
  301|       |
  302|    108|			r = (int)val_len;
  303|    108|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    108|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    108|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    108|	int _ret = r; \
  |  |  |  |  155|    108|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    102|	} else { \
  |  |  |  |  159|    102|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    102|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    102|	} \
  |  |  |  |  162|    108|	return _ret; \
  |  |  |  |  163|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|    108|		}
  305|    257|		if (val) {
  ------------------
  |  Branch (305:7): [True: 136, False: 121]
  ------------------
  306|    136|			free(val);
  307|    136|			val = NULL;
  308|    136|		}
  309|    257|	}
  310|    207|	if (val)
  ------------------
  |  Branch (310:6): [True: 0, False: 207]
  ------------------
  311|      0|	    free(val);
  312|       |
  313|    207|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    207|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    207|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    207|	int _ret = r; \
  |  |  |  |  155|    207|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    207|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    207|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    207|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    207|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    207|	return _ret; \
  |  |  |  |  163|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|    207|}
sc_pkcs15_get_bitstring_extension:
  324|    357|{
  325|    357|	int r;
  326|    357|	u8 *bit_string = NULL;
  327|    357|	size_t bit_string_len=0, val_len = sizeof(*value);
  328|    357|	struct sc_asn1_entry asn1_bit_string[] = {
  329|    357|		{ "bitString", SC_ASN1_BIT_FIELD, SC_ASN1_TAG_BIT_STRING, 0, value, &val_len },
  ------------------
  |  |  171|    357|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
              		{ "bitString", SC_ASN1_BIT_FIELD, SC_ASN1_TAG_BIT_STRING, 0, value, &val_len },
  ------------------
  |  |  197|    357|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
  330|    357|		{ NULL, 0, 0, 0, NULL, NULL }
  331|    357|	};
  332|       |
  333|    357|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    357|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    357|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    357|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    357|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 357]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  334|       |
  335|    357|	r = sc_pkcs15_get_extension(ctx, cert, type, &bit_string, &bit_string_len, is_critical);
  336|    357|	LOG_TEST_RET(ctx, r, "Get extension error");
  ------------------
  |  |  174|    357|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    357|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    357|	int _ret = (r); \
  |  |  |  |  168|    357|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 249, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  169|    249|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    249|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    249|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    249|		return _ret; \
  |  |  |  |  172|    249|	} \
  |  |  |  |  173|    357|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|       |
  338|    108|	r = sc_asn1_decode(ctx, asn1_bit_string, bit_string, bit_string_len, NULL, NULL);
  339|    108|	free(bit_string);
  340|    108|	LOG_TEST_RET(ctx, r, "Decoding extension bit string");
  ------------------
  |  |  174|    108|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    108|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    108|	int _ret = (r); \
  |  |  |  |  168|    108|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 98]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|     98|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     98|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     98|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     98|	int _ret = r; \
  |  |  |  |  155|     98|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 98, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     98|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  157|     98|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     98|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     98|	return _ret; \
  |  |  |  |  163|     98|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  343|     98|}
sc_pkcs15_read_certificate:
  370|  1.65k|{
  371|  1.65k|	struct sc_context *ctx = NULL;
  372|  1.65k|	struct sc_pkcs15_cert *cert = NULL;
  373|  1.65k|	struct sc_pkcs15_der der;
  374|  1.65k|	int r;
  375|       |
  376|  1.65k|	if (p15card == NULL || info == NULL || cert_out == NULL) {
  ------------------
  |  Branch (376:6): [True: 0, False: 1.65k]
  |  Branch (376:25): [True: 0, False: 1.65k]
  |  Branch (376:41): [True: 0, False: 1.65k]
  ------------------
  377|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  378|      0|	}
  379|  1.65k|	ctx = p15card->card->ctx;
  380|  1.65k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.65k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.65k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|       |
  382|  1.65k|	if (info->value.len && info->value.value)   {
  ------------------
  |  Branch (382:6): [True: 967, False: 690]
  |  Branch (382:25): [True: 967, False: 0]
  ------------------
  383|    967|		sc_der_copy(&der, &info->value);
  384|    967|	}
  385|    690|	else if (info->path.len) {
  ------------------
  |  Branch (385:11): [True: 556, False: 134]
  ------------------
  386|    556|		r = sc_pkcs15_read_file(p15card, &info->path, &der.value, &der.len, private_obj);
  387|    556|		LOG_TEST_RET(ctx, r, "Unable to read certificate file.");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 431, False: 125]
  |  |  |  |  ------------------
  |  |  |  |  169|    431|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    431|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    431|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    431|		return _ret; \
  |  |  |  |  172|    431|	} \
  |  |  |  |  173|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 125]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|    556|	}
  389|    134|	else   {
  390|    134|		LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    134|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    134|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    134|	int _ret = r; \
  |  |  |  |  155|    134|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 134, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 134, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    134|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    134|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    134|	return _ret; \
  |  |  |  |  163|    134|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|    134|	}
  392|       |
  393|  1.09k|	cert = malloc(sizeof(struct sc_pkcs15_cert));
  394|  1.09k|	if (cert == NULL) {
  ------------------
  |  Branch (394:6): [True: 0, False: 1.09k]
  ------------------
  395|      0|		free(der.value);
  396|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  397|      0|	}
  398|  1.09k|	memset(cert, 0, sizeof(struct sc_pkcs15_cert));
  399|  1.09k|	if (parse_x509_cert(ctx, &der, cert)) {
  ------------------
  |  Branch (399:6): [True: 726, False: 366]
  ------------------
  400|    726|		free(der.value);
  401|    726|		sc_pkcs15_free_certificate(cert);
  402|    726|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|    726|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    726|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    726|	int _ret = r; \
  |  |  |  |  155|    726|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 726, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    726|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    726|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 726, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    726|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    726|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    726|	return _ret; \
  |  |  |  |  163|    726|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  403|    726|	}
  404|    366|	free(der.value);
  405|       |
  406|    366|	*cert_out = cert;
  407|    366|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    366|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    366|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    366|	int _ret = r; \
  |  |  |  |  155|    366|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 366, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    366|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 366]
  |  |  |  |  ------------------
  |  |  |  |  157|    366|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    366|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    366|	return _ret; \
  |  |  |  |  163|    366|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  408|    366|}
sc_pkcs15_decode_cdf_entry:
  445|     13|{
  446|     13|	sc_context_t *ctx = p15card->card->ctx;
  447|     13|	struct sc_pkcs15_cert_info info;
  448|     13|	struct sc_asn1_entry	asn1_cred_ident[3], asn1_com_cert_attr[4],
  449|     13|				asn1_x509_cert_attr[2], asn1_type_cert_attr[2],
  450|     13|				asn1_cert[2], asn1_x509_cert_value_choice[3];
  451|     13|	struct sc_asn1_pkcs15_object cert_obj = {
  452|     13|		obj, asn1_com_cert_attr, NULL,
  453|     13|		asn1_type_cert_attr };
  454|     13|	sc_pkcs15_der_t *der = &info.value;
  455|     13|	u8 id_value[128];
  456|     13|	int id_type;
  457|     13|	size_t id_value_len = sizeof(id_value);
  458|     13|	int r;
  459|       |
  460|     13|	sc_copy_asn1_entry(c_asn1_cred_ident, asn1_cred_ident);
  461|     13|	sc_copy_asn1_entry(c_asn1_com_cert_attr, asn1_com_cert_attr);
  462|     13|	sc_copy_asn1_entry(c_asn1_x509_cert_attr, asn1_x509_cert_attr);
  463|     13|	sc_copy_asn1_entry(c_asn1_x509_cert_value_choice, asn1_x509_cert_value_choice);
  464|     13|	sc_copy_asn1_entry(c_asn1_type_cert_attr, asn1_type_cert_attr);
  465|     13|	sc_copy_asn1_entry(c_asn1_cert, asn1_cert);
  466|       |
  467|     13|	sc_format_asn1_entry(asn1_cred_ident + 0, &id_type, NULL, 0);
  468|     13|	sc_format_asn1_entry(asn1_cred_ident + 1, &id_value, &id_value_len, 0);
  469|     13|	sc_format_asn1_entry(asn1_com_cert_attr + 0, &info.id, NULL, 0);
  470|     13|	sc_format_asn1_entry(asn1_com_cert_attr + 1, &info.authority, NULL, 0);
  471|     13|	sc_format_asn1_entry(asn1_com_cert_attr + 2, asn1_cred_ident, NULL, 0);
  472|     13|	sc_format_asn1_entry(asn1_x509_cert_attr + 0, asn1_x509_cert_value_choice, NULL, 0);
  473|     13|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 0, &info.path, NULL, 0);
  474|     13|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 1, &der->value, &der->len, 0);
  475|     13|	sc_format_asn1_entry(asn1_type_cert_attr + 0, asn1_x509_cert_attr, NULL, 0);
  476|     13|	sc_format_asn1_entry(asn1_cert + 0, &cert_obj, NULL, 0);
  477|       |
  478|       |	/* Fill in defaults */
  479|     13|	memset(&info, 0, sizeof(info));
  480|     13|	info.authority = 0;
  481|       |
  482|     13|	r = sc_asn1_decode(ctx, asn1_cert, *buf, *buflen, buf, buflen);
  483|       |	/* In case of error, trash the cert value (direct coding) */
  484|     13|	if (r < 0 && der->value)
  ------------------
  |  Branch (484:6): [True: 13, False: 0]
  |  Branch (484:15): [True: 0, False: 13]
  ------------------
  485|      0|		free(der->value);
  486|     13|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     13|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (486:6): [True: 2, False: 11]
  ------------------
  487|      2|		return r;
  488|     11|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  489|       |
  490|      0|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (490:6): [True: 0, False: 0]
  |  Branch (490:23): [True: 0, False: 0]
  ------------------
  491|      0|		if (!p15card->file_app) {
  ------------------
  |  Branch (491:7): [True: 0, False: 0]
  ------------------
  492|      0|			free(der->value);
  493|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  494|      0|		}
  495|      0|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path);
  496|      0|		LOG_TEST_RET(ctx, r, "Cannot make absolute path");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|      0|	}
  498|      0|	else   {
  499|      0|		info.path.aid = p15card->app->ddo.aid;
  500|      0|	}
  501|      0|	sc_log(ctx, "Certificate path '%s'", sc_print_path(&info.path));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  502|       |
  503|      0|	switch (p15card->opts.pin_protected_certificate) {
  ------------------
  |  Branch (503:10): [True: 0, False: 0]
  ------------------
  504|      0|		case SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY:
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
  |  Branch (504:3): [True: 0, False: 0]
  ------------------
  505|      0|			sc_log(ctx, "Declassifying certificate");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  506|      0|			obj->flags &= ~SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  507|      0|			break;
  508|      0|		case SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE:
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
  |  Branch (508:3): [True: 0, False: 0]
  ------------------
  509|      0|			sc_log(ctx, "Ignoring certificate");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  510|      0|			free(der->value);
  511|      0|			return 0;
  512|      0|	}
  513|       |
  514|      0|	obj->type = SC_PKCS15_TYPE_CERT_X509;
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  515|      0|	obj->data = malloc(sizeof(info));
  516|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (516:6): [True: 0, False: 0]
  ------------------
  517|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  518|      0|	memcpy(obj->data, &info, sizeof(info));
  519|       |
  520|      0|	return 0;
  521|      0|}
sc_pkcs15_map_usage:
  612|     68|{
  613|     68|	unsigned int pub_usage = 0, pr_usage = 0;
  614|     68|	unsigned int alg_flags = sc_pkcs15_alg_flags_from_algorithm(algorithm);
  615|       |
  616|     68|	if (cert_usage & SC_PKCS15_X509_USAGE_SIGNATURE) {
  ------------------
  |  |  591|     68|	(SC_X509_DIGITAL_SIGNATURE | \
  |  |  ------------------
  |  |  |  |  614|     68|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  |  |  ------------------
  |  |  592|     68|	SC_X509_NON_REPUDIATION    | \
  |  |  ------------------
  |  |  |  |  615|     68|#define SC_X509_NON_REPUDIATION       0x0002UL
  |  |  ------------------
  |  |  593|     68|	SC_X509_KEY_CERT_SIGN      | \
  |  |  ------------------
  |  |  |  |  619|     68|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  |  |  ------------------
  |  |  594|     68|	SC_X509_CRL_SIGN)
  |  |  ------------------
  |  |  |  |  620|     68|#define SC_X509_CRL_SIGN              0x0040UL
  |  |  ------------------
  ------------------
  |  Branch (616:6): [True: 65, False: 3]
  ------------------
  617|     65|		pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  311|     65|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              		pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     65|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  618|     65|		pr_usage |= SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  307|     65|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		pr_usage |= SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     65|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  619|     65|	}
  620|     68|	if (cert_usage & SC_PKCS15_X509_USAGE_DERIVE) {
  ------------------
  |  |  596|     68|	(SC_X509_KEY_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  616|     68|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  |  |  ------------------
  |  |  597|     68|			SC_X509_KEY_AGREEMENT)
  |  |  ------------------
  |  |  |  |  618|     68|#define SC_X509_KEY_AGREEMENT         0x0010UL
  |  |  ------------------
  ------------------
  |  Branch (620:6): [True: 3, False: 65]
  ------------------
  621|      3|		pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      3|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  622|      3|		pr_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      3|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  623|      3|	}
  624|     68|	if (cert_usage & (SC_PKCS15_X509_USAGE_DECRYPT|SC_PKCS15_X509_USAGE_UNWRAP)) {
  ------------------
  |  |  602|     68|	(SC_X509_DATA_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  617|     68|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  |  |  ------------------
  |  |  603|     68|	SC_X509_ENCIPHER_ONLY)
  |  |  ------------------
  |  |  |  |  621|     68|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  |  |  ------------------
  ------------------
              	if (cert_usage & (SC_PKCS15_X509_USAGE_DECRYPT|SC_PKCS15_X509_USAGE_UNWRAP)) {
  ------------------
  |  |  599|     68|	(SC_X509_KEY_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  616|     68|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  |  |  ------------------
  |  |  600|     68|	SC_X509_KEY_AGREEMENT)
  |  |  ------------------
  |  |  |  |  618|     68|#define SC_X509_KEY_AGREEMENT         0x0010UL
  |  |  ------------------
  ------------------
  |  Branch (624:6): [True: 62, False: 6]
  ------------------
  625|     62|		pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|     62|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  626|     62|		pr_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|     62|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  627|     62|	}
  628|     68|	if (allow_nonrepudiation && (cert_usage & SC_PKCS15_X509_USAGE_NONREPUDIATION)) {
  ------------------
  |  |  605|     68|	SC_X509_NON_REPUDIATION
  |  |  ------------------
  |  |  |  |  615|     68|#define SC_X509_NON_REPUDIATION       0x0002UL
  |  |  ------------------
  ------------------
  |  Branch (628:6): [True: 68, False: 0]
  |  Branch (628:30): [True: 6, False: 62]
  ------------------
  629|      6|		pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      6|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  630|      6|		pr_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      6|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  631|      6|	}
  632|       |	/* filter usages algorithm */
  633|     68|	if (pub_usage_ptr) {
  ------------------
  |  Branch (633:6): [True: 68, False: 0]
  ------------------
  634|     68|		*pub_usage_ptr = pub_usage & alg_flags;
  635|     68|	}
  636|     68|	if (pr_usage_ptr) {
  ------------------
  |  Branch (636:6): [True: 68, False: 0]
  ------------------
  637|     68|		*pr_usage_ptr = pr_usage & alg_flags;
  638|     68|	}
  639|     68|	return SC_SUCCESS;
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  640|     68|}
sc_pkcs15_free_certificate:
  644|  1.09k|{
  645|  1.09k|	if (cert == NULL) {
  ------------------
  |  Branch (645:6): [True: 0, False: 1.09k]
  ------------------
  646|      0|		return;
  647|      0|	}
  648|       |
  649|  1.09k|	sc_pkcs15_free_pubkey(cert->key);
  650|  1.09k|	free(cert->subject);
  651|  1.09k|	free(cert->issuer);
  652|  1.09k|	free(cert->serial);
  653|  1.09k|	free(cert->data.value);
  654|  1.09k|	free(cert->extensions);
  655|  1.09k|	free(cert);
  656|  1.09k|}
sc_pkcs15_free_cert_info:
  661|  1.12k|{
  662|  1.12k|	if (!cert)
  ------------------
  |  Branch (662:6): [True: 0, False: 1.12k]
  ------------------
  663|      0|		return;
  664|  1.12k|	free(cert->value.value);
  665|  1.12k|	free(cert);
  666|  1.12k|}
pkcs15-cert.c:parse_x509_cert:
   39|  1.09k|{
   40|  1.09k|	int r;
   41|  1.09k|	struct sc_algorithm_id sig_alg = {0};
   42|  1.09k|	struct sc_pkcs15_pubkey *pubkey = NULL;
   43|  1.09k|	unsigned char *serial = NULL, *issuer = NULL, *subject = NULL, *buf =  der->value;
   44|  1.09k|	size_t serial_len = 0, issuer_len = 0, subject_len = 0, data_len = 0, buflen = der->len;
   45|  1.09k|	struct sc_asn1_entry asn1_version[] = {
   46|  1.09k|		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  154|  1.09k|#define SC_ASN1_INTEGER                 2
  ------------------
              		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  196|  1.09k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
   47|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   48|  1.09k|	};
   49|  1.09k|	struct sc_asn1_entry asn1_extensions[] = {
   50|  1.09k|		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  148|  1.09k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   51|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   52|  1.09k|	};
   53|  1.09k|	struct sc_asn1_entry asn1_tbscert[] = {
   54|  1.09k|		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  169|  1.09k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  139|  1.09k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  148|  1.09k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   55|  1.09k|		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  196|  1.09k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   56|  1.09k|		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  1.09k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   57|  1.09k|		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   58|  1.09k|		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  1.09k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   59|  1.09k|		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   60|       |		/* Use a callback to get the algorithm, parameters and pubkey into sc_pkcs15_pubkey */
   61|  1.09k|		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  181|  1.09k|#define SC_ASN1_CALLBACK		384
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   62|  1.09k|		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  169|  1.09k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  139|  1.09k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  148|  1.09k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   63|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   64|  1.09k|	};
   65|  1.09k|	struct sc_asn1_entry asn1_cert[] = {
   66|  1.09k|		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  169|  1.09k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   67|  1.09k|		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  177|  1.09k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   68|  1.09k|		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  155|  1.09k|#define SC_ASN1_BIT_STRING              3
  ------------------
              		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  197|  1.09k|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
   69|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   70|  1.09k|	};
   71|  1.09k|	struct sc_asn1_entry asn1_serial_number[] = {
   72|  1.09k|		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  196|  1.09k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   73|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   74|  1.09k|	};
   75|  1.09k|	struct sc_asn1_entry asn1_subject[] = {
   76|  1.09k|		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   77|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   78|  1.09k|	};
   79|  1.09k|	struct sc_asn1_entry asn1_issuer[] = {
   80|  1.09k|		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  1.09k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  1.09k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   81|  1.09k|		{ NULL, 0, 0, 0, NULL, NULL }
   82|  1.09k|	};
   83|       |
   84|  1.09k|	const u8 *obj;
   85|  1.09k|	size_t objlen;
   86|       |
   87|  1.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|       |
   89|  1.09k|	memset(cert, 0, sizeof(*cert));
   90|  1.09k|	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  206|  1.09k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  141|  1.09k|#define SC_ASN1_CONS			0x20000000
  ------------------
   91|  1.09k|	if (obj == NULL)
  ------------------
  |  Branch (91:6): [True: 436, False: 656]
  ------------------
   92|  1.09k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "X.509 certificate not found");
  ------------------
  |  |  174|    436|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    436|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    436|	int _ret = (r); \
  |  |  |  |  168|    436|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 436, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    436|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    436|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    436|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    436|		return _ret; \
  |  |  |  |  172|    436|	} \
  |  |  |  |  173|    436|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|       |
   94|    656|	data_len = objlen + (obj - buf);
   95|    656|	cert->data.value = malloc(data_len);
   96|    656|	if (!cert->data.value)
  ------------------
  |  Branch (96:6): [True: 0, False: 656]
  ------------------
   97|    656|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   98|    656|	memcpy(cert->data.value, buf, data_len);
   99|    656|	cert->data.len = data_len;
  100|       |
  101|    656|	r = sc_asn1_decode(ctx, asn1_cert, obj, objlen, NULL, NULL);
  102|    656|	cert->key = pubkey;
  103|    656|	cert->version++;
  104|       |
  105|    656|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of certificate failed");
  ------------------
  |  |  184|    656|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    656|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    656|	int _ret = (r); \
  |  |  |  |  178|    656|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 290, False: 366]
  |  |  |  |  ------------------
  |  |  |  |  179|    290|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    290|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    290|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    290|		goto err; \
  |  |  |  |  182|    290|	} \
  |  |  |  |  183|    656|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 366]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|       |
  107|    366|	if (!pubkey)
  ------------------
  |  Branch (107:6): [True: 7, False: 359]
  ------------------
  108|    366|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Unable to decode subjectPublicKeyInfo from cert");
  ------------------
  |  |  184|      7|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      7|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      7|	int _ret = (r); \
  |  |  |  |  178|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      7|		goto err; \
  |  |  |  |  182|      7|	} \
  |  |  |  |  183|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|       |
  110|       |
  111|    359|	if (serial && serial_len)   {
  ------------------
  |  Branch (111:6): [True: 357, False: 2]
  |  Branch (111:16): [True: 357, False: 0]
  ------------------
  112|    357|		sc_format_asn1_entry(asn1_serial_number + 0, serial, &serial_len, 1);
  113|    357|		r = sc_asn1_encode(ctx, asn1_serial_number, &cert->serial, &cert->serial_len);
  114|    357|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of serial failed");
  ------------------
  |  |  184|    357|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    357|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    357|	int _ret = (r); \
  |  |  |  |  178|    357|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 357]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    357|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 357]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  115|    357|	}
  116|       |
  117|    359|	if (subject && subject_len)   {
  ------------------
  |  Branch (117:6): [True: 359, False: 0]
  |  Branch (117:17): [True: 359, False: 0]
  ------------------
  118|    359|		sc_format_asn1_entry(asn1_subject + 0, subject, &subject_len, 1);
  119|    359|		r = sc_asn1_encode(ctx, asn1_subject, &cert->subject, &cert->subject_len);
  120|    359|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of subject");
  ------------------
  |  |  184|    359|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    359|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    359|	int _ret = (r); \
  |  |  |  |  178|    359|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 359]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    359|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 359]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|    359|	}
  122|       |
  123|    359|	if (issuer && issuer_len)   {
  ------------------
  |  Branch (123:6): [True: 359, False: 0]
  |  Branch (123:16): [True: 359, False: 0]
  ------------------
  124|    359|		sc_format_asn1_entry(asn1_issuer + 0, issuer, &issuer_len, 1);
  125|    359|		r = sc_asn1_encode(ctx, asn1_issuer, &cert->issuer, &cert->issuer_len);
  126|    359|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of issuer");
  ------------------
  |  |  184|    359|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    359|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    359|	int _ret = (r); \
  |  |  |  |  178|    359|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 359]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    359|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 359]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  127|    359|	}
  128|       |
  129|    656|err:
  130|       |	/* not used for anything */
  131|    656|	sc_asn1_clear_algorithm_id(&sig_alg);
  132|    656|	free(serial);
  133|    656|	free(subject);
  134|    656|	free(issuer);
  135|       |
  136|    656|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    656|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    656|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    656|	int _ret = r; \
  |  |  |  |  155|    656|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 656, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    656|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    290|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 290, False: 366]
  |  |  |  |  ------------------
  |  |  |  |  157|    656|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    656|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    656|	return _ret; \
  |  |  |  |  163|    656|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  137|    656|}
pkcs15-cert.c:sc_pkcs15_alg_flags_from_algorithm:
  567|     68|{
  568|     68|	switch (algorithm) {
  ------------------
  |  Branch (568:10): [True: 68, False: 0]
  ------------------
  569|     68|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|     68|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (569:2): [True: 68, False: 0]
  ------------------
  570|     68|		return SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  305|     68|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              		return SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  309|     68|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  571|     68|		       SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  311|     68|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  312|     68|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  572|     68|		       SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  306|     68|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  310|     68|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  573|     68|		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  307|     68|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  308|     68|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  574|     68|		       SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|     68|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  575|       |#ifdef SC_ALGORITHM_DH
  576|       |	case SC_ALGORITHM_DH:
  577|       |		return SC_PKCS15_PRKEY_USAGE_DERIVE ;
  578|       |#endif
  579|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (579:2): [True: 0, False: 68]
  ------------------
  580|      0|		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
              		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  581|      0|		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  582|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (582:2): [True: 0, False: 68]
  ------------------
  583|      0|		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
              		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  584|      0|		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  585|     68|	}
  586|      0|	return 0;
  587|     68|}

sc_pkcs15emu_chipdocit_init_ex:
  219|  7.45k|{
  220|  7.45k|	sc_card_t *card = p15card->card;
  221|  7.45k|	sc_pkcs15_id_t id_auth, id_ds;
  222|  7.45k|	struct sc_apdu apdu;
  223|       |
  224|  7.45k|	memset(&id_auth, 0, sizeof id_auth);
  225|  7.45k|	id_auth.len = 1;
  226|  7.45k|	id_auth.value[0] = 0x01;
  227|  7.45k|	memset(&id_ds, 0, sizeof id_ds);
  228|  7.45k|	id_ds.len = 1;
  229|  7.45k|	id_ds.value[0] = 0x02;
  230|  7.45k|	u8 csn[32];
  231|  7.45k|	int r;
  232|       |
  233|  7.45k|	(void)aid;
  234|  7.45k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|  7.45k|	if (card->type != SC_CARD_TYPE_CHIPDOC_IT)
  ------------------
  |  Branch (235:6): [True: 7.45k, False: 0]
  ------------------
  236|  7.45k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  7.45k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.45k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.45k|	int _ret = r; \
  |  |  |  |  155|  7.45k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.45k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.45k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.45k|	return _ret; \
  |  |  |  |  163|  7.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  237|       |
  238|      0|	set_string(&p15card->tokeninfo->label, card->name);
  239|      0|	set_string(&p15card->tokeninfo->manufacturer_id, "Bit4id / NXP");
  240|       |
  241|       |	/* Serial = card serial number (GET DATA 00 CA 01 14), read in clear. */
  242|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, 0x14);
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  243|      0|	apdu.resp = csn;
  244|      0|	apdu.resplen = sizeof csn;
  245|      0|	apdu.le = 256;
  246|      0|	if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS && sc_check_sw(card, apdu.sw1, apdu.sw2) == SC_SUCCESS && apdu.resplen) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              	if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS && sc_check_sw(card, apdu.sw1, apdu.sw2) == SC_SUCCESS && apdu.resplen) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (246:6): [True: 0, False: 0]
  |  Branch (246:53): [True: 0, False: 0]
  |  Branch (246:108): [True: 0, False: 0]
  ------------------
  247|      0|		char hex[2 * sizeof(csn) + 1];
  248|      0|		sc_bin_to_hex(csn, apdu.resplen, hex, sizeof hex, 0);
  249|      0|		set_string(&p15card->tokeninfo->serial_number, hex);
  250|      0|	}
  251|       |
  252|      0|	r = add_pin(p15card);
  253|      0|	LOG_TEST_RET(card->ctx, r, "add PIN failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|       |
  255|       |	/* Auth key/cert: LCNS0, key ref 0x10, EF 0001. */
  256|      0|	r = read_ds_cert(p15card, 0x0001, &id_auth, "CNS", 0);
  257|      0|	LOG_TEST_RET(card->ctx, r, "read auth cert failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  258|      0|	r = add_prkey(p15card, &id_auth, "CNS",
  259|      0|			0x10, SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DECRYPT, 0);
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              			0x10, SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DECRYPT, 0);
  ------------------
  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  260|      0|	LOG_TEST_RET(card->ctx, r, "add auth key failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  261|       |
  262|       |	/* Qualified-signature key/cert: DS3, key ref 0x11, EF 0002, nonRepudiation. */
  263|      0|	r = read_ds_cert(p15card, 0x0002, &id_ds, "DS3", 1);
  264|      0|	LOG_TEST_RET(card->ctx, r, "read DS cert failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  265|      0|	r = add_prkey(p15card, &id_ds, "DS3",
  266|      0|			0x11, SC_PKCS15_PRKEY_USAGE_NONREPUDIATION, 1);
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  267|      0|	LOG_TEST_RET(card->ctx, r, "add DS key failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  270|      0|}

coolkey_get_attribute_lv:
  244|  1.63k|{
  245|  1.63k|	struct sc_pkcs15_data *item = (struct sc_pkcs15_data *)ptr;
  246|  1.63k|	return coolkey_get_attribute_bytes_alloc(card, obj, type, &item->data, &item->data_len);
  247|  1.63k|}
sc_pkcs15emu_coolkey_init_ex:
  727|  9.01k|{
  728|  9.01k|	sc_card_t      *card = p15card->card;
  729|  9.01k|	sc_context_t    *ctx = card->ctx;
  730|  9.01k|	int rv;
  731|       |
  732|  9.01k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  9.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  733|       |
  734|  9.01k|	rv = coolkey_detect_card(p15card);
  735|  9.01k|	if (rv)
  ------------------
  |  Branch (735:6): [True: 8.41k, False: 603]
  ------------------
  736|  9.01k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  8.41k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.41k|	int _ret = r; \
  |  |  |  |  155|  8.41k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.41k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.41k|	return _ret; \
  |  |  |  |  163|  8.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|    603|	rv = sc_pkcs15emu_coolkey_init(p15card);
  738|       |
  739|    603|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    603|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    603|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    603|	int _ret = r; \
  |  |  |  |  155|    603|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 603, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    603|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 603]
  |  |  |  |  ------------------
  |  |  |  |  157|    603|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    603|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    603|	return _ret; \
  |  |  |  |  163|    603|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  740|    603|}
pkcs15-coolkey.c:coolkey_get_attribute_bytes_alloc:
  206|  1.63k|{
  207|  1.63k|	const u8 *val;
  208|  1.63k|	size_t val_len;
  209|  1.63k|	int r;
  210|       |
  211|  1.63k|	r = coolkey_get_attribute(card, obj, type, &val, &val_len, NULL);
  212|  1.63k|	if (r < 0 || val_len < 1) {
  ------------------
  |  Branch (212:6): [True: 1.61k, False: 18]
  |  Branch (212:15): [True: 7, False: 11]
  ------------------
  213|  1.62k|		return r;
  214|  1.62k|	}
  215|     11|	*data = malloc(val_len);
  216|     11|	if (*data == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 11]
  ------------------
  217|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  218|      0|	}
  219|     11|	memcpy(*data, val, val_len);
  220|     11|	*data_len = val_len;
  221|     11|	return SC_SUCCESS;
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  222|     11|}
pkcs15-coolkey.c:coolkey_get_attribute:
   91|  34.7k|coolkey_get_attribute(sc_card_t *card, sc_cardctl_coolkey_object_t *obj, CK_ATTRIBUTE_TYPE type, const u8 **val, size_t *val_len, u8 *data_type) {
   92|  34.7k|	sc_cardctl_coolkey_attribute_t attribute;
   93|  34.7k|	int r;
   94|       |
   95|  34.7k|	attribute.object = obj;
   96|  34.7k|	attribute.attribute_type = type;
   97|       |
   98|  34.7k|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_GET_ATTRIBUTE, &attribute);
   99|  34.7k|	if (r < 0) {
  ------------------
  |  Branch (99:6): [True: 19.5k, False: 15.1k]
  ------------------
  100|  19.5k|		return r;
  101|  19.5k|	}
  102|  15.1k|	*val = attribute.attribute_value;
  103|  15.1k|	*val_len = attribute.attribute_length;
  104|  15.1k|	if (data_type) {
  ------------------
  |  Branch (104:6): [True: 1.60k, False: 13.5k]
  ------------------
  105|  1.60k|		*data_type = attribute.attribute_data_type;
  106|  1.60k|	}
  107|  15.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.1k|#define SC_SUCCESS				0
  ------------------
  108|  34.7k|}
pkcs15-coolkey.c:coolkey_detect_card:
   60|  9.01k|{
   61|  9.01k|	sc_card_t *card = p15card->card;
   62|       |
   63|  9.01k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.01k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.01k]
  |  |  ------------------
  ------------------
   64|  9.01k|	if (card->type < SC_CARD_TYPE_COOLKEY_GENERIC
  ------------------
  |  Branch (64:6): [True: 8.18k, False: 832]
  ------------------
   65|    832|		|| card->type >= SC_CARD_TYPE_COOLKEY_GENERIC+1000)
  ------------------
  |  Branch (65:6): [True: 229, False: 603]
  ------------------
   66|  8.41k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  8.41k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   67|    603|	return SC_SUCCESS;
  ------------------
  |  |   28|    603|#define SC_SUCCESS				0
  ------------------
   68|  9.01k|}
pkcs15-coolkey.c:sc_pkcs15emu_coolkey_init:
  467|    603|{
  468|    603|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  469|    603|	static const pindata pins[] = {
  470|    603|		{ "1", NULL, "", 0x00,
  471|    603|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    603|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  472|    603|		  32, 4, 32,
  473|    603|		  SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   58|    603|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  474|    603|		  -1, 0xFF,
  475|    603|		  SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|    603|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  476|    603|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  477|    603|	};
  478|       |
  479|       |	/*
  480|       |	 * The size of the key or the algid is not really known
  481|       |	 * but can be derived from the certificates.
  482|       |	 * the cert, pubkey and privkey are a set.
  483|       |	 * Key usages bits taken from certificate key usage extension.
  484|       |	 */
  485|       |
  486|    603|	int    r, i;
  487|    603|	sc_card_t *card = p15card->card;
  488|    603|	sc_serial_number_t serial;
  489|    603|	int count;
  490|    603|	struct sc_pkcs15_object *obj;
  491|       |
  492|    603|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    603|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    603|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    603|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 603]
  |  |  ------------------
  ------------------
  493|       |
  494|    603|	memset(&serial, 0, sizeof(serial));
  495|       |
  496|       |	/* coolkey caches a nonce once it logs in, don't keep the pin around. The card will
  497|       |	 * stay logged in until it's been pulled from the reader, in which case you want to reauthenticate
  498|       |	 * anyway */
  499|    603|	p15card->opts.use_pin_cache = 0;
  500|       |
  501|       |	/* get the token info from the card */
  502|    603|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_GET_TOKEN_INFO, p15card->tokeninfo);
  503|    603|	if (r < 0) {
  ------------------
  |  Branch (503:6): [True: 0, False: 603]
  ------------------
  504|       |		/* put some defaults in if we didn't succeed */
  505|      0|		set_string(&p15card->tokeninfo->label, "Coolkey");
  506|      0|		set_string(&p15card->tokeninfo->manufacturer_id, "Unknown");
  507|      0|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  508|      0|	}
  509|       |
  510|       |	/* set pins */
  511|    603|	sc_log(card->ctx,  "Coolkey adding pins...");
  ------------------
  |  |   71|    603|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  512|  1.20k|	for (i = 0; pins[i].id; i++) {
  ------------------
  |  Branch (512:14): [True: 603, False: 603]
  ------------------
  513|    603|		struct sc_pkcs15_auth_info pin_info;
  514|    603|		struct sc_pkcs15_object   pin_obj;
  515|    603|		const char * label;
  516|       |
  517|    603|		memset(&pin_info, 0, sizeof(pin_info));
  518|    603|		memset(&pin_obj,  0, sizeof(pin_obj));
  519|       |
  520|    603|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    603|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  521|    603|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  522|    603|		pin_info.attrs.pin.reference     = pins[i].ref;
  523|    603|		pin_info.attrs.pin.flags         = pins[i].flags;
  524|    603|		pin_info.attrs.pin.type          = pins[i].type;
  525|    603|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  526|    603|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  527|    603|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  528|    603|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  529|    603|		sc_format_path(pins[i].path, &pin_info.path);
  530|    603|		pin_info.tries_left    = -1;
  531|       |
  532|    603|		label = pins[i].label? pins[i].label : p15card->tokeninfo->label;
  ------------------
  |  Branch (532:11): [True: 0, False: 603]
  ------------------
  533|    603|		sc_log(card->ctx,  "Coolkey Adding pin %d label=%s",i, label);
  ------------------
  |  |   71|    603|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  534|    603|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    603|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  535|    603|		pin_obj.flags = pins[i].obj_flags;
  536|       |
  537|    603|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  538|    603|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object.");
  ------------------
  |  |  184|    603|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    603|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    603|	int _ret = (r); \
  |  |  |  |  178|    603|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 603]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    603|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 603]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    603|	}
  540|       |
  541|       |	/* set other objects */
  542|    603|	r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS, &count);
  543|    603|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate objects.");
  ------------------
  |  |  184|    603|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    603|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    603|	int _ret = (r); \
  |  |  |  |  178|    603|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 603]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    603|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 603]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  544|       |
  545|    603|	sc_log(card->ctx,  "Iterating over %d objects", count);
  ------------------
  |  |   71|    603|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  546|  4.71k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (546:14): [True: 4.11k, False: 603]
  ------------------
  547|  4.11k|		struct sc_cardctl_coolkey_object     coolkey_obj;
  548|  4.11k|		struct sc_pkcs15_object    obj_obj;
  549|  4.11k|		struct sc_pkcs15_cert_info cert_info = {0};
  550|  4.11k|		struct sc_pkcs15_pubkey_info pubkey_info = {0};
  551|  4.11k|		struct sc_pkcs15_prkey_info prkey_info = {0};
  552|  4.11k|		sc_pkcs15_pubkey_t *key = NULL;
  553|  4.11k|		void *obj_info = NULL;
  554|  4.11k|		int obj_type = 0;
  555|  4.11k|		CK_KEY_TYPE key_type;
  556|  4.11k|		CK_OBJECT_CLASS obj_class;
  557|  4.11k|		size_t len;
  558|       |
  559|  4.11k|		r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT, &coolkey_obj);
  560|  4.11k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next object from card.");
  ------------------
  |  |  184|  4.11k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.11k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.11k|	int _ret = (r); \
  |  |  |  |  178|  4.11k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 4.11k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  4.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.11k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  561|  4.11k|		sc_log(card->ctx, "Loading object %d", i);
  ------------------
  |  |   71|  4.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  562|  4.11k|		memset(&obj_obj, 0, sizeof(obj_obj));
  563|       |		/* coolkey applets have label only on the certificates,
  564|       |		 * but we should copy it also to the keys matching the same ID */
  565|  4.11k|		coolkey_get_attribute_bytes(card, &coolkey_obj, CKA_LABEL, (u8 *)obj_obj.label, &len, sizeof(obj_obj.label));
  ------------------
  |  |  140|  4.11k|#define CKA_LABEL 0x00000003UL
  ------------------
  566|  4.11k|		coolkey_get_flags(card, &coolkey_obj, &obj_obj.flags);
  567|  4.11k|		if (obj_obj.flags & SC_PKCS15_CO_FLAG_PRIVATE) {
  ------------------
  |  |   50|  4.11k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (567:7): [True: 524, False: 3.59k]
  ------------------
  568|    524|			sc_pkcs15_format_id(pins[0].id, &obj_obj.auth_id);
  569|    524|		}
  570|       |
  571|  4.11k|		r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_CLASS, &obj_class);
  ------------------
  |  |  137|  4.11k|#define CKA_CLASS 0x00000000UL
  ------------------
  572|  4.11k|		if (r < 0) {
  ------------------
  |  Branch (572:7): [True: 2.59k, False: 1.51k]
  ------------------
  573|  2.59k|			goto fail;
  574|  2.59k|		}
  575|  1.51k|		switch (obj_class) {
  576|  1.00k|		case CKO_PRIVATE_KEY:
  ------------------
  |  | 1030|  1.00k|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (576:3): [True: 1.00k, False: 511]
  ------------------
  577|  1.00k|			sc_log(card->ctx, "Processing private key object %d", i);
  ------------------
  |  |   71|  1.00k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  578|  1.00k|			r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_KEY_TYPE, &key_type);
  ------------------
  |  |  159|  1.00k|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  579|       |			/* default to CKK_RSA */
  580|  1.00k|			if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|  1.00k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (580:8): [True: 961, False: 47]
  ------------------
  581|    961|				key_type = CKK_RSA;
  ------------------
  |  |  464|    961|#define CKK_RSA 0x00000000UL
  ------------------
  582|    961|				r = SC_SUCCESS;
  ------------------
  |  |   28|    961|#define SC_SUCCESS				0
  ------------------
  583|    961|			}
  584|  1.00k|			if (r < 0) {
  ------------------
  |  Branch (584:8): [True: 11, False: 997]
  ------------------
  585|     11|				goto fail;
  586|     11|			}
  587|       |			/* set the info values */
  588|    997|			obj_info = &prkey_info;
  589|    997|			coolkey_get_id(card, &coolkey_obj, &prkey_info.id);
  590|    997|			prkey_info.path = coolkey_obj.path;
  591|    997|			prkey_info.key_reference = (int)coolkey_obj.id;
  592|    997|			prkey_info.native = 1;
  593|    997|			coolkey_get_usage(card, &coolkey_obj, &prkey_info.usage);
  594|    997|			coolkey_get_access(card, &coolkey_obj, &prkey_info.access_flags);
  595|    997|			key = coolkey_get_public_key(p15card, &coolkey_obj, key_type);
  596|    997|			if (key_type == CKK_RSA) {
  ------------------
  |  |  464|    997|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (596:8): [True: 961, False: 36]
  ------------------
  597|    961|				obj_type = SC_PKCS15_TYPE_PRKEY_RSA;
  ------------------
  |  |  419|    961|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  598|    961|				if (key) {
  ------------------
  |  Branch (598:9): [True: 1, False: 960]
  ------------------
  599|      1|					prkey_info.modulus_length = key->u.rsa.modulus.len*8;
  600|      1|				}
  601|    961|			} else if (key_type == CKK_EC) {
  ------------------
  |  |  467|     36|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (601:15): [True: 4, False: 32]
  ------------------
  602|      4|				obj_type = SC_PKCS15_TYPE_PRKEY_EC;
  ------------------
  |  |  421|      4|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  603|      4|				if (key) {
  ------------------
  |  Branch (603:9): [True: 0, False: 4]
  ------------------
  604|      0|					prkey_info.field_length = key->u.ec.params.field_length;
  605|      0|				}
  606|     32|			} else {
  607|     32|				goto fail;
  608|     32|			}
  609|    965|			break;
  610|       |
  611|    965|		case CKO_PUBLIC_KEY:
  ------------------
  |  | 1029|    150|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  |  Branch (611:3): [True: 150, False: 1.36k]
  ------------------
  612|    150|			sc_log(card->ctx, "Processing public key object %d", i);
  ------------------
  |  |   71|    150|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  613|    150|			r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_KEY_TYPE, &key_type);
  ------------------
  |  |  159|    150|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  614|       |			/* default to CKK_RSA */
  615|    150|			if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    150|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (615:8): [True: 134, False: 16]
  ------------------
  616|    134|				key_type = CKK_RSA;
  ------------------
  |  |  464|    134|#define CKK_RSA 0x00000000UL
  ------------------
  617|    134|				r = SC_SUCCESS;
  ------------------
  |  |   28|    134|#define SC_SUCCESS				0
  ------------------
  618|    134|			}
  619|    150|			if (r < 0) {
  ------------------
  |  Branch (619:8): [True: 10, False: 140]
  ------------------
  620|     10|				goto fail;
  621|     10|			}
  622|    140|			key = coolkey_get_public_key(p15card, &coolkey_obj, key_type);
  623|    140|			if (key == NULL) {
  ------------------
  |  Branch (623:8): [True: 132, False: 8]
  ------------------
  624|    132|				goto fail;
  625|    132|			}
  626|       |			/* set the info values */
  627|      8|			obj_info = &pubkey_info;
  628|      8|			r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, key, &pubkey_info.direct.spki.value,
  629|      8|				&pubkey_info.direct.spki.len);
  630|      8|			if (r < 0)
  ------------------
  |  Branch (630:8): [True: 7, False: 1]
  ------------------
  631|      7|				goto fail;
  632|      1|			coolkey_get_id(card, &coolkey_obj, &pubkey_info.id);
  633|      1|			pubkey_info.path = coolkey_obj.path;
  634|      1|			pubkey_info.native = 1;
  635|      1|			pubkey_info.key_reference = (int)coolkey_obj.id;
  636|      1|			coolkey_get_usage(card, &coolkey_obj, &pubkey_info.usage);
  637|      1|			coolkey_get_access(card, &coolkey_obj, &pubkey_info.access_flags);
  638|      1|			if (key_type == CKK_RSA) {
  ------------------
  |  |  464|      1|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (638:8): [True: 1, False: 0]
  ------------------
  639|      1|				obj_type = SC_PKCS15_TYPE_PUBKEY_RSA;
  ------------------
  |  |  426|      1|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  640|      1|				pubkey_info.modulus_length = key->u.rsa.modulus.len*8;
  641|      1|			} else if (key_type == CKK_EC) {
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (641:15): [True: 0, False: 0]
  ------------------
  642|      0|				obj_type = SC_PKCS15_TYPE_PUBKEY_EC;
  ------------------
  |  |  428|      0|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  643|      0|				pubkey_info.field_length = key->u.ec.params.field_length;
  644|      0|			} else {
  645|      0|				goto fail;
  646|      0|			}
  647|       |			/* set the obj values */
  648|      1|			obj_obj.emulated = key;
  649|      1|			key = NULL;
  650|      1|			break;
  651|       |
  652|    288|		case CKO_CERTIFICATE:
  ------------------
  |  | 1028|    288|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  |  Branch (652:3): [True: 288, False: 1.23k]
  ------------------
  653|    288|			sc_log(card->ctx, "Processing certificate object %d", i);
  ------------------
  |  |   71|    288|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  654|    288|			obj_info = &cert_info;
  655|    288|			coolkey_get_id(card, &coolkey_obj, &cert_info.id);
  656|    288|			cert_info.path = coolkey_obj.path;
  657|    288|			obj_type = SC_PKCS15_TYPE_CERT_X509;
  ------------------
  |  |  439|    288|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  658|       |
  659|       |			/* following will find the cached cert in cert_info */
  660|    288|			r = coolkey_get_certificate(card, &coolkey_obj, &cert_info.value);
  661|    288|			if (r < 0) {
  ------------------
  |  Branch (661:8): [True: 205, False: 83]
  ------------------
  662|    205|				goto fail;
  663|    205|			}
  664|     83|			break;
  665|       |
  666|       |
  667|     83|		default:
  ------------------
  |  Branch (667:3): [True: 73, False: 1.44k]
  ------------------
  668|       |			/* no other recognized types which are stored 'on card' */
  669|     73|			sc_log(card->ctx, "Unknown object type %lu, skipping", obj_class);
  ------------------
  |  |   71|     73|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  670|     73|			continue;
  671|  1.51k|		}
  672|       |
  673|  1.04k|		r = sc_pkcs15emu_object_add(p15card, obj_type, &obj_obj, obj_info);
  674|  1.04k|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.04k|#define SC_SUCCESS				0
  ------------------
  |  Branch (674:7): [True: 0, False: 1.04k]
  ------------------
  675|      0|			sc_log(card->ctx, "sc_pkcs15emu_object_add() returned %d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  676|  4.04k|fail:
  677|  4.04k|		if (key) {
  ------------------
  |  Branch (677:7): [True: 40, False: 4.00k]
  ------------------
  678|     40|			sc_pkcs15_free_pubkey(key);
  679|     40|		}
  680|  4.04k|		free(cert_info.value.value);
  681|  4.04k|		free(pubkey_info.direct.spki.value);
  682|  4.04k|	}
  683|    603|	r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS, &count);
  684|    603|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize objects.");
  ------------------
  |  |  184|    603|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    603|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    603|	int _ret = (r); \
  |  |  |  |  178|    603|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 603]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    603|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 603]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  685|       |
  686|       |	/* Iterate over all the created objects and fill missing labels */
  687|  2.25k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (687:32): [True: 1.65k, False: 603]
  ------------------
  688|  1.65k|		struct sc_pkcs15_id *id = NULL;
  689|  1.65k|		struct sc_pkcs15_object *cert_object;
  690|       |
  691|       |		/* label non-empty -- do not overwrite */
  692|  1.65k|		if (obj->label[0] != '\0')
  ------------------
  |  Branch (692:7): [True: 606, False: 1.04k]
  ------------------
  693|    606|			continue;
  694|       |
  695|  1.04k|		switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  1.04k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  696|      1|		case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      1|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (696:3): [True: 1, False: 1.04k]
  ------------------
  697|      1|			id = &((struct sc_pkcs15_pubkey_info *)obj->data)->id;
  698|      1|			break;
  699|    961|		case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|    961|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (699:3): [True: 961, False: 85]
  ------------------
  700|    961|			id = &((struct sc_pkcs15_prkey_info *)obj->data)->id;
  701|    961|			break;
  702|     84|		default:
  ------------------
  |  Branch (702:3): [True: 84, False: 962]
  ------------------
  703|       |			/* We do not care about other objects */
  704|     84|			continue;
  705|  1.04k|		}
  706|    962|		r = sc_pkcs15_find_cert_by_id(p15card, id, &cert_object);
  707|    962|		if (r != 0)
  ------------------
  |  Branch (707:7): [True: 831, False: 131]
  ------------------
  708|    831|			continue;
  709|       |
  710|    131|		sc_log(card->ctx, "Copy label \"%s\" from cert to key object",
  ------------------
  |  |   71|    131|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  711|    131|			cert_object->label);
  712|    131|		memcpy(obj->label, cert_object->label, SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|    131|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  713|    131|	}
  714|       |
  715|    603|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    603|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    603|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    603|	int _ret = r; \
  |  |  |  |  155|    603|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 603, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    603|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 603]
  |  |  |  |  ------------------
  |  |  |  |  157|    603|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    603|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    603|	return _ret; \
  |  |  |  |  163|    603|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|       |
  717|      0|err:
  718|      0|	sc_pkcs15_card_clear(p15card);
  719|      0|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  720|       |
  721|      0|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  722|      0|}
pkcs15-coolkey.c:coolkey_get_attribute_bytes:
  187|  5.40k|{
  188|  5.40k|	const u8 *val;
  189|  5.40k|	size_t val_len = 0;
  190|  5.40k|	int r;
  191|       |
  192|  5.40k|	r = coolkey_get_attribute(card, obj, type, &val, &val_len, NULL);
  193|  5.40k|	if (r < 0) {
  ------------------
  |  Branch (193:6): [True: 4.16k, False: 1.23k]
  ------------------
  194|  4.16k|		return r;
  195|  4.16k|	}
  196|  1.23k|	if (val_len > max_data_len) {
  ------------------
  |  Branch (196:6): [True: 2, False: 1.23k]
  ------------------
  197|      2|		val_len = max_data_len;
  198|      2|	}
  199|  1.23k|	memcpy(data, val, val_len);
  200|  1.23k|	*data_len = val_len;
  201|  1.23k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.23k|#define SC_SUCCESS				0
  ------------------
  202|  5.40k|}
pkcs15-coolkey.c:coolkey_get_flags:
  359|  4.22k|{
  360|  4.22k|	return coolkey_set_bool_flags(card, obj, flag_ptr, flag_table, flag_table_size);
  361|  4.22k|}
pkcs15-coolkey.c:coolkey_set_bool_flags:
  336|  6.22k|{
  337|  6.22k|	unsigned int flags = 0;
  338|  6.22k|	int i;
  339|       |
  340|  28.6k|	for (i=0; i< table_size; i++) {
  ------------------
  |  Branch (340:12): [True: 22.4k, False: 6.22k]
  ------------------
  341|  22.4k|		if (coolkey_get_attribute_boolean(card, obj, table[i].attribute_type)) {
  ------------------
  |  Branch (341:7): [True: 3.98k, False: 18.4k]
  ------------------
  342|  3.98k|			flags |= table[i].pkcs15_flags;
  343|  3.98k|		}
  344|  22.4k|	}
  345|  6.22k|	*flags_ptr = flags;
  346|  6.22k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.22k|#define SC_SUCCESS				0
  ------------------
  347|  6.22k|}
pkcs15-coolkey.c:coolkey_get_attribute_boolean:
  169|  22.4k|{
  170|  22.4k|	int r;
  171|  22.4k|	const u8 *val = NULL;
  172|  22.4k|	size_t val_len = 0;
  173|       |
  174|  22.4k|	r = coolkey_get_attribute(card, obj, attr_type, &val, &val_len, NULL);
  175|  22.4k|	if (r < 0) {
  ------------------
  |  Branch (175:6): [True: 10.0k, False: 12.3k]
  ------------------
  176|       |		/* attribute not valid for this object, set boolean to false */
  177|  10.0k|		return 0;
  178|  10.0k|	}
  179|  12.3k|	if ((val_len == 1) && (*val == 1)) {
  ------------------
  |  Branch (179:6): [True: 12.3k, False: 16]
  |  Branch (179:24): [True: 3.98k, False: 8.33k]
  ------------------
  180|  3.98k|		return 1;
  181|  3.98k|	}
  182|  8.34k|	return 0;
  183|  12.3k|}
pkcs15-coolkey.c:coolkey_get_attribute_ulong:
  149|  5.27k|{
  150|  5.27k|	const u8 *val = NULL;
  151|  5.27k|	size_t val_len = 0;
  152|  5.27k|	u8 data_type = 0;
  153|  5.27k|	int r;
  154|       |
  155|  5.27k|	r  = coolkey_get_attribute(card, obj, type, &val, &val_len, &data_type);
  156|  5.27k|	if (r < 0) {
  ------------------
  |  Branch (156:6): [True: 3.66k, False: 1.60k]
  ------------------
  157|  3.66k|		return r;
  158|  3.66k|	}
  159|  1.60k|	if ((data_type != SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG) &&
  ------------------
  |  | 1069|  1.60k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  |  Branch (159:6): [True: 61, False: 1.54k]
  ------------------
  160|     61|	    (val_len != sizeof(CK_ULONG))) {
  ------------------
  |  Branch (160:6): [True: 46, False: 15]
  ------------------
  161|     46|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     46|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  162|     46|	}
  163|  1.56k|	*value = bebytes2ulong(val);
  164|  1.56k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.56k|#define SC_SUCCESS				0
  ------------------
  165|  1.60k|}
pkcs15-coolkey.c:coolkey_get_id:
  226|  1.28k|{
  227|  1.28k|	return coolkey_get_attribute_bytes(card, obj, CKA_ID, id->value , &id->len, sizeof(id->value));
  ------------------
  |  |  161|  1.28k|#define CKA_ID 0x00000102UL
  ------------------
  228|  1.28k|}
pkcs15-coolkey.c:coolkey_get_usage:
  352|    998|{
  353|    998|	return coolkey_set_bool_flags(card, obj, usage_ptr, usage_table, usage_table_size);
  354|    998|}
pkcs15-coolkey.c:coolkey_get_access:
  365|    998|{
  366|    998|	return coolkey_set_bool_flags(card, obj, access_ptr, access_table, access_table_size);
  367|    998|}
pkcs15-coolkey.c:coolkey_get_public_key:
  456|  1.13k|{
  457|  1.13k|	sc_pkcs15_pubkey_t *key;
  458|       |
  459|  1.13k|	key = coolkey_make_public_key(p15card->card, obj, key_type);
  460|  1.13k|	if (key) {
  ------------------
  |  Branch (460:6): [True: 41, False: 1.09k]
  ------------------
  461|     41|		return key;
  462|     41|	}
  463|  1.09k|	return coolkey_get_public_key_from_certificate(p15card, obj);
  464|  1.13k|}
pkcs15-coolkey.c:coolkey_make_public_key:
  375|  1.13k|{
  376|  1.13k|	sc_pkcs15_pubkey_t *key;
  377|  1.13k|	int r;
  378|       |
  379|  1.13k|	key = calloc(1, sizeof(struct sc_pkcs15_pubkey));
  380|  1.13k|	if (!key)
  ------------------
  |  Branch (380:6): [True: 0, False: 1.13k]
  ------------------
  381|      0|		return NULL;
  382|  1.13k|	switch (key_type) {
  ------------------
  |  Branch (382:10): [True: 1.09k, False: 38]
  ------------------
  383|  1.09k|	case CKK_RSA:
  ------------------
  |  |  464|  1.09k|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (383:2): [True: 1.09k, False: 42]
  ------------------
  384|  1.09k|		key->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  1.09k|#define SC_ALGORITHM_RSA		0
  ------------------
  385|  1.09k|		r = coolkey_get_attribute_lv(card, obj, CKA_MODULUS, &key->u.rsa.modulus);
  ------------------
  |  |  174|  1.09k|#define CKA_MODULUS 0x00000120UL
  ------------------
  386|  1.09k|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (386:7): [True: 1.08k, False: 8]
  ------------------
  387|  1.08k|			goto fail;
  388|  1.08k|		}
  389|      8|		r = coolkey_get_attribute_lv(card, obj, CKA_PUBLIC_EXPONENT, &key->u.rsa.exponent);
  ------------------
  |  |  176|      8|#define CKA_PUBLIC_EXPONENT 0x00000122UL
  ------------------
  390|      8|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  |  Branch (390:7): [True: 5, False: 3]
  ------------------
  391|      5|			goto fail;
  392|      5|		}
  393|      3|		break;
  394|      4|	case CKK_EC:
  ------------------
  |  |  467|      4|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (394:2): [True: 4, False: 1.13k]
  ------------------
  395|      4|		key->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|      4|#define SC_ALGORITHM_EC		2
  ------------------
  396|      4|		r = coolkey_get_attribute_bytes_alloc(card, obj, CKA_EC_POINT, &key->u.ec.ecpointQ.value, &key->u.ec.ecpointQ.len);
  ------------------
  |  |  201|      4|#define CKA_EC_POINT 0x00000181UL
  ------------------
  397|      4|	    if(r < 0) {
  ------------------
  |  Branch (397:9): [True: 3, False: 1]
  ------------------
  398|      3|			goto fail;
  399|      3|		}
  400|      1|		r = coolkey_get_attribute_bytes_alloc(card, obj, CKA_EC_PARAMS,
  ------------------
  |  |  200|      1|#define CKA_EC_PARAMS 0x00000180UL
  ------------------
  401|      1|				&key->u.ec.params.der.value, &key->u.ec.params.der.len);
  402|      1|		if (r < 0) {
  ------------------
  |  Branch (402:7): [True: 1, False: 0]
  ------------------
  403|      1|			goto fail;
  404|      1|		}
  405|      0|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &key->u.ec.params);
  406|      0|		if (r < 0) {
  ------------------
  |  Branch (406:7): [True: 0, False: 0]
  ------------------
  407|      0|			goto fail;
  408|      0|		}
  409|      0|		break;
  410|  1.13k|	}
  411|     41|	return key;
  412|  1.09k|fail:
  413|  1.09k|	sc_pkcs15_free_pubkey(key);
  414|       |
  415|       |	/* now parse the DER cert */
  416|       |	return NULL;
  417|  1.13k|}
pkcs15-coolkey.c:coolkey_get_public_key_from_certificate:
  422|  1.09k|{
  423|  1.09k|	sc_pkcs15_cert_info_t cert_info;
  424|  1.09k|	sc_pkcs15_cert_t *cert_out = NULL;
  425|  1.09k|	sc_pkcs15_pubkey_t *key = NULL;
  426|  1.09k|	int r, private_obj;
  427|  1.09k|	unsigned int flags;
  428|       |
  429|  1.09k|	memset(&cert_info, 0, sizeof(cert_info));
  430|       |
  431|  1.09k|	r = coolkey_get_certificate(p15card->card, obj, &cert_info.value);
  432|  1.09k|	if (r < 0) {
  ------------------
  |  Branch (432:6): [True: 983, False: 113]
  ------------------
  433|    983|		goto fail;
  434|    983|	}
  435|       |
  436|    113|	coolkey_get_flags(p15card->card, obj, &flags);
  437|    113|	private_obj = flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    113|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  438|    113|	r = sc_pkcs15_read_certificate(p15card, &cert_info, private_obj, &cert_out);
  439|    113|	if (r < 0) {
  ------------------
  |  Branch (439:6): [True: 113, False: 0]
  ------------------
  440|    113|		goto fail;
  441|    113|	}
  442|      0|	key = cert_out->key;
  443|      0|	cert_out->key = NULL; /* adopt the key from the cert */
  444|  1.09k|fail:
  445|  1.09k|	if (cert_out) {
  ------------------
  |  Branch (445:6): [True: 0, False: 1.09k]
  ------------------
  446|      0|		sc_pkcs15_free_certificate(cert_out);
  447|      0|	}
  448|  1.09k|	if (cert_info.value.value) {
  ------------------
  |  Branch (448:6): [True: 112, False: 984]
  ------------------
  449|    112|		free(cert_info.value.value);
  450|    112|	}
  451|  1.09k|	return key;
  452|      0|}
pkcs15-coolkey.c:coolkey_get_certificate:
  267|  1.38k|{
  268|  1.38k|	sc_cardctl_coolkey_object_t *cert_obj;
  269|  1.38k|	unsigned long object_id;
  270|  1.38k|	int r;
  271|       |
  272|  1.38k|	cert_obj = obj;
  273|  1.38k|	if (coolkey_get_object_type(obj->id) != COOLKEY_ID_CERT) {
  ------------------
  |  |  249|  1.38k|#define COOLKEY_ID_CERT ((unsigned long)'c')
  ------------------
  |  Branch (273:6): [True: 1.37k, False: 11]
  ------------------
  274|  1.37k|		r = coolkey_find_matching_cert(card, obj, &cert_obj);
  275|  1.37k|		if (r < 0) {
  ------------------
  |  Branch (275:7): [True: 856, False: 517]
  ------------------
  276|    856|			return r;
  277|    856|		}
  278|  1.37k|	}
  279|    528|	r = coolkey_get_attribute_lv(card, cert_obj, CKA_VALUE, cert);
  ------------------
  |  |  143|    528|#define CKA_VALUE 0x00000011UL
  ------------------
  280|    528|	if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    528|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (280:6): [True: 508, False: 20]
  ------------------
  281|    508|		object_id = coolkey_make_new_id(cert_obj->id, COOLKEY_ID_CERT_DATA);
  ------------------
  |  |  251|    508|#define COOLKEY_ID_CERT_DATA ((unsigned long)'C')
  ------------------
  282|    508|		r = coolkey_get_object(card, object_id, &cert_obj);
  283|    508|		if (r < 0) {
  ------------------
  |  Branch (283:7): [True: 318, False: 190]
  ------------------
  284|    318|			return r;
  285|    318|		}
  286|       |		/* fill in cert data */
  287|    190|		cert->value = malloc(cert_obj->length);
  288|    190|		if (cert->value == NULL) {
  ------------------
  |  Branch (288:7): [True: 0, False: 190]
  ------------------
  289|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  290|      0|		}
  291|    190|		memcpy(cert->value, cert_obj->data, cert_obj->length);
  292|    190|		cert->len = cert_obj->length;
  293|    190|		return SC_SUCCESS;
  ------------------
  |  |   28|    190|#define SC_SUCCESS				0
  ------------------
  294|    190|	}
  295|     20|	return r;
  296|    528|}
pkcs15-coolkey.c:coolkey_get_object_type:
  254|  1.38k|coolkey_get_object_type(unsigned long object_id) { return ((object_id >> 24 ) & 0xff); }
pkcs15-coolkey.c:coolkey_find_matching_cert:
  111|  1.37k|coolkey_find_matching_cert(sc_card_t *card, sc_cardctl_coolkey_object_t *in_obj, sc_cardctl_coolkey_object_t **cert_obj) {
  112|  1.37k|	sc_cardctl_coolkey_find_object_t fobj;
  113|  1.37k|	sc_cardctl_coolkey_attribute_t template[2];
  114|  1.37k|	u8 obj_class[4];
  115|  1.37k|	int r;
  116|       |
  117|       |	/* we are searching for certs .. */
  118|  1.37k|	template[0].attribute_type = CKA_CLASS;
  ------------------
  |  |  137|  1.37k|#define CKA_CLASS 0x00000000UL
  ------------------
  119|  1.37k|	template[0].attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|  1.37k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  120|  1.37k|	template[0].attribute_length = sizeof(obj_class);
  121|  1.37k|	template[0].attribute_value = obj_class;
  122|  1.37k|	ulong2bebytes(obj_class, CKO_CERTIFICATE);
  ------------------
  |  | 1028|  1.37k|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  123|       |
  124|       |	/* fetch the current object's CKA_ID */
  125|  1.37k|	template[1].attribute_type = CKA_ID;
  ------------------
  |  |  161|  1.37k|#define CKA_ID 0x00000102UL
  ------------------
  126|  1.37k|	template[1].object = in_obj;
  127|  1.37k|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_GET_ATTRIBUTE, &template[1]);
  128|  1.37k|	if (r < 0) {
  ------------------
  |  Branch (128:6): [True: 54, False: 1.31k]
  ------------------
  129|     54|		return r;
  130|     54|	}
  131|  1.31k|	template[0].object = NULL; /*paranoia */
  132|  1.31k|	template[1].object = NULL; /*paranoia */
  133|       |
  134|       |	/* now find the cert that has the ID */
  135|  1.31k|	fobj.type = SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE;
  ------------------
  |  | 1080|  1.31k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  136|  1.31k|	fobj.obj = NULL;
  137|  1.31k|	fobj.coolkey_template = &template[0];
  138|  1.31k|	fobj.template_count=2;
  139|  1.31k|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_FIND_OBJECT, &fobj);
  140|  1.31k|	if (r < 0) {
  ------------------
  |  Branch (140:6): [True: 802, False: 517]
  ------------------
  141|    802|		return r;
  142|    802|	}
  143|    517|	*cert_obj = fobj.obj;
  144|    517|	return SC_SUCCESS;
  ------------------
  |  |   28|    517|#define SC_SUCCESS				0
  ------------------
  145|  1.31k|}
pkcs15-coolkey.c:coolkey_make_new_id:
  258|    508|{ return ((object_id  & 0x00ffffffUL)|(id_type << 24)); }
pkcs15-coolkey.c:coolkey_get_object:
   71|    508|coolkey_get_object(sc_card_t *card, unsigned long object_id, sc_cardctl_coolkey_object_t **obj) {
   72|    508|	sc_cardctl_coolkey_find_object_t fobj;
   73|    508|	int r;
   74|       |
   75|    508|	fobj.type = SC_CARDCTL_COOLKEY_FIND_BY_ID;
  ------------------
  |  | 1079|    508|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
   76|    508|	fobj.find_id = object_id;
   77|    508|	fobj.obj = NULL;
   78|    508|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_FIND_OBJECT, &fobj);
   79|    508|	if (r < 0) {
  ------------------
  |  Branch (79:6): [True: 318, False: 190]
  ------------------
   80|    318|		return r;
   81|    318|	}
   82|    190|	*obj = fobj.obj;
   83|    190|	return SC_SUCCESS;
  ------------------
  |  |   28|    190|#define SC_SUCCESS				0
  ------------------
   84|    508|}

sc_pkcs15_read_data_object:
   46|    184|{
   47|    184|	struct sc_context *ctx = p15card->card->ctx;
   48|    184|	struct sc_pkcs15_data *data_object;
   49|    184|	struct sc_pkcs15_der der;
   50|    184|	int r;
   51|       |
   52|    184|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    184|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    184|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    184|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    184|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|    184|	if (!info || !data_object_out)
  ------------------
  |  Branch (53:6): [True: 0, False: 184]
  |  Branch (53:15): [True: 0, False: 184]
  ------------------
   54|    184|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   55|       |
   56|    184|	if (!info->data.value)   {
  ------------------
  |  Branch (56:6): [True: 184, False: 0]
  ------------------
   57|    184|		r = sc_pkcs15_read_file(p15card, &info->path, (unsigned char **) &info->data.value, (size_t *) &info->data.len, private_obj);
   58|    184|		LOG_TEST_RET(ctx, r, "Cannot get DATA object data");
  ------------------
  |  |  174|    184|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    184|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    184|	int _ret = (r); \
  |  |  |  |  168|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 127, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  169|    127|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    127|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    127|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    127|		return _ret; \
  |  |  |  |  172|    127|	} \
  |  |  |  |  173|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|    184|	}
   60|       |
   61|     57|	r = sc_der_copy(&der, &info->data);
   62|     57|	LOG_TEST_RET(ctx, r, "Cannot allocate memory for der value");
  ------------------
  |  |  174|     57|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     57|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     57|	int _ret = (r); \
  |  |  |  |  168|     57|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|       |
   64|     57|	data_object = calloc(1, sizeof(struct sc_pkcs15_data));
   65|     57|	if (!data_object)   {
  ------------------
  |  Branch (65:6): [True: 0, False: 57]
  ------------------
   66|      0|		free(der.value);
   67|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate memory for data object");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   68|      0|	}
   69|       |
   70|     57|	data_object->data = der.value;
   71|     57|	data_object->data_len = der.len;
   72|     57|	*data_object_out = data_object;
   73|       |
   74|     57|	LOG_FUNC_RETURN(ctx,SC_SUCCESS);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|     57|}
sc_pkcs15_free_data_object:
  180|     57|{
  181|     57|	if (data_object == NULL)
  ------------------
  |  Branch (181:6): [True: 0, False: 57]
  ------------------
  182|      0|		return;
  183|       |
  184|     57|	free(data_object->data);
  185|     57|	free(data_object);
  186|     57|}
sc_pkcs15_free_data_info:
  189|  19.0k|{
  190|  19.0k|	if (info && info->data.value)
  ------------------
  |  Branch (190:6): [True: 19.0k, False: 0]
  |  Branch (190:14): [True: 0, False: 19.0k]
  ------------------
  191|      0|		free(info->data.value);
  192|       |
  193|  19.0k|	free(info);
  194|  19.0k|}

sc_pkcs15emu_din_66291_init_ex:
  197|  8.41k|{
  198|  8.41k|    int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.41k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  199|  8.41k|    sc_path_t path;
  200|  8.41k|    unsigned char *tokeninfo_content = NULL;
  201|  8.41k|    struct sc_file *file_tokeninfo = NULL;
  202|  8.41k|    struct sc_pkcs15_tokeninfo *tokeninfo = NULL;
  203|  8.41k|	sc_serial_number_t serial;
  204|       |
  205|  8.41k|    if (!p15card || ! p15card->card)
  ------------------
  |  Branch (205:9): [True: 0, False: 8.41k]
  |  Branch (205:21): [True: 0, False: 8.41k]
  ------------------
  206|      0|        return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  207|       |
  208|  8.41k|    SC_FUNC_CALLED(p15card->card->ctx, 1);
  ------------------
  |  |  148|  8.41k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.41k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.41k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.41k]
  |  |  ------------------
  ------------------
  209|       |
  210|  8.41k|    tokeninfo = sc_pkcs15_tokeninfo_new();
  211|  8.41k|    if (!p15card || !tokeninfo
  ------------------
  |  Branch (211:9): [True: 0, False: 8.41k]
  |  Branch (211:21): [True: 0, False: 8.41k]
  ------------------
  212|  8.41k|            || (aid && (aid->len != sizeof aid_CIA
  ------------------
  |  Branch (212:17): [True: 273, False: 8.14k]
  |  Branch (212:25): [True: 264, False: 9]
  ------------------
  213|      9|                    || 0 != memcmp(aid->value, aid_CIA, sizeof aid_CIA))))
  ------------------
  |  Branch (213:24): [True: 9, False: 0]
  ------------------
  214|    273|        goto err;
  215|       |
  216|  8.14k|    if (!p15card->tokeninfo
  ------------------
  |  Branch (216:9): [True: 0, False: 8.14k]
  ------------------
  217|  8.14k|            || !p15card->tokeninfo->profile_indication.name
  ------------------
  |  Branch (217:16): [True: 8.13k, False: 3]
  ------------------
  218|      3|            || 0 != strcmp("DIN V 66291",
  ------------------
  |  Branch (218:16): [True: 3, False: 0]
  ------------------
  219|  8.14k|                p15card->tokeninfo->profile_indication.name)) {
  220|       |        /* it is possible that p15card->tokeninfo has not been touched yet */
  221|  8.14k|        if (SC_SUCCESS == sc_path_set(&path, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |   28|  8.14k|#define SC_SUCCESS				0
  ------------------
                      if (SC_SUCCESS == sc_path_set(&path, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  8.14k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (221:13): [True: 8.14k, False: 0]
  ------------------
  222|  8.14k|                    aid_CIA, sizeof aid_CIA, 0, 0)
  223|  8.14k|                && SC_SUCCESS == sc_select_file(p15card->card, &path, NULL)) {
  ------------------
  |  |   28|  8.14k|#define SC_SUCCESS				0
  ------------------
  |  Branch (223:20): [True: 602, False: 7.53k]
  ------------------
  224|    602|            sc_format_path("5032", &path);
  225|    602|            if (SC_SUCCESS != sc_select_file(p15card->card, &path, &file_tokeninfo))
  ------------------
  |  |   28|    602|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:17): [True: 290, False: 312]
  ------------------
  226|    290|                goto err;
  227|       |
  228|    312|            tokeninfo_content = malloc(file_tokeninfo->size);
  229|    312|            if (!tokeninfo_content)
  ------------------
  |  Branch (229:17): [True: 0, False: 312]
  ------------------
  230|      0|                goto err;
  231|    312|            r = sc_read_binary(p15card->card, 0, tokeninfo_content, file_tokeninfo->size, 0);
  232|    312|            if (r < 0)
  ------------------
  |  Branch (232:17): [True: 71, False: 241]
  ------------------
  233|     71|                goto err;
  234|    241|            r = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, tokeninfo, tokeninfo_content, r);
  235|    241|            if (r != SC_SUCCESS)
  ------------------
  |  |   28|    241|#define SC_SUCCESS				0
  ------------------
  |  Branch (235:17): [True: 172, False: 69]
  ------------------
  236|    172|                goto err;
  237|       |
  238|     69|            if (!tokeninfo->profile_indication.name
  ------------------
  |  Branch (238:17): [True: 14, False: 55]
  ------------------
  239|     55|                    || 0 != strcmp("DIN V 66291",
  ------------------
  |  Branch (239:24): [True: 55, False: 0]
  ------------------
  240|     69|                        tokeninfo->profile_indication.name)) {
  241|     69|                goto err;
  242|     69|            }
  243|  7.53k|        } else {
  244|       |            /* BARMER eGK doesn't include MF / DF.CIA_ESIGN / EF.CIA_Info
  245|       |             * just detect it via its specific AID */
  246|  7.53k|            if (SC_SUCCESS != sc_path_set(&path, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |   28|  7.53k|#define SC_SUCCESS				0
  ------------------
                          if (SC_SUCCESS != sc_path_set(&path, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  7.53k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (246:17): [True: 0, False: 7.53k]
  ------------------
  247|  7.53k|                        aid_gematik_egk, sizeof aid_gematik_egk, 0, 0)
  248|  7.53k|                    || SC_SUCCESS != sc_select_file(p15card->card, &path, NULL))
  ------------------
  |  |   28|  7.53k|#define SC_SUCCESS				0
  ------------------
  |  Branch (248:24): [True: 6.62k, False: 916]
  ------------------
  249|  6.62k|                goto err;
  250|       |
  251|    916|            tokeninfo->profile_indication.name = strdup("DIN V 66291");
  252|    916|        }
  253|  8.14k|    }
  254|       |
  255|    916|    if (SC_SUCCESS != sc_pkcs15emu_din_66291_init(p15card))
  ------------------
  |  |   28|    916|#define SC_SUCCESS				0
  ------------------
  |  Branch (255:9): [True: 40, False: 876]
  ------------------
  256|     40|        goto err;
  257|       |
  258|       |    /* save tokeninfo and file_tokeninfo */
  259|    876|    sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  260|    876|    sc_file_free(p15card->file_tokeninfo);
  261|    876|    p15card->tokeninfo = tokeninfo;
  262|    876|    p15card->file_tokeninfo = file_tokeninfo;
  263|    876|    tokeninfo = NULL;
  264|    876|    file_tokeninfo = NULL;
  265|       |
  266|       |    /* get the card serial number */
  267|    876|    if (!p15card->tokeninfo->serial_number
  ------------------
  |  Branch (267:9): [True: 876, False: 0]
  ------------------
  268|    876|            && SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &serial)) {
  ------------------
  |  |   28|    876|#define SC_SUCCESS				0
  ------------------
  |  Branch (268:16): [True: 148, False: 728]
  ------------------
  269|    148|        char serial_hex[SC_MAX_SERIALNR*2+2];
  270|    148|        sc_bin_to_hex(serial.value, serial.len , serial_hex, sizeof serial_hex, 0);
  271|    148|        set_string(&p15card->tokeninfo->serial_number, serial_hex);
  272|    148|    }
  273|       |
  274|    876|    r = SC_SUCCESS;
  ------------------
  |  |   28|    876|#define SC_SUCCESS				0
  ------------------
  275|       |
  276|  8.41k|err:
  277|  8.41k|    sc_pkcs15_free_tokeninfo(tokeninfo);
  278|  8.41k|    sc_file_free(file_tokeninfo);
  279|  8.41k|    free(tokeninfo_content);
  280|       |
  281|  8.41k|    return r;
  282|    876|}
pkcs15-din-66291.c:sc_pkcs15emu_din_66291_init:
   42|    916|{
   43|       |    /*  EF.C.CH.AUT
   44|       |     *  fileIdentifier ´C5 00´
   45|       |     *  shortFileIdentifier ´01´= 1 
   46|       |     *  PrK.CH.AUT 
   47|       |     *  keyIdentifier ´02´ = 2
   48|       |     *  privateKey …, Moduluslänge 2048 Bit 
   49|       |     *
   50|       |     *  EF.C.CH.ENC 
   51|       |     *  fileIdentifier ´C2 00´
   52|       |     *  shortFileIdentifier ´02´= 2
   53|       |     *  PrK.CH.ENC 
   54|       |     *  keyIdentifier ´03´ = 3
   55|       |     *  privateKey …, Moduluslänge 2048 Bit 
   56|       |     */
   57|    916|    sc_path_t path;
   58|    916|    size_t i;
   59|    916|    struct sc_pin_cmd_data data;
   60|    916|    const unsigned char user_pin_ref = 0x02;
   61|       |
   62|    916|    sc_path_set(&path, SC_PATH_TYPE_DF_NAME, aid_ESIGN, sizeof aid_ESIGN, 0, 0);
  ------------------
  |  |  118|    916|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|    916|    if (SC_SUCCESS != sc_select_file(p15card->card, &path, NULL))
  ------------------
  |  |   28|    916|#define SC_SUCCESS				0
  ------------------
  |  Branch (63:9): [True: 40, False: 876]
  ------------------
   64|     40|        return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     40|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   65|       |
   66|    876|    memset(&data, 0, sizeof(data));
   67|    876|    data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    876|#define SC_PIN_CMD_GET_INFO	3
  ------------------
   68|    876|    data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|    876|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
   69|    876|    data.pin_reference = user_pin_ref;
   70|       |
   71|    876|    if (SC_SUCCESS == sc_pin_cmd(p15card->card, &data)) {
  ------------------
  |  |   28|    876|#define SC_SUCCESS				0
  ------------------
  |  Branch (71:9): [True: 304, False: 572]
  ------------------
   72|    304|        const unsigned char user_pin_id = 1;
   73|       |
   74|    912|        for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (74:21): [True: 608, False: 304]
  ------------------
   75|    608|            const char *pin_names[3] = { "PIN", "PUK" };
   76|    608|            const int pin_min[] = {6, 10};
   77|    608|            const int pin_max[] = {8, 8};
   78|    608|            const unsigned char user_puk_id = 2;
   79|    608|            const int pin_id[] = {user_pin_id, user_puk_id};
   80|    608|            const int pin_flags[] = {SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   58|    608|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
   81|    608|                SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN|SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED};
  ------------------
  |  |   60|    608|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
                              SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN|SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED};
  ------------------
  |  |   57|    608|#define SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED		0x0008
  ------------------
   82|    608|            const int max_tries[] = {3, 10};
   83|    608|            struct sc_pkcs15_auth_info pin_info;
   84|    608|            struct sc_pkcs15_object pin_obj;
   85|       |
   86|    608|            memset(&pin_info, 0, sizeof(pin_info));
   87|    608|            memset(&pin_obj, 0, sizeof(pin_obj));
   88|       |
   89|    608|            pin_info.auth_id.value[0] = pin_id[i];
   90|    608|            pin_info.auth_id.len = 1;
   91|    608|            pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;	
  ------------------
  |  |   94|    608|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
   92|    608|            pin_info.attrs.pin.flags = pin_flags[i];
   93|    608|            pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    608|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
   94|    608|            pin_info.attrs.pin.min_length = pin_min[i];
   95|    608|            pin_info.attrs.pin.stored_length = pin_max[i];
   96|    608|            pin_info.attrs.pin.max_length = pin_max[i];
   97|    608|            pin_info.max_tries = max_tries[i];
   98|       |
   99|    608|            strlcpy(pin_obj.label, pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|    608|#define strlcpy _strlcpy
  ------------------
  100|       |
  101|       |            /* catch the differences between PIN and PUK */
  102|    608|            if (pin_flags[i] & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN) {
  ------------------
  |  |   60|    608|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  |  Branch (102:17): [True: 304, False: 304]
  ------------------
  103|    304|                pin_info.tries_left = max_tries[i];
  104|    304|            } else {
  105|    304|                pin_info.attrs.pin.reference = user_pin_ref;
  106|    304|                pin_info.tries_left = data.pin1.tries_left;
  107|    304|                pin_info.logged_in = data.pin1.logged_in;
  108|    304|                pin_obj.auth_id.value[0] = user_puk_id;
  109|    304|                pin_obj.auth_id.len = 1;
  110|    304|            }
  111|       |
  112|    608|            if (0 > sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info)) {
  ------------------
  |  Branch (112:17): [True: 0, False: 608]
  ------------------
  113|      0|                sc_pkcs15_card_clear(p15card);
  114|      0|                return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  115|      0|            }
  116|    608|        }
  117|       |
  118|    912|        for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (118:21): [True: 608, False: 304]
  ------------------
  119|    608|            struct sc_aid aid;
  120|    608|            const char *din_66291_cert_fids[] = { "C500", "C200"};
  121|    608|            const char prk_id[] = { 0x10, 0x11,};
  122|    608|            struct sc_pkcs15_cert_info cert_info;
  123|    608|            struct sc_pkcs15_object cert_obj;
  124|    608|            struct sc_pkcs15_prkey_info prkey_info;
  125|    608|            struct sc_pkcs15_object prkey_obj;
  126|    608|            const int prk_usage[2] = {
  127|    608|                SC_PKCS15_PRKEY_USAGE_ENCRYPT
  ------------------
  |  |  305|    608|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  128|    608|                    | SC_PKCS15_PRKEY_USAGE_DECRYPT
  ------------------
  |  |  306|    608|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  129|    608|                    | SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|    608|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  130|    608|                SC_PKCS15_PRKEY_USAGE_NONREPUDIATION};
  ------------------
  |  |  314|    608|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  131|       |
  132|    608|            memcpy(aid.value, aid_CIA, sizeof aid_CIA);
  133|    608|            aid.len = sizeof aid_CIA;
  134|       |
  135|    608|            memset(&prkey_info, 0, sizeof(prkey_info));
  136|    608|            memset(&prkey_obj, 0, sizeof(prkey_obj));
  137|    608|            memset(&cert_info, 0, sizeof(cert_info));
  138|    608|            memset(&cert_obj, 0, sizeof(cert_obj));
  139|       |
  140|       |
  141|    608|            sc_format_path(din_66291_cert_fids[i], &cert_info.path);
  142|    608|            if (SC_SUCCESS != sc_select_file(p15card->card, &cert_info.path, NULL))
  ------------------
  |  |   28|    608|#define SC_SUCCESS				0
  ------------------
  |  Branch (142:17): [True: 306, False: 302]
  ------------------
  143|    306|                continue;
  144|    302|            cert_info.path.aid = aid;
  145|       |
  146|    302|            cert_info.id.value[0] = prk_id[i];
  147|    302|            cert_info.id.len = 1;
  148|       |
  149|    302|            if (0 > sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info))
  ------------------
  |  Branch (149:17): [True: 0, False: 302]
  ------------------
  150|      0|                continue;
  151|       |
  152|    302|            if (i == 0) {
  ------------------
  |  Branch (152:17): [True: 253, False: 49]
  ------------------
  153|    253|                sc_pkcs15_cert_t *cert;
  154|    253|                if (SC_SUCCESS == sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert)) {
  ------------------
  |  |   28|    253|#define SC_SUCCESS				0
  ------------------
  |  Branch (154:21): [True: 0, False: 253]
  ------------------
  155|      0|                    static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  156|      0|                    u8 *cn_name = NULL;
  157|      0|                    size_t cn_len = 0;
  158|      0|                    sc_pkcs15_get_name_from_dn(p15card->card->ctx, cert->subject,
  159|      0|                            cert->subject_len, &cn_oid, &cn_name, &cn_len);
  160|      0|                    if (cn_len > 0) {
  ------------------
  |  Branch (160:25): [True: 0, False: 0]
  ------------------
  161|      0|                        char *token_name = malloc(cn_len+1);
  162|      0|                        if (token_name) {
  ------------------
  |  Branch (162:29): [True: 0, False: 0]
  ------------------
  163|      0|                            memcpy(token_name, cn_name, cn_len);
  164|      0|                            token_name[cn_len] = '\0';
  165|      0|                            free(p15card->tokeninfo->label);
  166|      0|                            p15card->tokeninfo->label = token_name;
  167|      0|                        }
  168|      0|                    }
  169|      0|                    free(cn_name);
  170|      0|                    sc_pkcs15_free_certificate(cert);
  171|      0|                }
  172|    253|            }
  173|       |
  174|    302|            memset(&prkey_info, 0, sizeof(prkey_info));
  175|    302|            memset(&prkey_obj, 0, sizeof(prkey_obj));
  176|       |
  177|    302|            prkey_info.id.value[0] = prk_id[i];
  178|    302|            prkey_info.id.len = 1;
  179|    302|            prkey_info.usage  = prk_usage[i];
  180|    302|            prkey_info.native = 1;
  181|    302|            prkey_info.key_reference = prk_id[i];
  182|    302|            prkey_info.modulus_length = 2048;
  183|    302|            prkey_obj.auth_id.value[0] = user_pin_id;
  184|    302|            prkey_obj.auth_id.len = 1;
  185|    302|            prkey_obj.user_consent = 0;
  186|    302|            prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    302|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  187|       |
  188|    302|            if (0 > sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info))
  ------------------
  |  Branch (188:17): [True: 0, False: 302]
  ------------------
  189|      0|                continue;
  190|    302|        }
  191|    304|    }
  192|       |
  193|    876|    return SC_SUCCESS;
  ------------------
  |  |   28|    876|#define SC_SUCCESS				0
  ------------------
  194|    876|}

sc_pkcs15emu_dnie_init_ex:
  281|  9.12k|{
  282|  9.12k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  9.12k|#define SC_SUCCESS				0
  ------------------
  283|  9.12k|	sc_context_t *ctx = p15card->card->ctx;
  284|  9.12k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  9.12k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.12k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.12k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.12k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.12k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  9.12k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  9.12k|	r = dnie_match_card(p15card->card);
  289|  9.12k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 8.59k, False: 536]
  ------------------
  290|  9.12k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  8.59k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.59k|	int _ret = r; \
  |  |  |  |  155|  8.59k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.59k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.59k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.59k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.59k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.59k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.59k|	return _ret; \
  |  |  |  |  163|  8.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    536|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  164|    536|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    536|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    536|	int _ret = r; \
  |  |  |  |  155|    536|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 536, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    536|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    520|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 520, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|    536|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    536|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    536|	return _ret; \
  |  |  |  |  163|    536|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|       |#else
  294|       |	r = SC_ERROR_WRONG_CARD;
  295|       |	LOG_FUNC_RETURN(ctx, r);
  296|       |#endif
  297|    536|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    536|{
  140|    536|	u8 buf[1024];
  141|    536|	sc_pkcs15_df_t *df;
  142|    536|	sc_pkcs15_object_t *p15_obj;
  143|    536|	size_t len = sizeof(buf);
  144|    536|	int rv;
  145|    536|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    536|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    536|	sc_context_t *ctx = p15card->card->ctx;
  149|    536|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    536|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    536|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    536|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    536|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 536]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    536|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 6, False: 530]
  ------------------
  153|      6|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      6|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    530|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 530]
  ------------------
  157|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  158|       |
  159|       |	/* The two keys inside DNIe 3.0 needs login before performing any signature.
  160|       |	 * They are CKA_ALWAYS_AUTHENTICATE although they are not tagged like that.
  161|       |	 * For the moment caching is forced if 3.0 is detected to make it work properly. */
  162|    530|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    530|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 273, False: 257]
  ------------------
  163|    273|		p15card->opts.use_pin_cache = 1;
  164|    273|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|    273|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|    273|		sc_log(ctx, "DNIe 3.0 detected - PKCS#15 options reset: use_file_cache=%d use_pin_cache=%d pin_cache_counter=%d pin_cache_ignore_user_consent=%d",
  ------------------
  |  |   71|    273|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  166|    273|			p15card->opts.use_file_cache,
  167|    273|			p15card->opts.use_pin_cache,
  168|    273|			p15card->opts.pin_cache_counter,
  169|    273|			p15card->opts.pin_cache_ignore_user_consent);
  170|    273|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    530|	sc_file_free(p15card->file_app);
  174|    530|	p15card->file_app = sc_file_new();
  175|    530|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 530]
  ------------------
  176|      0|		rv = SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|      0|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  177|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Can not create file.");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|      0|	}
  179|    530|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    530|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    530|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    530|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    530|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    530|	int _ret = (r); \
  |  |  |  |  178|    530|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 423, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  179|    423|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    423|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    423|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    423|		goto err; \
  |  |  |  |  182|    423|	} \
  |  |  |  |  183|    530|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|    107|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  186|    107|				       buf, len);
  187|    107|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    107|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    107|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    107|	int _ret = (r); \
  |  |  |  |  178|    107|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 25, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  179|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     25|		goto err; \
  |  |  |  |  182|     25|	} \
  |  |  |  |  183|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* Only accept the original stuff */
  190|     82|	if (strcmp(p15card->tokeninfo->manufacturer_id, "DGP-FNMT") != 0) {
  ------------------
  |  Branch (190:6): [True: 60, False: 22]
  ------------------
  191|     60|		rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     60|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  192|     60|		LOG_TEST_GOTO_ERR(ctx, rv, "Wrong card.");
  ------------------
  |  |  184|     60|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     60|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     60|	int _ret = (r); \
  |  |  |  |  178|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 60, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     60|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     60|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     60|		goto err; \
  |  |  |  |  182|     60|	} \
  |  |  |  |  183|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     60|	}
  194|       |
  195|       |	/* Load ODF */
  196|     22|	rv = dump_ef(p15card->card, "3F0050155031", buf, &len);
  197|     22|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of ODF failed.");
  ------------------
  |  |  184|     22|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     22|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     22|	int _ret = (r); \
  |  |  |  |  178|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|     18|	rv = parse_odf(buf, len, p15card);
  200|     18|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of ODF failed.");
  ------------------
  |  |  184|     18|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     18|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     18|	int _ret = (r); \
  |  |  |  |  178|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  179|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      2|		goto err; \
  |  |  |  |  182|      2|	} \
  |  |  |  |  183|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|       |	/* Decode EF.PrKDF, EF.PuKDF and EF.CDF */
  203|     73|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (203:30): [True: 57, False: 16]
  ------------------
  204|     57|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|     57|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (204:7): [True: 10, False: 47]
  ------------------
  205|     10|			rv = sc_pkcs15_parse_df(p15card, df);
  206|     10|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  |  Branch (206:8): [True: 10, False: 0]
  ------------------
  207|     10|				sc_log(ctx,
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  208|     10|				       "Decoding of EF.PrKDF (%s) failed: %d",
  209|     10|				       sc_print_path(&df->path), rv);
  210|     10|			}
  211|     10|		}
  212|     57|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|     57|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (212:7): [True: 8, False: 49]
  ------------------
  213|      8|			rv = sc_pkcs15_parse_df(p15card, df);
  214|      8|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  |  Branch (214:8): [True: 8, False: 0]
  ------------------
  215|      8|				sc_log(ctx,
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  216|      8|				       "Decoding of EF.PuKDF (%s) failed: %d",
  217|      8|				       sc_print_path(&df->path), rv);
  218|      8|			}
  219|      8|		}
  220|     57|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|     57|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (220:7): [True: 1, False: 56]
  ------------------
  221|      1|			rv = sc_pkcs15_parse_df(p15card, df);
  222|      1|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:8): [True: 1, False: 0]
  ------------------
  223|      1|				sc_log(ctx,
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  224|      1|				       "Decoding of EF.CDF (%s) failed: %d",
  225|      1|				       sc_print_path(&df->path), rv);
  226|      1|			}
  227|      1|		}
  228|     57|		if (df->type == SC_PKCS15_DODF) {
  ------------------
  |  |  495|     57|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (228:7): [True: 21, False: 36]
  ------------------
  229|     21|			rv = sc_pkcs15_parse_df(p15card, df);
  230|     21|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     21|#define SC_SUCCESS				0
  ------------------
  |  Branch (230:8): [True: 21, False: 0]
  ------------------
  231|     21|				sc_log(ctx,
  ------------------
  |  |   71|     21|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  232|     21|				       "Decoding of EF.DODF (%s) failed: %d",
  233|     21|				       sc_print_path(&df->path), rv);
  234|     21|			}
  235|     21|		}
  236|     57|	}
  237|       |
  238|       |	/* Perform required fixes */
  239|     16|	p15_obj = p15card->obj_list;
  240|     16|	while (p15_obj != NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 16]
  ------------------
  241|       |		/* Add missing 'auth_id' to private objects */
  242|      0|		if ((p15_obj->flags & SC_PKCS15_CO_FLAG_PRIVATE)
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (242:7): [True: 0, False: 0]
  ------------------
  243|      0|		    && (p15_obj->auth_id.len == 0)) {
  ------------------
  |  Branch (243:10): [True: 0, False: 0]
  ------------------
  244|      0|			p15_obj->auth_id.value[0] = 0x01;
  245|      0|			p15_obj->auth_id.len = 1;
  246|      0|		};
  247|       |		/* Set path count to -1 for public certificates, as they
  248|       |		   will need to be decompressed and read_binary()'d, so
  249|       |		   we make sure we end up reading the file->size and not the
  250|       |		   path->count which is the compressed size on newer
  251|       |                   DNIe versions  */
  252|      0|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_CDF) ) {
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (252:8): [True: 0, False: 0]
  |  Branch (252:23): [True: 0, False: 0]
  ------------------
  253|      0|                    p15_info = (struct sc_pkcs15_cert_info *) p15_obj ->data;
  254|      0|		    p15_info ->path.count = -1;
  255|      0|		}
  256|       |		/* Remove found public keys as cannot be read_binary()'d */
  257|      0|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_PUKDF) ) {
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (257:8): [True: 0, False: 0]
  |  Branch (257:23): [True: 0, False: 0]
  ------------------
  258|      0|			sc_pkcs15_object_t *puk = p15_obj;
  259|      0|			p15_obj = p15_obj->next;
  260|      0|			sc_pkcs15_remove_object(p15card, puk);
  261|      0|			sc_pkcs15_free_object(puk);
  262|      0|                } else {
  263|      0|			p15_obj = p15_obj->next;
  264|      0|		}
  265|      0|	}
  266|       |	
  267|     16|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|    514|err:
  270|    514|	sc_pkcs15_card_clear(p15card);
  271|    514|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    514|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    514|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    514|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    514|	int _ret = r; \
  |  |  |  |  155|    514|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 514, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    514|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    514|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 514, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    514|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    514|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    514|	return _ret; \
  |  |  |  |  163|    514|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    514|}
pkcs15-dnie.c:dump_ef:
   42|    552|{
   43|    552|	int rv;
   44|    552|	sc_file_t *file = NULL;
   45|    552|	sc_path_t scpath;
   46|    552|	sc_format_path(path, &scpath);
   47|    552|	rv = sc_select_file(card, &scpath, &file);
   48|    552|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 409, False: 143]
  ------------------
   49|    409|		sc_file_free(file);
   50|    409|		return rv;
   51|    409|	}
   52|    143|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 15, False: 128]
  ------------------
   53|     15|		sc_file_free(file);
   54|     15|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     15|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|     15|	}
   56|    128|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   57|    128|	sc_file_free(file);
   58|    128|	if (rv < 0)
  ------------------
  |  Branch (58:6): [True: 3, False: 125]
  ------------------
   59|      3|		return rv;
   60|    125|	*buf_len = rv;
   61|       |
   62|    125|	return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
   63|    128|}
pkcs15-dnie.c:parse_odf:
  101|     18|{
  102|     18|	const u8 *p = buf;
  103|     18|	size_t left = buflen;
  104|     18|	int r, i, type;
  105|     18|	sc_path_t path;
  106|     18|	struct sc_asn1_entry asn1_obj_or_path[] = {
  107|     18|		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  174|     18|#define SC_ASN1_PATH			256
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  141|     18|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  162|     18|#define SC_ASN1_SEQUENCE                16
  ------------------
  108|     18|		 &path, NULL},
  109|     18|		{NULL, 0, 0, 0, NULL, NULL}
  110|     18|	};
  111|     18|	struct sc_asn1_entry asn1_odf[10];
  112|       |
  113|     18|	sc_path_t path_prefix;
  114|       |
  115|     18|	sc_format_path("3F005015", &path_prefix);
  116|       |
  117|     18|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  118|    180|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (118:14): [True: 162, False: 18]
  ------------------
  119|    162|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  120|     80|	while (left > 0) {
  ------------------
  |  Branch (120:9): [True: 79, False: 1]
  ------------------
  121|     79|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left,
  122|     79|					  &p, &left);
  123|     79|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     79|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (123:7): [True: 15, False: 64]
  ------------------
  124|     15|			break;
  125|     64|		if (r < 0)
  ------------------
  |  Branch (125:7): [True: 2, False: 62]
  ------------------
  126|      2|			return r;
  127|     62|		type = r;
  128|     62|		r = sc_pkcs15_make_absolute_path(&path_prefix, &path);
  129|     62|		if (r < 0)
  ------------------
  |  Branch (129:7): [True: 0, False: 62]
  ------------------
  130|      0|			return r;
  131|     62|		r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  132|     62|		if (r)
  ------------------
  |  Branch (132:7): [True: 0, False: 62]
  ------------------
  133|      0|			return r;
  134|     62|	}
  135|     16|	return 0;
  136|     18|}

sc_pkcs15emu_dtrust_init_ex:
  125|  7.45k|{
  126|  7.45k|	if (dtrust_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (126:6): [True: 7.45k, False: 0]
  ------------------
  127|  7.45k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  128|       |
  129|      0|	return sc_pkcs15emu_dtrust_init(p15card, aid);
  130|  7.45k|}
pkcs15-dtrust.c:dtrust_pkcs15emu_detect_card:
   82|  7.45k|{
   83|  7.45k|	if (p15card->card->type < SC_CARD_TYPE_DTRUST_V4_1_STD)
  ------------------
  |  Branch (83:6): [True: 7.45k, False: 0]
  ------------------
   84|  7.45k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   85|       |
   86|      0|	if (p15card->card->type > SC_CARD_TYPE_DTRUST_V5_4_MULTI)
  ------------------
  |  Branch (86:6): [True: 0, False: 0]
  ------------------
   87|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   88|       |
   89|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
   90|      0|}

sc_pkcs15emu_eoi_init_ex:
   35|  7.45k|{
   36|  7.45k|	struct sc_card *card = p15card->card;
   37|  7.45k|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
   38|  7.45k|	struct sc_pkcs15_search_key sk;
   39|  7.45k|	struct sc_pkcs15_object *objs[MAX_OBJECTS];
   40|  7.45k|	int i, j, len;
   41|       |
   42|  7.45k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   43|       |
   44|  7.45k|	if (card->type != SC_CARD_TYPE_EOI && card->type != SC_CARD_TYPE_EOI_CONTACTLESS)
  ------------------
  |  Branch (44:6): [True: 7.45k, False: 0]
  |  Branch (44:40): [True: 7.45k, False: 0]
  ------------------
   45|  7.45k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  7.45k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.45k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.45k|	int _ret = r; \
  |  |  |  |  155|  7.45k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.45k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.45k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.45k|	return _ret; \
  |  |  |  |  163|  7.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   46|       |
   47|      0|	if (!privdata)
  ------------------
  |  Branch (47:6): [True: 0, False: 0]
  ------------------
   48|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   49|       |
   50|       |	/*
   51|       |	 * Some of the data is not accessible over the unencrypted channel
   52|       |	 * when contactless reader is used. So start SM now (if not yet established).
   53|       |	 */
   54|      0|	if (card->type == SC_CARD_TYPE_EOI_CONTACTLESS && card->sm_ctx.sm_mode == SM_MODE_NONE) {
  ------------------
  |  |   43|      0|#define SM_MODE_NONE		0x0
  ------------------
  |  Branch (54:6): [True: 0, False: 0]
  |  Branch (54:52): [True: 0, False: 0]
  ------------------
   55|      0|		int r = card->sm_ctx.ops.open(card);
   56|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:7): [True: 0, False: 0]
  ------------------
   57|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|      0|	}
   59|       |
   60|       |	/*
   61|       |	 * Get the card objects, so we can manipulate them. See below
   62|       |	 */
   63|      0|	LOG_TEST_RET(card->ctx, sc_pkcs15_bind_internal(p15card, aid),
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   64|      0|		"sc_pkcs15_bind_internal failed");
   65|       |
   66|       |	/*
   67|       |	 * PIN objects:
   68|       |	 * 1) Find the "Card CAN" PIN and store it's path, so we'll be able to fetch the CAN and do the PACE auth
   69|       |	 * 2) Add PIN's auth_info->path to the list of paths that can fail on select. sc_pin_cmd would break otherwise
   70|       |	 */
   71|      0|	memset(&sk, 0, sizeof(sk));
   72|      0|	sk.class_mask = SC_PKCS15_SEARCH_CLASS_AUTH;
  ------------------
  |  |  455|      0|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
   73|      0|	len = sc_pkcs15_search_objects(p15card, &sk, (struct sc_pkcs15_object **)&objs, MAX_OBJECTS);
  ------------------
  |  |   24|      0|#define MAX_OBJECTS 8
  ------------------
   74|      0|	for (i = 0, j = 0; i < len; i++) {
  ------------------
  |  Branch (74:21): [True: 0, False: 0]
  ------------------
   75|      0|		struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)objs[i]->data;
   76|      0|		if (auth_info && auth_info->auth_id.len == 8 && !strcmp((char*)auth_info->auth_id.value, "Card CAN")) {
  ------------------
  |  Branch (76:7): [True: 0, False: 0]
  |  Branch (76:20): [True: 0, False: 0]
  |  Branch (76:51): [True: 0, False: 0]
  ------------------
   77|      0|			auth_info->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|      0|#define SC_PATH_TYPE_PATH		2
  ------------------
   78|       |			/* Read the file that contains serial and encrypted CAN */
   79|      0|			if (sc_pkcs15_read_file(p15card, &auth_info->path, &privdata->enc_can.value, &privdata->enc_can.len, 0) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (79:8): [True: 0, False: 0]
  ------------------
   80|       |				/* File should be 24 bytes long */
   81|      0|				if (privdata->enc_can.len != 24)
  ------------------
  |  Branch (81:9): [True: 0, False: 0]
  ------------------
   82|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   83|      0|				if (strlen(p15card->tokeninfo->serial_number) != 20)
  ------------------
  |  Branch (83:9): [True: 0, False: 0]
  ------------------
   84|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|       |				/* First 8 bytes are used as serial number */
   86|      0|				sc_bin_to_hex(privdata->enc_can.value, 8, &p15card->tokeninfo->serial_number[4], 17, 0);
   87|      0|			}
   88|       |			/* Do not add "Card CAN" to the list of PIN paths to ignore, otherwise the 2nd PKCS#15 app can not access it */
   89|      0|			auth_info = NULL;
   90|       |			/* Mark "Card CAN" as NOT a PIN object, so that it doesn't get it's own PKCS#11 slot */
   91|      0|			objs[i]->type &= ~SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|      0|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
   92|      0|		}
   93|       |		/*
   94|       |		 * For some reason QES app has "Norm PUK" not flagged as unblocking PIN and thus "Norm PUK" appears as a slot in
   95|       |		 * PKCS#11. Flag it as unblockingPin, so it doesn't appear as a separate slot.
   96|       |		 */
   97|      0|		if (auth_info && auth_info->auth_id.len == 8 && !strcmp((char*)auth_info->auth_id.value, "Norm PUK")) {
  ------------------
  |  Branch (97:7): [True: 0, False: 0]
  |  Branch (97:20): [True: 0, False: 0]
  |  Branch (97:51): [True: 0, False: 0]
  ------------------
   98|      0|			auth_info->attrs.pin.flags |= SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
   99|      0|		}
  100|      0|		if (auth_info) {
  ------------------
  |  Branch (100:7): [True: 0, False: 0]
  ------------------
  101|      0|			privdata->pin_paths[j++] = &auth_info->path;
  102|      0|		}
  103|      0|	}
  104|       |
  105|       |	/*
  106|       |	 * Private key objects:
  107|       |	 * 1) Rename "Card PIN" to "Norm PIN" as it's the later name that is used throughout the PKCS#15 objects
  108|       |	 * 2) Add the key references to the prkey_mappings array, as it seems that eOI expects them counted from 0xA0 up (starting from 1 within each app)
  109|       |	 *    Currently there are 3 private keys on the card
  110|       |	 *     key_ref
  111|       |	 *       2 - for pinless entry (Prijava brez PIN-a), maps to 0xA1
  112|       |	 *       1 - for authentication in QES app (Podpis in prijava), maps to 0xA1
  113|       |	 *       3 - for signing in QES app (Podpis in prijava), maps to 0xA2
  114|       |	 */
  115|      0|	memset(&sk, 0, sizeof(sk));
  116|      0|	sk.class_mask = SC_PKCS15_SEARCH_CLASS_PRKEY;
  ------------------
  |  |  450|      0|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  117|      0|	len = sc_pkcs15_search_objects(p15card, &sk, (struct sc_pkcs15_object **)&objs, MAX_OBJECTS);
  ------------------
  |  |   24|      0|#define MAX_OBJECTS 8
  ------------------
  118|       |	/*
  119|       |	 * If both PKCS#15 apps are enabled, prkey_mappings can already be partially filled up from the first PKCS#15 app
  120|       |	 * as the privdata is shared between both apps which use the same driver
  121|       |	  */
  122|      0|	for (j = 0; j < MAX_OBJECTS && privdata->prkey_mappings[j][1] != 0; j++) {
  ------------------
  |  |   24|      0|#define MAX_OBJECTS 8
  ------------------
  |  Branch (122:14): [True: 0, False: 0]
  |  Branch (122:33): [True: 0, False: 0]
  ------------------
  123|       |		/* NOP */
  124|      0|	}
  125|      0|	for (i = 0; i < len; i++) {
  ------------------
  |  Branch (125:14): [True: 0, False: 0]
  ------------------
  126|      0|		struct sc_pkcs15_prkey_info *prkey_info = (struct sc_pkcs15_prkey_info *)objs[i]->data;
  127|      0|		if ((objs[i]->auth_id.len == 8) && !strncmp((char*)objs[i]->auth_id.value, "Card PIN", 8)) {
  ------------------
  |  Branch (127:7): [True: 0, False: 0]
  |  Branch (127:38): [True: 0, False: 0]
  ------------------
  128|      0|			memcpy(objs[i]->auth_id.value, "Norm PIN", 8);
  129|      0|		}
  130|      0|		if (prkey_info && j < MAX_OBJECTS) {
  ------------------
  |  |   24|      0|#define MAX_OBJECTS 8
  ------------------
  |  Branch (130:7): [True: 0, False: 0]
  |  Branch (130:21): [True: 0, False: 0]
  ------------------
  131|      0|			privdata->prkey_mappings[j][0] = prkey_info->key_reference;
  132|      0|			privdata->prkey_mappings[j++][1] = 0xA0 + (i + 1);
  133|      0|		}
  134|      0|	}
  135|       |
  136|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  137|      0|}

sc_pkcs15emu_entersafe_init_ex:
   79|  9.28k|{
   80|  9.28k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.28k]
  |  |  ------------------
  ------------------
   81|       |
   82|  9.28k|	if (entersafe_detect_card(p15card))
  ------------------
  |  Branch (82:6): [True: 9.10k, False: 186]
  ------------------
   83|  9.10k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.10k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   84|    186|	return sc_pkcs15emu_entersafe_init(p15card);
   85|  9.28k|}
pkcs15-esinit.c:entersafe_detect_card:
   33|  9.28k|{
   34|  9.28k|	sc_card_t *card = p15card->card;
   35|       |
   36|  9.28k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.28k]
  |  |  ------------------
  ------------------
   37|       |
   38|       |	/* check if we have the correct card OS */
   39|  9.28k|	if (strcmp(card->name, "entersafe"))
  ------------------
  |  Branch (39:6): [True: 9.10k, False: 186]
  ------------------
   40|  9.10k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.10k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   41|       |
   42|    186|    return SC_SUCCESS;
  ------------------
  |  |   28|    186|#define SC_SUCCESS				0
  ------------------
   43|  9.28k|}
pkcs15-esinit.c:sc_pkcs15emu_entersafe_init:
   46|    186|{
   47|    186|	int    r;
   48|    186|	char   buf[256];
   49|    186|	sc_card_t *card = p15card->card;
   50|    186|	sc_serial_number_t serial;
   51|       |
   52|    186|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    186|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    186|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    186|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 186]
  |  |  ------------------
  ------------------
   53|       |
   54|       |	/* get serial number */
   55|    186|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   56|    186|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    186|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:6): [True: 184, False: 2]
  ------------------
   57|    184|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    184|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|      2|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   59|      2|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  |  Branch (59:6): [True: 0, False: 2]
  ------------------
   60|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   61|       |
   62|      2|	set_string(&p15card->tokeninfo->serial_number, buf);
   63|      2|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (63:6): [True: 0, False: 2]
  ------------------
   64|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   65|       |
   66|       |	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
   67|      2|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   30|      2|#define MANU_ID		"entersafe"
  ------------------
   68|      2|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (68:6): [True: 0, False: 2]
  ------------------
   69|      0|		free(p15card->tokeninfo->serial_number);
   70|      0|		p15card->tokeninfo->serial_number = NULL;
   71|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   72|      0|	}
   73|       |
   74|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
   75|      2|}

sc_pkcs15emu_esteid2018_init_ex:
  256|  7.46k|int sc_pkcs15emu_esteid2018_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid) {
  257|  7.46k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2018 ||
  ------------------
  |  Branch (257:6): [True: 60, False: 7.40k]
  ------------------
  258|  7.40k|			p15card->card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025 ||
  ------------------
  |  Branch (258:4): [True: 0, False: 7.40k]
  ------------------
  259|  7.40k|			is_latvian_eid(p15card))
  ------------------
  |  Branch (259:4): [True: 0, False: 7.40k]
  ------------------
  260|     60|		return sc_pkcs15emu_esteid2018_init(p15card);
  261|  7.40k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.40k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  262|  7.46k|}
pkcs15-esteid2018.c:is_latvian_eid:
   38|  7.41k|{
   39|  7.41k|	return p15card->card->type == SC_CARD_TYPE_LATEID_2018 ||
  ------------------
  |  Branch (39:9): [True: 0, False: 7.41k]
  ------------------
   40|  7.41k|	       p15card->card->type == SC_CARD_TYPE_LATEID_2018_V2_2025;
  ------------------
  |  Branch (40:9): [True: 0, False: 7.41k]
  ------------------
   41|  7.41k|}
pkcs15-esteid2018.c:sc_pkcs15emu_esteid2018_init:
   43|     60|static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
   44|     60|	sc_card_t *card = p15card->card;
   45|     60|	u8 buff[11];
   46|     60|	int r, i, cert_slot = 0;
   47|     60|	size_t field_length = 0, taglen, buflen;
   48|     60|	sc_path_t tmppath;
   49|       |
   50|       |	/* Read documber number to be used as serial */
   51|     60|	sc_format_path("3F00D003", &tmppath);
   52|     60|	LOG_TEST_RET(card->ctx, sc_select_file(card, &tmppath, NULL), "SELECT docnr");
  ------------------
  |  |  174|     60|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     60|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     60|	int _ret = (r); \
  |  |  |  |  168|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  169|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     20|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     20|		return _ret; \
  |  |  |  |  172|     20|	} \
  |  |  |  |  173|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|     40|	r = sc_read_binary(card, 0, buff, 11, 0);
   54|     40|	LOG_TEST_RET(card->ctx, r, "read document number failed");
  ------------------
  |  |  174|     40|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     40|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     40|	int _ret = (r); \
  |  |  |  |  168|     40|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   55|     35|	const u8 *tag = sc_asn1_find_tag(card->ctx, buff, (size_t)r, 0x04, &taglen);
   56|     35|	if (tag == NULL)
  ------------------
  |  Branch (56:6): [True: 30, False: 5]
  ------------------
   57|     35|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|       |
   59|     15|	for (size_t j = 0; j < taglen; j++)
  ------------------
  |  Branch (59:21): [True: 13, False: 2]
  ------------------
   60|     13|		if (!isalnum(tag[j]))
  ------------------
  |  Branch (60:7): [True: 3, False: 10]
  ------------------
   61|      5|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   62|      2|	free(p15card->tokeninfo->serial_number);
   63|      2|	p15card->tokeninfo->serial_number = malloc(taglen + 1);
   64|      2|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (64:6): [True: 0, False: 2]
  ------------------
   65|      2|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   66|       |
   67|      2|	set_string(&p15card->tokeninfo->label, "ID-kaart");
   68|      2|	set_string(&p15card->tokeninfo->manufacturer_id, "IDEMIA");
   69|      2|	p15card->tokeninfo->serial_number = memcpy(p15card->tokeninfo->serial_number, tag, taglen);
   70|      2|	p15card->tokeninfo->serial_number[taglen] = '\0';
   71|      2|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      2|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
   72|       |
   73|      2|	if (is_latvian_eid(p15card)) {
  ------------------
  |  Branch (73:6): [True: 0, False: 2]
  ------------------
   74|      0|		u8 *buf;
   75|      0|		const u8 *ptr;
   76|      0|		sc_pkcs15_object_t obj = {0};
   77|      0|		sc_pkcs15_cert_info_t *cert_info = NULL;
   78|       |
   79|      0|		if (!p15card->file_app) {
  ------------------
  |  Branch (79:7): [True: 0, False: 0]
  ------------------
   80|      0|			p15card->file_app = sc_file_new();
   81|      0|		}
   82|      0|		if (!p15card->file_app) {
  ------------------
  |  Branch (82:7): [True: 0, False: 0]
  ------------------
   83|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   84|      0|		}
   85|       |
   86|      0|		sc_format_path("3F00adf1", &p15card->file_app->path);
   87|      0|		sc_format_path("3F00adf17005", &tmppath);
   88|      0|		r = sc_pkcs15_read_file(p15card, &tmppath, &buf, &buflen, 0);
   89|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Reading EF.CDF file failed");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|      0|		ptr = buf;
   91|      0|		r = sc_pkcs15_decode_cdf_entry(p15card, &obj, &ptr, &buflen);
   92|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Decoding EF.CDF file failed");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|       |
   94|      0|		cert_info = (struct sc_pkcs15_cert_info *)obj.data;
   95|      0|		if (cert_info && cert_info->path.len > 0) {
  ------------------
  |  Branch (95:7): [True: 0, False: 0]
  |  Branch (95:20): [True: 0, False: 0]
  ------------------
   96|      0|			cert_slot = cert_info->path.value[cert_info->path.len - 1] - 1;
   97|      0|			if (cert_slot != 0 && cert_slot != 1) {
  ------------------
  |  Branch (97:8): [True: 0, False: 0]
  |  Branch (97:26): [True: 0, False: 0]
  ------------------
   98|       |				/* unknown slot, see `cert_paths` below */
   99|      0|				r = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      0|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  100|      0|				LOG_TEST_GOTO_ERR(card->ctx, r, "Unknown certificate path");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|      0|			}
  102|      0|		}
  103|       |
  104|      0|		sc_pkcs15_free_cert_info(cert_info);
  105|      0|		sc_file_free(p15card->file_app);
  106|      0|		p15card->file_app = NULL;
  107|      0|		free(buf);
  108|      0|	}
  109|       |
  110|       |	/* add certificates */
  111|      2|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (111:14): [True: 2, False: 0]
  ------------------
  112|      2|		static const char *esteid_cert_names[2] = {"Isikutuvastus", "Allkirjastamine"};
  113|      2|		static const char *cert_paths[2][2] = {
  114|      2|				{"3f00:adf1:3401", "3f00:adf2:341f"},
  115|      2|				{"3f00:adf1:3402", "3f00:adf2:341e"}
  116|      2|		    };
  117|      2|		static const u8 esteid_cert_ids[2] = {1, 2};
  118|       |
  119|      2|		struct sc_pkcs15_cert_info cert_info = {
  120|      2|				.id = {.len = 1, .value[0] = esteid_cert_ids[i]}
  121|      2|		};
  122|      2|		struct sc_pkcs15_object cert_obj = {0};
  123|       |
  124|      2|		strlcpy(cert_obj.label, esteid_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|      2|#define strlcpy _strlcpy
  ------------------
  125|      2|		sc_format_path(cert_paths[cert_slot][i], &cert_info.path);
  126|      2|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  127|      2|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not add cert oebjct");
  ------------------
  |  |  184|      2|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      2|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      2|	int _ret = (r); \
  |  |  |  |  178|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|       |		// Read data from first cert
  130|      2|		if (i != 0)
  ------------------
  |  Branch (130:7): [True: 0, False: 2]
  ------------------
  131|      0|			continue;
  132|       |
  133|      2|		sc_pkcs15_cert_t *cert = NULL;
  134|      2|		r = sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert);
  135|      2|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not read authentication certificate");
  ------------------
  |  |  184|      2|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      2|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      2|	int _ret = (r); \
  |  |  |  |  178|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      2|		goto err; \
  |  |  |  |  182|      2|	} \
  |  |  |  |  183|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  136|       |
  137|      0|		if (cert->key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			field_length = cert->key->u.ec.params.field_length;
  139|       |
  140|      0|		static const struct sc_object_id cn_oid = {
  141|      0|				{2, 5, 4, 3, -1}
  142|      0|		};
  143|      0|		u8 *cn_name = NULL;
  144|      0|		size_t cn_len = 0;
  145|      0|		sc_pkcs15_get_name_from_dn(card->ctx, cert->subject, cert->subject_len, &cn_oid, &cn_name, &cn_len);
  146|      0|		sc_pkcs15_free_certificate(cert);
  147|      0|		if (cn_len > 0) {
  ------------------
  |  Branch (147:7): [True: 0, False: 0]
  ------------------
  148|      0|			char *token_name = (char *)realloc(cn_name, cn_len + 1);
  149|      0|			if (token_name) {
  ------------------
  |  Branch (149:8): [True: 0, False: 0]
  ------------------
  150|      0|				token_name[cn_len] = '\0';
  151|      0|				free(p15card->tokeninfo->label);
  152|      0|				p15card->tokeninfo->label = token_name;
  153|      0|			} else
  154|      0|				free(cn_name);
  155|      0|		}
  156|      0|	}
  157|       |
  158|       |	/* add pins */
  159|      0|	static const u8 pin_authid[3] = {1, 2, 3};
  160|      0|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (160:14): [True: 0, False: 0]
  ------------------
  161|      0|		static const char *esteid_pin_names[3] = {"PIN1", "PIN2", "PUK"};
  162|      0|		static const size_t pin_min[2][3] = {
  163|      0|				{4, 5, 8}, // Estonian
  164|      0|				{4, 6, 8}, // Latvian
  165|      0|		};
  166|      0|		static const int esteid_pin_ref[3] = {0x01, 0x85, 0x02};
  167|      0|		static const char *esteid_pin_path[3] = {"3F00", "3F00ADF2", "3F00"};
  168|       |
  169|      0|		static const unsigned int esteid_pin_flags[3] = {
  170|      0|				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL,
  ------------------
  |  |   59|      0|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
              				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL,
  ------------------
  |  |   75|      0|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
  171|      0|				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PIN_LOCAL,
  ------------------
  |  |   59|      0|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
              				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PIN_LOCAL,
  ------------------
  |  |   78|      0|	( SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |               	( SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
  |  |  ------------------
  |  |  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  |  |  ------------------
  ------------------
  172|      0|				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PUK_GLOBAL};
  ------------------
  |  |   59|      0|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
              				SC_PKCS15_PIN_FLAG_NEEDS_PADDING | SC_PKCS15_PIN_TYPE_FLAGS_PUK_GLOBAL};
  ------------------
  |  |   81|      0|	( SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN				\
  |  |  ------------------
  |  |  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  |  |  ------------------
  |  |   82|      0|	| SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
  173|       |
  174|      0|		struct sc_pkcs15_auth_info pin_info = {
  175|      0|				.auth_id = {.len = 1, .value[0] = pin_authid[i]},
  176|      0|				.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN,
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  177|      0|				.attrs = {
  178|      0|						.pin = {
  179|      0|								.reference = esteid_pin_ref[i],
  180|      0|								.flags = esteid_pin_flags[i],
  181|      0|								.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|      0|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  182|      0|								.min_length = pin_min[is_latvian_eid(p15card)][i],
  183|      0|								.stored_length = 12,
  184|      0|								.max_length = 12,
  185|      0|								.pad_char = 0xFF}},
  186|      0|				.tries_left = 3,
  187|      0|				.max_tries = 3
  188|      0|		      };
  189|      0|		struct sc_pkcs15_object pin_obj = {
  190|      0|				.flags = esteid_pin_flags[i]};
  191|       |
  192|      0|		sc_format_path(esteid_pin_path[i], &pin_info.path);
  193|      0|		strlcpy(pin_obj.label, esteid_pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  194|       |
  195|       |		/* Link normal PINs with PUK */
  196|      0|		if (i < 2) {
  ------------------
  |  Branch (196:7): [True: 0, False: 0]
  ------------------
  197|      0|			pin_obj.auth_id.len = 1;
  198|      0|			pin_obj.auth_id.value[0] = 3;
  199|      0|		}
  200|       |
  201|      0|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  202|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not add pin object");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|      0|	}
  204|       |
  205|       |	// trigger PIN counter refresh via pin_cmd
  206|      0|	struct sc_pkcs15_object *objs[3];
  207|      0|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH, objs, 3);
  ------------------
  |  |  444|      0|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  208|      0|	if (r != 3) {
  ------------------
  |  Branch (208:6): [True: 0, False: 0]
  ------------------
  209|      0|		sc_log(card->ctx, "Can not get auth objects");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  210|      0|		goto err;
  211|      0|	}
  212|      0|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (212:14): [True: 0, False: 0]
  ------------------
  213|      0|		r = sc_pkcs15_get_pin_info(p15card, objs[i]);
  214|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not get pin object");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|      0|	}
  216|       |
  217|       |	/* add private keys */
  218|      0|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (218:14): [True: 0, False: 0]
  ------------------
  219|      0|		static const u8 prkey_id[2] = {1, 2};
  220|      0|		static const char *prkey_name[2] = {"Isikutuvastus", "Allkirjastamine"};
  221|      0|		static const char *prkey_path[2] = {"3F00:ADF1", "3F00:ADF2"};
  222|      0|		static const unsigned int prkey_usage[2] = {SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		static const unsigned int prkey_usage[2] = {SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  223|      0|				SC_PKCS15_PRKEY_USAGE_NONREPUDIATION};
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  224|      0|		static const int prkey_consent[2] = {0, 1};
  225|      0|		static const u8 prkey_ref[2][2] = {
  226|      0|				{0x81, 0x9F}, // Slot 1
  227|      0|				{0x82, 0x9E}, // Slot 2
  228|      0|		};
  229|       |
  230|      0|		struct sc_pkcs15_prkey_info prkey_info = {
  231|      0|				.id = {.len = 1, .value[0] = prkey_id[i]},
  232|      0|				.native = 1,
  233|      0|				.key_reference = prkey_ref[is_latvian_eid(p15card)][i],
  234|      0|				.field_length = field_length,
  235|      0|				.usage = prkey_usage[i]
  236|      0|		       };
  237|      0|		struct sc_pkcs15_object prkey_obj = {
  238|      0|				.auth_id = {.len = 1, .value[0] = pin_authid[i]},
  239|      0|				.user_consent = prkey_consent[i],
  240|      0|				.flags = SC_PKCS15_CO_FLAG_PRIVATE
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  241|      0|		  };
  242|       |
  243|      0|		sc_format_path(prkey_path[i], &prkey_info.path);
  244|      0|		strlcpy(prkey_obj.label, prkey_name[i], sizeof(prkey_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  245|       |
  246|      0|		r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
  247|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not add private key object");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  248|      0|	}
  249|       |
  250|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  251|      2|err:
  252|      2|	sc_pkcs15_card_clear(p15card);
  253|      2|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|      2|}

sc_pkcs15emu_esteid2025_init_ex:
  260|  7.46k|{
  261|  7.46k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2025 || is_fin_eid(p15card))
  ------------------
  |  Branch (261:6): [True: 0, False: 7.46k]
  |  Branch (261:57): [True: 0, False: 7.46k]
  ------------------
  262|      0|		return sc_pkcs15emu_esteid2025_init(p15card);
  263|  7.46k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.46k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  264|  7.46k|}
pkcs15-esteid2025.c:is_fin_eid:
   37|  7.46k|{
   38|  7.46k|	return p15card->card->type == SC_CARD_TYPE_FINEID_2022 ||
  ------------------
  |  Branch (38:9): [True: 0, False: 7.46k]
  ------------------
   39|  7.46k|	       p15card->card->type == SC_CARD_TYPE_FINEID_2025;
  ------------------
  |  Branch (39:9): [True: 0, False: 7.46k]
  ------------------
   40|  7.46k|}

sc_pkcs15emu_gemsafeV1_init_ex:
  451|  9.29k|{
  452|  9.29k|	if (gemsafe_detect_card(p15card))
  ------------------
  |  Branch (452:6): [True: 8.68k, False: 610]
  ------------------
  453|  8.68k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.68k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  454|    610|	return sc_pkcs15emu_gemsafeV1_init(p15card);
  455|  9.29k|}
pkcs15-gemsafeV1.c:gemsafe_detect_card:
  298|  9.29k|{
  299|  9.29k|	if (strcmp(p15card->card->name, "GemSAFE V1"))
  ------------------
  |  Branch (299:6): [True: 8.68k, False: 610]
  ------------------
  300|  8.68k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.68k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  301|       |
  302|    610|	return SC_SUCCESS;
  ------------------
  |  |   28|    610|#define SC_SUCCESS				0
  ------------------
  303|  9.29k|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_gemsafeV1_init:
  306|    610|{
  307|    610|	int		    r;
  308|    610|	unsigned int    i;
  309|    610|	struct sc_path  path;
  310|    610|	struct sc_file *file = NULL;
  311|    610|	struct sc_card *card = p15card->card;
  312|    610|	struct sc_apdu  apdu;
  313|    610|	u8		    rbuf[SC_MAX_APDU_BUFFER_SIZE];
  314|       |
  315|    610|	sc_log(p15card->card->ctx, "Setting pkcs15 parameters");
  ------------------
  |  |   71|    610|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  316|       |
  317|    610|	set_string(&p15card->tokeninfo->label, APPLET_NAME);
  ------------------
  |  |   32|    610|#define APPLET_NAME		"GemSAFE V1"
  ------------------
  318|    610|	if (!p15card->tokeninfo->label)
  ------------------
  |  Branch (318:6): [True: 0, False: 610]
  ------------------
  319|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  320|       |
  321|    610|	set_string(&p15card->tokeninfo->serial_number, DRIVER_SERIAL_NUMBER);
  ------------------
  |  |   33|    610|#define DRIVER_SERIAL_NUMBER	"v0.9"
  ------------------
  322|    610|	if (!p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (322:6): [True: 0, False: 610]
  ------------------
  323|      0|		free(p15card->tokeninfo->label);
  324|      0|		p15card->tokeninfo->label = NULL;
  325|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  326|      0|	}
  327|       |
  328|       |	/* the GemSAFE applet version number */
  329|    610|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0xdf, 0x03);
  ------------------
  |  |  292|    610|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  330|    610|	apdu.cla = 0x80;
  331|    610|	apdu.resp = rbuf;
  332|    610|	apdu.resplen = sizeof(rbuf);
  333|       |	/* Manual says Le=0x05, but should be 0x08 to return full version number */
  334|    610|	apdu.le = 0x08;
  335|    610|	apdu.lc = 0;
  336|    610|	apdu.datalen = 0;
  337|    610|	r = sc_transmit_apdu(card, &apdu);
  338|    610|	if (r < 0)
  ------------------
  |  Branch (338:6): [True: 5, False: 605]
  ------------------
  339|      5|		sc_pkcs15_card_clear(p15card);
  340|    610|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    610|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    610|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    610|	int _ret = (r); \
  |  |  |  |  168|    610|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 605]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|    610|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 605]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|    605|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || r != SC_SUCCESS) {
  ------------------
  |  |   28|    226|#define SC_SUCCESS				0
  ------------------
  |  Branch (342:6): [True: 368, False: 237]
  |  Branch (342:26): [True: 11, False: 226]
  |  Branch (342:46): [True: 0, False: 226]
  ------------------
  343|    379|		sc_pkcs15_card_clear(p15card);
  344|    379|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    379|#define SC_ERROR_INTERNAL			-1400
  ------------------
  345|    379|	}
  346|       |
  347|       |	/* the manufacturer ID, in this case GemPlus */
  348|    226|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   31|    226|#define MANU_ID			"Gemplus"
  ------------------
  349|    226|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (349:6): [True: 0, False: 226]
  ------------------
  350|      0|		sc_pkcs15_card_clear(p15card);
  351|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  352|      0|	}
  353|       |
  354|       |	/* determine allocated key containers and length of certificates */
  355|    226|	r = gemsafe_get_cert_len(card);
  356|    226|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    226|#define SC_SUCCESS				0
  ------------------
  |  Branch (356:6): [True: 196, False: 30]
  ------------------
  357|    196|		sc_pkcs15_card_clear(p15card);
  358|    196|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    196|#define SC_ERROR_INTERNAL			-1400
  ------------------
  359|    196|	}
  360|       |
  361|       |	/* set certs */
  362|     30|	sc_log(p15card->card->ctx, "Setting certificates");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  363|    390|	for (i = 0; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (363:14): [True: 360, False: 30]
  ------------------
  364|    360|		struct sc_pkcs15_id p15Id;
  365|    360|		struct sc_path path;
  366|       |
  367|    360|		if (gemsafe_cert[i].label == NULL)
  ------------------
  |  Branch (367:7): [True: 360, False: 0]
  ------------------
  368|    360|			continue;
  369|      0|		sc_format_path(gemsafe_cert[i].path, &path);
  370|      0|		sc_pkcs15_format_id(gemsafe_cert[i].id, &p15Id);
  371|      0|		path.index = gemsafe_cert[i].index;
  372|      0|		path.count = gemsafe_cert[i].count;
  373|      0|		sc_pkcs15emu_add_cert(p15card, SC_PKCS15_TYPE_CERT_X509,
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  374|      0|				      gemsafe_cert[i].authority, &path, &p15Id,
  375|      0|				      gemsafe_cert[i].label, gemsafe_cert[i].obj_flags);
  376|      0|	}
  377|       |
  378|       |	/* set gemsafe_pin */
  379|     30|	sc_log(p15card->card->ctx, "Setting PIN");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  380|     59|	for (i=0; i < gemsafe_pin_max; i++) {
  ------------------
  |  Branch (380:12): [True: 59, False: 0]
  ------------------
  381|     59|		struct sc_pkcs15_id	p15Id;
  382|     59|		struct sc_path path;
  383|       |
  384|     59|		sc_pkcs15_format_id(gemsafe_pin[i].id, &p15Id);
  385|     59|		sc_format_path(gemsafe_pin[i].path, &path);
  386|     59|		if (gemsafe_pin[i].atr_len == 0 ||
  ------------------
  |  Branch (386:7): [True: 29, False: 30]
  ------------------
  387|     30|		   (gemsafe_pin[i].atr_len == p15card->card->atr.len &&
  ------------------
  |  Branch (387:7): [True: 7, False: 23]
  ------------------
  388|      7|		    memcmp(p15card->card->atr.value, gemsafe_pin[i].atr,
  ------------------
  |  Branch (388:7): [True: 1, False: 6]
  ------------------
  389|     30|			   p15card->card->atr.len) == 0)) {
  390|     30|			sc_pkcs15emu_add_pin(p15card, &p15Id, gemsafe_pin[i].label,
  391|     30|					     &path, gemsafe_pin[i].ref, gemsafe_pin[i].type,
  392|     30|					     gemsafe_pin[i].minlen, gemsafe_pin[i].maxlen,
  393|     30|					     gemsafe_pin[i].flags, gemsafe_pin[i].tries_left,
  394|     30|					     gemsafe_pin[i].pad_char, gemsafe_pin[i].obj_flags);
  395|     30|			break;
  396|     30|		}
  397|     59|	};
  398|       |
  399|       |	/* set private keys */
  400|     30|	sc_log(p15card->card->ctx, "Setting private keys");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  401|    390|	for (i = 0; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (401:14): [True: 360, False: 30]
  ------------------
  402|    360|		struct sc_pkcs15_id p15Id, authId, *pauthId;
  403|    360|		struct sc_path path;
  404|    360|		int key_ref = 0x03;
  405|       |
  406|    360|		if (gemsafe_prkeys[i].label == NULL)
  ------------------
  |  Branch (406:7): [True: 360, False: 0]
  ------------------
  407|    360|			continue;
  408|      0|		sc_pkcs15_format_id(gemsafe_prkeys[i].id, &p15Id);
  409|      0|		if (gemsafe_prkeys[i].auth_id) {
  ------------------
  |  Branch (409:7): [True: 0, False: 0]
  ------------------
  410|      0|			sc_pkcs15_format_id(gemsafe_prkeys[i].auth_id, &authId);
  411|      0|			pauthId = &authId;
  412|      0|		} else
  413|      0|			pauthId = NULL;
  414|      0|		sc_format_path(gemsafe_prkeys[i].path, &path);
  415|       |		/*
  416|       |		 * The key ref may be different for different sites;
  417|       |		 * by adding flags=n where the low order 4 bits can be
  418|       |		 * the key ref we can force it.
  419|       |		 */
  420|      0|		if ( p15card->card->flags & 0x0F) {
  ------------------
  |  Branch (420:8): [True: 0, False: 0]
  ------------------
  421|      0|			key_ref = p15card->card->flags & 0x0F;
  422|      0|			sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  423|      0|				 "Overriding key_ref %d with %d\n",
  424|      0|				 gemsafe_prkeys[i].ref, key_ref);
  425|      0|		} else
  426|      0|			key_ref = gemsafe_prkeys[i].ref;
  427|      0|		sc_pkcs15emu_add_prkey(p15card, &p15Id, gemsafe_prkeys[i].label,
  428|      0|				       SC_PKCS15_TYPE_PRKEY_RSA,
  ------------------
  |  |  419|      0|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  429|      0|				       gemsafe_prkeys[i].modulus_len, gemsafe_prkeys[i].usage,
  430|      0|				       &path, key_ref, pauthId,
  431|      0|				       gemsafe_prkeys[i].obj_flags);
  432|      0|	}
  433|       |
  434|       |	/* select the application DF */
  435|     30|	sc_log(p15card->card->ctx, "Selecting application DF");
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  436|     30|	sc_format_path(GEMSAFE_APP_PATH, &path);
  ------------------
  |  |   34|     30|#define GEMSAFE_APP_PATH	"3F001600"
  ------------------
  437|     30|	r = sc_select_file(card, &path, &file);
  438|     30|	if (r != SC_SUCCESS || !file) {
  ------------------
  |  |   28|     60|#define SC_SUCCESS				0
  ------------------
  |  Branch (438:6): [True: 28, False: 2]
  |  Branch (438:25): [True: 0, False: 2]
  ------------------
  439|     28|		sc_pkcs15_card_clear(p15card);
  440|     28|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     28|#define SC_ERROR_INTERNAL			-1400
  ------------------
  441|     28|	}
  442|       |	/* set the application DF */
  443|      2|	sc_file_free(p15card->file_app);
  444|      2|	p15card->file_app = file;
  445|       |
  446|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  447|     30|}
pkcs15-gemsafeV1.c:gemsafe_get_cert_len:
  163|    226|{
  164|    226|	int r;
  165|    226|	u8  ibuf[GEMSAFE_MAX_OBJLEN];
  166|    226|	u8 *iptr;
  167|    226|	struct sc_path path;
  168|    226|	struct sc_file *file;
  169|    226|	size_t objlen;
  170|    226|	int certlen;
  171|    226|	unsigned int ind, i=0;
  172|    226|	int read_len;
  173|       |
  174|    226|	sc_format_path(GEMSAFE_PATH, &path);
  ------------------
  |  |   35|    226|#define GEMSAFE_PATH		"3F0016000004"
  ------------------
  175|    226|	r = sc_select_file(card, &path, &file);
  176|    226|	if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|    452|#define SC_SUCCESS				0
  ------------------
  |  Branch (176:6): [True: 96, False: 130]
  |  Branch (176:25): [True: 0, False: 130]
  ------------------
  177|     96|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     96|#define SC_ERROR_INTERNAL			-1400
  ------------------
  178|    130|	sc_file_free(file);
  179|       |
  180|       |	/* Initial read */
  181|    130|	read_len = sc_read_binary(card, 0, ibuf, GEMSAFE_READ_QUANTUM, 0);
  ------------------
  |  |   40|    130|#define GEMSAFE_READ_QUANTUM    248
  ------------------
  182|    130|	if (read_len <= 2) {
  ------------------
  |  Branch (182:6): [True: 20, False: 110]
  ------------------
  183|     20|		sc_log(card->ctx, "Invalid size of object data: %d", read_len);
  ------------------
  |  |   71|     20|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  184|     20|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     20|#define SC_ERROR_INTERNAL			-1400
  ------------------
  185|     20|	}
  186|       |
  187|       |	/* Actual stored object size is encoded in first 2 bytes
  188|       |	 * (allocated EF space is much greater!)
  189|       |	 */
  190|    110|	objlen = (((size_t) ibuf[0]) << 8) | ibuf[1];
  191|    110|	sc_log(card->ctx, "Stored object is of size: %zu", objlen);
  ------------------
  |  |   71|    110|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  192|    110|	if (objlen < 1 || objlen > GEMSAFE_MAX_OBJLEN) {
  ------------------
  |  |   41|    109|#define GEMSAFE_MAX_OBJLEN      28672
  ------------------
  |  Branch (192:6): [True: 1, False: 109]
  |  Branch (192:20): [True: 13, False: 96]
  ------------------
  193|     14|		sc_log(card->ctx, "Invalid object size: %zu", objlen);
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  194|     14|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     14|#define SC_ERROR_INTERNAL			-1400
  ------------------
  195|     14|	}
  196|       |
  197|       |	/* It looks like the first thing in the block is a table of
  198|       |	 * which keys are allocated. The table is small and is in the
  199|       |	 * first 248 bytes. Example for a card with 10 key containers:
  200|       |	 * 01 f0 00 03 03 b0 00 03     <=  1st key unallocated
  201|       |	 * 01 f0 00 04 03 b0 00 04     <=  2nd key unallocated
  202|       |	 * 01 fe 14 00 05 03 b0 00 05  <=  3rd key allocated
  203|       |	 * 01 fe 14 01 06 03 b0 00 06  <=  4th key allocated
  204|       |	 * 01 f0 00 07 03 b0 00 07     <=  5th key unallocated
  205|       |	 * ...
  206|       |	 * 01 f0 00 0c 03 b0 00 0c     <= 10th key unallocated
  207|       |	 * For allocated keys, the fourth byte seems to indicate the
  208|       |	 * default key and the fifth byte indicates the key_ref of
  209|       |	 * the private key.
  210|       |	 */
  211|     96|	ind = 2; /* skip length */
  212|    176|	while (ind + 1 < (size_t)read_len && ibuf[ind] == 0x01 && i < gemsafe_cert_max) {
  ------------------
  |  Branch (212:9): [True: 151, False: 25]
  |  Branch (212:39): [True: 80, False: 71]
  |  Branch (212:60): [True: 80, False: 0]
  ------------------
  213|     80|		if (ibuf[ind+1] == 0xFE) {
  ------------------
  |  Branch (213:7): [True: 10, False: 70]
  ------------------
  214|     10|			gemsafe_prkeys[i].ref = ibuf[ind+4];
  215|     10|			sc_log(card->ctx, "Key container %d is allocated and uses key_ref %d",
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  216|     10|					i+1, gemsafe_prkeys[i].ref);
  217|     10|			ind += 9;
  218|     10|		}
  219|     70|		else {
  220|     70|			gemsafe_prkeys[i].label = NULL;
  221|     70|			gemsafe_cert[i].label = NULL;
  222|     70|			sc_log(card->ctx, "Key container %d is unallocated", i+1);
  ------------------
  |  |   71|     70|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  223|     70|			ind += 8;
  224|     70|		}
  225|     80|		i++;
  226|     80|	}
  227|       |
  228|       |	/* Delete additional key containers from the data structures if
  229|       |	 * this card can't accommodate them.
  230|       |	 */
  231|  1.16k|	for (; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (231:9): [True: 1.07k, False: 96]
  ------------------
  232|  1.07k|		gemsafe_prkeys[i].label = NULL;
  233|  1.07k|		gemsafe_cert[i].label = NULL;
  234|  1.07k|	}
  235|       |
  236|       |	/* Read entire file, then dissect in memory.
  237|       |	 * Gemalto ClassicClient seems to do it the same way.
  238|       |	 */
  239|     96|	iptr = ibuf + read_len;
  240|    428|	while ((size_t)(iptr - ibuf) < objlen) {
  ------------------
  |  Branch (240:9): [True: 398, False: 30]
  ------------------
  241|    398|		r = sc_read_binary(card, (unsigned)(iptr - ibuf), iptr,
  242|    398|				   MIN(GEMSAFE_READ_QUANTUM, objlen - (iptr - ibuf)), 0);
  ------------------
  |  |   69|    398|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 348, False: 50]
  |  |  ------------------
  ------------------
  243|    398|		if (r < 0) {
  ------------------
  |  Branch (243:7): [True: 65, False: 333]
  ------------------
  244|     65|			sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   71|     65|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  245|     65|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     65|#define SC_ERROR_INTERNAL			-1400
  ------------------
  246|     65|		}
  247|    333|		if (r == 0)
  ------------------
  |  Branch (247:7): [True: 1, False: 332]
  ------------------
  248|      1|			break;
  249|    332|		read_len += r;
  250|    332|		iptr += r;
  251|    332|	}
  252|     31|	if ((size_t)read_len < objlen) {
  ------------------
  |  Branch (252:6): [True: 1, False: 30]
  ------------------
  253|      1|		sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  254|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
  255|      1|	}
  256|       |
  257|       |	/* Search buffer for certificates, they start with 0x3082. */
  258|     30|	i = 0;
  259|  1.66k|	while (ind < objlen - 1) {
  ------------------
  |  Branch (259:9): [True: 1.63k, False: 29]
  ------------------
  260|  1.63k|		if (ibuf[ind] == 0x30 && ibuf[ind+1] == 0x82) {
  ------------------
  |  Branch (260:7): [True: 222, False: 1.41k]
  |  Branch (260:28): [True: 1, False: 221]
  ------------------
  261|       |			/* Find next allocated key container */
  262|     13|			while (i < gemsafe_cert_max && gemsafe_cert[i].label == NULL)
  ------------------
  |  Branch (262:11): [True: 12, False: 1]
  |  Branch (262:35): [True: 12, False: 0]
  ------------------
  263|     12|				i++;
  264|      1|			if (i == gemsafe_cert_max) {
  ------------------
  |  Branch (264:8): [True: 1, False: 0]
  ------------------
  265|      1|				sc_log(card->ctx, "Warning: Found orphaned certificate at offset %d", ind);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  266|      1|				return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  267|      1|			}
  268|       |			/* DER cert len is encoded this way */
  269|      0|			if (ind+3 >= sizeof ibuf)
  ------------------
  |  Branch (269:8): [True: 0, False: 0]
  ------------------
  270|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  271|      0|			certlen = ((((int)ibuf[ind + 2]) << 8) | ibuf[ind + 3]) + 4;
  272|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  273|      0|			       "Found certificate of key container %d at offset %d, len %d",
  274|      0|			       i+1, ind, certlen);
  275|      0|			gemsafe_cert[i].index = ind;
  276|      0|			gemsafe_cert[i].count = certlen;
  277|      0|			ind += certlen;
  278|      0|			i++;
  279|      0|		} else
  280|  1.63k|			ind++;
  281|  1.63k|	}
  282|       |
  283|       |	/* Delete additional key containers from the data structures if
  284|       |	 * they're missing on the card.
  285|       |	 */
  286|    377|	for (; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (286:9): [True: 348, False: 29]
  ------------------
  287|    348|		if (gemsafe_cert[i].label) {
  ------------------
  |  Branch (287:7): [True: 0, False: 348]
  ------------------
  288|      0|			sc_log(card->ctx, "Warning: Certificate of key container %d is missing", i+1);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  289|      0|			gemsafe_prkeys[i].label = NULL;
  290|      0|			gemsafe_cert[i].label = NULL;
  291|      0|		}
  292|    348|	}
  293|       |
  294|     29|	return SC_SUCCESS;
  ------------------
  |  |   28|     29|#define SC_SUCCESS				0
  ------------------
  295|     30|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_add_object:
  490|     30|{
  491|     30|	sc_pkcs15_object_t *obj;
  492|     30|	int		df_type;
  493|       |
  494|     30|	obj = calloc(1, sizeof(*obj));
  495|     30|	if (!obj) {
  ------------------
  |  Branch (495:6): [True: 0, False: 30]
  ------------------
  496|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|      0|	}
  498|       |
  499|     30|	obj->type  = type;
  500|     30|	obj->data  = data;
  501|       |
  502|     30|	if (label)
  ------------------
  |  Branch (502:6): [True: 30, False: 0]
  ------------------
  503|     30|		strncpy(obj->label, label, sizeof(obj->label)-1);
  504|       |
  505|     30|	obj->flags = obj_flags;
  506|     30|	if (auth_id)
  ------------------
  |  Branch (506:6): [True: 0, False: 30]
  ------------------
  507|      0|		obj->auth_id = *auth_id;
  508|       |
  509|     30|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|     30|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  510|     30|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|     30|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (510:2): [True: 30, False: 0]
  ------------------
  511|     30|		df_type = SC_PKCS15_AODF;
  ------------------
  |  |  496|     30|#define SC_PKCS15_AODF			8
  ------------------
  512|     30|		break;
  513|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (513:2): [True: 0, False: 30]
  ------------------
  514|      0|		df_type = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|      0|#define SC_PKCS15_PRKDF			0
  ------------------
  515|      0|		break;
  516|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (516:2): [True: 0, False: 30]
  ------------------
  517|      0|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
  518|      0|		break;
  519|      0|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (519:2): [True: 0, False: 30]
  ------------------
  520|      0|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
  521|      0|		break;
  522|      0|	default:
  ------------------
  |  Branch (522:2): [True: 0, False: 30]
  ------------------
  523|      0|		sc_log(p15card->card->ctx, "Unknown PKCS15 object type %d", type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  524|      0|		free(obj);
  525|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  526|     30|	}
  527|       |
  528|     30|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  529|     30|	sc_pkcs15_add_object(p15card, obj);
  530|       |
  531|     30|	return 0;
  532|     30|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_get_df:
  459|     30|{
  460|     30|	sc_pkcs15_df_t	*df;
  461|     30|	sc_file_t	*file;
  462|     30|	int		created = 0;
  463|       |
  464|     60|	while (1) {
  ------------------
  |  Branch (464:9): [True: 60, Folded]
  ------------------
  465|     60|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (465:31): [True: 30, False: 30]
  ------------------
  466|     30|			if (df->type == type) {
  ------------------
  |  Branch (466:8): [True: 30, False: 0]
  ------------------
  467|     30|				if (created)
  ------------------
  |  Branch (467:9): [True: 30, False: 0]
  ------------------
  468|     30|					df->enumerated = 1;
  469|     30|				return df;
  470|     30|			}
  471|     30|		}
  472|       |
  473|     30|		if (created != 0)
  ------------------
  |  Branch (473:7): [True: 0, False: 30]
  ------------------
  474|      0|			return NULL;
  475|       |
  476|     30|		file = sc_file_new();
  477|     30|		if (!file)
  ------------------
  |  Branch (477:7): [True: 0, False: 30]
  ------------------
  478|      0|			return NULL;
  479|     30|		sc_format_path("11001101", &file->path);
  480|     30|		sc_pkcs15_add_df(p15card, type, &file->path);
  481|     30|		sc_file_free(file);
  482|     30|		created++;
  483|     30|	}
  484|     30|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_add_pin:
  541|     30|{
  542|     30|	sc_pkcs15_auth_info_t *info;
  543|       |
  544|     30|	info = calloc(1, sizeof(*info));
  545|     30|	if (!info)
  ------------------
  |  Branch (545:6): [True: 0, False: 30]
  ------------------
  546|     30|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  547|       |
  548|     30|	info->auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     30|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  549|     30|	info->auth_method = SC_AC_CHV;
  ------------------
  |  |  151|     30|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  550|     30|	info->auth_id           = *id;
  551|     30|	info->attrs.pin.min_length        = min_length;
  552|     30|	info->attrs.pin.max_length        = max_length;
  553|     30|	info->attrs.pin.stored_length     = max_length;
  554|     30|	info->attrs.pin.type              = type;
  555|     30|	info->attrs.pin.reference         = ref;
  556|     30|	info->attrs.pin.flags             = flags;
  557|     30|	info->attrs.pin.pad_char          = pad_char;
  558|     30|	info->tries_left        = tries_left;
  559|     30|	info->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|     30|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  560|       |
  561|     30|	if (path)
  ------------------
  |  Branch (561:6): [True: 30, False: 0]
  ------------------
  562|     30|		info->path = *path;
  563|       |
  564|     30|	return sc_pkcs15emu_add_object(p15card, SC_PKCS15_TYPE_AUTH_PIN, label, info, NULL, obj_flags);
  ------------------
  |  |  445|     30|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  565|     30|}

sc_pkcs15emu_gids_init_ex:
  241|  9.11k|{
  242|  9.11k|	if (p15card->card->type != SC_CARD_TYPE_GIDS_GENERIC && p15card->card->type != SC_CARD_TYPE_GIDS_V1 && p15card->card->type != SC_CARD_TYPE_GIDS_V2) {
  ------------------
  |  Branch (242:6): [True: 8.99k, False: 118]
  |  Branch (242:58): [True: 8.99k, False: 1]
  |  Branch (242:105): [True: 8.99k, False: 1]
  ------------------
  243|  8.99k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.99k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  244|  8.99k|	}
  245|    120|	return sc_pkcs15emu_gids_init(p15card);
  246|  9.11k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  112|    120|{
  113|    120|	sc_card_t *card = p15card->card;
  114|    120|	int r;
  115|    120|	size_t i;
  116|    120|	struct sc_pkcs15_auth_info pin_info;
  117|    120|	struct sc_pkcs15_object pin_obj;
  118|    120|	struct sc_pin_cmd_data pin_cmd_data;
  119|    120|	size_t recordsnum;
  120|    120|	int has_puk;
  121|       |
  122|    120|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  123|    120|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  174|    120|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    120|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    120|	int _ret = (r); \
  |  |  |  |  168|    120|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 120, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    120|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    120|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    120|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    120|		return _ret; \
  |  |  |  |  172|    120|	} \
  |  |  |  |  173|    120|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|       |
  125|      0|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, NULL);
  126|      0|	LOG_TEST_RET(card->ctx, r, "unable to get the serial number. Uninitialized card ?");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  127|       |
  128|      0|	free(p15card->tokeninfo->serial_number);
  129|      0|	p15card->tokeninfo->serial_number = (char*) malloc(card->serialnr.len *2 +1);
  130|      0|	if (!p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (130:6): [True: 0, False: 0]
  ------------------
  131|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  132|      0|	}
  133|      0|	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, p15card->tokeninfo->serial_number, card->serialnr.len *2 +1, 0);
  134|       |
  135|      0|	if (p15card->tokeninfo->label == NULL) {
  ------------------
  |  Branch (135:6): [True: 0, False: 0]
  ------------------
  136|      0|		p15card->tokeninfo->label = strdup("GIDS card");
  137|      0|		if (p15card->tokeninfo->label == NULL) {
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			free(p15card->tokeninfo->serial_number);
  139|      0|			p15card->tokeninfo->serial_number = NULL;
  140|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|      0|		}
  142|      0|	}
  143|       |
  144|      0|	if ((p15card->tokeninfo->manufacturer_id != NULL) && !strcmp("(unknown)", p15card->tokeninfo->manufacturer_id)) {
  ------------------
  |  Branch (144:6): [True: 0, False: 0]
  |  Branch (144:55): [True: 0, False: 0]
  ------------------
  145|      0|		free(p15card->tokeninfo->manufacturer_id);
  146|      0|		p15card->tokeninfo->manufacturer_id = NULL;
  147|      0|	}
  148|       |
  149|      0|	if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (149:6): [True: 0, False: 0]
  ------------------
  150|      0|		p15card->tokeninfo->manufacturer_id = strdup("www.mysmartlogon.com");
  151|      0|		if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 0]
  ------------------
  152|      0|			sc_pkcs15_card_clear(p15card);
  153|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  154|      0|		}
  155|      0|	}
  156|      0|	if (p15card->card->type == SC_CARD_TYPE_GIDS_V2) {
  ------------------
  |  Branch (156:6): [True: 0, False: 0]
  ------------------
  157|      0|		p15card->tokeninfo->version = 2;
  158|      0|	} else if (p15card->card->type == SC_CARD_TYPE_GIDS_V1) {
  ------------------
  |  Branch (158:13): [True: 0, False: 0]
  ------------------
  159|      0|		p15card->tokeninfo->version = 1;
  160|      0|	}
  161|       |
  162|      0|	memset(&pin_info, 0, sizeof(pin_info));
  163|      0|	memset(&pin_obj, 0, sizeof(pin_obj));
  164|       |
  165|      0|	pin_info.auth_id.len = 1;
  166|      0|	pin_info.auth_id.value[0] = 0x80;
  167|      0|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  168|      0|	pin_info.attrs.pin.reference = 0x80;
  169|      0|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  170|      0|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|      0|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  171|      0|	pin_info.attrs.pin.min_length = 4;
  172|      0|	pin_info.attrs.pin.stored_length = 0;
  173|      0|	pin_info.attrs.pin.max_length = 15;
  174|      0|	pin_info.attrs.pin.pad_char = '\0';
  175|      0|	pin_info.tries_left = -1;
  176|      0|	pin_info.max_tries = -1;
  177|       |
  178|      0|	memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  179|      0|	pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  180|      0|	pin_cmd_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  181|      0|	pin_cmd_data.pin_reference = pin_info.attrs.pin.reference;
  182|       |
  183|      0|	r = sc_pin_cmd(card, &pin_cmd_data);
  184|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (184:6): [True: 0, False: 0]
  ------------------
  185|      0|		pin_info.max_tries = pin_cmd_data.pin1.max_tries;
  186|      0|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  187|      0|	}
  188|       |
  189|      0|	strlcpy(pin_obj.label, "UserPIN", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  190|      0|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  191|       |
  192|       |	/*
  193|       |	 * check whether PUK is available on this card and then optionally
  194|       |	 * link PIN with PUK.
  195|       |	 */
  196|      0|	pin_cmd_data.pin_reference = 0x81;
  197|      0|	has_puk = sc_pin_cmd(card, &pin_cmd_data) == SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  198|      0|	if (has_puk) {
  ------------------
  |  Branch (198:6): [True: 0, False: 0]
  ------------------
  199|      0|		pin_obj.auth_id.len = 1;
  200|      0|		pin_obj.auth_id.value[0] = 0x81;
  201|      0|	}
  202|       |
  203|      0|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  204|      0|	LOG_TEST_GOTO_ERR(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|       |
  206|      0|	if (has_puk) {
  ------------------
  |  Branch (206:6): [True: 0, False: 0]
  ------------------
  207|      0|		pin_info.auth_id.value[0] = 0x81;
  208|      0|		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  209|      0|		pin_info.attrs.pin.reference = 0x81;
  210|      0|		pin_info.max_tries = pin_cmd_data.pin1.max_tries;
  211|      0|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  212|      0|		strlcpy(pin_obj.label, "PUK", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  213|      0|		pin_obj.auth_id.len = 0;
  214|      0|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  215|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj with PUK");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  216|      0|	}
  217|       |
  218|      0|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  219|      0|	LOG_TEST_GOTO_ERR(card->ctx, r, "sc_card_ctl SC_CARDCTL_GIDS_GET_ALL_CONTAINERS");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|       |
  221|      0|	for (i = 0; i < recordsnum; i++) {
  ------------------
  |  Branch (221:14): [True: 0, False: 0]
  ------------------
  222|      0|		sc_cardctl_gids_get_container_t container;
  223|      0|		memset(&container, 0, sizeof(sc_cardctl_gids_get_container_t));
  224|      0|		container.containernum = i;
  225|      0|		r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL, &container);
  226|      0|		if (r < 0) {
  ------------------
  |  Branch (226:7): [True: 0, False: 0]
  ------------------
  227|       |			// one of the container information couldn't be retrieved
  228|       |			// ignore it
  229|      0|			continue;
  230|      0|		}
  231|      0|		sc_pkcs15emu_gids_add_prkey(p15card, &container);
  232|      0|	}
  233|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  234|      0|err:
  235|      0|	sc_pkcs15_card_clear(p15card);
  236|      0|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  237|      0|}

sc_pkcs15emu_iasecc_init_ex:
  268|  9.03k|{
  269|  9.03k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (269:6): [True: 8.37k, False: 656]
  ------------------
  270|  8.37k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.37k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  271|       |
  272|    656|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  273|  9.03k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  239|  9.03k|{
  240|  9.03k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (240:6): [True: 6.70k, False: 2.32k]
  ------------------
  241|  6.70k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.70k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  242|       |
  243|  2.32k|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (243:6): [True: 1.67k, False: 656]
  ------------------
  244|  1.67k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.67k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  245|       |
  246|    656|	return SC_SUCCESS;
  ------------------
  |  |   28|    656|#define SC_SUCCESS				0
  ------------------
  247|  2.32k|}
pkcs15-iasecc.c:sc_pkcs15emu_iasecc_init:
  252|    656|{
  253|    656|	struct sc_context *ctx = p15card->card->ctx;
  254|    656|	int rv;
  255|       |
  256|    656|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    656|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    656|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    656|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    656|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 656]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|       |
  258|    656|	rv = sc_pkcs15_bind_internal(p15card, aid);
  259|       |
  260|    656|	p15card->ops.parse_df = _iasecc_parse_df;
  261|       |
  262|    656|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    656|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    656|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    656|	int _ret = r; \
  |  |  |  |  155|    656|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 656, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    656|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    656|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 656, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    656|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    656|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    656|	return _ret; \
  |  |  |  |  163|    656|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|    656|}

sc_pkcs15emu_idprime_init_ex:
  357|  9.59k|{
  358|  9.59k|	sc_card_t   *card = p15card->card;
  359|  9.59k|	sc_context_t    *ctx = card->ctx;
  360|       |
  361|  9.59k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  9.59k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.59k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.59k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.59k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  362|       |
  363|  9.59k|	if (idprime_detect_card(p15card))
  ------------------
  |  Branch (363:6): [True: 9.29k, False: 300]
  ------------------
  364|  9.29k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.29k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  365|    300|	return sc_pkcs15emu_idprime_init(p15card);
  366|  9.59k|}
pkcs15-idprime.c:idprime_detect_card:
   40|  9.59k|{
   41|  9.59k|	sc_card_t *card = p15card->card;
   42|       |
   43|  9.59k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.59k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.59k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.59k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.59k]
  |  |  ------------------
  ------------------
   44|       |
   45|  9.59k|	if (card->type < SC_CARD_TYPE_IDPRIME_BASE
  ------------------
  |  Branch (45:6): [True: 9.20k, False: 388]
  ------------------
   46|    388|		|| card->type >= SC_CARD_TYPE_IDPRIME_BASE+1000)
  ------------------
  |  Branch (46:6): [True: 88, False: 300]
  ------------------
   47|  9.29k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  9.29k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   48|    300|	return SC_SUCCESS;
  ------------------
  |  |   28|    300|#define SC_SUCCESS				0
  ------------------
   49|  9.59k|}
pkcs15-idprime.c:sc_pkcs15emu_idprime_init:
   52|    300|{
   53|    300|	int r, i;
   54|    300|	sc_card_t *card = p15card->card;
   55|    300|	sc_serial_number_t serial;
   56|    300|	char buf[SC_MAX_SERIALNR * 2 + 1];
   57|    300|	int count;
   58|    300|	char *token_name = NULL;
   59|    300|	struct sc_pkcs15_auth_info pin_info;
   60|    300|	struct sc_pkcs15_object   pin_obj;
   61|    300|	const char pin_label[] = "PIN";
   62|    300|	const char *pin_id = "11";
   63|    300|	const char sig_pin_label[] = "Digital Signature PIN";
   64|    300|	const char *sig_pin_id = "83";
   65|       |
   66|       |	/* oid for key usage */
   67|    300|	static const struct sc_object_id usage_type = {{ 2, 5, 29, 15, -1 }};
   68|    300|	unsigned int usage;
   69|       |
   70|    300|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    300|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    300|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    300|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 300]
  |  |  ------------------
  ------------------
   71|       |
   72|       |	/* could read this off card if needed */
   73|    300|	set_string(&p15card->tokeninfo->label, "IDPrime");
   74|    300|	set_string(&p15card->tokeninfo->manufacturer_id, "Gemalto");
   75|       |
   76|       |	/*
   77|       |	 * get serial number
   78|       |	 */
   79|    300|	memset(&serial, 0, sizeof(serial));
   80|    300|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   81|    300|	if (r < 0) {
  ------------------
  |  Branch (81:6): [True: 297, False: 3]
  ------------------
   82|    297|		sc_log(card->ctx, "sc_card_ctl rc=%d", r);
  ------------------
  |  |   71|    297|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   83|    297|		set_string(&p15card->tokeninfo->serial_number, "00000000");
   84|    297|	} else {
   85|      3|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   86|      3|		set_string(&p15card->tokeninfo->serial_number, buf);
   87|      3|	}
   88|       |	/* set pin */
   89|    300|	sc_log(card->ctx,  "IDPrime adding pin...");
  ------------------
  |  |   71|    300|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   90|    300|	memset(&pin_info, 0, sizeof(pin_info));
   91|    300|	memset(&pin_obj,  0, sizeof(pin_obj));
   92|       |
   93|    300|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    300|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
   94|    300|	sc_pkcs15_format_id(pin_id, &pin_info.auth_id);
   95|    300|	pin_info.attrs.pin.reference     = 0x11;
   96|    300|	pin_info.attrs.pin.flags         = SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|    300|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
   97|    300|	pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    300|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
   98|    300|	pin_info.attrs.pin.min_length    = 4;
   99|    300|	pin_info.attrs.pin.stored_length = 0;
  100|    300|	pin_info.attrs.pin.max_length    = 16;
  101|    300|	pin_info.tries_left    = -1;
  102|       |
  103|    300|	if (card->type == SC_CARD_TYPE_IDPRIME_840
  ------------------
  |  Branch (103:6): [True: 31, False: 269]
  ------------------
  104|    269|	    || card->type == SC_CARD_TYPE_IDPRIME_940
  ------------------
  |  Branch (104:9): [True: 50, False: 219]
  ------------------
  105|    260|	    || card->type == SC_CARD_TYPE_IDPRIME_GENERIC) {
  ------------------
  |  Branch (105:9): [True: 179, False: 40]
  ------------------
  106|    260|		pin_info.attrs.pin.flags |= SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|    260|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  107|    260|		pin_info.attrs.pin.stored_length = 16;
  108|    260|		pin_info.attrs.pin.pad_char = 0x00;
  109|    260|	}
  110|       |
  111|    300|	sc_log(card->ctx,  "IDPrime Adding pin with label=%s", pin_label);
  ------------------
  |  |   71|    300|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  112|    300|	strncpy(pin_obj.label, pin_label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    300|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  113|    300|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    300|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  114|       |
  115|    300|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  116|    300|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object");
  ------------------
  |  |  184|    300|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    300|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    300|	int _ret = (r); \
  |  |  |  |  178|    300|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 300]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    300|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|       |
  118|       |	/* set signature pin for 940 cards */
  119|    300|	if (card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (119:6): [True: 50, False: 250]
  ------------------
  120|     50|		sc_log(card->ctx,  "IDPrime adding Digital Signature pin...");
  ------------------
  |  |   71|     50|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  121|     50|		memset(&pin_info, 0, sizeof(pin_info));
  122|     50|		memset(&pin_obj,  0, sizeof(pin_obj));
  123|       |
  124|     50|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     50|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  125|     50|		sc_pkcs15_format_id(sig_pin_id, &pin_info.auth_id);
  126|     50|		pin_info.attrs.pin.reference     = 0x83;
  127|     50|		pin_info.attrs.pin.flags         = SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|     50|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  128|     50|		pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     50|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  129|     50|		pin_info.attrs.pin.min_length    = 4;
  130|     50|		pin_info.attrs.pin.stored_length = 0;
  131|     50|		pin_info.attrs.pin.max_length    = 16;
  132|     50|		pin_info.tries_left    = -1;
  133|       |
  134|     50|		pin_info.attrs.pin.flags |= SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     50|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  135|     50|		pin_info.attrs.pin.stored_length = 16;
  136|     50|		pin_info.attrs.pin.pad_char = 0x00;
  137|       |
  138|     50|		sc_log(card->ctx,  "IDPrime Adding Digital Signature pin with label=%s", sig_pin_label);
  ------------------
  |  |   71|     50|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  139|     50|		strncpy(pin_obj.label, sig_pin_label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|     50|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  140|     50|		pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     50|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  141|       |
  142|     50|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  143|     50|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add Digital Signature pin object");
  ------------------
  |  |  184|     50|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     50|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     50|	int _ret = (r); \
  |  |  |  |  178|     50|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|     50|	}
  145|       |
  146|       |	/*
  147|       |	 * get token name if provided
  148|       |	 */
  149|    300|	r = sc_card_ctl(card, SC_CARDCTL_IDPRIME_GET_TOKEN_NAME, &token_name);
  150|    300|	if (r < 0) {
  ------------------
  |  Branch (150:6): [True: 287, False: 13]
  ------------------
  151|       |		/* On failure we will get the token name from certificates later */
  152|    287|		sc_log(card->ctx, "sc_card_ctl rc=%d", r);
  ------------------
  |  |   71|    287|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  153|    287|	} else {
  154|     13|		free(p15card->tokeninfo->label);
  155|     13|		p15card->tokeninfo->label = token_name;
  156|     13|		sc_log(card->ctx,  "IDPrime setting token label = %s", token_name);
  ------------------
  |  |   71|     13|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  157|     13|	}
  158|       |	/*
  159|       |	 * certs, pubkeys and priv keys are related and we assume
  160|       |	 * they are in order
  161|       |	 * We need to read the cert, get modulus and keylen
  162|       |	 * We use those for the pubkey, and priv key objects.
  163|       |	 */
  164|    300|	sc_log(card->ctx,  "IDPrime adding certs, pub and priv keys...");
  ------------------
  |  |   71|    300|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  165|    300|	r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_INIT_GET_OBJECTS, &count);
  166|    300|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate cert objects.");
  ------------------
  |  |  184|    300|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    300|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    300|	int _ret = (r); \
  |  |  |  |  178|    300|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 300]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    300|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|       |
  168|  2.45k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (168:14): [True: 2.15k, False: 300]
  ------------------
  169|  2.15k|		struct sc_pkcs15_prkey_info prkey_info;
  170|  2.15k|		struct sc_pkcs15_cert_info cert_info;
  171|  2.15k|		struct sc_pkcs15_pubkey_info pubkey_info;
  172|  2.15k|		struct sc_pkcs15_object cert_obj;
  173|  2.15k|		struct sc_pkcs15_object pubkey_obj;
  174|  2.15k|		struct sc_pkcs15_object prkey_obj;
  175|  2.15k|		sc_pkcs15_der_t cert_der;
  176|  2.15k|		sc_pkcs15_cert_t *cert_out = NULL;
  177|  2.15k|		const char *pin_id = NULL;
  178|       |
  179|  2.15k|		r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_GET_PIN_ID, (void *) &pin_id);
  180|  2.15k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get PIN id of next object ");
  ------------------
  |  |  184|  2.15k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.15k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.15k|	int _ret = (r); \
  |  |  |  |  178|  2.15k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.15k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|  2.15k|		r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_GET_NEXT_OBJECT, &prkey_info);
  182|  2.15k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next object");
  ------------------
  |  |  184|  2.15k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.15k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.15k|	int _ret = (r); \
  |  |  |  |  178|  2.15k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.15k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|  2.15k|		memset(&cert_info, 0, sizeof(cert_info));
  185|  2.15k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  186|       |		/* prkey_info cleaned by the card_ctl call */
  187|  2.15k|		memset(&cert_obj,  0, sizeof(cert_obj));
  188|  2.15k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  189|  2.15k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  190|       |
  191|  2.15k|		cert_info.id = prkey_info.id;
  192|  2.15k|		pubkey_info.id = prkey_info.id;
  193|  2.15k|		cert_info.path = prkey_info.path;
  194|       |		/* For private keys, we no longer care for the path, just
  195|       |		 * the key reference later used in the security environment */
  196|  2.15k|		prkey_info.path.len = 0;
  197|  2.15k|		prkey_info.path.aid.len = 0;
  198|  2.15k|		pubkey_info.key_reference = prkey_info.key_reference;
  199|  2.15k|		sc_log(card->ctx,  "Key ref r=%x", prkey_info.key_reference);
  ------------------
  |  |   71|  2.15k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  200|       |
  201|  2.15k|		pubkey_info.native        = 1;
  202|  2.15k|		prkey_info.native        = 1;
  203|       |
  204|  2.15k|		snprintf(cert_obj.label, SC_PKCS15_MAX_LABEL_SIZE, CERT_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|  2.15k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(cert_obj.label, SC_PKCS15_MAX_LABEL_SIZE, CERT_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|  2.15k|#define CERT_LABEL_TEMPLATE "Certificate %d"
  ------------------
  205|  2.15k|		snprintf(pubkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PUBKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|  2.15k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(pubkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PUBKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   36|  2.15k|#define PUBKEY_LABEL_TEMPLATE "Public key %d"
  ------------------
  206|  2.15k|		snprintf(prkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PRIVKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|  2.15k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(prkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PRIVKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   37|  2.15k|#define PRIVKEY_LABEL_TEMPLATE "Private key %d"
  ------------------
  207|  2.15k|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  2.15k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  208|       |
  209|       |		/* Differentiate between objects accessible with normal and with digital signature pin */
  210|  2.15k|		sc_pkcs15_format_id(pin_id, &prkey_obj.auth_id);
  211|  2.15k|		sc_log(card->ctx,  "Pin ID r=%s", pin_id);
  ------------------
  |  |   71|  2.15k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  212|       |
  213|  2.15k|		if (memcmp(pin_id, sig_pin_id, 2) == 0)
  ------------------
  |  Branch (213:7): [True: 89, False: 2.06k]
  ------------------
  214|     89|			prkey_obj.user_consent = 1;
  215|       |
  216|  2.15k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, 0);
  217|       |
  218|  2.15k|		if (r) {
  ------------------
  |  Branch (218:7): [True: 2.12k, False: 27]
  ------------------
  219|  2.12k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  2.12k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  220|  2.12k|			continue;
  221|  2.12k|		}
  222|     27|		cert_info.path.count = (int)cert_der.len;
  223|       |
  224|     27|		sc_log(card->ctx, "cert len=%zu, cert_info.path.count=%d r=%d",
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  225|     27|				cert_der.len, cert_info.path.count, r);
  226|     27|		sc_log_hex(card->ctx, "cert", cert_der.value, cert_der.len);
  ------------------
  |  |  129|     27|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     27|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|       |
  228|       |		/* cache it using the PKCS15 emulation objects */
  229|       |		/* as it does not change */
  230|     27|		if (cert_der.value) {
  ------------------
  |  Branch (230:7): [True: 19, False: 8]
  ------------------
  231|     19|			cert_info.value.value = cert_der.value;
  232|     19|			cert_info.value.len = cert_der.len;
  233|     19|			cert_info.path.len = 0; /* use in mem cert from now on */
  234|     19|		}
  235|       |
  236|       |		/* following will find the cached cert in cert_info */
  237|     27|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert_out);
  238|     27|		if (r < 0 || cert_out->key == NULL) {
  ------------------
  |  Branch (238:7): [True: 27, False: 0]
  |  Branch (238:16): [True: 0, False: 0]
  ------------------
  239|     27|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  240|     27|			if (cert_out != NULL)
  ------------------
  |  Branch (240:8): [True: 0, False: 27]
  ------------------
  241|      0|				sc_pkcs15_free_certificate(cert_out);
  242|     27|			free(cert_der.value);
  243|     27|			continue;
  244|     27|		}
  245|       |
  246|      0|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  247|      0|		if (r < 0) {
  ------------------
  |  Branch (247:7): [True: 0, False: 0]
  ------------------
  248|      0|			sc_log(card->ctx,  " Failed to add cert obj r=%d",r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  249|      0|			sc_pkcs15_free_certificate(cert_out);
  250|      0|			free(cert_der.value);
  251|      0|			continue;
  252|      0|		}
  253|       |		/* set the token name to the name of the CN of the first certificate */
  254|      0|		if (!token_name) {
  ------------------
  |  Branch (254:7): [True: 0, False: 0]
  ------------------
  255|      0|			u8 * cn_name = NULL;
  256|      0|			size_t cn_len = 0;
  257|      0|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  258|      0|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  259|      0|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  260|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (260:8): [True: 0, False: 0]
  ------------------
  261|      0|				token_name = malloc (cn_len+1);
  262|      0|				if (!token_name) {
  ------------------
  |  Branch (262:9): [True: 0, False: 0]
  ------------------
  263|      0|					free(cn_name);
  264|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  265|      0|					goto fail;
  266|      0|				}
  267|      0|				memcpy(token_name, cn_name, cn_len);
  268|      0|				free(cn_name);
  269|      0|				token_name[cn_len] = '\0';
  270|      0|				free(p15card->tokeninfo->label);
  271|      0|				p15card->tokeninfo->label = token_name;
  272|      0|			}
  273|      0|		}
  274|       |
  275|       |
  276|      0|		r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, cert_out->key,
  277|      0|			&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
  278|      0|		if (r < 0)
  ------------------
  |  Branch (278:7): [True: 0, False: 0]
  ------------------
  279|      0|			goto fail;
  280|      0|		pubkey_obj.emulated = cert_out->key;
  281|       |
  282|      0|		r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out, &usage_type, &usage, NULL);
  283|      0|		if (r < 0) {
  ------------------
  |  Branch (283:7): [True: 0, False: 0]
  ------------------
  284|      0|			usage = SC_X509_DATA_ENCIPHERMENT|SC_X509_DIGITAL_SIGNATURE; /* basic default usage */
  ------------------
  |  |  617|      0|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
              			usage = SC_X509_DATA_ENCIPHERMENT|SC_X509_DIGITAL_SIGNATURE; /* basic default usage */
  ------------------
  |  |  614|      0|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  ------------------
  285|      0|		}
  286|      0|		sc_pkcs15_map_usage(usage, cert_out->key->algorithm, &pubkey_info.usage, &prkey_info.usage, 1);
  287|      0|		sc_log(card->ctx, "cert %s: cert_usage=0x%x, pub_usage=0x%x priv_usage=0x%x\n",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  288|      0|			sc_dump_hex(cert_info.id.value, cert_info.id.len),
  289|      0|			usage, pubkey_info.usage, prkey_info.usage);
  290|       |
  291|      0|		if (cert_out->key->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (291:7): [True: 0, False: 0]
  ------------------
  292|      0|			pubkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  293|      0|			prkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  294|      0|			sc_log(card->ctx, "adding rsa public key r=%d usage=%x", r, pubkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  295|      0|			r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  296|      0|			if (r < 0) {
  ------------------
  |  Branch (296:8): [True: 0, False: 0]
  ------------------
  297|      0|				free(pubkey_info.direct.spki.value);
  298|      0|				goto fail;
  299|      0|			}
  300|      0|			pubkey_info.direct.spki.value = NULL; /* moved to the pubkey object on p15card  */
  301|      0|			pubkey_info.direct.spki.len = 0;
  302|      0|			if (prkey_info.key_reference >= 0) {
  ------------------
  |  Branch (302:8): [True: 0, False: 0]
  ------------------
  303|      0|				sc_log(card->ctx, "adding rsa private key r=%d usage=%x", r, prkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  304|      0|				r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  305|      0|			} else {
  306|      0|				sc_log(card->ctx, "missing rsa private key r=%d usage=%x", r, prkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  307|      0|			}
  308|      0|			if (r < 0)
  ------------------
  |  Branch (308:8): [True: 0, False: 0]
  ------------------
  309|      0|				goto fail;
  310|      0|		} else if (cert_out->key->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (310:14): [True: 0, False: 0]
  ------------------
  311|      0|			pubkey_info.field_length = cert_out->key->u.ec.params.field_length;
  312|      0|			prkey_info.field_length = cert_out->key->u.ec.params.field_length;
  313|      0|			sc_log(card->ctx, "adding ec public key r=%d usage=%x", r, pubkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  314|      0|			r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
  315|      0|			if (r < 0) {
  ------------------
  |  Branch (315:8): [True: 0, False: 0]
  ------------------
  316|      0|				free(pubkey_info.direct.spki.value);
  317|      0|				goto fail;
  318|      0|			}
  319|      0|			pubkey_info.direct.spki.value = NULL;
  320|      0|			pubkey_info.direct.spki.len = 0;
  321|      0|			if (prkey_info.key_reference >= 0) {
  ------------------
  |  Branch (321:8): [True: 0, False: 0]
  ------------------
  322|      0|				sc_log(card->ctx, "adding ec private key r=%d usage=%x", r, prkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  323|      0|				r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
  324|      0|			} else {
  325|      0|				sc_log(card->ctx, "missing ec private key r=%d usage=%x", r, prkey_info.usage);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  326|      0|			}
  327|      0|			if (r < 0)
  ------------------
  |  Branch (327:8): [True: 0, False: 0]
  ------------------
  328|      0|				goto fail;
  329|      0|		} else {
  330|      0|			sc_log(card->ctx, "unsupported key.algorithm %lu", cert_out->key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  331|      0|			sc_pkcs15_free_certificate(cert_out);
  332|      0|			free(pubkey_info.direct.spki.value);
  333|      0|			continue;
  334|      0|		}
  335|       |
  336|      0|		cert_out->key = NULL;
  337|      0|fail:
  338|      0|		sc_pkcs15_free_certificate(cert_out);
  339|      0|		if (r < 0) {
  ------------------
  |  Branch (339:7): [True: 0, False: 0]
  ------------------
  340|      0|			(card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_FINAL_GET_OBJECTS, &count);
  341|      0|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add object.");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|      0|		}
  343|       |
  344|      0|	}
  345|    300|	r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_FINAL_GET_OBJECTS, &count);
  346|    300|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize cert objects.");
  ------------------
  |  |  184|    300|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    300|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    300|	int _ret = (r); \
  |  |  |  |  178|    300|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 300]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    300|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|       |
  348|    300|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    300|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    300|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    300|	int _ret = r; \
  |  |  |  |  155|    300|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 300, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    300|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 300]
  |  |  |  |  ------------------
  |  |  |  |  157|    300|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    300|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    300|	return _ret; \
  |  |  |  |  163|    300|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|       |
  350|      0|err:
  351|      0|	sc_pkcs15_card_clear(p15card);
  352|      0|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      0|}

sc_pkcs15emu_itacns_init_ex:
  881|  11.4k|{
  882|  11.4k|	sc_card_t *card = p15card->card;
  883|  11.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  11.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.4k]
  |  |  ------------------
  ------------------
  884|       |
  885|       |	/* Check card */
  886|  11.4k|	if (! (
  887|  11.4k|			(card->type > SC_CARD_TYPE_ITACNS_BASE &&
  ------------------
  |  Branch (887:5): [True: 3.95k, False: 7.51k]
  ------------------
  888|  3.95k|			card->type < SC_CARD_TYPE_ITACNS_BASE + 1000)
  ------------------
  |  Branch (888:4): [True: 281, False: 3.67k]
  ------------------
  889|  11.1k|		|| card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (889:6): [True: 0, False: 11.1k]
  ------------------
  890|  11.4k|		)
  891|  11.1k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.1k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  892|       |
  893|       |	/* Init card */
  894|    281|	return itacns_init(p15card);
  895|  11.4k|}
pkcs15-itacns.c:itacns_init:
  761|    281|{
  762|    281|	int r;
  763|    281|	sc_path_t path;
  764|    281|	int certificate_count = 0;
  765|    281|	int found_certs;
  766|    281|	int card_is_cie_v1, cns0_secenv;
  767|       |
  768|    281|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    281|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    281|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    281|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 281]
  |  |  ------------------
  ------------------
  769|       |
  770|    281|	set_string(&p15card->tokeninfo->label, p15card->card->name);
  771|    281|	if(p15card->card->drv_data) {
  ------------------
  |  Branch (771:5): [True: 281, False: 0]
  ------------------
  772|    281|		unsigned int mask_code, ic_code;
  773|    281|		char buffer[256];
  774|    281|		itacns_drv_data_t *data =
  775|    281|			(itacns_drv_data_t*) p15card->card->drv_data;
  776|    281|		mask_code = data->mask_manufacturer_code;
  777|    281|		if (mask_code >= sizeof(itacns_mask_manufacturers)
  ------------------
  |  Branch (777:7): [True: 46, False: 235]
  ------------------
  778|    281|			/sizeof(itacns_mask_manufacturers[0]))
  779|     46|			mask_code = 0;
  780|    281|		ic_code = data->ic_manufacturer_code;
  781|    281|		if (ic_code >= sizeof(iso7816_ic_manufacturers)
  ------------------
  |  Branch (781:7): [True: 261, False: 20]
  ------------------
  782|    281|			/sizeof(iso7816_ic_manufacturers[0]))
  783|    261|			ic_code = 0;
  784|    281|		snprintf(buffer, sizeof(buffer), "IC: %s; mask: %s",
  785|    281|			iso7816_ic_manufacturers[ic_code],
  786|    281|			itacns_mask_manufacturers[mask_code]);
  787|    281|		set_string(&p15card->tokeninfo->manufacturer_id, buffer);
  788|    281|	}
  789|       |
  790|       |	/* Read and set serial */
  791|    281|	{
  792|    281|		u8 serial[17];
  793|    281|		int bytes;
  794|    281|		sc_format_path(path_serial, &path);
  795|    281|		bytes = loadFile(p15card, &path, serial, 16);
  796|    281|		if (bytes < 0) return bytes;
  ------------------
  |  Branch (796:7): [True: 97, False: 184]
  ------------------
  797|    184|		if (bytes > 16) return -1;
  ------------------
  |  Branch (797:7): [True: 0, False: 184]
  ------------------
  798|    184|		serial[bytes] = '\0';
  799|    184|		set_string(&p15card->tokeninfo->serial_number, (char*)serial);
  800|    184|	}
  801|       |
  802|       |	/* Is the card a CIE v1? */
  803|      0|	card_is_cie_v1 =
  804|    184|		   (p15card->card->type == SC_CARD_TYPE_ITACNS_CIE_V1)
  ------------------
  |  Branch (804:6): [True: 168, False: 16]
  ------------------
  805|     16|		|| (p15card->card->type == SC_CARD_TYPE_CARDOS_CIE_V1);
  ------------------
  |  Branch (805:6): [True: 0, False: 16]
  ------------------
  806|    184|	cns0_secenv = (card_is_cie_v1 ? 0x31 : 0x01);
  ------------------
  |  Branch (806:17): [True: 168, False: 16]
  ------------------
  807|       |
  808|       |	/* If it's a Siemens CIE v1 card, set algo flags accordingly. */
  809|    184|	if (card_is_cie_v1) {
  ------------------
  |  Branch (809:6): [True: 168, False: 16]
  ------------------
  810|    168|		int i;
  811|    336|		for (i = 0; i < p15card->card->algorithm_count; i++) {
  ------------------
  |  Branch (811:15): [True: 168, False: 168]
  ------------------
  812|    168|			sc_algorithm_info_t *info =
  813|    168|				&p15card->card->algorithms[i];
  814|       |
  815|    168|			if (info->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    168|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (815:8): [True: 0, False: 168]
  ------------------
  816|      0|				continue;
  817|    168|			info->flags &= ~(SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    168|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  818|    168|				| SC_ALGORITHM_RSA_HASH_NONE);
  ------------------
  |  |  133|    168|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  819|    168|			info->flags |= (SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    168|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    168|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    168|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  820|    168|				| SC_ALGORITHM_RSA_HASHES);
  ------------------
  |  |  142|    168|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  821|    168|		}
  822|    168|	}
  823|       |
  824|       |	/* Data files */
  825|    184|	r = itacns_add_data_files(p15card);
  826|    184|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    184|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    184|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    184|	int _ret = (r); \
  |  |  |  |  178|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|    184|		"Could not add data files");
  828|       |
  829|       |	/*** Certificate and keys. ***/
  830|       |	/* Standard CNS */
  831|    184|	r = itacns_check_and_add_keyset(p15card, "CNS0", cns0_secenv,
  832|    184|		0, "3F0011001101", "3F003F01", NULL,
  833|    184|		0x10, &found_certs);
  834|    184|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    184|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    184|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    184|	int _ret = (r); \
  |  |  |  |  178|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 128, False: 56]
  |  |  |  |  ------------------
  |  |  |  |  179|    128|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    128|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    128|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    128|		goto err; \
  |  |  |  |  182|    128|	} \
  |  |  |  |  183|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 56]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|     56|		"Could not add CNS0");
  836|     56|	certificate_count += found_certs;
  837|       |
  838|       |	/* Infocamere 1204 */
  839|     56|	r = itacns_check_and_add_keyset(p15card, "CNS01", 0x21,
  840|     56|		5, "3F002FFF8228", NULL, "3F002FFF0000",
  841|     56|		0x10, &found_certs);
  842|     56|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     56|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     56|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     56|	int _ret = (r); \
  |  |  |  |  178|     56|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 20, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  179|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     20|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     20|		goto err; \
  |  |  |  |  182|     20|	} \
  |  |  |  |  183|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     36|		"Could not add CNS01");
  844|     36|	certificate_count += found_certs;
  845|       |
  846|       |	/* Digital signature */
  847|     36|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x10,
  848|     36|		0, "3F0014009010", "3F00140081108010", "3F0014008110",
  849|     36|		0x1a, &found_certs);
  850|     36|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     36|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     36|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     36|	int _ret = (r); \
  |  |  |  |  178|     36|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 25, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  179|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     25|		goto err; \
  |  |  |  |  182|     25|	} \
  |  |  |  |  183|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|     11|		"Could not add CNS1");
  852|     11|	certificate_count += found_certs;
  853|       |
  854|       |	/* Idemia card */
  855|     11|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x02,
  856|     11|		0, "3F00140090012002", "3F0011001102", "3F0014009002",
  857|     11|		0x10, &found_certs);
  858|     11|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|      8|		"Could not add CNS1");
  860|      8|	certificate_count += found_certs;
  861|       |
  862|       |	/* Did we find anything? */
  863|      8|	if (certificate_count == 0)
  ------------------
  |  Branch (863:6): [True: 8, False: 0]
  ------------------
  864|      8|		sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|      8|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  865|      8|			"Warning: no certificates found!");
  866|       |
  867|       |	/* Back to Master File */
  868|      8|	sc_format_path("3F00", &path);
  869|      8|	r = sc_select_file(p15card->card, &path, NULL);
  870|      8|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|      8|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      8|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      8|	int _ret = (r); \
  |  |  |  |  178|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  179|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      7|		goto err; \
  |  |  |  |  182|      7|	} \
  |  |  |  |  183|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  871|      1|		"Could not select master file again");
  872|       |
  873|      1|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  874|       |
  875|    180|err:
  876|    180|	sc_pkcs15_card_clear(p15card);
  877|    180|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    180|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    180|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    180|	int _ret = r; \
  |  |  |  |  155|    180|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 180, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    180|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    180|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 180, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    180|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    180|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    180|	return _ret; \
  |  |  |  |  163|    180|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    180|}
pkcs15-itacns.c:loadFile:
  169|    324|{
  170|    324|	int sc_res;
  171|    324|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    324|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    324|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    324|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 324]
  |  |  ------------------
  ------------------
  172|       |
  173|    324|	sc_res = sc_select_file(p15card->card, path, NULL);
  174|    324|	if(sc_res != SC_SUCCESS)
  ------------------
  |  |   28|    324|#define SC_SUCCESS				0
  ------------------
  |  Branch (174:5): [True: 92, False: 232]
  ------------------
  175|     92|		return sc_res;
  176|       |
  177|    232|	sc_res = sc_read_binary(p15card->card, 0, buf, buflen, 0);
  178|    232|	return sc_res;
  179|    324|}
pkcs15-itacns.c:itacns_add_data_files:
  482|    184|{
  483|    184|	const size_t array_size =
  484|    184|		sizeof(itacns_data_files)/sizeof(itacns_data_files[0]);
  485|    184|	unsigned int i;
  486|    184|	int rv;
  487|    184|	sc_pkcs15_data_t *p15_personaldata = NULL;
  488|    184|	sc_pkcs15_data_info_t dinfo;
  489|    184|	struct sc_pkcs15_object *objs[32];
  490|    184|	struct sc_pkcs15_data_info *cinfo;
  491|    184|	int private_obj;
  492|       |
  493|  2.76k|	for(i=0; i < array_size; i++) {
  ------------------
  |  Branch (493:11): [True: 2.57k, False: 184]
  ------------------
  494|  2.57k|		sc_path_t path;
  495|  2.57k|		sc_pkcs15_data_info_t data;
  496|  2.57k|		sc_pkcs15_object_t    obj;
  497|       |
  498|  2.57k|		if (itacns_data_files[i].cie_only &&
  ------------------
  |  Branch (498:7): [True: 736, False: 1.84k]
  ------------------
  499|    736|			p15card->card->type != SC_CARD_TYPE_ITACNS_CIE_V2)
  ------------------
  |  Branch (499:4): [True: 732, False: 4]
  ------------------
  500|    732|			continue;
  501|       |
  502|  1.84k|		sc_format_path(itacns_data_files[i].path, &path);
  503|       |
  504|  1.84k|		memset(&data, 0, sizeof(data));
  505|  1.84k|		memset(&obj, 0, sizeof(obj));
  506|  1.84k|		strlcpy(data.app_label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.84k|#define strlcpy _strlcpy
  ------------------
  507|  1.84k|			sizeof(data.app_label));
  508|  1.84k|		strlcpy(obj.label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.84k|#define strlcpy _strlcpy
  ------------------
  509|  1.84k|			sizeof(obj.label));
  510|  1.84k|		data.path = path;
  511|  1.84k|		rv = sc_pkcs15emu_add_data_object(p15card, &obj, &data);
  512|  1.84k|		LOG_TEST_RET(p15card->card->ctx, rv,
  ------------------
  |  |  174|  1.84k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.84k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.84k|	int _ret = (r); \
  |  |  |  |  168|  1.84k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.84k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  1.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|  1.84k|			"Could not add data file");
  514|  1.84k|	}
  515|       |
  516|       |	/*
  517|       |	 * If we got this far, we can read the Personal Data file and glean
  518|       |	 * the user's full name. Thus we can use it to put together a
  519|       |	 * user-friendlier card name.
  520|       |	 */
  521|    184|	memset(&dinfo, 0, sizeof(dinfo));
  522|    184|	strlcpy(dinfo.app_label, "EF_DatiPersonali", sizeof(dinfo.app_label));
  ------------------
  |  |   43|    184|#define strlcpy _strlcpy
  ------------------
  523|       |
  524|       |	/* Find EF_DatiPersonali */
  525|       |
  526|    184|	rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    184|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  527|    184|		objs, 32);
  528|    184|	if(rv < 0) {
  ------------------
  |  Branch (528:5): [True: 0, False: 184]
  ------------------
  529|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  530|      0|			"Data enumeration failed");
  531|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  532|      0|	}
  533|       |
  534|    553|	for(i=0; i<32; i++) {
  ------------------
  |  Branch (534:11): [True: 553, False: 0]
  ------------------
  535|    553|		cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  536|    553|		if(!strcmp("EF_DatiPersonali", objs[i]->label))
  ------------------
  |  Branch (536:6): [True: 184, False: 369]
  ------------------
  537|    184|			break;
  538|    553|	}
  539|       |
  540|    184|	if(i>=32) {
  ------------------
  |  Branch (540:5): [True: 0, False: 184]
  ------------------
  541|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  542|      0|			"Could not find EF_DatiPersonali: "
  543|      0|			"keeping generic card name");
  544|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  545|      0|	}
  546|       |
  547|    184|	private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    184|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  548|    184|	rv = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &p15_personaldata);
  549|    184|	if (rv) {
  ------------------
  |  Branch (549:6): [True: 127, False: 57]
  ------------------
  550|    127|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|    127|			"Could not read EF_DatiPersonali: "
  552|    127|			"keeping generic card name");
  553|    127|		return SC_SUCCESS;
  ------------------
  |  |   28|    127|#define SC_SUCCESS				0
  ------------------
  554|    127|	}
  555|       |
  556|     57|	if (p15_personaldata->data) {
  ------------------
  |  Branch (556:6): [True: 52, False: 5]
  ------------------
  557|     52|		char fullname[160];
  558|     52|		if (get_name_from_EF_DatiPersonali(p15_personaldata->data,
  ------------------
  |  Branch (558:7): [True: 51, False: 1]
  ------------------
  559|     52|			p15_personaldata->data_len, fullname, sizeof(fullname))) {
  560|     51|			sc_log(p15card->card->ctx,
  ------------------
  |  |   71|     51|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  561|     51|				"Could not parse EF_DatiPersonali: "
  562|     51|				"keeping generic card name");
  563|     51|			sc_pkcs15_free_data_object(p15_personaldata);
  564|     51|			free(cinfo->data.value);
  565|     51|			cinfo->data.value = NULL;
  566|     51|			return SC_SUCCESS;
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  567|     51|		}
  568|      1|		set_string(&p15card->tokeninfo->label, fullname);
  569|      1|	}
  570|      6|	free(cinfo->data.value);
  571|      6|	cinfo->data.value = NULL;
  572|      6|	sc_pkcs15_free_data_object(p15_personaldata);
  573|      6|	return SC_SUCCESS;
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  574|     57|}
pkcs15-itacns.c:get_name_from_EF_DatiPersonali:
  387|     52|{
  388|     52|	const unsigned int EF_personaldata_maxlen = 400;
  389|     52|	const unsigned int tlv_length_size = 6;
  390|     52|	char *file = NULL;
  391|     52|	int file_size;
  392|       |
  393|       |	/*
  394|       |	 * Bytes 0-5 contain the ASCII encoding of the following TLV
  395|       |	 * structure's total size, in base 16.
  396|       |	 */
  397|     52|	if (EFdata_len < tlv_length_size) {
  ------------------
  |  Branch (397:6): [True: 11, False: 41]
  ------------------
  398|       |		/* We need at least 6 bytes for file length here */
  399|     11|		return -1;
  400|     11|	}
  401|     41|	file_size = hextoint((char*)EFdata, tlv_length_size);
  402|     41|	if (EFdata_len < (file_size + tlv_length_size)) {
  ------------------
  |  Branch (402:6): [True: 16, False: 25]
  ------------------
  403|       |		/* Inconsistent external file length and internal file length
  404|       |		 * suggests we are trying to process junk data.
  405|       |		 * If the internal data length is shorter, the data can be padded,
  406|       |		 * but we should be fine as we will not go behind the buffer limits */
  407|     16|		return -1;
  408|     16|	}
  409|     25|	file = (char*)&EFdata[tlv_length_size];
  410|       |
  411|     25|	enum {
  412|     25|		f_issuer_code = 0,
  413|     25|		f_issuing_date,
  414|     25|		f_expiry_date,
  415|     25|		f_last_name,
  416|     25|		f_first_name,
  417|     25|		f_birth_date,
  418|     25|		f_sex,
  419|     25|		f_height,
  420|     25|		f_codice_fiscale,
  421|     25|		f_citizenship_code,
  422|     25|		f_birth_township_code,
  423|     25|		f_birth_country,
  424|     25|		f_birth_certificate,
  425|     25|		f_residence_township_code,
  426|     25|		f_residence_address,
  427|     25|		f_expat_notes
  428|     25|	};
  429|       |
  430|       |	/* Read the fields up to f_first_name */
  431|     25|	struct {
  432|     25|		int len;
  433|     25|		char value[256];
  434|     25|	} fields[f_first_name+1];
  435|     25|	int i=0; /* offset inside the file */
  436|     25|	int f; /* field number */
  437|       |
  438|     25|	if (file_size < 0)
  ------------------
  |  Branch (438:6): [True: 15, False: 10]
  ------------------
  439|     15|		return -1;
  440|       |
  441|       |	/*
  442|       |	 * This shouldn't happen, but let us be protected against wrong
  443|       |	 * or malicious cards
  444|       |	 */
  445|     10|	if(file_size > (int)EF_personaldata_maxlen - (int)tlv_length_size)
  ------------------
  |  Branch (445:5): [True: 0, False: 10]
  ------------------
  446|      0|		file_size = EF_personaldata_maxlen - tlv_length_size;
  447|       |
  448|       |
  449|     10|	memset(fields, 0, sizeof(fields));
  450|       |
  451|     26|	for(f=0; f<f_first_name+1; f++) {
  ------------------
  |  Branch (451:11): [True: 25, False: 1]
  ------------------
  452|     25|		int field_size;
  453|       |
  454|       |		/* Don't read beyond the allocated buffer */
  455|     25|		if(i+2 > file_size)
  ------------------
  |  Branch (455:6): [True: 4, False: 21]
  ------------------
  456|      4|			return -1;
  457|     21|		field_size = hextoint((char*) &file[i], 2);
  458|     21|		i += 2;
  459|       |
  460|     21|		if (field_size < 0
  ------------------
  |  Branch (460:7): [True: 3, False: 18]
  ------------------
  461|     18|				|| i + field_size > file_size
  ------------------
  |  Branch (461:8): [True: 2, False: 16]
  ------------------
  462|     16|				|| field_size >= (int)sizeof(fields[f].value))
  ------------------
  |  Branch (462:8): [True: 0, False: 16]
  ------------------
  463|      5|			return -1;
  464|       |
  465|     16|		fields[f].len = field_size;
  466|     16|		strncpy(fields[f].value, &file[i], field_size);
  467|     16|		fields[f].value[field_size] = '\0';
  468|     16|		i += field_size;
  469|     16|	}
  470|       |
  471|      1|	if (fields[f_first_name].len + fields[f_last_name].len + 1 >= name_len)
  ------------------
  |  Branch (471:6): [True: 0, False: 1]
  ------------------
  472|      0|		return -1;
  473|       |
  474|       |	/* the lengths are already checked that they will fit in buffer */
  475|      1|	snprintf(name, name_len, "%.*s %.*s",
  476|      1|		fields[f_first_name].len, fields[f_first_name].value,
  477|      1|		fields[f_last_name].len, fields[f_last_name].value);
  478|      1|	return 0;
  479|      1|}
pkcs15-itacns.c:hextoint:
  370|     62|{
  371|     62|	char hex[16];
  372|     62|	char *end;
  373|     62|	int res;
  374|       |
  375|     62|	if(len >= sizeof(hex))
  ------------------
  |  Branch (375:5): [True: 0, False: 62]
  ------------------
  376|      0|		return -1;
  377|     62|	strncpy(hex, src, len);
  378|     62|	hex[len] = '\0';
  379|     62|	res = (int)strtol(hex, &end, 0x10);
  380|     62|	if(end != (char*)&hex[len])
  ------------------
  |  Branch (380:5): [True: 17, False: 45]
  ------------------
  381|     17|		return -1;
  382|     45|	return res;
  383|     62|}
pkcs15-itacns.c:itacns_check_and_add_keyset:
  654|    287|{
  655|    287|	int r;
  656|    287|	sc_path_t path;
  657|    287|	sc_pkcs15_id_t cert_id;
  658|    287|	int ext_info_ok;
  659|    287|	int ku = 0, xku = 0;
  660|    287|	size_t modulus_len = 0;
  661|    287|	int pubkey_usage_flags = 0, prkey_usage_flags = 0;
  662|       |
  663|    287|	cert_id.len = 1;
  664|    287|	cert_id.value[0] = sec_env;
  665|    287|	*found_certificates = 0;
  666|       |
  667|       |	/* Certificate */
  668|    287|	if (!cert_path) {
  ------------------
  |  Branch (668:6): [True: 0, False: 287]
  ------------------
  669|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  670|      0|			"We cannot use keys without a matching certificate");
  671|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|      0|	}
  673|       |
  674|    287|	sc_format_path(cert_path, &path);
  675|    287|	r = sc_select_file(p15card->card, &path, NULL);
  676|    287|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    287|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (676:6): [True: 31, False: 256]
  ------------------
  677|     31|		return 0;
  678|    256|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    256|#define SC_SUCCESS				0
  ------------------
  |  Branch (678:6): [True: 136, False: 120]
  ------------------
  679|    136|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  680|    136|			"Could not find certificate for %s", label);
  681|    136|		return r;
  682|    136|	}
  683|       |
  684|       |	/*
  685|       |	 * Infocamere 1204 (and others?) store a more complex structure. We
  686|       |	 * are going to read the first bytes to guess its length, and invoke
  687|       |	 * itacns_add_cert so that it only reads the certificate.
  688|       |	 */
  689|    120|	if (cert_offset) {
  ------------------
  |  Branch (689:6): [True: 43, False: 77]
  ------------------
  690|     43|		u8 certlen[3];
  691|     43|		memset(certlen, 0, sizeof certlen);
  692|     43|		r = loadFile(p15card, &path, certlen, sizeof(certlen));
  693|     43|		LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 41]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|     41|			"Could not read certificate file");
  695|     41|		if (r < 3)
  ------------------
  |  Branch (695:7): [True: 1, False: 40]
  ------------------
  696|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  697|     40|		path.index = (int)cert_offset;
  698|     40|		path.count = (certlen[1] << 8) + certlen[2];
  699|       |		/* If those bytes are 00, then we are probably dealing with an
  700|       |		 * empty file. */
  701|     40|		if (path.count == 0)
  ------------------
  |  Branch (701:7): [True: 4, False: 36]
  ------------------
  702|      4|			return 0;
  703|     40|	}
  704|       |
  705|    113|	r = itacns_add_cert(p15card, SC_PKCS15_TYPE_CERT_X509, 0,
  ------------------
  |  |  439|    113|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  706|    113|		&path, &cert_id, label, 0, &ext_info_ok, &ku, &xku, &modulus_len);
  707|    113|	if (r == SC_ERROR_INVALID_ASN1_OBJECT)
  ------------------
  |  |   82|    113|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (707:6): [True: 76, False: 37]
  ------------------
  708|     76|		return 0;
  709|     37|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     37|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     37|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     37|	int _ret = (r); \
  |  |  |  |  168|     37|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 37, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     37|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     37|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     37|		return _ret; \
  |  |  |  |  172|     37|	} \
  |  |  |  |  173|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  710|      0|		"Could not add certificate");
  711|      0|	(*found_certificates)++;
  712|       |
  713|       |	/* Set usage flags */
  714|      0|	if(ext_info_ok) {
  ------------------
  |  Branch (714:5): [True: 0, False: 0]
  ------------------
  715|      0|#ifdef ENABLE_OPENSSL
  716|      0|		if (ku & KU_DIGITAL_SIGNATURE) {
  ------------------
  |  Branch (716:7): [True: 0, False: 0]
  ------------------
  717|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  718|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  719|      0|		}
  720|      0|		if (ku & KU_NON_REPUDIATION) {
  ------------------
  |  Branch (720:7): [True: 0, False: 0]
  ------------------
  721|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  722|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  723|      0|		}
  724|      0|		if (ku & KU_KEY_ENCIPHERMENT || ku & KU_KEY_AGREEMENT
  ------------------
  |  Branch (724:7): [True: 0, False: 0]
  |  Branch (724:35): [True: 0, False: 0]
  ------------------
  725|      0|			|| xku & XKU_SSL_CLIENT) {
  ------------------
  |  Branch (725:7): [True: 0, False: 0]
  ------------------
  726|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  727|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  728|      0|		}
  729|      0|		if (ku & KU_DATA_ENCIPHERMENT || xku & XKU_SMIME) {
  ------------------
  |  Branch (729:7): [True: 0, False: 0]
  |  Branch (729:36): [True: 0, False: 0]
  ------------------
  730|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|      0|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  731|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  732|      0|		}
  733|       |#else /* ENABLE_OPENSSL */
  734|       |		sc_log(p15card->card->ctx,
  735|       |			"Extended certificate info retrieved without OpenSSL. "
  736|       |			"How is this possible?");
  737|       |		return SC_ERROR_INTERNAL;
  738|       |#endif /* ENABLE_OPENSSL */
  739|      0|	} else {
  740|       |		/* Certificate info not retrieved; fall back onto defaults */
  741|      0|		pubkey_usage_flags =
  742|      0|			  SC_PKCS15_PRKEY_USAGE_VERIFY
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  743|      0|			| SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  744|      0|		prkey_usage_flags =
  745|      0|			  SC_PKCS15_PRKEY_USAGE_SIGN
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  746|      0|			| SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  747|      0|	}
  748|       |
  749|      0|	r = itacns_add_keyset(p15card, label, sec_env, &cert_id,
  750|      0|		pubkey_path, prkey_path, pubkey_usage_flags, prkey_usage_flags,
  751|      0|		pin_ref, modulus_len);
  752|      0|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|      0|		"Could not add keys for this certificate");
  754|       |
  755|      0|	return r;
  756|      0|}
pkcs15-itacns.c:itacns_add_cert:
  189|    113|{
  190|    113|	int r;
  191|       |	/* const char *label = "Certificate"; */
  192|    113|	sc_pkcs15_cert_info_t info;
  193|    113|	sc_pkcs15_object_t    obj;
  194|    113|#ifdef ENABLE_OPENSSL
  195|    113|	X509 *x509;
  196|    113|	sc_pkcs15_cert_t *cert;
  197|    113|	int private_obj;
  198|    113|#endif
  199|       |
  200|    113|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    113|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    113|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    113|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 113]
  |  |  ------------------
  ------------------
  201|       |
  202|    113|	if(type != SC_PKCS15_TYPE_CERT_X509) {
  ------------------
  |  |  439|    113|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (202:5): [True: 0, False: 113]
  ------------------
  203|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  204|      0|			"Cannot add a certificate of a type other than X.509");
  205|      0|		return 1;
  206|      0|	}
  207|       |
  208|    113|	*ext_info_ok = 0;
  209|       |
  210|       |
  211|    113|	memset(&info, 0, sizeof(info));
  212|    113|	memset(&obj,  0, sizeof(obj));
  213|       |
  214|    113|	info.id                = *id;
  215|    113|	info.authority         = authority;
  216|    113|	if (path)
  ------------------
  |  Branch (216:6): [True: 113, False: 0]
  ------------------
  217|    113|		info.path = *path;
  218|       |
  219|    113|	strlcpy(obj.label, label, sizeof(obj.label));
  ------------------
  |  |   43|    113|#define strlcpy _strlcpy
  ------------------
  220|       |
  221|       |	/* If we have OpenSSL, read keyUsage */
  222|    113|#ifdef ENABLE_OPENSSL
  223|    113|	private_obj = obj_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    113|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  224|    113|	r = sc_pkcs15_read_certificate(p15card, &info, private_obj, &cert);
  225|    113|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|    113|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    113|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    113|	int _ret = (r); \
  |  |  |  |  168|    113|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 113, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    113|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    113|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    113|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    113|		return _ret; \
  |  |  |  |  172|    113|	} \
  |  |  |  |  173|    113|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  226|      0|		"Could not read X.509 certificate");
  227|       |
  228|      0|	{
  229|      0|		const u8 *throwaway = cert->data.value;
  230|      0|		x509 = d2i_X509(NULL, &throwaway, cert->data.len);
  231|      0|	}
  232|       |
  233|      0|	if (cert->key && cert->key->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (233:6): [True: 0, False: 0]
  |  Branch (233:19): [True: 0, False: 0]
  ------------------
  234|      0|		*modulus_len = cert->key->u.rsa.modulus.len * 8;
  235|      0|	}
  236|       |
  237|      0|	sc_pkcs15_free_certificate(cert);
  238|      0|	if (!x509) {
  ------------------
  |  Branch (238:6): [True: 0, False: 0]
  ------------------
  239|      0|		sc_log_openssl(p15card->card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  240|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  241|      0|	}
  242|      0|	X509_check_purpose(x509, -1, 0);
  243|       |
  244|      0|	if(X509_get_extension_flags(x509) & EXFLAG_KUSAGE) {
  ------------------
  |  Branch (244:5): [True: 0, False: 0]
  ------------------
  245|      0|		*ext_info_ok = 1;
  246|      0|		*key_usage = X509_get_key_usage(x509);
  247|      0|		*x_key_usage = X509_get_extended_key_usage(x509);
  248|      0|	}
  249|      0|	OPENSSL_free(x509);
  250|       |
  251|      0|#endif /* ENABLE_OPENSSL */
  252|       |
  253|      0|	obj.flags = obj_flags;
  254|      0|	r = sc_pkcs15emu_add_x509_cert(p15card, &obj, &info);
  255|      0|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|      0|		"Could not add X.509 certificate");
  257|       |
  258|      0|	return r;
  259|      0|}

sc_pkcs15emu_jpki_init_ex:
  248|  9.03k|{
  249|  9.03k|	if (p15card->card->type != SC_CARD_TYPE_JPKI_BASE)
  ------------------
  |  Branch (249:6): [True: 8.98k, False: 49]
  ------------------
  250|  8.98k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.98k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  251|     49|	return sc_pkcs15emu_jpki_init(p15card);
  252|  9.03k|}
pkcs15-jpki.c:sc_pkcs15emu_jpki_init:
   38|     49|{
   39|     49|	sc_card_t *card = p15card->card;
   40|     49|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     49|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   41|     49|	int i, rc;
   42|       |
   43|     49|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|     49|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     49|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     49|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     49|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|       |
   45|     49|	set_string(&p15card->tokeninfo->label, "JPKI");
   46|     49|	set_string(&p15card->tokeninfo->manufacturer_id, "JPKI");
   47|       |	/* set dummy until we found serial number */
   48|     49|	set_string(&p15card->tokeninfo->serial_number, "00000000");
   49|       |
   50|       |	/* Select application directory */
   51|     49|	if (drvdata->selected != SELECT_JPKI_AP) {
  ------------------
  |  |   25|     49|#define SELECT_JPKI_AP 1
  ------------------
  |  Branch (51:6): [True: 49, False: 0]
  ------------------
   52|     49|		rc = jpki_select_ap(card);
   53|     49|		LOG_TEST_RET(card->ctx, rc, "select AP failed");
  ------------------
  |  |  174|     49|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     49|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     49|	int _ret = (r); \
  |  |  |  |  168|     49|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   54|     36|		drvdata->selected = SELECT_JPKI_AP;
  ------------------
  |  |   25|     36|#define SELECT_JPKI_AP 1
  ------------------
   55|     36|	}
   56|       |
   57|       |	/* add certificates */
   58|    180|	for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (58:14): [True: 144, False: 36]
  ------------------
   59|    144|		static const char *jpki_cert_names[4] = {
   60|    144|			"User Authentication Certificate",
   61|    144|			"Digital Signature Certificate",
   62|    144|			"User Authentication Certificate CA",
   63|    144|			"Digital Signature Certificate CA"
   64|    144|		};
   65|    144|		static char const *jpki_cert_paths[4] = {
   66|    144|			"000A",
   67|    144|			"0001",
   68|    144|			"000B",
   69|    144|			"0002"
   70|    144|		};
   71|    144|		static int jpki_cert_ids[4] = { 1, 2, 3, 4 };
   72|    144|		static int jpki_cert_flags[4] = {
   73|    144|			0,
   74|    144|			SC_PKCS15_CO_FLAG_PRIVATE,
  ------------------
  |  |   50|    144|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   75|    144|			0,
   76|    144|			0,
   77|    144|		};
   78|    144|		static int jpki_cert_auth_id[4] = { 0, 2, 0, 0 };
   79|    144|		static int jpki_cert_authority[4] = {0, 0, 1, 1};
   80|    144|		struct sc_pkcs15_cert_info cert_info;
   81|    144|		struct sc_pkcs15_object cert_obj;
   82|    144|		memset(&cert_info, 0, sizeof(cert_info));
   83|    144|		memset(&cert_obj, 0, sizeof(cert_obj));
   84|       |
   85|    144|		cert_info.id.value[0] = jpki_cert_ids[i];
   86|    144|		cert_info.id.len = 1;
   87|    144|		sc_format_path(jpki_cert_paths[i], &cert_info.path);
   88|    144|		cert_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    144|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
   89|       |
   90|    144|		strlcpy(cert_obj.label, jpki_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|    144|#define strlcpy _strlcpy
  ------------------
   91|    144|		cert_info.authority = jpki_cert_authority[i];
   92|    144|		cert_obj.flags = jpki_cert_flags[i];
   93|    144|		if (jpki_cert_auth_id[i]) {
  ------------------
  |  Branch (93:7): [True: 36, False: 108]
  ------------------
   94|     36|			cert_obj.auth_id.len = 1;
   95|     36|			cert_obj.auth_id.value[0] = jpki_cert_auth_id[i];
   96|     36|		}
   97|    144|		rc = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
   98|    144|		if (rc < 0) {
  ------------------
  |  Branch (98:7): [True: 0, False: 144]
  ------------------
   99|      0|			sc_pkcs15_card_clear(p15card);
  100|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|      0|		}
  102|       |
  103|    144|	}
  104|       |
  105|       |	/* add pins */
  106|     70|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (106:14): [True: 55, False: 15]
  ------------------
  107|     55|		static const char *jpki_pin_names[2] = {
  108|     55|			"User Authentication PIN",
  109|     55|			"Digital Signature PIN"
  110|     55|		};
  111|     55|		static const int jpki_pin_min[2] = { 4, 6 };
  112|     55|		static const int jpki_pin_max[2] = { 4, 16 };
  113|     55|		static const int jpki_pin_ref[2] = { 1, 2 };
  114|     55|		static const int jpki_pin_authid[2] = { 1, 2 };
  115|     55|		static const int jpki_pin_flags[2] = {
  116|     55|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|     55|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  117|     55|			SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|     55|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  118|     55|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|     55|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  119|     55|			SC_PKCS15_PIN_FLAG_LOCAL
  ------------------
  |  |   55|     55|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  120|     55|		};
  121|     55|		static const int jpki_pin_max_tries[2] = {
  122|     55|			JPKI_AUTH_PIN_MAX_TRIES,
  ------------------
  |  |   30|     55|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  123|     55|			JPKI_SIGN_PIN_MAX_TRIES
  ------------------
  |  |   34|     55|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  124|     55|		};
  125|       |
  126|     55|		struct sc_pkcs15_auth_info pin_info;
  127|     55|		struct sc_pkcs15_object pin_obj;
  128|     55|		struct sc_pin_cmd_data pin_cmd_data;
  129|     55|		memset(&pin_info, 0, sizeof (pin_info));
  130|     55|		memset(&pin_obj, 0, sizeof (pin_obj));
  131|     55|		memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  132|       |
  133|     55|		pin_info.auth_id.len = 1;
  134|     55|		pin_info.auth_id.value[0] = jpki_pin_authid[i];
  135|     55|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     55|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  136|     55|		pin_info.attrs.pin.reference = jpki_pin_ref[i];
  137|     55|		pin_info.attrs.pin.flags = jpki_pin_flags[i];
  138|     55|		pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     55|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  139|     55|		pin_info.attrs.pin.min_length = jpki_pin_min[i];
  140|     55|		pin_info.attrs.pin.stored_length = 0;
  141|     55|		pin_info.attrs.pin.max_length = jpki_pin_max[i];
  142|     55|		pin_info.attrs.pin.pad_char = '\0';
  143|     55|		pin_info.max_tries = jpki_pin_max_tries[i];
  144|     55|		pin_info.tries_left = -1;
  145|     55|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|     55|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  146|       |
  147|     55|		pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     55|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  148|     55|		pin_cmd_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|     55|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  149|     55|		pin_cmd_data.pin_reference = jpki_pin_ref[i];
  150|     55|		rc = sc_pin_cmd(card, &pin_cmd_data);
  151|     55|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  152|     55|		LOG_TEST_RET(card->ctx, rc, "sc_pin_cmd failed");
  ------------------
  |  |  174|     55|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     55|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     55|	int _ret = (r); \
  |  |  |  |  168|     55|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  169|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     21|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     21|		return _ret; \
  |  |  |  |  172|     21|	} \
  |  |  |  |  173|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  153|     34|		strlcpy(pin_obj.label, jpki_pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|     34|#define strlcpy _strlcpy
  ------------------
  154|     34|		pin_obj.flags = jpki_pin_flags[i];
  155|       |
  156|     34|		rc = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  157|     34|		if (rc < 0) {
  ------------------
  |  Branch (157:7): [True: 0, False: 34]
  ------------------
  158|      0|			sc_pkcs15_card_clear(p15card);
  159|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|      0|		}
  161|     34|	}
  162|       |
  163|       |	/* add private keys */
  164|     45|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (164:14): [True: 30, False: 15]
  ------------------
  165|     30|		static int prkey_pin[2] = { 1, 2 };
  166|     30|		static int prkey_usage[2] = {
  167|     30|			SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|     30|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  168|     30|			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  307|     30|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  314|     30|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  169|     30|		};
  170|     30|		static const char *prkey_name[2] = {
  171|     30|			"User Authentication Key",
  172|     30|			"Digital Signature Key"
  173|     30|		};
  174|     30|		static int prkey_user_consent[2] = { 0, 1 };
  175|     30|		struct sc_pkcs15_prkey_info prkey_info;
  176|     30|		struct sc_pkcs15_object prkey_obj;
  177|       |
  178|     30|		memset(&prkey_info, 0, sizeof (prkey_info));
  179|     30|		memset(&prkey_obj, 0, sizeof (prkey_obj));
  180|       |
  181|     30|		prkey_info.id.len = 1;
  182|     30|		prkey_info.id.value[0] = prkey_pin[i];
  183|     30|		prkey_info.usage = prkey_usage[i];
  184|     30|		prkey_info.native = 1;
  185|     30|		prkey_info.key_reference = i + 1;
  186|     30|		prkey_info.modulus_length = 2048;
  187|       |
  188|     30|		strlcpy(prkey_obj.label, prkey_name[i], sizeof (prkey_obj.label));
  ------------------
  |  |   43|     30|#define strlcpy _strlcpy
  ------------------
  189|     30|		prkey_obj.auth_id.len = 1;
  190|     30|		prkey_obj.auth_id.value[0] = prkey_pin[i];
  191|     30|		prkey_obj.user_consent = prkey_user_consent[i];
  192|     30|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     30|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  193|       |
  194|     30|		rc = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  195|     30|		if (rc < 0) {
  ------------------
  |  Branch (195:7): [True: 0, False: 30]
  ------------------
  196|      0|			sc_pkcs15_card_clear(p15card);
  197|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|      0|		}
  199|     30|	}
  200|       |
  201|       |	/* add public keys */
  202|     45|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (202:14): [True: 30, False: 15]
  ------------------
  203|     30|		static int pubkey_id[2] = { 1, 2 };
  204|     30|		static const char *jpki_pubkey_names[2] = {
  205|     30|			"User Authentication Public Key",
  206|     30|			"Digital Signature Public Key"
  207|     30|		};
  208|     30|		static int jpki_pubkey_flags[2] = {
  209|     30|				0,
  210|     30|				SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     30|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  211|     30|		static int jpki_pubkey_auth_id[2] = {0, 2};
  212|     30|		struct sc_pkcs15_pubkey_info pubkey_info;
  213|     30|		struct sc_pkcs15_object pubkey_obj;
  214|     30|		static char const *jpki_pubkey_paths[2] = {
  215|     30|			"000A",
  216|     30|			"0001"
  217|     30|		};
  218|       |
  219|     30|		memset(&pubkey_info, 0, sizeof (pubkey_info));
  220|     30|		memset(&pubkey_obj, 0, sizeof (pubkey_obj));
  221|       |
  222|     30|		strlcpy(pubkey_obj.label, jpki_pubkey_names[i], sizeof (pubkey_obj.label));
  ------------------
  |  |   43|     30|#define strlcpy _strlcpy
  ------------------
  223|     30|		pubkey_info.id.len = 1;
  224|     30|		pubkey_info.id.value[0] = pubkey_id[i];
  225|     30|		pubkey_info.native = 1;
  226|     30|		pubkey_info.key_reference = i + 1;
  227|       |
  228|     30|		sc_format_path(jpki_pubkey_paths[i], &pubkey_info.path);
  229|     30|		pubkey_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     30|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  230|     30|		pubkey_obj.flags = jpki_pubkey_flags[i];
  231|     30|		if (jpki_pubkey_auth_id[i]) {
  ------------------
  |  Branch (231:7): [True: 15, False: 15]
  ------------------
  232|     15|			pubkey_obj.auth_id.len = 1;
  233|     15|			pubkey_obj.auth_id.value[0] = jpki_pubkey_auth_id[i];
  234|     15|		}
  235|       |
  236|     30|		rc = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  237|     30|		if (rc < 0) {
  ------------------
  |  Branch (237:7): [True: 0, False: 30]
  ------------------
  238|      0|			sc_pkcs15_card_clear(p15card);
  239|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|      0|		}
  241|     30|	}
  242|     15|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     15|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     15|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     15|	int _ret = r; \
  |  |  |  |  155|     15|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     15|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  157|     15|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     15|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     15|	return _ret; \
  |  |  |  |  163|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|     15|}

sc_pkcs15emu_lteid_init_ex:
   70|  7.45k|{
   71|  7.45k|	if (p15card->card->type == SC_CARD_TYPE_LTEID) {
  ------------------
  |  Branch (71:6): [True: 0, False: 7.45k]
  ------------------
   72|      0|		return sc_pkcs15emu_lteid_init(p15card, aid);
   73|      0|	}
   74|       |
   75|  7.45k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   76|  7.45k|}

sc_pkcs15emu_nqapplet_init_ex:
  179|  7.45k|{
  180|  7.45k|	int rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  181|  7.45k|	sc_context_t *ctx;
  182|  7.45k|	sc_card_t *card;
  183|       |
  184|  7.45k|	if (!p15card || !p15card->card || !p15card->card->ctx) {
  ------------------
  |  Branch (184:6): [True: 0, False: 7.45k]
  |  Branch (184:18): [True: 0, False: 7.45k]
  |  Branch (184:36): [True: 0, False: 7.45k]
  ------------------
  185|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  186|      0|	}
  187|       |
  188|  7.45k|	card = p15card->card;
  189|  7.45k|	ctx = card->ctx;
  190|       |
  191|  7.45k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  7.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.45k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.45k]
  |  |  ------------------
  ------------------
  192|       |
  193|  7.45k|	if (card->type < SC_CARD_TYPE_NQ_APPLET || card->type > SC_CARD_TYPE_NQ_APPLET_RFID) {
  ------------------
  |  Branch (193:6): [True: 7.45k, False: 2]
  |  Branch (193:45): [True: 2, False: 0]
  ------------------
  194|  7.45k|		sc_log(p15card->card->ctx, "Unsupported card type: %d", card->type);
  ------------------
  |  |   71|  7.45k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  195|  7.45k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  196|  7.45k|	}
  197|       |
  198|      0|	rv = add_nqapplet_objects(p15card);
  199|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Failed to add PKCS15");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|       |
  201|      0|	if (aid != NULL) {
  ------------------
  |  Branch (201:6): [True: 0, False: 0]
  ------------------
  202|      0|		struct sc_file *file = sc_file_new();
  203|      0|		if (file != NULL) {
  ------------------
  |  Branch (203:7): [True: 0, False: 0]
  ------------------
  204|       |			/* PKCS11 depends on the file_app object, provide MF */
  205|      0|			sc_format_path("3f00", &file->path);
  206|      0|			sc_file_free(p15card->file_app);
  207|      0|			p15card->file_app = file;
  208|      0|		}
  209|      0|	}
  210|       |
  211|      0|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  212|       |
  213|      0|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  214|      0|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (214:6): [True: 0, False: 0]
  ------------------
  215|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  216|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "unable to create tokeninfo struct");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|	} else {
  218|      0|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  219|       |
  220|      0|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial_hex, sizeof(serial_hex), 0);
  221|      0|		set_string(&p15card->tokeninfo->serial_number, serial_hex);
  222|      0|		set_string(&p15card->tokeninfo->label, name_Card);
  223|      0|		set_string(&p15card->tokeninfo->manufacturer_id, name_Vendor);
  224|      0|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      0|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  225|      0|	}
  226|       |
  227|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  228|      0|err:
  229|      0|	sc_pkcs15_card_clear(p15card);
  230|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|      0|}

sc_pkcs15emu_oberthur_init_ex:
 1160|  9.14k|{
 1161|  9.14k|	int rv;
 1162|       |
 1163|  9.14k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  9.14k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.14k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.14k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.14k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.14k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  9.14k|	rv = oberthur_detect_card(p15card);
 1165|  9.14k|	if (!rv)
  ------------------
  |  Branch (1165:6): [True: 749, False: 8.40k]
  ------------------
 1166|    749|		rv = sc_pkcs15emu_oberthur_init(p15card);
 1167|       |
 1168|  9.14k|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|  9.14k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.14k|	int _ret = r; \
  |  |  |  |  155|  9.14k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.14k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.14k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.12k, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.14k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.14k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.14k|	return _ret; \
  |  |  |  |  163|  9.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|  9.14k|}
pkcs15-oberthur.c:oberthur_detect_card:
 1148|  9.14k|{
 1149|  9.14k|	struct sc_card *card = p15card->card;
 1150|       |
 1151|  9.14k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.14k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.14k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.14k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.14k]
  |  |  ------------------
  ------------------
 1152|  9.14k|	if (p15card->card->type != SC_CARD_TYPE_OBERTHUR_64K)
  ------------------
  |  Branch (1152:6): [True: 8.40k, False: 749]
  ------------------
 1153|  9.14k|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  8.40k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.40k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.40k|	int _ret = r; \
  |  |  |  |  155|  8.40k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.40k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.40k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.40k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.40k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.40k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.40k|	return _ret; \
  |  |  |  |  163|  8.40k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1154|    749|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    749|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    749|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    749|	int _ret = r; \
  |  |  |  |  155|    749|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 749, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    749|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 749]
  |  |  |  |  ------------------
  |  |  |  |  157|    749|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    749|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    749|	return _ret; \
  |  |  |  |  163|    749|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1155|    749|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_init:
 1015|    749|{
 1016|    749|	struct sc_context *ctx = p15card->card->ctx;
 1017|    749|	struct sc_pkcs15_auth_info auth_info;
 1018|    749|	struct sc_pkcs15_object   obj;
 1019|    749|	struct sc_card *card = p15card->card;
 1020|    749|	struct sc_path path;
 1021|    749|	int rv, ii, tries_left;
 1022|    749|	char serial[0x10];
 1023|    749|	unsigned char sopin_reference = 0x04;
 1024|       |
 1025|    749|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    749|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    749|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    749|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 749]
  |  |  ------------------
  ------------------
 1026|    749|	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial, sizeof(serial), 0);
 1027|    749|	set_string(&p15card->tokeninfo->serial_number, serial);
 1028|       |
 1029|    749|	p15card->ops.parse_df = sc_awp_parse_df;
 1030|    749|	p15card->ops.clear = sc_awp_clear;
 1031|       |
 1032|    749|	sc_log(ctx, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|    749|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1033|       |
 1034|    749|	sc_format_path(AWP_PIN_DF, &path);
  ------------------
  |  |   69|    749|#define AWP_PIN_DF		"3F005011"
  ------------------
 1035|    749|	rv = sc_select_file(card, &path, NULL);
 1036|    749|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot select PIN dir");
  ------------------
  |  |  184|    749|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    749|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    749|	int _ret = (r); \
  |  |  |  |  178|    749|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 327, False: 422]
  |  |  |  |  ------------------
  |  |  |  |  179|    327|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    327|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    327|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    327|		goto err; \
  |  |  |  |  182|    327|	} \
  |  |  |  |  183|    749|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 422]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1037|       |
 1038|    422|	tries_left = -1;
 1039|    422|	rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    422|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1040|    422|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|     34|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1040:6): [True: 34, False: 388]
  |  Branch (1040:12): [True: 32, False: 2]
  ------------------
 1041|     32|		sopin_reference = 0x84;
 1042|     32|		rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|     32|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1043|     32|	}
 1044|    422|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|     30|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1044:6): [True: 30, False: 392]
  |  Branch (1044:12): [True: 24, False: 6]
  ------------------
 1045|    422|		LOG_TEST_GOTO_ERR(ctx, rv, "Invalid state of SO-PIN");
  ------------------
  |  |  184|     24|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     24|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     24|	int _ret = (r); \
  |  |  |  |  178|     24|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     24|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     24|		goto err; \
  |  |  |  |  182|     24|	} \
  |  |  |  |  183|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1046|       |
 1047|       |	/* add PIN */
 1048|    398|	memset(&auth_info, 0, sizeof(auth_info));
 1049|    398|	memset(&obj,  0, sizeof(obj));
 1050|       |
 1051|    398|	auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    398|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1052|    398|	auth_info.auth_method	= SC_AC_CHV;
  ------------------
  |  |  151|    398|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1053|    398|	auth_info.auth_id.len = 1;
 1054|    398|	auth_info.auth_id.value[0] = 0xFF;
 1055|    398|	auth_info.attrs.pin.min_length		= 4;
 1056|    398|	auth_info.attrs.pin.max_length		= 64;
 1057|    398|	auth_info.attrs.pin.stored_length	= 64;
 1058|    398|	auth_info.attrs.pin.type		= SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    398|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1059|    398|	auth_info.attrs.pin.reference		= sopin_reference;
 1060|    398|	auth_info.attrs.pin.pad_char		= 0xFF;
 1061|    398|	auth_info.attrs.pin.flags		= SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
  ------------------
  |  |   54|    398|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
 1062|    398|				| SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|    398|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1063|    398|				| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
  ------------------
  |  |   59|    398|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
 1064|    398|				| SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   61|    398|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
 1065|    398|	auth_info.tries_left		= tries_left;
 1066|    398|	auth_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    398|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1067|       |
 1068|    398|	strncpy(obj.label, "SO PIN", SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|    398|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1069|    398|	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    398|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    398|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1070|       |
 1071|    398|	sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
  ------------------
  |  |   71|    398|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1072|    398|			sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
 1073|    398|	rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
 1074|    398|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot add PIN object");
  ------------------
  |  |  184|    398|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    398|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    398|	int _ret = (r); \
  |  |  |  |  178|    398|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 398]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    398|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 398]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1075|       |
 1076|    398|	tries_left = -1;
 1077|    398|	rv = sc_verify(card, SC_AC_CHV, 0x81, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    398|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1078|    398|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|    398|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1078:6): [True: 4, False: 394]
  ------------------
 1079|       |		/* add PIN */
 1080|      4|		memset(&auth_info, 0, sizeof(auth_info));
 1081|      4|		memset(&obj,  0, sizeof(obj));
 1082|       |
 1083|      4|		auth_info.auth_id.len = sizeof(PinDomainID) > sizeof(auth_info.auth_id.value)
  ------------------
  |  Branch (1083:27): [Folded, False: 4]
  ------------------
 1084|      4|				? sizeof(auth_info.auth_id.value) : sizeof(PinDomainID);
 1085|      4|		memcpy(auth_info.auth_id.value, PinDomainID, auth_info.auth_id.len);
 1086|      4|		auth_info.auth_method	= SC_AC_CHV;
  ------------------
  |  |  151|      4|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1087|       |
 1088|      4|		auth_info.attrs.pin.min_length		= 4;
 1089|      4|		auth_info.attrs.pin.max_length		= 64;
 1090|      4|		auth_info.attrs.pin.stored_length	= 64;
 1091|      4|		auth_info.attrs.pin.type		= SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|      4|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1092|      4|		auth_info.attrs.pin.reference		= 0x81;
 1093|      4|		auth_info.attrs.pin.pad_char		= 0xFF;
 1094|      4|		auth_info.attrs.pin.flags		= SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
  ------------------
  |  |   54|      4|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
 1095|      4|					| SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      4|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1096|      4|					| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
  ------------------
  |  |   59|      4|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
 1097|      4|					| SC_PKCS15_PIN_FLAG_LOCAL;
  ------------------
  |  |   55|      4|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
 1098|      4|		auth_info.tries_left		= tries_left;
 1099|       |
 1100|      4|		strncpy(obj.label, PIN_DOMAIN_LABEL, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   66|      4|#define PIN_DOMAIN_LABEL	"SCM"
  ------------------
              		strncpy(obj.label, PIN_DOMAIN_LABEL, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|      4|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1101|      4|		obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|      4|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      4|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1102|      4|		if (sopin_reference == 0x84) {
  ------------------
  |  Branch (1102:7): [True: 2, False: 2]
  ------------------
 1103|       |			/*
 1104|       |			 * auth_pin_reset_oberthur_style() in card-oberthur.c
 1105|       |			 * always uses PUK with reference 0x84 for
 1106|       |			 * unblocking of User PIN
 1107|       |			 */
 1108|      2|			obj.auth_id.len = 1;
 1109|      2|			obj.auth_id.value[0] = 0xFF;
 1110|      2|		}
 1111|       |
 1112|      4|		sc_format_path(AWP_PIN_DF, &auth_info.path);
  ------------------
  |  |   69|      4|#define AWP_PIN_DF		"3F005011"
  ------------------
 1113|      4|		auth_info.path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|      4|#define SC_PATH_TYPE_PATH		2
  ------------------
 1114|       |
 1115|      4|		sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1116|      4|				sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
 1117|      4|		rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
 1118|      4|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot add PIN object");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1119|      4|	}
 1120|    394|	else if (rv != SC_ERROR_DATA_OBJECT_NOT_FOUND)    {
  ------------------
  |  |   66|    394|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1120:11): [True: 393, False: 1]
  ------------------
 1121|    393|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot verify PIN");
  ------------------
  |  |  184|    393|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    393|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    393|	int _ret = (r); \
  |  |  |  |  178|    393|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7, False: 386]
  |  |  |  |  ------------------
  |  |  |  |  179|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      7|		goto err; \
  |  |  |  |  182|      7|	} \
  |  |  |  |  183|    393|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 386]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|    393|	}
 1123|       |
 1124|  1.11k|	for (ii=0; oberthur_infos[ii].name; ii++)   {
  ------------------
  |  Branch (1124:13): [True: 1.09k, False: 20]
  ------------------
 1125|  1.09k|		sc_log(ctx, "Oberthur init: read %s file", oberthur_infos[ii].name);
  ------------------
  |  |   71|  1.09k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1126|  1.09k|		free(oberthur_infos[ii].content);
 1127|  1.09k|		rv = sc_oberthur_read_file(p15card, oberthur_infos[ii].path,
 1128|  1.09k|				&oberthur_infos[ii].content, &oberthur_infos[ii].len, 1);
 1129|  1.09k|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: read oberthur file error");
  ------------------
  |  |  184|  1.09k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.09k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.09k|	int _ret = (r); \
  |  |  |  |  178|  1.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 152, False: 943]
  |  |  |  |  ------------------
  |  |  |  |  179|    152|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    152|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    152|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    152|		goto err; \
  |  |  |  |  182|    152|	} \
  |  |  |  |  183|  1.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 943]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|       |
 1131|    943|		sc_log(ctx, "Oberthur init: parse %s file, content length %zu",
  ------------------
  |  |   71|    943|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1132|    943|				oberthur_infos[ii].name, oberthur_infos[ii].len);
 1133|    943|		rv = oberthur_infos[ii].parser(p15card, oberthur_infos[ii].content, oberthur_infos[ii].len,
 1134|    943|				oberthur_infos[ii].postpone_allowed);
 1135|    943|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: parse error");
  ------------------
  |  |  184|    943|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    943|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    943|	int _ret = (r); \
  |  |  |  |  178|    943|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 219, False: 724]
  |  |  |  |  ------------------
  |  |  |  |  179|    219|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    219|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    219|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    219|		goto err; \
  |  |  |  |  182|    219|	} \
  |  |  |  |  183|    943|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 724]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|    943|	}
 1137|       |
 1138|     20|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1139|       |
 1140|    729|err:
 1141|    729|	sc_pkcs15_card_clear(p15card);
 1142|    729|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    729|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    729|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    729|	int _ret = r; \
  |  |  |  |  155|    729|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 729, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    729|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    729|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 729, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    729|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    729|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    729|	return _ret; \
  |  |  |  |  163|    729|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1143|    729|}
pkcs15-oberthur.c:sc_oberthur_parse_privateinfo:
  500|     35|{
  501|     35|	struct sc_context *ctx = p15card->card->ctx;
  502|     35|	size_t ii;
  503|     35|	int rv;
  504|     35|	int no_more_private_keys = 0, no_more_private_data = 0;
  505|       |
  506|     35|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     35|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     35|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     35|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     35|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  507|       |
  508|  49.9k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (508:13): [True: 49.9k, False: 20]
  ------------------
  509|  49.9k|		unsigned int file_id, size;
  510|       |
  511|  49.9k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (511:6): [True: 49.8k, False: 116]
  ------------------
  512|  49.8k|			continue;
  513|       |
  514|    116|		file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
  515|    116|		size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
  516|    116|		sc_log(ctx, "add private object (file-id:%04X, size:%X)", file_id, size);
  ------------------
  |  |   71|    116|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  517|       |
  518|    116|		switch (*(buff+ii + 1))   {
  519|      1|		case BASE_ID_PRV_RSA :
  ------------------
  |  |   83|      1|#define BASE_ID_PRV_RSA   0x30
  ------------------
  |  Branch (519:3): [True: 1, False: 115]
  ------------------
  520|      1|			if (no_more_private_keys)
  ------------------
  |  Branch (520:8): [True: 0, False: 1]
  ------------------
  521|      0|				break;
  522|       |
  523|      1|			rv = sc_pkcs15emu_oberthur_add_prvkey(p15card, file_id, size);
  524|      1|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|      2|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (524:8): [True: 0, False: 1]
  |  Branch (524:56): [True: 0, False: 0]
  ------------------
  525|      0|				struct sc_path path;
  526|       |
  527|      0|				sc_log(ctx, "postpone adding of the private keys");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  528|      0|				sc_format_path("5011A5A5", &path);
  529|      0|				rv = sc_pkcs15_add_df(p15card, SC_PKCS15_PRKDF, &path);
  ------------------
  |  |  488|      0|#define SC_PKCS15_PRKDF			0
  ------------------
  530|      0|				LOG_TEST_RET(ctx, rv, "Add PrkDF error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  531|      0|				no_more_private_keys = 1;
  532|      0|			}
  533|      1|			LOG_TEST_RET(ctx, rv, "Cannot parse private key info");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|      0|			break;
  535|     66|		case BASE_ID_PRV_DES :
  ------------------
  |  |   84|     66|#define BASE_ID_PRV_DES   0x40
  ------------------
  |  Branch (535:3): [True: 66, False: 50]
  ------------------
  536|     66|			break;
  537|     39|		case BASE_ID_PRV_DATA :
  ------------------
  |  |   86|     39|#define BASE_ID_PRV_DATA  0x60
  ------------------
  |  Branch (537:3): [True: 39, False: 77]
  ------------------
  538|     39|			sc_log(ctx, "*(buff+ii + 1):%X", *(buff+ii + 1));
  ------------------
  |  |   71|     39|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  539|     39|			if (no_more_private_data)
  ------------------
  |  Branch (539:8): [True: 10, False: 29]
  ------------------
  540|     10|				break;
  541|       |
  542|     29|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 1);
  543|     29|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|     58|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (543:8): [True: 7, False: 22]
  |  Branch (543:56): [True: 7, False: 0]
  ------------------
  544|      7|				struct sc_path path;
  545|       |
  546|      7|				sc_log(ctx, "postpone adding of the private data");
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  547|      7|				sc_format_path("5011A6A6", &path);
  548|      7|				rv = sc_pkcs15_add_df(p15card, SC_PKCS15_DODF, &path);
  ------------------
  |  |  495|      7|#define SC_PKCS15_DODF			7
  ------------------
  549|      7|				LOG_TEST_RET(ctx, rv, "Add DODF error");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  550|      7|				no_more_private_data = 1;
  551|      7|			}
  552|     29|			LOG_TEST_RET(ctx, rv, "Cannot parse private data info");
  ------------------
  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 25]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|     25|			break;
  554|     25|		default:
  ------------------
  |  Branch (554:3): [True: 10, False: 106]
  ------------------
  555|     10|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Private object parse error");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|    116|		}
  557|    116|	}
  558|       |
  559|     20|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|     20|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_prvkey:
  763|      1|{
  764|      1|	struct sc_context *ctx = p15card->card->ctx;
  765|      1|	struct sc_pkcs15_prkey_info kinfo;
  766|      1|	struct sc_pkcs15_object kobj;
  767|      1|	struct crypto_container ccont;
  768|      1|	unsigned char *info_blob = NULL;
  769|      1|	size_t info_len = 0;
  770|      1|	unsigned flags;
  771|      1|	size_t offs, len;
  772|      1|	char ch_tmp[0x100];
  773|      1|	int rv;
  774|       |
  775|      1|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      1|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      1|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      1|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      1|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|      1|	sc_log(ctx, "add private key(file-id:%04X,size:%04X)", file_id, size);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  777|       |
  778|      1|	memset(&kinfo, 0, sizeof(kinfo));
  779|      1|	memset(&kobj, 0, sizeof(kobj));
  780|      1|	memset(&ccont, 0, sizeof(ccont));
  781|       |
  782|      1|	rv = sc_oberthur_get_friends (file_id, &ccont);
  783|      1|	LOG_TEST_RET(ctx, rv, "Failed to add private key: get friends error");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  784|       |
  785|      0|	if (ccont.id_cert)   {
  ------------------
  |  Branch (785:6): [True: 0, False: 0]
  ------------------
  786|      0|		struct sc_pkcs15_object *objs[32];
  787|      0|		int ii;
  788|       |
  789|      0|		sc_log(ctx, "friend certificate %04X", ccont.id_cert);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  790|      0|		rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_CERT_X509, objs, 32);
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  791|      0|		LOG_TEST_RET(ctx, rv, "Failed to add private key: get certificates error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  792|       |
  793|      0|		for (ii=0; ii<rv; ii++) {
  ------------------
  |  Branch (793:14): [True: 0, False: 0]
  ------------------
  794|      0|			struct sc_pkcs15_cert_info *cert = (struct sc_pkcs15_cert_info *)objs[ii]->data;
  795|      0|			struct sc_path path = cert->path;
  796|      0|			unsigned int id = path.value[path.len - 2] * 0x100 + path.value[path.len - 1];
  797|       |
  798|      0|			if (id == ccont.id_cert)   {
  ------------------
  |  Branch (798:8): [True: 0, False: 0]
  ------------------
  799|      0|				strlcpy(kobj.label, objs[ii]->label, sizeof(kobj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  800|      0|				break;
  801|      0|			}
  802|      0|		}
  803|       |
  804|      0|		if (ii == rv)
  ------------------
  |  Branch (804:7): [True: 0, False: 0]
  ------------------
  805|      0|			LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "Failed to add private key: friend not found");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|      0|	}
  807|       |
  808|      0|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PRV, file_id | 0x100);
  ------------------
  |  |   76|      0|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
  809|      0|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  810|      0|	LOG_TEST_RET(ctx, rv, "Failed to add private key: read oberthur file error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  811|       |
  812|      0|	if (info_len < 2) {
  ------------------
  |  Branch (812:6): [True: 0, False: 0]
  ------------------
  813|      0|		free(info_blob);
  814|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'tag'");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|      0|	}
  816|      0|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  817|      0|	offs = 2;
  818|       |
  819|       |	/* CN */
  820|      0|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (820:6): [True: 0, False: 0]
  ------------------
  821|      0|		free(info_blob);
  822|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'CN'");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  823|      0|	}
  824|      0|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  825|      0|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (825:6): [True: 0, False: 0]
  ------------------
  826|      0|		free(info_blob);
  827|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'CN' length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  828|      0|	}
  829|      0|	if (len && !strlen(kobj.label))   {
  ------------------
  |  Branch (829:6): [True: 0, False: 0]
  |  Branch (829:13): [True: 0, False: 0]
  ------------------
  830|      0|		if (len > sizeof(kobj.label) - 1)
  ------------------
  |  Branch (830:7): [True: 0, False: 0]
  ------------------
  831|      0|			len = sizeof(kobj.label) - 1;
  832|      0|		strncpy(kobj.label, (char *)(info_blob + offs + 2), len);
  833|      0|	}
  834|      0|	offs += 2 + len;
  835|       |
  836|       |	/* ID */
  837|      0|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (837:6): [True: 0, False: 0]
  ------------------
  838|      0|		free(info_blob);
  839|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'ID'");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|      0|	}
  841|      0|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  842|      0|	if (!len) {
  ------------------
  |  Branch (842:6): [True: 0, False: 0]
  ------------------
  843|      0|		free(info_blob);
  844|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: zero length ID");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|      0|	} else if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (845:13): [True: 0, False: 0]
  ------------------
  846|      0|		free(info_blob);
  847|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'ID' length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  848|      0|	} else if (len > sizeof(kinfo.id.value)) {
  ------------------
  |  Branch (848:13): [True: 0, False: 0]
  ------------------
  849|      0|		free(info_blob);
  850|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add private key: invalid ID length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|      0|	}
  852|      0|	memcpy(kinfo.id.value, info_blob + offs + 2, len);
  853|      0|	kinfo.id.len = len;
  854|      0|	offs += 2 + len;
  855|       |
  856|       |	/* Ignore Start/End dates */
  857|      0|	offs += 16;
  858|       |
  859|       |	/* Subject encoded in ASN1 */
  860|      0|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (860:6): [True: 0, False: 0]
  ------------------
  861|      0|		free(info_blob);
  862|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'subject'");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  863|      0|	}
  864|      0|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  865|      0|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (865:6): [True: 0, False: 0]
  ------------------
  866|      0|		free(info_blob);
  867|      0|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'subject' length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  868|      0|	} else if (len) {
  ------------------
  |  Branch (868:13): [True: 0, False: 0]
  ------------------
  869|      0|		kinfo.subject.value = malloc(len);
  870|      0|		if (!kinfo.subject.value) {
  ------------------
  |  Branch (870:7): [True: 0, False: 0]
  ------------------
  871|      0|			free(info_blob);
  872|      0|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Failed to add private key: memory allocation error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  873|      0|		}
  874|      0|		kinfo.subject.len = len;
  875|      0|		memcpy(kinfo.subject.value, info_blob + offs + 2, len);
  876|      0|	}
  877|       |
  878|       |	/* Modulus and exponent are ignored */
  879|       |
  880|      0|	free(info_blob);
  881|       |
  882|      0|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PRV, file_id);
  ------------------
  |  |   76|      0|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
  883|      0|	sc_format_path(ch_tmp, &kinfo.path);
  884|      0|	sc_log(ctx, "Private key info path %s", ch_tmp);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  885|       |
  886|      0|	kinfo.modulus_length	= size;
  887|      0|	kinfo.native		= 1;
  888|      0|	kinfo.key_reference	 = file_id & 0xFF;
  889|       |
  890|      0|	kinfo.usage = sc_oberthur_decode_usage(flags);
  891|      0|	kobj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  892|      0|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|      0|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (892:6): [True: 0, False: 0]
  ------------------
  893|      0|		kobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  894|       |
  895|      0|	kobj.auth_id.len = sizeof(PinDomainID) > sizeof(kobj.auth_id.value)
  ------------------
  |  Branch (895:21): [Folded, False: 0]
  ------------------
  896|      0|			? sizeof(kobj.auth_id.value) : sizeof(PinDomainID);
  897|      0|	memcpy(kobj.auth_id.value, PinDomainID, kobj.auth_id.len);
  898|       |
  899|      0|	sc_log(ctx, "Parsed private key(reference:%i,usage:%X,flags:%X)", kinfo.key_reference, kinfo.usage, kobj.flags);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  900|       |
  901|      0|	rv = sc_pkcs15emu_add_rsa_prkey(p15card, &kobj, &kinfo);
  902|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  903|      0|}
pkcs15-oberthur.c:sc_oberthur_get_friends:
  165|      1|{
  166|      1|	struct container *cont;
  167|       |
  168|      1|	for (cont = Containers; cont; cont = cont->next)   {
  ------------------
  |  Branch (168:26): [True: 0, False: 1]
  ------------------
  169|      0|		if (cont->exchange.id_pub == id || cont->exchange.id_prv == id || cont->exchange.id_cert == id)   {
  ------------------
  |  Branch (169:7): [True: 0, False: 0]
  |  Branch (169:38): [True: 0, False: 0]
  |  Branch (169:69): [True: 0, False: 0]
  ------------------
  170|      0|			if (ccont)
  ------------------
  |  Branch (170:8): [True: 0, False: 0]
  ------------------
  171|      0|				memcpy(ccont, &cont->exchange, sizeof(struct crypto_container));
  172|      0|			break;
  173|      0|		}
  174|       |
  175|      0|		if (cont->sign.id_pub == id || cont->sign.id_prv == id || cont->sign.id_cert == id)   {
  ------------------
  |  Branch (175:7): [True: 0, False: 0]
  |  Branch (175:34): [True: 0, False: 0]
  |  Branch (175:61): [True: 0, False: 0]
  ------------------
  176|      0|			if (ccont)
  ------------------
  |  Branch (176:8): [True: 0, False: 0]
  ------------------
  177|      0|				memcpy(ccont, &cont->sign, sizeof(struct crypto_container));
  178|      0|			break;
  179|      0|		}
  180|      0|	}
  181|       |
  182|      1|	return cont ? 0 : SC_ERROR_TEMPLATE_NOT_FOUND;
  ------------------
  |  |  110|      1|#define SC_ERROR_TEMPLATE_NOT_FOUND		-1508
  ------------------
  |  Branch (182:9): [True: 0, False: 1]
  ------------------
  183|      1|}
pkcs15-oberthur.c:sc_oberthur_decode_usage:
  138|    105|{
  139|    105|	unsigned ret = 0;
  140|       |
  141|    105|	if (flags & OBERTHUR_ATTR_ENCRYPT)
  ------------------
  |  |   48|    105|#define OBERTHUR_ATTR_ENCRYPT		0x0008
  ------------------
  |  Branch (141:6): [True: 58, False: 47]
  ------------------
  142|     58|		ret |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|     58|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  143|    105|	if (flags & OBERTHUR_ATTR_DECRYPT)
  ------------------
  |  |   49|    105|#define OBERTHUR_ATTR_DECRYPT		0x0010
  ------------------
  |  Branch (143:6): [True: 47, False: 58]
  ------------------
  144|     47|		ret |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|     47|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  145|    105|	if (flags & OBERTHUR_ATTR_SIGN)
  ------------------
  |  |   50|    105|#define OBERTHUR_ATTR_SIGN		0x0020
  ------------------
  |  Branch (145:6): [True: 53, False: 52]
  ------------------
  146|     53|		ret |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     53|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  147|    105|	if (flags & OBERTHUR_ATTR_RSIGN)
  ------------------
  |  |   52|    105|#define OBERTHUR_ATTR_RSIGN		0x0080
  ------------------
  |  Branch (147:6): [True: 46, False: 59]
  ------------------
  148|     46|		ret |= SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     46|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  149|    105|	if (flags & OBERTHUR_ATTR_WRAP)
  ------------------
  |  |   54|    105|#define OBERTHUR_ATTR_WRAP		0x0200
  ------------------
  |  Branch (149:6): [True: 63, False: 42]
  ------------------
  150|     63|		ret |= SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|     63|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  151|    105|	if (flags & OBERTHUR_ATTR_UNWRAP)
  ------------------
  |  |   55|    105|#define OBERTHUR_ATTR_UNWRAP		0x0400
  ------------------
  |  Branch (151:6): [True: 61, False: 44]
  ------------------
  152|     61|		ret |= SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|     61|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  153|    105|	if (flags & OBERTHUR_ATTR_VERIFY)
  ------------------
  |  |   51|    105|#define OBERTHUR_ATTR_VERIFY		0x0040
  ------------------
  |  Branch (153:6): [True: 41, False: 64]
  ------------------
  154|     41|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|     41|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  155|    105|	if (flags & OBERTHUR_ATTR_RVERIFY)
  ------------------
  |  |   53|    105|#define OBERTHUR_ATTR_RVERIFY		0x0100
  ------------------
  |  Branch (155:6): [True: 41, False: 64]
  ------------------
  156|     41|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     41|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  157|    105|	if (flags & OBERTHUR_ATTR_DERIVE)
  ------------------
  |  |   56|    105|#define OBERTHUR_ATTR_DERIVE		0x0800
  ------------------
  |  Branch (157:6): [True: 59, False: 46]
  ------------------
  158|     59|		ret |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     59|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  159|    105|	return ret;
  160|    105|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_data:
  909|    155|{
  910|    155|	struct sc_context *ctx = p15card->card->ctx;
  911|    155|	struct sc_pkcs15_data_info dinfo;
  912|    155|	struct sc_pkcs15_object dobj;
  913|    155|	unsigned flags;
  914|    155|	unsigned char *info_blob = NULL, *label = NULL, *app = NULL, *oid = NULL;
  915|    155|	size_t info_len, label_len, app_len, oid_len, offs;
  916|    155|	char ch_tmp[0x100];
  917|    155|	int rv;
  918|       |
  919|    155|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    155|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    155|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    155|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 155]
  |  |  ------------------
  ------------------
  920|    155|	sc_log(ctx, "Add data(file-id:%04X,size:%i,is-private:%i)", file_id, size, private);
  ------------------
  |  |   71|    155|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  921|    155|	memset(&dinfo, 0, sizeof(dinfo));
  922|    155|	memset(&dobj, 0, sizeof(dobj));
  923|       |
  924|    155|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   76|     29|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
              	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|    126|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (924:45): [True: 29, False: 126]
  ------------------
  925|       |
  926|    155|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  927|    155|	LOG_TEST_RET(ctx, rv, "Failed to add data: read oberthur file error");
  ------------------
  |  |  174|    155|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    155|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    155|	int _ret = (r); \
  |  |  |  |  168|    155|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|       |
  929|    127|	if (info_len < 2) {
  ------------------
  |  Branch (929:6): [True: 2, False: 125]
  ------------------
  930|      2|		free(info_blob);
  931|      2|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  932|      2|	}
  933|    125|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  934|    125|	offs = 2;
  935|       |
  936|       |	/* Label */
  937|    125|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (937:6): [True: 1, False: 124]
  ------------------
  938|      1|		free(info_blob);
  939|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'label'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  940|      1|	}
  941|    124|	label = info_blob + offs + 2;
  942|    124|	label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  943|    124|	if (offs + 2 + label_len > info_len) {
  ------------------
  |  Branch (943:6): [True: 12, False: 112]
  ------------------
  944|     12|		free(info_blob);
  945|     12|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'label' received");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  946|     12|	}
  947|    112|	if (label_len > sizeof(dobj.label) - 1)
  ------------------
  |  Branch (947:6): [True: 63, False: 49]
  ------------------
  948|     63|		label_len = sizeof(dobj.label) - 1;
  949|    112|	offs += 2 + *(info_blob + offs + 1);
  950|       |
  951|       |	/* Application */
  952|    112|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (952:6): [True: 1, False: 111]
  ------------------
  953|      1|		free(info_blob);
  954|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'application'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  955|      1|	}
  956|    111|	app = info_blob + offs + 2;
  957|    111|	app_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  958|    111|	if (offs + 2 + app_len > info_len) {
  ------------------
  |  Branch (958:6): [True: 7, False: 104]
  ------------------
  959|      7|		free(info_blob);
  960|      7|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'application' received");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  961|      7|	}
  962|    104|	if (app_len > sizeof(dinfo.app_label) - 1)
  ------------------
  |  Branch (962:6): [True: 27, False: 77]
  ------------------
  963|     27|		app_len = sizeof(dinfo.app_label) - 1;
  964|    104|	offs += 2 + app_len;
  965|       |
  966|       |	/* OID encode like DER(ASN.1(oid)) */
  967|    104|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (967:6): [True: 1, False: 103]
  ------------------
  968|      1|		free(info_blob);
  969|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'OID'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|      1|	}
  971|    103|	oid_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  972|    103|	if (offs + 2 + oid_len > info_len) {
  ------------------
  |  Branch (972:6): [True: 1, False: 102]
  ------------------
  973|      1|		free(info_blob);
  974|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'oid' received");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  975|      1|	}
  976|    102|	if (oid_len > 2) {
  ------------------
  |  Branch (976:6): [True: 10, False: 92]
  ------------------
  977|     10|		oid = info_blob + offs + 2;
  978|     10|		if (*oid != 0x06 || (*(oid + 1) != oid_len - 2)) {
  ------------------
  |  Branch (978:7): [True: 1, False: 9]
  |  Branch (978:23): [True: 8, False: 1]
  ------------------
  979|      9|			free(info_blob);
  980|      9|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: invalid 'OID' format");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|      9|		}
  982|      1|		oid += 2;
  983|      1|		oid_len -= 2;
  984|      1|	}
  985|       |
  986|     93|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   76|     18|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
              	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     75|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (986:45): [True: 18, False: 75]
  ------------------
  987|       |
  988|     93|	sc_format_path(ch_tmp, &dinfo.path);
  989|       |
  990|     93|	memcpy(dobj.label, label, label_len);
  991|     93|	memcpy(dinfo.app_label, app, app_len);
  992|     93|	if (oid_len)
  ------------------
  |  Branch (992:6): [True: 4, False: 89]
  ------------------
  993|      4|		sc_asn1_decode_object_id(oid, oid_len, &dinfo.app_oid);
  994|       |
  995|     93|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|     93|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (995:6): [True: 49, False: 44]
  ------------------
  996|     49|		dobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     49|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  997|       |
  998|     93|	if (private)   {
  ------------------
  |  Branch (998:6): [True: 18, False: 75]
  ------------------
  999|     18|		dobj.auth_id.len = sizeof(PinDomainID) > sizeof(dobj.auth_id.value)
  ------------------
  |  Branch (999:22): [Folded, False: 18]
  ------------------
 1000|     18|				? sizeof(dobj.auth_id.value) : sizeof(PinDomainID);
 1001|     18|		memcpy(dobj.auth_id.value, PinDomainID, dobj.auth_id.len);
 1002|       |
 1003|     18|		dobj.flags |= SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     18|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1004|     18|	}
 1005|       |
 1006|     93|	rv = sc_pkcs15emu_add_data_object(p15card, &dobj, &dinfo);
 1007|       |
 1008|     93|	free(info_blob);
 1009|     93|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|     93|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     93|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     93|	int _ret = r; \
  |  |  |  |  155|     93|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  157|     93|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     93|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     93|	return _ret; \
  |  |  |  |  163|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1010|     93|}
pkcs15-oberthur.c:sc_awp_clear:
 1207|  1.47k|{
 1208|  1.47k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  1.47k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.47k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1209|  1.47k|}
pkcs15-oberthur.c:sc_oberthur_parse_tokeninfo:
  365|    334|{
  366|    334|	struct sc_context *ctx = p15card->card->ctx;
  367|    334|	char label[0x21];
  368|    334|	unsigned flags;
  369|    334|	int ii;
  370|       |
  371|    334|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    334|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    334|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    334|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    334|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 334]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|    334|	if (!buff || len < 0x24)
  ------------------
  |  Branch (372:6): [True: 0, False: 334]
  |  Branch (372:15): [True: 14, False: 320]
  ------------------
  373|    334|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot parse token info");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|       |
  375|    320|	memset(label, 0, sizeof(label));
  376|       |
  377|    320|	memcpy(label, buff, 0x20);
  378|    320|	ii = 0x20;
  379|    395|	while (*(label + --ii)==' ' && ii)
  ------------------
  |  Branch (379:9): [True: 76, False: 319]
  |  Branch (379:33): [True: 75, False: 1]
  ------------------
  380|     75|		;
  381|    320|	*(label + ii + 1) = '\0';
  382|       |
  383|    320|	flags = *(buff + 0x22) * 0x100 + *(buff + 0x23);
  384|       |
  385|    320|	set_string(&p15card->tokeninfo->label, label);
  386|    320|	set_string(&p15card->tokeninfo->manufacturer_id, "Oberthur/OpenSC");
  387|       |
  388|    320|	if (flags & 0x01)
  ------------------
  |  Branch (388:6): [True: 1, False: 319]
  ------------------
  389|      1|		p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION;
  ------------------
  |  |  597|      1|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
  390|       |
  391|    320|	sc_log(ctx, "label %s", p15card->tokeninfo->label);
  ------------------
  |  |   71|    320|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  392|    320|	sc_log(ctx, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
  ------------------
  |  |   71|    320|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  393|       |
  394|    320|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    320|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    320|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    320|	int _ret = r; \
  |  |  |  |  155|    320|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 320, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    320|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 320]
  |  |  |  |  ------------------
  |  |  |  |  157|    320|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    320|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    320|	return _ret; \
  |  |  |  |  163|    320|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|    320|}
pkcs15-oberthur.c:sc_oberthur_parse_containers:
  401|    299|{
  402|    299|	struct sc_context *ctx = p15card->card->ctx;
  403|    299|	size_t offs;
  404|       |
  405|    299|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    299|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    299|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    299|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    299|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 299]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  406|       |
  407|    910|	while (Containers)   {
  ------------------
  |  Branch (407:9): [True: 611, False: 299]
  ------------------
  408|    611|		struct container *next = Containers->next;
  409|       |
  410|    611|		free (Containers);
  411|    611|		Containers = next;
  412|    611|	}
  413|       |
  414|    910|	for (offs=0; offs + 2 + 2+2+2 + 2+2+2 + 2+36 <= len;)  {
  ------------------
  |  Branch (414:15): [True: 618, False: 292]
  ------------------
  415|    618|		struct container *cont;
  416|    618|		unsigned char *ptr =  buff + offs + 2;
  417|       |
  418|    618|		sc_log(ctx, "parse contaniers offs:%zu, len:%zu", offs, len);
  ------------------
  |  |   71|    618|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  419|    618|		if (*(buff + offs) != 'R')
  ------------------
  |  Branch (419:7): [True: 7, False: 611]
  ------------------
  420|      7|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      7|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  421|       |
  422|    611|		cont = (struct container *)calloc(1, sizeof(struct container));
  423|    611|		if (!cont)
  ------------------
  |  Branch (423:7): [True: 0, False: 611]
  ------------------
  424|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  425|       |
  426|    611|		cont->exchange.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  427|    611|		cont->exchange.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  428|    611|		cont->exchange.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  429|       |
  430|    611|		cont->sign.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  431|    611|		cont->sign.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  432|    611|		cont->sign.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  433|       |
  434|    611|		memcpy(cont->uuid, ptr + 2, 36);
  435|    611|		sc_log(ctx, "UUID: %s; 0x%X, 0x%X, 0x%X", cont->uuid,
  ------------------
  |  |   71|    611|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  436|    611|				cont->exchange.id_pub, cont->exchange.id_prv, cont->exchange.id_cert);
  437|       |
  438|    611|		if (!Containers)  {
  ------------------
  |  Branch (438:7): [True: 13, False: 598]
  ------------------
  439|     13|			Containers = cont;
  440|     13|		}
  441|    598|		else   {
  442|    598|			cont->next = Containers;
  443|    598|			Containers->prev = (void *)cont;
  444|    598|			Containers = cont;
  445|    598|		}
  446|       |
  447|    611|		offs += *(buff + offs + 1) + 2;
  448|    611|	}
  449|       |
  450|    292|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    292|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    292|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    292|	int _ret = r; \
  |  |  |  |  155|    292|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 292, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    292|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 292]
  |  |  |  |  ------------------
  |  |  |  |  157|    292|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    292|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    292|	return _ret; \
  |  |  |  |  163|    292|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  451|    292|}
pkcs15-oberthur.c:sc_oberthur_parse_publicinfo:
  457|    275|{
  458|    275|	struct sc_context *ctx = p15card->card->ctx;
  459|    275|	size_t ii;
  460|    275|	int rv;
  461|       |
  462|    275|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    275|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    275|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    275|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    275|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 275]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|   107k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (463:13): [True: 107k, False: 92]
  ------------------
  464|   107k|		unsigned int file_id, size;
  465|       |
  466|   107k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (466:6): [True: 107k, False: 328]
  ------------------
  467|   107k|			continue;
  468|       |
  469|    328|		file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
  470|    328|		size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
  471|    328|		sc_log(ctx, "add public object(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   71|    328|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|       |
  473|    328|		switch (*(buff+ii + 1))   {
  474|    117|		case BASE_ID_PUB_RSA :
  ------------------
  |  |   81|    117|#define BASE_ID_PUB_RSA   0x10
  ------------------
  |  Branch (474:3): [True: 117, False: 211]
  ------------------
  475|    117|			rv = sc_pkcs15emu_oberthur_add_pubkey(p15card, file_id, size);
  476|    117|			LOG_TEST_RET(ctx, rv, "Cannot parse public key info");
  ------------------
  |  |  174|    117|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    117|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    117|	int _ret = (r); \
  |  |  |  |  168|    117|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 65, False: 52]
  |  |  |  |  ------------------
  |  |  |  |  169|     65|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     65|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     65|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     65|		return _ret; \
  |  |  |  |  172|     65|	} \
  |  |  |  |  173|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 52]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|     52|			break;
  478|     61|		case BASE_ID_CERT :
  ------------------
  |  |   82|     61|#define BASE_ID_CERT	  0x20
  ------------------
  |  Branch (478:3): [True: 61, False: 267]
  ------------------
  479|     61|			rv = sc_pkcs15emu_oberthur_add_cert(p15card, file_id);
  480|     61|			LOG_TEST_RET(ctx, rv, "Cannot parse certificate info");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|      0|			break;
  482|     18|		case BASE_ID_PUB_DES :
  ------------------
  |  |   87|     18|#define BASE_ID_PUB_DES   0x70
  ------------------
  |  Branch (482:3): [True: 18, False: 310]
  ------------------
  483|     18|			break;
  484|    126|		case BASE_ID_PUB_DATA :
  ------------------
  |  |   85|    126|#define BASE_ID_PUB_DATA  0x50
  ------------------
  |  Branch (484:3): [True: 126, False: 202]
  ------------------
  485|    126|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 0);
  486|    126|			LOG_TEST_RET(ctx, rv, "Cannot parse data info");
  ------------------
  |  |  174|    126|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    126|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    126|	int _ret = (r); \
  |  |  |  |  168|    126|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 51, False: 75]
  |  |  |  |  ------------------
  |  |  |  |  169|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     51|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     51|		return _ret; \
  |  |  |  |  172|     51|	} \
  |  |  |  |  173|    126|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 75]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  487|     75|			break;
  488|     75|		default:
  ------------------
  |  Branch (488:3): [True: 6, False: 322]
  ------------------
  489|      6|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Public object parse error");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|    328|		}
  491|    328|	}
  492|       |
  493|     92|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     92|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     92|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     92|	int _ret = r; \
  |  |  |  |  155|     92|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 92, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     92|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 92]
  |  |  |  |  ------------------
  |  |  |  |  157|     92|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     92|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     92|	return _ret; \
  |  |  |  |  163|     92|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|     92|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_pubkey:
  574|    117|{
  575|    117|	struct sc_context *ctx = p15card->card->ctx;
  576|    117|	struct sc_pkcs15_pubkey_info key_info;
  577|    117|	struct sc_pkcs15_object key_obj;
  578|    117|	char ch_tmp[0x100];
  579|    117|	unsigned char *info_blob = NULL;
  580|    117|	size_t len, info_len, offs;
  581|    117|	unsigned flags;
  582|    117|	int rv;
  583|       |
  584|    117|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    117|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    117|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    117|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    117|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 117]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|    117|	sc_log(ctx, "public key(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   71|    117|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  586|       |
  587|    117|	memset(&key_info, 0, sizeof(key_info));
  588|    117|	memset(&key_obj, 0, sizeof(key_obj));
  589|       |
  590|    117|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|    117|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  591|    117|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  592|    117|	LOG_TEST_RET(ctx, rv, "Failed to add public key: read oberthur file error");
  ------------------
  |  |  174|    117|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    117|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    117|	int _ret = (r); \
  |  |  |  |  168|    117|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  593|       |
  594|       |	/* Flags */
  595|    107|	offs = 2;
  596|    107|	if (offs > info_len) {
  ------------------
  |  Branch (596:6): [True: 2, False: 105]
  ------------------
  597|      2|		free(info_blob);
  598|      2|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'tag'");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  599|      2|	}
  600|    105|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  601|    105|	key_info.usage = sc_oberthur_decode_usage(flags);
  602|    105|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|    105|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (602:6): [True: 38, False: 67]
  ------------------
  603|     38|		key_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     38|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  604|    105|	sc_log(ctx, "Public key key-usage:%04X", key_info.usage);
  ------------------
  |  |   71|    105|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  605|       |
  606|       |	/* Label */
  607|    105|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (607:6): [True: 1, False: 104]
  ------------------
  608|      1|		free(info_blob);
  609|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'Label'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  610|      1|	}
  611|    104|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  612|    104|	if (offs + 2 + len > info_len) {
  ------------------
  |  Branch (612:6): [True: 7, False: 97]
  ------------------
  613|      7|		free(info_blob);
  614|      7|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'Label' length");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|     97|	} else if (len) {
  ------------------
  |  Branch (615:13): [True: 37, False: 60]
  ------------------
  616|     37|		if (len > sizeof(key_obj.label) - 1)
  ------------------
  |  Branch (616:7): [True: 24, False: 13]
  ------------------
  617|     24|			len = sizeof(key_obj.label) - 1;
  618|     37|		memcpy(key_obj.label, info_blob + offs + 2, len);
  619|     37|	}
  620|     97|	offs += 2 + len;
  621|       |
  622|       |	/* ID */
  623|     97|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (623:6): [True: 1, False: 96]
  ------------------
  624|      1|		free(info_blob);
  625|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'ID'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  626|      1|	}
  627|     96|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  628|     96|	if (len == 0
  ------------------
  |  Branch (628:6): [True: 25, False: 71]
  ------------------
  629|     71|			|| len > sizeof(key_info.id.value)
  ------------------
  |  Branch (629:7): [True: 15, False: 56]
  ------------------
  630|     56|			|| offs + 2 + len > info_len) {
  ------------------
  |  Branch (630:7): [True: 4, False: 52]
  ------------------
  631|     44|		free(info_blob);
  632|     44|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'ID' length");
  ------------------
  |  |  174|     44|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     44|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     44|	int _ret = (r); \
  |  |  |  |  168|     44|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 44, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     44|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     44|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     44|		return _ret; \
  |  |  |  |  172|     44|	} \
  |  |  |  |  173|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|     44|	}
  634|     52|	memcpy(key_info.id.value, info_blob + offs + 2, len);
  635|     52|	key_info.id.len = len;
  636|       |
  637|     52|	free(info_blob);
  638|       |
  639|       |	/* Ignore Start/End dates */
  640|       |
  641|     52|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     52|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  642|     52|	sc_format_path(ch_tmp, &key_info.path);
  643|       |
  644|     52|	key_info.native = 1;
  645|     52|	key_info.key_reference = file_id & 0xFF;
  646|     52|	key_info.modulus_length = size;
  647|       |
  648|     52|	rv = sc_pkcs15emu_add_rsa_pubkey(p15card, &key_obj, &key_info);
  649|       |
  650|     52|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     52|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     52|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     52|	int _ret = r; \
  |  |  |  |  155|     52|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 52, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     52|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 52]
  |  |  |  |  ------------------
  |  |  |  |  157|     52|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     52|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     52|	return _ret; \
  |  |  |  |  163|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|     52|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_cert:
  664|     61|{
  665|     61|	struct sc_context *ctx = p15card->card->ctx;
  666|     61|	struct sc_pkcs15_cert_info cinfo;
  667|     61|	struct sc_pkcs15_object cobj;
  668|     61|	unsigned char *info_blob = NULL, *cert_blob = NULL;
  669|     61|	size_t info_len, cert_len, len, offs;
  670|     61|	unsigned flags;
  671|     61|	int rv;
  672|     61|	char ch_tmp[0x20];
  673|       |
  674|     61|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  675|     61|	sc_log(ctx, "add certificate(file-id:%04X)", file_id);
  ------------------
  |  |   71|     61|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  676|       |
  677|     61|	memset(&cinfo, 0, sizeof(cinfo));
  678|     61|	memset(&cobj, 0, sizeof(cobj));
  679|       |
  680|     61|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|     61|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  681|     61|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  682|     61|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read oberthur file error");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  683|       |
  684|     57|	if (info_len < 2) {
  ------------------
  |  Branch (684:6): [True: 1, False: 56]
  ------------------
  685|      1|		free(info_blob);
  686|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|      1|	}
  688|     56|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  689|     56|	offs = 2;
  690|       |
  691|       |	/* Label */
  692|     56|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (692:6): [True: 1, False: 55]
  ------------------
  693|      1|		free(info_blob);
  694|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'CN'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  695|      1|	}
  696|     55|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  697|     55|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (697:6): [True: 12, False: 43]
  ------------------
  698|     12|		free(info_blob);
  699|     12|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'CN' length");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  700|     43|	} else if (len) {
  ------------------
  |  Branch (700:13): [True: 31, False: 12]
  ------------------
  701|     31|		if (len > sizeof(cobj.label) - 1)
  ------------------
  |  Branch (701:7): [True: 16, False: 15]
  ------------------
  702|     16|			len = sizeof(cobj.label) - 1;
  703|     31|		memcpy(cobj.label, info_blob + offs + 2, len);
  704|     31|	}
  705|     43|	offs += 2 + len;
  706|       |
  707|       |	/* ID */
  708|     43|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (708:6): [True: 1, False: 42]
  ------------------
  709|      1|		free(info_blob);
  710|      1|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'ID'");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  711|      1|	}
  712|     42|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  713|     42|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (713:6): [True: 8, False: 34]
  ------------------
  714|      8|		free(info_blob);
  715|      8|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'ID' length");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|     34|	} else if (len > sizeof(cinfo.id.value)) {
  ------------------
  |  Branch (716:13): [True: 9, False: 25]
  ------------------
  717|      9|		free(info_blob);
  718|      9|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add certificate: invalid 'ID' length");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  719|      9|	}
  720|     25|	memcpy(cinfo.id.value, info_blob + offs + 2, len);
  721|     25|	cinfo.id.len = len;
  722|       |
  723|     25|	free(info_blob);
  724|       |
  725|       |	/* Ignore subject, issuer and serial */
  726|       |
  727|     25|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     25|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  728|     25|	sc_format_path(ch_tmp, &cinfo.path);
  729|     25|	rv = sc_oberthur_read_file(p15card, ch_tmp, &cert_blob, &cert_len, 1);
  730|     25|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read certificate error");
  ------------------
  |  |  174|     25|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     25|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     25|	int _ret = (r); \
  |  |  |  |  168|     25|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 24, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     24|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     24|		return _ret; \
  |  |  |  |  172|     24|	} \
  |  |  |  |  173|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|      1|	cinfo.value.value = cert_blob;
  733|      1|	cinfo.value.len = cert_len;
  734|       |
  735|      1|	rv = sc_oberthur_get_certificate_authority(ctx, &cinfo.value, &cinfo.authority);
  736|      1|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (736:6): [True: 1, False: 0]
  ------------------
  737|      1|		free(cinfo.value.value);
  738|      1|		LOG_TEST_RET(ctx, rv, "Failed to add certificate: get certificate attributes error");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  739|      1|	}
  740|       |
  741|      0|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|      0|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (741:6): [True: 0, False: 0]
  ------------------
  742|      0|		cobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  743|       |
  744|      0|	rv = sc_pkcs15emu_add_x509_cert(p15card, &cobj, &cinfo);
  745|       |
  746|      0|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|      0|}
pkcs15-oberthur.c:sc_oberthur_get_certificate_authority:
  188|      1|{
  189|      1|#ifdef ENABLE_OPENSSL
  190|      1|	X509	*x;
  191|      1|	BUF_MEM buf_mem;
  192|      1|	BIO *bio = NULL;
  193|      1|	BASIC_CONSTRAINTS *bs = NULL;
  194|       |
  195|      1|	if (!der)
  ------------------
  |  Branch (195:6): [True: 0, False: 1]
  ------------------
  196|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  197|       |
  198|      1|	buf_mem.data = malloc(der->len);
  199|      1|	if (!buf_mem.data)
  ------------------
  |  Branch (199:6): [True: 0, False: 1]
  ------------------
  200|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  201|       |
  202|      1|	memcpy(buf_mem.data, der->value, der->len);
  203|      1|	buf_mem.max = buf_mem.length = der->len;
  204|       |
  205|      1|	bio = BIO_new(BIO_s_mem());
  206|      1|	if (!bio) {
  ------------------
  |  Branch (206:6): [True: 0, False: 1]
  ------------------
  207|      0|		free(buf_mem.data);
  208|      0|		sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  209|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  210|      0|	}
  211|       |
  212|      1|	BIO_set_mem_buf(bio, &buf_mem, BIO_NOCLOSE);
  213|      1|	x = d2i_X509_bio(bio, 0);
  214|      1|	free(buf_mem.data);
  215|      1|	BIO_free(bio);
  216|      1|	if (!x) {
  ------------------
  |  Branch (216:6): [True: 1, False: 0]
  ------------------
  217|      1|		sc_log_openssl(ctx);
  ------------------
  |  |   72|      1|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  218|      1|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  219|      1|	}
  220|       |
  221|      0|	bs = (BASIC_CONSTRAINTS *)X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL);
  222|      0|	if (out_authority)
  ------------------
  |  Branch (222:6): [True: 0, False: 0]
  ------------------
  223|      0|		*out_authority = (bs && bs->ca);
  ------------------
  |  Branch (223:21): [True: 0, False: 0]
  |  Branch (223:27): [True: 0, False: 0]
  ------------------
  224|       |
  225|      0|	X509_free(x);
  226|       |
  227|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  228|       |#else
  229|       |	return SC_ERROR_NOT_SUPPORTED;
  230|       |#endif
  231|      1|}
pkcs15-oberthur.c:sc_oberthur_read_file:
  238|  1.45k|{
  239|  1.45k|	struct sc_context *ctx = p15card->card->ctx;
  240|  1.45k|	struct sc_card *card = p15card->card;
  241|  1.45k|	struct sc_file *file = NULL;
  242|  1.45k|	struct sc_path path;
  243|  1.45k|	size_t sz;
  244|  1.45k|	int rv;
  245|       |
  246|  1.45k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  247|  1.45k|	if (!in_path || !out || !out_len)
  ------------------
  |  Branch (247:6): [True: 0, False: 1.45k]
  |  Branch (247:18): [True: 0, False: 1.45k]
  |  Branch (247:26): [True: 0, False: 1.45k]
  ------------------
  248|  1.45k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot read oberthur file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  249|       |
  250|  1.45k|	sc_log(ctx, "read file '%s'; verify_pin:%i", in_path, verify_pin);
  ------------------
  |  |   71|  1.45k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  251|       |
  252|  1.45k|	*out = NULL;
  253|  1.45k|	*out_len = 0;
  254|       |
  255|  1.45k|	sc_format_path(in_path, &path);
  256|  1.45k|	rv = sc_select_file(card, &path, &file);
  257|  1.45k|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  1.45k|#define SC_SUCCESS				0
  ------------------
  |  Branch (257:6): [True: 169, False: 1.28k]
  ------------------
  258|    169|		sc_file_free(file);
  259|    169|		LOG_TEST_RET(ctx, rv, "Cannot select oberthur file to read");
  ------------------
  |  |  174|    169|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    169|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    169|	int _ret = (r); \
  |  |  |  |  168|    169|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 169, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    169|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    169|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    169|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    169|		return _ret; \
  |  |  |  |  172|    169|	} \
  |  |  |  |  173|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|    169|	}
  261|       |
  262|  1.28k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)
  ------------------
  |  |  221|  1.28k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (262:6): [True: 898, False: 386]
  ------------------
  263|    898|		sz = file->size;
  264|    386|	else
  265|    386|		sz = (file->record_length + 2) * file->record_count;
  266|       |
  267|  1.28k|	*out = calloc(1, sz);
  268|  1.28k|	if (*out == NULL) {
  ------------------
  |  Branch (268:6): [True: 0, False: 1.28k]
  ------------------
  269|      0|		sc_file_free(file);
  270|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot read oberthur file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|      0|	}
  272|       |
  273|  1.28k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)   {
  ------------------
  |  |  221|  1.28k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (273:6): [True: 898, False: 386]
  ------------------
  274|    898|		rv = sc_read_binary(card, 0, *out, sz, 0);
  275|    898|	}
  276|    386|	else	{
  277|    386|		unsigned int rec;
  278|    386|		size_t offs = 0;
  279|    386|		size_t rec_len = file->record_length;
  280|       |
  281|  4.29k|		for (rec = 1; ; rec++)   {
  282|  4.29k|			if (rec > file->record_count) {
  ------------------
  |  Branch (282:8): [True: 348, False: 3.94k]
  ------------------
  283|    348|				rv = 0;
  284|    348|				break;
  285|    348|			}
  286|  3.94k|			rv = sc_read_record(card, rec, 0, *out + offs + 2, rec_len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  3.94k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  287|  3.94k|			if (rv == SC_ERROR_RECORD_NOT_FOUND)   {
  ------------------
  |  |   52|  3.94k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (287:8): [True: 1, False: 3.94k]
  ------------------
  288|      1|				rv = 0;
  289|      1|				break;
  290|      1|			}
  291|  3.94k|			else if (rv < 0)   {
  ------------------
  |  Branch (291:13): [True: 37, False: 3.90k]
  ------------------
  292|     37|				break;
  293|     37|			}
  294|       |
  295|  3.90k|			rec_len = rv;
  296|       |
  297|  3.90k|			*(*out + offs) = 'R';
  298|  3.90k|			*(*out + offs + 1) = rv;
  299|       |
  300|  3.90k|			offs += rv + 2;
  301|  3.90k|		}
  302|       |
  303|    386|		sz = offs;
  304|    386|	}
  305|       |
  306|  1.28k|	sc_log(ctx, "read oberthur file result %i", rv);
  ------------------
  |  |   71|  1.28k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  307|  1.28k|	if (verify_pin && rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)   {
  ------------------
  |  |   61|  1.28k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (307:6): [True: 1.28k, False: 0]
  |  Branch (307:20): [True: 3, False: 1.28k]
  ------------------
  308|      3|		struct sc_pkcs15_object *objs[0x10], *pin_obj = NULL;
  309|      3|		const struct sc_acl_entry *acl = sc_file_get_acl_entry(file, SC_AC_OP_READ);
  ------------------
  |  |  188|      3|#define SC_AC_OP_READ			22
  ------------------
  310|      3|		int ii, nobjs;
  311|       |
  312|      3|		if (acl == NULL) {
  ------------------
  |  Branch (312:7): [True: 1, False: 2]
  ------------------
  313|      1|			sc_file_free(file);
  314|      1|			free(*out);
  315|      1|			*out = NULL;
  316|      1|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|      1|		}
  318|       |
  319|      2|		nobjs = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 0x10);
  ------------------
  |  |  445|      2|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  320|      2|		if (nobjs < 1) {
  ------------------
  |  Branch (320:7): [True: 0, False: 2]
  ------------------
  321|      0|			sc_file_free(file);
  322|      0|			free(*out);
  323|      0|			*out = NULL;
  324|      0|			LOG_TEST_RET(ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|      0|				"Cannot read oberthur file: get AUTH objects error");
  326|      0|		}
  327|       |
  328|      3|		for (ii = 0; ii < nobjs; ii++) {
  ------------------
  |  Branch (328:16): [True: 2, False: 1]
  ------------------
  329|      2|			struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
  330|      2|			sc_log(ctx, "compare PIN/ACL refs:%i/%i, method:%i/%i",
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  331|      2|				auth_info->attrs.pin.reference, acl->key_ref, auth_info->auth_method, acl->method);
  332|      2|			if (auth_info->attrs.pin.reference == (int)acl->key_ref && auth_info->auth_method == (unsigned)acl->method)   {
  ------------------
  |  Branch (332:8): [True: 1, False: 1]
  |  Branch (332:63): [True: 1, False: 0]
  ------------------
  333|      1|				pin_obj = objs[ii];
  334|      1|				break;
  335|      1|			}
  336|      2|		}
  337|       |
  338|      2|		if (!pin_obj || !pin_obj->content.value)    {
  ------------------
  |  Branch (338:7): [True: 1, False: 1]
  |  Branch (338:19): [True: 1, False: 0]
  ------------------
  339|      2|			rv = SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      2|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  340|      2|		}
  341|      0|		else    {
  342|      0|			rv = sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  343|      0|			if (!rv)
  ------------------
  |  Branch (343:8): [True: 0, False: 0]
  ------------------
  344|      0|				rv = sc_oberthur_read_file(p15card, in_path, out, out_len, 0);
  345|      0|		}
  346|      2|	}
  347|       |
  348|  1.28k|	sc_file_free(file);
  349|       |
  350|  1.28k|	if (rv < 0)   {
  ------------------
  |  Branch (350:6): [True: 48, False: 1.23k]
  ------------------
  351|     48|		free(*out);
  352|     48|		*out = NULL;
  353|     48|		*out_len = 0;
  354|     48|	}
  355|       |
  356|  1.28k|	*out_len = sz;
  357|       |
  358|  1.28k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.28k|	int _ret = r; \
  |  |  |  |  155|  1.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 416, False: 867]
  |  |  |  |  ------------------
  |  |  |  |  156|    416|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     48|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 48, False: 368]
  |  |  |  |  ------------------
  |  |  |  |  157|    416|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    867|	} else { \
  |  |  |  |  159|    867|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    867|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    867|	} \
  |  |  |  |  162|  1.28k|	return _ret; \
  |  |  |  |  163|  1.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|  1.28k|}

sc_pkcs15emu_openpgp_init_ex:
  694|  11.7k|{
  695|  11.7k|	if (openpgp_detect_card(p15card))
  ------------------
  |  Branch (695:6): [True: 10.9k, False: 833]
  ------------------
  696|  10.9k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.9k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  697|    833|	return sc_pkcs15emu_openpgp_init(p15card);
  698|  11.7k|}
pkcs15-openpgp.c:openpgp_detect_card:
  682|  11.7k|{
  683|  11.7k|	if (p15card->card->type == SC_CARD_TYPE_OPENPGP_BASE
  ------------------
  |  Branch (683:6): [True: 792, False: 10.9k]
  ------------------
  684|  10.9k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V1
  ------------------
  |  Branch (684:7): [True: 2, False: 10.9k]
  ------------------
  685|  10.9k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
  ------------------
  |  Branch (685:7): [True: 2, False: 10.9k]
  ------------------
  686|  10.9k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_GNUK
  ------------------
  |  Branch (686:7): [True: 30, False: 10.9k]
  ------------------
  687|  10.9k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V3)
  ------------------
  |  Branch (687:7): [True: 7, False: 10.9k]
  ------------------
  688|    833|		return SC_SUCCESS;
  ------------------
  |  |   28|    833|#define SC_SUCCESS				0
  ------------------
  689|  10.9k|	else
  690|  10.9k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.9k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  691|  11.7k|}
pkcs15-openpgp.c:sc_pkcs15emu_openpgp_init:
  181|    833|{
  182|    833|	sc_card_t	*card = p15card->card;
  183|    833|	sc_context_t	*ctx = card->ctx;
  184|    833|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    833|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  185|    833|	char		string[256];
  186|    833|	u8		c4data[10];
  187|    833|	u8		c5data[100];
  188|    833|	int		r, i;
  189|    833|	const pgp_pin_cfg_t *pin_cfg = (card->type == SC_CARD_TYPE_OPENPGP_V1)
  ------------------
  |  Branch (189:33): [True: 2, False: 831]
  ------------------
  190|    833|	                               ? pin_cfg_v1 : pin_cfg_v2;
  191|    833|	sc_path_t path;
  192|    833|	sc_file_t *file = NULL;
  193|       |
  194|    833|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    833|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    833|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    833|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    833|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 833]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    833|	set_string(&p15card->tokeninfo->label, "OpenPGP card");
  197|    833|	set_string(&p15card->tokeninfo->manufacturer_id, "OpenPGP project");
  198|       |
  199|       |	/* card->serialnr = 2 byte manufacturer_id + 4 byte serial_number */
  200|    833|	if (card->serialnr.len > 0) {
  ------------------
  |  Branch (200:6): [True: 561, False: 272]
  ------------------
  201|    561|		unsigned short manuf_id = bebytes2ushort(card->serialnr.value);
  202|    561|		int j;
  203|       |
  204|    561|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, string, sizeof(string), 0);
  205|    561|		set_string(&p15card->tokeninfo->serial_number, string);
  206|       |
  207|  13.4k|		for (j = 0; manuf_map[j].name != NULL; j++) {
  ------------------
  |  Branch (207:15): [True: 13.0k, False: 470]
  ------------------
  208|  13.0k|			if (manuf_id == manuf_map[j].id) {
  ------------------
  |  Branch (208:8): [True: 91, False: 12.9k]
  ------------------
  209|     91|				set_string(&p15card->tokeninfo->manufacturer_id, manuf_map[j].name);
  210|     91|				break;
  211|     91|			}
  212|  13.0k|		}
  213|    561|	}
  214|       |
  215|    833|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
  ------------------
  |  |  597|    833|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
              	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
  ------------------
  |  |  598|    833|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  216|       |
  217|       |	/* Extract preferred language */
  218|    833|	r = read_file(card, "0065:5f2d", string, sizeof(string)-1);
  219|    833|	if (r < 0)
  ------------------
  |  Branch (219:6): [True: 612, False: 221]
  ------------------
  220|    612|		goto failed;
  221|    221|	string[r] = '\0';
  222|    221|	set_string(&p15card->tokeninfo->preferred_language, string);
  223|       |
  224|       |	/* Get CHV status bytes from DO 006E/0073/00C4:
  225|       |	 *  00:		1 == user consent for signature PIN
  226|       |	 *		(i.e. PIN still valid for next PSO:CDS command)
  227|       |	 *  01-03:	max length of pins 1-3
  228|       |	 *  04-07:	tries left for pins 1-3
  229|       |	 */
  230|    221|	sc_log(ctx, "Reading PW status bytes");
  ------------------
  |  |   71|    221|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|    221|	if ((r = read_file(card, "006E:0073:00C4", c4data, sizeof(c4data))) < 0)
  ------------------
  |  Branch (231:6): [True: 25, False: 196]
  ------------------
  232|     25|		goto failed;
  233|    196|	if (r != 7) {
  ------------------
  |  Branch (233:6): [True: 2, False: 194]
  ------------------
  234|      2|		sc_log(ctx, "CHV status bytes have unexpected length (expected 7, got %d)\n", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  235|      2|		r = SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      2|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
  236|      2|		goto failed;
  237|      2|	}
  238|       |
  239|       |	/* Add PIN codes */
  240|    776|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (240:14): [True: 582, False: 194]
  ------------------
  241|    582|		sc_pkcs15_auth_info_t pin_info;
  242|    582|		sc_pkcs15_object_t   pin_obj;
  243|       |
  244|    582|		memset(&pin_info, 0, sizeof(pin_info));
  245|    582|		memset(&pin_obj,  0, sizeof(pin_obj));
  246|       |
  247|    582|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    582|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  248|    582|		pin_info.auth_id.len      = 1;
  249|    582|		pin_info.auth_id.value[0] = pin_cfg[i].reference;
  250|    582|		pin_info.attrs.pin.reference     = pin_cfg[i].reference;
  251|    582|		pin_info.attrs.pin.flags         = pin_cfg[i].flags;
  252|    582|		pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_UTF8;
  ------------------
  |  |   90|    582|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  253|    582|		pin_info.attrs.pin.min_length    = pin_cfg[i].min_length;
  254|    582|		pin_info.attrs.pin.stored_length = c4data[1 + pin_cfg[i].do_index];
  255|    582|		pin_info.attrs.pin.max_length    = c4data[1 + pin_cfg[i].do_index];
  256|    582|		pin_info.attrs.pin.pad_char      = '\0';
  257|    582|		pin_info.tries_left = c4data[4 + pin_cfg[i].do_index];
  258|    582|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    582|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  259|       |
  260|    582|		sc_format_path("3F00", &pin_info.path);
  261|       |
  262|    582|		strlcpy(pin_obj.label, pin_cfg[i].label, sizeof(pin_obj.label));
  ------------------
  |  |   43|    582|#define strlcpy _strlcpy
  ------------------
  263|    582|		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    582|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    582|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  264|    582|		if (i < 2) {
  ------------------
  |  Branch (264:7): [True: 388, False: 194]
  ------------------
  265|    388|			pin_obj.auth_id.len = 1;
  266|    388|			pin_obj.auth_id.value[0] = 3;
  267|    388|		}
  268|       |
  269|    582|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  270|    582|		if (r < 0) {
  ------------------
  |  Branch (270:7): [True: 0, False: 582]
  ------------------
  271|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  272|      0|			goto failed;
  273|      0|		}
  274|    582|	}
  275|       |
  276|       |	/* Get private key finger prints from DO 006E/0073/00C5:
  277|       |	 *  00-19:	finger print for SIG key
  278|       |	 *  20-39:	finger print for ENC key
  279|       |	 *  40-59:	finger print for AUT key
  280|       |	 */
  281|    194|	sc_log(ctx, "Reading Fingerprints");
  ------------------
  |  |   71|    194|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  282|    194|	if ((r = read_file(card, "006E:0073:00C5", c5data, sizeof(c5data))) < 0)
  ------------------
  |  Branch (282:6): [True: 2, False: 192]
  ------------------
  283|      2|		goto failed;
  284|    192|	if (r < 60) {
  ------------------
  |  Branch (284:6): [True: 1, False: 191]
  ------------------
  285|      1|		sc_log(ctx,
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  286|      1|			"finger print bytes have unexpected length (expected 60, got %d)\n", r);
  287|      1|		r = SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      1|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
  288|      1|		goto failed;
  289|      1|	}
  290|       |
  291|    191|	sc_log(ctx, "Adding private keys");
  ------------------
  |  |   71|    191|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  292|       |	/* XXX: check if "halfkeys" can be stored with gpg2. If not, add key pairs in one loop */
  293|    630|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (293:14): [True: 536, False: 94]
  ------------------
  294|    536|		sc_pkcs15_prkey_info_t prkey_info;
  295|    536|		sc_pkcs15_object_t     prkey_obj;
  296|    536|		u8 cxdata[12];
  297|    536|		int cxdata_len = sizeof(cxdata);
  298|    536|		char path_template[] = "006E:0073:00Cx";
  299|    536|		int j;
  300|       |
  301|    536|		memset(&prkey_info, 0, sizeof(prkey_info));
  302|    536|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  303|    536|		memset(&cxdata, 0, sizeof(cxdata));
  304|       |
  305|    536|		path_template[13] = '1' + i; /* The needed tags are C1 C2 and C3 */
  306|    536|		if ((cxdata_len = read_file(card, path_template, cxdata, sizeof(cxdata))) < 1)
  ------------------
  |  Branch (306:7): [True: 93, False: 443]
  ------------------
  307|     93|			goto failed;
  308|       |
  309|       |		/* check validity using finger prints */
  310|  2.15k|		for (j = 19; j >= 0; j--) {
  ------------------
  |  Branch (310:16): [True: 2.12k, False: 30]
  ------------------
  311|  2.12k|			if (c5data[20 * i + j] != '\0')
  ------------------
  |  Branch (311:8): [True: 413, False: 1.71k]
  ------------------
  312|    413|				break;
  313|  2.12k|		}
  314|       |
  315|       |		/* only add valid keys, i.e. those with a legal algorithm identifier & finger print */
  316|    443|		if (j >= 0 && cxdata[0] != 0) {
  ------------------
  |  Branch (316:7): [True: 413, False: 30]
  |  Branch (316:17): [True: 383, False: 30]
  ------------------
  317|    383|			struct sc_object_id oid = {0};
  318|    383|			struct sc_algorithm_info * algorithm_info; /* no need to free */
  319|       |
  320|    383|			algorithm_info = NULL;
  321|    383|			prkey_info.id.len         = 1;
  322|    383|			prkey_info.id.value[0]    = i + 1;
  323|    383|			prkey_info.usage          = key_cfg[i].prkey_usage;
  324|    383|			prkey_info.native         = 1;
  325|    383|			prkey_info.key_reference  = i;
  326|       |
  327|    383|			strlcpy(prkey_obj.label, key_cfg[i].label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    383|#define strlcpy _strlcpy
  ------------------
  328|    383|			prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|    383|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              			prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|    383|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  329|    383|			prkey_obj.auth_id.len      = 1;
  330|    383|			prkey_obj.auth_id.value[0] = key_cfg[i].prkey_pin;
  331|       |
  332|       |			/* need to get size from algorithms using oid */
  333|    383|			if (cxdata[0] == SC_OPENPGP_KEYALGO_ECDH ||
  ------------------
  |  |  878|    766|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (333:8): [True: 61, False: 322]
  ------------------
  334|    322|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  879|    705|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (334:5): [True: 29, False: 293]
  ------------------
  335|    293|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  880|    293|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (335:5): [True: 54, False: 239]
  ------------------
  336|       |				/* Last byte could be Import-Format of private key, let's ignore it,
  337|       |				 * as it is not part of OID */
  338|    144|				if (cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STD ||
  ------------------
  |  |  887|    288|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (338:9): [True: 66, False: 78]
  ------------------
  339|     78|				    cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB)
  ------------------
  |  |  888|     78|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (339:9): [True: 13, False: 65]
  ------------------
  340|     79|					cxdata_len--;
  341|    144|				r = sc_asn1_decode_object_id(&cxdata[1], cxdata_len-1, &oid);
  342|    144|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    144|#define SC_SUCCESS				0
  ------------------
  |  Branch (342:9): [True: 74, False: 70]
  ------------------
  343|     74|					sc_log(ctx, "Failed to parse OID for elliptic curve algorithm");
  ------------------
  |  |   71|     74|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  344|     74|				}
  345|    144|			}
  346|       |
  347|    383|			switch (cxdata[0]) {
  ------------------
  |  Branch (347:12): [True: 144, False: 239]
  ------------------
  348|     61|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|     61|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (348:4): [True: 61, False: 322]
  ------------------
  349|     61|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (349:9): [True: 0, False: 61]
  ------------------
  350|      0|					if ((algorithm_info = sc_card_find_xeddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (350:10): [True: 0, False: 0]
  ------------------
  351|      0|						prkey_info.field_length = algorithm_info->key_length;
  352|      0|					else {
  353|      0|						sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  354|      0|						continue;
  355|      0|					}
  356|      0|					break;
  357|      0|				}
  358|       |				/* Fall through */
  359|     90|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|     90|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (359:4): [True: 29, False: 354]
  ------------------
  360|     90|				if((algorithm_info = sc_card_find_ec_alg(card, 0, &oid)))
  ------------------
  |  Branch (360:8): [True: 5, False: 85]
  ------------------
  361|      5|					prkey_info.field_length = algorithm_info->key_length;
  362|     85|				else {
  363|     85|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|     85|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  364|     85|					continue;
  365|     85|				}
  366|      5|				break;
  367|     54|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|     54|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (367:4): [True: 54, False: 329]
  ------------------
  368|     54|				if ((algorithm_info = sc_card_find_eddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (368:9): [True: 4, False: 50]
  ------------------
  369|      4|					prkey_info.field_length = algorithm_info->key_length;
  370|     50|				else {
  371|     50|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|     50|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  372|     50|					continue;
  373|     50|				}
  374|      4|				break;
  375|    383|			}
  376|       |
  377|    248|			switch (cxdata[0]) {
  378|      4|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|      4|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (378:4): [True: 4, False: 244]
  ------------------
  379|       |				/* Filter out invalid usage: EdDSA does not support anything but sign */
  380|      4|				prkey_info.usage &= PGP_SIG_PRKEY_USAGE;
  ------------------
  |  |   78|      4|#define PGP_SIG_PRKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_SIGN \
  |  |  ------------------
  |  |  |  |  307|      4|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  |  |   79|      4|				| SC_PKCS15_PRKEY_USAGE_SIGNRECOVER \
  |  |  ------------------
  |  |  |  |  308|      4|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  |  |  ------------------
  |  |   80|      4|				| SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)
  |  |  ------------------
  |  |  |  |  314|      4|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  381|      4|				r = sc_pkcs15emu_add_eddsa_prkey(p15card, &prkey_obj, &prkey_info);
  382|      4|				break;
  383|       |
  384|      2|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|      2|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (384:4): [True: 2, False: 246]
  ------------------
  385|       |				/* This can result in either ECDSA key or EC_MONTGOMERY
  386|       |				 * so we need to check OID */
  387|      2|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (387:9): [True: 0, False: 2]
  ------------------
  388|       |					/* This can do only DERIVE */
  389|      0|					prkey_info.usage = SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  390|      0|					r = sc_pkcs15emu_add_xeddsa_prkey(p15card, &prkey_obj, &prkey_info);
  391|      0|					break;
  392|      0|				}
  393|      2|				prkey_info.usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      2|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  394|      2|				prkey_info.usage &= ~PGP_ENC_PRKEY_USAGE;
  ------------------
  |  |   81|      2|#define	PGP_ENC_PRKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_DECRYPT \
  |  |  ------------------
  |  |  |  |  306|      2|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   82|      2|				| SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|      2|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  395|      2|				r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
  396|      2|				break;
  397|       |
  398|      3|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|      3|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (398:4): [True: 3, False: 245]
  ------------------
  399|      3|				prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      3|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  400|      3|				r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
  401|      3|				break;
  402|       |
  403|    101|			case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    101|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (403:4): [True: 101, False: 147]
  ------------------
  404|    101|				if (cxdata_len >= 3) {
  ------------------
  |  Branch (404:9): [True: 84, False: 17]
  ------------------
  405|       |					/* with Authentication key, can only decrypt if can change MSE */
  406|     84|					if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
  ------------------
  |  Branch (406:10): [True: 4, False: 80]
  |  Branch (406:20): [True: 4, False: 0]
  ------------------
  407|      4|						prkey_info.usage &= ~PGP_ENC_PRKEY_USAGE;
  ------------------
  |  |   81|      4|#define	PGP_ENC_PRKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_DECRYPT \
  |  |  ------------------
  |  |  |  |  306|      4|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   82|      4|				| SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|      4|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  408|      4|					}
  409|     84|					prkey_info.modulus_length = bebytes2ushort(cxdata + 1);
  410|     84|					r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  411|     84|					break;
  412|     84|				}
  413|       |				/* Fallthrough */
  414|    155|			default:
  ------------------
  |  Branch (414:4): [True: 138, False: 110]
  ------------------
  415|    155|				sc_log(ctx, "Invalid algorithm identifier %x (length = %d)",
  ------------------
  |  |   71|    155|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  416|    248|					cxdata[0], r);
  417|    248|			}
  418|       |
  419|    248|			if (r < 0) {
  ------------------
  |  Branch (419:8): [True: 4, False: 244]
  ------------------
  420|      4|				r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
  421|      4|				goto failed;
  422|      4|			}
  423|    248|		}
  424|    443|	}
  425|       |
  426|     94|	sc_log(ctx, "Adding public keys");
  ------------------
  |  |   71|     94|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  427|       |	/* Add public keys */
  428|    367|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (428:14): [True: 276, False: 91]
  ------------------
  429|    276|		sc_pkcs15_pubkey_info_t pubkey_info;
  430|    276|		sc_pkcs15_object_t      pubkey_obj;
  431|    276|		u8 cxdata[12];
  432|    276|		int cxdata_len = sizeof(cxdata);
  433|    276|		char path_template[] = "006E:0073:00Cx";
  434|    276|		int j;
  435|       |
  436|    276|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  437|    276|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  438|    276|		memset(&cxdata, 0, sizeof(cxdata));
  439|       |
  440|    276|		path_template[13] = '1' + i; /* The needed tags are C1 C2 and C3 */
  441|    276|		if ((cxdata_len = read_file(card, path_template, cxdata, sizeof(cxdata))) < 1)
  ------------------
  |  Branch (441:7): [True: 0, False: 276]
  ------------------
  442|      0|			goto failed;
  443|       |
  444|       |		/* check validity using finger prints */
  445|  1.03k|		for (j = 19; j >= 0; j--) {
  ------------------
  |  Branch (445:16): [True: 1.02k, False: 9]
  ------------------
  446|  1.02k|			if (c5data[20 * i + j] != '\0')
  ------------------
  |  Branch (446:8): [True: 267, False: 758]
  ------------------
  447|    267|				break;
  448|  1.02k|		}
  449|       |
  450|       |		/* only add valid keys, i.e. those with a legal algorithm identifier & finger print */
  451|    276|		if (j >= 0 && cxdata[0] != 0) {
  ------------------
  |  Branch (451:7): [True: 267, False: 9]
  |  Branch (451:17): [True: 238, False: 29]
  ------------------
  452|    238|			struct sc_object_id oid;
  453|    238|			struct sc_algorithm_info * algorithm_info; /* no need to free */
  454|       |
  455|    238|			algorithm_info = NULL;
  456|    238|			pubkey_info.id.len         = 1;
  457|    238|			pubkey_info.id.value[0]    = i + 1;
  458|    238|			pubkey_info.usage          = key_cfg[i].pubkey_usage;
  459|    238|			sc_format_path(key_cfg[i].pubkey_path, &pubkey_info.path);
  460|       |
  461|    238|			strlcpy(pubkey_obj.label, key_cfg[i].label, sizeof(pubkey_obj.label));
  ------------------
  |  |   43|    238|#define strlcpy _strlcpy
  ------------------
  462|    238|			pubkey_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|    238|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  463|       |
  464|    238|			if (cxdata[0] == SC_OPENPGP_KEYALGO_ECDH ||
  ------------------
  |  |  878|    476|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (464:8): [True: 47, False: 191]
  ------------------
  465|    191|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  879|    429|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (465:5): [True: 21, False: 170]
  ------------------
  466|    170|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  880|    170|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (466:5): [True: 45, False: 125]
  ------------------
  467|       |				/* Last byte could be Import-Format of private key, let's ignore it,
  468|       |				 * as it is not part of OID */
  469|    113|				if (cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STD ||
  ------------------
  |  |  887|    226|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (469:9): [True: 54, False: 59]
  ------------------
  470|     59|				    cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB)
  ------------------
  |  |  888|     59|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (470:9): [True: 10, False: 49]
  ------------------
  471|     64|					cxdata_len--;
  472|    113|				r = sc_asn1_decode_object_id(&cxdata[1], cxdata_len-1, &oid);
  473|    113|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    113|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:9): [True: 54, False: 59]
  ------------------
  474|     54|					sc_log(ctx, "Failed to parse OID for elliptic curve algorithm");
  ------------------
  |  |   71|     54|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  475|     54|				}
  476|    113|			}
  477|       |
  478|    238|			switch (cxdata[0]) {
  ------------------
  |  Branch (478:12): [True: 113, False: 125]
  ------------------
  479|     47|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|     47|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (479:4): [True: 47, False: 191]
  ------------------
  480|     47|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (480:9): [True: 0, False: 47]
  ------------------
  481|      0|					if ((algorithm_info = sc_card_find_xeddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (481:10): [True: 0, False: 0]
  ------------------
  482|      0|						pubkey_info.field_length = algorithm_info->key_length;
  483|      0|					else {
  484|      0|						sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  485|      0|						continue;
  486|      0|					}
  487|      0|					break;
  488|      0|				}
  489|       |				/* Fall through */
  490|     68|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|     68|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (490:4): [True: 21, False: 217]
  ------------------
  491|     68|				if((algorithm_info = sc_card_find_ec_alg(card, 0, &oid)))
  ------------------
  |  Branch (491:8): [True: 8, False: 60]
  ------------------
  492|      8|					pubkey_info.field_length = algorithm_info->key_length;
  493|     60|				else {
  494|     60|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|     60|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  495|     60|					continue;
  496|     60|				}
  497|      8|				break;
  498|     45|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|     45|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (498:4): [True: 45, False: 193]
  ------------------
  499|     45|				if ((algorithm_info = sc_card_find_eddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (499:9): [True: 3, False: 42]
  ------------------
  500|      3|					pubkey_info.field_length = algorithm_info->key_length;
  501|     42|				else {
  502|     42|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|     42|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|     42|					continue;
  504|     42|				}
  505|      3|				break;
  506|    238|			}
  507|       |
  508|    136|			switch (cxdata[0]) {
  509|      3|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|      3|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (509:4): [True: 3, False: 133]
  ------------------
  510|       |				/* assuming Ed25519 as it is the only supported now */
  511|       |				/* Filter out invalid usage: ED does not support anything but sign */
  512|      3|				pubkey_info.usage &= PGP_SIG_PUBKEY_USAGE;
  ------------------
  |  |   85|      3|#define	PGP_SIG_PUBKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_VERIFY \
  |  |  ------------------
  |  |  |  |  311|      3|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  |  |  ------------------
  |  |   86|      3|				| SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER)
  |  |  ------------------
  |  |  |  |  312|      3|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  |  |  ------------------
  ------------------
  513|      3|				r = sc_pkcs15emu_add_eddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  514|      3|				break;
  515|      4|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|      4|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (515:4): [True: 4, False: 132]
  ------------------
  516|       |				/* This can result in either ECDSA key or EC_MONTGOMERY
  517|       |				 * so we need to check OID */
  518|      4|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (518:9): [True: 0, False: 4]
  ------------------
  519|       |					/* XXX What can this key do? */
  520|      0|					pubkey_info.usage = SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  521|      0|					r = sc_pkcs15emu_add_xeddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  522|      0|					break;
  523|      0|				}
  524|      4|				pubkey_info.usage = SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      4|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  525|      4|				r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
  526|      4|				break;
  527|      4|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|      4|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (527:4): [True: 4, False: 132]
  ------------------
  528|      4|				pubkey_info.usage = PGP_SIG_PUBKEY_USAGE;
  ------------------
  |  |   85|      4|#define	PGP_SIG_PUBKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_VERIFY \
  |  |  ------------------
  |  |  |  |  311|      4|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  |  |  ------------------
  |  |   86|      4|				| SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER)
  |  |  ------------------
  |  |  |  |  312|      4|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  |  |  ------------------
  ------------------
  529|      4|				r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
  530|      4|				break;
  531|     23|			case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|     23|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (531:4): [True: 23, False: 113]
  ------------------
  532|     23|				if (cxdata_len >= 3) {
  ------------------
  |  Branch (532:9): [True: 9, False: 14]
  ------------------
  533|       |					/* with Authentication pubkey, can only encrypt if can change MSE */
  534|      9|					if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
  ------------------
  |  Branch (534:10): [True: 4, False: 5]
  |  Branch (534:20): [True: 4, False: 0]
  ------------------
  535|      4|						pubkey_info.usage &= ~PGP_ENC_PUBKEY_USAGE;
  ------------------
  |  |   87|      4|#define	PGP_ENC_PUBKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_ENCRYPT \
  |  |  ------------------
  |  |  |  |  305|      4|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   88|      4|				| SC_PKCS15_PRKEY_USAGE_WRAP)
  |  |  ------------------
  |  |  |  |  309|      4|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  ------------------
  536|      4|					}
  537|      9|					pubkey_info.modulus_length = bebytes2ushort(cxdata + 1);
  538|      9|					r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  539|      9|					break;
  540|      9|				}
  541|       |				/* Fall through */
  542|    116|			default:
  ------------------
  |  Branch (542:4): [True: 102, False: 34]
  ------------------
  543|    116|				sc_log(ctx, "Invalid algorithm identifier %x (length = %d)",
  ------------------
  |  |   71|    116|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  544|    136|					cxdata[0], r);
  545|    136|			}
  546|       |
  547|    136|			if (r < 0) {
  ------------------
  |  Branch (547:8): [True: 3, False: 133]
  ------------------
  548|      3|				r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
  549|      3|				goto failed;
  550|      3|			}
  551|    136|		}
  552|    276|	}
  553|       |
  554|       |	/* Check if certificate DO 7F21 holds data */
  555|     91|	sc_format_path("7F21", &path);
  556|     91|	r = sc_select_file(card, &path, &file);
  557|     91|	if (r < 0)
  ------------------
  |  Branch (557:6): [True: 28, False: 63]
  ------------------
  558|     28|		goto failed;
  559|       |
  560|    116|	for(u8 i=0; i<PGP_MAX_NUM_CERTS; i++) {
  ------------------
  |  |   47|    116|#define PGP_MAX_NUM_CERTS    3
  ------------------
  |  Branch (560:14): [True: 106, False: 10]
  ------------------
  561|    106|		struct sc_pkcs15_cert_info cert_info;
  562|    106|		struct sc_pkcs15_object    cert_obj;
  563|    106|		u8* buffer = malloc(MAX_OPENPGP_DO_SIZE);
  ------------------
  |  |  172|    106|#define	MAX_OPENPGP_DO_SIZE	8192
  ------------------
  564|    106|		int resp_len = 0;
  565|       |
  566|    106|		if (buffer == NULL)
  ------------------
  |  Branch (566:7): [True: 0, False: 106]
  ------------------
  567|      0|			goto failed;
  568|       |
  569|    106|		memset(&cert_info, 0, sizeof(cert_info));
  570|    106|		memset(&cert_obj,  0, sizeof(cert_obj));
  571|       |
  572|       |		/* try to SELECT DATA. Will only work for OpenPGP >= v3, errors are non-critical */
  573|    106|		sc_card_ctl(card, SC_CARDCTL_OPENPGP_SELECT_DATA, &i);
  574|       |
  575|    106|		sc_format_path(certs[i].path, &cert_info.path);
  576|       |
  577|       |		/* Certificate ID. We use the same ID as the authentication key */
  578|    106|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  579|       |
  580|    106|		resp_len = sc_get_data(card, 0x7F21, buffer, MAX_OPENPGP_DO_SIZE);
  ------------------
  |  |  172|    106|#define	MAX_OPENPGP_DO_SIZE	8192
  ------------------
  581|       |
  582|       |		/* Response length => free buffer and continue with next id */
  583|    106|		if (resp_len == 0) {
  ------------------
  |  Branch (583:7): [True: 23, False: 83]
  ------------------
  584|     23|			free(buffer);
  585|     23|			continue;
  586|     23|		}
  587|       |
  588|       |		/* Catch error during sc_get_data */
  589|     83|		if (resp_len < 0) {
  ------------------
  |  Branch (589:7): [True: 37, False: 46]
  ------------------
  590|     37|			free(buffer);
  591|     37|			goto failed;
  592|     37|		}
  593|       |
  594|       |		/* Assemble certificate info struct, based on `certs` array */
  595|     46|		cert_info.value.len = resp_len;
  596|     46|		cert_info.value.value = buffer;
  597|     46|		cert_info.authority = certs[i].authority;
  598|     46|		cert_obj.flags = certs[i].obj_flags;
  599|       |
  600|       |		/* Object label */
  601|     46|		strlcpy(cert_obj.label, certs[i].label, sizeof(cert_obj.label));
  ------------------
  |  |   43|     46|#define strlcpy _strlcpy
  ------------------
  602|       |
  603|     46|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  604|     46|		if (r < 0) {
  ------------------
  |  Branch (604:7): [True: 0, False: 46]
  ------------------
  605|      0|			free(buffer);
  606|      0|			goto failed;
  607|      0|		}
  608|       |
  609|       |		/* only iterate, for OpenPGP >= v3, thus break on < v3 */
  610|     46|		if (card->type < SC_CARD_TYPE_OPENPGP_V3)
  ------------------
  |  Branch (610:7): [True: 16, False: 30]
  ------------------
  611|     16|			break;
  612|     46|	}
  613|       |
  614|       |	/* Add PKCS#15 DATA objects from other OpenPGP card DOs. The return
  615|       |	 * value is ignored, so this will not cause initialization to fail.
  616|       |	 */
  617|     26|	sc_pkcs15emu_openpgp_add_data(p15card);
  618|       |
  619|    833|failed:
  620|    833|	if (r < 0) {
  ------------------
  |  Branch (620:6): [True: 685, False: 148]
  ------------------
  621|    685|		sc_log(card->ctx,
  ------------------
  |  |   71|    685|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  622|    685|				"Failed to initialize OpenPGP emulation: %s\n",
  623|    685|				sc_strerror(r));
  624|    685|		sc_pkcs15_card_clear(p15card);
  625|    685|	}
  626|    833|	sc_file_free(file);
  627|    833|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    833|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    833|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    833|	int _ret = r; \
  |  |  |  |  155|    833|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 828, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  156|    828|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    685|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 685, False: 143]
  |  |  |  |  ------------------
  |  |  |  |  157|    828|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    828|	} else { \
  |  |  |  |  159|      5|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      5|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      5|	} \
  |  |  |  |  162|    833|	return _ret; \
  |  |  |  |  163|    833|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  628|    833|}
pkcs15-openpgp.c:read_file:
  162|  2.16k|{
  163|  2.16k|	sc_path_t	path;
  164|  2.16k|	sc_file_t	*file;
  165|  2.16k|	int		r;
  166|       |
  167|  2.16k|	sc_format_path(path_name, &path);
  168|  2.16k|	if ((r = sc_select_file(card, &path, &file)) < 0)
  ------------------
  |  Branch (168:6): [True: 730, False: 1.43k]
  ------------------
  169|    730|		return r;
  170|       |
  171|  1.43k|	if (file->size < len)
  ------------------
  |  Branch (171:6): [True: 1.36k, False: 70]
  ------------------
  172|  1.36k|		len = file->size;
  173|       |
  174|  1.43k|	sc_file_free(file);
  175|       |
  176|  1.43k|	return sc_read_binary(card, 0, (u8 *) buf, len, 0);
  177|  2.16k|}
pkcs15-openpgp.c:sc_pkcs15emu_openpgp_add_data:
  635|     26|{
  636|     26|	sc_context_t *ctx = p15card->card->ctx;
  637|     26|	int i, r;
  638|       |
  639|     26|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     26|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     26|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     26|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     26|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |	/* Optional private use DOs 0101 to 0104 */
  641|    130|	for (i = 1; i <= PGP_NUM_PRIVDO; i++) {
  ------------------
  |  |   46|    130|#define PGP_NUM_PRIVDO       4
  ------------------
  |  Branch (641:14): [True: 104, False: 26]
  ------------------
  642|    104|		sc_pkcs15_data_info_t dat_info;
  643|    104|		sc_pkcs15_object_t dat_obj;
  644|    104|		char name[6 + LEN_MAX_INT_AS_STR];
  645|    104|		char path[7 + LEN_MAX_INT_AS_STR];
  646|    104|		u8 content[254];
  647|    104|		memset(&dat_info, 0, sizeof(dat_info));
  648|    104|		memset(&dat_obj, 0, sizeof(dat_obj));
  649|       |
  650|    104|		snprintf(name, 8, "PrivDO%d", i);
  651|    104|		snprintf(path, 9, "3F00010%d", i);
  652|       |
  653|       |		/* Check if the DO can be read and is not empty. Otherwise we
  654|       |		 * won't expose a PKCS#15 DATA object.
  655|       |		 */
  656|    104|		r = read_file(p15card->card, path, content, sizeof(content));
  657|    104|		if (r <= 0 ) {
  ------------------
  |  Branch (657:7): [True: 76, False: 28]
  ------------------
  658|     76|			sc_log(ctx, "Cannot read DO 010%d or there is no data in it", i);
  ------------------
  |  |   71|     76|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  659|       |			/* Skip */
  660|     76|			continue;
  661|     76|		}
  662|     28|		sc_format_path(path, &dat_info.path);
  663|     28|		strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
  ------------------
  |  |   43|     28|#define strlcpy _strlcpy
  ------------------
  664|     28|		strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
  ------------------
  |  |   43|     28|#define strlcpy _strlcpy
  ------------------
  665|       |
  666|       |		/* Add DATA object to slot protected by PIN2 (PW1 with Ref 0x82) */
  667|     28|		dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|     28|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              		dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     28|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  668|     28|		dat_obj.auth_id.len = 1;
  669|     28|		if (i == 1 || i == 3)
  ------------------
  |  Branch (669:7): [True: 12, False: 16]
  |  Branch (669:17): [True: 4, False: 12]
  ------------------
  670|     16|			dat_obj.auth_id.value[0] = 2;
  671|     12|		else
  672|     12|			dat_obj.auth_id.value[0] = 3;
  673|       |
  674|     28|		sc_log(ctx, "Add %s data object", name);
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  675|     28|		r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
  676|     28|		LOG_TEST_RET(ctx, r, "Could not add data object to framework");
  ------------------
  |  |  174|     28|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     28|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     28|	int _ret = (r); \
  |  |  |  |  168|     28|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|     28|	}
  678|     26|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     26|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     26|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     26|	int _ret = r; \
  |  |  |  |  155|     26|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  157|     26|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     26|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  679|     26|}

sc_pkcs15_decode_aodf_entry:
   85|    229|{
   86|    229|	sc_context_t *ctx = p15card->card->ctx;
   87|    229|	struct sc_pkcs15_auth_info info;
   88|    229|	int r;
   89|    229|	size_t flags_len = sizeof(info.attrs.pin.flags);
   90|    229|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   91|    229|	size_t padchar_len = 1;
   92|    229|	struct sc_asn1_entry asn1_com_ao_attr[2];
   93|    229|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   94|    229|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   95|    229|	struct sc_asn1_entry asn1_auth_type[2];
   96|    229|	struct sc_asn1_entry asn1_auth_type_choice[4];
   97|    229|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   98|    229|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
   99|       |
  100|    229|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|    229|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    229|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    229|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 229]
  |  |  ------------------
  ------------------
  101|       |
  102|    229|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  103|    229|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  104|       |
  105|    229|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  106|       |
  107|    229|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  108|    229|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  109|       |
  110|    229|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  111|    229|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  112|       |
  113|    229|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  114|    229|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  115|    229|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  116|       |
  117|       |	/* pinAttributes */
  118|    229|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  119|    229|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  120|    229|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  121|    229|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  122|    229|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  123|    229|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  124|    229|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  125|    229|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  126|       |
  127|       |	/* authKeyAttributes */
  128|    229|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  129|    229|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  130|    229|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  131|       |
  132|       |	/* We don't support lastPinChange yet. */
  133|    229|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  134|       |
  135|    229|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  136|       |
  137|       |	/* Fill in defaults */
  138|    229|	memset(&info, 0, sizeof(info));
  139|    229|	info.tries_left = -1;
  140|    229|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    229|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  141|       |
  142|    229|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  143|    229|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    229|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (143:6): [True: 14, False: 215]
  ------------------
  144|     14|		return r;
  145|    215|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|    215|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    215|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    215|	int _ret = (r); \
  |  |  |  |  168|    215|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 92, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  169|     92|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     92|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     92|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     92|		return _ret; \
  |  |  |  |  172|     92|	} \
  |  |  |  |  173|    215|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|       |
  147|    123|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    123|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (147:6): [True: 121, False: 2]
  ------------------
  148|    121|		sc_log(ctx, "AuthType: PIN");
  ------------------
  |  |   71|    121|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  149|    121|		obj->type = SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|    121|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  150|    121|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    121|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  151|    121|		info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|    121|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  152|       |
  153|    121|		if (info.attrs.pin.max_length == 0) {
  ------------------
  |  Branch (153:7): [True: 99, False: 22]
  ------------------
  154|     99|			if (p15card->card->max_pin_len != 0)
  ------------------
  |  Branch (154:8): [True: 0, False: 99]
  ------------------
  155|      0|				info.attrs.pin.max_length = p15card->card->max_pin_len;
  156|     99|			else if (info.attrs.pin.stored_length != 0)
  ------------------
  |  Branch (156:13): [True: 93, False: 6]
  ------------------
  157|     93|				info.attrs.pin.max_length = info.attrs.pin.type != SC_PKCS15_PIN_TYPE_BCD ?
  ------------------
  |  |   88|     93|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (157:33): [True: 87, False: 6]
  ------------------
  158|     87|					info.attrs.pin.stored_length : 2 * info.attrs.pin.stored_length;
  159|      6|			else
  160|      6|				info.attrs.pin.max_length = 8; /* shouldn't happen */
  161|     99|		}
  162|       |
  163|       |		/* OpenSC 0.11.4 and older encoded "pinReference" as a negative
  164|       |		   value. Fixed in 0.11.5 we need to add a hack, so old cards
  165|       |		   continue to work.
  166|       |		   The same invalid encoding has some models of the proprietary PKCS#15 cards.
  167|       |		*/
  168|    121|		if (info.attrs.pin.reference < 0)
  ------------------
  |  Branch (168:7): [True: 1, False: 120]
  ------------------
  169|      1|			info.attrs.pin.reference += 256;
  170|       |
  171|    121|		if (info.attrs.pin.flags & SC_PKCS15_PIN_FLAG_LOCAL)   {
  ------------------
  |  |   55|    121|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  |  Branch (171:7): [True: 106, False: 15]
  ------------------
  172|       |			/* In OpenSC pkcs#15 framework 'path' is mandatory for the 'Local' PINs.
  173|       |			 * If 'path' do not present in PinAttributes, derive it from the PKCS#15 context. */
  174|    106|			if (!info.path.len)   {
  ------------------
  |  Branch (174:8): [True: 105, False: 1]
  ------------------
  175|       |				/* Give priority to AID defined in the application DDO */
  176|    105|				if (p15card->app && p15card->app->ddo.aid.len)
  ------------------
  |  Branch (176:9): [True: 0, False: 105]
  |  Branch (176:25): [True: 0, False: 0]
  ------------------
  177|      0|					info.path.aid = p15card->app->ddo.aid;
  178|    105|				else if (p15card->file_app && p15card->file_app->path.len)
  ------------------
  |  Branch (178:14): [True: 105, False: 0]
  |  Branch (178:35): [True: 105, False: 0]
  ------------------
  179|    105|					info.path = p15card->file_app->path;
  180|      0|				else
  181|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  182|    105|			}
  183|    106|		}
  184|    121|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
  ------------------
  |  |   70|    121|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  185|    121|	}
  186|      2|	else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      2|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (186:11): [True: 2, False: 0]
  ------------------
  187|      2|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet supported");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|      2|	}
  189|      0|	else if (asn1_auth_type_choice[2].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (189:11): [True: 0, False: 0]
  ------------------
  190|      0|		sc_log(ctx, "AuthType: AuthKey");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  191|      0|		obj->type = SC_PKCS15_TYPE_AUTH_AUTHKEY;
  ------------------
  |  |  447|      0|#define SC_PKCS15_TYPE_AUTH_AUTHKEY		0x603
  ------------------
  192|      0|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY;
  ------------------
  |  |   96|      0|#define SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY		2
  ------------------
  193|      0|		info.auth_method = SC_AC_AUT;
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  194|      0|		if (!(asn1_authkey_attr[0].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (194:7): [True: 0, False: 0]
  ------------------
  195|      0|			info.attrs.authkey.derived = 1;
  196|      0|	}
  197|      0|	else   {
  198|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unknown authentication type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|      0|	}
  200|       |
  201|    121|	obj->data = malloc(sizeof(info));
  202|    121|	if (obj->data == NULL)
  ------------------
  |  Branch (202:6): [True: 0, False: 121]
  ------------------
  203|    121|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  204|    121|	memcpy(obj->data, &info, sizeof(info));
  205|       |
  206|    121|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_SUCCESS);
  ------------------
  |  |  153|    121|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    121|	int _ret = r; \
  |  |  155|    121|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 121, False: 0]
  |  |  ------------------
  |  |  156|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 121]
  |  |  ------------------
  |  |  157|    121|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    121|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    121|	return _ret; \
  |  |  163|    121|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  207|    121|}
sc_pkcs15_verify_pin:
  298|    476|{
  299|    476|	struct sc_context *ctx = p15card->card->ctx;
  300|    476|	struct sc_pkcs15_auth_info *auth_info;
  301|    476|	int r;
  302|       |
  303|    476|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    476|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    476|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    476|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    476|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 476]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|       |
  305|    476|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (305:6): [True: 0, False: 476]
  |  Branch (305:18): [True: 0, False: 476]
  ------------------
  306|    476|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_PIN_REFERENCE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|    476|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  308|       |
  309|       |	/* Check the provided pin matches pin requirements */
  310|    476|	r = _validate_pin(p15card, auth_info, pinlen);
  311|       |
  312|    476|	if (r)
  ------------------
  |  Branch (312:6): [True: 195, False: 281]
  ------------------
  313|    476|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 195, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    195|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    195|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 195, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    195|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    195|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|       |
  315|    281|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  316|       |
  317|    281|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    281|#define SC_SUCCESS				0
  ------------------
  |  Branch (317:6): [True: 191, False: 90]
  ------------------
  318|    191|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  319|       |
  320|    281|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    281|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    281|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    281|	int _ret = r; \
  |  |  |  |  155|    281|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 281, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    281|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     90|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 90, False: 191]
  |  |  |  |  ------------------
  |  |  |  |  157|    281|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    281|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    281|	return _ret; \
  |  |  |  |  163|    281|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  321|    281|}
_sc_pkcs15_verify_pin:
  327|    309|{
  328|    309|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  329|    309|			pinlen, NULL, NULL);
  330|    309|}
sc_pkcs15_verify_pin_with_session_pin:
  343|    309|{
  344|    309|	struct sc_context *ctx = p15card->card->ctx;
  345|    309|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  346|    309|	int r;
  347|    309|	sc_card_t *card;
  348|    309|	struct sc_pin_cmd_data data;
  349|       |
  350|    309|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    309|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    309|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    309|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    309|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 309]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|    309|	sc_log(ctx, "PIN(type:%X; method:%X; value(%p:%zu)",
  ------------------
  |  |   71|    309|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  352|    309|			auth_info->auth_type, auth_info->auth_method, pincode, pinlen);
  353|    309|	card = p15card->card;
  354|       |
  355|    309|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|    309|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (355:6): [True: 0, False: 309]
  ------------------
  356|      0|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  357|      0|				NOTIFY_PIN_BAD);
  358|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_LENGTH, "Invalid PIN size");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|      0|	}
  360|       |
  361|       |	/* Initialize arguments */
  362|    309|	memset(&data, 0, sizeof(data));
  363|    309|	data.pin_type = auth_info->auth_method;
  364|       |
  365|    309|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    309|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (365:6): [True: 309, False: 0]
  ------------------
  366|    309|		data.pin_reference = auth_info->attrs.pin.reference;
  367|    309|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  368|    309|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  369|    309|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  370|    309|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  371|    309|		data.pin1.data = pincode;
  372|    309|		data.pin1.len = pinlen;
  373|       |
  374|    309|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    309|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (374:7): [True: 82, False: 227]
  ------------------
  375|     82|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     82|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  376|       |
  377|    309|		switch (auth_info->attrs.pin.type) {
  378|      0|		case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (378:3): [True: 0, False: 309]
  ------------------
  379|      0|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  380|      0|			break;
  381|    242|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    242|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (381:3): [True: 242, False: 67]
  ------------------
  382|    242|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    242|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  383|    242|			break;
  384|     67|		default:
  ------------------
  |  Branch (384:3): [True: 67, False: 242]
  ------------------
  385|       |			/* assume/hope the card driver knows how to encode the pin */
  386|     67|			data.pin1.encoding = 0;
  387|    309|		}
  388|    309|	}
  389|      0|	else if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY)   {
  ------------------
  |  |   96|      0|#define SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY		2
  ------------------
  |  Branch (389:11): [True: 0, False: 0]
  ------------------
  390|      0|		struct sc_pkcs15_object *skey_obj = NULL;
  391|      0|		struct sc_pkcs15_id *skey_id =  &auth_info->attrs.authkey.skey_id;
  392|      0|		struct sc_pkcs15_skey_info *skey_info = NULL;
  393|       |
  394|      0|		r = sc_pkcs15_find_skey_by_id(p15card, skey_id, &skey_obj);
  395|      0|		if (r)   {
  ------------------
  |  Branch (395:7): [True: 0, False: 0]
  ------------------
  396|      0|			sc_log(ctx, "cannot find secret key with id:%s", sc_pkcs15_print_id(skey_id));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  397|      0|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|      0|		}
  399|      0|		skey_info = (struct sc_pkcs15_skey_info *)skey_obj->data;
  400|       |
  401|      0|		sc_log(ctx, "found secret key '%s'", skey_obj->label);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  402|      0|		data.pin_reference = skey_info->key_reference;
  403|      0|	}
  404|       |
  405|    309|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    618|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (405:7): [True: 0, False: 309]
  ------------------
  406|    309|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|    309|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (406:8): [True: 0, False: 309]
  ------------------
  407|      0|		if (!pincode && !pinlen)
  ------------------
  |  Branch (407:7): [True: 0, False: 0]
  |  Branch (407:19): [True: 0, False: 0]
  ------------------
  408|      0|			data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  409|       |
  410|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN)
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (410:7): [True: 0, False: 0]
  ------------------
  411|      0|			data.pin1.prompt = "Please enter SO PIN";
  412|      0|		else
  413|      0|			data.pin1.prompt = "Please enter PIN";
  414|      0|	}
  415|       |
  416|    309|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  563|    618|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (416:6): [True: 0, False: 309]
  |  Branch (416:46): [True: 0, False: 0]
  |  Branch (416:60): [True: 0, False: 0]
  ------------------
  417|       |		/* session pin is requested and supported with standard verification*/
  418|      0|		data.cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  419|      0|		memcpy(&data.pin2, &data.pin1, sizeof (data.pin1));
  420|      0|		data.pin2.data = sessionpin;
  421|      0|		data.pin2.len = *sessionpinlen;
  422|    309|	} else {
  423|       |		/* perform a standard verify */
  424|    309|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    309|#define SC_PIN_CMD_VERIFY	0
  ------------------
  425|    309|		if (sessionpinlen)
  ------------------
  |  Branch (425:7): [True: 0, False: 309]
  ------------------
  426|      0|			*sessionpinlen = 0;
  427|    309|	}
  428|       |
  429|    309|	r = sc_lock(card);
  430|    309|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    309|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    309|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    309|	int _ret = (r); \
  |  |  |  |  168|    309|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 309]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    309|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 309]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|       |
  432|       |	/* the path in the pin object is optional */
  433|    309|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (433:6): [True: 69, False: 240]
  |  Branch (433:35): [True: 1, False: 239]
  ------------------
  434|     70|		r = sc_select_file(card, &auth_info->path, NULL);
  435|     70|		if (r)
  ------------------
  |  Branch (435:7): [True: 1, False: 69]
  ------------------
  436|      1|			goto out;
  437|     70|	}
  438|       |
  439|    308|	r = sc_pin_cmd(card, &data);
  440|    308|	auth_info->tries_left = data.pin1.tries_left;
  441|    308|	sc_log(ctx, "PIN cmd result %i", r);
  ------------------
  |  |   71|    308|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  442|    308|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 214, False: 94]
  ------------------
  443|    214|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  444|    214|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    428|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (444:7): [True: 0, False: 214]
  |  Branch (444:49): [True: 0, False: 0]
  ------------------
  445|      0|			*sessionpinlen = data.pin2.len;
  446|      0|		}
  447|    214|	} else {
  448|     94|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  449|     94|				NOTIFY_PIN_BAD);
  450|     94|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    188|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (450:7): [True: 0, False: 94]
  |  Branch (450:49): [True: 0, False: 0]
  ------------------
  451|      0|			*sessionpinlen = 0;
  452|      0|		}
  453|     94|	}
  454|       |
  455|    308|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|    616|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (455:6): [True: 308, False: 0]
  ------------------
  456|    308|			&& auth_info->auth_method != SC_AC_SESSION) {
  ------------------
  |  |  159|    308|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (456:7): [True: 308, False: 0]
  ------------------
  457|    308|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  458|    308|				r == SC_SUCCESS ? NOTIFY_PIN_GOOD : NOTIFY_PIN_BAD);
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
  |  Branch (458:5): [True: 214, False: 94]
  ------------------
  459|    308|	}
  460|       |
  461|    309|out:
  462|    309|	sc_unlock(card);
  463|    309|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    309|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    309|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    309|	int _ret = r; \
  |  |  |  |  155|    309|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 309, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    309|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     95|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 95, False: 214]
  |  |  |  |  ------------------
  |  |  |  |  157|    309|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    309|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    309|	return _ret; \
  |  |  |  |  163|    309|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|    309|}
sc_pkcs15_free_auth_info:
  734|  5.71k|{
  735|  5.71k|	free(auth_info);
  736|  5.71k|}
sc_pkcs15_pincache_add:
  742|    405|{
  743|    405|	struct sc_context *ctx = p15card->card->ctx;
  744|    405|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  745|    405|	struct sc_pkcs15_object *obj = NULL;
  746|    405|	int r;
  747|       |
  748|    405|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    405|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    405|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    405|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    405|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 405]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|       |
  750|    405|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (750:6): [True: 0, False: 405]
  |  Branch (750:14): [True: 0, False: 405]
  ------------------
  751|      0|		sc_log(ctx, "No cache for zero length PIN");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  752|      0|		return;
  753|      0|	}
  754|    405|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (754:11): [True: 4, False: 401]
  ------------------
  755|      4|		sc_log(ctx, "PIN caching not enabled");
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  756|      4|		return;
  757|      4|	}
  758|    401|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    401|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (758:11): [True: 0, False: 401]
  ------------------
  759|      0|		sc_log(ctx, "only 'PIN' auth. object can be cached");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  760|      0|		return;
  761|      0|	}
  762|       |
  763|       |	/* If the PIN protects an object with user consent, don't cache it */
  764|       |
  765|    401|	obj = p15card->obj_list;
  766|  2.79k|	while (obj != NULL) {
  ------------------
  |  Branch (766:9): [True: 2.39k, False: 393]
  ------------------
  767|       |		/* Compare 'sc_pkcs15_object.auth_id' with 'sc_pkcs15_pin_info.auth_id'.
  768|       |		 * In accordance with PKCS#15 "6.1.8 CommonObjectAttributes" and
  769|       |		 * "6.1.16 CommonAuthenticationObjectAttributes" with the exception that
  770|       |		 * "CommonObjectAttributes.accessControlRules" are not taken into account. */
  771|       |
  772|  2.39k|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (772:7): [True: 499, False: 1.89k]
  ------------------
  773|       |			/* Caching is refused, if the protected object requires user consent */
  774|    499|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (774:8): [True: 499, False: 0]
  ------------------
  775|    499|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (775:9): [True: 8, False: 491]
  ------------------
  776|      8|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  777|      8|					return;
  778|      8|				}
  779|    499|			}
  780|    499|		}
  781|       |
  782|  2.38k|		obj = obj->next;
  783|  2.38k|	}
  784|       |
  785|    393|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  786|    393|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|    393|#define SC_SUCCESS				0
  ------------------
  |  Branch (786:6): [True: 0, False: 393]
  ------------------
  787|      0|		sc_log(ctx, "Failed to allocate object content");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  788|      0|		return;
  789|      0|	}
  790|       |
  791|    393|	pin_obj->usage_counter = 0;
  792|    393|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   71|    393|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  793|    393|}
sc_pkcs15_pincache_revalidate:
  798|     45|{
  799|     45|	struct sc_context *ctx = p15card->card->ctx;
  800|     45|	sc_pkcs15_object_t *pin_obj;
  801|     45|	int r;
  802|       |
  803|     45|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     45|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     45|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     45|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     45|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 45]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  804|     45|	if (!p15card->opts.use_pin_cache)
  ------------------
  |  Branch (804:6): [True: 0, False: 45]
  ------------------
  805|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  806|       |
  807|       |	/*  Apps that do not support CK_ALWAYS_AUTHENTICATE
  808|       |	 *  may need pin_cache_ignore_user_consent = 1 */
  809|     45|	if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (809:6): [True: 45, False: 0]
  ------------------
  810|     45|	    if (obj->user_consent)
  ------------------
  |  Branch (810:10): [True: 0, False: 45]
  ------------------
  811|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  812|     45|	}
  813|       |
  814|     45|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|     90|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (814:7): [True: 0, False: 45]
  ------------------
  815|     45|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  560|     45|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (815:8): [True: 0, False: 45]
  ------------------
  816|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  817|       |
  818|     45|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
  819|     45|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     45|#define SC_SUCCESS				0
  ------------------
  |  Branch (819:6): [True: 1, False: 44]
  ------------------
  820|      1|		sc_log(ctx, "Could not find pin object for auth_id %s", sc_pkcs15_print_id(&obj->auth_id));
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  821|      1|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      1|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  822|      1|	}
  823|       |
  824|     44|	if (pin_obj->usage_counter >= p15card->opts.pin_cache_counter) {
  ------------------
  |  Branch (824:6): [True: 0, False: 44]
  ------------------
  825|      0|		sc_pkcs15_free_object_content(pin_obj);
  826|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  827|      0|	}
  828|       |
  829|     44|	if (!pin_obj->content.value || !pin_obj->content.len)
  ------------------
  |  Branch (829:6): [True: 16, False: 28]
  |  Branch (829:33): [True: 0, False: 28]
  ------------------
  830|     16|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     16|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  831|       |
  832|     28|	pin_obj->usage_counter++;
  833|     28|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  834|     28|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  |  Branch (834:6): [True: 5, False: 23]
  ------------------
  835|       |		/* Ensure that wrong PIN isn't used again */
  836|      5|		sc_pkcs15_free_object_content(pin_obj);
  837|       |
  838|      5|		sc_log(ctx, "Verify PIN error %i", r);
  ------------------
  |  |   71|      5|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  839|      5|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      5|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  840|      5|	}
  841|       |
  842|     23|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     23|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     23|}
sc_pkcs15_pincache_clear:
  846|  4.53k|{
  847|  4.53k|	struct sc_pkcs15_object *objs[32];
  848|  4.53k|	int i, r;
  849|       |
  850|  4.53k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  4.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|  4.53k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|  4.53k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  852|  9.62k|	for (i = 0; i < r; i++)
  ------------------
  |  Branch (852:14): [True: 5.08k, False: 4.53k]
  ------------------
  853|  5.08k|		sc_pkcs15_free_object_content(objs[i]);
  854|  4.53k|}
pkcs15-pin.c:_validate_pin:
  260|    476|{
  261|    476|	size_t max_length;
  262|    476|	if (p15card == NULL) {
  ------------------
  |  Branch (262:6): [True: 0, False: 476]
  ------------------
  263|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  264|      0|	}
  265|       |
  266|       |	/* Ignore validation of the non-PIN authentication objects */
  267|    476|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    476|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (267:6): [True: 0, False: 476]
  ------------------
  268|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  269|       |
  270|       |	/* prevent buffer overflow from hostile card */
  271|    476|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|    476|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (271:6): [True: 0, False: 476]
  ------------------
  272|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  273|       |
  274|       |	/* if we use pinpad, no more checks are needed */
  275|    476|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    952|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (275:7): [True: 0, False: 476]
  ------------------
  276|    476|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    476|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (276:8): [True: 0, False: 476]
  ------------------
  277|      0|		   	&& !pinlen)
  ------------------
  |  Branch (277:10): [True: 0, False: 0]
  ------------------
  278|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  279|       |
  280|       |	/* If pin is given, make sure it is within limits */
  281|    476|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|    508|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (281:15): [True: 444, False: 32]
  ------------------
  282|    476|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (282:6): [True: 18, False: 458]
  |  Branch (282:29): [True: 177, False: 281]
  ------------------
  283|    195|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|    195|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  284|       |
  285|    281|	return SC_SUCCESS;
  ------------------
  |  |   28|    281|#define SC_SUCCESS				0
  ------------------
  286|    476|}

sc_pkcs15emu_piv_init_ex:
 1431|  11.4k|{
 1432|  11.4k|	sc_card_t   *card = p15card->card;
 1433|  11.4k|	sc_context_t    *ctx = card->ctx;
 1434|       |
 1435|  11.4k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.4k]
  |  |  ------------------
  ------------------
 1436|       |
 1437|  11.4k|	if (piv_detect_card(p15card))
  ------------------
  |  Branch (1437:6): [True: 10.5k, False: 937]
  ------------------
 1438|  10.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1439|    937|	return sc_pkcs15emu_piv_init(p15card);
 1440|  11.4k|}
pkcs15-piv.c:piv_detect_card:
  237|  11.4k|{
  238|  11.4k|	sc_card_t *card = p15card->card;
  239|       |
  240|  11.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.4k]
  |  |  ------------------
  ------------------
  241|  11.4k|	if (card->type < SC_CARD_TYPE_PIV_II_BASE
  ------------------
  |  Branch (241:6): [True: 4.36k, False: 7.10k]
  ------------------
  242|  7.10k|		|| card->type >= SC_CARD_TYPE_PIV_II_BASE + 1000)
  ------------------
  |  Branch (242:6): [True: 6.16k, False: 937]
  ------------------
  243|  10.5k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  10.5k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  244|    937|	return SC_SUCCESS;
  ------------------
  |  |   28|    937|#define SC_SUCCESS				0
  ------------------
  245|  11.4k|}
pkcs15-piv.c:sc_pkcs15emu_piv_init:
  274|    937|{
  275|       |
  276|       |	/* The cert objects will return all the data */
  277|       |	/* Note: pkcs11 objects do not have CK_ID values */
  278|       |
  279|       |	// clang-format off
  280|    937|	static const objdata objects[] = {
  281|    937|	{"01", "Card Capability Container",
  282|    937|			"2.16.840.1.101.3.7.1.219.0", NULL, "DB00", 0},
  283|    937|	{"02", "Card Holder Unique Identifier",
  284|    937|			"2.16.840.1.101.3.7.2.48.0", NULL, "3000", 0},
  285|    937|	{"03", "Unsigned Card Holder Unique Identifier",
  286|    937|			"2.16.840.1.101.3.7.2.48.2", NULL, "3010", 0},
  287|    937|	{"04", "X.509 Certificate for PIV Authentication",
  288|    937|			"2.16.840.1.101.3.7.2.1.1", NULL, "0101", 0},
  289|    937|	{"05", "Cardholder Fingerprints",
  290|    937|			"2.16.840.1.101.3.7.2.96.16", "01", "6010", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  291|    937|	{"06", "Printed Information",
  292|    937|			"2.16.840.1.101.3.7.2.48.1", "01", "3001", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  293|    937|	{"07", "Cardholder Facial Image",
  294|    937|			"2.16.840.1.101.3.7.2.96.48", "01", "6030", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  295|    937|	{"08", "X.509 Certificate for Digital Signature",
  296|    937|			"2.16.840.1.101.3.7.2.1.0",  NULL, "0100", 0},
  297|    937|	{"09", "X.509 Certificate for Key Management",
  298|    937|			"2.16.840.1.101.3.7.2.1.2", NULL, "0102", 0},
  299|    937|	{"10","X.509 Certificate for Card Authentication",
  300|    937|			"2.16.840.1.101.3.7.2.5.0", NULL, "0500", 0},
  301|    937|	{"11", "Security Object",
  302|    937|			"2.16.840.1.101.3.7.2.144.0", NULL, "9000", 0},
  303|    937|	{"12", "Discovery Object",
  304|    937|			"2.16.840.1.101.3.7.2.96.80", NULL, "6050", 0},
  305|    937|	{"13", "Key History Object",
  306|    937|			"2.16.840.1.101.3.7.2.96.96", NULL, "6060", 0},
  307|    937|	{"14", "Cardholder Iris Image",
  308|    937|			"2.16.840.1.101.3.7.2.16.21", NULL, "1015", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  309|       |
  310|    937|	{"15", "Retired X.509 Certificate for Key Management 1",
  311|    937|			"2.16.840.1.101.3.7.2.16.1", NULL, "1001", 0},
  312|    937|	{"16", "Retired X.509 Certificate for Key Management 2",
  313|    937|			"2.16.840.1.101.3.7.2.16.2", NULL, "1002", 0},
  314|    937|	{"17", "Retired X.509 Certificate for Key Management 3",
  315|    937|			"2.16.840.1.101.3.7.2.16.3", NULL, "1003", 0},
  316|    937|	{"18", "Retired X.509 Certificate for Key Management 4",
  317|    937|			"2.16.840.1.101.3.7.2.16.4", NULL, "1004", 0},
  318|    937|	{"19", "Retired X.509 Certificate for Key Management 5",
  319|    937|			"2.16.840.1.101.3.7.2.16.5", NULL, "1005", 0},
  320|    937|	{"20", "Retired X.509 Certificate for Key Management 6",
  321|    937|			"2.16.840.1.101.3.7.2.16.6", NULL, "1006", 0},
  322|    937|	{"21", "Retired X.509 Certificate for Key Management 7",
  323|    937|			"2.16.840.1.101.3.7.2.16.7", NULL, "1007", 0},
  324|    937|	{"22", "Retired X.509 Certificate for Key Management 8",
  325|    937|			"2.16.840.1.101.3.7.2.16.8", NULL, "1008", 0},
  326|    937|	{"23", "Retired X.509 Certificate for Key Management 9",
  327|    937|			"2.16.840.1.101.3.7.2.16.9", NULL, "1009", 0},
  328|    937|	{"24", "Retired X.509 Certificate for Key Management 10",
  329|    937|			"2.16.840.1.101.3.7.2.16.10", NULL, "100A", 0},
  330|    937|	{"25", "Retired X.509 Certificate for Key Management 11",
  331|    937|			"2.16.840.1.101.3.7.2.16.11", NULL, "100B", 0},
  332|    937|	{"26", "Retired X.509 Certificate for Key Management 12",
  333|    937|			"2.16.840.1.101.3.7.2.16.12", NULL, "100C", 0},
  334|    937|	{"27", "Retired X.509 Certificate for Key Management 13",
  335|    937|			"2.16.840.1.101.3.7.2.16.13", NULL, "100D", 0},
  336|    937|	{"28", "Retired X.509 Certificate for Key Management 14",
  337|    937|			"2.16.840.1.101.3.7.2.16.14", NULL, "100E", 0},
  338|    937|	{"29", "Retired X.509 Certificate for Key Management 15",
  339|    937|			"2.16.840.1.101.3.7.2.16.15", NULL, "100F", 0},
  340|    937|	{"30", "Retired X.509 Certificate for Key Management 16",
  341|    937|			"2.16.840.1.101.3.7.2.16.16", NULL, "1010", 0},
  342|    937|	{"31", "Retired X.509 Certificate for Key Management 17",
  343|    937|			"2.16.840.1.101.3.7.2.16.17", NULL, "1011", 0},
  344|    937|	{"32", "Retired X.509 Certificate for Key Management 18",
  345|    937|			"2.16.840.1.101.3.7.2.16.18", NULL, "1012", 0},
  346|    937|	{"33", "Retired X.509 Certificate for Key Management 19",
  347|    937|			"2.16.840.1.101.3.7.2.16.19", NULL, "1013", 0},
  348|    937|	{"34", "Retired X.509 Certificate for Key Management 20",
  349|    937|			"2.16.840.1.101.3.7.2.16.20", NULL, "1014", 0},
  350|       |	/* new in 800-73-4 */
  351|    937|	{"35", "Biometric Information Templates Group Template",
  352|    937|			"2.16.840.1.101.3.7.2.16.22", NULL, "1016", 0},
  353|    937|	{"36", "Secure Messaging Certificate Signer",
  354|    937|			"2.16.840.1.101.3.7.2.16.23", NULL, "1017", 0},
  355|    937|	{"37", "Pairing Code Reference Data Container",
  356|    937|			"2.16.840.1.101.3.7.2.16.24", NULL, "1018", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  357|    937|	{NULL, NULL, NULL, NULL, NULL, 0}
  358|    937|	};
  359|       |	// clang-format on
  360|       |	/* NIST 800-73-1 lifted the restriction on
  361|       |	 * requiring pin protected certs. Thus the default is to
  362|       |	 * not require this.
  363|       |	 *
  364|       |	 * Certs will be pulled out from the cert objects
  365|       |	 * But there may be extra certs (SM Signer cert) that do
  366|       |	 * not have a private keys on the card. These certs must be last
  367|       |	 */
  368|       |
  369|       |	/* Any certs on card without private key must be last */
  370|    937|#define PIV_NUM_CERTS 25
  371|    937|#define PIV_NUM_KEYS  24
  372|       |
  373|       |	// clang-format off
  374|    937|	static const cdata certs[PIV_NUM_CERTS] = {
  375|    937|		{"01", "Certificate for PIV Authentication", "0101cece", 0, 0},
  376|    937|		{"02", "Certificate for Digital Signature", "0100cece", 0, 0},
  377|    937|		{"03", "Certificate for Key Management", "0102cece", 0, 0},
  378|    937|		{"04", "Certificate for Card Authentication", "0500cece", 0, 0},
  379|    937|		{"05", "Retired Certificate for Key Management 1", "1001cece", 0, 0},
  380|    937|		{"06", "Retired Certificate for Key Management 2", "1002cece", 0, 0},
  381|    937|		{"07", "Retired Certificate for Key Management 3", "1003cece", 0, 0},
  382|    937|		{"08", "Retired Certificate for Key Management 4", "1004cece", 0, 0},
  383|    937|		{"09", "Retired Certificate for Key Management 5", "1005cece", 0, 0},
  384|    937|		{"10", "Retired Certificate for Key Management 6", "1006cece", 0, 0},
  385|    937|		{"11", "Retired Certificate for Key Management 7", "1007cece", 0, 0},
  386|    937|		{"12", "Retired Certificate for Key Management 8", "1008cece", 0, 0},
  387|    937|		{"13", "Retired Certificate for Key Management 9", "1009cece", 0, 0},
  388|    937|		{"14", "Retired Certificate for Key Management 10", "100Acece", 0, 0},
  389|    937|		{"15", "Retired Certificate for Key Management 11", "100Bcece", 0, 0},
  390|    937|		{"16", "Retired Certificate for Key Management 12", "100Ccece", 0, 0},
  391|    937|		{"17", "Retired Certificate for Key Management 13", "100Dcece", 0, 0},
  392|    937|		{"18", "Retired Certificate for Key Management 14", "100Ecece", 0, 0},
  393|    937|		{"19", "Retired Certificate for Key Management 15", "100Fcece", 0, 0},
  394|    937|		{"20", "Retired Certificate for Key Management 16", "1010cece", 0, 0},
  395|    937|		{"21", "Retired Certificate for Key Management 17", "1011cece", 0, 0},
  396|    937|		{"22", "Retired Certificate for Key Management 18", "1012cece", 0, 0},
  397|    937|		{"23", "Retired Certificate for Key Management 19", "1013cece", 0, 0},
  398|    937|		{"24", "Retired Certificate for Key Management 20", "1014cece", 0, 0},
  399|       |		/* Yubikey Attestation uses "25" but not read via GET_DATA */
  400|    937|		{"81", "Secure Messaging Certificate Signer",   "1017cece", 0, 0} /* no keys on card */
  401|    937|	};
  402|       |	// clang-format on
  403|       |
  404|       |	// clang-format off
  405|    937|	static const pindata pins[] = {
  406|    937|		{ "01", "PIN", "", 0x80,
  407|       |		  /* label, flag  and ref will change if using global pin */
  408|    937|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    937|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  409|    937|		  8, 4, 8,
  410|    937|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    937|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  411|    937|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    937|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  412|    937|		  SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    937|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  413|    937|		  -1, 0xFF,
  414|    937|		  SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  415|       |
  416|    937|		{ "02", "PIV PUK", "", 0x81,
  417|    937|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    937|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  418|    937|		  8, 4, 8,
  419|    937|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    937|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  420|    937|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    937|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  421|    937|		  SC_PKCS15_PIN_FLAG_SO_PIN |
  ------------------
  |  |   61|    937|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  422|    937|		  SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN,
  ------------------
  |  |   60|    937|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  423|    937|		  -1, 0xFF,
  424|    937|		  SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  425|       |
  426|       |		/* only used with minidriver */
  427|    937|		{ "03", "PIN", "", 0x80,
  428|       |		  /* used in minidriver as the sign key and for 9C key */
  429|       |		  /* label, flag  and ref will change if using global pin */
  430|    937|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    937|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  431|    937|		  8, 4, 8,
  432|    937|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    937|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  433|    937|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    937|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  434|    937|		  SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    937|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  435|    937|		  -1, 0xFF,
  436|    937|		  SC_PKCS15_CO_FLAG_PRIVATE, 1}, /* only use if cardmod */
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  437|    937|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  438|    937|	};
  439|       |	// clang-format on
  440|       |
  441|       |
  442|       |	/*
  443|       |	 * The size of the key or the algid is not really known
  444|       |	 * but can be derived from the certificates.
  445|       |	 * the cert, pubkey and privkey are a set.
  446|       |	 * Key usages bits taken from pkcs15v1_1 Table 2
  447|       |	 * RSA and EC have different sets of usage
  448|       |	 */
  449|       |	// clang-format off
  450|    937|	static const pubdata pubkeys[PIV_NUM_KEYS] = {
  451|    937|		{ "01", "PIV AUTH pubkey",
  452|    937|			 	/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT |
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  453|    937|			 		SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  454|    937|					SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  455|    937|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER,
  ------------------
  |  |  312|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  456|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY,
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  457|    937|			"9A06", 0x9A, NULL, 0, "PIV_9A_KEY"},
  458|    937|		{ "02", "SIGN pubkey",
  459|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT |
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  460|    937|					SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  461|    937|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  312|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  462|    937|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    937|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  463|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  464|    937|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    937|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  465|    937|			"9C06", 0x9C, NULL, 0, "PIV_9C_KEY"},
  466|    937|		{ "03", "KEY MAN pubkey",
  467|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  468|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  469|    937|			"9D06", 0x9D, NULL, 0, "PIV_9D_KEY"},
  470|    937|		{ "04", "CARD AUTH pubkey",
  471|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  472|    937|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER,
  ------------------
  |  |  312|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  473|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY,
  ------------------
  |  |  311|    937|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  474|    937|			"9E06", 0x9E, NULL, 0, "PIV_9E_KEY"},  /* no pin, and avail in contactless */
  475|       |
  476|    937|		{ "05", "Retired KEY MAN 1",
  477|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  478|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  479|    937|			 "8206", 0x82, NULL, 0, "PIV_82_KEY"},
  480|    937|		{ "06", "Retired KEY MAN 2",
  481|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  482|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  483|    937|			 "8306", 0x83, NULL, 0, "PIV_83_KEY"},
  484|    937|		{ "07", "Retired KEY MAN 3",
  485|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  486|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  487|    937|			 "8406", 0x84, NULL, 0, "PIV_84_KEY"},
  488|    937|		{ "08", "Retired KEY MAN 4",
  489|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  490|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  491|    937|			 "8506", 0x85, NULL, 0, "PIV_85_KEY"},
  492|    937|		{ "09", "Retired KEY MAN 5",
  493|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  494|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  495|    937|			 "8606", 0x86, NULL, 0, "PIV_86_KEY"},
  496|    937|		{ "10", "Retired KEY MAN 6",
  497|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  498|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  499|    937|			 "8706", 0x87, NULL, 0, "PIV_87_KEY"},
  500|    937|		{ "11", "Retired KEY MAN 7",
  501|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  502|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  503|    937|			 "8806", 0x88, NULL, 0, "PIV_88_KEY"},
  504|    937|		{ "12", "Retired KEY MAN 8",
  505|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  506|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  507|    937|			 "8906", 0x89, NULL, 0, "PIV_89_KEY"},
  508|    937|		{ "13", "Retired KEY MAN 9",
  509|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  510|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  511|    937|			 "8A06", 0x8A, NULL, 0, "PIV_8A_KEY"},
  512|    937|		{ "14", "Retired KEY MAN 10",
  513|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  514|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  515|    937|			 "8B06", 0x8B, NULL, 0, "PIV_8B_KEY"},
  516|    937|		{ "15", "Retired KEY MAN 11",
  517|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  518|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  519|    937|			 "8C06", 0x8C, NULL, 0, "PIV_8C_KEY"},
  520|    937|		{ "16", "Retired KEY MAN 12",
  521|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  522|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  523|    937|			 "8D06", 0x8D, NULL, 0, "PIV_8D_KEY"},
  524|    937|		{ "17", "Retired KEY MAN 13",
  525|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  526|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  527|    937|			 "8E06", 0x8E, NULL, 0, "PIV_8E_KEY"},
  528|    937|		{ "18", "Retired KEY MAN 14",
  529|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  530|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  531|    937|			 "8F06", 0x8F, NULL, 0, "PIV_8F_KEY"},
  532|    937|		{ "19", "Retired KEY MAN 15",
  533|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  534|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  535|    937|			 "9006", 0x90, NULL, 0, "PIV_90_KEY"},
  536|    937|		{ "20", "Retired KEY MAN 16",
  537|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  538|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  539|    937|			 "9106", 0x91, NULL, 0, "PIV_91_KEY"},
  540|    937|		{ "21", "Retired KEY MAN 17",
  541|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  542|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  543|    937|			 "9206", 0x92, NULL, 0, "PIV_92_KEY"},
  544|    937|		{ "22", "Retired KEY MAN 18",
  545|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  546|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  547|    937|			 "9306", 0x93, NULL, 0, "PIV_93_KEY"},
  548|    937|		{ "23", "Retired KEY MAN 19",
  549|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  550|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  551|    937|			 "9406", 0x94, NULL, 0, "PIV_94_KEY"},
  552|    937|		{ "24", "Retired KEY MAN 20",
  553|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    937|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    937|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  554|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  555|    937|			 "9506", 0x95, NULL, 0, "PIV_95_KEY"}
  556|    937|	};
  557|       |	// clang-format on
  558|       |
  559|       |/*
  560|       | * Note some of the SC_PKCS15_PRKEY values are dependent
  561|       | * on the key algorithm, and will be reset.
  562|       |
  563|       | * No SM Signer private Key on card
  564|       | * The 04 SM ECC CVC pubkey is in response to SELECT AID
  565|       | */
  566|       |	// clang-format off
  567|    937|	static const prdata prkeys[PIV_NUM_KEYS] = {
  568|    937|		{ "01", "PIV AUTH key",
  569|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT |
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  570|    937|					SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  571|    937|					SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  572|    937|					SC_PKCS15_PRKEY_USAGE_SIGNRECOVER,
  ------------------
  |  |  308|    937|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  573|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  574|    937|			"", 0x9A, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  575|    937|		{ "02", "SIGN key",
  576|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT |
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  577|    937|					SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  578|    937|					SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  308|    937|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  579|    937|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    937|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  580|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  581|    937|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    937|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  582|    937|			"", 0x9C, "01", SC_PKCS15_CO_FLAG_PRIVATE, 1}, /* use sign pin and user_consent */
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  583|    937|		{ "03", "KEY MAN key",
  584|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  585|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  586|    937|			"", 0x9D, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  587|    937|		{ "04", "CARD AUTH key",
  588|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  589|    937|				SC_PKCS15_PRKEY_USAGE_SIGNRECOVER,
  ------------------
  |  |  308|    937|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  590|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|    937|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  591|    937|			"", 0x9E, NULL, 0, 0}, /* no PIN needed, works with wireless */
  592|    937|		{ "05", "Retired KEY MAN 1",
  593|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  594|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  595|    937|			"", 0x82, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  596|    937|		{ "06", "Retired KEY MAN 2",
  597|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  598|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  599|    937|			"", 0x83, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  600|    937|		{ "07", "Retired KEY MAN 3",
  601|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  602|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  603|    937|			"", 0x84, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  604|    937|		{ "08", "Retired KEY MAN 4",
  605|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  606|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  607|    937|			"", 0x85, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  608|    937|		{ "09", "Retired KEY MAN 5",
  609|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  610|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  611|    937|			"", 0x86, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  612|    937|		{ "10", "Retired KEY MAN 6",
  613|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  614|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  615|    937|			"", 0x87, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  616|    937|		{ "11", "Retired KEY MAN 7",
  617|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  618|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  619|    937|			"", 0x88, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  620|    937|		{ "12", "Retired KEY MAN 8",
  621|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  622|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  623|    937|			"", 0x89, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  624|    937|		{ "13", "Retired KEY MAN 9",
  625|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  626|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  627|    937|			"", 0x8A, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  628|    937|		{ "14", "Retired KEY MAN 10",
  629|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  630|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  631|    937|			"", 0x8B, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  632|    937|		{ "15", "Retired KEY MAN 11",
  633|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  634|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  635|    937|			"", 0x8C, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  636|    937|		{ "16", "Retired KEY MAN 12",
  637|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  638|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  639|    937|			"", 0x8D, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  640|    937|		{ "17", "Retired KEY MAN 13",
  641|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  642|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  643|    937|			"", 0x8E, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  644|    937|		{ "18", "Retired KEY MAN 14",
  645|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  646|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  647|    937|			"", 0x8F, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  648|    937|		{ "19", "Retired KEY MAN 15",
  649|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  650|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  651|    937|			"", 0x90, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  652|    937|		{ "20", "Retired KEY MAN 16",
  653|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  654|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  655|    937|			"", 0x91, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  656|    937|		{ "21", "Retired KEY MAN 17",
  657|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  658|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  659|    937|			"", 0x92, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  660|    937|		{ "22", "Retired KEY MAN 18",
  661|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  662|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  663|    937|			"", 0x93, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  664|    937|		{ "23", "Retired KEY MAN 19",
  665|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  666|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  667|    937|			"", 0x94, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  668|    937|		{ "24", "Retired KEY MAN 20",
  669|    937|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    937|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    937|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  670|    937|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    937|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  671|    937|			"", 0x95, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0}
  ------------------
  |  |   50|    937|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  672|       |		/* SM Signer certificate does not have private key on card */
  673|    937|	};
  674|       |	// clang-format on
  675|       |
  676|    937|	int    r, i;
  677|    937|	sc_card_t *card = p15card->card;
  678|    937|	sc_serial_number_t serial;
  679|    937|	char buf[SC_MAX_SERIALNR * 2 + 1];
  680|    937|	common_key_info ckis[PIV_NUM_CERTS];
  681|    937|	int follows_nist_fascn = 0;
  682|    937|	char *token_name = NULL;
  683|       |
  684|    937|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    937|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    937|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    937|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 937]
  |  |  ------------------
  ------------------
  685|       |
  686|    937|	memset(&serial, 0, sizeof(serial));
  687|       |
  688|       |	/* could read this off card if needed */
  689|       |
  690|       |	/* CSP does not like a - in the name */
  691|    937|	set_string(&p15card->tokeninfo->label, "PIV_II");
  692|    937|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   42|    937|#define MANU_ID		"piv_II "
  ------------------
  693|       |
  694|       |	/*
  695|       |	 * get serial number
  696|       |	 * We will use the FASC-N from the CHUID
  697|       |	 * Note we are not verifying CHUID, belongs to this card
  698|       |	 * but need serial number for Mac tokend
  699|       |	 */
  700|       |
  701|    937|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  702|    937|	if (r < 0) {
  ------------------
  |  Branch (702:6): [True: 916, False: 21]
  ------------------
  703|    916|		sc_log(card->ctx, "sc_card_ctl rc=%d",r);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  704|    916|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  705|    916|	} else {
  706|     21|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  707|     21|		set_string(&p15card->tokeninfo->serial_number, buf);
  708|     21|	}
  709|       |	/* US gov issued PIVs have CHUID with a FASCN that does not start with 9999 */
  710|    937|	if (serial.len == 25 && !(serial.value[0] == 0xD4 && serial.value[1] == 0xE7 && serial.value[2] == 0x39 && (serial.value[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (710:6): [True: 19, False: 918]
  |  Branch (710:28): [True: 10, False: 9]
  |  Branch (710:55): [True: 6, False: 4]
  |  Branch (710:82): [True: 3, False: 3]
  |  Branch (710:109): [True: 1, False: 2]
  ------------------
  711|     18|	    follows_nist_fascn = 1;
  712|     18|	}
  713|       |
  714|    937|	sc_log(card->ctx,  "PIV-II adding objects...");
  ------------------
  |  |   71|    937|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  715|       |
  716|       |	/* set other objects */
  717|  35.6k|	for (i = 0; objects[i].label; i++) {
  ------------------
  |  Branch (717:14): [True: 34.6k, False: 937]
  ------------------
  718|  34.6k|		struct sc_pkcs15_data_info obj_info;
  719|  34.6k|		struct sc_pkcs15_object    obj_obj;
  720|       |
  721|  34.6k|		memset(&obj_info, 0, sizeof(obj_info));
  722|  34.6k|		memset(&obj_obj, 0, sizeof(obj_obj));
  723|  34.6k|		sc_pkcs15_format_id(objects[i].id, &obj_info.id);
  724|  34.6k|		sc_format_path(objects[i].path, &obj_info.path);
  725|       |
  726|       |		/* See if the object can not be present on the card */
  727|  34.6k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &obj_info.path);
  728|  34.6k|		if (r == 1)
  ------------------
  |  Branch (728:7): [True: 19.4k, False: 15.2k]
  ------------------
  729|  19.4k|			continue; /* Not on card, do not define the object */
  730|       |
  731|  15.2k|		strncpy(obj_info.app_label, objects[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  15.2k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  732|  15.2k|		r = sc_format_oid(&obj_info.app_oid, objects[i].aoid);
  733|  15.2k|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (733:7): [True: 0, False: 15.2k]
  ------------------
  734|  15.2k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  735|       |
  736|       |		/* We can not read all the objects, as some need the PIN! */
  737|  15.2k|		if (objects[i].auth_id)
  ------------------
  |  Branch (737:7): [True: 2.81k, False: 12.4k]
  ------------------
  738|  2.81k|			sc_pkcs15_format_id(objects[i].auth_id, &obj_obj.auth_id);
  739|       |
  740|  15.2k|		strncpy(obj_obj.label, objects[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  15.2k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  741|  15.2k|		obj_obj.flags = objects[i].obj_flags;
  742|       |
  743|  15.2k|		r = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|  15.2k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  744|  15.2k|			&obj_obj, &obj_info);
  745|       |
  746|  15.2k|		if (r < 0)
  ------------------
  |  Branch (746:7): [True: 0, False: 15.2k]
  ------------------
  747|  15.2k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  748|  15.2k|	}
  749|       |
  750|       |	/*
  751|       |	 * certs, pubkeys and priv keys are related and we assume
  752|       |	 * they are in order
  753|       |	 * We need to read the cert, get modulus and keylen
  754|       |	 * We use those for the pubkey, and priv key objects.
  755|       |	 * If no cert, then see if pubkey (i.e. we are initializing,
  756|       |	 * and the pubkey is in a file,) then add pubkey and privkey
  757|       |	 * If no cert and no pubkey, skip adding them.
  758|       |
  759|       |	 */
  760|       |	/* set certs */
  761|    937|	sc_log(card->ctx,  "PIV-II adding certs...");
  ------------------
  |  |   71|    937|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  762|  24.3k|	for (i = 0; i < PIV_NUM_CERTS; i++) {
  ------------------
  |  |  370|  24.3k|#define PIV_NUM_CERTS 25
  ------------------
  |  Branch (762:14): [True: 23.4k, False: 937]
  ------------------
  763|  23.4k|		struct sc_pkcs15_cert_info cert_info;
  764|  23.4k|		struct sc_pkcs15_object    cert_obj;
  765|  23.4k|		sc_pkcs15_der_t   cert_der;
  766|  23.4k|		sc_pkcs15_cert_t *cert_out = NULL;
  767|  23.4k|		int private_obj;
  768|       |
  769|  23.4k|		ckis[i].cert_found = 0;
  770|  23.4k|		ckis[i].key_alg = -1;
  771|  23.4k|		ckis[i].pubkey_found = 0;
  772|  23.4k|		ckis[i].pubkey_from_file = 0;
  773|  23.4k|		ckis[i].pubkey_len = 0;
  774|  23.4k|		ckis[i].pubkey_from_cert = NULL;
  775|  23.4k|		ckis[i].cert_keyUsage = 0;
  776|  23.4k|		ckis[i].cert_keyUsage_present = 0;
  777|  23.4k|		ckis[i].pub_usage = 0;
  778|  23.4k|		ckis[i].priv_usage = 0;
  779|       |
  780|  23.4k|		memset(&cert_info, 0, sizeof(cert_info));
  781|  23.4k|		memset(&cert_obj,  0, sizeof(cert_obj));
  782|       |
  783|  23.4k|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  784|  23.4k|		cert_info.authority = certs[i].authority;
  785|  23.4k|		sc_format_path(certs[i].path, &cert_info.path);
  786|       |
  787|  23.4k|		strncpy(cert_obj.label, certs[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  23.4k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  788|  23.4k|		cert_obj.flags = certs[i].obj_flags;
  789|       |
  790|       |		/* See if the cert might be present or not. */
  791|  23.4k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &cert_info.path);
  792|  23.4k|		if (r == 1) {
  ------------------
  |  Branch (792:7): [True: 17.7k, False: 5.65k]
  ------------------
  793|  17.7k|			sc_log(card->ctx,  "Cert can not be present,i=%d", i);
  ------------------
  |  |   71|  17.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  794|  17.7k|			continue;
  795|  17.7k|		}
  796|       |
  797|  5.65k|		private_obj = cert_obj.flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  5.65k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  798|  5.65k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, private_obj);
  799|       |
  800|  5.65k|		if (r) {
  ------------------
  |  Branch (800:7): [True: 5.04k, False: 608]
  ------------------
  801|  5.04k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  5.04k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  802|  5.04k|			continue;
  803|  5.04k|		}
  804|       |
  805|    608|		ckis[i].cert_found = 1;
  806|       |		/* cache it using the PKCS15 emulation objects */
  807|       |		/* as it does not change */
  808|    608|		if (cert_der.value) {
  ------------------
  |  Branch (808:7): [True: 608, False: 0]
  ------------------
  809|    608|			cert_info.value.value = cert_der.value;
  810|    608|			cert_info.value.len = cert_der.len;
  811|    608|			if (!p15card->opts.use_file_cache
  ------------------
  |  Branch (811:8): [True: 608, False: 0]
  ------------------
  812|    608|			    || (private_obj && !(p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES))) {
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (812:12): [True: 0, False: 0]
  |  Branch (812:27): [True: 0, False: 0]
  ------------------
  813|    608|				cert_info.path.len = 0; /* use in mem cert from now on */
  814|    608|			}
  815|    608|		}
  816|       |		/* following will find the cached cert in cert_info */
  817|    608|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, private_obj, &cert_out);
  818|    608|		if (r < 0 || cert_out == NULL || cert_out->key == NULL) {
  ------------------
  |  Branch (818:7): [True: 310, False: 298]
  |  Branch (818:16): [True: 0, False: 298]
  |  Branch (818:36): [True: 7, False: 291]
  ------------------
  819|    317|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|    317|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  820|    317|			if (cert_out != NULL)
  ------------------
  |  Branch (820:8): [True: 7, False: 310]
  ------------------
  821|      7|				sc_pkcs15_free_certificate(cert_out);
  822|    317|			free(cert_der.value);
  823|    317|			continue;
  824|    317|		}
  825|       |
  826|       |		/* set the token name to the name of the CN of the first certificate */
  827|    291|		if (!token_name) {
  ------------------
  |  Branch (827:7): [True: 275, False: 16]
  ------------------
  828|    275|			u8 * cn_name = NULL;
  829|    275|			size_t cn_len = 0;
  830|    275|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  831|    275|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  832|    275|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  833|    275|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    275|#define SC_SUCCESS				0
  ------------------
  |  Branch (833:8): [True: 11, False: 264]
  ------------------
  834|     11|				token_name = realloc(cn_name, cn_len + 1);
  835|     11|				if (!token_name) {
  ------------------
  |  Branch (835:9): [True: 0, False: 11]
  ------------------
  836|      0|					sc_pkcs15_free_certificate(cert_out);
  837|      0|					free(cert_info.value.value);
  838|      0|					free(cn_name);
  839|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  840|      0|					LOG_TEST_GOTO_ERR(card->ctx, r,
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|      0|						"Failed to allocate memory");
  842|      0|				}
  843|     11|				token_name[cn_len] = '\0';
  844|     11|				free(p15card->tokeninfo->label);
  845|     11|				p15card->tokeninfo->label = token_name;
  846|     11|			}
  847|    275|		}
  848|       |
  849|       |		/*
  850|       |		 * get keyUsage if present save in ckis[i]
  851|       |		 * Will only use it if this in a non FED issued card
  852|       |		 * which has a CHUID with FASC-N not starting with 9999
  853|       |		 */
  854|       |
  855|    291|		if (follows_nist_fascn == 0) {
  ------------------
  |  Branch (855:7): [True: 289, False: 2]
  ------------------
  856|    289|			struct sc_object_id keyUsage_oid={{2,5,29,15,-1}};
  857|    289|			int r = 0;
  858|       |
  859|    289|			r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out,
  860|    289|				&keyUsage_oid,
  861|    289|				&ckis[i].cert_keyUsage, NULL);
  862|    289|			if ( r >= 0)
  ------------------
  |  Branch (862:9): [True: 89, False: 200]
  ------------------
  863|     89|				ckis[i].cert_keyUsage_present = 1;
  864|       |				/* TODO if no key usage, we could set all uses */
  865|    289|		}
  866|       |
  867|       |
  868|    291|		ckis[i].key_alg = cert_out->key->algorithm;
  869|    291|		switch (cert_out->key->algorithm) {
  870|    208|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    208|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (870:4): [True: 208, False: 83]
  ------------------
  871|       |				/* save pubkey_len for pub and priv */
  872|    208|				ckis[i].pubkey_len = cert_out->key->u.rsa.modulus.len * 8;
  873|       |				/* See RFC 5280 and PKCS#11 V2.40 */
  874|    208|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (874:9): [True: 89, False: 119]
  ------------------
  875|     89|					if (ckis[i].cert_keyUsage & SC_X509_DIGITAL_SIGNATURE) {
  ------------------
  |  |  614|     89|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  ------------------
  |  Branch (875:10): [True: 81, False: 8]
  ------------------
  876|     81|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT /* extra*/
  ------------------
  |  |  305|     81|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  877|     81|									|SC_PKCS15_PRKEY_USAGE_WRAP
  ------------------
  |  |  309|     81|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  878|     81|									|SC_PKCS15_PRKEY_USAGE_VERIFY
  ------------------
  |  |  311|     81|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  879|     81|									|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     81|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  880|     81|					        ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT /*extra */
  ------------------
  |  |  306|     81|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  881|     81|									|SC_PKCS15_PRKEY_USAGE_UNWRAP
  ------------------
  |  |  310|     81|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  882|     81|									|SC_PKCS15_PRKEY_USAGE_SIGN
  ------------------
  |  |  307|     81|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  883|     81|									|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     81|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  884|     81|					}
  885|     89|					if (ckis[i].cert_keyUsage & SC_X509_NON_REPUDIATION) {
  ------------------
  |  |  615|     89|#define SC_X509_NON_REPUDIATION       0x0002UL
  ------------------
  |  Branch (885:10): [True: 14, False: 75]
  ------------------
  886|     14|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT /* extra */
  ------------------
  |  |  305|     14|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  887|     14|									|SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  314|     14|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  888|     14|									|SC_PKCS15_PRKEY_USAGE_VERIFY
  ------------------
  |  |  311|     14|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  889|     14|									|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     14|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  890|     14|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT /*extra*/
  ------------------
  |  |  306|     14|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  891|     14|									|SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  314|     14|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  892|     14|									|SC_PKCS15_PRKEY_USAGE_SIGN
  ------------------
  |  |  307|     14|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  893|     14|									|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     14|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  894|     14|					}
  895|     89|					if (ckis[i].cert_keyUsage & SC_X509_KEY_ENCIPHERMENT) {
  ------------------
  |  |  616|     89|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  ------------------
  |  Branch (895:10): [True: 13, False: 76]
  ------------------
  896|     13|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  305|     13|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|     13|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  897|     13|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT| SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  306|     13|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT| SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|     13|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  898|     13|					}
  899|     89|					if (ckis[i].cert_keyUsage & SC_X509_DATA_ENCIPHERMENT) {
  ------------------
  |  |  617|     89|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
  |  Branch (899:10): [True: 86, False: 3]
  ------------------
  900|     86|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|     86|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  901|     86|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|     86|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  902|     86|					}
  903|     89|					if (ckis[i].cert_keyUsage & SC_X509_KEY_AGREEMENT) {
  ------------------
  |  |  618|     89|#define SC_X509_KEY_AGREEMENT         0x0010UL
  ------------------
  |  Branch (903:10): [True: 79, False: 10]
  ------------------
  904|     79|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     79|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  905|     79|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     79|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  906|     79|					}
  907|     89|					if (ckis[i].cert_keyUsage & SC_X509_KEY_CERT_SIGN) {
  ------------------
  |  |  619|     89|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  ------------------
  |  Branch (907:10): [True: 79, False: 10]
  ------------------
  908|     79|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  311|     79|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     79|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  909|     79|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     79|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  910|     79|					}
  911|     89|					if (ckis[i].cert_keyUsage & SC_X509_CRL_SIGN) {
  ------------------
  |  |  620|     89|#define SC_X509_CRL_SIGN              0x0040UL
  ------------------
  |  Branch (911:10): [True: 78, False: 11]
  ------------------
  912|     78|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  311|     78|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     78|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  913|     78|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     78|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  914|     78|					}
  915|     89|					if (ckis[i].cert_keyUsage & SC_X509_ENCIPHER_ONLY) {
  ------------------
  |  |  621|     89|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  ------------------
  |  Branch (915:10): [True: 79, False: 10]
  ------------------
  916|     79|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT|SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  305|     79|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT|SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|     79|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  917|     79|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  306|     79|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|     79|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  918|     79|					}
  919|     89|					if (ckis[i].cert_keyUsage & SC_X509_DECIPHER_ONLY) { /* TODO is this correct */
  ------------------
  |  |  622|     89|#define SC_X509_DECIPHER_ONLY         0x0100UL
  ------------------
  |  Branch (919:10): [True: 0, False: 89]
  ------------------
  920|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  921|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT|SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  305|      0|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT|SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  922|      0|					}
  923|     89|				}
  924|    208|				break;
  925|       |
  926|     83|			case SC_ALGORITHM_EC:
  ------------------
  |  |   70|     83|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (926:4): [True: 83, False: 208]
  ------------------
  927|     83|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|     83|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (927:4): [True: 0, False: 291]
  ------------------
  928|     83|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|     83|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (928:4): [True: 0, False: 291]
  ------------------
  929|     83|				ckis[i].pubkey_len = cert_out->key->u.ec.params.field_length;
  930|     83|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (930:9): [True: 0, False: 83]
  ------------------
  931|      0|					if (ckis[i].cert_keyUsage & SC_X509_DIGITAL_SIGNATURE) {
  ------------------
  |  |  614|      0|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  ------------------
  |  Branch (931:10): [True: 0, False: 0]
  ------------------
  932|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  933|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  934|      0|					}
  935|      0|					if (ckis[i].cert_keyUsage & SC_X509_NON_REPUDIATION) {
  ------------------
  |  |  615|      0|#define SC_X509_NON_REPUDIATION       0x0002UL
  ------------------
  |  Branch (935:10): [True: 0, False: 0]
  ------------------
  936|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  937|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  938|      0|					}
  939|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_ENCIPHERMENT) {
  ------------------
  |  |  616|      0|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  ------------------
  |  Branch (939:10): [True: 0, False: 0]
  ------------------
  940|      0|						ckis[i].pub_usage |= 0;
  941|      0|						ckis[i].priv_usage |= 0;
  942|      0|					}
  943|      0|					if (ckis[i].cert_keyUsage & SC_X509_DATA_ENCIPHERMENT) {
  ------------------
  |  |  617|      0|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
  |  Branch (943:10): [True: 0, False: 0]
  ------------------
  944|      0|						ckis[i].pub_usage |= 0;
  945|      0|						ckis[i].priv_usage |= 0;
  946|      0|					}
  947|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_AGREEMENT) {
  ------------------
  |  |  618|      0|#define SC_X509_KEY_AGREEMENT         0x0010UL
  ------------------
  |  Branch (947:10): [True: 0, False: 0]
  ------------------
  948|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  949|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  950|      0|					}
  951|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_CERT_SIGN) {
  ------------------
  |  |  619|      0|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  ------------------
  |  Branch (951:10): [True: 0, False: 0]
  ------------------
  952|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  953|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  954|      0|					}
  955|      0|					if (ckis[i].cert_keyUsage & SC_X509_CRL_SIGN) {
  ------------------
  |  |  620|      0|#define SC_X509_CRL_SIGN              0x0040UL
  ------------------
  |  Branch (955:10): [True: 0, False: 0]
  ------------------
  956|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  957|      0|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  958|      0|					}
  959|      0|					if (ckis[i].cert_keyUsage & SC_X509_ENCIPHER_ONLY) {
  ------------------
  |  |  621|      0|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  ------------------
  |  Branch (959:10): [True: 0, False: 0]
  ------------------
  960|      0|						ckis[i].pub_usage |= 0;
  961|      0|						ckis[i].priv_usage |= 0;
  962|      0|					}
  963|      0|					if (ckis[i].cert_keyUsage & SC_X509_DECIPHER_ONLY) {
  ------------------
  |  |  622|      0|#define SC_X509_DECIPHER_ONLY         0x0100UL
  ------------------
  |  Branch (963:10): [True: 0, False: 0]
  ------------------
  964|      0|						ckis[i].pub_usage |= 0;
  965|      0|						ckis[i].priv_usage |= 0;
  966|      0|					}
  967|      0|				}
  968|     83|				break;
  969|       |
  970|      0|			default:
  ------------------
  |  Branch (970:4): [True: 0, False: 291]
  ------------------
  971|      0|				sc_log(card->ctx, "Unsupported key.algorithm %lu", cert_out->key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  972|      0|				ckis[i].pubkey_len = 0; /* set some value for now */
  973|    291|		}
  974|    291|		if (i < PIV_NUM_KEYS) { /* Only save pub key if card can have private key */
  ------------------
  |  |  371|    291|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (974:7): [True: 280, False: 11]
  ------------------
  975|    280|			ckis[i].pubkey_from_cert = cert_out->key;
  976|    280|			cert_out->key = NULL;
  977|    280|		}
  978|    291|		sc_pkcs15_free_certificate(cert_out);
  979|       |
  980|    291|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  981|    291|		if (r < 0) {
  ------------------
  |  Branch (981:7): [True: 0, False: 291]
  ------------------
  982|      0|			sc_log(card->ctx,  " Failed to add cert obj r=%d",r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  983|      0|			continue;
  984|      0|		}
  985|    291|	}
  986|       |
  987|       |	/* set pins */
  988|    937|	sc_log(card->ctx,  "PIV-II adding pins...");
  ------------------
  |  |   71|    937|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  989|  3.74k|	for (i = 0; pins[i].label; i++) {
  ------------------
  |  Branch (989:14): [True: 2.81k, False: 937]
  ------------------
  990|  2.81k|		struct sc_pkcs15_auth_info pin_info;
  991|  2.81k|		struct sc_pkcs15_object   pin_obj;
  992|  2.81k|		const char * label;
  993|  2.81k|		int pin_ref;
  994|       |
  995|       |		/* the SignPIN is only used with minidriver */
  996|  2.81k|		if (pins[i].cardmod && (strcmp(card->ctx->app_name, "cardmod") != 0))
  ------------------
  |  Branch (996:7): [True: 937, False: 1.87k]
  |  Branch (996:26): [True: 937, False: 0]
  ------------------
  997|    937|			continue;
  998|       |
  999|  1.87k|		memset(&pin_info, 0, sizeof(pin_info));
 1000|  1.87k|		memset(&pin_obj,  0, sizeof(pin_obj));
 1001|       |
 1002|  1.87k|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  1.87k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1003|  1.87k|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
 1004|  1.87k|		pin_info.attrs.pin.reference     = pins[i].ref;
 1005|  1.87k|		pin_info.attrs.pin.flags         = pins[i].flags;
 1006|  1.87k|		pin_info.attrs.pin.type          = pins[i].type;
 1007|  1.87k|		pin_info.attrs.pin.min_length    = pins[i].minlen;
 1008|  1.87k|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
 1009|  1.87k|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
 1010|  1.87k|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
 1011|  1.87k|		pin_info.tries_left              = pins[i].tries_left;
 1012|  1.87k|		sc_format_path(pins[i].path, &pin_info.path);
 1013|       |
 1014|  1.87k|		label = pins[i].label;
 1015|  1.87k|		if ((i == 0 || pins[i].cardmod) &&
  ------------------
  |  Branch (1015:8): [True: 937, False: 937]
  |  Branch (1015:18): [True: 0, False: 937]
  ------------------
 1016|    937|			sc_card_ctl(card, SC_CARDCTL_PIV_PIN_PREFERENCE,
  ------------------
  |  Branch (1016:4): [True: 937, False: 0]
  ------------------
 1017|    937|					&pin_ref) == 0 &&
 1018|    937|				pin_ref == 0x00) { /* must be 80 for PIV pin, or 00 for Global PIN */
  ------------------
  |  Branch (1018:5): [True: 2, False: 935]
  ------------------
 1019|      2|			pin_info.attrs.pin.reference = pin_ref;
 1020|      2|			label = "Global PIN";
 1021|      2|		}
 1022|       |
 1023|  1.87k|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  1.87k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1024|  1.87k|		pin_obj.flags = pins[i].obj_flags;
 1025|  1.87k|		if ((i == 0 || pins[i].cardmod)) {
  ------------------
  |  Branch (1025:8): [True: 937, False: 937]
  |  Branch (1025:18): [True: 0, False: 937]
  ------------------
 1026|       |			/*
 1027|       |			 * according to description of "RESET RETRY COUNTER"
 1028|       |			 * command in specs PUK can only unblock PIV PIN
 1029|       |			 */
 1030|    937|			pin_obj.auth_id.len = 1;
 1031|    937|			pin_obj.auth_id.value[0] = 2;
 1032|    937|		}
 1033|       |
 1034|  1.87k|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
 1035|  1.87k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add PIN");
  ------------------
  |  |  184|  1.87k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.87k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.87k|	int _ret = (r); \
  |  |  |  |  178|  1.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.87k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  1.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1036|  1.87k|	}
 1037|       |
 1038|       |	/* set public keys */
 1039|       |	/* We may only need this during initialization when genkey
 1040|       |	 * gets the pubkey, but it can not be read from the card
 1041|       |	 * at a later time. The piv-tool can stash  pubkey in file
 1042|       |	 */
 1043|    937|	sc_log(card->ctx,  "PIV-II adding pub keys...");
  ------------------
  |  |   71|    937|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1044|  23.0k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  371|  23.0k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1044:14): [True: 22.1k, False: 921]
  ------------------
 1045|  22.1k|		struct sc_pkcs15_pubkey_info pubkey_info;
 1046|  22.1k|		struct sc_pkcs15_object     pubkey_obj;
 1047|  22.1k|		struct sc_pkcs15_pubkey *p15_key = NULL;
 1048|       |
 1049|  22.1k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
 1050|  22.1k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
 1051|       |
 1052|       |
 1053|  22.1k|		sc_pkcs15_format_id(pubkeys[i].id, &pubkey_info.id);
 1054|  22.1k|		pubkey_info.native        = 1;
 1055|  22.1k|		pubkey_info.key_reference = pubkeys[i].ref;
 1056|       |
 1057|       |//		sc_format_path(pubkeys[i].path, &pubkey_info.path);
 1058|       |
 1059|  22.1k|		strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  22.1k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1060|       |
 1061|  22.1k|		pubkey_obj.flags = pubkeys[i].obj_flags;
 1062|       |
 1063|  22.1k|		if (pubkeys[i].auth_id)
  ------------------
  |  Branch (1063:7): [True: 0, False: 22.1k]
  ------------------
 1064|      0|			sc_pkcs15_format_id(pubkeys[i].auth_id, &pubkey_obj.auth_id);
 1065|       |
 1066|       |		/* If no cert found, piv-tool may have stashed the pubkey
 1067|       |		 * so we can use it when generating a certificate request
 1068|       |		 * The file is a OpenSSL DER EVP_KEY, which looks like
 1069|       |		 * a certificate subjectPublicKeyInfo.
 1070|       |		 *
 1071|       |		 */
 1072|  22.1k|		if (ckis[i].cert_found == 0 ) { /*  no cert found */
  ------------------
  |  Branch (1072:7): [True: 21.5k, False: 582]
  ------------------
 1073|  21.5k|			sc_cardctl_piv_pubkey_info_t info = {0};
 1074|       |
 1075|  21.5k|			sc_log(card->ctx, "No cert for this pub key i=%d",i);
  ------------------
  |  |   71|  21.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1076|       |
 1077|       |			/* First try to use yubikey extension to pull missing public key from metadata */
 1078|  21.5k|			info.slot = pubkeys[i].ref;
 1079|  21.5k|			r = sc_card_ctl(card, SC_CARDCTL_PIV_YK_GET_PUBKEY_INFO, &info);
 1080|  21.5k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  21.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1080:8): [True: 163, False: 21.4k]
  ------------------
 1081|    163|				struct sc_pkcs15_pubkey pubkey = {0};
 1082|    163|				const unsigned char *p;
 1083|    163|				unsigned int cla, tag;
 1084|    163|				size_t tag_len;
 1085|    163|				int r;
 1086|       |
 1087|    163|				switch (info.algorithm) {
 1088|      1|				case 0x06: // RSA
  ------------------
  |  Branch (1088:5): [True: 1, False: 162]
  ------------------
 1089|     13|				case 0x07:
  ------------------
  |  Branch (1089:5): [True: 12, False: 151]
  ------------------
 1090|     70|				case 0x08:
  ------------------
  |  Branch (1090:5): [True: 57, False: 106]
  ------------------
 1091|     70|					p = info.pubkey.value;
 1092|     70|					r = sc_asn1_read_tag(&p, info.pubkey.len, &cla, &tag, &tag_len);
 1093|     70|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     70|#define SC_SUCCESS				0
  ------------------
  |  Branch (1093:10): [True: 11, False: 59]
  ------------------
 1094|     11|						sc_log(card->ctx, "Failed to parse RSA modulus: %d", r);
  ------------------
  |  |   71|     11|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1095|     11|						goto next_pubkey;
 1096|     11|					}
 1097|     59|					if ((tag | cla) != 0x81) {
  ------------------
  |  Branch (1097:10): [True: 19, False: 40]
  ------------------
 1098|     19|						sc_log(card->ctx, "Unexpected tag %u received, expected 0x81", (tag | cla));
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1099|     19|						goto next_pubkey;
 1100|     19|					}
 1101|     40|					pubkey.u.rsa.modulus.data = malloc(tag_len);
 1102|     40|					if (pubkey.u.rsa.modulus.data == NULL) {
  ------------------
  |  Branch (1102:10): [True: 0, False: 40]
  ------------------
 1103|      0|						sc_log(card->ctx, "Out of memory");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1104|      0|						goto next_pubkey;
 1105|      0|					}
 1106|     40|					memcpy(pubkey.u.rsa.modulus.data, p, tag_len);
 1107|     40|					pubkey.u.rsa.modulus.len = tag_len;
 1108|       |
 1109|     40|					p += tag_len;
 1110|     40|					r = sc_asn1_read_tag(&p, info.pubkey.len - (p - info.pubkey.value), &cla, &tag, &tag_len);
 1111|     40|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     40|#define SC_SUCCESS				0
  ------------------
  |  Branch (1111:10): [True: 15, False: 25]
  ------------------
 1112|     15|						sc_log(card->ctx, "Failed to parse RSA exponent: %d", r);
  ------------------
  |  |   71|     15|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1113|     15|						goto next_pubkey;
 1114|     15|					}
 1115|     25|					if ((tag | cla) != 0x82) {
  ------------------
  |  Branch (1115:10): [True: 25, False: 0]
  ------------------
 1116|     25|						sc_log(card->ctx, "Unexpected tag %u received, expected 0x82", (tag | cla));
  ------------------
  |  |   71|     25|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1117|     25|						goto next_pubkey;
 1118|     25|					}
 1119|      0|					pubkey.u.rsa.exponent.data = malloc(tag_len);
 1120|      0|					if (pubkey.u.rsa.exponent.data == NULL) {
  ------------------
  |  Branch (1120:10): [True: 0, False: 0]
  ------------------
 1121|      0|						sc_log(card->ctx, "Out of memory");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1122|      0|						goto next_pubkey;
 1123|      0|					}
 1124|      0|					memcpy(pubkey.u.rsa.exponent.data, p, tag_len);
 1125|      0|					pubkey.u.rsa.exponent.len = tag_len;
 1126|       |
 1127|      0|					pubkey.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
 1128|      0|					break;
 1129|     19|				case 0x11: // ECDSA
  ------------------
  |  Branch (1129:5): [True: 19, False: 144]
  ------------------
 1130|     42|				case 0x14:
  ------------------
  |  Branch (1130:5): [True: 23, False: 140]
  ------------------
 1131|     42|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1132|     42|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     42|#define SC_SUCCESS				0
  ------------------
  |  Branch (1132:10): [True: 32, False: 10]
  ------------------
 1133|     32|						sc_log(card->ctx, "Failed to parse ECDSA public key. %d", r);
  ------------------
  |  |   71|     32|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1134|     32|						goto next_pubkey;
 1135|     32|					}
 1136|     10|					pubkey.algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|     10|#define SC_ALGORITHM_EC		2
  ------------------
 1137|     10|					break;
 1138|     23|				case 0xE0: // Yubico extension: EDDSA
  ------------------
  |  Branch (1138:5): [True: 23, False: 140]
  ------------------
 1139|     23|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1140|     23|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
  |  Branch (1140:10): [True: 12, False: 11]
  ------------------
 1141|     12|						sc_log(card->ctx, "Failed to parse EDDSA public key. %d", r);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1142|     12|						goto next_pubkey;
 1143|     12|					}
 1144|     11|					pubkey.algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|     11|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1145|     11|					break;
 1146|     18|				case 0xE1: // Yubico extension: XEDDSA
  ------------------
  |  Branch (1146:5): [True: 18, False: 145]
  ------------------
 1147|     18|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1148|     18|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (1148:10): [True: 6, False: 12]
  ------------------
 1149|      6|						sc_log(card->ctx, "Failed to parse XEDDSA public key. %d", r);
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1150|      6|						goto next_pubkey;
 1151|      6|					}
 1152|     12|					pubkey.algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|     12|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1153|     12|					break;
 1154|     10|				default:
  ------------------
  |  Branch (1154:5): [True: 10, False: 153]
  ------------------
 1155|     10|					sc_log(card->ctx, "Got unknown algorithm ID %d", info.algorithm);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1156|     10|					goto next_pubkey;
 1157|    163|				}
 1158|       |
 1159|     33|				r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &pubkey,
 1160|     33|						&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1161|     33|				if (r < 0) {
  ------------------
  |  Branch (1161:9): [True: 0, False: 33]
  ------------------
 1162|      0|					goto next_pubkey;
 1163|      0|				}
 1164|     33|				r = sc_pkcs15_pubkey_from_spki_sequence(card->ctx,
 1165|     33|						pubkey_info.direct.spki.value, pubkey_info.direct.spki.len,
 1166|     33|						&p15_key);
 1167|     33|				if (r < 0) {
  ------------------
  |  Branch (1167:9): [True: 10, False: 23]
  ------------------
 1168|     10|					free(p15_key);
 1169|     10|					p15_key = NULL;
 1170|     10|				}
 1171|    163|next_pubkey:
 1172|    163|				sc_pkcs15_erase_pubkey(&pubkey);
 1173|    163|				if (!p15_key)
  ------------------
  |  Branch (1173:9): [True: 141, False: 22]
  ------------------
 1174|    141|					continue;
 1175|  21.4k|			} else {
 1176|  21.4k|				char *filename = NULL;
 1177|       |
 1178|  21.4k|				sc_log(card->ctx, "Failed to get public key. Not a Yubikey? rc=%d", r);
  ------------------
  |  |   71|  21.4k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1179|       |				/*
 1180|       |				 * If we used the piv-tool or ykman to generate a key,
 1181|       |				 * we would have saved the public key as a file.
 1182|       |				 * This code is only used while signing a request
 1183|       |				 * After the certificate is loaded on the card,
 1184|       |				 * the public key is extracted from the certificate.
 1185|       |				 */
 1186|       |
 1187|  21.4k|				sc_log(card->ctx, "DEE look for env %s",
  ------------------
  |  |   71|  42.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 21.4k, False: 0]
  |  |  ------------------
  ------------------
 1188|  21.4k|						pubkeys[i].getenvname ? pubkeys[i].getenvname : "NULL");
 1189|       |
 1190|  21.4k|				if (pubkeys[i].getenvname == NULL)
  ------------------
  |  Branch (1190:9): [True: 0, False: 21.4k]
  ------------------
 1191|      0|					continue;
 1192|       |
 1193|  21.4k|				filename = getenv(pubkeys[i].getenvname);
 1194|  21.4k|				sc_log(card->ctx, "DEE look for file %s", filename ? filename : "NULL");
  ------------------
  |  |   71|  42.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 21.4k]
  |  |  ------------------
  ------------------
 1195|  21.4k|				if (filename == NULL)
  ------------------
  |  Branch (1195:9): [True: 21.4k, False: 0]
  ------------------
 1196|  21.4k|					continue;
 1197|       |
 1198|      0|				sc_log(card->ctx, "Adding pubkey from file %s", filename);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1199|       |
 1200|      0|				r = sc_pkcs15_pubkey_from_spki_file(card->ctx, filename, &p15_key);
 1201|      0|				if (r < 0) {
  ------------------
  |  Branch (1201:9): [True: 0, False: 0]
  ------------------
 1202|      0|					free(p15_key);
 1203|      0|					continue;
 1204|      0|				}
 1205|       |
 1206|       |				/* Lets also try another method. */
 1207|      0|				r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, p15_key,
 1208|      0|						&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1209|      0|				LOG_TEST_GOTO_ERR(card->ctx, r, "SPKI encode public key error");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1210|      0|			}
 1211|       |
 1212|       |			/* Only get here if no cert, and the the above found the
 1213|       |			 * pub key file (actually the SPKI version). This only
 1214|       |			 * happens when trying initializing a card and have set
 1215|       |			 * env PIV_9A_KEY or 9C, 9D, 9E to point at the file.
 1216|       |			 * Or with Yubikey 5.3+ pulling this information from
 1217|       |			 * GET METADATA instruction.
 1218|       |			 *
 1219|       |			 * We will cache it using the PKCS15 emulation objects
 1220|       |			 */
 1221|       |
 1222|     22|			pubkey_info.path.len = 0;
 1223|       |
 1224|     22|			ckis[i].key_alg = p15_key->algorithm;
 1225|     22|			switch (p15_key->algorithm) {
 1226|      0|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1226:4): [True: 0, False: 22]
  ------------------
 1227|       |				/* save pubkey_len in pub and priv */
 1228|      0|				ckis[i].pubkey_len = p15_key->u.rsa.modulus.len * 8;
 1229|      0|				break;
 1230|      0|			case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1230:4): [True: 0, False: 22]
  ------------------
 1231|     11|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|     11|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1231:4): [True: 11, False: 11]
  ------------------
 1232|     22|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|     22|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1232:4): [True: 11, False: 11]
  ------------------
 1233|     22|				ckis[i].key_alg = p15_key->algorithm;
 1234|     22|				ckis[i].pubkey_len = p15_key->u.ec.params.field_length;
 1235|     22|				break;
 1236|      0|			default:
  ------------------
  |  Branch (1236:4): [True: 0, False: 22]
  ------------------
 1237|      0|				sc_log(card->ctx, "Unsupported key_alg %lu", p15_key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1238|      0|				continue;
 1239|     22|			}
 1240|     22|			ckis[i].pubkey_found = 1;
 1241|     22|			ckis[i].pubkey_from_file = 1;
 1242|     22|			pubkey_obj.emulated = p15_key;
 1243|     22|			p15_key = NULL;
 1244|     22|		}
 1245|    582|		else if (ckis[i].pubkey_from_cert)   {
  ------------------
  |  Branch (1245:12): [True: 277, False: 305]
  ------------------
 1246|    277|			r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, ckis[i].pubkey_from_cert,
 1247|    277|				&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1248|    277|			LOG_TEST_GOTO_ERR(card->ctx, r, "SPKI encode public key error");
  ------------------
  |  |  184|    277|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    277|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    277|	int _ret = (r); \
  |  |  |  |  178|    277|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 16, False: 261]
  |  |  |  |  ------------------
  |  |  |  |  179|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     16|		goto err; \
  |  |  |  |  182|     16|	} \
  |  |  |  |  183|    277|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 261]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1249|       |
 1250|    261|			pubkey_obj.emulated = ckis[i].pubkey_from_cert;
 1251|    261|			ckis[i].pubkey_from_cert = NULL;
 1252|    261|		}
 1253|       |
 1254|    588|		sc_log(card->ctx, "adding pubkey for %d keyalg=%lu", i, ckis[i].key_alg);
  ------------------
  |  |   71|    588|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1255|    588|		switch (ckis[i].key_alg) {
 1256|    179|		case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    179|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1256:3): [True: 179, False: 409]
  ------------------
 1257|    179|			if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1257:8): [True: 85, False: 94]
  ------------------
 1258|     85|				pubkey_info.usage = ckis[i].pub_usage;
 1259|     94|			} else {
 1260|     94|				pubkey_info.usage = pubkeys[i].usage_rsa;
 1261|     94|			}
 1262|    179|			pubkey_info.modulus_length = ckis[i].pubkey_len;
 1263|    179|			strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    179|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1264|       |
 1265|       |			/* should not fail */
 1266|    179|			r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1267|    179|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add RSA pubkey");
  ------------------
  |  |  184|    179|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    179|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    179|	int _ret = (r); \
  |  |  |  |  178|    179|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1268|       |
 1269|    179|			ckis[i].pubkey_found = 1;
 1270|    179|			break;
 1271|     82|		case SC_ALGORITHM_EC:
  ------------------
  |  |   70|     82|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1271:3): [True: 82, False: 506]
  ------------------
 1272|     93|		case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|     93|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1272:3): [True: 11, False: 577]
  ------------------
 1273|    104|		case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    104|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1273:3): [True: 11, False: 577]
  ------------------
 1274|    104|			if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1274:8): [True: 0, False: 104]
  ------------------
 1275|      0|				pubkey_info.usage = ckis[i].pub_usage;
 1276|    104|			} else {
 1277|    104|				pubkey_info.usage = pubkeys[i].usage_ec;
 1278|    104|			}
 1279|       |
 1280|    104|			pubkey_info.field_length = ckis[i].pubkey_len;
 1281|    104|			strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    104|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1282|       |
 1283|       |			/* should not fail */
 1284|       |
 1285|    104|			if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    104|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1285:8): [True: 11, False: 93]
  ------------------
 1286|     11|				r = sc_pkcs15emu_add_eddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1287|     93|			else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     93|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1287:13): [True: 11, False: 82]
  ------------------
 1288|     11|				r = sc_pkcs15emu_add_xeddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1289|     82|			else
 1290|     82|				r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1291|       |
 1292|    104|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add EC pubkey");
  ------------------
  |  |  184|    104|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    104|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    104|	int _ret = (r); \
  |  |  |  |  178|    104|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 104]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 104]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1293|       |
 1294|    104|			ckis[i].pubkey_found = 1;
 1295|    104|			break;
 1296|    305|		default:
  ------------------
  |  Branch (1296:3): [True: 305, False: 283]
  ------------------
 1297|    305|			sc_log(card->ctx, "key_alg %lu not supported", ckis[i].key_alg);
  ------------------
  |  |   71|    305|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1298|    305|			continue;
 1299|    588|		}
 1300|    283|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x",
  ------------------
  |  |   71|    283|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1301|    283|				ckis[i].cert_keyUsage_present, pubkey_info.usage);
 1302|    283|	}
 1303|       |
 1304|       |
 1305|       |	/* set private keys */
 1306|    921|	sc_log(card->ctx,  "PIV-II adding private keys...");
  ------------------
  |  |   71|    921|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|  23.0k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  371|  23.0k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1307:14): [True: 22.1k, False: 921]
  ------------------
 1308|  22.1k|		struct sc_pkcs15_prkey_info prkey_info;
 1309|  22.1k|		struct sc_pkcs15_object     prkey_obj;
 1310|  22.1k|		u8 pin_policy = prkeys[i].ref;
 1311|       |
 1312|  22.1k|		memset(&prkey_info, 0, sizeof(prkey_info));
 1313|  22.1k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
 1314|       |
 1315|  22.1k|		if (ckis[i].cert_found == 0 && ckis[i].pubkey_found == 0)
  ------------------
  |  Branch (1315:7): [True: 21.5k, False: 559]
  |  Branch (1315:34): [True: 21.5k, False: 22]
  ------------------
 1316|  21.5k|			continue; /* i.e. no cert or pubkey */
 1317|       |
 1318|    581|		sc_pkcs15_format_id(prkeys[i].id, &prkey_info.id);
 1319|    581|		prkey_info.native        = 1;
 1320|    581|		prkey_info.key_reference = prkeys[i].ref;
 1321|    581|		sc_format_path(prkeys[i].path, &prkey_info.path);
 1322|       |
 1323|    581|		strncpy(prkey_obj.label, prkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    581|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1324|    581|		prkey_obj.flags = prkeys[i].obj_flags;
 1325|    581|		prkey_obj.user_consent = prkeys[i].user_consent; /* only Sign key */
 1326|       |
 1327|    581|		r = sc_card_ctl(p15card->card, SC_CARDCTL_PIV_YK_PIN_POLICY, &pin_policy);
 1328|    581|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    581|#define SC_SUCCESS				0
  ------------------
  |  Branch (1328:7): [True: 19, False: 562]
  ------------------
 1329|     19|			switch (pin_policy) {
 1330|      1|			case 0x01:
  ------------------
  |  Branch (1330:4): [True: 1, False: 18]
  ------------------
 1331|      1|				prkey_obj.flags &= ~SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      1|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1332|      1|				sc_log(card->ctx, "PIN is never checked");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1333|      1|				break;
 1334|      1|			case 0x02:
  ------------------
  |  Branch (1334:4): [True: 1, False: 18]
  ------------------
 1335|      1|				prkey_obj.user_consent = 0;
 1336|      1|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1337|      1|				sc_log(card->ctx, "PIN is checked once for the session");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1338|      1|				break;
 1339|      2|			case 0x03:
  ------------------
  |  Branch (1339:4): [True: 2, False: 17]
  ------------------
 1340|      2|				prkey_obj.user_consent = 1;
 1341|      2|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1342|      2|				sc_log(card->ctx, "PIN is verified just before operation");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1343|      2|				break;
 1344|     14|			case 0x00:
  ------------------
  |  Branch (1344:4): [True: 14, False: 5]
  ------------------
 1345|     15|			default:
  ------------------
  |  Branch (1345:4): [True: 1, False: 18]
  ------------------
 1346|     15|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1347|     15|				break;
 1348|     19|			}
 1349|     19|		} else
 1350|    562|			sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1351|       |
 1352|       |		/* If using minidriver, use Sign PIN  for 9C key */
 1353|    581|		if (prkey_obj.user_consent && (strcmp(card->ctx->app_name, "cardmod") == 0))
  ------------------
  |  Branch (1353:7): [True: 77, False: 504]
  |  Branch (1353:33): [True: 0, False: 77]
  ------------------
 1354|      0|			sc_pkcs15_format_id("03", &prkey_obj.auth_id);
 1355|       |
 1356|       |		/*
 1357|       |		 * When no cert is present and a pubkey in a file was found,
 1358|       |		 * means the caller is initializing a card. A sign operation
 1359|       |		 * will be required to sign a certificate request even if
 1360|       |		 * normal usage would not allow it. Set SC_PKCS15_PRKEY_USAGE_SIGN
 1361|       |		 * TODO if code is added to allow key generation and request
 1362|       |		 * sign in the same session, similar code will be needed.
 1363|       |		 * Exclude XEDDSA keys as they are not signing capable
 1364|       |		 */
 1365|       |
 1366|    581|		if (ckis[i].pubkey_from_file == 1) {
  ------------------
  |  Branch (1366:7): [True: 22, False: 559]
  ------------------
 1367|     22|			switch (ckis[i].key_alg) {
 1368|     11|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|     11|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1368:4): [True: 11, False: 11]
  ------------------
 1369|     11|				break;
 1370|     11|			default:
  ------------------
  |  Branch (1370:4): [True: 11, False: 11]
  ------------------
 1371|     11|				prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     11|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
 1372|     11|				sc_log(card->ctx, "Adding SC_PKCS15_PRKEY_USAGE_SIGN");
  ------------------
  |  |   71|     11|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1373|     11|				break;
 1374|     22|			}
 1375|     22|		}
 1376|       |
 1377|    581|		if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1377:7): [True: 85, False: 496]
  ------------------
 1378|     85|			prkey_info.usage |= ckis[i].priv_usage;
 1379|       |			/* If retired key and non gov cert has NONREPUDIATION, treat as user_consent */
 1380|     85|			if (i >= 4 && (ckis[i].priv_usage & SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)) {
  ------------------
  |  |  314|     59|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  |  Branch (1380:8): [True: 59, False: 26]
  |  Branch (1380:18): [True: 3, False: 56]
  ------------------
 1381|      3|				prkey_obj.user_consent = 1;
 1382|      3|			}
 1383|     85|		}
 1384|       |
 1385|    581|		switch (ckis[i].key_alg) {
 1386|    172|		case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    172|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1386:3): [True: 172, False: 409]
  ------------------
 1387|    172|			if (!ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1387:8): [True: 87, False: 85]
  ------------------
 1388|     87|				prkey_info.usage |= prkeys[i].usage_rsa;
 1389|     87|			}
 1390|    172|			prkey_info.modulus_length = ckis[i].pubkey_len;
 1391|    172|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
 1392|    172|			break;
 1393|     82|		case SC_ALGORITHM_EC:
  ------------------
  |  |   70|     82|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1393:3): [True: 82, False: 499]
  ------------------
 1394|     93|		case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|     93|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1394:3): [True: 11, False: 570]
  ------------------
 1395|    104|		case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    104|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1395:3): [True: 11, False: 570]
  ------------------
 1396|    104|			if (!ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1396:8): [True: 104, False: 0]
  ------------------
 1397|    104|				prkey_info.usage |= prkeys[i].usage_ec;
 1398|    104|			}
 1399|    104|			prkey_info.field_length = ckis[i].pubkey_len;
 1400|    104|			sc_log(card->ctx, "DEE added key_alg %2.2lx prkey_obj.flags %8.8x",
  ------------------
  |  |   71|    104|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1401|    104|					ckis[i].key_alg, prkey_obj.flags);
 1402|       |
 1403|    104|			if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    104|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1403:8): [True: 11, False: 93]
  ------------------
 1404|     11|				r = sc_pkcs15emu_add_eddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1405|     93|			else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     93|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1405:13): [True: 11, False: 82]
  ------------------
 1406|     11|				r = sc_pkcs15emu_add_xeddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1407|     82|			else
 1408|     82|				r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
 1409|    104|			break;
 1410|    305|		default:
  ------------------
  |  Branch (1410:3): [True: 305, False: 276]
  ------------------
 1411|    305|			sc_log(card->ctx, "Unsupported key_alg %lu", ckis[i].key_alg);
  ------------------
  |  |   71|    305|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1412|    305|			r = 0; /* we just skip this one */
 1413|    581|		}
 1414|    581|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x", ckis[i].cert_keyUsage_present, prkey_info.usage);
  ------------------
  |  |   71|    581|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1415|    581|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add Private key");
  ------------------
  |  |  184|    581|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    581|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    581|	int _ret = (r); \
  |  |  |  |  178|    581|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 581]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    581|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 581]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|    581|	}
 1417|       |
 1418|    921|	p15card->ops.get_guid = piv_get_guid;
 1419|       |
 1420|    921|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    921|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    921|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    921|	int _ret = r; \
  |  |  |  |  155|    921|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 921, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    921|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 921]
  |  |  |  |  ------------------
  |  |  |  |  157|    921|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    921|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    921|	return _ret; \
  |  |  |  |  163|    921|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1421|     16|err:
 1422|    416|	for (i = 0; i < PIV_NUM_CERTS; i++) {
  ------------------
  |  |  370|    416|#define PIV_NUM_CERTS 25
  ------------------
  |  Branch (1422:14): [True: 400, False: 16]
  ------------------
 1423|    400|		sc_pkcs15_free_pubkey(ckis[i].pubkey_from_cert);
 1424|    400|	}
 1425|     16|	sc_pkcs15_card_clear(p15card);
 1426|     16|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1427|     16|}
pkcs15-piv.c:yk_copy_pubkey_from_tag:
  249|     83|{
  250|     83|	const unsigned char *p;
  251|     83|	unsigned int cla, tag;
  252|     83|	size_t tag_len;
  253|     83|	int r;
  254|       |
  255|     83|	p = info->pubkey.value;
  256|     83|	r = sc_asn1_read_tag(&p, info->pubkey.len, &cla, &tag, &tag_len);
  257|     83|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     83|#define SC_SUCCESS				0
  ------------------
  |  Branch (257:6): [True: 31, False: 52]
  ------------------
  258|     31|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     31|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  259|     31|	}
  260|     52|	if ((tag | cla) != tag_exp) {
  ------------------
  |  Branch (260:6): [True: 19, False: 33]
  ------------------
  261|     19|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     19|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  262|     19|	}
  263|     33|	dst->value = malloc(tag_len);
  264|     33|	if (dst->value == NULL) {
  ------------------
  |  Branch (264:6): [True: 0, False: 33]
  ------------------
  265|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  266|      0|	}
  267|     33|	memcpy(dst->value, p, tag_len);
  268|     33|	dst->len = tag_len;
  269|       |
  270|     33|	return SC_SUCCESS;
  ------------------
  |  |   28|     33|#define SC_SUCCESS				0
  ------------------
  271|     33|}

sc_pkcs15_decode_prkdf_entry:
  156|     50|{
  157|     50|	sc_context_t *ctx = p15card->card->ctx;
  158|     50|	struct sc_pkcs15_prkey_info info;
  159|     50|	int r, i, gostr3410_params[3];
  160|     50|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  161|     50|	size_t usage_len = sizeof(info.usage);
  162|     50|	size_t af_len = sizeof(info.access_flags);
  163|     50|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  164|     50|	struct sc_asn1_entry asn1_com_prkey_attr[C_ASN1_COM_PRKEY_ATTR_SIZE];
  165|     50|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  166|     50|	struct sc_asn1_entry asn1_prk_rsa_attr[C_ASN1_PRK_RSA_ATTR_SIZE];
  167|     50|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOSTR3410KEY_ATTR_SIZE];
  168|     50|	struct sc_asn1_entry asn1_prk_gostr3410_attr[C_ASN1_PRK_GOSTR3410_ATTR_SIZE];
  169|     50|	struct sc_asn1_entry asn1_ecckey_attr[C_ASN1_ECCKEY_ATTR];
  170|     50|	struct sc_asn1_entry asn1_prk_ecc_attr[C_ASN1_PRK_ECC_ATTR];
  171|     50|	struct sc_asn1_entry asn1_prkey[C_ASN1_PRKEY_SIZE];
  172|     50|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  173|     50|	struct sc_asn1_pkcs15_object rsa_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_rsa_attr};
  174|     50|	struct sc_asn1_pkcs15_object gostr3410_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_gostr3410_attr};
  175|     50|	struct sc_asn1_pkcs15_object ecc_prkey_obj = { obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_ecc_attr };
  176|     50|	u8 ec_domain[32];
  177|     50|	size_t ec_domain_len = sizeof(ec_domain);
  178|       |
  179|     50|	sc_copy_asn1_entry(c_asn1_prkey, asn1_prkey);
  180|     50|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  181|       |
  182|     50|	sc_copy_asn1_entry(c_asn1_prk_rsa_attr, asn1_prk_rsa_attr);
  183|     50|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  184|     50|	sc_copy_asn1_entry(c_asn1_prk_gostr3410_attr, asn1_prk_gostr3410_attr);
  185|     50|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  186|     50|	sc_copy_asn1_entry(c_asn1_prk_ecc_attr, asn1_prk_ecc_attr);
  187|     50|	sc_copy_asn1_entry(c_asn1_ecckey_attr, asn1_ecckey_attr);
  188|       |
  189|     50|	sc_copy_asn1_entry(c_asn1_com_prkey_attr, asn1_com_prkey_attr);
  190|     50|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  191|       |
  192|     50|	sc_format_asn1_entry(asn1_prkey + 0, &rsa_prkey_obj, NULL, 0);
  193|     50|	sc_format_asn1_entry(asn1_prkey + 1, &ecc_prkey_obj, NULL, 0);
  194|     50|	sc_format_asn1_entry(asn1_prkey + 2, &gostr3410_prkey_obj, NULL, 0);
  195|       |
  196|     50|	sc_format_asn1_entry(asn1_prk_rsa_attr + 0, asn1_rsakey_attr, NULL, 0);
  197|     50|	sc_format_asn1_entry(asn1_prk_gostr3410_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  198|     50|	sc_format_asn1_entry(asn1_prk_ecc_attr + 0, asn1_ecckey_attr, NULL, 0);
  199|       |
  200|     50|	sc_format_asn1_entry(asn1_rsakey_attr + 0, &info.path, NULL, 0);
  201|     50|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info.modulus_length, NULL, 0);
  202|       |
  203|     50|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info.path, NULL, 0);
  204|     50|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  205|     50|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  206|     50|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  207|       |
  208|     50|	sc_format_asn1_entry(asn1_ecckey_attr + 0, &info.path, NULL, 0);
  209|     50|	sc_format_asn1_entry(asn1_ecckey_attr + 1, &info.field_length, NULL, 0);
  210|     50|	sc_format_asn1_entry(asn1_ecckey_attr + 3, ec_domain, &ec_domain_len, 0);
  211|       |
  212|     50|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  213|     50|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  214|     50|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  215|     50|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  216|     50|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  217|       |
  218|    850|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|  1.70k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (218:12): [True: 800, False: 50]
  |  Branch (218:45): [True: 800, False: 0]
  ------------------
  219|    800|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  220|     50|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  221|       |
  222|     50|	sc_format_asn1_entry(asn1_com_prkey_attr + 0, &info.subject.value, &info.subject.len, 0);
  223|       |
  224|       |	/* Fill in defaults */
  225|     50|	memset(&info, 0, sizeof(info));
  226|     50|	info.key_reference = -1;
  227|     50|	info.native = 1;
  228|     50|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  229|       |
  230|     50|	r = sc_asn1_decode_choice(ctx, asn1_prkey, *buf, *buflen, buf, buflen);
  231|     50|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     50|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (231:6): [True: 3, False: 47]
  ------------------
  232|      3|		goto err;
  233|     47|	LOG_TEST_GOTO_ERR(ctx, r, "PrKey DF ASN.1 decoding failed");
  ------------------
  |  |  184|     47|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     47|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     47|	int _ret = (r); \
  |  |  |  |  178|     47|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 27, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  179|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     27|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     27|		goto err; \
  |  |  |  |  182|     27|	} \
  |  |  |  |  183|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     20|	if (asn1_prkey[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     20|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (234:6): [True: 13, False: 7]
  ------------------
  235|     13|		obj->type = SC_PKCS15_TYPE_PRKEY_RSA;
  ------------------
  |  |  419|     13|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  236|     13|	}
  237|      7|	else if (asn1_prkey[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      7|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (237:11): [True: 4, False: 3]
  ------------------
  238|      4|		obj->type = SC_PKCS15_TYPE_PRKEY_EC;
  ------------------
  |  |  421|      4|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  239|      4|#ifdef ENABLE_OPENSSL
  240|      4|		if (!(asn1_ecckey_attr[1].flags & SC_ASN1_PRESENT) && (asn1_ecckey_attr[3].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      4|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              		if (!(asn1_ecckey_attr[1].flags & SC_ASN1_PRESENT) && (asn1_ecckey_attr[3].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      2|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (240:7): [True: 2, False: 2]
  |  Branch (240:57): [True: 1, False: 1]
  ------------------
  241|      1|			const unsigned char *p = ec_domain;
  242|      1|			ASN1_OBJECT *object = d2i_ASN1_OBJECT(NULL, &p, ec_domain_len);
  243|      1|			int nid;
  244|      1|			EC_GROUP *group;
  245|      1|			if (!object) {
  ------------------
  |  Branch (245:8): [True: 1, False: 0]
  ------------------
  246|      1|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  247|      1|				goto err;
  248|      1|			}
  249|      0|			nid = OBJ_obj2nid(object);
  250|      0|			ASN1_OBJECT_free(object);
  251|      0|			if (nid == NID_undef) {
  ------------------
  |  Branch (251:8): [True: 0, False: 0]
  ------------------
  252|      0|				sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  253|      0|				r = SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  254|      0|				goto err;
  255|      0|			}
  256|      0|			group = EC_GROUP_new_by_curve_name(nid);
  257|      0|			if (!group) {
  ------------------
  |  Branch (257:8): [True: 0, False: 0]
  ------------------
  258|      0|				sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  259|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  260|      0|				goto err;
  261|      0|			}
  262|      0|			info.field_length = EC_GROUP_order_bits(group);
  263|      0|			EC_GROUP_free(group);
  264|      0|			if (!info.field_length) {
  ------------------
  |  Branch (264:8): [True: 0, False: 0]
  ------------------
  265|      0|				sc_log_openssl(ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  266|      0|				r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  267|      0|				goto err;
  268|      0|			}
  269|      0|		}
  270|      4|#endif
  271|      4|	}
  272|      3|	else if (asn1_prkey[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      3|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:11): [True: 1, False: 2]
  ------------------
  273|       |		/* FIXME proper handling of gost parameters without the need of
  274|       |		 * allocating data here. this would also make sc_pkcs15_free_key_params
  275|       |		 * obsolete */
  276|      1|		obj->type = SC_PKCS15_TYPE_PRKEY_GOSTR3410;
  ------------------
  |  |  420|      1|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  277|      1|		if (info.modulus_length != 0 || info.params.len != 0) {
  ------------------
  |  Branch (277:7): [True: 0, False: 1]
  |  Branch (277:35): [True: 0, False: 1]
  ------------------
  278|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  279|      0|			goto err;
  280|      0|		}
  281|      1|		info.modulus_length = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      1|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
  282|      1|		info.params.len = sizeof(struct sc_pkcs15_keyinfo_gostparams);
  283|      1|		info.params.data = malloc(info.params.len);
  284|      1|		if (info.params.data == NULL) {
  ------------------
  |  Branch (284:7): [True: 0, False: 1]
  ------------------
  285|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  286|      0|			goto err;
  287|      0|		}
  288|      1|		keyinfo_gostparams = info.params.data;
  289|      1|		keyinfo_gostparams->gostr3410 = gostr3410_params[0];
  290|      1|		keyinfo_gostparams->gostr3411 = gostr3410_params[1];
  291|      1|		keyinfo_gostparams->gost28147 = gostr3410_params[2];
  292|      1|	}
  293|      2|	else {
  294|      2|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  295|      2|		LOG_TEST_GOTO_ERR(ctx, r, "Neither RSA or GOSTR3410 or ECC key in PrKDF entry.");
  ------------------
  |  |  184|      2|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      2|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      2|	int _ret = (r); \
  |  |  |  |  178|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      2|		goto err; \
  |  |  |  |  182|      2|	} \
  |  |  |  |  183|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|      2|	}
  297|       |
  298|     17|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (298:6): [True: 17, False: 0]
  |  Branch (298:23): [True: 0, False: 0]
  ------------------
  299|     17|		if (!p15card->file_app) {
  ------------------
  |  Branch (299:7): [True: 0, False: 17]
  ------------------
  300|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  301|      0|			goto err;
  302|      0|		}
  303|     17|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path);
  304|     17|		if (r < 0) {
  ------------------
  |  Branch (304:7): [True: 0, False: 17]
  ------------------
  305|      0|			goto err;
  306|      0|		}
  307|     17|	}
  308|      0|	else   {
  309|      0|		info.path.aid = p15card->app->ddo.aid;
  310|      0|	}
  311|     17|	sc_log(ctx, "PrivKey path '%s'", sc_print_path(&info.path));
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  312|       |
  313|       |	/* OpenSC 0.11.4 and older encoded "keyReference" as a negative value.
  314|       |	 * Fixed in 0.11.5 we need to add a hack, so old cards continue to work. */
  315|     17|	if (info.key_reference < -1)
  ------------------
  |  Branch (315:6): [True: 1, False: 16]
  ------------------
  316|      1|		info.key_reference += 256;
  317|       |
  318|       |	/* Check the auth_id - if not present, try and find it in access rules */
  319|     17|	if ((obj->flags & SC_PKCS15_CO_FLAG_PRIVATE) && (obj->auth_id.len == 0)) {
  ------------------
  |  |   50|     17|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (319:6): [True: 3, False: 14]
  |  Branch (319:50): [True: 2, False: 1]
  ------------------
  320|      2|		sc_log(ctx, "Private key %s has no auth ID - checking AccessControlRules",
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  321|      2|				sc_pkcs15_print_id(&info.id));
  322|       |
  323|       |		/* Search in the access_rules for an appropriate auth ID */
  324|     18|		for (i = 0; i < SC_PKCS15_MAX_ACCESS_RULES; i++) {
  ------------------
  |  |   42|     18|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (324:15): [True: 16, False: 2]
  ------------------
  325|       |			/* If access_mode is one of the private key usage modes */
  326|     16|			if (obj->access_rules[i].access_mode &
  ------------------
  |  Branch (326:8): [True: 0, False: 16]
  ------------------
  327|     16|					(SC_PKCS15_ACCESS_RULE_MODE_EXECUTE |
  ------------------
  |  |  337|     16|#define SC_PKCS15_ACCESS_RULE_MODE_EXECUTE      0x04
  ------------------
  328|     16|					 SC_PKCS15_ACCESS_RULE_MODE_PSO_CDS |
  ------------------
  |  |  340|     16|#define SC_PKCS15_ACCESS_RULE_MODE_PSO_CDS      0x20
  ------------------
  329|     16|					 SC_PKCS15_ACCESS_RULE_MODE_PSO_DECRYPT |
  ------------------
  |  |  342|     16|#define SC_PKCS15_ACCESS_RULE_MODE_PSO_DECRYPT  0x80
  ------------------
  330|     16|					 SC_PKCS15_ACCESS_RULE_MODE_INT_AUTH)) {
  ------------------
  |  |  344|     16|#define SC_PKCS15_ACCESS_RULE_MODE_INT_AUTH     0x200
  ------------------
  331|      0|				if (obj->access_rules[i].auth_id.len != 0) {
  ------------------
  |  Branch (331:9): [True: 0, False: 0]
  ------------------
  332|       |					/* Found an auth ID to use for private key access */
  333|      0|					obj->auth_id = obj->access_rules[i].auth_id;
  334|      0|					sc_log(ctx, "Auth ID found - %s",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  335|      0|						 sc_pkcs15_print_id(&obj->auth_id));
  336|      0|					break;
  337|      0|				}
  338|      0|			}
  339|     16|		}
  340|       |
  341|       |		/* No auth ID found */
  342|      2|		if (i == SC_PKCS15_MAX_ACCESS_RULES)
  ------------------
  |  |   42|      2|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (342:7): [True: 2, False: 0]
  ------------------
  343|      2|			sc_log(ctx, "Warning: No auth ID found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  344|      2|	}
  345|       |
  346|     17|	obj->data = malloc(sizeof(info));
  347|     17|	if (obj->data == NULL) {
  ------------------
  |  Branch (347:6): [True: 0, False: 17]
  ------------------
  348|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  349|      0|		goto err;
  350|      0|	}
  351|     17|	memcpy(obj->data, &info, sizeof(info));
  352|       |
  353|     17|	sc_log(ctx, "Key Subject %s", sc_dump_hex(info.subject.value, info.subject.len));
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  354|     17|	sc_log(ctx, "Key path %s", sc_print_path(&info.path));
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  355|       |
  356|     17|	r = SC_SUCCESS;
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  357|       |
  358|     50|err:
  359|     50|	if (r < 0) {
  ------------------
  |  Branch (359:6): [True: 33, False: 17]
  ------------------
  360|       |		/* This might have allocated something. If so, clear it now */
  361|     33|		free(info.subject.value);
  362|     33|		sc_pkcs15_free_key_params(&info.params);
  363|     33|	}
  364|       |
  365|     50|	return r;
  366|     17|}
sc_pkcs15_free_prkey_info:
  592|  2.03k|{
  593|  2.03k|	if (!key)
  ------------------
  |  Branch (593:6): [True: 0, False: 2.03k]
  ------------------
  594|      0|		return;
  595|       |
  596|  2.03k|	if (key->subject.value)
  ------------------
  |  Branch (596:6): [True: 0, False: 2.03k]
  ------------------
  597|      0|		free(key->subject.value);
  598|       |
  599|  2.03k|	sc_pkcs15_free_key_params(&key->params);
  600|       |
  601|  2.03k|	sc_aux_data_free(&key->aux_data);
  602|       |
  603|  2.03k|	free(key);
  604|  2.03k|}

sc_pkcs15emu_pteid_init_ex:
  349|  9.28k|{
  350|  9.28k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  9.28k|#define SC_SUCCESS				0
  ------------------
  351|  9.28k|	sc_context_t *ctx = p15card->card->ctx;
  352|  9.28k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  9.28k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.28k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.28k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|       |
  354|       |	/* check for proper card */
  355|  9.28k|	r = pteid_detect_card(p15card->card);
  356|  9.28k|	if (r == SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  9.28k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (356:6): [True: 8.78k, False: 498]
  ------------------
  357|  9.28k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  8.78k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.78k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.78k|	int _ret = r; \
  |  |  |  |  155|  8.78k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.78k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.78k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.78k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.78k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.78k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.78k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.78k|	return _ret; \
  |  |  |  |  163|  8.78k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|       |	/* ok: initialize and return */
  359|    498|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_pteid_init(p15card));
  ------------------
  |  |  164|    498|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    498|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    498|	int _ret = r; \
  |  |  |  |  155|    498|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 498, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    498|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    360|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 360, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  157|    498|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    498|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    498|	return _ret; \
  |  |  |  |  163|    498|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|    498|}
pkcs15-pteid.c:pteid_detect_card:
  342|  9.78k|{
  343|  9.78k|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID)
  ------------------
  |  Branch (343:6): [True: 996, False: 8.78k]
  ------------------
  344|    996|		return SC_SUCCESS;
  ------------------
  |  |   28|    996|#define SC_SUCCESS				0
  ------------------
  345|  8.78k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  8.78k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  346|  9.78k|}
pkcs15-pteid.c:sc_pkcs15emu_pteid_init:
  143|    498|{
  144|    498|	u8 buf[1024];
  145|    498|	sc_pkcs15_df_t *df;
  146|    498|	sc_pkcs15_object_t *p15_obj;
  147|    498|	sc_path_t path;
  148|    498|	struct sc_file *file = NULL;
  149|    498|	size_t len;
  150|    498|	int rv;
  151|    498|	int i;
  152|       |
  153|    498|	sc_context_t *ctx = p15card->card->ctx;
  154|    498|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    498|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    498|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    498|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    498|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 498]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Check for correct card atr */
  157|    498|	if (pteid_detect_card(p15card->card) != SC_SUCCESS)
  ------------------
  |  |   28|    498|#define SC_SUCCESS				0
  ------------------
  |  Branch (157:6): [True: 0, False: 498]
  ------------------
  158|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  159|       |
  160|    498|	sc_log(p15card->card->ctx, "Selecting application DF");
  ------------------
  |  |   71|    498|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  161|    498|	sc_format_path("4F00", &path);
  162|    498|	rv = sc_select_file(p15card->card, &path, &file);
  163|    498|	if (rv != SC_SUCCESS || !file)
  ------------------
  |  |   28|    996|#define SC_SUCCESS				0
  ------------------
  |  Branch (163:6): [True: 239, False: 259]
  |  Branch (163:26): [True: 0, False: 259]
  ------------------
  164|    239|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    239|#define SC_ERROR_INTERNAL			-1400
  ------------------
  165|       |	/* set the application DF */
  166|    259|	sc_file_free(p15card->file_app);
  167|    259|	p15card->file_app = file;
  168|       |
  169|       |	/* Load TokenInfo */
  170|    259|	len = sizeof(buf);
  171|    259|	rv = dump_ef(p15card->card, "4F005032", buf, &len);
  172|    259|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    259|#define SC_SUCCESS				0
  ------------------
  |  Branch (172:6): [True: 70, False: 189]
  ------------------
  173|     70|		sc_log(ctx, "Reading of EF.TOKENINFO failed: %d", rv);
  ------------------
  |  |   71|     70|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  174|     70|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     70|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     70|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     70|	return _ret; \
  |  |  |  |  163|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  175|     70|	}
  176|    189|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  177|    189|				       buf, len);
  178|    189|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    189|#define SC_SUCCESS				0
  ------------------
  |  Branch (178:6): [True: 30, False: 159]
  ------------------
  179|     30|		sc_log(ctx, "Decoding of EF.TOKENINFO failed: %d", rv);
  ------------------
  |  |   71|     30|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  180|     30|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|     30|	}
  182|       |
  183|    159|	p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION
  ------------------
  |  |  597|    159|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
  184|    159|				  | SC_PKCS15_TOKEN_EID_COMPLIANT
  ------------------
  |  |  598|    159|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  185|    159|				  | SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|    159|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  186|       |
  187|       |	/* Load ODF */
  188|    159|	len = sizeof(buf);
  189|    159|	rv = dump_ef(p15card->card, "4F005031", buf, &len);
  190|    159|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (190:6): [True: 14, False: 145]
  ------------------
  191|     14|		sc_log(ctx, "Reading of ODF failed: %d", rv);
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  192|     14|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     14|	}
  194|    145|	rv = parse_odf(buf, len, p15card);
  195|    145|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    145|#define SC_SUCCESS				0
  ------------------
  |  Branch (195:6): [True: 7, False: 138]
  ------------------
  196|      7|		sc_log(ctx, "Decoding of ODF failed: %d", rv);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  197|      7|		sc_pkcs15_card_clear(p15card);
  198|      7|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|      7|	}
  200|       |
  201|       |	/* Decode EF.PrKDF, EF.PuKDF, EF.CDF and EF.AODF */
  202|    582|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (202:30): [True: 444, False: 138]
  ------------------
  203|    444|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|    444|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (203:7): [True: 98, False: 346]
  ------------------
  204|     98|			rv = sc_pkcs15_parse_df(p15card, df);
  205|     98|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     98|#define SC_SUCCESS				0
  ------------------
  |  Branch (205:8): [True: 96, False: 2]
  ------------------
  206|     96|				sc_log(ctx,
  ------------------
  |  |   71|     96|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  207|     96|				       "Decoding of EF.PrKDF (%s) failed: %d",
  208|     96|				       sc_print_path(&df->path), rv);
  209|     96|			}
  210|     98|		}
  211|    444|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|    444|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (211:7): [True: 55, False: 389]
  ------------------
  212|     55|			rv = sc_pkcs15_parse_df(p15card, df);
  213|     55|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     55|#define SC_SUCCESS				0
  ------------------
  |  Branch (213:8): [True: 37, False: 18]
  ------------------
  214|     37|				sc_log(ctx,
  ------------------
  |  |   71|     37|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  215|     37|				       "Decoding of EF.PuKDF (%s) failed: %d",
  216|     37|				       sc_print_path(&df->path), rv);
  217|     37|			}
  218|     55|		}
  219|    444|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|    444|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (219:7): [True: 99, False: 345]
  ------------------
  220|     99|			rv = sc_pkcs15_parse_df(p15card, df);
  221|     99|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     99|#define SC_SUCCESS				0
  ------------------
  |  Branch (221:8): [True: 88, False: 11]
  ------------------
  222|     88|				sc_log(ctx,
  ------------------
  |  |   71|     88|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  223|     88|				       "Decoding of EF.CDF (%s) failed: %d",
  224|     88|				       sc_print_path(&df->path), rv);
  225|     88|			}
  226|     99|		}
  227|    444|		if (df->type == SC_PKCS15_AODF) {
  ------------------
  |  |  496|    444|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (227:7): [True: 141, False: 303]
  ------------------
  228|    141|			rv = sc_pkcs15_parse_df(p15card, df);
  229|    141|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    141|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:8): [True: 123, False: 18]
  ------------------
  230|    123|				sc_log(ctx,
  ------------------
  |  |   71|    123|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|    123|				       "Decoding of EF.AODF (%s) failed: %d",
  232|    123|				       sc_print_path(&df->path), rv);
  233|    123|			}
  234|    141|		}
  235|    444|	}
  236|       |
  237|    138|	p15_obj = p15card->obj_list;
  238|    217|	while (p15_obj != NULL) {
  ------------------
  |  Branch (238:9): [True: 79, False: 138]
  ------------------
  239|     79|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_PRKDF) ) {
  ------------------
  |  |  488|     79|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (239:8): [True: 79, False: 0]
  |  Branch (239:23): [True: 1, False: 78]
  ------------------
  240|      1|			struct sc_pkcs15_prkey_info *prkey_info = (sc_pkcs15_prkey_info_t *) p15_obj->data;
  241|      1|			prkey_info->access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|      1|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  242|      1|					| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|      1|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  243|      1|					| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|      1|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  244|      1|					| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|      1|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  245|      1|			p15_obj->flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      1|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  246|      1|		}
  247|       |
  248|       |
  249|     79|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_AODF) ) {
  ------------------
  |  |  496|     79|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (249:8): [True: 79, False: 0]
  |  Branch (249:23): [True: 75, False: 4]
  ------------------
  250|     75|			static const char *pteid_pin_names[3] = {
  251|     75|			    "Auth PIN",
  252|     75|			    "Sign PIN",
  253|     75|			    "Address PIN"
  254|     75|			};
  255|       |
  256|     75|			struct sc_pin_cmd_data pin_cmd_data;
  257|     75|			struct sc_pkcs15_auth_info *pin_info = (sc_pkcs15_auth_info_t *) p15_obj->data;
  258|       |
  259|     75|			if (pin_info->auth_id.value[0] < 1 || pin_info->auth_id.value[0] > 3) {
  ------------------
  |  Branch (259:8): [True: 6, False: 69]
  |  Branch (259:42): [True: 6, False: 63]
  ------------------
  260|     12|				sc_log(ctx, "Invalid auth_id for PIN: Value %d out of range. Skipping.",
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  261|     12|						pin_info->auth_id.value[0]);
  262|     12|				p15_obj = p15_obj->next;
  263|     12|				continue;
  264|     12|			}
  265|       |
  266|     63|			strlcpy(p15_obj->label, pteid_pin_names[pin_info->auth_id.value[0]-1], sizeof(p15_obj->label));
  ------------------
  |  |   43|     63|#define strlcpy _strlcpy
  ------------------
  267|       |
  268|     63|			pin_info->attrs.pin.flags |= SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     63|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  269|     63|			pin_info->tries_left = -1;
  270|     63|			pin_info->max_tries = 3;
  271|     63|			pin_info->auth_method = SC_AC_CHV;
  ------------------
  |  |  151|     63|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  272|       |
  273|     63|			memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  274|     63|			pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     63|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  275|     63|			pin_cmd_data.pin_type = pin_info->attrs.pin.type;
  276|     63|			pin_cmd_data.pin_reference = pin_info->attrs.pin.reference;
  277|     63|			rv = sc_pin_cmd(p15card->card, &pin_cmd_data);
  278|     63|			if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|     63|#define SC_SUCCESS				0
  ------------------
  |  Branch (278:8): [True: 1, False: 62]
  ------------------
  279|      1|				pin_info->tries_left = pin_cmd_data.pin1.tries_left;
  280|      1|				pin_info->logged_in = pin_cmd_data.pin1.logged_in;
  281|      1|			}
  282|     63|		}
  283|       |		/* Remove found public keys as cannot be read_binary()'d */
  284|     67|		if ( p15_obj->df && (p15_obj->df->type == SC_PKCS15_PUKDF) ) {
  ------------------
  |  |  489|     67|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (284:8): [True: 67, False: 0]
  |  Branch (284:23): [True: 3, False: 64]
  ------------------
  285|      3|			sc_pkcs15_object_t *puk = p15_obj;
  286|      3|			p15_obj = p15_obj->next;
  287|      3|			sc_pkcs15_remove_object(p15card, puk);
  288|      3|			sc_pkcs15_free_object(puk);
  289|     64|		} else {
  290|     64|			p15_obj = p15_obj->next;
  291|     64|		}
  292|     67|	}
  293|       |
  294|       |	/* Add data objects */
  295|    828|	for (i = 0; i < 5; i++) {
  ------------------
  |  Branch (295:14): [True: 690, False: 138]
  ------------------
  296|    690|		static const char *object_labels[5] = {
  297|    690|			"Trace",
  298|    690|			"Citizen Data",
  299|    690|			"Citizen Address Data",
  300|    690|			"SOd",
  301|    690|			"Citizen Notepad",
  302|    690|		};
  303|    690|		static const char *object_authids[5] = {NULL, NULL, "3", NULL, NULL};
  304|    690|		static const char *object_paths[5] = {
  305|    690|			"3f000003",
  306|    690|			"3f005f00ef02",
  307|    690|			"3f005f00ef05",
  308|    690|			"3f005f00ef06",
  309|    690|			"3f005f00ef07",
  310|    690|		};
  311|    690|		static const int object_flags[5] = {
  312|    690|			0,
  313|    690|			0,
  314|    690|			SC_PKCS15_CO_FLAG_PRIVATE,
  ------------------
  |  |   50|    690|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  315|    690|			0,
  316|    690|			0,
  317|    690|		};
  318|    690|		struct sc_pkcs15_data_info obj_info;
  319|    690|		struct sc_pkcs15_object obj_obj;
  320|       |
  321|    690|		memset(&obj_info, 0, sizeof(obj_info));
  322|    690|		memset(&obj_obj, 0, sizeof(obj_obj));
  323|       |
  324|    690|		sc_format_path(object_paths[i], &obj_info.path);
  325|    690|		strlcpy(obj_info.app_label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   43|    690|#define strlcpy _strlcpy
  ------------------
              		strlcpy(obj_info.app_label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|    690|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  326|    690|		if (object_authids[i] != NULL)
  ------------------
  |  Branch (326:7): [True: 138, False: 552]
  ------------------
  327|    138|			sc_pkcs15_format_id(object_authids[i], &obj_obj.auth_id);
  328|    690|		strlcpy(obj_obj.label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   43|    690|#define strlcpy _strlcpy
  ------------------
              		strlcpy(obj_obj.label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|    690|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  329|    690|		obj_obj.flags = object_flags[i];
  330|       |
  331|    690|		rv = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, &obj_obj, &obj_info);
  ------------------
  |  |  442|    690|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  332|    690|		if (rv != SC_SUCCESS){
  ------------------
  |  |   28|    690|#define SC_SUCCESS				0
  ------------------
  |  Branch (332:7): [True: 0, False: 690]
  ------------------
  333|      0|			sc_log(ctx, "Object add failed: %d", rv);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  334|      0|			break;
  335|      0|		}
  336|    690|	}
  337|       |
  338|    138|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    138|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    138|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    138|	int _ret = r; \
  |  |  |  |  155|    138|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 138, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    138|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  157|    138|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    138|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    138|	return _ret; \
  |  |  |  |  163|    138|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  339|    138|}
pkcs15-pteid.c:dump_ef:
   55|    418|{
   56|    418|	int rv;
   57|    418|	sc_file_t *file = NULL;
   58|    418|	sc_path_t scpath;
   59|    418|	sc_format_path(path, &scpath);
   60|    418|	rv = sc_select_file(card, &scpath, &file);
   61|    418|	if (rv < 0) {
  ------------------
  |  Branch (61:6): [True: 64, False: 354]
  ------------------
   62|     64|		sc_file_free(file);
   63|     64|		return rv;
   64|     64|	}
   65|    354|	if (file->size > *buf_len) {
  ------------------
  |  Branch (65:6): [True: 17, False: 337]
  ------------------
   66|     17|		sc_file_free(file);
   67|     17|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     17|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   68|     17|	}
   69|    337|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   70|    337|	sc_file_free(file);
   71|    337|	if (rv < 0)
  ------------------
  |  Branch (71:6): [True: 3, False: 334]
  ------------------
   72|      3|		return rv;
   73|    334|	*buf_len = rv;
   74|       |
   75|    334|	return SC_SUCCESS;
  ------------------
  |  |   28|    334|#define SC_SUCCESS				0
  ------------------
   76|    337|}
pkcs15-pteid.c:parse_odf:
  105|    145|{
  106|    145|	const u8 *p = buf;
  107|    145|	size_t left = buflen;
  108|    145|	int r, i, type;
  109|    145|	sc_path_t path;
  110|    145|	struct sc_asn1_entry asn1_obj_or_path[] = {
  111|    145|		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  174|    145|#define SC_ASN1_PATH			256
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  141|    145|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  162|    145|#define SC_ASN1_SEQUENCE                16
  ------------------
  112|    145|		 &path, NULL},
  113|    145|		{NULL, 0, 0, 0, NULL, NULL}
  114|    145|	};
  115|    145|	struct sc_asn1_entry asn1_odf[10];
  116|       |
  117|    145|	sc_path_t path_prefix;
  118|       |
  119|    145|	sc_format_path("3F004F00", &path_prefix);
  120|       |
  121|    145|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  122|  1.45k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (122:14): [True: 1.30k, False: 145]
  ------------------
  123|  1.30k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  124|    615|	while (left > 0) {
  ------------------
  |  Branch (124:9): [True: 611, False: 4]
  ------------------
  125|    611|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left,
  126|    611|					  &p, &left);
  127|    611|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    611|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (127:7): [True: 134, False: 477]
  ------------------
  128|    134|			break;
  129|    477|		if (r < 0)
  ------------------
  |  Branch (129:7): [True: 7, False: 470]
  ------------------
  130|      7|			return r;
  131|    470|		type = r;
  132|    470|		r = sc_pkcs15_make_absolute_path(&path_prefix, &path);
  133|    470|		if (r < 0)
  ------------------
  |  Branch (133:7): [True: 0, False: 470]
  ------------------
  134|      0|			return r;
  135|    470|		r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  136|    470|		if (r)
  ------------------
  |  Branch (136:7): [True: 0, False: 470]
  ------------------
  137|      0|			return r;
  138|    470|	}
  139|    138|	return 0;
  140|    145|}

sc_pkcs15_decode_pubkey_direct_value:
  154|      3|{
  155|      3|	struct sc_context *ctx = p15card->card->ctx;
  156|      3|	struct sc_pkcs15_pubkey_info *info = (struct sc_pkcs15_pubkey_info *) obj->data;
  157|       |
  158|      3|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      3|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      3|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      3|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      3|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|      3|	if (obj->content.value == NULL || obj->content.len == 0)
  ------------------
  |  Branch (159:6): [True: 3, False: 0]
  |  Branch (159:36): [True: 0, False: 0]
  ------------------
  160|      3|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|       |
  162|      0|	if (*obj->content.value == (SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE))   {
  ------------------
  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
              	if (*obj->content.value == (SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE))   {
  ------------------
  |  |  206|      0|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
  |  Branch (162:6): [True: 0, False: 0]
  ------------------
  163|       |		/* RAW direct value */
  164|      0|		sc_log(ctx, "Decoding 'RAW' direct value");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  165|      0|		info->direct.raw.value = malloc(obj->content.len);
  166|      0|		if (!info->direct.raw.value)
  ------------------
  |  Branch (166:7): [True: 0, False: 0]
  ------------------
  167|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|      0|		memcpy(info->direct.raw.value, obj->content.value, obj->content.len);
  169|      0|		info->direct.raw.len = obj->content.len;
  170|       |
  171|       |		/* TODO: encode 'spki' direct value */
  172|      0|	}
  173|       |
  174|      0|	if (*obj->content.value == (SC_ASN1_TAG_CONTEXT | SC_ASN1_TAG_CONSTRUCTED | 0x01))   {
  ------------------
  |  |  187|      0|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
              	if (*obj->content.value == (SC_ASN1_TAG_CONTEXT | SC_ASN1_TAG_CONSTRUCTED | 0x01))   {
  ------------------
  |  |  190|      0|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (174:6): [True: 0, False: 0]
  ------------------
  175|      0|		struct sc_pkcs15_pubkey *pubkey = NULL;
  176|      0|		int rv;
  177|       |
  178|       |		/* SPKI direct value */
  179|      0|		sc_log(ctx, "Decoding 'SPKI' direct value");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  180|      0|		info->direct.spki.value = malloc(obj->content.len);
  181|      0|		if (!info->direct.spki.value)
  ------------------
  |  Branch (181:7): [True: 0, False: 0]
  ------------------
  182|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|      0|		memcpy(info->direct.spki.value, obj->content.value, obj->content.len);
  184|      0|		info->direct.spki.len = obj->content.len;
  185|       |
  186|      0|		rv = sc_pkcs15_pubkey_from_spki_sequence(ctx, info->direct.spki.value, info->direct.spki.len, &pubkey);
  187|      0|		LOG_TEST_RET(ctx, rv, "Failed to decode 'SPKI' direct value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|      0|		rv = sc_pkcs15_encode_pubkey(ctx, pubkey, &info->direct.raw.value, &info->direct.raw.len);
  190|      0|		sc_pkcs15_free_pubkey(pubkey);
  191|      0|		LOG_TEST_RET(ctx, rv, "Failed to encode 'RAW' direct value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|      0|	}
  193|       |
  194|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|      0|}
sc_pkcs15_decode_pukdf_entry:
  201|     26|{
  202|     26|	struct sc_context *ctx = p15card->card->ctx;
  203|     26|	struct sc_pkcs15_pubkey_info *info;
  204|     26|	int r, gostr3410_params[3];
  205|     26|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  206|     26|	size_t usage_len, af_len;
  207|     26|	struct sc_pkcs15_der *der = &obj->content;
  208|     26|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  209|     26|	struct sc_asn1_entry asn1_com_pubkey_attr[C_ASN1_COM_PUBKEY_ATTR_SIZE];
  210|     26|	struct sc_asn1_entry asn1_rsakey_value_choice[C_ASN1_RSAKEY_VALUE_CHOICE_SIZE];
  211|     26|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  212|     26|	struct sc_asn1_entry asn1_rsa_type_attr[C_ASN1_RSA_TYPE_ATTR_SIZE];
  213|     26|	struct sc_asn1_entry asn1_eckey_value_choice[C_ASN1_ECKEY_VALUE_CHOICE_SIZE];
  214|     26|	struct sc_asn1_entry asn1_eckey_attr[C_ASN1_ECKEY_ATTR_SIZE];
  215|     26|	struct sc_asn1_entry asn1_ec_type_attr[C_ASN1_EC_TYPE_ATTR_SIZE];
  216|     26|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOST3410KEY_ATTR_SIZE];
  217|     26|	struct sc_asn1_entry asn1_gostr3410_type_attr[C_ASN1_GOST3410_TYPE_ATTR_SIZE];
  218|     26|	struct sc_asn1_entry asn1_pubkey_choice[C_ASN1_PUBKEY_CHOICE_SIZE];
  219|     26|	struct sc_asn1_entry asn1_pubkey[C_ASN1_PUBKEY_SIZE];
  220|     26|	struct sc_asn1_pkcs15_object rsakey_obj = { obj, asn1_com_key_attr,
  221|     26|			asn1_com_pubkey_attr, asn1_rsa_type_attr };
  222|     26|	struct sc_asn1_pkcs15_object eckey_obj = { obj, asn1_com_key_attr,
  223|     26|			asn1_com_pubkey_attr, asn1_ec_type_attr };
  224|     26|	struct sc_asn1_pkcs15_object gostr3410key_obj =  { obj, asn1_com_key_attr,
  225|     26|			asn1_com_pubkey_attr, asn1_gostr3410_type_attr };
  226|       |
  227|     26|	info = calloc(1, sizeof *info);
  228|     26|	if (info == NULL) {
  ------------------
  |  Branch (228:6): [True: 0, False: 26]
  ------------------
  229|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  230|      0|		goto err;
  231|      0|	}
  232|     26|	usage_len = sizeof(info->usage);
  233|     26|	af_len = sizeof(info->access_flags);
  234|       |
  235|     26|	sc_copy_asn1_entry(c_asn1_pubkey, asn1_pubkey);
  236|     26|	sc_copy_asn1_entry(c_asn1_pubkey_choice, asn1_pubkey_choice);
  237|     26|	sc_copy_asn1_entry(c_asn1_rsa_type_attr, asn1_rsa_type_attr);
  238|     26|	sc_copy_asn1_entry(c_asn1_rsakey_value_choice, asn1_rsakey_value_choice);
  239|     26|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  240|     26|	sc_copy_asn1_entry(c_asn1_ec_type_attr, asn1_ec_type_attr);
  241|     26|	sc_copy_asn1_entry(c_asn1_eckey_value_choice, asn1_eckey_value_choice);
  242|     26|	sc_copy_asn1_entry(c_asn1_eckey_attr, asn1_eckey_attr);
  243|     26|	sc_copy_asn1_entry(c_asn1_gostr3410_type_attr, asn1_gostr3410_type_attr);
  244|     26|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  245|     26|	sc_copy_asn1_entry(c_asn1_com_pubkey_attr, asn1_com_pubkey_attr);
  246|     26|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  247|       |
  248|     26|	sc_format_asn1_entry(asn1_com_pubkey_attr + 0, &info->subject.value, &info->subject.len, 0);
  249|       |
  250|     26|	sc_format_asn1_entry(asn1_pubkey_choice + 0, &rsakey_obj, NULL, 0);
  251|     26|	sc_format_asn1_entry(asn1_pubkey_choice + 1, &gostr3410key_obj, NULL, 0);
  252|     26|	sc_format_asn1_entry(asn1_pubkey_choice + 2, &eckey_obj, NULL, 0);
  253|       |
  254|     26|	sc_format_asn1_entry(asn1_rsa_type_attr + 0, asn1_rsakey_attr, NULL, 0);
  255|       |
  256|     26|	sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &info->path, NULL, 0);
  257|     26|	sc_format_asn1_entry(asn1_rsakey_value_choice + 1, &der->value, &der->len, 0);
  258|       |
  259|     26|	sc_format_asn1_entry(asn1_rsakey_attr + 0, asn1_rsakey_value_choice, NULL, 0);
  260|     26|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info->modulus_length, NULL, 0);
  261|       |
  262|     26|	sc_format_asn1_entry(asn1_ec_type_attr + 0, asn1_eckey_attr, NULL, 0);
  263|       |
  264|     26|	sc_format_asn1_entry(asn1_eckey_value_choice + 0, &info->path, NULL, 0);
  265|     26|	sc_format_asn1_entry(asn1_eckey_value_choice + 1, &der->value, &der->len, 0);
  266|       |
  267|     26|	sc_format_asn1_entry(asn1_eckey_attr + 0, asn1_eckey_value_choice, NULL, 0);
  268|       |
  269|     26|	sc_format_asn1_entry(asn1_gostr3410_type_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  270|       |
  271|     26|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info->path, NULL, 0);
  272|     26|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  273|     26|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  274|     26|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  275|       |
  276|     26|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info->id, NULL, 0);
  277|     26|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info->usage, &usage_len, 0);
  278|     26|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info->native, NULL, 0);
  279|     26|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info->access_flags, &af_len, 0);
  280|     26|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info->key_reference, NULL, 0);
  281|       |
  282|     26|	sc_format_asn1_entry(asn1_pubkey + 0, asn1_pubkey_choice, NULL, 0);
  283|       |
  284|       |	/* Fill in defaults */
  285|     26|	info->key_reference = -1;
  286|     26|	info->native = 1;
  287|     26|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  288|       |
  289|     26|	r = sc_asn1_decode(ctx, asn1_pubkey, *buf, *buflen, buf, buflen);
  290|     26|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     26|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (290:6): [True: 9, False: 17]
  ------------------
  291|      9|		goto err;
  292|     17|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  184|     17|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     17|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     17|	int _ret = (r); \
  |  |  |  |  178|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 14, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  179|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     14|		goto err; \
  |  |  |  |  182|     14|	} \
  |  |  |  |  183|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|      3|	if (asn1_pubkey_choice[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      3|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (293:6): [True: 1, False: 2]
  ------------------
  294|      1|		obj->type = SC_PKCS15_TYPE_PUBKEY_RSA;
  ------------------
  |  |  426|      1|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  295|      2|	} else if (asn1_pubkey_choice[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      2|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (295:13): [True: 1, False: 1]
  ------------------
  296|      1|		obj->type = SC_PKCS15_TYPE_PUBKEY_GOSTR3410;
  ------------------
  |  |  427|      1|#define SC_PKCS15_TYPE_PUBKEY_GOSTR3410		0x203
  ------------------
  297|      1|		if (info->modulus_length != 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 1]
  ------------------
  298|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  299|      1|		info->modulus_length = SC_PKCS15_GOSTR3410_KEYSIZE;
  ------------------
  |  |  326|      1|#define SC_PKCS15_GOSTR3410_KEYSIZE             256
  ------------------
  300|      1|		if (info->params.len != 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 1]
  ------------------
  301|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  302|      1|		info->params.len = sizeof(struct sc_pkcs15_keyinfo_gostparams);
  303|      1|		info->params.data = malloc(info->params.len);
  304|      1|		if (info->params.data == NULL) {
  ------------------
  |  Branch (304:7): [True: 0, False: 1]
  ------------------
  305|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  306|      0|			goto err;
  307|      0|		}
  308|      1|		if (sizeof(*keyinfo_gostparams) != info->params.len)
  ------------------
  |  Branch (308:7): [True: 0, False: 1]
  ------------------
  309|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  310|      1|		keyinfo_gostparams = info->params.data;
  311|      1|		keyinfo_gostparams->gostr3410 = (unsigned int)gostr3410_params[0];
  312|      1|		keyinfo_gostparams->gostr3411 = (unsigned int)gostr3410_params[1];
  313|      1|		keyinfo_gostparams->gost28147 = (unsigned int)gostr3410_params[2];
  314|      1|	}
  315|      1|	else if (asn1_pubkey_choice[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      1|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (315:11): [True: 1, False: 0]
  ------------------
  316|      1|		obj->type = SC_PKCS15_TYPE_PUBKEY_EC;
  ------------------
  |  |  428|      1|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  317|      1|	}
  318|      0|	else {
  319|      0|		goto err;
  320|      0|	}
  321|       |
  322|      3|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (322:6): [True: 3, False: 0]
  |  Branch (322:23): [True: 0, False: 0]
  ------------------
  323|      3|		if (!p15card->file_app) {
  ------------------
  |  Branch (323:7): [True: 0, False: 3]
  ------------------
  324|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  325|      0|			goto err;
  326|      0|		}
  327|      3|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info->path);
  328|      3|		if (r < 0) {
  ------------------
  |  Branch (328:7): [True: 0, False: 3]
  ------------------
  329|      0|			goto err;
  330|      0|		}
  331|      3|	}
  332|      0|	else   {
  333|      0|		info->path.aid = p15card->app->ddo.aid;
  334|      0|	}
  335|      3|	sc_log(ctx, "PubKey path '%s'", sc_print_path(&info->path));
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  336|       |
  337|       |	/* OpenSC 0.11.4 and older encoded "keyReference" as a negative
  338|       |	   value. Fixed in 0.11.5 we need to add a hack, so old cards
  339|       |	   continue to work. */
  340|      3|	if (info->key_reference < -1)
  ------------------
  |  Branch (340:6): [True: 0, False: 3]
  ------------------
  341|      0|		info->key_reference += 256;
  342|       |
  343|      3|	obj->data = info;
  344|      3|	info = NULL;
  345|       |
  346|      3|	r = sc_pkcs15_decode_pubkey_direct_value(p15card, obj);
  347|      3|	if (r < 0) {
  ------------------
  |  Branch (347:6): [True: 0, False: 3]
  ------------------
  348|      0|		info = obj->data;
  349|      0|		obj->data = NULL;
  350|      0|	}
  351|      3|	LOG_TEST_GOTO_ERR(ctx, r, "Decode public key direct value failed");
  ------------------
  |  |  184|      3|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      3|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      3|	int _ret = (r); \
  |  |  |  |  178|      3|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|       |
  353|     26|err:
  354|     26|	if (r < 0) {
  ------------------
  |  Branch (354:6): [True: 23, False: 3]
  ------------------
  355|     23|		sc_pkcs15_free_pubkey_info(info);
  356|     23|		if (der->len) {
  ------------------
  |  Branch (356:7): [True: 0, False: 23]
  ------------------
  357|      0|			free(der->value);
  358|       |			/* der points to obj->content */
  359|      0|			obj->content.value = NULL;
  360|      0|			obj->content.len = 0;
  361|      0|		}
  362|     23|	}
  363|       |
  364|     26|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     26|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     26|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     26|	int _ret = r; \
  |  |  |  |  155|     26|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|     26|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     26|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|     26|}
sc_pkcs15_decode_pubkey_rsa:
  562|    291|{
  563|    291|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  564|    291|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  565|    291|	int r;
  566|       |
  567|    291|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    291|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    291|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    291|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    291|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 291]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  568|    291|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  569|    291|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 0);
  570|       |
  571|    291|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  572|    291|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, &key->modulus.data, &key->modulus.len, 0);
  573|    291|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, &key->exponent.data, &key->exponent.len, 0);
  574|       |
  575|    291|	r = sc_asn1_decode(ctx, asn1_public_key, buf, buflen, NULL, NULL);
  576|    291|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of public key failed");
  ------------------
  |  |  174|    291|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    291|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    291|	int _ret = (r); \
  |  |  |  |  168|    291|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 280]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|    291|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 280]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  577|       |
  578|    280|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    280|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    280|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    280|	int _ret = r; \
  |  |  |  |  155|    280|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 280, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    280|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 280]
  |  |  |  |  ------------------
  |  |  |  |  157|    280|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    280|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    280|	return _ret; \
  |  |  |  |  163|    280|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  579|    280|}
sc_pkcs15_encode_pubkey_rsa:
  585|    387|{
  586|    387|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  587|    387|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  588|    387|	int r;
  589|       |
  590|    387|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    387|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    387|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    387|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    387|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 387]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|    387|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  592|    387|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 1);
  593|       |
  594|    387|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  595|    387|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, key->modulus.data, &key->modulus.len, 1);
  596|    387|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, key->exponent.data, &key->exponent.len, 1);
  597|       |
  598|    387|	r = sc_asn1_encode(ctx, asn1_public_key, buf, buflen);
  599|    387|	LOG_TEST_RET(ctx, r, "ASN.1 encoding failed");
  ------------------
  |  |  174|    387|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    387|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    387|	int _ret = (r); \
  |  |  |  |  168|    387|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 360]
  |  |  |  |  ------------------
  |  |  |  |  169|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     27|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     27|		return _ret; \
  |  |  |  |  172|     27|	} \
  |  |  |  |  173|    387|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 360]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  600|       |
  601|    360|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    360|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    360|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    360|	int _ret = r; \
  |  |  |  |  155|    360|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 360, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    360|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 360]
  |  |  |  |  ------------------
  |  |  |  |  157|    360|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    360|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    360|	return _ret; \
  |  |  |  |  163|    360|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|    360|}
sc_pkcs15_encode_pubkey:
  768|    271|{
  769|    271|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    271|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (769:6): [True: 271, False: 0]
  ------------------
  770|    271|		return sc_pkcs15_encode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  771|      0|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (771:6): [True: 0, False: 0]
  ------------------
  772|      0|		return sc_pkcs15_encode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  773|      0|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (773:6): [True: 0, False: 0]
  ------------------
  774|      0|		return sc_pkcs15_encode_pubkey_ec(ctx, &key->u.ec, buf, len);
  775|      0|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (775:6): [True: 0, False: 0]
  |  Branch (775:46): [True: 0, False: 0]
  ------------------
  776|      0|		return sc_pkcs15_encode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  777|       |
  778|      0|	sc_log(ctx, "Encoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  779|      0|	LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|      0|}
sc_pkcs15_encode_pubkey_as_spki:
  800|    386|{
  801|    386|	int r = 0;
  802|    386|	struct sc_asn1_entry  asn1_spki_key[2], asn1_spki_key_items[3];
  803|    386|	struct sc_pkcs15_u8 pkey;
  804|    386|	size_t key_len;
  805|       |
  806|    386|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    386|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    386|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    386|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    386|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 386]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  807|    386|	pkey.value =  NULL;
  808|    386|	pkey.len = 0;
  809|       |
  810|    386|	sc_log(ctx, "Encoding public key with algorithm %lu", pubkey->algorithm);
  ------------------
  |  |   71|    386|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  811|    386|	if (!pubkey->alg_id)   {
  ------------------
  |  Branch (811:6): [True: 41, False: 345]
  ------------------
  812|     41|		pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
  813|     41|		if (!pubkey->alg_id)
  ------------------
  |  Branch (813:7): [True: 0, False: 41]
  ------------------
  814|     41|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|       |
  816|     41|		sc_init_oid(&pubkey->alg_id->oid);
  817|     41|		pubkey->alg_id->algorithm = pubkey->algorithm;
  818|     41|	}
  819|       |
  820|    386|	switch (pubkey->algorithm) {
  821|     92|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|     92|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (821:2): [True: 92, False: 294]
  ------------------
  822|    103|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|    103|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (822:2): [True: 11, False: 375]
  ------------------
  823|    115|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    115|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (823:2): [True: 12, False: 374]
  ------------------
  824|       |		/*
  825|       |		 * most keys, but not EC have only one encoding.
  826|       |		 * For a SPKI, the ecpoint is placed directly in the
  827|       |		 * BIT STRING
  828|       |		 */
  829|    115|		key_len = pubkey->u.ec.ecpointQ.len * 8;
  830|    115|		pkey.value = pubkey->u.ec.ecpointQ.value;
  831|    115|		pkey.len = 0; /* flag as do not delete */
  832|       |
  833|    115|		if (pubkey->u.ec.params.named_curve || pubkey->u.ec.params.der.value)   {
  ------------------
  |  Branch (833:7): [True: 75, False: 40]
  |  Branch (833:42): [True: 0, False: 40]
  ------------------
  834|     75|			struct sc_ec_parameters *ec_params = NULL;
  835|       |
  836|     75|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
  837|     75|			LOG_TEST_RET(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  174|     75|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     75|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     75|	int _ret = (r); \
  |  |  |  |  168|     75|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 75]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 75]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  838|       |
  839|       |			/* EDDSA and XEDDSA only have algo and no param in SPKI */
  840|     75|			if (pubkey->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|     75|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (840:8): [True: 75, False: 0]
  ------------------
  841|     75|				ec_params = calloc(1, sizeof(struct sc_ec_parameters));
  842|     75|				if (!ec_params)
  ------------------
  |  Branch (842:9): [True: 0, False: 75]
  ------------------
  843|     75|					LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|     75|				ec_params->type = 1;
  845|     75|				ec_params->der.value = calloc(1, pubkey->u.ec.params.der.len);
  846|     75|				if (!ec_params->der.value) {
  ------------------
  |  Branch (846:9): [True: 0, False: 75]
  ------------------
  847|      0|					free(ec_params);
  848|      0|					LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  849|      0|				}
  850|     75|				memcpy(ec_params->der.value, pubkey->u.ec.params.der.value, pubkey->u.ec.params.der.len);
  851|     75|				ec_params->der.len = pubkey->u.ec.params.der.len;
  852|     75|			}
  853|       |			/* This could have been already allocated: avoid memory leak */
  854|     75|			sc_asn1_clear_algorithm_id(pubkey->alg_id);
  855|     75|			pubkey->alg_id->params = ec_params; /* NULL for EDDSA and XEDDSA */
  856|     75|		}
  857|    115|		break;
  858|    115|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (858:2): [True: 0, False: 386]
  ------------------
  859|       |		/* TODO is this needed?  does it cause mem leak? */
  860|      0|		pubkey->alg_id->params = &pubkey->u.gostr3410.params;
  861|      0|		r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
  862|      0|		key_len = pkey.len * 8;
  863|      0|		break;
  864|    271|	default:
  ------------------
  |  Branch (864:2): [True: 271, False: 115]
  ------------------
  865|    271|		r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
  866|    271|		key_len = pkey.len * 8;
  867|    271|		break;
  868|    386|	}
  869|       |
  870|    386|	if (r == 0) {
  ------------------
  |  Branch (870:6): [True: 363, False: 23]
  ------------------
  871|    363|		sc_copy_asn1_entry(c_asn1_spki_key, asn1_spki_key);
  872|    363|		sc_copy_asn1_entry(c_asn1_spki_key_items, asn1_spki_key_items);
  873|    363|		sc_format_asn1_entry(asn1_spki_key + 0, asn1_spki_key_items, NULL, 1);
  874|    363|		sc_format_asn1_entry(asn1_spki_key_items + 0, pubkey->alg_id, NULL, 1);
  875|    363|		sc_format_asn1_entry(asn1_spki_key_items + 1, pkey.value, &key_len, 1);
  876|       |
  877|    363|		r =  sc_asn1_encode(ctx, asn1_spki_key, buf, len);
  878|    363|	}
  879|       |
  880|       |	/*  pkey.len == 0 is flag to not delete */
  881|    386|	if (pkey.len && pkey.value)
  ------------------
  |  Branch (881:6): [True: 248, False: 138]
  |  Branch (881:18): [True: 248, False: 0]
  ------------------
  882|    248|		free(pkey.value);
  883|       |
  884|    386|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    386|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    386|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    386|	int _ret = r; \
  |  |  |  |  155|    386|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 386, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    386|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 363]
  |  |  |  |  ------------------
  |  |  |  |  157|    386|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    386|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    386|	return _ret; \
  |  |  |  |  163|    386|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  885|    386|}
sc_pkcs15_decode_pubkey:
  891|    301|{
  892|    301|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    301|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (892:6): [True: 291, False: 10]
  ------------------
  893|    291|		return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  894|     10|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   71|     10|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (894:6): [True: 0, False: 10]
  ------------------
  895|      0|		return sc_pkcs15_decode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  896|     10|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   70|     10|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (896:6): [True: 0, False: 10]
  ------------------
  897|      0|		return sc_pkcs15_decode_pubkey_ec(ctx, &key->u.ec, buf, len);
  898|     10|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   72|     20|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     10|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (898:6): [True: 0, False: 10]
  |  Branch (898:46): [True: 0, False: 10]
  ------------------
  899|      0|		return sc_pkcs15_decode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  900|       |
  901|     10|	sc_log(ctx, "Decoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  902|     10|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     10|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  903|     10|}
sc_pkcs15_erase_pubkey:
 1186|  1.85k|{
 1187|  1.85k|	if (key == NULL) {
  ------------------
  |  Branch (1187:6): [True: 0, False: 1.85k]
  ------------------
 1188|      0|		return;
 1189|      0|	}
 1190|  1.85k|	if (key->alg_id) {
  ------------------
  |  Branch (1190:6): [True: 503, False: 1.35k]
  ------------------
 1191|    503|		sc_asn1_clear_algorithm_id(key->alg_id);
 1192|    503|		free(key->alg_id);
 1193|    503|	}
 1194|  1.85k|	switch (key->algorithm) {
  ------------------
  |  Branch (1194:10): [True: 1.83k, False: 20]
  ------------------
 1195|  1.64k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|  1.64k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1195:2): [True: 1.64k, False: 208]
  ------------------
 1196|  1.64k|		free(key->u.rsa.modulus.data);
 1197|  1.64k|		free(key->u.rsa.exponent.data);
 1198|  1.64k|		break;
 1199|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (1199:2): [True: 0, False: 1.85k]
  ------------------
 1200|      0|		free(key->u.gostr3410.xy.data);
 1201|      0|		break;
 1202|    142|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|    142|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1202:2): [True: 142, False: 1.71k]
  ------------------
 1203|    164|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|    164|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1203:2): [True: 22, False: 1.83k]
  ------------------
 1204|    188|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|    188|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1204:2): [True: 24, False: 1.83k]
  ------------------
 1205|    188|		free(key->u.ec.params.der.value);
 1206|    188|		free(key->u.ec.params.named_curve);
 1207|    188|		free(key->u.ec.ecpointQ.value);
 1208|    188|		break;
 1209|  1.85k|	}
 1210|  1.85k|	sc_mem_clear(key, sizeof(*key));
 1211|  1.85k|}
sc_pkcs15_free_pubkey:
 1216|  3.53k|{
 1217|  3.53k|	if (!key)
  ------------------
  |  Branch (1217:6): [True: 1.84k, False: 1.69k]
  ------------------
 1218|  1.84k|		return;
 1219|  1.69k|	sc_pkcs15_erase_pubkey(key);
 1220|  1.69k|	free(key);
 1221|  1.69k|}
sc_pkcs15_free_pubkey_info:
 1226|    480|{
 1227|    480|	if (info) {
  ------------------
  |  Branch (1227:6): [True: 480, False: 0]
  ------------------
 1228|    480|		free(info->subject.value);
 1229|    480|		free(info->direct.spki.value);
 1230|    480|		free(info->direct.raw.value);
 1231|    480|		sc_pkcs15_free_key_params(&info->params);
 1232|    480|		free(info);
 1233|    480|	}
 1234|    480|}
sc_pkcs15_pubkey_from_spki_fields:
 1325|    579|{
 1326|       |
 1327|    579|	struct sc_pkcs15_pubkey *pubkey = NULL;
 1328|    579|	struct sc_pkcs15_der pk = { NULL, 0 };
 1329|    579|	struct sc_algorithm_id pk_alg;
 1330|    579|	struct sc_asn1_entry asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE];
 1331|    579|	unsigned char *tmp_buf = NULL;
 1332|    579|	int r;
 1333|       |
 1334|    579|	sc_log(ctx, "sc_pkcs15_pubkey_from_spki_fields() called: %p:%zu\n%s",
  ------------------
  |  |   71|    579|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1335|    579|			buf, buflen, sc_dump_hex(buf, buflen));
 1336|       |
 1337|    579|	if (buflen < 1) {
  ------------------
  |  Branch (1337:6): [True: 24, False: 555]
  ------------------
 1338|     24|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "subjectPublicKeyInfo can not be empty");
  ------------------
  |  |  174|     24|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     24|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     24|	int _ret = (r); \
  |  |  |  |  168|     24|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     24|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     24|		return _ret; \
  |  |  |  |  172|     24|	} \
  |  |  |  |  173|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1339|     24|	}
 1340|       |
 1341|    555|	tmp_buf = malloc(buflen);
 1342|    555|	if (!tmp_buf) {
  ------------------
  |  Branch (1342:6): [True: 0, False: 555]
  ------------------
 1343|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1344|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1345|      0|	}
 1346|    555|	memcpy(tmp_buf, buf, buflen);
 1347|       |
 1348|    555|	if (buflen > 0 && (*tmp_buf & SC_ASN1_TAG_CONTEXT))
  ------------------
  |  |  187|    555|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (1348:6): [True: 555, False: 0]
  |  Branch (1348:20): [True: 40, False: 515]
  ------------------
 1349|     40|		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  190|     40|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
              		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  206|     40|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 1350|       |
 1351|    555|	memset(&pk_alg, 0, sizeof(pk_alg));
 1352|    555|	pubkey = calloc(1, sizeof(sc_pkcs15_pubkey_t));
 1353|    555|	if (pubkey == NULL) {
  ------------------
  |  Branch (1353:6): [True: 0, False: 555]
  ------------------
 1354|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1355|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1356|      0|	}
 1357|       |
 1358|    555|	sc_copy_asn1_entry(c_asn1_pkinfo, asn1_pkinfo);
 1359|       |
 1360|    555|	sc_format_asn1_entry(asn1_pkinfo + 0, &pk_alg, NULL, 0);
 1361|    555|	sc_format_asn1_entry(asn1_pkinfo + 1, &pk.value, &pk.len, 0);
 1362|       |
 1363|    555|	r = sc_asn1_decode(ctx, asn1_pkinfo, tmp_buf, buflen, NULL, NULL);
 1364|    555|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    555|#define SC_SUCCESS				0
  ------------------
  |  Branch (1364:6): [True: 93, False: 462]
  ------------------
 1365|     93|		sc_asn1_clear_algorithm_id(&pk_alg);
 1366|     93|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|     93|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     93|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     93|	int _ret = (r); \
  |  |  |  |  178|     93|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     93|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     93|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     93|		goto err; \
  |  |  |  |  182|     93|	} \
  |  |  |  |  183|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1367|     93|	}
 1368|       |
 1369|    462|	pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
 1370|    462|	if (pubkey->alg_id == NULL) {
  ------------------
  |  Branch (1370:6): [True: 0, False: 462]
  ------------------
 1371|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1372|      0|		LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|      0|	}
 1374|       |
 1375|    462|	memcpy(pubkey->alg_id, &pk_alg, sizeof(struct sc_algorithm_id));
 1376|    462|	pubkey->algorithm = pk_alg.algorithm;
 1377|    462|	pk_alg.params = NULL;
 1378|    462|	sc_log(ctx, "DEE pk_alg.algorithm=%lu", pk_alg.algorithm);
  ------------------
  |  |   71|    462|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1379|       |
 1380|    462|	if (pk.len == 0)
  ------------------
  |  Branch (1380:6): [True: 15, False: 447]
  ------------------
 1381|    462|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INTERNAL, "Incorrect length of key");
  ------------------
  |  |  184|     15|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     15|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     15|	int _ret = (r); \
  |  |  |  |  178|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 15, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     15|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     15|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     15|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     15|		goto err; \
  |  |  |  |  182|     15|	} \
  |  |  |  |  183|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1382|    447|	pk.len = BYTES4BITS(pk.len); /* convert number of bits to bytes */
  ------------------
  |  |  145|    447|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1383|       |
 1384|    447|	if (pk_alg.algorithm == SC_ALGORITHM_EC)   {
  ------------------
  |  |   70|    447|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1384:6): [True: 124, False: 323]
  ------------------
 1385|       |		/* EC public key is not encapsulated into BIT STRING -- it's a BIT STRING */
 1386|       |		/*
 1387|       |		 * sc_pkcs15_fix_ec_parameters below will set field_length from curve.
 1388|       |		 * if no alg_id->params, assume field_length is multiple of 8
 1389|       |		 */
 1390|    124|		pubkey->u.ec.params.field_length = (pk.len - 1) / 2 * 8;
 1391|       |
 1392|    124|		if (pubkey->alg_id->params) {
  ------------------
  |  Branch (1392:7): [True: 115, False: 9]
  ------------------
 1393|    115|			struct sc_ec_parameters *ecp = (struct sc_ec_parameters *)pubkey->alg_id->params;
 1394|       |
 1395|    115|			pubkey->u.ec.params.der.value = malloc(ecp->der.len);
 1396|    115|			if (pubkey->u.ec.params.der.value == NULL) {
  ------------------
  |  Branch (1396:8): [True: 0, False: 115]
  ------------------
 1397|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1398|      0|				LOG_TEST_GOTO_ERR(ctx, r, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1399|      0|			}
 1400|       |
 1401|    115|			memcpy(pubkey->u.ec.params.der.value, ecp->der.value, ecp->der.len);
 1402|    115|			pubkey->u.ec.params.der.len = ecp->der.len;
 1403|    115|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1404|    115|			LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|    115|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    115|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    115|	int _ret = (r); \
  |  |  |  |  178|    115|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 23, False: 92]
  |  |  |  |  ------------------
  |  |  |  |  179|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     23|		goto err; \
  |  |  |  |  182|     23|	} \
  |  |  |  |  183|    115|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 92]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1405|    115|		}
 1406|       |
 1407|    101|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1408|    101|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1408:7): [True: 0, False: 101]
  ------------------
 1409|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1410|      0|			LOG_TEST_GOTO_ERR(ctx, r, "failed to malloc() memory");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1411|      0|		}
 1412|    101|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1413|    101|		pubkey->u.ec.ecpointQ.len = pk.len;
 1414|    323|	} else if (pk_alg.algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|    646|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1414:13): [True: 11, False: 312]
  ------------------
 1415|    312|		   pk_alg.algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|    312|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1415:6): [True: 11, False: 301]
  ------------------
 1416|       |		/*
 1417|       |		 * SPKI will have OID, EDDSA can have ED25519 or ED448 with different sizes
 1418|       |		 * EDDSA/XEDDSA public key is not encapsulated into BIT STRING -- it's a BIT STRING
 1419|       |		 * no params, but oid is the params.
 1420|       |		 */
 1421|     22|		r = sc_encode_oid(ctx, &pk_alg.oid, &pubkey->u.ec.params.der.value, &pubkey->u.ec.params.der.len);
 1422|     22|		LOG_TEST_GOTO_ERR(ctx, r, "failed to encode (X)EDDSA oid");
  ------------------
  |  |  184|     22|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     22|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     22|	int _ret = (r); \
  |  |  |  |  178|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1423|     22|		r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1424|     22|		LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|     22|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     22|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     22|	int _ret = (r); \
  |  |  |  |  178|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|       |
 1426|     22|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1427|     22|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1427:7): [True: 0, False: 22]
  ------------------
 1428|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1429|      0|			LOG_TEST_GOTO_ERR(ctx, r, "failed to malloc() memory");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|      0|		}
 1431|       |
 1432|     22|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1433|     22|		pubkey->u.ec.ecpointQ.len = pk.len;
 1434|    301|	} else {
 1435|       |		/* Public key is expected to be encapsulated into BIT STRING */
 1436|    301|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, pk.value, pk.len);
 1437|    301|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|    301|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    301|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    301|	int _ret = (r); \
  |  |  |  |  178|    301|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 21, False: 280]
  |  |  |  |  ------------------
  |  |  |  |  179|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     21|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     21|		goto err; \
  |  |  |  |  182|     21|	} \
  |  |  |  |  183|    301|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 280]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1438|    301|	}
 1439|       |
 1440|    403|	*outpubkey = pubkey;
 1441|    403|	pubkey = NULL;
 1442|       |
 1443|    555|err:
 1444|    555|	sc_pkcs15_free_pubkey(pubkey);
 1445|    555|	free(pk.value);
 1446|    555|	free(tmp_buf);
 1447|       |
 1448|    555|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    555|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    555|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    555|	int _ret = r; \
  |  |  |  |  155|    555|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 555, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    555|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    137|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 137, False: 418]
  |  |  |  |  ------------------
  |  |  |  |  157|    555|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    555|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    555|	return _ret; \
  |  |  |  |  163|    555|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1449|    555|}
sc_pkcs15_pubkey_from_spki_sequence:
 1455|     33|{
 1456|     33|	struct sc_pkcs15_pubkey * pubkey = NULL;
 1457|     33|	struct sc_asn1_entry asn1_spki[] = {
 1458|     33|			{ "subjectPublicKeyInfo", SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields, &pubkey},
  ------------------
  |  |  181|     33|#define SC_ASN1_CALLBACK		384
  ------------------
              			{ "subjectPublicKeyInfo", SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields, &pubkey},
  ------------------
  |  |  206|     33|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              			{ "subjectPublicKeyInfo", SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields, &pubkey},
  ------------------
  |  |  141|     33|#define SC_ASN1_CONS			0x20000000
  ------------------
 1459|     33|			{ NULL, 0, 0, 0, NULL, NULL } };
 1460|     33|	int r;
 1461|       |
 1462|     33|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     33|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     33|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     33|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     33|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 33]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1463|       |
 1464|     33|	r = sc_asn1_decode(ctx, asn1_spki, buf, buflen, NULL, NULL);
 1465|     33|	LOG_TEST_RET(ctx, r, "ASN.1 cannot parse subjectPublicKeyInfo");
  ------------------
  |  |  174|     33|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     33|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     33|	int _ret = (r); \
  |  |  |  |  168|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1466|       |
 1467|     23|	if(outpubkey) {
  ------------------
  |  Branch (1467:5): [True: 23, False: 0]
  ------------------
 1468|     23|		free(*outpubkey);
 1469|     23|		*outpubkey = pubkey;
 1470|     23|	} else
 1471|      0|		free(pubkey);
 1472|       |
 1473|     23|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     23|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1474|     23|}
sc_pkcs15_fix_ec_parameters:
 1563|  5.29k|{
 1564|  5.29k|	int rv, ii;
 1565|  5.29k|	int mapped_string = 0; /* der is printable string that can be replaced with der of OID */
 1566|       |
 1567|  5.29k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.29k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.29k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1568|       |
 1569|       |	/* In PKCS#11 EC parameters arrives in DER encoded form */
 1570|  5.29k|	if (ecparams->der.value && ecparams->der.len && ecparams->der.len > 2) {
  ------------------
  |  Branch (1570:6): [True: 5.29k, False: 0]
  |  Branch (1570:29): [True: 5.29k, False: 0]
  |  Branch (1570:50): [True: 5.29k, False: 0]
  ------------------
 1571|       |
 1572|  5.29k|		switch (ecparams->der.value[0]) {
 1573|  5.29k|		case 0x06: /* der.value is an OID */
  ------------------
  |  Branch (1573:3): [True: 5.29k, False: 1]
  ------------------
 1574|   114k|			for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1574:17): [True: 114k, False: 22]
  ------------------
 1575|   114k|				size_t len = ec_curve_infos[ii].oid_der.len;
 1576|       |
 1577|   114k|				if (ecparams->der.len == len &&
  ------------------
  |  Branch (1577:9): [True: 14.2k, False: 99.8k]
  ------------------
 1578|  14.2k|						memcmp(ecparams->der.value, ec_curve_infos[ii].oid_der.value, len) == 0)
  ------------------
  |  Branch (1578:7): [True: 5.27k, False: 9.01k]
  ------------------
 1579|  5.27k|					break; /* found ec_curve_infos[ii] */
 1580|   114k|			}
 1581|  5.29k|			break;
 1582|       |
 1583|      0|		case 0x13:
  ------------------
  |  Branch (1583:3): [True: 0, False: 5.29k]
  ------------------
 1584|       |			/* printable string as per PKCS11 V 3.0 for experimental curves */
 1585|      0|			{
 1586|      0|				int r_tag;
 1587|      0|				const u8 *body = ecparams->der.value;
 1588|      0|				size_t len = ecparams->der.len;
 1589|      0|				unsigned int cla_out, tag_out;
 1590|      0|				size_t bodylen;
 1591|       |
 1592|      0|				r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 1593|      0|				if (r_tag != SC_SUCCESS || tag_out != 0x13) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1593:9): [True: 0, False: 0]
  |  Branch (1593:32): [True: 0, False: 0]
  ------------------
 1594|      0|					sc_log(ctx, "Invalid printable string");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1595|      0|					LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1596|      0|				}
 1597|      0|				for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1597:18): [True: 0, False: 0]
  ------------------
 1598|      0|					size_t len = strlen(ec_curve_infos[ii].name);
 1599|      0|					if (bodylen != len || memcmp(ec_curve_infos[ii].name, body, len) != 0)
  ------------------
  |  Branch (1599:10): [True: 0, False: 0]
  |  Branch (1599:28): [True: 0, False: 0]
  ------------------
 1600|      0|						continue;
 1601|       |					/* found replacement of printable string to OID */
 1602|      0|					mapped_string = 1;
 1603|      0|					break;
 1604|      0|				}
 1605|      0|			}
 1606|      0|			break;
 1607|       |
 1608|      1|		default:
  ------------------
  |  Branch (1608:3): [True: 1, False: 5.29k]
  ------------------
 1609|      1|			sc_log(ctx, "Unsupported ec params");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1610|      1|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1611|  5.29k|		}
 1612|       |
 1613|  5.29k|		if (ec_curve_infos[ii].name == NULL) /* end of ec_curve_info */
  ------------------
  |  Branch (1613:7): [True: 22, False: 5.27k]
  ------------------
 1614|  5.29k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported named curve");
  ------------------
  |  |  174|     22|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     22|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     22|	int _ret = (r); \
  |  |  |  |  168|     22|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     22|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     22|		return _ret; \
  |  |  |  |  172|     22|	} \
  |  |  |  |  173|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1615|       |
 1616|       |		/* ii points to entry with matching oid_der or a mapped entry with replacement oid_der */
 1617|  5.27k|		sc_log(ctx, "Found known curve '%s'", ec_curve_infos[ii].name);
  ------------------
  |  |   71|  5.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1618|  5.27k|		if (mapped_string) { /* free previous name if any replace below with new name */
  ------------------
  |  Branch (1618:7): [True: 0, False: 5.27k]
  ------------------
 1619|      0|			free(ecparams->named_curve);
 1620|      0|			ecparams->named_curve = NULL;
 1621|      0|		}
 1622|       |
 1623|  5.27k|		if (!ecparams->named_curve) { /* if present,keep the name as some curves have multiple names */
  ------------------
  |  Branch (1623:7): [True: 5.20k, False: 75]
  ------------------
 1624|  5.20k|			ecparams->named_curve = strdup(ec_curve_infos[ii].name);
 1625|  5.20k|			if (!ecparams->named_curve)
  ------------------
  |  Branch (1625:8): [True: 0, False: 5.20k]
  ------------------
 1626|  5.20k|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1627|       |
 1628|  5.20k|			sc_log(ctx, "Curve name: '%s'", ecparams->named_curve);
  ------------------
  |  |   71|  5.20k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1629|  5.20k|		}
 1630|       |
 1631|       |		/* fill in object_id based on oid_der */
 1632|  5.27k|		sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1633|       |
 1634|  5.27k|		ecparams->field_length = ec_curve_infos[ii].size;
 1635|  5.27k|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1636|  5.27k|		sc_log(ctx, "Curve length %zu key_type %d", ecparams->field_length, ecparams->key_type);
  ------------------
  |  |   71|  5.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1637|  5.27k|		if (mapped_string) {
  ------------------
  |  Branch (1637:7): [True: 0, False: 5.27k]
  ------------------
 1638|       |			/* replace the printable string version with the oid */
 1639|      0|			if (ecparams->der.value)
  ------------------
  |  Branch (1639:8): [True: 0, False: 0]
  ------------------
 1640|      0|				free(ecparams->der.value);
 1641|      0|			ecparams->der.len = ec_curve_infos[ii].oid_der.len;
 1642|      0|			ecparams->der.value = malloc(ecparams->der.len);
 1643|      0|			if (ecparams->der.value == NULL) {
  ------------------
  |  Branch (1643:8): [True: 0, False: 0]
  ------------------
 1644|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1645|      0|			}
 1646|      0|			memcpy(ecparams->der.value, ec_curve_infos[ii].oid_der.value, ecparams->der.len);
 1647|      0|		}
 1648|  5.27k|	} else if (ecparams->named_curve) { /* it can be name of curve or OID in ASCII form */
  ------------------
  |  Branch (1648:13): [True: 0, False: 0]
  ------------------
 1649|       |		/* caller did not provide an OID, look for a name or oid_string */
 1650|      0|		for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1650:16): [True: 0, False: 0]
  ------------------
 1651|      0|			if (!strcmp(ec_curve_infos[ii].name, ecparams->named_curve))
  ------------------
  |  Branch (1651:8): [True: 0, False: 0]
  ------------------
 1652|      0|				break;
 1653|      0|			if (!strcmp(ec_curve_infos[ii].oid_str, ecparams->named_curve))
  ------------------
  |  Branch (1653:8): [True: 0, False: 0]
  ------------------
 1654|      0|				break;
 1655|      0|		}
 1656|      0|		if (!ec_curve_infos[ii].name) {
  ------------------
  |  Branch (1656:7): [True: 0, False: 0]
  ------------------
 1657|      0|			sc_log(ctx, "Named curve '%s' not supported", ecparams->named_curve);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1658|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1659|      0|		}
 1660|       |
 1661|      0|		rv = sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1662|      0|		LOG_TEST_RET(ctx, rv, "Invalid OID format");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1663|       |
 1664|      0|		ecparams->field_length = ec_curve_infos[ii].size;
 1665|      0|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1666|      0|		sc_log(ctx, "Curve length %zu key_type %d", ecparams->field_length, ecparams->key_type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1667|       |
 1668|      0|		if (ecparams->der.value == NULL || ecparams->der.len == 0) {
  ------------------
  |  Branch (1668:7): [True: 0, False: 0]
  |  Branch (1668:38): [True: 0, False: 0]
  ------------------
 1669|      0|			free(ecparams->der.value); /* just in case */
 1670|      0|			ecparams->der.value = NULL;
 1671|      0|			ecparams->der.len = 0;
 1672|       |			/* if caller did not provide valid der OID, fill in */
 1673|      0|			rv = sc_encode_oid (ctx, &ecparams->id, &ecparams->der.value, &ecparams->der.len);
 1674|      0|			LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1675|      0|		}
 1676|      0|	} else
 1677|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "EC parameters has to be presented as a named curve or explicit data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1678|       |
 1679|  5.27k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  5.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.27k|	int _ret = r; \
  |  |  |  |  155|  5.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.27k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.27k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.27k|	return _ret; \
  |  |  |  |  163|  5.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1680|  5.27k|}

sc_pkcs15emu_sc_hsm_decode_cvc:
  433|     68|{
  434|     68|	sc_card_t *card = p15card->card;
  435|     68|	struct sc_asn1_entry asn1_req[C_ASN1_REQ_SIZE];
  436|     68|	struct sc_asn1_entry asn1_authreq[C_ASN1_AUTHREQ_SIZE];
  437|     68|	struct sc_asn1_entry asn1_cvc[C_ASN1_CVC_SIZE];
  438|     68|	struct sc_asn1_entry asn1_cvcert[C_ASN1_CVCERT_SIZE];
  439|     68|	struct sc_asn1_entry asn1_cvc_body[C_ASN1_CVC_BODY_SIZE];
  440|     68|	struct sc_asn1_entry asn1_cvc_pubkey[C_ASN1_CVC_PUBKEY_SIZE];
  441|     68|	unsigned int cla = 0, tag = 0;
  442|     68|	size_t taglen;
  443|     68|	const u8 *tbuf;
  444|     68|	int r;
  445|       |
  446|     68|	memset(cvc, 0, sizeof(*cvc));
  447|     68|	sc_copy_asn1_entry(c_asn1_req, asn1_req);
  448|     68|	sc_copy_asn1_entry(c_asn1_cvc, asn1_cvc);
  449|       |
  450|     68|	r = sc_pkcs15emu_sc_hsm_format_asn1_cvcert(
  451|     68|			asn1_cvcert, C_ASN1_CVCERT_SIZE,
  ------------------
  |  |  242|     68|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  452|     68|			asn1_cvc_body, C_ASN1_CVC_BODY_SIZE,
  ------------------
  |  |  233|     68|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  453|     68|			asn1_cvc_pubkey, C_ASN1_CVC_PUBKEY_SIZE,
  ------------------
  |  |  219|     68|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  454|     68|			cvc);
  455|     68|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  174|     68|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     68|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     68|	int _ret = (r); \
  |  |  |  |  168|     68|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  456|       |
  457|     68|	sc_format_asn1_entry(asn1_cvc, asn1_cvcert, NULL, 0);
  458|       |
  459|     68|	r = sc_pkcs15emu_sc_hsm_format_asn1_req(
  460|     68|			asn1_authreq, C_ASN1_AUTHREQ_SIZE,
  ------------------
  |  |  255|     68|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  461|     68|			asn1_cvcert, cvc);
  462|     68|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  174|     68|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     68|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     68|	int _ret = (r); \
  |  |  |  |  168|     68|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|       |
  464|     68|	sc_format_asn1_entry(asn1_req, asn1_authreq, NULL, 0);
  465|       |
  466|       |/*	sc_asn1_print_tags(*buf, *buflen); */
  467|       |
  468|     68|	tbuf = *buf;
  469|     68|	r = sc_asn1_read_tag(&tbuf, *buflen, &cla, &tag, &taglen);
  470|     68|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  174|     68|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     68|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     68|	int _ret = (r); \
  |  |  |  |  168|     68|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 37, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  169|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     37|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     37|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     37|		return _ret; \
  |  |  |  |  172|     37|	} \
  |  |  |  |  173|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  471|       |
  472|       |	/*  Determine if we deal with an authenticated request, plain request or certificate */
  473|     31|	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  186|     31|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
              	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  190|     31|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (473:6): [True: 13, False: 18]
  |  Branch (473:68): [True: 3, False: 10]
  ------------------
  474|      3|		r = sc_asn1_decode(card->ctx, asn1_req, *buf, *buflen, buf, buflen);
  475|     28|	} else {
  476|     28|		r = sc_asn1_decode(card->ctx, asn1_cvc, *buf, *buflen, buf, buflen);
  477|     28|	}
  478|       |
  479|     31|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  174|     31|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     31|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     31|	int _ret = (r); \
  |  |  |  |  168|     31|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     31|		return _ret; \
  |  |  |  |  172|     31|	} \
  |  |  |  |  173|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|       |
  481|      0|	fixup_cvc_printable_string_lengths(cvc);
  482|       |
  483|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|      0|}
sc_pkcs15emu_sc_hsm_free_cvc:
 1025|     16|{
 1026|     16|	if (cvc->outerSignature) {
  ------------------
  |  Branch (1026:6): [True: 0, False: 16]
  ------------------
 1027|      0|		free(cvc->outerSignature);
 1028|      0|		cvc->outerSignature = NULL;
 1029|      0|	}
 1030|     16|	if (cvc->signature) {
  ------------------
  |  Branch (1030:6): [True: 0, False: 16]
  ------------------
 1031|      0|		free(cvc->signature);
 1032|      0|		cvc->signature = NULL;
 1033|      0|	}
 1034|     16|	if (cvc->primeOrModulus) {
  ------------------
  |  Branch (1034:6): [True: 0, False: 16]
  ------------------
 1035|      0|		free(cvc->primeOrModulus);
 1036|      0|		cvc->primeOrModulus = NULL;
 1037|      0|	}
 1038|     16|	if (cvc->coefficientAorExponent) {
  ------------------
  |  Branch (1038:6): [True: 0, False: 16]
  ------------------
 1039|      0|		free(cvc->coefficientAorExponent);
 1040|      0|		cvc->coefficientAorExponent = NULL;
 1041|      0|	}
 1042|     16|	if (cvc->coefficientB) {
  ------------------
  |  Branch (1042:6): [True: 0, False: 16]
  ------------------
 1043|      0|		free(cvc->coefficientB);
 1044|      0|		cvc->coefficientB = NULL;
 1045|      0|	}
 1046|     16|	if (cvc->basePointG) {
  ------------------
  |  Branch (1046:6): [True: 0, False: 16]
  ------------------
 1047|      0|		free(cvc->basePointG);
 1048|      0|		cvc->basePointG = NULL;
 1049|      0|	}
 1050|     16|	if (cvc->order) {
  ------------------
  |  Branch (1050:6): [True: 0, False: 16]
  ------------------
 1051|      0|		free(cvc->order);
 1052|      0|		cvc->order = NULL;
 1053|      0|	}
 1054|     16|	if (cvc->publicPoint) {
  ------------------
  |  Branch (1054:6): [True: 0, False: 16]
  ------------------
 1055|      0|		free(cvc->publicPoint);
 1056|      0|		cvc->publicPoint = NULL;
 1057|      0|	}
 1058|     16|	if (cvc->cofactor) {
  ------------------
  |  Branch (1058:6): [True: 0, False: 16]
  ------------------
 1059|      0|		free(cvc->cofactor);
 1060|       |		cvc->cofactor = NULL;
 1061|      0|	}
 1062|     16|}
sc_pkcs15emu_sc_hsm_init_ex:
 1612|  9.12k|{
 1613|  9.12k|	if (p15card->card->type != SC_CARD_TYPE_SC_HSM
  ------------------
  |  Branch (1613:6): [True: 9.12k, False: 0]
  ------------------
 1614|  9.12k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1614:7): [True: 9.12k, False: 0]
  ------------------
 1615|  9.12k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1615:7): [True: 9.01k, False: 115]
  ------------------
 1616|  9.01k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1617|  9.01k|	}
 1618|    115|	return sc_pkcs15emu_sc_hsm_init(p15card);
 1619|  9.12k|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_cvcert:
  365|     68|{
  366|     68|	if ((asn1_cvc_pubkey_len < C_ASN1_CVC_PUBKEY_SIZE) ||
  ------------------
  |  |  219|     68|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  |  Branch (366:6): [True: 0, False: 68]
  ------------------
  367|     68|		(asn1_cvc_body_len < C_ASN1_CVC_BODY_SIZE) ||
  ------------------
  |  |  233|     68|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  |  Branch (367:3): [True: 0, False: 68]
  ------------------
  368|     68|		(asn1_cvcert_len < C_ASN1_CVCERT_SIZE)) {
  ------------------
  |  |  242|     68|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  |  Branch (368:3): [True: 0, False: 68]
  ------------------
  369|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  370|      0|	}
  371|       |
  372|     68|	sc_copy_asn1_entry(c_asn1_cvc_pubkey, asn1_cvc_pubkey);
  373|     68|	sc_copy_asn1_entry(c_asn1_cvc_body, asn1_cvc_body);
  374|     68|	sc_copy_asn1_entry(c_asn1_cvcert, asn1_cvcert);
  375|       |
  376|     68|	sc_format_asn1_entry(asn1_cvc_pubkey    , &cvc->pukoid, NULL, 0);
  377|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 1, &cvc->primeOrModulus, &cvc->primeOrModuluslen, 0);
  378|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 2, &cvc->coefficientAorExponent, &cvc->coefficientAorExponentlen, 0);
  379|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 3, &cvc->coefficientB, &cvc->coefficientBlen, 0);
  380|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 4, &cvc->basePointG, &cvc->basePointGlen, 0);
  381|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 5, &cvc->order, &cvc->orderlen, 0);
  382|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 6, &cvc->publicPoint, &cvc->publicPointlen, 0);
  383|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 7, &cvc->cofactor, &cvc->cofactorlen, 0);
  384|     68|	sc_format_asn1_entry(asn1_cvc_pubkey + 8, &cvc->modulusSize, NULL, 0);
  385|       |
  386|     68|	sc_format_asn1_entry(asn1_cvc_body    , &cvc->cpi, NULL, 0);
  387|     68|	cvc->carLen = sizeof(cvc->car);
  388|     68|	sc_format_asn1_entry(asn1_cvc_body + 1, &cvc->car, &cvc->carLen, 0);
  389|     68|	sc_format_asn1_entry(asn1_cvc_body + 2, asn1_cvc_pubkey, NULL, 0);
  390|     68|	cvc->chrLen = sizeof(cvc->chr);
  391|     68|	sc_format_asn1_entry(asn1_cvc_body + 3, &cvc->chr, &cvc->chrLen, 0);
  392|       |
  393|     68|	sc_format_asn1_entry(asn1_cvcert    , asn1_cvc_body, NULL, 0);
  394|     68|	sc_format_asn1_entry(asn1_cvcert + 1, &cvc->signature, &cvc->signatureLen, 0);
  395|     68|	return SC_SUCCESS;
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  396|     68|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_req:
  413|     68|{
  414|     68|	if (asn1_authreq_len < C_ASN1_AUTHREQ_SIZE) {
  ------------------
  |  |  255|     68|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  |  Branch (414:6): [True: 0, False: 68]
  ------------------
  415|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  416|      0|	}
  417|       |
  418|     68|	sc_copy_asn1_entry(c_asn1_authreq, asn1_authreq);
  419|       |
  420|     68|	sc_format_asn1_entry(asn1_authreq    , asn1_cvcert, NULL, 0);
  421|     68|	cvc->outerCARLen = sizeof(cvc->outer_car);
  422|     68|	sc_format_asn1_entry(asn1_authreq + 1, &cvc->outer_car, &cvc->outerCARLen, 0);
  423|     68|	sc_format_asn1_entry(asn1_authreq + 2, &cvc->outerSignature, &cvc->outerSignatureLen, 0);
  424|     68|	return SC_SUCCESS;
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  425|     68|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_init:
 1350|    115|{
 1351|    115|	sc_card_t *card = p15card->card;
 1352|    115|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1353|    115|	sc_file_t *file = NULL;
 1354|    115|	sc_path_t path;
 1355|    115|	u8 filelist[MAX_EXT_APDU_LENGTH];
 1356|    115|	int filelistlength;
 1357|    115|	int r, i;
 1358|    115|	sc_cvc_t devcert;
 1359|    115|	struct sc_app_info *appinfo;
 1360|    115|	struct sc_pkcs15_auth_info pin_info;
 1361|    115|	struct sc_pkcs15_object pin_obj;
 1362|    115|	struct sc_pin_cmd_data pindata;
 1363|    115|	u8 efbin[1024];
 1364|    115|	u8 *ptr;
 1365|    115|	size_t len;
 1366|       |
 1367|    115|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    115|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    115|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    115|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    115|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 115]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1368|       |
 1369|    115|	appinfo = calloc(1, sizeof(struct sc_app_info));
 1370|       |
 1371|    115|	if (appinfo == NULL) {
  ------------------
  |  Branch (1371:6): [True: 0, False: 115]
  ------------------
 1372|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|      0|	}
 1374|       |
 1375|    115|	appinfo->aid = sc_hsm_aid;
 1376|       |
 1377|    115|	appinfo->ddo.aid = sc_hsm_aid;
 1378|    115|	p15card->app = appinfo;
 1379|       |
 1380|    115|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    115|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1381|    115|	r = sc_select_file(card, &path, &file);
 1382|    115|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|    115|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    115|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    115|	int _ret = (r); \
  |  |  |  |  168|    115|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 48, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  169|     48|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     48|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     48|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     48|		return _ret; \
  |  |  |  |  172|     48|	} \
  |  |  |  |  173|    115|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|       |
 1384|     67|	p15card->card->version.hw_major = 24;	/* JCOP 2.4.1r3 */
 1385|     67|	p15card->card->version.hw_minor = 13;
 1386|     67|	if (file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1386:6): [True: 67, False: 0]
  |  Branch (1386:14): [True: 6, False: 61]
  |  Branch (1386:33): [True: 4, False: 2]
  ------------------
 1387|      4|		p15card->card->version.fw_major = file->prop_attr[file->prop_attr_len - 2];
 1388|      4|		p15card->card->version.fw_minor = file->prop_attr[file->prop_attr_len - 1];
 1389|      4|	}
 1390|       |
 1391|     67|	sc_file_free(file);
 1392|       |
 1393|       |	/* Read device certificate to determine serial number */
 1394|     67|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (1394:6): [True: 0, False: 67]
  |  Branch (1394:27): [True: 0, False: 0]
  ------------------
 1395|      0|		ptr = priv->EF_C_DevAut;
 1396|      0|		len = priv->EF_C_DevAut_len;
 1397|     67|	} else {
 1398|     67|		len = sizeof efbin;
 1399|     67|		r = read_file(p15card, (u8 *) "\x2F\x02", efbin, &len, 1);
 1400|     67|		LOG_TEST_RET(card->ctx, r, "Skipping optional EF.C_DevAut");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|       |
 1402|     67|		if (len > 0) {
  ------------------
  |  Branch (1402:7): [True: 35, False: 32]
  ------------------
 1403|       |			/* save EF_C_DevAut for further use */
 1404|     35|			ptr = realloc(priv->EF_C_DevAut, len);
 1405|     35|			if (ptr) {
  ------------------
  |  Branch (1405:8): [True: 35, False: 0]
  ------------------
 1406|     35|				memcpy(ptr, efbin, len);
 1407|     35|				priv->EF_C_DevAut = ptr;
 1408|     35|				priv->EF_C_DevAut_len = len;
 1409|     35|			}
 1410|     35|		}
 1411|       |
 1412|     67|		ptr = efbin;
 1413|     67|	}
 1414|       |
 1415|     67|	memset(&devcert, 0 ,sizeof(devcert));
 1416|     67|	r = sc_pkcs15emu_sc_hsm_decode_cvc(p15card, (const u8 **)&ptr, &len, &devcert);
 1417|     67|	LOG_TEST_RET(card->ctx, r, "Could not decode EF.C_DevAut");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     67|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     67|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     67|		return _ret; \
  |  |  |  |  172|     67|	} \
  |  |  |  |  173|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1418|       |
 1419|      0|	sc_pkcs15emu_sc_hsm_read_tokeninfo(p15card);
 1420|       |
 1421|      0|	if (p15card->tokeninfo->label == NULL) {
  ------------------
  |  Branch (1421:6): [True: 0, False: 0]
  ------------------
 1422|      0|		if (p15card->card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (1422:7): [True: 0, False: 0]
  ------------------
 1423|      0|				|| p15card->card->type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (1423:8): [True: 0, False: 0]
  ------------------
 1424|      0|			p15card->tokeninfo->label = strdup("GoID");
 1425|      0|		} else {
 1426|      0|			p15card->tokeninfo->label = strdup("SmartCard-HSM");
 1427|      0|		}
 1428|      0|		if (p15card->tokeninfo->label == NULL)
  ------------------
  |  Branch (1428:7): [True: 0, False: 0]
  ------------------
 1429|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|      0|	}
 1431|       |
 1432|      0|	if ((p15card->tokeninfo->manufacturer_id != NULL) && !strcmp("(unknown)", p15card->tokeninfo->manufacturer_id)) {
  ------------------
  |  Branch (1432:6): [True: 0, False: 0]
  |  Branch (1432:55): [True: 0, False: 0]
  ------------------
 1433|      0|		free(p15card->tokeninfo->manufacturer_id);
 1434|      0|		p15card->tokeninfo->manufacturer_id = NULL;
 1435|      0|	}
 1436|       |
 1437|      0|	if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (1437:6): [True: 0, False: 0]
  ------------------
 1438|      0|		if (p15card->card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (1438:7): [True: 0, False: 0]
  ------------------
 1439|      0|				|| p15card->card->type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (1439:8): [True: 0, False: 0]
  ------------------
 1440|      0|			p15card->tokeninfo->manufacturer_id = strdup("Bundesdruckerei GmbH");
 1441|      0|		} else {
 1442|      0|			p15card->tokeninfo->manufacturer_id = strdup("www.CardContact.de");
 1443|      0|		}
 1444|      0|		if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (1444:7): [True: 0, False: 0]
  ------------------
 1445|      0|			sc_pkcs15_card_clear(p15card);
 1446|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1447|      0|		}
 1448|      0|	}
 1449|       |
 1450|      0|	appinfo->label = strdup(p15card->tokeninfo->label);
 1451|      0|	if (appinfo->label == NULL) {
  ------------------
  |  Branch (1451:6): [True: 0, False: 0]
  ------------------
 1452|      0|		sc_pkcs15_card_clear(p15card);
 1453|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1454|      0|	}
 1455|       |
 1456|      0|	len = strnlen(devcert.chr, sizeof devcert.chr);		/* Strip last 5 digit sequence number from CHR */
 1457|      0|	if (len < 8)
  ------------------
  |  Branch (1457:6): [True: 0, False: 0]
  ------------------
 1458|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1459|      0|	len -= 5;
 1460|       |
 1461|      0|	free(p15card->tokeninfo->serial_number);
 1462|      0|	p15card->tokeninfo->serial_number = calloc(1, len + 1);
 1463|      0|	if (p15card->tokeninfo->serial_number == NULL) {
  ------------------
  |  Branch (1463:6): [True: 0, False: 0]
  ------------------
 1464|      0|		sc_pkcs15_card_clear(p15card);
 1465|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1466|      0|	}
 1467|       |
 1468|      0|	memcpy(p15card->tokeninfo->serial_number, devcert.chr, len);
 1469|      0|	*(p15card->tokeninfo->serial_number + len) = 0;
 1470|       |
 1471|      0|	sc_hsm_set_serialnr(card, p15card->tokeninfo->serial_number);
 1472|       |
 1473|      0|	sc_pkcs15emu_sc_hsm_free_cvc(&devcert);
 1474|       |
 1475|      0|	memset(&pin_info, 0, sizeof(pin_info));
 1476|      0|	memset(&pin_obj, 0, sizeof(pin_obj));
 1477|       |
 1478|      0|	pin_info.auth_id.len = 1;
 1479|      0|	pin_info.auth_id.value[0] = 1;
 1480|      0|	pin_info.path.aid = sc_hsm_aid;
 1481|      0|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1482|      0|	pin_info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1483|      0|	pin_info.attrs.pin.reference = 0x81;
 1484|      0|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED|SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED|SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED|SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA;
  ------------------
  |  |   65|      0|#define SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA		0x0800
  ------------------
 1485|      0|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|      0|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1486|      0|	pin_info.attrs.pin.min_length = 6;
 1487|      0|	pin_info.attrs.pin.stored_length = 0;
 1488|      0|	pin_info.attrs.pin.max_length = 15;
 1489|      0|	pin_info.attrs.pin.pad_char = '\0';
 1490|      0|	pin_info.tries_left = 3;
 1491|      0|	pin_info.max_tries = 3;
 1492|       |
 1493|      0|	pin_obj.auth_id.len = 1;
 1494|      0|	pin_obj.auth_id.value[0] = 2;
 1495|      0|	strlcpy(pin_obj.label, "UserPIN", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1496|      0|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
 1497|       |
 1498|      0|	pin_obj.data = &pin_info;
 1499|       |
 1500|      0|	r = sc_pkcs15_get_pin_info(p15card, &pin_obj);
 1501|       |
 1502|      0|	if (r != SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1502:6): [True: 0, False: 0]
  ------------------
 1503|      0|		if (r < 0) {
  ------------------
  |  Branch (1503:7): [True: 0, False: 0]
  ------------------
 1504|      0|			sc_pkcs15_card_clear(p15card);
 1505|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1506|      0|		}
 1507|       |
 1508|      0|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
 1509|      0|		if (r < 0) {
  ------------------
  |  Branch (1509:7): [True: 0, False: 0]
  ------------------
 1510|      0|			sc_pkcs15_card_clear(p15card);
 1511|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1512|      0|		}
 1513|      0|	}
 1514|       |
 1515|      0|	memset(&pin_info, 0, sizeof(pin_info));
 1516|      0|	memset(&pin_obj, 0, sizeof(pin_obj));
 1517|       |
 1518|      0|	pin_info.auth_id.len = 1;
 1519|      0|	pin_info.auth_id.value[0] = 2;
 1520|      0|	pin_info.path.aid = sc_hsm_aid;
 1521|      0|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1522|      0|	pin_info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1523|      0|	pin_info.attrs.pin.reference = 0x88;
 1524|      0|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED|SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED|SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   57|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED		0x0008
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED|SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
 1525|      0|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_BCD;
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
 1526|      0|	pin_info.attrs.pin.min_length = 16;
 1527|      0|	pin_info.attrs.pin.stored_length = 0;
 1528|      0|	pin_info.attrs.pin.max_length = 16;
 1529|      0|	pin_info.attrs.pin.pad_char = '\0';
 1530|      0|	pin_info.tries_left = 15;
 1531|      0|	pin_info.max_tries = 15;
 1532|       |
 1533|      0|	strlcpy(pin_obj.label, "SOPIN", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1534|      0|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1535|       |
 1536|      0|	pin_obj.data = &pin_info;
 1537|       |
 1538|      0|	r = sc_pkcs15_get_pin_info(p15card, &pin_obj);
 1539|       |
 1540|      0|	if (r != SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1540:6): [True: 0, False: 0]
  ------------------
 1541|      0|		pin_info.attrs.pin.flags |= SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1542|      0|	} else {
 1543|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1544|      0|	}
 1545|       |
 1546|      0|	if (r < 0) {
  ------------------
  |  Branch (1546:6): [True: 0, False: 0]
  ------------------
 1547|      0|		sc_pkcs15_card_clear(p15card);
 1548|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1549|      0|	}
 1550|       |
 1551|      0|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
 1552|      0|	if (r < 0) {
  ------------------
  |  Branch (1552:6): [True: 0, False: 0]
  ------------------
 1553|      0|		sc_pkcs15_card_clear(p15card);
 1554|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1555|      0|	}
 1556|       |
 1557|       |
 1558|      0|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1558:6): [True: 0, False: 0]
  ------------------
 1559|      0|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1559:7): [True: 0, False: 0]
  ------------------
 1560|       |		/* SC-HSM of this type always has a PIN-Pad */
 1561|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1562|      0|	} else {
 1563|      0|		memset(&pindata, 0, sizeof(pindata));
 1564|      0|		pindata.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1565|      0|		pindata.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1566|      0|		pindata.pin_reference = 0x85;
 1567|       |
 1568|      0|		r = sc_pin_cmd(card, &pindata);
 1569|      0|	}
 1570|      0|	if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1570:6): [True: 0, False: 0]
  ------------------
 1571|      0|		memset(&pindata, 0, sizeof(pindata));
 1572|      0|		pindata.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1573|      0|		pindata.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1574|      0|		pindata.pin_reference = 0x86;
 1575|       |
 1576|      0|		r = sc_pin_cmd(card, &pindata);
 1577|      0|	}
 1578|       |
 1579|      0|	if ((r != SC_ERROR_DATA_OBJECT_NOT_FOUND) && (r != SC_ERROR_INCORRECT_PARAMETERS) && (r != SC_ERROR_REF_DATA_NOT_USABLE))
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
              	if ((r != SC_ERROR_DATA_OBJECT_NOT_FOUND) && (r != SC_ERROR_INCORRECT_PARAMETERS) && (r != SC_ERROR_REF_DATA_NOT_USABLE))
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
              	if ((r != SC_ERROR_DATA_OBJECT_NOT_FOUND) && (r != SC_ERROR_INCORRECT_PARAMETERS) && (r != SC_ERROR_REF_DATA_NOT_USABLE))
  ------------------
  |  |   70|      0|#define SC_ERROR_REF_DATA_NOT_USABLE	-1220
  ------------------
  |  Branch (1579:6): [True: 0, False: 0]
  |  Branch (1579:47): [True: 0, False: 0]
  |  Branch (1579:87): [True: 0, False: 0]
  ------------------
 1580|      0|		card->caps |= SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH;
  ------------------
  |  |  560|      0|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
 1581|       |
 1582|       |
 1583|      0|	filelistlength = sc_list_files(card, filelist, sizeof(filelist));
 1584|      0|	if (filelistlength < 0)
  ------------------
  |  Branch (1584:6): [True: 0, False: 0]
  ------------------
 1585|      0|		sc_pkcs15_card_clear(p15card);
 1586|      0|	LOG_TEST_RET(card->ctx, filelistlength, "Could not enumerate file and key identifier");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1587|       |
 1588|      0|	for (i = 0; i < filelistlength; i += 2) {
  ------------------
  |  Branch (1588:14): [True: 0, False: 0]
  ------------------
 1589|      0|		switch(filelist[i]) {
  ------------------
  |  Branch (1589:10): [True: 0, False: 0]
  ------------------
 1590|      0|		case KEY_PREFIX:
  ------------------
  |  |   33|      0|#define KEY_PREFIX		0xCC		/* Hi byte in file identifier for key objects */
  ------------------
  |  Branch (1590:3): [True: 0, False: 0]
  ------------------
 1591|      0|			r = sc_pkcs15emu_sc_hsm_add_prkd(p15card, filelist[i + 1]);
 1592|      0|			break;
 1593|      0|		case DCOD_PREFIX:
  ------------------
  |  |   31|      0|#define DCOD_PREFIX		0xC9		/* Hi byte in file identifier for PKCS#15 DCOD objects */
  ------------------
  |  Branch (1593:3): [True: 0, False: 0]
  ------------------
 1594|      0|			r = sc_pkcs15emu_sc_hsm_add_dcod(p15card, filelist[i + 1]);
 1595|      0|			break;
 1596|      0|		case CD_PREFIX:
  ------------------
  |  |   30|      0|#define CD_PREFIX		0xC8		/* Hi byte in file identifier for PKCS#15 CD objects */
  ------------------
  |  Branch (1596:3): [True: 0, False: 0]
  ------------------
 1597|      0|			r = sc_pkcs15emu_sc_hsm_add_cd(p15card, filelist[i + 1]);
 1598|      0|			break;
 1599|      0|		}
 1600|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1600:7): [True: 0, False: 0]
  ------------------
 1601|      0|			sc_log(card->ctx, "Error %d adding elements to framework", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1602|      0|		}
 1603|      0|	}
 1604|       |
 1605|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1606|      0|}
pkcs15-sc-hsm.c:read_file:
  293|     67|{
  294|     67|	sc_path_t path;
  295|     67|	int r;
  296|       |
  297|     67|	sc_path_set(&path, SC_PATH_TYPE_FILE_ID, fid, 2, 0, 0);
  ------------------
  |  |  117|     67|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  298|       |	/* look this up with our AID */
  299|     67|	path.aid = sc_hsm_aid;
  300|       |	/* we don't have a pre-known size of the file */
  301|     67|	path.count = -1;
  302|     67|	if (!p15card->opts.use_file_cache || !efbin
  ------------------
  |  Branch (302:6): [True: 67, False: 0]
  |  Branch (302:39): [True: 0, False: 0]
  ------------------
  303|     67|			|| SC_SUCCESS != sc_pkcs15_read_cached_file(p15card, &path, &efbin, len)) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (303:7): [True: 0, False: 0]
  ------------------
  304|       |		/* avoid re-selection of SC-HSM */
  305|     67|		path.aid.len = 0;
  306|     67|		r = sc_select_file(p15card->card, &path, NULL);
  307|     67|		if (r < 0) {
  ------------------
  |  Branch (307:7): [True: 19, False: 48]
  ------------------
  308|     19|			sc_log(p15card->card->ctx, "Could not select EF");
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  309|     48|		} else {
  310|     48|			r = sc_read_binary(p15card->card, 0, efbin, *len, 0);
  311|     48|		}
  312|       |
  313|     67|		if (r < 0) {
  ------------------
  |  Branch (313:7): [True: 27, False: 40]
  ------------------
  314|     27|			sc_log(p15card->card->ctx, "Could not read EF");
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|     27|			if (!optional) {
  ------------------
  |  Branch (315:8): [True: 0, False: 27]
  ------------------
  316|      0|				return r;
  317|      0|			}
  318|       |			/* optional files are saved as empty files to avoid card
  319|       |			 * transactions. Parsing the file's data will reveal that they were
  320|       |			 * missing. */
  321|     27|			*len = 0;
  322|     40|		} else {
  323|     40|			*len = r;
  324|     40|		}
  325|       |
  326|     67|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (326:7): [True: 0, False: 67]
  ------------------
  327|       |			/* save this with our AID */
  328|      0|			path.aid = sc_hsm_aid;
  329|      0|			sc_pkcs15_cache_file(p15card, &path, efbin, *len);
  330|      0|		}
  331|     67|	}
  332|       |
  333|     67|	return SC_SUCCESS;
  ------------------
  |  |   28|     67|#define SC_SUCCESS				0
  ------------------
  334|     67|}

sc_pkcs15_decipher:
  283|    272|{
  284|    272|	sc_context_t *ctx = p15card->card->ctx;
  285|    272|	int r;
  286|    272|	sc_algorithm_info_t *alg_info = NULL;
  287|    272|	sc_security_env_t senv;
  288|    272|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  289|    272|	unsigned long pad_flags = 0, sec_flags = 0;
  290|       |
  291|    272|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    272|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    272|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    272|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    272|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 272]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|    272|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|    272|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|    272|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (293:6): [True: 0, False: 272]
  ------------------
  294|    272|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for decryption");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|       |
  296|    272|	r = format_senv(p15card, obj, &senv, &alg_info);
  297|    272|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    272|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    272|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    272|	int _ret = (r); \
  |  |  |  |  168|    272|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 259]
  |  |  |  |  ------------------
  |  |  |  |  169|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     13|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     13|		return _ret; \
  |  |  |  |  172|     13|	} \
  |  |  |  |  173|    272|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 259]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|    259|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|    259|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  299|       |
  300|    259|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  301|    259|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    259|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    259|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    259|	int _ret = (r); \
  |  |  |  |  168|    259|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 255]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|    259|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|    255|	senv.algorithm_flags = sec_flags;
  303|       |
  304|    255|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  305|    255|			outlen);
  306|    255|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 141, False: 114]
  |  |  |  |  ------------------
  |  |  |  |  169|    141|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    141|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    141|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    141|		return _ret; \
  |  |  |  |  172|    141|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 114]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Strip any padding */
  309|    114|	if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  110|    114|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (309:6): [True: 80, False: 34]
  ------------------
  310|     80|		unsigned int s = r;
  311|     80|		unsigned int key_size = (unsigned int)alg_info->key_length;
  312|     80|		r = sc_pkcs1_strip_02_padding_constant_time(ctx, key_size / 8, out, s, out, &s);
  313|       |		/* for keeping PKCS#1 v1.5 depadding constant-time, do not log error here */
  314|     80|	}
  315|     34|#ifdef ENABLE_OPENSSL
  316|     34|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|     34|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (316:11): [True: 0, False: 34]
  ------------------
  317|      0|		size_t s = r;
  318|      0|		uint8_t *param = NULL;
  319|      0|		size_t paramlen = 0;
  320|      0|		if (pMechanism != NULL) {
  ------------------
  |  Branch (320:7): [True: 0, False: 0]
  ------------------
  321|      0|			CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
  322|      0|			if (mech->pParameter && sizeof(CK_RSA_PKCS_OAEP_PARAMS) == mech->ulParameterLen) {
  ------------------
  |  Branch (322:8): [True: 0, False: 0]
  |  Branch (322:28): [True: 0, False: 0]
  ------------------
  323|      0|				CK_RSA_PKCS_OAEP_PARAMS * oaep_params = mech->pParameter;
  324|      0|				if (oaep_params->source == CKZ_DATA_SPECIFIED) {
  ------------------
  |  | 1227|      0|#define CKZ_DATA_SPECIFIED 0x00000001UL
  ------------------
  |  Branch (324:9): [True: 0, False: 0]
  ------------------
  325|      0|					param = oaep_params->pSourceData;
  326|      0|					paramlen = (size_t)oaep_params->ulSourceDataLen;
  327|      0|				}
  328|      0|			}
  329|      0|		}
  330|      0|		r = sc_pkcs1_strip_oaep_padding(ctx, out, s, flags, param, paramlen);
  331|      0|		LOG_TEST_RET(ctx, r, "Invalid OAEP padding");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  332|      0|	}
  333|    114|#endif
  334|       |	/* do not log error code to prevent side channel attack */
  335|    114|	return r;
  336|    114|}
sc_pkcs15_compute_signature:
  597|    192|{
  598|    192|	sc_context_t *ctx = p15card->card->ctx;
  599|    192|	int r;
  600|    192|	sc_security_env_t senv;
  601|    192|	sc_algorithm_info_t *alg_info;
  602|    192|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  603|    192|	u8 *buf = NULL, *tmp;
  604|    192|	size_t modlen = 0, buflen = 0;
  605|    192|	unsigned long pad_flags = 0, sec_flags = 0;
  606|       |
  607|    192|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    192|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    192|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    192|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    192|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 192]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|    192|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|    192|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|    192|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (609:6): [True: 0, False: 192]
  ------------------
  610|    192|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|    192|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  611|    192|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for signing");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|    192|	r = format_senv(p15card, obj, &senv, &alg_info);
  614|    192|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    192|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    192|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    192|	int _ret = (r); \
  |  |  |  |  168|    192|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|    192|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|    184|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|    184|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  616|       |
  617|    184|	switch (obj->type) {
  618|    144|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    144|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (618:3): [True: 144, False: 40]
  ------------------
  619|    144|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  145|    144|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  620|    144|			break;
  621|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (621:3): [True: 0, False: 184]
  ------------------
  622|      0|			modlen = BYTES4BITS(prkey->modulus_length) * 2;
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  623|      0|			break;
  624|     40|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     40|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (624:3): [True: 40, False: 144]
  ------------------
  625|     40|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|     40|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (625:3): [True: 0, False: 184]
  ------------------
  626|     40|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|     40|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (626:3): [True: 0, False: 184]
  ------------------
  627|     40|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  145|     40|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  628|     40|			break;
  629|      0|		default:
  ------------------
  |  Branch (629:3): [True: 0, False: 184]
  ------------------
  630|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|    184|	}
  632|       |
  633|       |	/* Probably never happens, but better make sure */
  634|    184|	if (outlen < modlen)
  ------------------
  |  Branch (634:6): [True: 3, False: 181]
  ------------------
  635|    184|		LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    181|	buflen = inlen + modlen;
  638|    181|	buf = sc_mem_secure_alloc(buflen);
  639|    181|	if (buf == NULL)
  ------------------
  |  Branch (639:6): [True: 0, False: 181]
  ------------------
  640|    181|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  641|    181|	memcpy(buf, in, inlen);
  642|       |
  643|       |	/* revert data to sign when signing with the GOST key.
  644|       |	 * TODO: can it be confirmed by the GOST standard?
  645|       |	 * TODO: tested with RuTokenECP, has to be validated for RuToken. */
  646|    181|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|    181|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (646:6): [True: 0, False: 181]
  ------------------
  647|      0|		r = sc_mem_reverse(buf, inlen);
  648|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Reverse memory error");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  649|      0|	}
  650|       |
  651|    181|	tmp = buf;
  652|       |
  653|       |	/* flags: the requested algo
  654|       |	 * algo_info->flags: what is supported by the card
  655|       |	 * senv.algorithm_flags: what the card will have to do */
  656|       |
  657|       |	/* if the card has SC_ALGORITHM_NEED_USAGE set, and the
  658|       |	 * key is for signing and decryption, we need to emulate signing */
  659|       |
  660|    181|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|    181|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  661|    181|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|    181|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (661:6): [True: 141, False: 40]
  ------------------
  662|    141|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |   95|    141|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (662:7): [True: 0, False: 141]
  ------------------
  663|      0|			((prkey->usage & USAGE_ANY_SIGN) &&
  ------------------
  |  |  588|      0|#define USAGE_ANY_SIGN          (SC_PKCS15_PRKEY_USAGE_SIGN|\
  |  |  ------------------
  |  |  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  |  |  589|      0|                                 SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)
  |  |  ------------------
  |  |  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  |  Branch (663:5): [True: 0, False: 0]
  ------------------
  664|      0|			(prkey->usage & USAGE_ANY_DECIPHER)) ) {
  ------------------
  |  |  590|      0|#define USAGE_ANY_DECIPHER      (SC_PKCS15_PRKEY_USAGE_DECRYPT|\
  |  |  ------------------
  |  |  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |  591|      0|                                 SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  |  Branch (664:4): [True: 0, False: 0]
  ------------------
  665|      0|			size_t tmplen = buflen;
  666|      0|			if (flags & SC_ALGORITHM_RSA_RAW) {
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (666:8): [True: 0, False: 0]
  ------------------
  667|      0|				r = sc_pkcs15_decipher(p15card, obj, flags, in, inlen, out, outlen, NULL);
  668|      0|				goto err;
  669|      0|			}
  670|      0|			if (modlen > tmplen)
  ------------------
  |  Branch (670:8): [True: 0, False: 0]
  ------------------
  671|      0|				LOG_TEST_GOTO_ERR(ctx, SC_ERROR_NOT_ALLOWED, "Buffer too small, needs recompile!");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|       |
  673|       |			/* XXX Assuming RSA key here */
  674|      0|			r = sc_pkcs1_encode(ctx, flags, in, inlen, buf, &tmplen, prkey->modulus_length, pMechanism);
  675|       |
  676|       |			/* no padding needed - already done */
  677|      0|			flags &= ~SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|      0|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  678|       |			/* instead use raw rsa */
  679|      0|			flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  680|       |
  681|      0|			LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|       |
  683|      0|			r = sc_pkcs15_decipher(p15card, obj, flags, buf, modlen, out, outlen, NULL);
  684|      0|			goto err;
  685|      0|		}
  686|       |
  687|       |
  688|       |		/* If the card doesn't support the requested algorithm, we normally add the
  689|       |		 * padding here in software and ask the card to do a raw signature.  There's
  690|       |		 * one exception to that, where we might be able to get the signature to
  691|       |		 * succeed by stripping padding if the card only offers higher-level
  692|       |		 * signature operations.  The only thing we can strip is the DigestInfo
  693|       |		 * block from PKCS1 padding. */
  694|    141|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|    141|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|    141|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (694:7): [True: 0, False: 141]
  ------------------
  695|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (695:4): [True: 0, False: 0]
  ------------------
  696|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_HASH_NONE) &&
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (696:4): [True: 0, False: 0]
  ------------------
  697|      0|			(alg_info->flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (697:4): [True: 0, False: 0]
  ------------------
  698|      0|			unsigned int algo;
  699|      0|			size_t tmplen = buflen;
  700|       |
  701|      0|			r = sc_pkcs1_strip_digest_info_prefix(&algo, tmp, inlen, tmp, &tmplen);
  702|      0|			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (702:8): [True: 0, False: 0]
  |  Branch (702:27): [True: 0, False: 0]
  ------------------
  703|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|				goto err;
  705|      0|			}
  706|      0|			flags &= ~SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  707|      0|			flags |= algo;
  708|      0|			inlen = tmplen;
  709|      0|		}
  710|    141|	}
  711|       |
  712|       |
  713|       |	/* ECDSA software hash has already been done, or is not needed, or card will do hash */
  714|       |	/* if card can not do the hash, will use SC_ALGORITHM_ECDSA_RAW */
  715|    181|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|    181|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (715:6): [True: 40, False: 141]
  ------------------
  716|     40|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  174|     40|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (716:7): [True: 40, False: 0]
  ------------------
  717|     40|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  181|     40|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     40|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     40|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     40|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     40|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     40|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     40|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     40|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     40|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     40|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (717:8): [True: 40, False: 0]
  ------------------
  718|     40|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  719|     40|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|     40|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  720|     40|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  181|     40|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     40|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     40|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     40|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     40|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     40|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     40|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     40|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     40|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     40|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|     40|		}
  722|     40|	}
  723|       |
  724|    181|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  725|    181|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    181|#define SC_SUCCESS				0
  ------------------
  |  Branch (725:6): [True: 1, False: 180]
  ------------------
  726|      1|		goto err;
  727|      1|	}
  728|       |	/* senv now has flags card or driver will do */
  729|    180|	senv.algorithm_flags = sec_flags;
  730|       |
  731|    180|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|    180|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  732|    180|		flags, alg_info->flags, pad_flags, sec_flags);
  733|       |
  734|       |	/* add the padding bytes (if necessary) */
  735|    180|	if (pad_flags != 0) {
  ------------------
  |  Branch (735:6): [True: 88, False: 92]
  ------------------
  736|     88|		size_t tmplen = buflen;
  737|       |
  738|       |		/* XXX Assuming RSA key here */
  739|     88|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  740|     88|		    prkey->modulus_length, pMechanism);
  741|     88|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|     88|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     88|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     88|	int _ret = (r); \
  |  |  |  |  178|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 80]
  |  |  |  |  ------------------
  |  |  |  |  179|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      8|		goto err; \
  |  |  |  |  182|      8|	} \
  |  |  |  |  183|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 80]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|     80|		inlen = tmplen;
  743|     80|	}
  744|     92|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   69|    184|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (744:12): [True: 52, False: 40]
  ------------------
  745|     52|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  103|     52|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  104|     52|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (745:12): [True: 0, False: 52]
  ------------------
  746|       |		/* Add zero-padding if input is shorter than the modulus */
  747|      0|		if (inlen < modlen) {
  ------------------
  |  Branch (747:7): [True: 0, False: 0]
  ------------------
  748|      0|			if (modlen > buflen) {
  ------------------
  |  Branch (748:8): [True: 0, False: 0]
  ------------------
  749|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  750|      0|				goto err;
  751|      0|			}
  752|      0|			memmove(tmp+modlen-inlen, tmp, inlen);
  753|      0|			memset(tmp, 0, modlen-inlen);
  754|      0|		}
  755|      0|		inlen = modlen;
  756|      0|	}
  757|       |	/* PKCS#11 MECHANISMS V2.30: 6.3.1 EC Signatures
  758|       |	 * If the length of the hash value is larger than the bit length of n, only
  759|       |	 * the leftmost bits of the hash up to the length of n will be used. Any
  760|       |	 * truncation is done by the token.
  761|       |	 * But if card is going to do the hash, pass in all the data
  762|       |	 */
  763|     92|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   70|    184|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (763:11): [True: 40, False: 52]
  ------------------
  764|     40|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  181|     40|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     40|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     40|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     40|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     40|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     40|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     40|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     40|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     40|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     40|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     40|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (764:4): [True: 40, False: 0]
  ------------------
  765|     40|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   69|     40|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 27, False: 13]
  |  |  ------------------
  ------------------
  766|     40|	}
  767|       |
  768|       |
  769|    172|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  770|    172|			out, outlen);
  771|    172|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|    172|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    172|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    172|	int _ret = (r); \
  |  |  |  |  178|    172|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 136, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  179|    136|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    136|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    136|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    136|		goto err; \
  |  |  |  |  182|    136|	} \
  |  |  |  |  183|    172|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|       |
  773|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  774|       |	/* Already know outlen >= modlen and r >= 0 */
  775|     36|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|     72|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (775:6): [True: 32, False: 4]
  |  Branch (775:47): [True: 28, False: 4]
  ------------------
  776|     28|		memmove(out + modlen - r, out, r);
  777|     28|		memset(out, 0, modlen - r);
  778|     28|		r = (int)modlen;
  779|     28|	}
  780|       |
  781|    181|err:
  782|    181|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1580|    181|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    181|	sc_mem_clear(ptr, len); \
  |  | 1582|    181|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    181|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 181]
  |  |  ------------------
  ------------------
  783|       |
  784|    181|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    181|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    181|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    181|	int _ret = r; \
  |  |  |  |  155|    181|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 145, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  156|    145|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    145|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 145, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    145|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    145|	} else { \
  |  |  |  |  159|     36|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     36|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     36|	} \
  |  |  |  |  162|    181|	return _ret; \
  |  |  |  |  163|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    181|}
pkcs15-sec.c:format_senv:
  175|    464|{
  176|    464|	sc_context_t *ctx = p15card->card->ctx;
  177|    464|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|    464|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|    464|	memset(senv_out, 0, sizeof(*senv_out));
  181|       |
  182|       |	/* Card driver should have the access to supported algorithms from 'tokenInfo'. So that
  183|       |	 * it can get value of card specific 'AlgorithmInfo::algRef'. */
  184|    464|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|    464|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|    464|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  418|    928|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (186:8): [True: 464, False: 0]
  |  Branch (186:75): [True: 0, False: 0]
  ------------------
  187|    464|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This is not a private or secret key");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* If the key is not native, we can't operate with it. */
  190|    464|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 464]
  ------------------
  191|    464|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "This key is not native, cannot operate with it");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|       |
  193|    464|	switch (obj->type) {
  194|    413|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    413|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 413, False: 51]
  ------------------
  195|    413|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|    413|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 10, False: 403]
  ------------------
  197|     10|				sc_log(ctx, "Card does not support RSA with key length %zu",
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  198|     10|						prkey->modulus_length);
  199|     10|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|     10|			}
  201|    403|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|    403|#define SC_ALGORITHM_RSA		0
  ------------------
  202|    403|			senv_out->key_size_bits = prkey->modulus_length;
  203|    403|			break;
  204|       |
  205|      1|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      1|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (205:3): [True: 1, False: 463]
  ------------------
  206|      1|			*alg_info_out = sc_card_find_gostr3410_alg(p15card->card, prkey->modulus_length);
  207|      1|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (207:8): [True: 1, False: 0]
  ------------------
  208|      1|				sc_log(ctx, "Card does not support GOSTR3410 with key length %zu",
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  209|      1|						prkey->modulus_length);
  210|      1|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|      1|			}
  212|      0|			senv_out->algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  213|      0|			senv_out->key_size_bits = prkey->modulus_length;
  214|      0|			break;
  215|       |
  216|      3|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      3|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (216:3): [True: 3, False: 461]
  ------------------
  217|      3|			*alg_info_out = sc_card_find_eddsa_alg(p15card->card, prkey->field_length, NULL);
  218|      3|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (218:8): [True: 3, False: 0]
  ------------------
  219|      3|				sc_log(ctx, "Card does not support EDDSA with field_size %zu",
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  220|      3|						prkey->field_length);
  221|      3|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      3|			}
  223|      0|			senv_out->algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  224|      0|			senv_out->key_size_bits = prkey->field_length;
  225|      0|			break;
  226|       |
  227|      1|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|      1|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (227:3): [True: 1, False: 463]
  ------------------
  228|      1|			*alg_info_out = sc_card_find_xeddsa_alg(p15card->card, prkey->field_length, NULL);
  229|      1|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (229:8): [True: 1, False: 0]
  ------------------
  230|      1|				sc_log(ctx, "Card does not support XEDDSA with field_size %zu",
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|      1|						prkey->field_length);
  232|      1|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|      1|			}
  234|      0|			senv_out->algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  235|      0|			senv_out->key_size_bits = prkey->field_length;
  236|      0|			break;
  237|       |
  238|     46|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     46|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (238:3): [True: 46, False: 418]
  ------------------
  239|     46|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  240|     46|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (240:8): [True: 6, False: 40]
  ------------------
  241|      6|				sc_log(ctx, "Card does not support EC with field_size %zu",
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  242|      6|						prkey->field_length);
  243|      6|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|      6|			}
  245|     40|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|     40|#define SC_ALGORITHM_EC		2
  ------------------
  246|     40|			senv_out->key_size_bits = prkey->field_length;
  247|       |
  248|     40|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|     40|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  249|     40|			senv_out->algorithm_ref = prkey->field_length;
  250|     40|			break;
  251|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (251:3): [True: 0, False: 464]
  ------------------
  252|      0|			if (skey->key_type != CKK_AES)
  ------------------
  |  |  485|      0|#define CKK_AES 0x0000001FUL
  ------------------
  |  Branch (252:8): [True: 0, False: 0]
  ------------------
  253|      0|				LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|      0|			*alg_info_out = sc_card_find_alg(p15card->card, SC_ALGORITHM_AES,
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  255|      0|					skey->value_len, NULL);
  256|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (256:8): [True: 0, False: 0]
  ------------------
  257|      0|				sc_log(ctx, "Card does not support AES with key length %zu", skey->value_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|      0|			}
  260|      0|			senv_out->algorithm = SC_ALGORITHM_AES;
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  261|      0|			senv_out->key_size_bits = skey->value_len;
  262|      0|			break;
  263|       |			/* add other crypto types here */
  264|      0|		default:
  ------------------
  |  Branch (264:3): [True: 0, False: 464]
  ------------------
  265|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|    464|	}
  267|    443|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|    443|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  268|       |
  269|       |	/* optional keyReference attribute (the default value is -1) */
  270|    443|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (270:6): [True: 440, False: 3]
  ------------------
  271|    440|		senv_out->key_ref_len = 1;
  272|    440|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  273|    440|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|    440|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  274|    440|	}
  275|       |
  276|    443|	return SC_SUCCESS;
  ------------------
  |  |   28|    443|#define SC_SUCCESS				0
  ------------------
  277|    464|}
pkcs15-sec.c:use_key:
  133|    427|{
  134|    427|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    427|#define SC_SUCCESS				0
  ------------------
  135|    427|	int revalidated_cached_pin = 0;
  136|    427|	sc_path_t path;
  137|    427|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  174|    427|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    427|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    427|	int _ret = (r); \
  |  |  |  |  168|    427|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 427]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    427|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 427]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|    427|	r = sc_lock(p15card->card);
  140|    427|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    427|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    427|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    427|	int _ret = (r); \
  |  |  |  |  168|    427|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 427]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    427|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 427]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|    450|	do {
  143|    450|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 21, False: 429]
  |  Branch (143:24): [True: 60, False: 369]
  ------------------
  144|     81|			r = select_key_file(p15card, obj, senv);
  145|     81|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 8, False: 73]
  ------------------
  146|      8|				sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|      8|						"Unable to select private key file");
  148|      8|			}
  149|     81|		}
  150|    450|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    450|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 442, False: 8]
  ------------------
  151|    442|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|    450|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    450|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 397, False: 53]
  ------------------
  154|    397|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|    450|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 23, False: 427]
  ------------------
  157|       |			/* only re-validate once */
  158|     23|			break;
  159|    427|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|    427|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 45, False: 382]
  ------------------
  160|     45|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|     45|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 22, False: 23]
  ------------------
  162|     22|				break;
  163|     23|			revalidated_cached_pin = 1;
  164|     23|		}
  165|    427|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 23, False: 382]
  ------------------
  166|       |
  167|    427|	sc_unlock(p15card->card);
  168|       |
  169|    427|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    427|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    427|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    427|	int _ret = r; \
  |  |  |  |  155|    427|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 307, False: 120]
  |  |  |  |  ------------------
  |  |  |  |  156|    307|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    277|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 277, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  157|    307|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    307|	} else { \
  |  |  |  |  159|    120|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    120|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    120|	} \
  |  |  |  |  162|    427|	return _ret; \
  |  |  |  |  163|    427|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|    427|}
pkcs15-sec.c:get_file_path:
   57|    508|{
   58|    508|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 508]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|    508|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|    508|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|    508|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|    508|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|    508|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 508, False: 0]
  ------------------
   65|    508|		*path = prkey->path;
   66|    508|	}
   67|      0|	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (67:11): [True: 0, False: 0]
  ------------------
   68|      0|		*path = skey->path;
   69|      0|	}
   70|      0|	else
   71|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   72|       |
   73|    508|	return SC_SUCCESS;
  ------------------
  |  |   28|    508|#define SC_SUCCESS				0
  ------------------
   74|    508|}
pkcs15-sec.c:select_key_file:
   80|     81|{
   81|     81|	sc_context_t *ctx = p15card->card->ctx;
   82|     81|	sc_path_t orig_path;
   83|     81|	sc_path_t path, file_id;
   84|     81|	int r;
   85|       |
   86|     81|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     81|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     81|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     81|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     81|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|     81|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|     81|	memset(&path, 0, sizeof(sc_path_t));
   90|     81|	memset(&file_id, 0, sizeof(sc_path_t));
   91|       |
   92|       |	/* TODO: Why file_app may be NULL -- at least 3F00 has to be present?
   93|       |	 * Check validity of the following assumption. */
   94|       |	/* For pkcs15-emulated cards, the file_app may be NULL,
   95|       |	 * in that case we always assume an absolute path */
   96|     81|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 60, False: 21]
  |  Branch (96:24): [True: 60, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|     60|		path = orig_path;
   99|     60|	}
  100|     21|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 21]
  |  Branch (100:33): [True: 0, False: 0]
  ------------------
  101|       |		/* Path is relative to app. DF */
  102|      0|		path = p15card->file_app->path;
  103|      0|		file_id = orig_path;
  104|      0|		sc_append_path(&path, &file_id);
  105|      0|		senv->file_ref = file_id;
  106|      0|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|      0|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  107|      0|	}
  108|     21|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 21, False: 0]
  ------------------
  109|     21|		path = orig_path;
  110|     21|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|     21|		file_id.len = 2;
  112|     21|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     21|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|     21|		senv->file_ref = file_id;
  114|     21|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|     21|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|     21|	}
  116|      0|	else {
  117|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid private key path");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  118|      0|	}
  119|       |
  120|     81|	r = sc_select_file(p15card->card, &path, NULL);
  121|     81|	LOG_TEST_RET(ctx, r, "sc_select_file() failed");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 73]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     73|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     73|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     73|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     73|	int _ret = r; \
  |  |  |  |  155|     73|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 73, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     73|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  157|     73|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     73|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     73|	return _ret; \
  |  |  |  |  163|     73|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|     73|}

sc_pkcs15emu_skeid_init_ex:
  181|  7.46k|{
  182|  7.46k|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.46k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  183|       |
  184|  7.46k|	if (p15card->card->type == SC_CARD_TYPE_SKEID_V3
  ------------------
  |  Branch (184:6): [True: 6, False: 7.46k]
  ------------------
  185|      6|		&& (aid == NULL || (aid->len == skeid_aid_qes.len && !memcmp(aid->value, &skeid_aid_qes.value, skeid_aid_qes.len))))
  ------------------
  |  Branch (185:7): [True: 4, False: 2]
  |  Branch (185:23): [True: 1, False: 1]
  |  Branch (185:56): [True: 0, False: 1]
  ------------------
  186|      4|		r = sc_pkcs15emu_skeid_init(p15card);
  187|       |
  188|  7.46k|	return r;
  189|  7.46k|}
pkcs15-skeid.c:sc_pkcs15emu_skeid_init:
   39|      4|{
   40|      4|	int r;
   41|      4|	int i;
   42|      4|	size_t sn_len;
   43|      4|	char *buf;
   44|       |
   45|      4|	set_string(&p15card->tokeninfo->label, "eID karta");
   46|      4|	set_string(&p15card->tokeninfo->manufacturer_id, "Atos Information Technology GmbH");
   47|       |
   48|      4|	sn_len = p15card->card->serialnr.len;
   49|      4|	if (sn_len > 0) {
  ------------------
  |  Branch (49:6): [True: 4, False: 0]
  ------------------
   50|      4|		buf = malloc(2 * sn_len + 1);
   51|      4|		if (!buf) return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  |  Branch (51:7): [True: 0, False: 4]
  ------------------
   52|      4|		sc_bin_to_hex(p15card->card->serialnr.value, sn_len, buf,
   53|      4|			2 * sn_len + 1, 0);
   54|      4|		p15card->tokeninfo->serial_number = buf;
   55|      4|	}
   56|       |
   57|      4|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  597|      4|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
              	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      4|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
   58|       |
   59|       |	/* add certificates */
   60|      4|	const char *skeid_cert_names[3] = {
   61|      4|		"Kvalifikovany certifikat pre elektronicky podpis",
   62|      4|		"Certifikat pre elektronicky podpis",
   63|      4|		"Sifrovaci certifikat"
   64|      4|	};
   65|       |
   66|      4|	const char *skeid_cert_paths[3] = {
   67|      4|		"3f0001030201",
   68|      4|		"3f0001030202",
   69|      4|		"3f0001030203"
   70|      4|	};
   71|       |
   72|     16|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (72:14): [True: 12, False: 4]
  ------------------
   73|     12|		struct sc_pkcs15_cert_info cert_info;
   74|     12|		struct sc_pkcs15_object cert_obj;
   75|       |
   76|     12|		memset(&cert_info, 0, sizeof(cert_info));
   77|     12|		memset(&cert_obj, 0, sizeof(cert_obj));
   78|       |
   79|     12|		cert_info.id.value[0] = i + 1;
   80|     12|		cert_info.id.len = 1;
   81|       |
   82|     12|		sc_format_path(skeid_cert_paths[i], &cert_info.path);
   83|     12|		strlcpy(cert_obj.label, skeid_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|     12|#define strlcpy _strlcpy
  ------------------
   84|       |
   85|     12|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
   86|       |
   87|     12|		LOG_TEST_RET(p15card->card->ctx, r, "Error adding certificate.");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|     12|	}
   89|       |
   90|       |	/* add pins */
   91|      4|	const char *skeid_pin_names[2] = {
   92|      4|		"BOK",
   93|      4|		"Podpisovy PIN"
   94|      4|	};
   95|       |
   96|      4|	const unsigned int skeid_pin_max_length[2] = {6, 10};
   97|      4|	const unsigned int skeid_pin_max_tries[2] = {5, 3};
   98|      4|	const int skeid_pin_ref[2] = {0x03, 0x87};
   99|      4|	const char *skeid_pin_paths[2] = {"3F00", "3F000101"};
  100|       |
  101|      4|	const unsigned int skeid_pin_flags[2] =	{SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   54|      4|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              	const unsigned int skeid_pin_flags[2] =	{SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   65|      4|#define SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA		0x0800
  ------------------
              	const unsigned int skeid_pin_flags[2] =	{SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   58|      4|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  102|      4|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED};
  ------------------
  |  |   54|      4|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED};
  ------------------
  |  |   55|      4|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED};
  ------------------
  |  |   65|      4|#define SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA		0x0800
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA | SC_PKCS15_PIN_FLAG_INITIALIZED};
  ------------------
  |  |   58|      4|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  103|       |
  104|     12|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (104:14): [True: 8, False: 4]
  ------------------
  105|      8|		struct sc_pkcs15_auth_info pin_info;
  106|      8|		struct sc_pkcs15_object pin_obj;
  107|       |
  108|      8|		memset(&pin_info, 0, sizeof(pin_info));
  109|      8|		memset(&pin_obj, 0, sizeof(pin_obj));
  110|       |
  111|      8|		pin_info.auth_id.len = 1;
  112|      8|		pin_info.auth_id.value[0] = i + 1;
  113|      8|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      8|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  114|      8|		pin_info.attrs.pin.reference = skeid_pin_ref[i];
  115|      8|		pin_info.attrs.pin.flags = skeid_pin_flags[i];
  116|      8|		pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|      8|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  117|      8|		pin_info.attrs.pin.min_length = 6;
  118|      8|		pin_info.attrs.pin.max_length = skeid_pin_max_length[i];
  119|      8|		pin_info.max_tries = skeid_pin_max_tries[i];
  120|       |
  121|      8|		strlcpy(pin_obj.label, skeid_pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|      8|#define strlcpy _strlcpy
  ------------------
  122|      8|		pin_obj.flags = skeid_pin_flags[i];
  123|       |
  124|      8|		sc_format_path(skeid_pin_paths[i], &pin_info.path);
  125|       |
  126|      8|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  127|       |
  128|      8|		LOG_TEST_RET(p15card->card->ctx, r, "Error adding PIN.");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  129|      8|	}
  130|       |
  131|       |	/* add private keys */
  132|      4|	const u8 skeid_prkey_pin[3] = {2, 1, 1};
  133|       |
  134|       |	/* store seIdentifier rather than keyReference */
  135|      4|	const int skeid_prkey_ref[3] = {0x01, 0x34, 0x44};
  136|      4|	const int skeid_prkey_usage[3] =
  137|      4|		{ SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  314|      4|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
              		{ SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|      4|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  138|      4|		  SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|      4|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  139|      4|		  SC_PKCS15_PRKEY_USAGE_DECRYPT
  ------------------
  |  |  306|      4|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  140|      4|		};
  141|       |
  142|      4|	const char *skeid_prkey_paths[3] = {"3F000101", "3F000102", "3F000102"};
  143|       |
  144|      4|	const char *skeid_prkey_name[3] = {
  145|      4|		"Podpisovy kluc (KEP)",
  146|      4|		"Podpisovy kluc",
  147|      4|		"Sifrovaci kluc",
  148|      4|	};
  149|       |
  150|     16|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (150:14): [True: 12, False: 4]
  ------------------
  151|     12|		struct sc_pkcs15_prkey_info prkey_info;
  152|     12|		struct sc_pkcs15_object prkey_obj;
  153|       |
  154|     12|		memset(&prkey_info, 0, sizeof(prkey_info));
  155|     12|		memset(&prkey_obj, 0, sizeof(prkey_obj));
  156|       |
  157|     12|		prkey_info.id.len = 1;
  158|     12|		prkey_info.id.value[0] = i + 1;
  159|     12|		prkey_info.native = 1;
  160|     12|		prkey_info.key_reference = skeid_prkey_ref[i];
  161|     12|		prkey_info.modulus_length = 3072;
  162|     12|		sc_format_path(skeid_prkey_paths[i], &prkey_info.path);
  163|       |
  164|     12|		prkey_info.usage = skeid_prkey_usage[i];
  165|       |
  166|     12|		strlcpy(prkey_obj.label, skeid_prkey_name[i], sizeof(prkey_obj.label));
  ------------------
  |  |   43|     12|#define strlcpy _strlcpy
  ------------------
  167|     12|		prkey_obj.auth_id.len = 1;
  168|     12|		prkey_obj.auth_id.value[0] = skeid_prkey_pin[i];
  169|     12|		if (i == 0) prkey_obj.user_consent = 1;
  ------------------
  |  Branch (169:7): [True: 4, False: 8]
  ------------------
  170|       |
  171|     12|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     12|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  172|       |
  173|     12|		r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  174|       |
  175|     12|		LOG_TEST_RET(p15card->card->ctx, r, "Error adding private key.");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|     12|	}
  177|      4|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|      4|}

sc_pkcs15emu_srbeid_init_ex:
  572|  7.45k|{
  573|  7.45k|	(void)aid;
  574|       |
  575|  7.45k|	if (p15card->card->type != SC_CARD_TYPE_SRBEID_BASE)
  ------------------
  |  Branch (575:6): [True: 7.45k, False: 0]
  ------------------
  576|  7.45k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  577|       |
  578|      0|	return sc_pkcs15emu_srbeid_init(p15card);
  579|  7.45k|}

sc_pkcs15emu_starcert_init_ex:
  274|  11.6k|{
  275|  11.6k|	if (starcert_detect_card(p15card))
  ------------------
  |  Branch (275:6): [True: 11.5k, False: 52]
  ------------------
  276|  11.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  277|     52|	return sc_pkcs15emu_starcert_init(p15card);
  278|  11.6k|}
pkcs15-starcert.c:starcert_detect_card:
  101|  11.6k|{
  102|  11.6k|	int       r;
  103|  11.6k|	u8        buf[128];
  104|  11.6k|	sc_path_t path;
  105|  11.6k|	sc_card_t *card = p15card->card;
  106|       |
  107|       |	/* check if we have the correct card OS */
  108|  11.6k|	if (strcmp(card->name, "STARCOS"))
  ------------------
  |  Branch (108:6): [True: 11.4k, False: 204]
  ------------------
  109|  11.4k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.4k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  110|       |	/* read EF_Info file */
  111|    204|	sc_format_path("3F00FE13", &path);
  112|    204|	r = sc_select_file(card, &path, NULL);
  113|    204|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    204|#define SC_SUCCESS				0
  ------------------
  |  Branch (113:6): [True: 134, False: 70]
  ------------------
  114|    134|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    134|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  115|     70|	r = sc_read_binary(card, 0, buf, 64, 0);
  116|     70|	if (r != 64)
  ------------------
  |  Branch (116:6): [True: 9, False: 61]
  ------------------
  117|      9|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      9|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  118|     61|	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|     61|#define STARCERT	"StarCertV2201"
  ------------------
              	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|     61|#define STARCERT	"StarCertV2201"
  ------------------
  |  Branch (118:6): [True: 9, False: 52]
  ------------------
  119|      9|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      9|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  120|       |
  121|     52|	return SC_SUCCESS;
  ------------------
  |  |   28|     52|#define SC_SUCCESS				0
  ------------------
  122|     61|}
pkcs15-starcert.c:sc_pkcs15emu_starcert_init:
  125|     52|{
  126|     52|	const cdata certs[] = {
  127|     52|		{"DS certificate", 0, "3F00DF01C000","1",
  128|     52|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     52|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  129|     52|		{"CA certificate", 1, "3F00DF01C008","2",
  130|     52|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     52|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  131|     52|		{"KE certificate", 0, "3F00DF01C200","3",
  132|     52|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     52|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  133|     52|		{"AUT certificate",0, "3F00DF01C500","4",
  134|     52|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     52|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  135|     52|		{NULL, 0, NULL, NULL, 0}
  136|     52|	};
  137|       |
  138|     52|	const pindata pins[] = {
  139|     52|		{ "99", "DS pin", "3F00DF01", 0x99,
  140|     52|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|     52|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  141|     52|		  8, 8, 8, SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|     52|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  142|     52|		  SC_PKCS15_PIN_FLAG_LOCAL, -1, 0x00,
  ------------------
  |  |   55|     52|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  143|     52|		  SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   51|     52|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		  SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|     52|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  144|     52|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  145|     52|	};
  146|       |
  147|     52|	const prdata prkeys[] = {
  148|     52|		{ "01", "DS key", 1024, USAGE_NONREP, "3F00DF01",
  ------------------
  |  |   71|     52|#define USAGE_NONREP	SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  |  |  ------------------
  |  |  |  |  314|     52|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  149|     52|		  0x84, "99", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     52|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  150|     52|		{ "03", "KE key", 1024, USAGE_KE, "3F00DF01",
  ------------------
  |  |   72|     52|#define USAGE_KE	SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     52|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   73|     52|			SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     52|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   74|     52|			SC_PKCS15_PRKEY_USAGE_WRAP    | \
  |  |  ------------------
  |  |  |  |  309|     52|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   75|     52|			SC_PKCS15_PRKEY_USAGE_UNWRAP
  |  |  ------------------
  |  |  |  |  310|     52|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  151|     52|		  0x85, NULL, SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     52|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  152|     52|		{ "04", "AUT key", 1024, USAGE_AUT, "3F00DF01",
  ------------------
  |  |   76|     52|#define USAGE_AUT	SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     52|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   77|     52|			SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     52|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   78|     52|			SC_PKCS15_PRKEY_USAGE_WRAP    | \
  |  |  ------------------
  |  |  |  |  309|     52|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   79|     52|			SC_PKCS15_PRKEY_USAGE_UNWRAP  | \
  |  |  ------------------
  |  |  |  |  310|     52|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  |  |   80|     52|			SC_PKCS15_PRKEY_USAGE_SIGN
  |  |  ------------------
  |  |  |  |  307|     52|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  ------------------
  153|     52|		  0x82, NULL, SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     52|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  154|     52|		{ NULL, NULL, 0, 0, NULL, 0, NULL, 0}
  155|     52|	};
  156|       |
  157|     52|	int    r, i;
  158|     52|	char   buf[256];
  159|     52|	sc_path_t path;
  160|     52|	sc_file_t *file = NULL;
  161|     52|	sc_card_t *card = p15card->card;
  162|     52|	sc_serial_number_t serial;
  163|       |
  164|       |	/* get serial number */
  165|     52|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  166|     52|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     52|#define SC_SUCCESS				0
  ------------------
  |  Branch (166:6): [True: 6, False: 46]
  ------------------
  167|      6|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      6|#define SC_ERROR_INTERNAL			-1400
  ------------------
  168|     46|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  169|     46|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     46|#define SC_SUCCESS				0
  ------------------
  |  Branch (169:6): [True: 0, False: 46]
  ------------------
  170|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  171|       |
  172|     46|	set_string(&p15card->tokeninfo->serial_number, buf);
  173|     46|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (173:6): [True: 0, False: 46]
  ------------------
  174|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  175|       |	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
  176|     46|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   34|     46|#define MANU_ID		"Giesecke & Devrient GmbH"
  ------------------
  177|     46|	if (!p15card->tokeninfo->manufacturer_id)
  ------------------
  |  Branch (177:6): [True: 0, False: 46]
  ------------------
  178|      0|		goto err;
  179|       |
  180|       |	/* set certs */
  181|    230|	for (i = 0; certs[i].label; i++) {
  ------------------
  |  Branch (181:14): [True: 184, False: 46]
  ------------------
  182|    184|		struct sc_pkcs15_cert_info cert_info;
  183|    184|		struct sc_pkcs15_object    cert_obj;
  184|       |
  185|    184|		memset(&cert_info, 0, sizeof(cert_info));
  186|    184|		memset(&cert_obj,  0, sizeof(cert_obj));
  187|       |
  188|    184|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  189|    184|		cert_info.authority = certs[i].authority;
  190|    184|		sc_format_path(certs[i].path, &cert_info.path);
  191|    184|		if (!get_cert_len(card, &cert_info.path))
  ------------------
  |  Branch (191:7): [True: 183, False: 1]
  ------------------
  192|       |			/* skip errors */
  193|    183|			continue;
  194|       |
  195|      1|		strlcpy(cert_obj.label, certs[i].label, sizeof(cert_obj.label));
  ------------------
  |  |   43|      1|#define strlcpy _strlcpy
  ------------------
  196|      1|		cert_obj.flags = certs[i].obj_flags;
  197|       |
  198|      1|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  199|      1|		if (r < 0)
  ------------------
  |  Branch (199:7): [True: 0, False: 1]
  ------------------
  200|      0|			goto err;
  201|      1|	}
  202|       |	/* set pins */
  203|     92|	for (i = 0; pins[i].label; i++) {
  ------------------
  |  Branch (203:14): [True: 46, False: 46]
  ------------------
  204|     46|		struct sc_pkcs15_auth_info pin_info;
  205|     46|		struct sc_pkcs15_object   pin_obj;
  206|       |
  207|     46|		memset(&pin_info, 0, sizeof(pin_info));
  208|     46|		memset(&pin_obj,  0, sizeof(pin_obj));
  209|       |
  210|       |
  211|     46|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  212|     46|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     46|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  213|     46|		pin_info.attrs.pin.reference     = pins[i].ref;
  214|     46|		pin_info.attrs.pin.flags         = pins[i].flags;
  215|     46|		pin_info.attrs.pin.type          = pins[i].type;
  216|     46|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  217|     46|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  218|     46|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  219|     46|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  220|     46|		sc_format_path(pins[i].path, &pin_info.path);
  221|     46|		pin_info.tries_left    = -1;
  222|     46|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|     46|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  223|       |
  224|     46|		strlcpy(pin_obj.label, pins[i].label, sizeof(pin_obj.label));
  ------------------
  |  |   43|     46|#define strlcpy _strlcpy
  ------------------
  225|     46|		pin_obj.flags = pins[i].obj_flags;
  226|       |
  227|     46|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  228|     46|		if (r < 0)
  ------------------
  |  Branch (228:7): [True: 0, False: 46]
  ------------------
  229|      0|			goto err;
  230|     46|	}
  231|       |	/* set private keys */
  232|    184|	for (i = 0; prkeys[i].label; i++) {
  ------------------
  |  Branch (232:14): [True: 138, False: 46]
  ------------------
  233|    138|		struct sc_pkcs15_prkey_info prkey_info;
  234|    138|		struct sc_pkcs15_object     prkey_obj;
  235|       |
  236|    138|		memset(&prkey_info, 0, sizeof(prkey_info));
  237|    138|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  238|       |
  239|    138|		sc_pkcs15_format_id(prkeys[i].id, &prkey_info.id);
  240|    138|		prkey_info.usage         = prkeys[i].usage;
  241|    138|		prkey_info.native        = 1;
  242|    138|		prkey_info.key_reference = prkeys[i].ref;
  243|    138|		prkey_info.modulus_length= prkeys[i].modulus_len;
  244|    138|		sc_format_path(prkeys[i].path, &prkey_info.path);
  245|       |
  246|    138|		strlcpy(prkey_obj.label, prkeys[i].label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    138|#define strlcpy _strlcpy
  ------------------
  247|    138|		prkey_obj.flags = prkeys[i].obj_flags;
  248|    138|		if (prkeys[i].auth_id)
  ------------------
  |  Branch (248:7): [True: 46, False: 92]
  ------------------
  249|     46|			sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
  250|       |
  251|    138|		r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  252|    138|		if (r < 0)
  ------------------
  |  Branch (252:7): [True: 0, False: 138]
  ------------------
  253|      0|			goto err;
  254|    138|	}
  255|       |
  256|       |	/* select the application DF */
  257|     46|	sc_format_path("3F00DF01", &path);
  258|     46|	r = sc_select_file(card, &path, &file);
  259|     46|	if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|     92|#define SC_SUCCESS				0
  ------------------
  |  Branch (259:6): [True: 29, False: 17]
  |  Branch (259:25): [True: 0, False: 17]
  ------------------
  260|     29|		goto err;
  261|       |	/* set the application DF */
  262|     17|	sc_file_free(p15card->file_app);
  263|     17|	p15card->file_app = file;
  264|       |
  265|     17|	return SC_SUCCESS;
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  266|       |
  267|     29|err:
  268|     29|	sc_pkcs15_card_clear(p15card);
  269|     29|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     29|#define SC_ERROR_INTERNAL			-1400
  ------------------
  270|     46|}
pkcs15-starcert.c:get_cert_len:
   83|    184|{
   84|    184|	int r;
   85|    184|	u8  buf[8];
   86|       |
   87|    184|	r = sc_select_file(card, path, NULL);
   88|    184|	if (r < 0)
  ------------------
  |  Branch (88:6): [True: 133, False: 51]
  ------------------
   89|    133|		return 0;
   90|     51|	r = sc_read_binary(card, 0, buf, sizeof(buf), 0);
   91|     51|	if (r < 4)
  ------------------
  |  Branch (91:6): [True: 21, False: 30]
  ------------------
   92|     21|		return 0;
   93|     30|	if (buf[0] != 0x30 || buf[1] != 0x82)
  ------------------
  |  Branch (93:6): [True: 14, False: 16]
  |  Branch (93:24): [True: 15, False: 1]
  ------------------
   94|     29|		return 0;
   95|      1|	path->index = 0;
   96|      1|	path->count = ((buf[2] << 8) | buf[3]) + 4;
   97|      1|	return 1;
   98|     30|}

sc_pkcs15emu_starcos_esign_init_ex:
  355|  7.45k|{
  356|  7.45k|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  357|       |
  358|  7.45k|	if (!p15card || !p15card->card || !p15card->card->ctx)
  ------------------
  |  Branch (358:6): [True: 0, False: 7.45k]
  |  Branch (358:18): [True: 0, False: 7.45k]
  |  Branch (358:36): [True: 0, False: 7.45k]
  ------------------
  359|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  360|       |
  361|  7.45k|	r = starcos_esign_init(p15card, aid);
  362|  7.45k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  7.45k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.45k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.45k|	int _ret = r; \
  |  |  |  |  155|  7.45k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.45k, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.45k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.45k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.45k|	return _ret; \
  |  |  |  |  163|  7.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|  7.45k|}
pkcs15-starcos-esign.c:starcos_esign_init:
  286|  7.45k|{
  287|  7.45k|	sc_card_t *card = p15card->card;
  288|  7.45k|	sc_context_t *ctx = card->ctx;
  289|  7.45k|	const char *label = name_Card;
  290|  7.45k|	int r;
  291|  7.45k|	int apps_added = 0;
  292|       |
  293|  7.45k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  7.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.45k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.45k]
  |  |  ------------------
  ------------------
  294|       |
  295|  7.45k|	if (card->type != SC_CARD_TYPE_STARCOS_V3_4_ESIGN && card->type != SC_CARD_TYPE_STARCOS_V3_5_ESIGN) {
  ------------------
  |  Branch (295:6): [True: 7.40k, False: 52]
  |  Branch (295:55): [True: 7.39k, False: 10]
  ------------------
  296|  7.39k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.39k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  297|  7.39k|	}
  298|       |
  299|     62|	if (aid == NULL) {
  ------------------
  |  Branch (299:6): [True: 51, False: 11]
  ------------------
  300|       |		// no aid: in this case all emulated apps are added, currently only the esign_app
  301|     51|		r = starcos_add_esign_app(p15card);
  302|     51|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  |  Branch (302:7): [True: 10, False: 41]
  ------------------
  303|     10|			apps_added++;
  304|     51|	} else {
  305|       |		// aid specified: only the matching app is added
  306|     11|		if (aid->len == sizeof(aid_ESIGN) && memcmp(aid->value, aid_ESIGN, sizeof(aid_ESIGN)) == 0) {
  ------------------
  |  Branch (306:7): [True: 9, False: 2]
  |  Branch (306:40): [True: 0, False: 9]
  ------------------
  307|      0|			r = starcos_add_esign_app(p15card);
  308|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (308:8): [True: 0, False: 0]
  ------------------
  309|      0|				label = name_ESign;
  310|      0|				apps_added++;
  311|      0|			}
  312|      0|		}
  313|       |
  314|     11|		if (apps_added > 0) {
  ------------------
  |  Branch (314:7): [True: 0, False: 11]
  ------------------
  315|       |			// pkcs11 requires the file_app
  316|      0|			struct sc_path path;
  317|      0|			struct sc_file *file = NULL;
  318|      0|			sc_path_set(&path, SC_PATH_TYPE_DF_NAME, aid->value, aid->len, 0, 0);
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  319|      0|			r = sc_select_file(card, &path, &file);
  320|      0|			if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (320:8): [True: 0, False: 0]
  |  Branch (320:27): [True: 0, False: 0]
  ------------------
  321|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  322|      0|			sc_file_free(p15card->file_app);
  323|      0|			p15card->file_app = file;
  324|      0|		}
  325|     11|	}
  326|       |
  327|     62|	if (apps_added == 0) {
  ------------------
  |  Branch (327:6): [True: 52, False: 10]
  ------------------
  328|     52|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_CARD, "No supported app found on this card");
  ------------------
  |  |  174|     52|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     52|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     52|	int _ret = (r); \
  |  |  |  |  168|     52|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 52, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     52|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     52|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     52|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     52|		return _ret; \
  |  |  |  |  172|     52|	} \
  |  |  |  |  173|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  329|     52|	}
  330|       |
  331|     10|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  332|       |
  333|     10|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  334|     10|	if (!p15card->tokeninfo) {
  ------------------
  |  Branch (334:6): [True: 0, False: 10]
  ------------------
  335|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "unable to create tokeninfo struct");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|     10|	} else {
  337|     10|		sc_serial_number_t serial;
  338|     10|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  339|     10|		r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  340|     10|		LOG_TEST_RET(ctx, r, "Failed to query card serial number");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|      1|		r = sc_bin_to_hex(serial.value, serial.len, serial_hex, sizeof serial_hex, 0);
  343|      1|		LOG_TEST_RET(ctx, r, "Failed to convert S/N to hex");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  344|      1|		p15card->tokeninfo->serial_number = strdup(serial_hex);
  345|      1|		p15card->tokeninfo->label = strdup(label);
  346|      1|		p15card->tokeninfo->manufacturer_id = strdup(name_Vendor);
  347|      1|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      1|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  348|      1|	}
  349|       |
  350|      1|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      1|}
pkcs15-starcos-esign.c:starcos_add_esign_app:
  253|     51|{
  254|     51|	static cdata auth_cert = {"C.CH.AUT", 0, "3F00060843F1", "1", 0};
  255|     51|	static cdata encr_cert = {"C.CH.ENC", 0, "3F0006084301", "2", 0};
  256|       |#ifdef ENABLE_ESIGN_ISSUER_CONTAINERS
  257|       |	const cdata auth_root_cert = { "C.RootCA_Auth", 1, "3F00060843F0", "3", 0 };
  258|       |	const cdata encr_root_cert = { "C.RootCA_Enc", 1, "3F0006084300", "4", 0 };
  259|       |#endif
  260|       |
  261|     51|	static prdata auth_key = {"1", "PrK.CH.AUT", 2048, USAGE_AUT, "3F000608", 0x81, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   89|     51|#define USAGE_AUT SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     51|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   90|     51|				  SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     51|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   91|     51|				  SC_PKCS15_PRKEY_USAGE_WRAP | \
  |  |  ------------------
  |  |  |  |  309|     51|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   92|     51|				  SC_PKCS15_PRKEY_USAGE_UNWRAP | \
  |  |  ------------------
  |  |  |  |  310|     51|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  |  |   93|     51|				  SC_PKCS15_PRKEY_USAGE_SIGN
  |  |  ------------------
  |  |  |  |  307|     51|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  ------------------
              	static prdata auth_key = {"1", "PrK.CH.AUT", 2048, USAGE_AUT, "3F000608", 0x81, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     51|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  262|     51|	static prdata encr_key = {"2", "PrK.CH.ENC", 2048, USAGE_KE, "3F000608", 0x83, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   85|     51|#define USAGE_KE     SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     51|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   86|     51|				 SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     51|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   87|     51|				 SC_PKCS15_PRKEY_USAGE_WRAP | \
  |  |  ------------------
  |  |  |  |  309|     51|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   88|     51|				 SC_PKCS15_PRKEY_USAGE_UNWRAP
  |  |  ------------------
  |  |  |  |  310|     51|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
              	static prdata encr_key = {"2", "PrK.CH.ENC", 2048, USAGE_KE, "3F000608", 0x83, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     51|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  263|       |
  264|     51|	static pindata auth_pin = {"1", "UserPIN", "3F00", 0x01, SC_PKCS15_PIN_TYPE_UTF8, 16, 6, 0,
  ------------------
  |  |   90|     51|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  265|     51|			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   94|     51|#define USER_PIN  SC_PKCS15_PIN_FLAG_INITIALIZED | \
  |  |  ------------------
  |  |  |  |   58|     51|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   95|     51|				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | \
  |  |  ------------------
  |  |  |  |   54|     51|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  |  |  ------------------
  |  |   96|     51|				SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | \
  |  |  ------------------
  |  |  |  |   75|     51|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|     51|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   97|     51|				SC_PKCS15_PIN_AUTH_TYPE_PIN
  |  |  ------------------
  |  |  |  |   94|     51|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  |  |  ------------------
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   51|     51|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     51|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  266|       |
  267|     51|	static pindata auth_pin_v35 = {"1", "UserPIN", "3F00", 0x06, SC_PKCS15_PIN_TYPE_UTF8, 16, 6, 0,
  ------------------
  |  |   90|     51|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  268|     51|			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   94|     51|#define USER_PIN  SC_PKCS15_PIN_FLAG_INITIALIZED | \
  |  |  ------------------
  |  |  |  |   58|     51|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   95|     51|				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | \
  |  |  ------------------
  |  |  |  |   54|     51|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  |  |  ------------------
  |  |   96|     51|				SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | \
  |  |  ------------------
  |  |  |  |   75|     51|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|     51|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   97|     51|				SC_PKCS15_PIN_AUTH_TYPE_PIN
  |  |  ------------------
  |  |  |  |   94|     51|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  |  |  ------------------
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   51|     51|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     51|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  269|       |
  270|     51|	ppindata auth = (p15card->card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN) ? &auth_pin_v35 : &auth_pin;
  ------------------
  |  Branch (270:18): [True: 9, False: 42]
  ------------------
  271|       |
  272|     51|	const container containers[] = {
  273|     51|			{"1", &auth_cert, auth, &auth_key},
  274|     51|			{"2", &encr_cert, auth, &encr_key},
  275|       |#ifdef ENABLE_ESIGN_ISSUER_CONTAINERS
  276|       |			{ "3", &auth_root_cert, 0, 0 },
  277|       |			{ "4", &encr_root_cert, 0, 0 },
  278|       |#endif
  279|     51|	};
  280|       |
  281|     51|	return add_app(p15card, containers, sizeof(containers) / sizeof(container));
  282|     51|}
pkcs15-starcos-esign.c:add_app:
  116|     51|{
  117|     51|	int i, containers_added = 0, r = SC_SUCCESS;
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  118|     51|	ppindata installed_pins[4];
  119|     51|	size_t installed_pin_count = 0;
  120|     51|	sc_card_t *card = p15card->card;
  121|       |
  122|     51|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     51|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     51|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     51|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     51|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 51]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|       |
  124|    153|	for (i = 0; i < container_count; i++) {
  ------------------
  |  Branch (124:14): [True: 102, False: 51]
  ------------------
  125|    102|		struct sc_pkcs15_cert_info cert_info;
  126|    102|		struct sc_pkcs15_object cert_obj;
  127|    102|		size_t cert_size;
  128|       |
  129|    102|		memset(&cert_info, 0, sizeof(cert_info));
  130|    102|		memset(&cert_obj, 0, sizeof(cert_obj));
  131|       |
  132|    102|		sc_pkcs15_format_id(containers[i].id, &cert_info.id);
  133|    102|		cert_info.authority = containers[i].certdata->authority;
  134|    102|		sc_format_path(containers[i].certdata->path, &cert_info.path);
  135|       |
  136|    102|		r = get_cert_size(card, &cert_info.path, &cert_size);
  137|    102|		if ( r != SC_SUCCESS ) {
  ------------------
  |  |   28|    102|#define SC_SUCCESS				0
  ------------------
  |  Branch (137:8): [True: 91, False: 11]
  ------------------
  138|     91|			sc_log(card->ctx, "Failed to determine size of certificate %s, ignoring container", containers[i].certdata->label);
  ------------------
  |  |   71|     91|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  139|     91|			continue;
  140|     91|		}
  141|       |
  142|     11|		strlcpy(cert_obj.label, containers[i].certdata->label, sizeof(cert_obj.label));
  ------------------
  |  |   43|     11|#define strlcpy _strlcpy
  ------------------
  143|     11|		cert_obj.flags = containers[i].certdata->obj_flags;
  144|       |
  145|     11|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  146|     11|		LOG_TEST_RET(card->ctx, r, "Failed to add certificate");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|     11|		if (containers[i].pindata != 0) {
  ------------------
  |  Branch (148:7): [True: 11, False: 0]
  ------------------
  149|     11|			size_t j;
  150|     11|			int is_pin_installed = 0;
  151|       |
  152|       |			/* A pin object could be used by more than 1 container, ensure it is added only once */
  153|     11|			for (j = 0; j < installed_pin_count; j++) {
  ------------------
  |  Branch (153:16): [True: 1, False: 10]
  ------------------
  154|      1|				if (installed_pins[j] == containers[i].pindata) {
  ------------------
  |  Branch (154:9): [True: 1, False: 0]
  ------------------
  155|      1|					is_pin_installed = 1;
  156|      1|					break;
  157|      1|				}
  158|      1|			}
  159|       |
  160|     11|			if (!is_pin_installed) {
  ------------------
  |  Branch (160:8): [True: 10, False: 1]
  ------------------
  161|     10|				struct sc_pkcs15_auth_info pin_info;
  162|     10|				struct sc_pkcs15_object pin_obj;
  163|       |
  164|     10|				if (installed_pin_count < (int)(sizeof(installed_pins) / sizeof(ppindata))) {
  ------------------
  |  Branch (164:9): [True: 10, False: 0]
  ------------------
  165|     10|					installed_pins[installed_pin_count++] = containers[i].pindata;
  166|     10|				} else {
  167|      0|					sc_log(card->ctx, "Warning: cannot add more than 4 pins");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  168|      0|					continue;
  169|      0|				}
  170|       |
  171|     10|				memset(&pin_info, 0, sizeof(pin_info));
  172|     10|				memset(&pin_obj, 0, sizeof(pin_obj));
  173|       |
  174|     10|				sc_pkcs15_format_id(containers[i].pindata->id, &pin_info.auth_id);
  175|     10|				pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     10|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  176|     10|				pin_info.attrs.pin.reference = containers[i].pindata->ref;
  177|     10|				pin_info.attrs.pin.flags = containers[i].pindata->flags;
  178|     10|				pin_info.attrs.pin.type = containers[i].pindata->type;
  179|     10|				pin_info.attrs.pin.min_length = containers[i].pindata->minlen;
  180|     10|				pin_info.attrs.pin.stored_length = containers[i].pindata->storedlen;
  181|     10|				pin_info.attrs.pin.max_length = containers[i].pindata->maxlen;
  182|     10|				pin_info.attrs.pin.pad_char = containers[i].pindata->pad_char;
  183|     10|				if (containers[i].pindata->path != NULL)
  ------------------
  |  Branch (183:9): [True: 10, False: 0]
  ------------------
  184|     10|					sc_format_path(containers[i].pindata->path, &pin_info.path);
  185|     10|				pin_info.tries_left = -1;
  186|     10|				pin_info.max_tries = containers[i].pindata->max_tries;
  187|       |
  188|     10|				strlcpy(pin_obj.label, containers[i].pindata->label, sizeof(pin_obj.label));
  ------------------
  |  |   43|     10|#define strlcpy _strlcpy
  ------------------
  189|     10|				pin_obj.flags = containers[i].pindata->obj_flags;
  190|       |
  191|     10|				r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  192|     10|				LOG_TEST_RET(card->ctx, r, "Failed to add PIN object");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     10|			}
  194|     11|		}
  195|       |
  196|     11|		if (containers[i].prdata != 0) {
  ------------------
  |  Branch (196:7): [True: 11, False: 0]
  ------------------
  197|     11|			struct sc_pkcs15_prkey_info prkey_info;
  198|     11|			struct sc_pkcs15_object prkey_obj;
  199|     11|			int modulus_len = containers[i].prdata->modulus_len;
  200|     11|			memset(&prkey_info, 0, sizeof(prkey_info));
  201|     11|			memset(&prkey_obj, 0, sizeof(prkey_obj));
  202|       |
  203|     11|			sc_pkcs15_format_id(containers[i].id, &prkey_info.id);
  204|     11|			prkey_info.usage = containers[i].prdata->usage;
  205|     11|			prkey_info.native = 1;
  206|     11|			prkey_info.key_reference = containers[i].prdata->ref;
  207|     11|			prkey_info.modulus_length = modulus_len;
  208|     11|			sc_format_path(containers[i].prdata->path, &prkey_info.path);
  209|       |
  210|     11|			strlcpy(prkey_obj.label, containers[i].prdata->label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|     11|#define strlcpy _strlcpy
  ------------------
  211|     11|			prkey_obj.flags = containers[i].prdata->obj_flags;
  212|     11|			if (containers[i].prdata->auth_id) {
  ------------------
  |  Branch (212:8): [True: 11, False: 0]
  ------------------
  213|     11|				sc_pkcs15_format_id(containers[i].prdata->auth_id, &prkey_obj.auth_id);
  214|     11|			}
  215|       |
  216|     11|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  217|     11|			LOG_TEST_RET(card->ctx, r, "Failed to add RSA prkey");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  218|     11|		}
  219|       |
  220|     11|		containers_added++;
  221|     11|	}
  222|       |
  223|     51|	if (containers_added == 0) {
  ------------------
  |  Branch (223:6): [True: 41, False: 10]
  ------------------
  224|     41|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     41|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  225|     41|	} else {
  226|     10|		r = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  227|     10|	}
  228|       |
  229|     51|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 41, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  230|     51|}
pkcs15-starcos-esign.c:get_cert_size:
  101|    102|{
  102|    102|	int r;
  103|    102|	sc_file_t *file = NULL;
  104|       |
  105|    102|	r = sc_select_file(card, path, &file);
  106|    102|	LOG_TEST_RET(card->ctx, r, "Failed to select EF certificate");
  ------------------
  |  |  174|    102|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    102|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    102|	int _ret = (r); \
  |  |  |  |  168|    102|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 91, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     91|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     91|		return _ret; \
  |  |  |  |  172|     91|	} \
  |  |  |  |  173|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|     11|	*psize = file->size;
  109|     11|	sc_file_free(file);
  110|       |
  111|     11|	return SC_SUCCESS;
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  112|    102|}

sc_pkcs15_is_emulation_only:
   90|  11.9k|{
   91|  11.9k|	switch (card->type) {
   92|    500|		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
  ------------------
  |  Branch (92:3): [True: 500, False: 11.4k]
  ------------------
   93|    502|		case SC_CARD_TYPE_OPENPGP_V1:
  ------------------
  |  Branch (93:3): [True: 2, False: 11.9k]
  ------------------
   94|    504|		case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (94:3): [True: 2, False: 11.9k]
  ------------------
   95|    534|		case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (95:3): [True: 30, False: 11.8k]
  ------------------
   96|    541|		case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (96:3): [True: 7, False: 11.9k]
  ------------------
   97|    541|		case SC_CARD_TYPE_SC_HSM:
  ------------------
  |  Branch (97:3): [True: 0, False: 11.9k]
  ------------------
   98|    541|		case SC_CARD_TYPE_SC_HSM_SOC:
  ------------------
  |  Branch (98:3): [True: 0, False: 11.9k]
  ------------------
   99|    541|		case SC_CARD_TYPE_DNIE_BASE:
  ------------------
  |  Branch (99:3): [True: 0, False: 11.9k]
  ------------------
  100|    541|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (100:3): [True: 0, False: 11.9k]
  ------------------
  101|    541|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (101:3): [True: 0, False: 11.9k]
  ------------------
  102|  1.07k|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (102:3): [True: 530, False: 11.3k]
  ------------------
  103|  1.07k|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (103:3): [True: 0, False: 11.9k]
  ------------------
  104|  1.07k|		case SC_CARD_TYPE_IASECC_GEMALTO:
  ------------------
  |  Branch (104:3): [True: 3, False: 11.9k]
  ------------------
  105|  1.10k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (105:3): [True: 33, False: 11.8k]
  ------------------
  106|  1.10k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (106:3): [True: 0, False: 11.9k]
  ------------------
  107|  1.10k|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (107:3): [True: 0, False: 11.9k]
  ------------------
  108|  1.10k|		case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (108:3): [True: 1, False: 11.9k]
  ------------------
  109|  1.17k|		case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (109:3): [True: 65, False: 11.8k]
  ------------------
  110|  1.24k|		case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (110:3): [True: 67, False: 11.8k]
  ------------------
  111|  1.24k|		case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (111:3): [True: 0, False: 11.9k]
  ------------------
  112|  1.30k|		case SC_CARD_TYPE_ESTEID_2018:
  ------------------
  |  Branch (112:3): [True: 60, False: 11.8k]
  ------------------
  113|  1.30k|		case SC_CARD_TYPE_CARDOS_V5_0:
  ------------------
  |  Branch (113:3): [True: 3, False: 11.9k]
  ------------------
  114|  1.64k|		case SC_CARD_TYPE_CARDOS_V5_3:
  ------------------
  |  Branch (114:3): [True: 340, False: 11.5k]
  ------------------
  115|  1.64k|		case SC_CARD_TYPE_NQ_APPLET:
  ------------------
  |  Branch (115:3): [True: 0, False: 11.9k]
  ------------------
  116|  1.64k|		case SC_CARD_TYPE_NQ_APPLET_RFID:
  ------------------
  |  Branch (116:3): [True: 0, False: 11.9k]
  ------------------
  117|  1.71k|		case SC_CARD_TYPE_STARCOS_V3_4_ESIGN:
  ------------------
  |  Branch (117:3): [True: 76, False: 11.8k]
  ------------------
  118|  1.73k|		case SC_CARD_TYPE_STARCOS_V3_5_ESIGN:
  ------------------
  |  Branch (118:3): [True: 11, False: 11.9k]
  ------------------
  119|  1.73k|		case SC_CARD_TYPE_SKEID_V3:
  ------------------
  |  Branch (119:3): [True: 6, False: 11.9k]
  ------------------
  120|  1.73k|		case SC_CARD_TYPE_EOI:
  ------------------
  |  Branch (120:3): [True: 0, False: 11.9k]
  ------------------
  121|  1.73k|		case SC_CARD_TYPE_EOI_CONTACTLESS:
  ------------------
  |  Branch (121:3): [True: 0, False: 11.9k]
  ------------------
  122|  1.73k|		case SC_CARD_TYPE_CHIPDOC_IT:
  ------------------
  |  Branch (122:3): [True: 0, False: 11.9k]
  ------------------
  123|  1.73k|		case SC_CARD_TYPE_DTRUST_V4_1_STD:
  ------------------
  |  Branch (123:3): [True: 0, False: 11.9k]
  ------------------
  124|  1.73k|		case SC_CARD_TYPE_DTRUST_V4_4_STD:
  ------------------
  |  Branch (124:3): [True: 0, False: 11.9k]
  ------------------
  125|  1.73k|		case SC_CARD_TYPE_DTRUST_V4_1_MULTI:
  ------------------
  |  Branch (125:3): [True: 0, False: 11.9k]
  ------------------
  126|  1.73k|		case SC_CARD_TYPE_DTRUST_V4_1_M100:
  ------------------
  |  Branch (126:3): [True: 0, False: 11.9k]
  ------------------
  127|  1.73k|		case SC_CARD_TYPE_DTRUST_V4_4_MULTI:
  ------------------
  |  Branch (127:3): [True: 0, False: 11.9k]
  ------------------
  128|  1.73k|		case SC_CARD_TYPE_DTRUST_V5_1_STD:
  ------------------
  |  Branch (128:3): [True: 0, False: 11.9k]
  ------------------
  129|  1.73k|		case SC_CARD_TYPE_DTRUST_V5_4_STD:
  ------------------
  |  Branch (129:3): [True: 0, False: 11.9k]
  ------------------
  130|  1.73k|		case SC_CARD_TYPE_DTRUST_V5_1_MULTI:
  ------------------
  |  Branch (130:3): [True: 0, False: 11.9k]
  ------------------
  131|  1.73k|		case SC_CARD_TYPE_DTRUST_V5_1_M100:
  ------------------
  |  Branch (131:3): [True: 0, False: 11.9k]
  ------------------
  132|  1.73k|		case SC_CARD_TYPE_DTRUST_V5_4_MULTI:
  ------------------
  |  Branch (132:3): [True: 0, False: 11.9k]
  ------------------
  133|  1.73k|		case SC_CARD_TYPE_LTEID:
  ------------------
  |  Branch (133:3): [True: 0, False: 11.9k]
  ------------------
  134|  1.81k|		case SC_CARD_TYPE_CEDULAUY:
  ------------------
  |  Branch (134:3): [True: 82, False: 11.8k]
  ------------------
  135|  1.81k|			return 1;
  136|  10.1k|		default:
  ------------------
  |  Branch (136:3): [True: 10.1k, False: 1.81k]
  ------------------
  137|  10.1k|			return 0;
  138|  11.9k|	}
  139|  11.9k|}
sc_pkcs15_bind_synthetic:
  143|  11.7k|{
  144|  11.7k|	sc_context_t		*ctx = p15card->card->ctx;
  145|  11.7k|	scconf_block		*conf_block, **blocks, *blk;
  146|  11.7k|	int			i, r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.7k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  147|       |
  148|  11.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.7k]
  |  |  ------------------
  ------------------
  149|  11.7k|	conf_block = NULL;
  150|       |
  151|  11.7k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
  152|       |
  153|  11.7k|	if (!conf_block) {
  ------------------
  |  Branch (153:6): [True: 11.7k, False: 0]
  ------------------
  154|       |		/* no conf file found => try builtin drivers  */
  155|  11.7k|		sc_log(ctx, "no conf file (or section), trying all builtin emulators");
  ------------------
  |  |   71|  11.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  156|   276k|		for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (156:15): [True: 269k, False: 7.45k]
  ------------------
  157|   269k|			sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|   269k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  158|   269k|			r = builtin_emulators[i].handler(p15card, aid);
  159|   269k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|   269k|#define SC_SUCCESS				0
  ------------------
  |  Branch (159:8): [True: 4.30k, False: 264k]
  ------------------
  160|       |				/* we got a hit */
  161|  4.30k|				goto out;
  162|   269k|		}
  163|  11.7k|	} else {
  164|       |		/* we have a conf file => let's use it */
  165|      0|		int builtin_enabled;
  166|      0|		const scconf_list *list;
  167|       |
  168|      0|		builtin_enabled = scconf_get_bool(conf_block, "enable_builtin_emulation", 1);
  169|      0|		list = scconf_find_list(conf_block, "builtin_emulators"); /* FIXME: rename to enabled_emulators */
  170|       |
  171|      0|		if (builtin_enabled && list) {
  ------------------
  |  Branch (171:7): [True: 0, False: 0]
  |  Branch (171:26): [True: 0, False: 0]
  ------------------
  172|       |			/* filter enabled emulation drivers from conf file */
  173|      0|			struct _sc_pkcs15_emulators filtered_emulators;
  174|      0|			struct sc_pkcs15_emulator_handler** lst;
  175|      0|			int ret;
  176|       |
  177|      0|			filtered_emulators.ccount = 0;
  178|      0|			ret = set_emulators(ctx, &filtered_emulators, list, builtin_emulators, old_emulators);
  179|      0|			if (ret == SC_SUCCESS || ret == SC_ERROR_TOO_MANY_OBJECTS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              			if (ret == SC_SUCCESS || ret == SC_ERROR_TOO_MANY_OBJECTS) {
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
  |  Branch (179:8): [True: 0, False: 0]
  |  Branch (179:29): [True: 0, False: 0]
  ------------------
  180|      0|				lst = filtered_emulators.list_of_handlers;
  181|       |
  182|      0|				if (ret == SC_ERROR_TOO_MANY_OBJECTS)
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
  |  Branch (182:9): [True: 0, False: 0]
  ------------------
  183|      0|					sc_log(ctx, "trying first %d emulators from conf file", SC_MAX_PKCS15_EMULATORS);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  183|      0|					sc_log(ctx, "trying first %d emulators from conf file", SC_MAX_PKCS15_EMULATORS);
  |  |  |  |  ------------------
  |  |  |  |  |  |   52|      0|#define SC_MAX_PKCS15_EMULATORS	48
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|      0|				for (i = 0; lst[i]; i++) {
  ------------------
  |  Branch (185:17): [True: 0, False: 0]
  ------------------
  186|      0|					sc_log(ctx, "trying %s", lst[i]->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  187|      0|					r = lst[i]->handler(p15card, aid);
  188|      0|					if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (188:10): [True: 0, False: 0]
  ------------------
  189|       |						/* we got a hit */
  190|      0|						goto out;
  191|      0|				}
  192|      0|			} else {
  193|      0|				sc_log(ctx, "failed to filter enabled card emulators: %s", sc_strerror(ret));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  194|      0|			}
  195|      0|		}
  196|      0|		else if (builtin_enabled) {
  ------------------
  |  Branch (196:12): [True: 0, False: 0]
  ------------------
  197|      0|			sc_log(ctx, "no emulator list in config file, trying all builtin emulators");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  198|      0|			for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (198:16): [True: 0, False: 0]
  ------------------
  199|      0|				sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  200|      0|				r = builtin_emulators[i].handler(p15card, aid);
  201|      0|				if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (201:9): [True: 0, False: 0]
  ------------------
  202|       |					/* we got a hit */
  203|      0|					goto out;
  204|      0|			}
  205|      0|		}
  206|       |
  207|       |		/* search for 'emulate foo { ... }' entries in the conf file */
  208|      0|		sc_log(ctx, "searching for 'emulate foo { ... }' blocks");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  209|      0|		blocks = scconf_find_blocks(ctx->conf, conf_block, "emulate", NULL);
  210|      0|		sc_log(ctx, "Blocks: %p", blocks);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  211|      0|		for (i = 0; blocks && (blk = blocks[i]) != NULL; i++) {
  ------------------
  |  Branch (211:15): [True: 0, False: 0]
  |  Branch (211:25): [True: 0, False: 0]
  ------------------
  212|      0|			const char *name = blk->name->data;
  213|      0|			sc_log(ctx, "trying %s", name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  214|      0|			r = parse_emu_block(p15card, aid, blk);
  215|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (215:8): [True: 0, False: 0]
  ------------------
  216|      0|				free(blocks);
  217|      0|				goto out;
  218|      0|			}
  219|      0|		}
  220|      0|		if (blocks)
  ------------------
  |  Branch (220:7): [True: 0, False: 0]
  ------------------
  221|      0|			free(blocks);
  222|      0|	}
  223|       |
  224|  11.7k|out:
  225|  11.7k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  11.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:6): [True: 4.30k, False: 7.45k]
  ------------------
  226|  4.30k|		p15card->magic  = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  4.30k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  227|  4.30k|		p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
  ------------------
  |  |  601|  4.30k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  228|  7.45k|	} else {
  229|  7.45k|		if (r != SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  7.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (229:7): [True: 0, False: 7.45k]
  ------------------
  230|      0|			sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|  7.45k|	}
  232|       |
  233|  11.7k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  11.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.7k|	int _ret = r; \
  |  |  |  |  155|  11.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.45k, False: 4.30k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.7k|	return _ret; \
  |  |  |  |  163|  11.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|  11.7k|}
sc_pkcs15emu_add_pin_obj:
  370|  5.56k|{
  371|  5.56k|	sc_pkcs15_auth_info_t pin = *in_pin;
  372|       |
  373|  5.56k|	pin.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  5.56k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  374|  5.56k|	if(!pin.auth_method) /* or SC_AC_NONE */
  ------------------
  |  Branch (374:5): [True: 5.16k, False: 402]
  ------------------
  375|  5.16k|		pin.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|  5.16k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  376|       |
  377|  5.56k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_AUTH_PIN, obj, &pin);
  ------------------
  |  |  445|  5.56k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  378|  5.56k|}
sc_pkcs15emu_add_rsa_prkey:
  382|    941|{
  383|    941|	sc_pkcs15_prkey_info_t key = *in_key;
  384|       |
  385|    941|	if (key.access_flags == 0)
  ------------------
  |  Branch (385:6): [True: 941, False: 0]
  ------------------
  386|    941|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    941|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  387|    941|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    941|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  388|    941|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    941|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  389|    941|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    941|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  390|       |
  391|    941|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_RSA, obj, &key);
  ------------------
  |  |  419|    941|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  392|    941|}
sc_pkcs15emu_add_rsa_pubkey:
  396|    338|{
  397|    338|	sc_pkcs15_pubkey_info_t key = *in_key;
  398|       |
  399|    338|	if (key.access_flags == 0)
  ------------------
  |  Branch (399:6): [True: 338, False: 0]
  ------------------
  400|    338|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    338|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  401|       |
  402|    338|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_RSA, obj, &key);
  ------------------
  |  |  426|    338|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  403|    338|}
sc_pkcs15emu_add_ec_prkey:
  407|     87|{
  408|     87|	sc_pkcs15_prkey_info_t key = *in_key;
  409|       |
  410|     87|	if (key.access_flags == 0)
  ------------------
  |  Branch (410:6): [True: 87, False: 0]
  ------------------
  411|     87|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|     87|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  412|     87|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|     87|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  413|     87|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|     87|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  414|     87|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|     87|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  415|       |
  416|     87|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EC, obj, &key);
  ------------------
  |  |  421|     87|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  417|     87|}
sc_pkcs15emu_add_ec_pubkey:
  421|     90|{
  422|     90|	sc_pkcs15_pubkey_info_t key = *in_key;
  423|       |
  424|     90|	if (key.access_flags == 0)
  ------------------
  |  Branch (424:6): [True: 90, False: 0]
  ------------------
  425|     90|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|     90|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  426|       |
  427|     90|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EC, obj, &key);
  ------------------
  |  |  428|     90|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  428|     90|}
sc_pkcs15emu_add_eddsa_prkey:
  432|     15|{
  433|     15|	sc_pkcs15_prkey_info_t key = *in_key;
  434|       |
  435|     15|	if (key.access_flags == 0)
  ------------------
  |  Branch (435:6): [True: 15, False: 0]
  ------------------
  436|     15|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|     15|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  437|     15|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|     15|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  438|     15|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|     15|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  439|     15|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|     15|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  440|       |
  441|     15|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EDDSA, obj, &key);
  ------------------
  |  |  422|     15|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  442|     15|}
sc_pkcs15emu_add_eddsa_pubkey:
  446|     14|{
  447|     14|	sc_pkcs15_pubkey_info_t key = *in_key;
  448|       |
  449|     14|	if (key.access_flags == 0)
  ------------------
  |  Branch (449:6): [True: 14, False: 0]
  ------------------
  450|     14|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|     14|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  451|       |
  452|     14|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EDDSA, obj, &key);
  ------------------
  |  |  429|     14|#define SC_PKCS15_TYPE_PUBKEY_EDDSA		0x205
  ------------------
  453|     14|}
sc_pkcs15emu_add_xeddsa_prkey:
  457|     11|{
  458|     11|	sc_pkcs15_prkey_info_t key = *in_key;
  459|       |
  460|     11|	if (key.access_flags == 0)
  ------------------
  |  Branch (460:6): [True: 11, False: 0]
  ------------------
  461|     11|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|     11|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  462|     11|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|     11|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  463|     11|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|     11|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  464|     11|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|     11|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  465|       |
  466|     11|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_XEDDSA, obj, &key);
  ------------------
  |  |  423|     11|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  467|     11|}
sc_pkcs15emu_add_xeddsa_pubkey:
  471|     11|{
  472|     11|	sc_pkcs15_pubkey_info_t key = *in_key;
  473|       |
  474|     11|	if (key.access_flags == 0)
  ------------------
  |  Branch (474:6): [True: 11, False: 0]
  ------------------
  475|     11|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|     11|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  476|       |
  477|     11|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_XEDDSA, obj, &key);
  ------------------
  |  |  430|     11|#define SC_PKCS15_TYPE_PUBKEY_XEDDSA		0x206
  ------------------
  478|     11|}
sc_pkcs15emu_add_x509_cert:
  482|  1.04k|{
  483|  1.04k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_CERT_X509, obj, cert);
  ------------------
  |  |  439|  1.04k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  484|  1.04k|}
sc_pkcs15emu_add_data_object:
  488|  2.29k|{
  489|  2.29k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, obj, data);
  ------------------
  |  |  442|  2.29k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  490|  2.29k|}
sc_pkcs15emu_object_add:
  494|  28.2k|{
  495|  28.2k|	sc_pkcs15_object_t *obj;
  496|  28.2k|	unsigned int	df_type;
  497|  28.2k|	size_t		data_len;
  498|       |
  499|  28.2k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  28.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  28.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  28.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 28.2k]
  |  |  ------------------
  ------------------
  500|       |
  501|  28.2k|	obj = calloc(1, sizeof(*obj));
  502|  28.2k|	if (!obj) {
  ------------------
  |  Branch (502:6): [True: 0, False: 28.2k]
  ------------------
  503|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  504|      0|	}
  505|       |
  506|  28.2k|	memcpy(obj, in_obj, sizeof(*obj));
  507|  28.2k|	obj->type = type;
  508|       |
  509|  28.2k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  28.2k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  510|  5.56k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  5.56k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (510:2): [True: 5.56k, False: 22.6k]
  ------------------
  511|  5.56k|		df_type  = SC_PKCS15_AODF;
  ------------------
  |  |  496|  5.56k|#define SC_PKCS15_AODF			8
  ------------------
  512|  5.56k|		data_len = sizeof(struct sc_pkcs15_auth_info);
  513|  5.56k|		break;
  514|  2.01k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  2.01k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (514:2): [True: 2.01k, False: 26.2k]
  ------------------
  515|  2.01k|		df_type  = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|  2.01k|#define SC_PKCS15_PRKDF			0
  ------------------
  516|  2.01k|		data_len = sizeof(struct sc_pkcs15_prkey_info);
  517|  2.01k|		break;
  518|    454|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    454|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (518:2): [True: 454, False: 27.8k]
  ------------------
  519|    454|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|    454|#define SC_PKCS15_PUKDF			1
  ------------------
  520|    454|		data_len = sizeof(struct sc_pkcs15_pubkey_info);
  521|    454|		break;
  522|  1.12k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.12k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (522:2): [True: 1.12k, False: 27.1k]
  ------------------
  523|  1.12k|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|  1.12k|#define SC_PKCS15_CDF			4
  ------------------
  524|  1.12k|		data_len = sizeof(struct sc_pkcs15_cert_info);
  525|  1.12k|		break;
  526|  19.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  19.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (526:2): [True: 19.0k, False: 9.16k]
  ------------------
  527|  19.0k|		df_type = SC_PKCS15_DODF;
  ------------------
  |  |  495|  19.0k|#define SC_PKCS15_DODF			7
  ------------------
  528|  19.0k|		data_len = sizeof(struct sc_pkcs15_data_info);
  529|  19.0k|		break;
  530|      0|	default:
  ------------------
  |  Branch (530:2): [True: 0, False: 28.2k]
  ------------------
  531|      0|		sc_log(p15card->card->ctx, "Unknown PKCS15 object type %d", type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  532|      0|		free(obj);
  533|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|  28.2k|	}
  535|       |
  536|  28.2k|	obj->data = calloc(1, data_len);
  537|  28.2k|	if (obj->data == NULL) {
  ------------------
  |  Branch (537:6): [True: 0, False: 28.2k]
  ------------------
  538|      0|		free(obj);
  539|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|      0|	}
  541|  28.2k|	memcpy(obj->data, data, data_len);
  542|       |
  543|  28.2k|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  544|  28.2k|	sc_pkcs15_add_object(p15card, obj);
  545|       |
  546|       |	/* release memory ownership of buffers that are now contained in `p15card` */
  547|  28.2k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  28.2k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  548|  5.56k|	default:
  ------------------
  |  Branch (548:2): [True: 5.56k, False: 22.6k]
  ------------------
  549|       |		/* `data`'s members copied by value, no buffer to release */
  550|  5.56k|		break;
  551|  5.56k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  2.01k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (551:2): [True: 2.01k, False: 26.2k]
  ------------------
  552|  2.01k|		((struct sc_pkcs15_prkey_info *)data)->subject.value = NULL;
  553|  2.01k|		break;
  554|    454|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    454|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (554:2): [True: 454, False: 27.8k]
  ------------------
  555|    454|		((struct sc_pkcs15_pubkey_info *)data)->subject.value = NULL;
  556|    454|		((struct sc_pkcs15_pubkey_info *)data)->direct.raw.value = NULL;
  557|    454|		((struct sc_pkcs15_pubkey_info *)data)->direct.spki.value = NULL;
  558|    454|		break;
  559|  1.12k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.12k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (559:2): [True: 1.12k, False: 27.1k]
  ------------------
  560|  1.12k|		((struct sc_pkcs15_cert_info *)data)->value.value = NULL;
  561|  1.12k|		break;
  562|  19.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  19.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (562:2): [True: 19.0k, False: 9.16k]
  ------------------
  563|  19.0k|		((struct sc_pkcs15_data_info *)data)->data.value = NULL;
  564|  19.0k|		break;
  565|  28.2k|	}
  566|       |
  567|  28.2k|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  28.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  28.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  28.2k|	int _ret = r; \
  |  |  |  |  155|  28.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  28.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28.2k]
  |  |  |  |  ------------------
  |  |  |  |  157|  28.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  28.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  28.2k|	return _ret; \
  |  |  |  |  163|  28.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  568|  28.2k|}
pkcs15-syn.c:sc_pkcs15emu_get_df:
  341|  28.2k|{
  342|  28.2k|	sc_pkcs15_df_t	*df;
  343|  28.2k|	sc_file_t	*file;
  344|  28.2k|	int		created = 0;
  345|       |
  346|  35.7k|	while (1) {
  ------------------
  |  Branch (346:9): [True: 35.7k, Folded]
  ------------------
  347|  53.6k|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (347:31): [True: 46.0k, False: 7.52k]
  ------------------
  348|  46.0k|			if (df->type == type) {
  ------------------
  |  Branch (348:8): [True: 28.2k, False: 17.8k]
  ------------------
  349|  28.2k|				if (created)
  ------------------
  |  Branch (349:9): [True: 7.52k, False: 20.7k]
  ------------------
  350|  7.52k|					df->enumerated = 1;
  351|  28.2k|				return df;
  352|  28.2k|			}
  353|  46.0k|		}
  354|       |
  355|  7.52k|		if (created != 0)
  ------------------
  |  Branch (355:7): [True: 0, False: 7.52k]
  ------------------
  356|      0|			return NULL;
  357|       |
  358|  7.52k|		file = sc_file_new();
  359|  7.52k|		if (!file)
  ------------------
  |  Branch (359:7): [True: 0, False: 7.52k]
  ------------------
  360|      0|			return NULL;
  361|  7.52k|		sc_format_path("11001101", &file->path);
  362|  7.52k|		sc_pkcs15_add_df(p15card, type, &file->path);
  363|  7.52k|		sc_file_free(file);
  364|  7.52k|		created++;
  365|  7.52k|	}
  366|  28.2k|}

sc_pkcs15emu_tcos_init_ex:
  522|  11.5k|){
  523|  11.5k|	sc_card_t         *card = p15card->card;
  524|  11.5k|	sc_context_t      *ctx = p15card->card->ctx;
  525|  11.5k|	sc_serial_number_t serialnr;
  526|  11.5k|	char               serial[30];
  527|  11.5k|	int r;
  528|       |
  529|       |	/* check if we have the correct card OS unless SC_PKCS15EMU_FLAGS_NO_CHECK */
  530|  11.5k|	if (card->type!=SC_CARD_TYPE_TCOS_V2 && card->type!=SC_CARD_TYPE_TCOS_V3) return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.8k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (530:6): [True: 10.8k, False: 713]
  |  Branch (530:42): [True: 10.8k, False: 0]
  ------------------
  531|       |
  532|       |	/* get the card serial number */
  533|    713|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serialnr);
  534|    713|	if (r < 0) {
  ------------------
  |  Branch (534:6): [True: 480, False: 233]
  ------------------
  535|    480|		sc_log(ctx, "unable to get ICCSN");
  ------------------
  |  |   71|    480|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  536|    480|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    480|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  537|    480|	}
  538|    233|	r = sc_bin_to_hex(serialnr.value, serialnr.len, serial, sizeof(serial), 0);
  539|    233|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    233|#define SC_SUCCESS				0
  ------------------
  |  Branch (539:6): [True: 2, False: 231]
  ------------------
  540|      2|		sc_log(ctx, "serial number invalid");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  541|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  542|      2|	}
  543|       |
  544|    231|	serial[19] = '\0';
  545|    231|	set_string(&p15card->tokeninfo->serial_number, serial);
  546|       |
  547|    231|	if(!detect_netkey(p15card)) return SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  |  Branch (547:5): [True: 64, False: 167]
  ------------------
  548|    167|	if(!detect_idkey(p15card)) return SC_SUCCESS;
  ------------------
  |  |   28|     39|#define SC_SUCCESS				0
  ------------------
  |  Branch (548:5): [True: 39, False: 128]
  ------------------
  549|    128|	if(!detect_unicard(p15card)) return SC_SUCCESS;
  ------------------
  |  |   28|     29|#define SC_SUCCESS				0
  ------------------
  |  Branch (549:5): [True: 29, False: 99]
  ------------------
  550|     99|	if(!detect_signtrust(p15card)) return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (550:5): [True: 1, False: 98]
  ------------------
  551|     98|	if(!detect_datev(p15card)) return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (551:5): [True: 1, False: 97]
  ------------------
  552|       |
  553|     97|	sc_pkcs15_card_clear(p15card);
  554|     97|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     97|#define SC_ERROR_INTERNAL			-1400
  ------------------
  555|     98|}
pkcs15-tcos.c:detect_netkey:
  296|    231|){
  297|    231|	sc_card_t *card=p15card->card;
  298|    231|	sc_path_t p;
  299|    231|	sc_file_t *f;
  300|    231|	int keylen;
  301|    231|	char dir[10];
  302|    231|	const char *c_auth;
  303|       |
  304|       |	/* NKS-Applikation ? */
  305|    231|	memset(&p, 0, sizeof(sc_path_t));
  306|    231|	p.type=SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    231|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  307|    231|	memcpy(p.value, "\xD2\x76\x00\x00\x03\x01\x02", p.len=7);
  308|    231|	if (sc_select_file(card,&p,&f)!=SC_SUCCESS) return 1;
  ------------------
  |  |   28|    231|#define SC_SUCCESS				0
  ------------------
  |  Branch (308:6): [True: 167, False: 64]
  ------------------
  309|     64|	sprintf(dir,"%04X", f->id);
  310|     64|	sc_file_free(f);
  311|       |
  312|     64|	set_string(&p15card->tokeninfo->manufacturer_id, "TeleSec GmbH");
  313|     64|	set_string(&p15card->tokeninfo->label, card->type==SC_CARD_TYPE_TCOS_V3 ? "NetKey V3 Card" : "NetKey Card");
  ------------------
  |  Branch (313:41): [True: 0, False: 64]
  ------------------
  314|     64|	keylen= card->type==SC_CARD_TYPE_TCOS_V3 ? 2048 : 1024;
  ------------------
  |  Branch (314:10): [True: 0, False: 64]
  ------------------
  315|     64|	c_auth= card->type==SC_CARD_TYPE_TCOS_V3 ? "C500" : "C100";
  ------------------
  |  Branch (315:10): [True: 0, False: 64]
  ------------------
  316|       |
  317|     64|	insert_cert(p15card, dirpath(dir,"4331"), 0x45, 1, "Signatur Zertifikat 1");
  318|     64|	insert_cert(p15card, dirpath(dir,"4332"), 0x45, 1, "Signatur Zertifikat 2");
  319|     64|	insert_cert(p15card, dirpath(dir,"C000"), 0x45, 0, "Telesec Signatur Zertifikat");
  320|     64|	insert_cert(p15card, dirpath(dir,"43B1"), 0x46, 1, "Verschluesselungs Zertifikat 1");
  321|     64|	insert_cert(p15card, dirpath(dir,"43B2"), 0x46, 1, "Verschluesselungs Zertifikat 2");
  322|     64|	insert_cert(p15card, dirpath(dir,"C200"), 0x46, 0, "Telesec Verschluesselungs Zertifikat");
  323|     64|	insert_cert(p15card, dirpath(dir,"4371"), 0x47, 1, "Authentifizierungs Zertifikat 1");
  324|     64|	insert_cert(p15card, dirpath(dir,"4372"), 0x47, 1, "Authentifizierungs Zertifikat 2");
  325|     64|	insert_cert(p15card, dirpath(dir,c_auth), 0x47, 0, "Telesec Authentifizierungs Zertifikat");
  326|     64|	insert_cert(p15card, dirpath(dir,"C201"), 0x48, 0, "Telesec 1024bit Zertifikat");
  327|       |
  328|     64|	insert_key(p15card, dirpath(dir,"5331"), 0x45, 0x80, keylen, 4, "Signatur Schluessel");
  329|     64|	insert_key(p15card, dirpath(dir,"53B1"), 0x46, 0x81, keylen, 3, "Verschluesselungs Schluessel");
  330|     64|	insert_key(p15card, dirpath(dir,"5371"), 0x47, 0x82, keylen, 3, "Authentifizierungs Schluessel");
  331|     64|	insert_key(p15card, dirpath(dir,"0000"), 0x48, 0x83, 1024,   3, "1024bit Schluessel");
  332|       |
  333|     64|	insert_pin(p15card, "5000", 1, 2, 0x00, 6, "PIN",
  334|     64|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   54|     64|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     64|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  335|     64|	);
  336|     64|	insert_pin(p15card, "5001", 2, 0, 0x01, 8, "PUK",
  337|     64|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   54|     64|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|     64|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  338|     64|		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   60|     64|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
              		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   61|     64|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  339|     64|	);
  340|     64|	if(card->type==SC_CARD_TYPE_TCOS_V3){
  ------------------
  |  Branch (340:5): [True: 0, False: 64]
  ------------------
  341|      0|		insert_pin(p15card, dirpath(dir,"0000"), 3, 1, 0x83, 6, "NetKey PIN2",
  342|      0|			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      0|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  343|      0|			SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  344|      0|		);
  345|     64|	} else {
  346|     64|		insert_pin(p15card, dirpath(dir,"5080"), 3, 1, 0x80, 6, "NetKey PIN0",
  347|     64|			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|     64|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|     64|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  348|     64|			SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     64|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  349|     64|		);
  350|     64|	}
  351|     64|	insert_pin(p15card, dirpath(dir,"5081"), 4, 1, 0x81, 6, "NetKey PIN1",
  352|     64|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|     64|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|     64|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  353|     64|		SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     64|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  354|     64|	);
  355|       |
  356|       |	/* SigG-Applikation */
  357|     64|	p.len=7; p.type=SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|     64|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  358|     64|	memcpy(p.value, "\xD2\x76\x00\x00\x66\x01", p.len=6);
  359|     64|	if (sc_select_file(card,&p,&f)==SC_SUCCESS){
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  |  Branch (359:6): [True: 2, False: 62]
  ------------------
  360|      2|		sprintf(dir,"%04X", f->id);
  361|      2|		sc_file_free(f);
  362|       |
  363|      2|		insert_cert(p15card, dirpath(dir,"C000"), 0x49, 1, "SigG Zertifikat 1");
  364|      2|		insert_cert(p15card, dirpath(dir,"4331"), 0x49, 1, "SigG Zertifikat 2");
  365|      2|		insert_cert(p15card, dirpath(dir,"4332"), 0x49, 1, "SigG Zertifikat 3");
  366|       |
  367|      2|		if(card->type==SC_CARD_TYPE_TCOS_V3){
  ------------------
  |  Branch (367:6): [True: 0, False: 2]
  ------------------
  368|      0|			insert_key(p15card, dirpath(dir,"0000"), 0x49, 0x84, 2048, 5, "SigG Schluessel");
  369|      2|		} else {
  370|      2|			insert_key(p15card, dirpath(dir,"5331"), 0x49, 0x80, 1024, 5, "SigG Schluessel");
  371|      2|		}
  372|       |
  373|      2|		insert_pin(p15card, dirpath(dir,"5081"), 5, 0, 0x81, 6, "SigG PIN",
  374|      2|			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      2|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      2|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  375|      2|			SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      2|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  376|      2|		);
  377|      2|		if(card->type==SC_CARD_TYPE_TCOS_V3){
  ------------------
  |  Branch (377:6): [True: 0, False: 2]
  ------------------
  378|      0|			insert_pin(p15card, dirpath(dir,"0000"), 6, 0, 0x83, 8, "SigG PIN2",
  379|      0|				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      0|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  380|      0|				SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  381|      0|			);
  382|      0|		}
  383|      2|	}
  384|       |
  385|     64|	return 0;
  386|    231|}
pkcs15-tcos.c:insert_cert:
   42|  1.36k|){
   43|  1.36k|	sc_card_t *card=p15card->card;
   44|  1.36k|	sc_context_t *ctx=p15card->card->ctx;
   45|  1.36k|	struct sc_pkcs15_cert_info cert_info;
   46|  1.36k|	struct sc_pkcs15_object cert_obj;
   47|  1.36k|	unsigned char cert[20];
   48|  1.36k|	size_t cert_len = 0;
   49|  1.36k|	int r;
   50|       |
   51|  1.36k|	memset(&cert_info, 0, sizeof(cert_info));
   52|  1.36k|	cert_info.id.len      = 1;
   53|  1.36k|	cert_info.id.value[0] = id;
   54|  1.36k|	cert_info.authority   = 0;
   55|  1.36k|	sc_format_path(path, &cert_info.path);
   56|       |
   57|  1.36k|	memset(&cert_obj, 0, sizeof(cert_obj));
   58|  1.36k|	strlcpy(cert_obj.label, label, sizeof(cert_obj.label));
  ------------------
  |  |   43|  1.36k|#define strlcpy _strlcpy
  ------------------
   59|  1.36k|	cert_obj.flags = writable ? SC_PKCS15_CO_FLAG_MODIFIABLE : 0;
  ------------------
  |  |   51|  1.01k|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  |  Branch (59:19): [True: 1.01k, False: 356]
  ------------------
   60|       |
   61|  1.36k|	if (sc_select_file(card, &cert_info.path, NULL) != SC_SUCCESS) {
  ------------------
  |  |   28|  1.36k|#define SC_SUCCESS				0
  ------------------
  |  Branch (61:6): [True: 1.13k, False: 229]
  ------------------
   62|  1.13k|		sc_log(ctx, "Select(%s) failed", path);
  ------------------
  |  |   71|  1.13k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   63|  1.13k|		return 1;
   64|  1.13k|	}
   65|    229|	r = sc_read_binary(card, 0, cert, sizeof(cert), 0);
   66|    229|	if (r <= 0) {
  ------------------
  |  Branch (66:6): [True: 76, False: 153]
  ------------------
   67|     76|		sc_log(ctx, "ReadBinary(%s) failed\n", path);
  ------------------
  |  |   71|     76|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   68|     76|		return 2;
   69|     76|	}
   70|    153|	cert_len = r; /* actual number of read bytes */
   71|    153|	if (cert_len < 4) {
  ------------------
  |  Branch (71:6): [True: 24, False: 129]
  ------------------
   72|     24|		sc_log(ctx, "Invalid certificate length");
  ------------------
  |  |   71|     24|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   73|     24|		return 3;
   74|     24|	}
   75|    129|	if (cert[0] != 0x30 || cert[1] != 0x82) {
  ------------------
  |  Branch (75:6): [True: 35, False: 94]
  |  Branch (75:25): [True: 10, False: 84]
  ------------------
   76|     45|		sc_log(ctx, "Invalid Cert: %02X:%02X:...\n", cert[0], cert[1]);
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   77|     45|		return 3;
   78|     45|	}
   79|       |
   80|       |	/* some certificates are prefixed by an OID */
   81|     84|	if (cert_len > 9 && (size_t)(7 + cert[5]) <= cert_len &&
  ------------------
  |  Branch (81:6): [True: 75, False: 9]
  |  Branch (81:22): [True: 57, False: 18]
  ------------------
   82|     57|			cert[4] == 0x06 && cert[5] < 10 && cert[6 + cert[5]] == 0x30 &&
  ------------------
  |  Branch (82:4): [True: 40, False: 17]
  |  Branch (82:23): [True: 21, False: 19]
  |  Branch (82:39): [True: 15, False: 6]
  ------------------
   83|     15|			cert[7 + cert[5]] == 0x82) {
  ------------------
  |  Branch (83:4): [True: 7, False: 8]
  ------------------
   84|      7|		if ((size_t)(9 + cert[5]) > cert_len) {
  ------------------
  |  Branch (84:7): [True: 1, False: 6]
  ------------------
   85|      1|			sc_log(ctx, "Invalid certificate length");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   86|      1|			return 3;
   87|      1|		}
   88|      6|		cert_info.path.index=6+cert[5];
   89|      6|		cert_info.path.count=(cert[8+cert[5]]<<8) + cert[9+cert[5]] + 4;
   90|     77|	} else {
   91|     77|		cert_info.path.index=0;
   92|     77|		cert_info.path.count=(cert[2]<<8) + cert[3] + 4;
   93|     77|	}
   94|       |
   95|     83|	r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
   96|     83|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     83|#define SC_SUCCESS				0
  ------------------
  |  Branch (96:6): [True: 0, False: 83]
  ------------------
   97|      0|		sc_log(ctx, "sc_pkcs15emu_add_x509_cert(%s) failed", path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   98|      0|		return 4;
   99|      0|	}
  100|     83|	sc_log(ctx, "%s: OK, Index=%d, Count=%d", path, cert_info.path.index, cert_info.path.count);
  ------------------
  |  |   71|     83|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  101|     83|	return 0;
  102|     83|}
pkcs15-tcos.c:dirpath:
  286|  1.03k|static char *dirpath(char *dir, const char *path){
  287|  1.03k|	static char buf[SC_MAX_PATH_STRING_SIZE];
  288|       |
  289|  1.03k|	strlcpy(buf,dir,sizeof buf);
  ------------------
  |  |   43|  1.03k|#define strlcpy _strlcpy
  ------------------
  290|  1.03k|	strlcat(buf,path,sizeof buf);
  291|  1.03k|	return buf;
  292|  1.03k|}
pkcs15-tcos.c:insert_key:
  113|    702|{
  114|    702|	sc_card_t *card = p15card->card;
  115|    702|	sc_context_t *ctx = p15card->card->ctx;
  116|    702|	sc_file_t *f;
  117|    702|	struct sc_pkcs15_prkey_info prkey_info;
  118|    702|	struct sc_pkcs15_object prkey_obj;
  119|    702|	int r, can_sign, can_crypt;
  120|       |
  121|    702|	memset(&prkey_info, 0, sizeof(prkey_info));
  122|    702|	prkey_info.id.len         = 1;
  123|    702|	prkey_info.id.value[0]    = id;
  124|    702|	prkey_info.native         = 1;
  125|    702|	prkey_info.key_reference  = key_reference;
  126|    702|	prkey_info.modulus_length = key_length;
  127|    702|	sc_format_path(path, &prkey_info.path);
  128|       |
  129|    702|	memset(&prkey_obj, 0, sizeof(prkey_obj));
  130|    702|	strlcpy(prkey_obj.label, label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    702|#define strlcpy _strlcpy
  ------------------
  131|    702|	prkey_obj.flags            = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    702|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  132|    702|	prkey_obj.auth_id.len      = 1;
  133|    702|	prkey_obj.auth_id.value[0] = auth_id;
  134|       |
  135|    702|	can_sign = can_crypt = 0;
  136|    702|	if (card->type == SC_CARD_TYPE_TCOS_V3) {
  ------------------
  |  Branch (136:6): [True: 0, False: 702]
  ------------------
  137|      0|		unsigned char buf[256];
  138|      0|		int i, rec_no = 0;
  139|      0|		if (prkey_info.path.len >= 2)
  ------------------
  |  Branch (139:7): [True: 0, False: 0]
  ------------------
  140|      0|			prkey_info.path.len -= 2;
  141|      0|		sc_append_file_id(&prkey_info.path, 0x5349);
  142|      0|		if (sc_select_file(card, &prkey_info.path, NULL) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (142:7): [True: 0, False: 0]
  ------------------
  143|      0|			sc_log(ctx, "Select(%s) failed", sc_print_path(&prkey_info.path));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  144|      0|			return 1;
  145|      0|		}
  146|      0|		sc_log(ctx, "Searching for Key-Ref %02X", key_reference);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|      0|		while ((r = sc_read_record(card, ++rec_no, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0) {
  ------------------
  |  | 1298|      0|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (147:10): [True: 0, False: 0]
  ------------------
  148|      0|			int found = 0;
  149|      0|			if (buf[0] != 0xA0 || r < 2)
  ------------------
  |  Branch (149:8): [True: 0, False: 0]
  |  Branch (149:26): [True: 0, False: 0]
  ------------------
  150|      0|				continue;
  151|      0|			for (i = 2; i < buf[1] + 2 && i < r - 2; i += 2 + buf[i + 1]) {
  ------------------
  |  Branch (151:16): [True: 0, False: 0]
  |  Branch (151:34): [True: 0, False: 0]
  ------------------
  152|      0|				if (buf[i] == 0x83 && buf[i + 1] == 1 && buf[i + 2] == key_reference)
  ------------------
  |  Branch (152:9): [True: 0, False: 0]
  |  Branch (152:27): [True: 0, False: 0]
  |  Branch (152:46): [True: 0, False: 0]
  ------------------
  153|      0|					++found;
  154|      0|			}
  155|      0|			if (found)
  ------------------
  |  Branch (155:8): [True: 0, False: 0]
  ------------------
  156|      0|				break;
  157|      0|		}
  158|      0|		if (r <= 0) {
  ------------------
  |  Branch (158:7): [True: 0, False: 0]
  ------------------
  159|      0|			sc_log(ctx, "No EF_KEYD-Record found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  160|      0|			return 1;
  161|      0|		}
  162|      0|		for (i = 0; i + 1 < r; i += 2 + buf[i + 1]) {
  ------------------
  |  Branch (162:15): [True: 0, False: 0]
  ------------------
  163|      0|			if (buf[i] == 0xB6)
  ------------------
  |  Branch (163:8): [True: 0, False: 0]
  ------------------
  164|      0|				can_sign++;
  165|      0|			if (buf[i] == 0xB8)
  ------------------
  |  Branch (165:8): [True: 0, False: 0]
  ------------------
  166|      0|				can_crypt++;
  167|      0|		}
  168|    702|	} else {
  169|    702|		if (sc_select_file(card, &prkey_info.path, &f) != SC_SUCCESS
  ------------------
  |  |   28|  1.40k|#define SC_SUCCESS				0
  ------------------
  |  Branch (169:7): [True: 614, False: 88]
  ------------------
  170|    660|			   	|| !f->prop_attr || f->prop_attr_len < 2){
  ------------------
  |  Branch (170:11): [True: 36, False: 52]
  |  Branch (170:28): [True: 10, False: 42]
  ------------------
  171|    660|			sc_log(ctx, "Select(%s) failed", sc_print_path(&prkey_info.path));
  ------------------
  |  |   71|    660|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  172|    660|			sc_file_free(f);
  173|    660|			return 1;
  174|    660|		}
  175|     42|		if (f->prop_attr[1] & 0x04)
  ------------------
  |  Branch (175:7): [True: 15, False: 27]
  ------------------
  176|     15|			can_crypt = 1;
  177|     42|		if (f->prop_attr[1] & 0x08)
  ------------------
  |  Branch (177:7): [True: 13, False: 29]
  ------------------
  178|     13|			can_sign = 1;
  179|     42|		sc_file_free(f);
  180|     42|	}
  181|     42|	prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     42|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  182|     42|	if (can_crypt)
  ------------------
  |  Branch (182:6): [True: 15, False: 27]
  ------------------
  183|     15|		prkey_info.usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  305|     15|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              		prkey_info.usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|     15|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  184|     42|	if (can_sign)
  ------------------
  |  Branch (184:6): [True: 13, False: 29]
  ------------------
  185|     13|		prkey_info.usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|     13|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  186|       |
  187|     42|	r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  188|     42|	if(r != SC_SUCCESS) {
  ------------------
  |  |   28|     42|#define SC_SUCCESS				0
  ------------------
  |  Branch (188:5): [True: 0, False: 42]
  ------------------
  189|      0|		sc_log(ctx,  "sc_pkcs15emu_add_rsa_prkey(%s) failed\n", path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  190|      0|		return 4;
  191|      0|	}
  192|     42|	sc_log(ctx,  "%s: OK%s%s\n", path, can_sign ? ", Sign" : "", can_crypt ? ", Crypt" : "");
  ------------------
  |  |   71|    168|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 13, False: 29]
  |  |  |  Branch (71:122): [True: 15, False: 27]
  |  |  ------------------
  ------------------
  193|     42|	return 0;
  194|     42|}
pkcs15-tcos.c:insert_pin:
  205|    398|){
  206|    398|	sc_card_t *card=p15card->card;
  207|    398|	sc_context_t *ctx=p15card->card->ctx;
  208|    398|	sc_file_t *f = NULL;
  209|    398|	struct sc_pkcs15_auth_info pin_info;
  210|    398|	struct sc_pkcs15_object pin_obj;
  211|    398|	int r;
  212|       |
  213|    398|	memset(&pin_info, 0, sizeof(pin_info));
  214|    398|	pin_info.auth_id.len      = 1;
  215|    398|	pin_info.auth_id.value[0] = id;
  216|    398|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    398|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  217|    398|	pin_info.attrs.pin.reference        = pin_reference;
  218|    398|	pin_info.attrs.pin.flags            = pin_flags;
  219|    398|	pin_info.attrs.pin.type             = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    398|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  220|    398|	pin_info.attrs.pin.min_length       = min_length;
  221|    398|	pin_info.attrs.pin.stored_length    = 16;
  222|    398|	pin_info.attrs.pin.max_length       = 16;
  223|    398|	pin_info.attrs.pin.pad_char         = '\0';
  224|    398|	pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    398|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  225|    398|	sc_format_path(path, &pin_info.path);
  226|       |
  227|    398|	memset(&pin_obj, 0, sizeof(pin_obj));
  228|    398|	strlcpy(pin_obj.label, label, sizeof(pin_obj.label));
  ------------------
  |  |   43|    398|#define strlcpy _strlcpy
  ------------------
  229|    398|	pin_obj.flags            = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    398|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              	pin_obj.flags            = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    398|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  230|    398|	pin_obj.auth_id.len      = auth_id ? 0 : 1;
  ------------------
  |  Branch (230:29): [True: 260, False: 138]
  ------------------
  231|    398|	pin_obj.auth_id.value[0] = auth_id;
  232|       |
  233|    398|	if(card->type == SC_CARD_TYPE_TCOS_V3) {
  ------------------
  |  Branch (233:5): [True: 0, False: 398]
  ------------------
  234|      0|		unsigned char buf[256];
  235|      0|		int i, rec_no=0;
  236|      0|		if (pin_info.path.len >= 2) {
  ------------------
  |  Branch (236:7): [True: 0, False: 0]
  ------------------
  237|      0|			pin_info.path.len -= 2;
  238|      0|		}
  239|      0|		sc_append_file_id(&pin_info.path, 0x5049);
  240|      0|		if (sc_select_file(card, &pin_info.path, NULL) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:7): [True: 0, False: 0]
  ------------------
  241|      0|			sc_log(ctx, "Select(%s) failed", sc_print_path(&pin_info.path));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  242|      0|			return 1;
  243|      0|		}
  244|      0|		sc_log(ctx, "Searching for PIN-Ref %02X", pin_reference);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  245|      0|		while ((r = sc_read_record(card, ++rec_no, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0) {
  ------------------
  |  | 1298|      0|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (245:10): [True: 0, False: 0]
  ------------------
  246|      0|			int found = 0, fbz = -1;
  247|      0|			if (r < 2 || buf[0] != 0xA0)
  ------------------
  |  Branch (247:8): [True: 0, False: 0]
  |  Branch (247:17): [True: 0, False: 0]
  ------------------
  248|      0|				continue;
  249|      0|			for (i = 2; i < buf[1] + 2 && (i + 2) < r; i += 2 + buf[i + 1]) {
  ------------------
  |  Branch (249:16): [True: 0, False: 0]
  |  Branch (249:34): [True: 0, False: 0]
  ------------------
  250|      0|				if (buf[i] == 0x83 && buf[i + 1] == 1 && buf[i + 2] == pin_reference) {
  ------------------
  |  Branch (250:9): [True: 0, False: 0]
  |  Branch (250:27): [True: 0, False: 0]
  |  Branch (250:46): [True: 0, False: 0]
  ------------------
  251|      0|					++found;
  252|      0|				}
  253|      0|				if (buf[i] == 0x90 && (i + 1 + buf[i + 1]) < r) {
  ------------------
  |  Branch (253:9): [True: 0, False: 0]
  |  Branch (253:27): [True: 0, False: 0]
  ------------------
  254|      0|					fbz = buf[i + 1 + buf[i + 1]];
  255|      0|				}
  256|      0|			}
  257|      0|			if (found) {
  ------------------
  |  Branch (257:8): [True: 0, False: 0]
  ------------------
  258|      0|				pin_info.tries_left = fbz;
  259|      0|				break;
  260|      0|			}
  261|      0|		}
  262|      0|		if (r <= 0) {
  ------------------
  |  Branch (262:7): [True: 0, False: 0]
  ------------------
  263|      0|			sc_log(ctx, "No EF_PWDD-Record found\n");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  264|      0|			return 1;
  265|      0|		}
  266|    398|	} else {
  267|    398|		if (sc_select_file(card, &pin_info.path, &f) != SC_SUCCESS
  ------------------
  |  |   28|    796|#define SC_SUCCESS				0
  ------------------
  |  Branch (267:7): [True: 372, False: 26]
  ------------------
  268|    387|			   	|| !f->prop_attr || f->prop_attr_len < 4){
  ------------------
  |  Branch (268:11): [True: 12, False: 14]
  |  Branch (268:28): [True: 3, False: 11]
  ------------------
  269|    387|			sc_log(ctx, "Select(%s) failed\n", path);
  ------------------
  |  |   71|    387|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  270|    387|			sc_file_free(f);
  271|    387|			return 1;
  272|    387|		}
  273|     11|		pin_info.tries_left = f->prop_attr[3];
  274|     11|		sc_file_free(f);
  275|     11|	}
  276|       |
  277|     11|	r=sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  278|     11|	if(r!=SC_SUCCESS){
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  |  Branch (278:5): [True: 0, False: 11]
  ------------------
  279|      0|		sc_log(ctx,  "sc_pkcs15emu_add_pin_obj(%s) failed\n", path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  280|      0|		return 4;
  281|      0|	}
  282|     11|	sc_log(ctx,  "%s: OK, FBZ=%d\n", path, pin_info.tries_left);
  ------------------
  |  |   71|     11|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  283|     11|	return 0;
  284|     11|}
pkcs15-tcos.c:detect_idkey:
  390|    167|){
  391|    167|	sc_card_t *card=p15card->card;
  392|    167|	sc_path_t p;
  393|       |
  394|       |	/* TCKEY-Applikation ? */
  395|    167|	memset(&p, 0, sizeof(sc_path_t));
  396|    167|	p.type=SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    167|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  397|    167|	memcpy(p.value, "\xD2\x76\x00\x00\x03\x0C\x01", p.len=7);
  398|    167|	if (sc_select_file(card,&p,NULL)!=SC_SUCCESS) return 1;
  ------------------
  |  |   28|    167|#define SC_SUCCESS				0
  ------------------
  |  Branch (398:6): [True: 128, False: 39]
  ------------------
  399|       |
  400|     39|	set_string(&p15card->tokeninfo->manufacturer_id, "TeleSec GmbH");
  401|     39|	set_string(&p15card->tokeninfo->label, "IDKey Card");
  402|       |
  403|     39|	insert_cert(p15card, "DF074331", 0x45, 1, "Signatur Zertifikat 1");
  404|     39|	insert_cert(p15card, "DF074332", 0x46, 1, "Signatur Zertifikat 2");
  405|     39|	insert_cert(p15card, "DF074333", 0x47, 1, "Signatur Zertifikat 3");
  406|     39|	insert_cert(p15card, "DF084331", 0x4B, 1, "Verschluesselungs Zertifikat 1");
  407|     39|	insert_cert(p15card, "DF084332", 0x4C, 1, "Verschluesselungs Zertifikat 2");
  408|     39|	insert_cert(p15card, "DF084333", 0x4D, 1, "Verschluesselungs Zertifikat 3");
  409|       |	/* TODO should others come here too? */
  410|       |
  411|     39|	insert_key(p15card, "DF074E03", 0x45, 0x84, 2048, 1, "IDKey1");
  412|     39|	insert_key(p15card, "DF074E04", 0x46, 0x85, 2048, 1, "IDKey2");
  413|     39|	insert_key(p15card, "DF074E05", 0x47, 0x86, 2048, 1, "IDKey3");
  414|     39|	insert_key(p15card, "DF074E06", 0x48, 0x87, 2048, 1, "IDKey4");
  415|     39|	insert_key(p15card, "DF074E07", 0x49, 0x88, 2048, 1, "IDKey5");
  416|     39|	insert_key(p15card, "DF074E08", 0x4A, 0x89, 2048, 1, "IDKey6");
  417|     39|	insert_key(p15card, "DF084E01", 0x4B, 0x81, 2048, 1, "IDKey7");
  418|     39|	insert_key(p15card, "DF084E02", 0x4C, 0x82, 2048, 1, "IDKey8");
  419|     39|	insert_key(p15card, "DF084E03", 0x4D, 0x83, 2048, 1, "IDKey9");
  420|       |
  421|     39|	insert_pin(p15card, "5000", 1, 2, 0x00, 6, "PIN",
  422|     39|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   54|     39|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     39|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  423|     39|	);
  424|     39|	insert_pin(p15card, "5001", 2, 0, 0x01, 8, "PUK",
  425|     39|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   54|     39|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|     39|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  426|     39|		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   60|     39|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
              		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   61|     39|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  427|     39|	);
  428|       |
  429|     39|	return 0;
  430|    167|}
pkcs15-tcos.c:detect_unicard:
  485|    128|){
  486|    128|	if(!insert_cert(p15card,"41004352", 0x45, 1, "Zertifikat 1")){
  ------------------
  |  Branch (486:5): [True: 28, False: 100]
  ------------------
  487|     28|		set_string(&p15card->tokeninfo->manufacturer_id, "JLU Giessen");
  488|     28|		set_string(&p15card->tokeninfo->label, "JLU Giessen Card");
  489|       |
  490|     28|		insert_cert(p15card,"41004353", 0x46, 1, "Zertifikat 2");
  491|     28|		insert_cert(p15card,"41004354", 0x47, 1, "Zertifikat 3");
  492|     28|		insert_key(p15card,"41005103", 0x45, 0x83, 1024, 1, "Schluessel 1");
  493|     28|		insert_key(p15card,"41005104", 0x46, 0x84, 1024, 1, "Schluessel 2");
  494|     28|		insert_key(p15card,"41005105", 0x47, 0x85, 1024, 1, "Schluessel 3");
  495|       |
  496|    100|	} else if(!insert_cert(p15card,"41014352", 0x45, 1, "Zertifikat 1")){
  ------------------
  |  Branch (496:12): [True: 1, False: 99]
  ------------------
  497|      1|		set_string(&p15card->tokeninfo->manufacturer_id, "TU Darmstadt");
  498|      1|		set_string(&p15card->tokeninfo->label, "TUD Card");
  499|       |
  500|      1|		insert_cert(p15card,"41014353", 0x46, 1, "Zertifikat 2");
  501|      1|		insert_cert(p15card,"41014354", 0x47, 1, "Zertifikat 3");
  502|      1|		insert_key(p15card,"41015103", 0x45, 0x83, 1024, 1, "Schluessel 1");
  503|      1|		insert_key(p15card,"41015104", 0x46, 0x84, 1024, 1, "Schluessel 2");
  504|      1|		insert_key(p15card,"41015105", 0x47, 0x85, 1024, 1, "Schluessel 3");
  505|       |
  506|     99|	} else return 1;
  507|       |
  508|     29|	insert_pin(p15card,"5000", 1, 2, 0x00, 6, "PIN",
  509|     29|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   54|     29|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|     29|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  510|     29|	);
  511|     29|	insert_pin(p15card,"5008", 2, 0, 0x01, 8, "PUK",
  512|     29|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   54|     29|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|     29|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  513|     29|		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   60|     29|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
              		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
  ------------------
  |  |   61|     29|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  514|     29|	);
  515|       |
  516|     29|	return 0;
  517|    128|}
pkcs15-tcos.c:detect_signtrust:
  434|     99|){
  435|     99|	if(insert_cert(p15card,"8000DF01C000", 0x45, 1, "Signatur Zertifikat")) return 1;
  ------------------
  |  Branch (435:5): [True: 98, False: 1]
  ------------------
  436|      1|	set_string(&p15card->tokeninfo->manufacturer_id, "Deutsche Post");
  437|      1|	set_string(&p15card->tokeninfo->label, "SignTrust Card");
  438|       |
  439|      1|	insert_cert(p15card,"800082008220", 0x46, 1, "Verschluesselungs Zertifikat");
  440|      1|	insert_cert(p15card,"800083008320", 0x47, 1, "Authentifizierungs Zertifikat");
  441|       |
  442|      1|	insert_key(p15card,"8000DF015331", 0x45, 0x80, 1024, 1, "Signatur Schluessel");
  443|      1|	insert_key(p15card,"800082008210", 0x46, 0x80, 1024, 2, "Verschluesselungs Schluessel");
  444|      1|	insert_key(p15card,"800083008310", 0x47, 0x80, 1024, 3, "Authentifizierungs Schluessel");
  445|       |
  446|      1|	insert_pin(p15card,"8000DF010000", 1, 0, 0x81, 6, "Signatur PIN",
  447|      1|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      1|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      1|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  448|      1|		SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      1|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  449|      1|	);
  450|      1|	insert_pin(p15card,"800082000040", 2, 0, 0x81, 6, "Verschluesselungs PIN",
  451|      1|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      1|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      1|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  452|      1|		SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      1|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  453|      1|	);
  454|      1|	insert_pin(p15card,"800083000040", 3, 0, 0x81, 6, "Authentifizierungs PIN",
  455|      1|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   54|      1|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
  ------------------
  |  |   55|      1|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  456|      1|		SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      1|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  457|      1|	);
  458|       |
  459|      1|	return 0;
  460|     99|}
pkcs15-tcos.c:detect_datev:
  464|     98|){
  465|     98|	if(insert_cert(p15card,"3000C500", 0x45, 0, "Signatur Zertifikat")) return 1;
  ------------------
  |  Branch (465:5): [True: 97, False: 1]
  ------------------
  466|      1|	set_string(&p15card->tokeninfo->manufacturer_id, "DATEV");
  467|      1|	set_string(&p15card->tokeninfo->label, "DATEV Classic");
  468|       |
  469|      1|	insert_cert(p15card,"DF02C200", 0x46, 0, "Verschluesselungs Zertifikat");
  470|      1|	insert_cert(p15card,"DF02C500", 0x47, 0, "Authentifizierungs Zertifikat");
  471|       |
  472|      1|	insert_key(p15card,"30005371", 0x45, 0x82, 1024, 1, "Signatur Schluessel");
  473|      1|	insert_key(p15card,"DF0253B1", 0x46, 0x81, 1024, 1, "Verschluesselungs Schluessel");
  474|      1|	insert_key(p15card,"DF025371", 0x47, 0x82, 1024, 1, "Authentifizierungs Schluessel");
  475|       |
  476|      1|	insert_pin(p15card,"5001", 1, 0, 0x01, 6, "PIN",
  477|      1|		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   54|      1|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
              		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|      1|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  478|      1|	);
  479|       |
  480|      1|	return 0;
  481|     98|}

sc_pkcs15_parse_tokeninfo:
  144|    838|{
  145|    838|	int r;
  146|    838|	size_t ii;
  147|    838|	u8 serial[128];
  148|    838|	size_t serial_len = sizeof(serial);
  149|    838|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  150|    838|	size_t mnfid_len  = sizeof(mnfid) - 1;
  151|    838|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  152|    838|	size_t label_len = sizeof(label) - 1;
  153|    838|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  154|    838|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  155|    838|	size_t flags_len   = sizeof(ti->flags);
  156|    838|	u8 preferred_language[64];
  157|    838|	size_t lang_length = sizeof(preferred_language) - 1;
  158|    838|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  159|    838|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  160|    838|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  161|    838|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  162|    838|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  163|    838|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  164|    838|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  165|    838|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  166|       |
  167|    838|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  168|    838|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  169|    838|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  170|       |
  171|    838|	memset(last_update, 0, sizeof(last_update));
  172|    838|	memset(label, 0, sizeof(label));
  173|    838|	memset(profile_indication, 0, sizeof(profile_indication));
  174|    838|	memset(mnfid, 0, sizeof(mnfid));
  175|       |
  176|    838|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  177|    838|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  178|    838|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  179|    838|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  180|    838|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  181|    838|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  182|       |
  183|  14.2k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  14.2k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (183:13): [True: 13.4k, False: 838]
  ------------------
  184|  13.4k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  185|  13.4k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  186|  13.4k|			asn1_algo_infos_parameters[ii]);
  187|  13.4k|	}
  188|    838|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  189|       |
  190|  14.2k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  14.2k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (190:13): [True: 13.4k, False: 838]
  ------------------
  191|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  192|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  193|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  194|  13.4k|			asn1_algo_infos_parameters[ii], NULL, 0);
  195|  13.4k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  196|  13.4k|			NULL, NULL, 0);
  197|  13.4k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  198|  13.4k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  199|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  200|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  201|  13.4k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  202|  13.4k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  203|  13.4k|	}
  204|       |
  205|    838|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  206|    838|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  207|       |
  208|    838|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  209|    838|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  210|       |
  211|    838|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  212|    838|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  213|    838|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  214|    838|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  215|    838|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  216|    838|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  217|    838|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  218|    838|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  219|    838|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  220|    838|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  221|    838|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  222|    838|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  223|    838|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  224|    838|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  225|    838|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  226|       |
  227|    838|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  228|    838|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    838|#define SC_SUCCESS				0
  ------------------
  |  Branch (228:6): [True: 397, False: 441]
  ------------------
  229|       |		/* The decoding could have allocated something we need to free */
  230|    397|		sc_pkcs15_clear_tokeninfo(ti);
  231|    397|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    397|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    397|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    397|	int _ret = (r); \
  |  |  |  |  168|    397|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 397, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    397|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    397|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    397|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    397|		return _ret; \
  |  |  |  |  172|    397|	} \
  |  |  |  |  173|    397|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  232|    397|	}
  233|       |
  234|    441|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  147|    882|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (234:6): [True: 130, False: 311]
  |  Branch (234:52): [True: 129, False: 1]
  ------------------
  235|    129|		free(ti->serial_number);
  236|    129|		ti->serial_number = malloc(serial_len * 2 + 1);
  237|    129|		if (ti->serial_number == NULL)
  ------------------
  |  Branch (237:7): [True: 0, False: 129]
  ------------------
  238|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  239|    129|		sc_bin_to_hex(serial, serial_len, ti->serial_number, serial_len * 2 + 1, 0);
  240|    129|		sc_log(ctx, "TokenInfo.serialNunmber '%s'", ti->serial_number);
  ------------------
  |  |   71|    129|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  241|    129|	}
  242|       |
  243|    441|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (243:6): [True: 441, False: 0]
  ------------------
  244|    441|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    441|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (244:7): [True: 84, False: 357]
  ------------------
  245|     84|			ti->manufacturer_id = strdup((char *) mnfid);
  246|    357|		else
  247|    357|			ti->manufacturer_id = strdup("(unknown)");
  248|    441|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (248:7): [True: 0, False: 441]
  ------------------
  249|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  250|    441|	}
  251|    441|	if (ti->label == NULL) {
  ------------------
  |  Branch (251:6): [True: 441, False: 0]
  ------------------
  252|    441|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  147|    882|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (252:7): [True: 3, False: 438]
  ------------------
  253|    438|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    438|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 0, False: 438]
  ------------------
  254|      3|			ti->label = strdup((char *) label);
  255|    438|		else
  256|    438|			ti->label = strdup("(unknown)");
  257|    441|		if (ti->label == NULL)
  ------------------
  |  Branch (257:7): [True: 0, False: 441]
  ------------------
  258|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  259|    441|	}
  260|    441|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    441|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (260:6): [True: 5, False: 436]
  ------------------
  261|      5|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      5|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:7): [True: 1, False: 4]
  ------------------
  262|      1|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  263|      1|			ti->last_update.gtime = strdup((char *)last_update);
  264|      1|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (264:8): [True: 0, False: 1]
  ------------------
  265|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  266|      1|		}
  267|      4|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|      4|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (267:12): [True: 0, False: 4]
  ------------------
  268|      0|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  269|      0|		}
  270|      5|	}
  271|    441|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    441|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (271:6): [True: 3, False: 438]
  ------------------
  272|      3|		preferred_language[lang_length] = 0;
  273|      3|		ti->preferred_language = strdup((char *)preferred_language);
  274|      3|		if (ti->preferred_language == NULL)
  ------------------
  |  Branch (274:7): [True: 0, False: 3]
  ------------------
  275|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  276|      3|	}
  277|       |
  278|    441|	sc_init_oid(&ti->profile_indication.oid);
  279|    441|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    441|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (279:6): [True: 60, False: 381]
  ------------------
  280|     60|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|     60|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:7): [True: 1, False: 59]
  ------------------
  281|      1|			sc_log(ctx, "ProfileIndication.oid present");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  282|      1|		}
  283|     59|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|     59|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (283:12): [True: 58, False: 1]
  ------------------
  284|     58|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   71|     58|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|     58|			ti->profile_indication.name = strdup((char *)profile_indication);
  286|     58|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (286:8): [True: 0, False: 58]
  ------------------
  287|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  288|     58|		}
  289|     60|	}
  290|       |
  291|    441|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   71|    441|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  292|    441|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   71|    441|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  293|    441|	return SC_SUCCESS;
  ------------------
  |  |   28|    441|#define SC_SUCCESS				0
  ------------------
  294|    441|}
sc_pkcs15_card_new:
  718|  11.9k|{
  719|  11.9k|	struct sc_pkcs15_card *p15card;
  720|       |
  721|  11.9k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  722|  11.9k|	if (p15card == NULL)
  ------------------
  |  Branch (722:6): [True: 0, False: 11.9k]
  ------------------
  723|      0|		return NULL;
  724|       |
  725|  11.9k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  726|  11.9k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (726:6): [True: 0, False: 11.9k]
  ------------------
  727|      0|		free(p15card);
  728|      0|		return NULL;
  729|      0|	}
  730|       |
  731|  11.9k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  11.9k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  732|  11.9k|	return p15card;
  733|  11.9k|}
sc_pkcs15_tokeninfo_new:
  738|  8.42k|{
  739|  8.42k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  740|       |
  741|  8.42k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  742|  8.42k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (742:6): [True: 0, False: 8.42k]
  ------------------
  743|      0|		return NULL;
  744|      0|	}
  745|       |
  746|  8.42k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  747|       |
  748|  8.42k|	return tokeninfo;
  749|  8.42k|}
sc_pkcs15_free_tokeninfo:
  780|  21.2k|{
  781|  21.2k|	if (!tokeninfo)
  ------------------
  |  Branch (781:6): [True: 876, False: 20.3k]
  ------------------
  782|    876|		return;
  783|       |
  784|  20.3k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  785|  20.3k|	free(tokeninfo);
  786|  20.3k|}
sc_pkcs15_free_app:
  790|  39.4k|{
  791|  39.4k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (791:6): [True: 39.4k, False: 0]
  |  Branch (791:17): [True: 722, False: 38.7k]
  ------------------
  792|    722|		free(p15card->app->label);
  793|    722|		free(p15card->app->ddo.value);
  794|    722|		free(p15card->app);
  795|       |		p15card->app = NULL;
  796|    722|	}
  797|  39.4k|}
sc_pkcs15_card_free:
  802|  11.9k|{
  803|  11.9k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  11.9k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (803:6): [True: 0, False: 11.9k]
  |  Branch (803:25): [True: 0, False: 11.9k]
  ------------------
  804|      0|		return;
  805|       |
  806|  11.9k|	if (p15card->ops.clear)
  ------------------
  |  Branch (806:6): [True: 749, False: 11.1k]
  ------------------
  807|    749|		p15card->ops.clear(p15card);
  808|       |
  809|       |	/* For more complicated MD data a dedicated release procedure
  810|       |	 * has to be implemented. */
  811|  11.9k|	if (p15card->md_data)
  ------------------
  |  Branch (811:6): [True: 0, False: 11.9k]
  ------------------
  812|      0|		free(p15card->md_data);
  813|       |
  814|  11.9k|	sc_pkcs15_free_app(p15card);
  815|  11.9k|	sc_pkcs15_remove_objects(p15card);
  816|  11.9k|	sc_pkcs15_remove_dfs(p15card);
  817|  11.9k|	sc_pkcs15_free_unusedspace(p15card);
  818|  11.9k|	p15card->unusedspace_read = 0;
  819|       |
  820|  11.9k|	sc_file_free(p15card->file_app);
  821|  11.9k|	sc_file_free(p15card->file_tokeninfo);
  822|  11.9k|	sc_file_free(p15card->file_odf);
  823|  11.9k|	sc_file_free(p15card->file_unusedspace);
  824|       |
  825|  11.9k|	p15card->magic = 0;
  826|  11.9k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  827|  11.9k|	sc_pkcs15_free_app(p15card);
  828|  11.9k|	free(p15card);
  829|  11.9k|}
sc_pkcs15_card_clear:
  834|  15.0k|{
  835|  15.0k|	if (p15card == NULL)
  ------------------
  |  Branch (835:6): [True: 0, False: 15.0k]
  ------------------
  836|      0|		return;
  837|       |
  838|  15.0k|	if (p15card->ops.clear)
  ------------------
  |  Branch (838:6): [True: 729, False: 14.3k]
  ------------------
  839|    729|		p15card->ops.clear(p15card);
  840|       |
  841|  15.0k|	p15card->flags = 0;
  842|  15.0k|	p15card->tokeninfo->version = 0;
  843|  15.0k|	p15card->tokeninfo->flags   = 0;
  844|       |
  845|  15.0k|	sc_pkcs15_remove_objects(p15card);
  846|  15.0k|	sc_pkcs15_remove_dfs(p15card);
  847|       |
  848|  15.0k|	p15card->df_list = NULL;
  849|  15.0k|	sc_file_free(p15card->file_app);
  850|  15.0k|	p15card->file_app = NULL;
  851|  15.0k|	sc_file_free(p15card->file_tokeninfo);
  852|  15.0k|	p15card->file_tokeninfo = NULL;
  853|  15.0k|	sc_file_free(p15card->file_odf);
  854|  15.0k|	p15card->file_odf = NULL;
  855|  15.0k|	sc_file_free(p15card->file_unusedspace);
  856|  15.0k|	p15card->file_unusedspace = NULL;
  857|       |
  858|  15.0k|	free(p15card->tokeninfo->label);
  859|  15.0k|	p15card->tokeninfo->label = NULL;
  860|  15.0k|	free(p15card->tokeninfo->serial_number);
  861|  15.0k|	p15card->tokeninfo->serial_number = NULL;
  862|  15.0k|	free(p15card->tokeninfo->manufacturer_id);
  863|  15.0k|	p15card->tokeninfo->manufacturer_id = NULL;
  864|  15.0k|	free(p15card->tokeninfo->last_update.gtime);
  865|  15.0k|	p15card->tokeninfo->last_update.gtime = NULL;
  866|  15.0k|	free(p15card->tokeninfo->preferred_language);
  867|  15.0k|	p15card->tokeninfo->preferred_language = NULL;
  868|  15.0k|	free(p15card->tokeninfo->profile_indication.name);
  869|  15.0k|	p15card->tokeninfo->profile_indication.name = NULL;
  870|  15.0k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (870:6): [True: 12, False: 15.0k]
  ------------------
  871|     12|		size_t i;
  872|     31|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (872:15): [True: 19, False: 12]
  ------------------
  873|     19|			free(p15card->tokeninfo->seInfo[i]);
  874|     12|		free(p15card->tokeninfo->seInfo);
  875|     12|		p15card->tokeninfo->seInfo     = NULL;
  876|     12|		p15card->tokeninfo->num_seInfo = 0;
  877|     12|	}
  878|       |
  879|  15.0k|	sc_pkcs15_free_app(p15card);
  880|  15.0k|}
sc_find_app:
  885|  12.4k|{
  886|  12.4k|	int ii;
  887|       |
  888|  12.4k|	if (card->app_count <= 0)
  ------------------
  |  Branch (888:6): [True: 11.8k, False: 601]
  ------------------
  889|  11.8k|		return NULL;
  890|       |
  891|    601|	if (!aid || !aid->len)
  ------------------
  |  Branch (891:6): [True: 421, False: 180]
  |  Branch (891:14): [True: 100, False: 80]
  ------------------
  892|    521|		return card->app[0];
  893|       |
  894|    207|	for (ii=0; ii < card->app_count; ii++) {
  ------------------
  |  Branch (894:13): [True: 131, False: 76]
  ------------------
  895|    131|		if (card->app[ii]->aid.len != aid->len)
  ------------------
  |  Branch (895:7): [True: 34, False: 97]
  ------------------
  896|     34|			continue;
  897|     97|		if (memcmp(card->app[ii]->aid.value, aid->value, aid->len))
  ------------------
  |  Branch (897:7): [True: 93, False: 4]
  ------------------
  898|     93|			continue;
  899|      4|		return card->app[ii];
  900|     97|	}
  901|     76|	return NULL;
  902|     80|}
sc_pkcs15_get_application_by_type:
  939|  11.6k|{
  940|  11.6k|	struct sc_app_info *out = NULL;
  941|  11.6k|	scconf_block *conf_block = NULL;
  942|  11.6k|	int i, rv;
  943|       |
  944|  11.6k|	if (!card)
  ------------------
  |  Branch (944:6): [True: 0, False: 11.6k]
  ------------------
  945|      0|		return NULL;
  946|       |
  947|  11.6k|	if (card->app_count < 0)   {
  ------------------
  |  Branch (947:6): [True: 11.6k, False: 0]
  ------------------
  948|  11.6k|		rv = sc_enum_apps(card);
  949|  11.6k|		if (rv < 0 && rv != SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  11.0k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (949:7): [True: 11.0k, False: 542]
  |  Branch (949:17): [True: 9.25k, False: 1.81k]
  ------------------
  950|  9.25k|			return NULL;
  951|  11.6k|	}
  952|       |
  953|  2.35k|	conf_block = sc_get_conf_block(card->ctx, "framework", "pkcs15", 1);
  954|  2.35k|	if (!conf_block)
  ------------------
  |  Branch (954:6): [True: 2.35k, False: 0]
  ------------------
  955|  2.35k|		return NULL;
  956|       |
  957|      0|	for (i = 0; i < card->app_count; i++)   {
  ------------------
  |  Branch (957:14): [True: 0, False: 0]
  ------------------
  958|      0|		struct sc_app_info *app_info = card->app[i];
  959|      0|		scconf_block **blocks = NULL;
  960|      0|		char str_path[SC_MAX_AID_STRING_SIZE];
  961|       |
  962|      0|		sc_bin_to_hex(app_info->aid.value, app_info->aid.len, str_path, sizeof(str_path), 0);
  963|      0|		blocks = scconf_find_blocks(card->ctx->conf, conf_block, "application", str_path);
  964|      0|		if (blocks)   {
  ------------------
  |  Branch (964:7): [True: 0, False: 0]
  ------------------
  965|      0|			if (blocks[0])   {
  ------------------
  |  Branch (965:8): [True: 0, False: 0]
  ------------------
  966|      0|				char *type = (char *)scconf_get_str(blocks[0], "type", app_type);
  967|      0|				if (!strcmp(type, app_type))   {
  ------------------
  |  Branch (967:9): [True: 0, False: 0]
  ------------------
  968|      0|					out = app_info;
  969|      0|					free(blocks);
  970|      0|					break;
  971|      0|				}
  972|      0|			}
  973|      0|			free(blocks);
  974|      0|		}
  975|      0|	}
  976|       |
  977|      0|	return out;
  978|  2.35k|}
sc_pkcs15_bind_internal_odf:
  982|    660|{
  983|    660|	struct sc_path tmppath;
  984|    660|	struct sc_card    *card = p15card->card;
  985|    660|	struct sc_context *ctx = card->ctx;
  986|    660|	struct sc_pkcs15_df *df;
  987|    660|	unsigned char *buf = NULL;
  988|    660|	size_t len;
  989|    660|	int    err, ok = 0;
  990|       |
  991|    660|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    660|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    660|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    660|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    660|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 660]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|    660|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (992:6): [True: 660, False: 0]
  ------------------
  993|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
  994|    660|		sc_format_path("5031", &tmppath);
  995|    660|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
  996|    660|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    660|#define SC_SUCCESS				0
  ------------------
  |  Branch (996:7): [True: 0, False: 660]
  ------------------
  997|      0|			sc_log(ctx, "Cannot make absolute path to EF(ODF); error:%i", err);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  998|      0|			goto end;
  999|      0|		}
 1000|    660|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|    660|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1001|    660|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1002|    660|	}
 1003|      0|	else {
 1004|      0|		tmppath = p15card->file_odf->path;
 1005|      0|		sc_file_free(p15card->file_odf);
 1006|      0|		p15card->file_odf = NULL;
 1007|      0|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1008|      0|	}
 1009|       |
 1010|    660|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|    660|#define SC_SUCCESS				0
  ------------------
  |  Branch (1010:6): [True: 319, False: 341]
  ------------------
 1011|    319|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   71|    319|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1012|    319|		goto end;
 1013|    319|	}
 1014|       |
 1015|    341|	len = p15card->file_odf->size;
 1016|    341|	if (!len) {
  ------------------
  |  Branch (1016:6): [True: 87, False: 254]
  ------------------
 1017|     87|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   71|     87|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1018|     87|		goto end;
 1019|     87|	}
 1020|    254|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    254|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1020:6): [True: 28, False: 226]
  ------------------
 1021|     28|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1022|     28|		goto end;
 1023|     28|	}
 1024|    226|	buf = malloc(len);
 1025|    226|	if(buf == NULL) {
  ------------------
  |  Branch (1025:5): [True: 0, False: 226]
  ------------------
 1026|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1027|      0|		goto end;
 1028|      0|	}
 1029|       |
 1030|    226|	err = -1; /* file state: not in cache */
 1031|    226|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1031:6): [True: 170, False: 56]
  ------------------
 1032|    170|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1033|    170|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    170|#define SC_SUCCESS				0
  ------------------
  |  Branch (1033:7): [True: 0, False: 170]
  ------------------
 1034|      0|			err = (int)len;
 1035|    170|	}
 1036|    226|	if (err < 0) {
  ------------------
  |  Branch (1036:6): [True: 226, False: 0]
  ------------------
 1037|    226|		err = sc_read_binary(card, 0, buf, len, 0);
 1038|    226|		if (err < 2) {
  ------------------
  |  Branch (1038:7): [True: 45, False: 181]
  ------------------
 1039|     45|			if (err < 0) {
  ------------------
  |  Branch (1039:8): [True: 38, False: 7]
  ------------------
 1040|     38|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|     38|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1041|     38|			} else {
 1042|      7|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|      7|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1043|      7|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1044|      7|			}
 1045|     45|			goto end;
 1046|     45|		}
 1047|       |		/* sc_read_binary may return less than requested */
 1048|    181|		len = err;
 1049|       |
 1050|    181|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1050:7): [True: 156, False: 25]
  ------------------
 1051|    156|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1052|    156|		}
 1053|    181|	}
 1054|       |
 1055|    181|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1055:6): [True: 56, False: 125]
  ------------------
 1056|     56|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     56|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1057|     56|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   71|     56|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1058|     56|		goto end;
 1059|     56|	}
 1060|    125|	free(buf);
 1061|    125|	buf = NULL;
 1062|       |
 1063|    125|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   71|    125|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1064|    362|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1064:30): [True: 237, False: 125]
  ------------------
 1065|    237|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   71|    362|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1066|    125|				sc_print_path(&df->path), df->path.index, df->path.count);
 1067|       |
 1068|    125|	ok = 1;
 1069|    660|end:
 1070|    660|	if (buf != NULL)
  ------------------
  |  Branch (1070:6): [True: 101, False: 559]
  ------------------
 1071|    101|		free(buf);
 1072|    660|	if (!ok) {
  ------------------
  |  Branch (1072:6): [True: 535, False: 125]
  ------------------
 1073|    535|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|    535|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    535|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    535|	int _ret = r; \
  |  |  |  |  155|    535|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 535, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    535|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    420|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 420, False: 115]
  |  |  |  |  ------------------
  |  |  |  |  157|    535|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    535|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    535|	return _ret; \
  |  |  |  |  163|    535|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1074|    535|	}
 1075|       |
 1076|    125|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    125|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    125|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    125|	int _ret = r; \
  |  |  |  |  155|    125|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 125, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 125]
  |  |  |  |  ------------------
  |  |  |  |  157|    125|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    125|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    125|	return _ret; \
  |  |  |  |  163|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1077|    125|}
sc_pkcs15_bind_internal_tokeninfo:
 1081|  11.7k|{
 1082|  11.7k|	struct sc_path tmppath;
 1083|  11.7k|	struct sc_card *card = p15card->card;
 1084|  11.7k|	struct sc_context *ctx = card->ctx;
 1085|  11.7k|	struct sc_pkcs15_tokeninfo tokeninfo;
 1086|  11.7k|	unsigned char *buf = NULL;
 1087|  11.7k|	size_t len;
 1088|  11.7k|	int err, ok = 0;
 1089|       |
 1090|  11.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1091|       |
 1092|  11.7k|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1092:6): [True: 11.7k, False: 6]
  ------------------
 1093|  11.7k|		sc_format_path("5032", &tmppath);
 1094|  11.7k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1095|  11.7k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  11.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1095:7): [True: 1, False: 11.7k]
  ------------------
 1096|      1|			sc_log(ctx, "Cannot make absolute path to EF(TokenInfo); error:%i", err);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1097|      1|			goto end;
 1098|      1|		}
 1099|  11.7k|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|  11.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1100|  11.7k|	}
 1101|      6|	else {
 1102|      6|		tmppath = p15card->file_tokeninfo->path;
 1103|      6|		sc_file_free(p15card->file_tokeninfo);
 1104|      6|		p15card->file_tokeninfo = NULL;
 1105|      6|	}
 1106|       |
 1107|  11.7k|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1108|  11.7k|	if (err)   {
  ------------------
  |  Branch (1108:6): [True: 10.5k, False: 1.19k]
  ------------------
 1109|  10.5k|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   71|  10.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1110|  10.5k|		goto end;
 1111|  10.5k|	}
 1112|       |
 1113|  1.19k|	len = p15card->file_tokeninfo->size;
 1114|  1.19k|	if (!len) {
  ------------------
  |  Branch (1114:6): [True: 450, False: 741]
  ------------------
 1115|    450|		sc_log(ctx, "EF(TokenInfo) is empty");
  ------------------
  |  |   71|    450|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1116|    450|		goto end;
 1117|    450|	}
 1118|    741|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    741|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1118:6): [True: 79, False: 662]
  ------------------
 1119|     79|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   71|     79|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1120|     79|		goto end;
 1121|     79|	}
 1122|    662|	buf = malloc(len);
 1123|    662|	if(buf == NULL) {
  ------------------
  |  Branch (1123:5): [True: 0, False: 662]
  ------------------
 1124|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1125|      0|		goto end;
 1126|      0|	}
 1127|       |
 1128|    662|	err = -1; /* file state: not in cache */
 1129|    662|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1129:6): [True: 235, False: 427]
  ------------------
 1130|    235|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1131|    235|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    235|#define SC_SUCCESS				0
  ------------------
  |  Branch (1131:7): [True: 0, False: 235]
  ------------------
 1132|      0|			err = (int)len;
 1133|    235|	}
 1134|    662|	if (err < 0) {
  ------------------
  |  Branch (1134:6): [True: 662, False: 0]
  ------------------
 1135|    662|		err = sc_read_binary(card, 0, buf, len, 0);
 1136|    662|		if (err <= 2) {
  ------------------
  |  Branch (1136:7): [True: 361, False: 301]
  ------------------
 1137|    361|			if (err < 0)   {
  ------------------
  |  Branch (1137:8): [True: 340, False: 21]
  ------------------
 1138|    340|				sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|    340|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1139|    340|			} else {
 1140|     21|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     21|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1141|     21|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   71|     21|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1142|     21|			}
 1143|    361|			goto end;
 1144|    361|		}
 1145|       |		/* sc_read_binary may return less than requested */
 1146|    301|		len = err;
 1147|       |
 1148|    301|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1148:7): [True: 163, False: 138]
  ------------------
 1149|    163|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1150|    163|		}
 1151|    301|	}
 1152|       |
 1153|    301|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1154|    301|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1155|    301|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    301|#define SC_SUCCESS				0
  ------------------
  |  Branch (1155:6): [True: 170, False: 131]
  ------------------
 1156|    170|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   71|    170|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1157|    170|		goto end;
 1158|    170|	}
 1159|       |
 1160|    131|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1161|    131|	*(p15card->tokeninfo) = tokeninfo;
 1162|       |
 1163|    131|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1163:6): [True: 113, False: 18]
  |  Branch (1163:44): [True: 113, False: 0]
  ------------------
 1164|    113|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1165|    113|	}
 1166|       |
 1167|    131|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1167:6): [True: 113, False: 18]
  |  Branch (1167:44): [True: 10, False: 103]
  ------------------
 1168|     10|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1169|     10|		size_t ii;
 1170|     10|		if (!serial) {
  ------------------
  |  Branch (1170:7): [True: 0, False: 10]
  ------------------
 1171|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1172|      0|			goto end;
 1173|      0|		}
 1174|       |
 1175|    106|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1175:12): [True: 96, False: 10]
  ------------------
 1176|     96|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1177|       |
 1178|     10|		p15card->tokeninfo->serial_number = serial;
 1179|     10|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1180|     10|	}
 1181|       |
 1182|    131|	ok = 1;
 1183|  11.7k|end:
 1184|  11.7k|	if (buf != NULL)
  ------------------
  |  Branch (1184:6): [True: 662, False: 11.0k]
  ------------------
 1185|    662|		free(buf);
 1186|  11.7k|	if (!ok) {
  ------------------
  |  Branch (1186:6): [True: 11.6k, False: 131]
  ------------------
 1187|  11.6k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  11.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.6k|	int _ret = r; \
  |  |  |  |  155|  11.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.0k, False: 529]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.6k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  11.6k|	return _ret; \
  |  |  |  |  163|  11.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1188|  11.6k|	}
 1189|       |
 1190|    131|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    131|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    131|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    131|	int _ret = r; \
  |  |  |  |  155|    131|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 131, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    131|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 131]
  |  |  |  |  ------------------
  |  |  |  |  157|    131|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    131|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    131|	return _ret; \
  |  |  |  |  163|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1191|    131|}
sc_pkcs15_bind_internal:
 1195|  12.4k|{
 1196|  12.4k|	struct sc_card *card = p15card->card;
 1197|  12.4k|	struct sc_context *ctx = card->ctx;
 1198|  12.4k|	const struct sc_app_info *info = NULL;
 1199|  12.4k|	int err, ok = 0;
 1200|       |
 1201|  12.4k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1202|       |	/* Enumerate apps now */
 1203|  12.4k|	if (card->app_count < 0) {
  ------------------
  |  Branch (1203:6): [True: 297, False: 12.1k]
  ------------------
 1204|    297|		err = sc_enum_apps(card);
 1205|    297|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|    297|#define SC_SUCCESS				0
  ------------------
  |  Branch (1205:7): [True: 285, False: 12]
  ------------------
 1206|    285|			sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(err));
  ------------------
  |  |   71|    285|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1207|    297|	}
 1208|  12.4k|	sc_file_free(p15card->file_app);
 1209|  12.4k|	p15card->file_app = sc_file_new();
 1210|  12.4k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (1210:6): [True: 0, False: 12.4k]
  ------------------
 1211|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1212|      0|		goto end;
 1213|      0|	}
 1214|       |
 1215|  12.4k|	sc_format_path("3F005015", &p15card->file_app->path);
 1216|       |
 1217|  12.4k|	info = sc_find_app(card, aid);
 1218|  12.4k|	if (info) {
  ------------------
  |  Branch (1218:6): [True: 525, False: 11.9k]
  ------------------
 1219|    525|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|    525|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1220|    525|		sc_pkcs15_free_app(p15card);
 1221|    525|		p15card->app = sc_dup_app_info(info);
 1222|    525|		if (!p15card->app) {
  ------------------
  |  Branch (1222:7): [True: 0, False: 525]
  ------------------
 1223|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1224|      0|			goto end;
 1225|      0|		}
 1226|       |
 1227|    525|		if (info->path.len)
  ------------------
  |  Branch (1227:7): [True: 416, False: 109]
  ------------------
 1228|    416|			p15card->file_app->path = info->path;
 1229|       |
 1230|    525|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1230:7): [True: 107, False: 418]
  |  Branch (1230:26): [True: 97, False: 10]
  ------------------
 1231|     97|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1232|       |
 1233|  11.9k|	} else if (aid) {
  ------------------
  |  Branch (1233:13): [True: 276, False: 11.6k]
  ------------------
 1234|    276|		sc_log(ctx, "Application '%s' not found", sc_dump_hex(aid->value, aid->len));
  ------------------
  |  |   71|    276|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1235|    276|		err = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    276|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1236|    276|		goto end;
 1237|    276|	}
 1238|  12.1k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   71|  12.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1239|       |
 1240|       |	/* Check if pkcs15 directory exists */
 1241|  12.1k|	err = sc_select_file(card, &p15card->file_app->path, NULL);
 1242|       |
 1243|       |	/* If the above test failed on cards without EF(DIR),
 1244|       |	 * try to continue read ODF from 3F005031. -aet
 1245|       |	 */
 1246|  12.1k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  12.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1246:6): [True: 10.1k, False: 1.98k]
  |  Branch (1246:29): [True: 9.75k, False: 414]
  ------------------
 1247|  9.75k|		sc_format_path("3F00", &p15card->file_app->path);
 1248|  9.75k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  9.75k|#define SC_SUCCESS				0
  ------------------
 1249|  9.75k|	}
 1250|       |
 1251|  12.1k|	if (err < 0) {
  ------------------
  |  Branch (1251:6): [True: 414, False: 11.7k]
  ------------------
 1252|    414|		sc_log(ctx, "Cannot select application path");
  ------------------
  |  |   71|    414|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1253|    414|		goto end;
 1254|    414|	}
 1255|       |
 1256|  11.7k|	err = sc_pkcs15_bind_internal_tokeninfo(p15card);
 1257|  11.7k|	if (err < 0) {
  ------------------
  |  Branch (1257:6): [True: 11.0k, False: 660]
  ------------------
 1258|  11.0k|		sc_log(ctx, "Cannot bind tokeninfo");
  ------------------
  |  |   71|  11.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1259|  11.0k|		goto end;
 1260|  11.0k|	}
 1261|       |
 1262|    660|	err = sc_pkcs15_bind_internal_odf(p15card);
 1263|    660|	if (err < 0) {
  ------------------
  |  Branch (1263:6): [True: 420, False: 240]
  ------------------
 1264|    420|		sc_log(ctx, "Cannot bind ODF");
  ------------------
  |  |   71|    420|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1265|    420|		goto end;
 1266|    420|	}
 1267|       |
 1268|    240|	ok = 1;
 1269|  12.4k|end:
 1270|  12.4k|	if (!ok) {
  ------------------
  |  Branch (1270:6): [True: 12.1k, False: 240]
  ------------------
 1271|  12.1k|		sc_pkcs15_card_clear(p15card);
 1272|  12.1k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  12.1k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1272:7): [True: 1.85k, False: 10.3k]
  ------------------
 1273|  1.85k|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.85k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1274|  12.1k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  12.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.1k|	int _ret = r; \
  |  |  |  |  155|  12.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.1k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.1k|	return _ret; \
  |  |  |  |  163|  12.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1275|  12.1k|	}
 1276|       |
 1277|    240|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    240|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    240|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    240|	int _ret = r; \
  |  |  |  |  155|    240|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 240]
  |  |  |  |  ------------------
  |  |  |  |  157|    240|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    240|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    240|	return _ret; \
  |  |  |  |  163|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1278|    240|}
pkcs15_get_default_use_file_cache:
 1281|  11.9k|{
 1282|       |	/* enable file caching by default for cards with static content to avoid
 1283|       |	 * synchronization problems.
 1284|       |	 *
 1285|       |	 * The following list was initialized with the cards that can't be modified
 1286|       |	 * with OpenSC i.e. which don't have a profile/driver for pkcs15-init. */
 1287|  11.9k|	const char *card_drivers_with_file_cache[] = {
 1288|  11.9k|			"atrust-acos",
 1289|  11.9k|			"belpic",
 1290|  11.9k|			"cac1",
 1291|  11.9k|			"cac",
 1292|  11.9k|			"cedulauy",
 1293|  11.9k|			"coolkey",
 1294|  11.9k|			"edo",
 1295|  11.9k|			"esteid2018",
 1296|  11.9k|			"esteid2025",
 1297|  11.9k|			"flex",
 1298|  11.9k|			"cyberflex",
 1299|  11.9k|			"gemsafeV1",
 1300|  11.9k|			"idprime",
 1301|  11.9k|			"itacns",
 1302|  11.9k|			"jpki",
 1303|  11.9k|			"MaskTech",
 1304|  11.9k|			"mcrd",
 1305|  11.9k|			"myeid",
 1306|  11.9k|			"npa",
 1307|  11.9k|			"nqapplet",
 1308|  11.9k|			"tcos",
 1309|  11.9k|			"dtrust",
 1310|  11.9k|			"lteid",
 1311|  11.9k|	};
 1312|       |
 1313|  11.9k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1313:6): [True: 0, False: 11.9k]
  |  Branch (1313:22): [True: 0, False: 11.9k]
  |  Branch (1313:46): [True: 0, False: 11.9k]
  ------------------
 1314|      0|		return "no";
 1315|   224k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1315:21): [True: 216k, False: 7.34k]
  ------------------
 1316|   216k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1316:7): [True: 4.57k, False: 212k]
  ------------------
 1317|  4.57k|			return "public";
 1318|   216k|	}
 1319|       |
 1320|  7.34k|	return "no";
 1321|  11.9k|}
sc_pkcs15_bind:
 1326|  11.9k|{
 1327|  11.9k|	struct sc_pkcs15_card *p15card = NULL;
 1328|  11.9k|	struct sc_context *ctx;
 1329|  11.9k|	scconf_block *conf_block = NULL;
 1330|  11.9k|	int r, emu_first, enable_emu;
 1331|  11.9k|	const char *use_file_cache;
 1332|  11.9k|	const char *pin_protected_certificate, *private_certificate;
 1333|       |
 1334|  11.9k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1334:6): [True: 0, False: 11.9k]
  |  Branch (1334:22): [True: 0, False: 11.9k]
  ------------------
 1335|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1336|      0|	}
 1337|  11.9k|	ctx = card->ctx;
 1338|       |
 1339|  11.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1340|  11.9k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   71|  23.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 311, False: 11.6k]
  |  |  ------------------
  ------------------
 1341|       |
 1342|  11.9k|	p15card = sc_pkcs15_card_new();
 1343|  11.9k|	if (p15card == NULL)
  ------------------
  |  Branch (1343:6): [True: 0, False: 11.9k]
  ------------------
 1344|  11.9k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1345|       |
 1346|  11.9k|	p15card->card = card;
 1347|  11.9k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  11.9k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1348|  11.9k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1349|  11.9k|	p15card->opts.use_pin_cache = 1;
 1350|  11.9k|	p15card->opts.pin_cache_counter = 10;
 1351|  11.9k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1352|  11.9k|	pin_protected_certificate = "protect";
 1353|  11.9k|	private_certificate = "";
 1354|       |
 1355|  11.9k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1356|  11.9k|	if (conf_block) {
  ------------------
  |  Branch (1356:6): [True: 0, False: 11.9k]
  ------------------
 1357|      0|		use_file_cache = scconf_get_str(conf_block, "use_file_caching", use_file_cache);
 1358|      0|		p15card->opts.use_pin_cache = scconf_get_bool(conf_block, "use_pin_caching", p15card->opts.use_pin_cache);
 1359|      0|		p15card->opts.pin_cache_counter = scconf_get_int(conf_block, "pin_cache_counter", p15card->opts.pin_cache_counter);
 1360|      0|		p15card->opts.pin_cache_ignore_user_consent = scconf_get_bool(conf_block, "pin_cache_ignore_user_consent",
 1361|      0|				p15card->opts.pin_cache_ignore_user_consent);
 1362|      0|		pin_protected_certificate = scconf_get_str(conf_block, "pin_protected_certificate", pin_protected_certificate);
 1363|       |		/* read also the old value to keep backward compatibility */
 1364|      0|		private_certificate = scconf_get_str(conf_block, "private_certificate", private_certificate);
 1365|      0|	}
 1366|       |
 1367|  11.9k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1367:6): [True: 0, False: 11.9k]
  ------------------
 1368|      0|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_ALL_FILES;
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
 1369|  11.9k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1369:13): [True: 4.57k, False: 7.34k]
  ------------------
 1370|  4.57k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  4.57k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1371|  7.34k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1371:13): [True: 7.34k, False: 0]
  ------------------
 1372|  7.34k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  7.34k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1373|  7.34k|	}
 1374|       |
 1375|  11.9k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1375:6): [True: 11.9k, False: 0]
  ------------------
 1376|  11.9k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  11.9k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1377|  11.9k|	} else if (0 == strcmp(pin_protected_certificate, "ignore")) {
  ------------------
  |  Branch (1377:13): [True: 0, False: 0]
  ------------------
 1378|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1379|      0|	} else if (0 == strcmp(pin_protected_certificate, "declassify")) {
  ------------------
  |  Branch (1379:13): [True: 0, False: 0]
  ------------------
 1380|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1381|      0|	}
 1382|       |	/* overwrite pin_protected_certificate when private_certificate set */
 1383|  11.9k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1383:6): [True: 0, False: 11.9k]
  ------------------
 1384|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1385|  11.9k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1385:13): [True: 0, False: 11.9k]
  ------------------
 1386|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1387|  11.9k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1387:13): [True: 0, False: 11.9k]
  ------------------
 1388|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1389|      0|	}
 1390|  11.9k|	sc_log(ctx, "PKCS#15 options: use_file_cache=%d use_pin_cache=%d pin_cache_counter=%d pin_cache_ignore_user_consent=%d pin_protected_certificate=%d",
  ------------------
  |  |   71|  11.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1391|  11.9k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1392|  11.9k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1393|       |
 1394|  11.9k|	r = sc_lock(card);
 1395|  11.9k|	if (r) {
  ------------------
  |  Branch (1395:6): [True: 0, False: 11.9k]
  ------------------
 1396|      0|		sc_log(ctx, "sc_lock() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1397|      0|		sc_pkcs15_card_free(p15card);
 1398|      0|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1399|      0|	}
 1400|       |
 1401|  11.9k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1402|  11.9k|	if (enable_emu) {
  ------------------
  |  Branch (1402:6): [True: 11.9k, False: 0]
  ------------------
 1403|  11.9k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  11.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1404|  11.9k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1405|  11.9k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1405:7): [True: 0, False: 11.9k]
  |  Branch (1405:20): [True: 1.81k, False: 10.1k]
  ------------------
 1406|  1.81k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1407|  1.81k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  1.81k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1407:8): [True: 512, False: 1.30k]
  ------------------
 1408|    512|				goto done;
 1409|  1.30k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1410|  1.30k|			if (r < 0)
  ------------------
  |  Branch (1410:8): [True: 1.23k, False: 71]
  ------------------
 1411|  1.23k|				goto error;
 1412|  10.1k|		} else {
 1413|  10.1k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1414|  10.1k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  10.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1414:8): [True: 164, False: 9.94k]
  ------------------
 1415|    164|				goto done;
 1416|  9.94k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1417|  9.94k|			if (r < 0)
  ------------------
  |  Branch (1417:8): [True: 6.15k, False: 3.78k]
  ------------------
 1418|  6.15k|				goto error;
 1419|  9.94k|		}
 1420|  11.9k|	}
 1421|      0|	else {
 1422|      0|		r = sc_pkcs15_bind_internal(p15card, aid);
 1423|      0|		if (r < 0)
  ------------------
  |  Branch (1423:7): [True: 0, False: 0]
  ------------------
 1424|      0|			goto error;
 1425|      0|	}
 1426|  4.53k|done:
 1427|  4.53k|	*p15card_out = p15card;
 1428|  4.53k|	sc_unlock(card);
 1429|  4.53k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  4.53k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.53k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.53k|	int _ret = r; \
  |  |  |  |  155|  4.53k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.53k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.53k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.53k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.53k|	return _ret; \
  |  |  |  |  163|  4.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|  7.38k|error:
 1431|  7.38k|	sc_unlock(card);
 1432|  7.38k|	sc_pkcs15_card_free(p15card);
 1433|  7.38k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  7.38k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.38k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.38k|	int _ret = r; \
  |  |  |  |  155|  7.38k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.38k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.38k|	return _ret; \
  |  |  |  |  163|  7.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1434|  7.38k|}
sc_pkcs15_unbind:
 1439|  4.53k|{
 1440|  4.53k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC) {
  ------------------
  |  |  519|  4.53k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (1440:6): [True: 0, False: 4.53k]
  |  Branch (1440:25): [True: 0, False: 4.53k]
  ------------------
 1441|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1442|      0|	}
 1443|       |
 1444|  4.53k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  4.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1445|  4.53k|	if (p15card->dll_handle)
  ------------------
  |  Branch (1445:6): [True: 0, False: 4.53k]
  ------------------
 1446|      0|		sc_dlclose(p15card->dll_handle);
 1447|  4.53k|	sc_pkcs15_pincache_clear(p15card);
 1448|  4.53k|	sc_pkcs15_card_free(p15card);
 1449|  4.53k|	return 0;
 1450|  4.53k|}
sc_pkcs15_get_objects:
 1538|  4.72k|{
 1539|  4.72k|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1540|  4.72k|}
sc_pkcs15_get_objects_cond:
 1734|  9.24k|{
 1735|  9.24k|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1736|  9.24k|			func, func_arg, ret, ret_size);
 1737|  9.24k|}
sc_pkcs15_find_object_by_id:
 1743|  1.73k|{
 1744|  1.73k|	struct sc_pkcs15_search_key sk;
 1745|  1.73k|	int	r;
 1746|       |
 1747|  1.73k|	memset(&sk, 0, sizeof(sk));
 1748|  1.73k|	sk.id = id;
 1749|       |
 1750|  1.73k|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1751|  1.73k|	if (r < 0)
  ------------------
  |  Branch (1751:6): [True: 0, False: 1.73k]
  ------------------
 1752|      0|		return r;
 1753|  1.73k|	if (r == 0)
  ------------------
  |  Branch (1753:6): [True: 838, False: 898]
  ------------------
 1754|    838|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    838|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1755|    898|	return 0;
 1756|  1.73k|}
sc_pkcs15_find_cert_by_id:
 1762|    962|{
 1763|    962|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|    962|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1764|    962|}
sc_pkcs15_find_pin_by_auth_id:
 1794|    774|{
 1795|    774|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|    774|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1796|    774|}
sc_pkcs15_find_prkey_by_id_usage:
 1957|  4.52k|{
 1958|  4.52k|	struct sc_pkcs15_search_key sk;
 1959|       |
 1960|  4.52k|	memset(&sk, 0, sizeof(sk));
 1961|  4.52k|	sk.usage_mask = sk.usage_value = usage;
 1962|  4.52k|	sk.id = id;
 1963|       |
 1964|  4.52k|	return find_by_key(p15card, SC_PKCS15_TYPE_PRKEY, &sk, out);
  ------------------
  |  |  418|  4.52k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
 1965|  4.52k|}
sc_pkcs15_add_object:
 1986|  28.4k|{
 1987|  28.4k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1988|       |
 1989|  28.4k|	if (!obj)
  ------------------
  |  Branch (1989:6): [True: 0, False: 28.4k]
  ------------------
 1990|      0|		return 0;
 1991|  28.4k|	obj->next = obj->prev = NULL;
 1992|  28.4k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1992:6): [True: 4.33k, False: 24.0k]
  ------------------
 1993|  4.33k|		p15card->obj_list = obj;
 1994|  4.33k|		return 0;
 1995|  4.33k|	}
 1996|   207k|	while (p->next != NULL)
  ------------------
  |  Branch (1996:9): [True: 183k, False: 24.0k]
  ------------------
 1997|   183k|		p = p->next;
 1998|  24.0k|	p->next = obj;
 1999|  24.0k|	obj->prev = p;
 2000|       |
 2001|  24.0k|	return 0;
 2002|  28.4k|}
sc_pkcs15_remove_object:
 2007|      3|{
 2008|      3|	if (!obj)
  ------------------
  |  Branch (2008:6): [True: 0, False: 3]
  ------------------
 2009|      0|		return;
 2010|      3|	else if (obj->prev == NULL)
  ------------------
  |  Branch (2010:11): [True: 3, False: 0]
  ------------------
 2011|      3|		p15card->obj_list = obj->next;
 2012|      0|	else
 2013|      0|		obj->prev->next = obj->next;
 2014|      3|	if (obj->next != NULL)
  ------------------
  |  Branch (2014:6): [True: 0, False: 3]
  ------------------
 2015|      0|		obj->next->prev = obj->prev;
 2016|      3|}
sc_pkcs15_free_object:
 2037|  28.4k|{
 2038|  28.4k|	if (!obj)
  ------------------
  |  Branch (2038:6): [True: 0, False: 28.4k]
  ------------------
 2039|      0|		return;
 2040|  28.4k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  28.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 2041|  2.03k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  2.03k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2041:2): [True: 2.03k, False: 26.3k]
  ------------------
 2042|  2.03k|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 2043|  2.03k|		break;
 2044|    457|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    457|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2044:2): [True: 457, False: 27.9k]
  ------------------
 2045|       |		/* This is normally passed to framework-pkcs15,
 2046|       |		 * but if something fails on the way, it would not get freed */
 2047|    457|		if (obj->emulated) {
  ------------------
  |  Branch (2047:7): [True: 352, False: 105]
  ------------------
 2048|    352|			sc_pkcs15_free_pubkey(obj->emulated);
 2049|    352|		}
 2050|    457|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 2051|    457|		break;
 2052|  1.12k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.12k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (2052:2): [True: 1.12k, False: 27.3k]
  ------------------
 2053|  1.12k|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 2054|  1.12k|		break;
 2055|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2055:2): [True: 0, False: 28.4k]
  ------------------
 2056|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2057|      0|		break;
 2058|  19.0k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  19.0k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2058:2): [True: 19.0k, False: 9.33k]
  ------------------
 2059|  19.0k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2060|  19.0k|		break;
 2061|  5.71k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  5.71k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2061:2): [True: 5.71k, False: 22.7k]
  ------------------
 2062|  5.71k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2063|  5.71k|		break;
 2064|      0|	default:
  ------------------
  |  Branch (2064:2): [True: 0, False: 28.4k]
  ------------------
 2065|      0|		free(obj->data);
 2066|  28.4k|	}
 2067|       |
 2068|  28.4k|	sc_pkcs15_free_object_content(obj);
 2069|       |
 2070|  28.4k|	free(obj);
 2071|  28.4k|}
sc_pkcs15_add_df:
 2076|  8.40k|{
 2077|  8.40k|	struct sc_pkcs15_df *p, *newdf;
 2078|       |
 2079|  8.40k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2080|  8.40k|	if (newdf == NULL)
  ------------------
  |  Branch (2080:6): [True: 0, False: 8.40k]
  ------------------
 2081|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2082|  8.40k|	newdf->path = *path;
 2083|  8.40k|	newdf->type = type;
 2084|       |
 2085|  8.40k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2085:6): [True: 4.44k, False: 3.95k]
  ------------------
 2086|  4.44k|		p15card->df_list = newdf;
 2087|  4.44k|		return 0;
 2088|  4.44k|	}
 2089|       |
 2090|  3.95k|	p = p15card->df_list;
 2091|  7.65k|	while (p->next != NULL)
  ------------------
  |  Branch (2091:9): [True: 3.70k, False: 3.95k]
  ------------------
 2092|  3.70k|		p = p->next;
 2093|  3.95k|	p->next = newdf;
 2094|  3.95k|	newdf->prev = p;
 2095|       |
 2096|  3.95k|	return 0;
 2097|  8.40k|}
sc_pkcs15_parse_df:
 2192|    835|{
 2193|    835|	struct sc_context *ctx = p15card->card->ctx;
 2194|    835|	unsigned char *buf;
 2195|    835|	const unsigned char *p;
 2196|    835|	size_t bufsize;
 2197|    835|	int r;
 2198|    835|	struct sc_pkcs15_object *obj = NULL;
 2199|    835|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2200|    835|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2201|       |
 2202|    835|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|    835|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2203|       |
 2204|    835|	if (df->enumerated)
  ------------------
  |  Branch (2204:6): [True: 0, False: 835]
  ------------------
 2205|    835|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2206|       |
 2207|    835|	switch (df->type) {
  ------------------
  |  Branch (2207:10): [True: 835, False: 0]
  ------------------
 2208|    272|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|    272|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2208:2): [True: 272, False: 563]
  ------------------
 2209|    272|		func = sc_pkcs15_decode_prkdf_entry;
 2210|    272|		break;
 2211|     63|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|     63|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2211:2): [True: 63, False: 772]
  ------------------
 2212|     63|		func = sc_pkcs15_decode_pukdf_entry;
 2213|     63|		break;
 2214|      0|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2214:2): [True: 0, False: 835]
  ------------------
 2215|      0|		func = sc_pkcs15_decode_skdf_entry;
 2216|      0|		break;
 2217|    100|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|    100|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2217:2): [True: 100, False: 735]
  ------------------
 2218|    100|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|    100|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2218:2): [True: 0, False: 835]
  ------------------
 2219|    100|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|    100|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2219:2): [True: 0, False: 835]
  ------------------
 2220|    100|		func = sc_pkcs15_decode_cdf_entry;
 2221|    100|		break;
 2222|     21|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|     21|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2222:2): [True: 21, False: 814]
  ------------------
 2223|     21|		func = sc_pkcs15_decode_dodf_entry;
 2224|     21|		break;
 2225|    379|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|    379|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2225:2): [True: 379, False: 456]
  ------------------
 2226|    379|		func = sc_pkcs15_decode_aodf_entry;
 2227|    379|		break;
 2228|    835|	}
 2229|    835|	if (func == NULL) {
  ------------------
  |  Branch (2229:6): [True: 0, False: 835]
  ------------------
 2230|      0|		sc_log(ctx, "unknown DF type: %d", df->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2231|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2232|      0|	}
 2233|    835|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2234|    835|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|    835|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    835|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    835|	int _ret = (r); \
  |  |  |  |  168|    835|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 611, False: 224]
  |  |  |  |  ------------------
  |  |  |  |  169|    611|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    611|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    611|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    611|		return _ret; \
  |  |  |  |  172|    611|	} \
  |  |  |  |  173|    835|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 224]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2235|       |
 2236|    224|	p = buf;
 2237|    365|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2237:9): [True: 327, False: 38]
  |  Branch (2237:20): [True: 318, False: 9]
  ------------------
 2238|       |
 2239|    318|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2240|    318|		if (obj == NULL) {
  ------------------
  |  Branch (2240:7): [True: 0, False: 318]
  ------------------
 2241|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2242|      0|			goto ret;
 2243|      0|		}
 2244|    318|		r = func(p15card, obj, &p, &bufsize);
 2245|    318|		if (r) {
  ------------------
  |  Branch (2245:7): [True: 177, False: 141]
  ------------------
 2246|    177|			free(obj);
 2247|    177|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|    177|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2247:8): [True: 28, False: 149]
  ------------------
 2248|     28|				r = 0;
 2249|     28|				break;
 2250|     28|			}
 2251|    149|			sc_log(ctx, "%s: Error decoding DF entry", sc_strerror(r));
  ------------------
  |  |   71|    149|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2252|    149|			goto ret;
 2253|    177|		}
 2254|       |
 2255|    141|		obj->df = df;
 2256|    141|		r = sc_pkcs15_add_object(p15card, obj);
 2257|    141|		if (r) {
  ------------------
  |  Branch (2257:7): [True: 0, False: 141]
  ------------------
 2258|      0|			if (obj->data)
  ------------------
  |  Branch (2258:8): [True: 0, False: 0]
  ------------------
 2259|      0|				free(obj->data);
 2260|      0|			free(obj);
 2261|      0|			sc_log(ctx, "%s: Error adding object", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2262|      0|			goto ret;
 2263|      0|		}
 2264|    469|		while (bufsize > 0 && *p == 00) {
  ------------------
  |  Branch (2264:10): [True: 453, False: 16]
  |  Branch (2264:25): [True: 328, False: 125]
  ------------------
 2265|    328|			bufsize--;
 2266|    328|			p++;
 2267|    328|		}
 2268|    141|	};
 2269|       |
 2270|     75|	if (r > 0)
  ------------------
  |  Branch (2270:6): [True: 0, False: 75]
  ------------------
 2271|      0|		r = 0;
 2272|    224|ret:
 2273|    224|	df->enumerated = 1;
 2274|    224|	free(buf);
 2275|    224|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    224|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    224|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    224|	int _ret = r; \
  |  |  |  |  155|    224|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 224, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    224|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    149|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 149, False: 75]
  |  |  |  |  ------------------
  |  |  |  |  157|    224|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    224|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    224|	return _ret; \
  |  |  |  |  163|    224|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|    224|}
sc_pkcs15_read_file:
 2528|  12.1k|{
 2529|  12.1k|	struct sc_context *ctx;
 2530|  12.1k|	struct sc_file *file = NULL;
 2531|  12.1k|	unsigned char *data = NULL;
 2532|  12.1k|	size_t	len = 0, offset = 0;
 2533|  12.1k|	int	r;
 2534|       |
 2535|  12.1k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2535:6): [True: 0, False: 12.1k]
  |  Branch (2535:25): [True: 0, False: 12.1k]
  |  Branch (2535:50): [True: 0, False: 12.1k]
  |  Branch (2535:69): [True: 0, False: 12.1k]
  ------------------
 2536|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2537|      0|	}
 2538|  12.1k|	ctx = p15card->card->ctx;
 2539|       |
 2540|  12.1k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2541|  12.1k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   71|  12.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2542|       |
 2543|  12.1k|	r = -1; /* file state: not in cache */
 2544|  12.1k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2544:6): [True: 6.34k, False: 5.79k]
  ------------------
 2545|  6.34k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  6.34k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2545:10): [True: 0, False: 6.34k]
  |  Branch (2545:77): [True: 6.34k, False: 0]
  ------------------
 2546|  6.34k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2547|       |
 2548|  6.34k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2548:7): [True: 0, False: 6.34k]
  |  Branch (2548:13): [True: 0, False: 0]
  |  Branch (2548:37): [True: 0, False: 0]
  ------------------
 2549|      0|			struct sc_path parent = *in_path;
 2550|       |
 2551|      0|			parent.len -= 2;
 2552|      0|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|      0|#define SC_PATH_TYPE_PATH		2
  ------------------
 2553|      0|			r = sc_select_file(p15card->card, &parent, NULL);
 2554|      0|		}
 2555|  6.34k|	}
 2556|       |
 2557|  12.1k|	if (r) {
  ------------------
  |  Branch (2557:6): [True: 12.1k, False: 0]
  ------------------
 2558|  12.1k|		r = sc_lock(p15card->card);
 2559|  12.1k|		if (r)
  ------------------
  |  Branch (2559:7): [True: 0, False: 12.1k]
  ------------------
 2560|      0|			goto fail;
 2561|  12.1k|		r = sc_select_file(p15card->card, in_path, &file);
 2562|  12.1k|		if (r)
  ------------------
  |  Branch (2562:7): [True: 9.53k, False: 2.61k]
  ------------------
 2563|  9.53k|			goto fail_unlock;
 2564|       |
 2565|       |		/* Handle the case where the ASN.1 Path object specified
 2566|       |		 * index and length values */
 2567|       |
 2568|  2.61k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  2.61k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2568:7): [True: 41, False: 2.57k]
  ------------------
 2569|       |
 2570|       |			// in_path->index: record_no
 2571|       |			// in_path->count: ignored!
 2572|       |
 2573|     41|			if(file->record_length > 0) {
  ------------------
  |  Branch (2573:7): [True: 38, False: 3]
  ------------------
 2574|     38|				if(file->record_length > MAX_FILE_SIZE) {
  ------------------
  |  |  220|     38|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2574:8): [True: 0, False: 38]
  ------------------
 2575|      0|					len = MAX_FILE_SIZE;
  ------------------
  |  |  220|      0|#define MAX_FILE_SIZE 65535
  ------------------
 2576|      0|					sc_log(ctx, "  record size truncated, encoded length: %zu", file->record_length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2577|     38|				} else {
 2578|     38|					len = file->record_length;
 2579|     38|				}
 2580|     38|			} else {
 2581|      3|				len = MAX_FILE_SIZE;
  ------------------
  |  |  220|      3|#define MAX_FILE_SIZE 65535
  ------------------
 2582|      3|			}
 2583|       |
 2584|     41|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2584:8): [True: 30, False: 11]
  |  Branch (2584:33): [True: 1, False: 10]
  ------------------
 2585|     31|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   71|     31|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2586|     31|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     31|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2587|     31|				goto fail_unlock;
 2588|     31|			}
 2589|       |
 2590|  2.57k|		} else {
 2591|       |
 2592|  2.57k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2592:8): [True: 1.10k, False: 1.46k]
  ------------------
 2593|  1.10k|				if (file->size)
  ------------------
  |  Branch (2593:9): [True: 804, False: 304]
  ------------------
 2594|    804|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|    804|#define MAX_FILE_SIZE 65535
  ------------------
              					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|      0|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2594:12): [True: 0, False: 804]
  ------------------
 2595|    304|				else
 2596|    304|					len = 1024;
 2597|  1.10k|				offset = 0;
 2598|  1.10k|			}
 2599|  1.46k|			else {
 2600|  1.46k|				offset = in_path->index;
 2601|  1.46k|				len = in_path->count;
 2602|       |				/* Make sure we're within proper bounds */
 2603|  1.46k|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2603:9): [True: 12, False: 1.45k]
  |  Branch (2603:33): [True: 10, False: 1.44k]
  ------------------
 2604|     22|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     22|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2605|     22|					goto fail_unlock;
 2606|     22|				}
 2607|  1.46k|			}
 2608|  2.57k|		}
 2609|       |
 2610|  2.55k|		free(data);
 2611|  2.55k|		data = malloc(len);
 2612|  2.55k|		if (data == NULL) {
  ------------------
  |  Branch (2612:7): [True: 0, False: 2.55k]
  ------------------
 2613|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2614|      0|			goto fail_unlock;
 2615|      0|		}
 2616|       |
 2617|  2.55k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE_TLV) {
  ------------------
  |  |  225|  2.55k|#define SC_FILE_EF_LINEAR_VARIABLE_TLV	0x05
  ------------------
  |  Branch (2617:7): [True: 52, False: 2.50k]
  ------------------
 2618|     52|			unsigned int i;
 2619|     52|			size_t l, record_len;
 2620|     52|			unsigned char *head = data;
 2621|       |
 2622|    621|			for (i=1; ; i++) {
 2623|    621|				l = len - (head - data);
 2624|    621|				if (l > 256) {
  ------------------
  |  Branch (2624:9): [True: 350, False: 271]
  ------------------
 2625|    350|					l = 256;
 2626|    350|				}
 2627|    621|				r = sc_read_record(p15card->card, i, 0, head, l, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|    621|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2628|    621|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|    621|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2628:9): [True: 1, False: 620]
  ------------------
 2629|      1|					break;
 2630|    620|				if (r < 0) {
  ------------------
  |  Branch (2630:9): [True: 48, False: 572]
  ------------------
 2631|     48|					goto fail_unlock;
 2632|     48|				}
 2633|    572|				if (r < 2)
  ------------------
  |  Branch (2633:9): [True: 2, False: 570]
  ------------------
 2634|      2|					break;
 2635|    570|				record_len = head[1];
 2636|    570|				if (record_len != 0xff) {
  ------------------
  |  Branch (2636:9): [True: 548, False: 22]
  ------------------
 2637|    548|					memmove(head, head+2, r-2);
 2638|    548|					head += (r-2);
 2639|    548|				}
 2640|     22|				else {
 2641|     22|					if (r < 4)
  ------------------
  |  Branch (2641:10): [True: 1, False: 21]
  ------------------
 2642|      1|						break;
 2643|     21|					memmove(head, head+4, r-4);
 2644|     21|					head += (r-4);
 2645|     21|				}
 2646|    570|			}
 2647|      4|			len = head-data;
 2648|      4|		}
 2649|  2.50k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  2.50k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2649:12): [True: 10, False: 2.49k]
  ------------------
 2650|     10|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|     10|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2651|     10|			if (r < 0) {
  ------------------
  |  Branch (2651:8): [True: 3, False: 7]
  ------------------
 2652|      3|				goto fail_unlock;
 2653|      3|			}
 2654|       |			/* sc_read_record may return less than requested */
 2655|      7|			len = r;
 2656|      7|		}
 2657|  2.49k|		else {
 2658|  2.49k|			unsigned long flags = 0;
 2659|  2.49k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2660|  2.49k|			if (r < 0) {
  ------------------
  |  Branch (2660:8): [True: 768, False: 1.72k]
  ------------------
 2661|    768|				goto fail_unlock;
 2662|    768|			}
 2663|       |			/* sc_read_binary may return less than requested */
 2664|  1.72k|			len = r;
 2665|       |
 2666|  1.72k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  3.45k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2666:8): [True: 308, False: 1.42k]
  ------------------
 2667|  1.42k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  3.15k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2667:11): [True: 0, False: 1.42k]
  ------------------
 2668|  1.42k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  1.42k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2668:11): [True: 0, False: 1.42k]
  ------------------
 2669|    308|				unsigned char *decompressed_buf = NULL;
 2670|    308|				size_t decompressed_len = 0;
 2671|    308|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2672|    308|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
  |  Branch (2672:9): [True: 240, False: 68]
  ------------------
 2673|    240|					goto fail_unlock;
 2674|    240|				}
 2675|     68|				free(data);
 2676|     68|				data = decompressed_buf;
 2677|     68|				len = decompressed_len;
 2678|     68|			}
 2679|  1.72k|		}
 2680|  1.50k|		sc_unlock(p15card->card);
 2681|       |
 2682|  1.50k|		sc_file_free(file);
 2683|       |
 2684|  1.50k|		if (p15card->opts.use_file_cache && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    892|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2684:7): [True: 892, False: 608]
  |  Branch (2684:40): [True: 0, False: 892]
  |  Branch (2684:107): [True: 892, False: 0]
  ------------------
 2685|    892|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2686|    892|		}
 2687|  1.50k|		if (len == 0) {
  ------------------
  |  Branch (2687:7): [True: 336, False: 1.16k]
  ------------------
 2688|    336|			free(data);
 2689|    336|			data = NULL;
 2690|    336|		}
 2691|  1.50k|	}
 2692|  1.50k|	*buf = data;
 2693|  1.50k|	*buflen = len;
 2694|  1.50k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.50k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.50k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.50k|	int _ret = r; \
  |  |  |  |  155|  1.50k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.50k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.50k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.50k|	return _ret; \
  |  |  |  |  163|  1.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2695|       |
 2696|  10.6k|fail_unlock:
 2697|  10.6k|	sc_unlock(p15card->card);
 2698|  10.6k|fail:
 2699|  10.6k|	free(data);
 2700|  10.6k|	sc_file_free(file);
 2701|  10.6k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  10.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.6k|	int _ret = r; \
  |  |  |  |  155|  10.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  10.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.6k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  10.6k|	return _ret; \
  |  |  |  |  163|  10.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2702|  10.6k|}
sc_pkcs15_compare_id:
 2707|  3.64k|{
 2708|  3.64k|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2708:6): [True: 0, False: 3.64k]
  |  Branch (2708:21): [True: 0, False: 3.64k]
  ------------------
 2709|      0|		return 0;
 2710|  3.64k|	if (id1->len != id2->len)
  ------------------
  |  Branch (2710:6): [True: 1.55k, False: 2.09k]
  ------------------
 2711|  1.55k|		return 0;
 2712|  2.09k|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2713|  3.64k|}
sc_pkcs15_format_id:
 2718|  94.2k|{
 2719|  94.2k|	size_t len;
 2720|       |
 2721|  94.2k|	if (!id)
  ------------------
  |  Branch (2721:6): [True: 0, False: 94.2k]
  ------------------
 2722|      0|		return;
 2723|  94.2k|	len = sizeof(id->value);
 2724|       |
 2725|  94.2k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  94.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2725:6): [True: 66, False: 94.2k]
  ------------------
 2726|     66|		id->len = 0;
 2727|  94.2k|	else
 2728|  94.2k|		id->len = len;
 2729|  94.2k|}
sc_pkcs15_print_id:
 2734|    405|{
 2735|    405|	static char buffer[256];
 2736|       |
 2737|    405|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2738|    405|	return buffer;
 2739|    405|}
sc_pkcs15_hex_string_to_id:
 2744|     31|{
 2745|     31|	out->len = sizeof(out->value);
 2746|     31|	return sc_hex_to_bin(in, out->value, &out->len);
 2747|     31|}
sc_pkcs15_make_absolute_path:
 2752|  13.2k|{
 2753|       |	/* nothing to do if child has valid 'aid' */
 2754|  13.2k|	if (child->aid.len)
  ------------------
  |  Branch (2754:6): [True: 0, False: 13.2k]
  ------------------
 2755|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2756|       |
 2757|  13.2k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2757:6): [True: 0, False: 13.2k]
  ------------------
 2758|      0|		sc_path_t ppath;
 2759|       |
 2760|       |		/* child inherits parent's 'aid' */
 2761|      0|		child->aid = parent->aid;
 2762|      0|		if (!parent->len)
  ------------------
  |  Branch (2762:7): [True: 0, False: 0]
  ------------------
 2763|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2764|       |
 2765|       |		/* parent has valid 'path' -- concatenate it with the child's one */
 2766|      0|		memcpy(&ppath, parent, sizeof(sc_path_t));
 2767|      0|		ppath.aid.len = 0;
 2768|      0|		ppath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 2769|      0|		return sc_concatenate_path(child, &ppath, child);
 2770|       |
 2771|      0|	}
 2772|  13.2k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  13.2k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2772:11): [True: 80, False: 13.1k]
  ------------------
 2773|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2774|     80|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2774:7): [True: 0, False: 80]
  ------------------
 2775|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2776|       |
 2777|     80|		memcpy(child->aid.value, parent->value, parent->len);
 2778|     80|		child->aid.len = parent->len;
 2779|       |
 2780|     80|		return SC_SUCCESS;
  ------------------
  |  |   28|     80|#define SC_SUCCESS				0
  ------------------
 2781|     80|	}
 2782|       |
 2783|       |	/* a 0 length path stays a 0 length path */
 2784|  13.1k|	if (child->len == 0)
  ------------------
  |  Branch (2784:6): [True: 110, False: 13.0k]
  ------------------
 2785|    110|		return SC_SUCCESS;
  ------------------
  |  |   28|    110|#define SC_SUCCESS				0
  ------------------
 2786|       |
 2787|  13.0k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2787:6): [True: 112, False: 12.9k]
  ------------------
 2788|    112|		return SC_SUCCESS;
  ------------------
  |  |   28|    112|#define SC_SUCCESS				0
  ------------------
 2789|       |
 2790|  12.9k|	return sc_concatenate_path(child, parent, child);
 2791|  13.0k|}
sc_pkcs15_free_object_content:
 2795|  33.9k|{
 2796|  33.9k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2796:6): [True: 393, False: 33.5k]
  |  Branch (2796:28): [True: 393, False: 0]
  ------------------
 2797|    393|		if (obj->content_free) {
  ------------------
  |  Branch (2797:7): [True: 393, False: 0]
  ------------------
 2798|    393|			obj->content_free(obj->content.value, obj->content.len);
 2799|    393|		} else {
 2800|      0|			free(obj->content.value);
 2801|      0|		}
 2802|    393|	}
 2803|       |	obj->content.value = NULL;
 2804|  33.9k|	obj->content.len = 0;
 2805|  33.9k|}
sc_pkcs15_allocate_object_content:
 2811|    393|{
 2812|    393|	unsigned char *tmp_buf;
 2813|       |
 2814|    393|	if (!obj)
  ------------------
  |  Branch (2814:6): [True: 0, False: 393]
  ------------------
 2815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2816|       |
 2817|    393|	if (!value || !len)   {
  ------------------
  |  Branch (2817:6): [True: 0, False: 393]
  |  Branch (2817:16): [True: 0, False: 393]
  ------------------
 2818|      0|		sc_pkcs15_free_object_content(obj);
 2819|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2820|      0|	}
 2821|       |
 2822|       |	/* Need to pass by temporary variable,
 2823|       |	 * because 'value' and 'content.value' pointers can be the sames.
 2824|       |	 */
 2825|    393|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|    393|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2825:6): [True: 393, False: 0]
  ------------------
 2826|      0|			|| SC_PKCS15_TYPE_SKEY & obj->type
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2826:7): [True: 0, False: 0]
  ------------------
 2827|    393|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2827:7): [True: 0, False: 0]
  ------------------
 2828|    393|		tmp_buf = sc_mem_secure_alloc(len);
 2829|    393|		obj->content_free = sc_mem_secure_free;
 2830|    393|	} else {
 2831|      0|		tmp_buf = malloc(len);
 2832|      0|	}
 2833|    393|	if (!tmp_buf)
  ------------------
  |  Branch (2833:6): [True: 0, False: 393]
  ------------------
 2834|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2835|       |
 2836|    393|	memcpy(tmp_buf, value, len);
 2837|       |
 2838|    393|	sc_pkcs15_free_object_content(obj);
 2839|       |
 2840|    393|	obj->content.value = tmp_buf;
 2841|    393|	obj->content.len = len;
 2842|       |
 2843|    393|	return SC_SUCCESS;
  ------------------
  |  |   28|    393|#define SC_SUCCESS				0
  ------------------
 2844|    393|}
sc_pkcs15_free_key_params:
 3137|  2.54k|{
 3138|  2.54k|	if (!params)
  ------------------
  |  Branch (3138:6): [True: 0, False: 2.54k]
  ------------------
 3139|      0|		return;
 3140|  2.54k|	if (params->data && params->free_params)
  ------------------
  |  Branch (3140:6): [True: 2, False: 2.54k]
  |  Branch (3140:22): [True: 0, False: 2]
  ------------------
 3141|      0|		params->free_params(params->data);
 3142|  2.54k|	else if (params->data)
  ------------------
  |  Branch (3142:11): [True: 2, False: 2.54k]
  ------------------
 3143|      2|		free(params->data);
 3144|       |
 3145|       |	params->data = NULL;
 3146|  2.54k|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  753|  20.8k|{
  754|  20.8k|	if (!tokeninfo)
  ------------------
  |  Branch (754:6): [True: 0, False: 20.8k]
  ------------------
  755|      0|		return;
  756|       |
  757|  20.8k|	free(tokeninfo->label);
  758|  20.8k|	tokeninfo->label = NULL;
  759|  20.8k|	free(tokeninfo->serial_number);
  760|  20.8k|	tokeninfo->serial_number = NULL;
  761|  20.8k|	free(tokeninfo->manufacturer_id);
  762|  20.8k|	tokeninfo->manufacturer_id = NULL;
  763|  20.8k|	free(tokeninfo->last_update.gtime);
  764|  20.8k|	tokeninfo->last_update.gtime = NULL;
  765|  20.8k|	free(tokeninfo->preferred_language);
  766|  20.8k|	tokeninfo->preferred_language = NULL;
  767|  20.8k|	free(tokeninfo->profile_indication.name);
  768|  20.8k|	tokeninfo->profile_indication.name = NULL;
  769|  20.8k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (769:6): [True: 7, False: 20.8k]
  ------------------
  770|      7|		unsigned i;
  771|     17|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (771:15): [True: 10, False: 7]
  ------------------
  772|     10|			free(tokeninfo->seInfo[i]);
  773|      7|		free(tokeninfo->seInfo);
  774|       |		tokeninfo->seInfo = NULL;
  775|      7|	}
  776|  20.8k|}
pkcs15.c:parse_odf:
  620|    181|{
  621|    181|	const unsigned char *p = buf;
  622|    181|	size_t left = buflen;
  623|    181|	int r, i, type;
  624|    181|	struct sc_path path;
  625|    181|	struct sc_asn1_entry asn1_obj_or_path[] = {
  626|    181|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  174|    181|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  141|    181|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  162|    181|#define SC_ASN1_SEQUENCE                16
  ------------------
  627|    181|		{ NULL, 0, 0, 0, NULL, NULL }
  628|    181|	};
  629|    181|	struct sc_asn1_entry asn1_odf[10];
  630|       |
  631|    181|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  632|  1.81k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (632:14): [True: 1.62k, False: 181]
  ------------------
  633|  1.62k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  634|    493|	while (left > 0) {
  ------------------
  |  Branch (634:9): [True: 466, False: 27]
  ------------------
  635|    466|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  636|    466|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    466|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (636:7): [True: 98, False: 368]
  ------------------
  637|     98|			break;
  638|    368|		if (r < 0)
  ------------------
  |  Branch (638:7): [True: 55, False: 313]
  ------------------
  639|     55|			return r;
  640|    313|		type = r;
  641|    313|		if (p15card->file_app) {
  ------------------
  |  Branch (641:7): [True: 313, False: 0]
  ------------------
  642|    313|			r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
  643|    313|			if (r < 0)
  ------------------
  |  Branch (643:8): [True: 1, False: 312]
  ------------------
  644|      1|				return r;
  645|    312|			r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  646|    312|			if (r)
  ------------------
  |  Branch (646:8): [True: 0, False: 312]
  ------------------
  647|      0|				return r;
  648|    312|		}
  649|    313|	}
  650|    125|	return 0;
  651|    181|}
pkcs15.c:sc_dup_app_info:
  907|    525|{
  908|    525|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  909|       |
  910|    525|	if (!out)
  ------------------
  |  Branch (910:6): [True: 0, False: 525]
  ------------------
  911|      0|		return NULL;
  912|       |
  913|    525|	memcpy(out, info, sizeof(struct sc_app_info));
  914|       |
  915|    525|	if (info->label) {
  ------------------
  |  Branch (915:6): [True: 11, False: 514]
  ------------------
  916|     11|		out->label = strdup(info->label);
  917|     11|		if (!out->label) {
  ------------------
  |  Branch (917:7): [True: 0, False: 11]
  ------------------
  918|      0|			free(out);
  919|      0|			return NULL;
  920|      0|		}
  921|     11|	} else
  922|    514|		out->label = NULL;
  923|       |
  924|    525|	out->ddo.value = malloc(info->ddo.len);
  925|    525|	if (!out->ddo.value) {
  ------------------
  |  Branch (925:6): [True: 0, False: 525]
  ------------------
  926|      0|		free(out->label);
  927|      0|		free(out);
  928|      0|		return NULL;
  929|      0|	}
  930|    525|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  931|    525|	out->ddo.len = info->ddo.len;
  932|       |
  933|    525|	return out;
  934|    525|}
pkcs15.c:parse_ddo:
  472|     97|{
  473|     97|	struct sc_context *ctx = p15card->card->ctx;
  474|     97|	struct sc_asn1_entry asn1_ddo[7];
  475|     97|	sc_path_t odf_path, ti_path, us_path;
  476|     97|	struct sc_iid iid;
  477|     97|	struct sc_aid aid;
  478|     97|	int r;
  479|       |
  480|     97|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     97|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     97|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     97|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     97|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|       |
  482|     97|	iid.len = sizeof(iid.value);
  483|     97|	aid.len = sizeof(aid.value);
  484|       |
  485|     97|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  486|     97|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  487|     97|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  488|     97|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  489|     97|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  490|     97|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  491|       |
  492|     97|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  493|     97|	LOG_TEST_RET(ctx, r, "DDO parsing failed");
  ------------------
  |  |  174|     97|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     97|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     97|	int _ret = (r); \
  |  |  |  |  168|     97|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 57, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  169|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     57|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     57|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     57|		return _ret; \
  |  |  |  |  172|     57|	} \
  |  |  |  |  173|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|       |
  495|     40|	if (asn1_ddo[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     40|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (495:6): [True: 7, False: 33]
  ------------------
  496|      7|		sc_file_free(p15card->file_odf);
  497|      7|		p15card->file_odf = sc_file_new();
  498|      7|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (498:7): [True: 0, False: 7]
  ------------------
  499|      0|			goto mem_err;
  500|      7|		p15card->file_odf->path = odf_path;
  501|      7|	}
  502|     40|	if (asn1_ddo[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     40|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (502:6): [True: 9, False: 31]
  ------------------
  503|      9|		sc_file_free(p15card->file_tokeninfo);
  504|      9|		p15card->file_tokeninfo = sc_file_new();
  505|      9|		if (p15card->file_tokeninfo == NULL)
  ------------------
  |  Branch (505:7): [True: 0, False: 9]
  ------------------
  506|      0|			goto mem_err;
  507|      9|		p15card->file_tokeninfo->path = ti_path;
  508|      9|	}
  509|     40|	if (asn1_ddo[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     40|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (509:6): [True: 3, False: 37]
  ------------------
  510|      3|		sc_file_free(p15card->file_unusedspace);
  511|      3|		p15card->file_unusedspace = sc_file_new();
  512|      3|		if (p15card->file_unusedspace == NULL)
  ------------------
  |  Branch (512:7): [True: 0, False: 3]
  ------------------
  513|      0|			goto mem_err;
  514|      3|		p15card->file_unusedspace->path = us_path;
  515|      3|	}
  516|     40|	if (asn1_ddo[4].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     40|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (516:6): [True: 3, False: 37]
  ------------------
  517|      3|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.IID '%s'", sc_dump_hex(iid.value, iid.len));
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  518|      3|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  519|      3|	}
  520|     40|	if (asn1_ddo[5].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     40|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (520:6): [True: 3, False: 37]
  ------------------
  521|      3|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.AID '%s'", sc_dump_hex(aid.value, aid.len));
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  522|      3|		memcpy(&p15card->app->ddo.aid, &aid, sizeof(struct sc_aid));
  523|      3|	}
  524|       |
  525|     40|	fix_authentic_ddo(p15card);
  526|     40|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     40|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     40|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     40|	int _ret = r; \
  |  |  |  |  155|     40|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 40, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  157|     40|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     40|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     40|	return _ret; \
  |  |  |  |  163|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  527|      0|mem_err:
  528|      0|	sc_file_free(p15card->file_odf);
  529|      0|	p15card->file_odf = NULL;
  530|      0|	sc_file_free(p15card->file_tokeninfo);
  531|      0|	p15card->file_tokeninfo = NULL;
  532|      0|	sc_file_free(p15card->file_unusedspace);
  533|      0|	p15card->file_unusedspace = NULL;
  534|      0|	LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|      0|}
pkcs15.c:fix_authentic_ddo:
  458|     40|{
  459|       |	/* AuthentIC v3.2 card has invalid ODF and tokenInfo paths encoded into DDO.
  460|       |	 * Cleanup this attributes -- default values must be OK.
  461|       |	 */
  462|     40|	if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)   {
  ------------------
  |  Branch (462:6): [True: 1, False: 39]
  ------------------
  463|      1|		sc_file_free(p15card->file_odf);
  464|      1|		p15card->file_odf = NULL;
  465|      1|		sc_file_free(p15card->file_tokeninfo);
  466|       |		p15card->file_tokeninfo = NULL;
  467|      1|	}
  468|     40|}
pkcs15.c:__sc_pkcs15_search_objects:
 1457|  10.9k|{
 1458|  10.9k|	struct sc_pkcs15_object *obj = NULL;
 1459|  10.9k|	struct sc_pkcs15_df	*df = NULL;
 1460|  10.9k|	unsigned int	df_mask = 0;
 1461|  10.9k|	size_t		match_count = 0;
 1462|  10.9k|	int r;
 1463|       |
 1464|  10.9k|	if (type)
  ------------------
  |  Branch (1464:6): [True: 10.9k, False: 0]
  ------------------
 1465|  10.9k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  10.9k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1466|       |
 1467|       |	/* Make sure the class mask we have makes sense */
 1468|  10.9k|	if (class_mask == 0
  ------------------
  |  Branch (1468:6): [True: 0, False: 10.9k]
  ------------------
 1469|  10.9k|			|| (class_mask & ~(
  ------------------
  |  Branch (1469:7): [True: 0, False: 10.9k]
  ------------------
 1470|  10.9k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  10.9k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1471|  10.9k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  10.9k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1472|  10.9k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  10.9k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1473|  10.9k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  10.9k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1474|  10.9k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  10.9k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1475|  10.9k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  10.9k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
 1476|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1477|      0|	}
 1478|       |
 1479|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  10.9k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1479:6): [True: 4.52k, False: 6.45k]
  ------------------
 1480|  4.52k|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|  4.52k|#define SC_PKCS15_PRKDF			0
  ------------------
 1481|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  10.9k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1481:6): [True: 0, False: 10.9k]
  ------------------
 1482|      0|		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
              		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  490|      0|#define SC_PKCS15_PUKDF_TRUSTED		2
  ------------------
 1483|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  10.9k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1483:6): [True: 962, False: 10.0k]
  ------------------
 1484|    962|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|    962|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|    962|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|    962|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1485|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  10.9k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1485:6): [True: 184, False: 10.8k]
  ------------------
 1486|    184|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|    184|#define SC_PKCS15_DODF			7
  ------------------
 1487|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  10.9k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1487:6): [True: 5.31k, False: 5.67k]
  ------------------
 1488|  5.31k|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|  5.31k|#define SC_PKCS15_AODF			8
  ------------------
 1489|  10.9k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  10.9k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1489:6): [True: 0, False: 10.9k]
  ------------------
 1490|      0|		df_mask |= (1 << SC_PKCS15_SKDF);
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
 1491|       |
 1492|       |	/* Make sure all the DFs we want to search have been
 1493|       |	 * enumerated. */
 1494|  30.7k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1494:30): [True: 19.7k, False: 10.9k]
  ------------------
 1495|  19.7k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1495:7): [True: 13.7k, False: 5.99k]
  ------------------
 1496|  13.7k|			continue;
 1497|  13.7k|		}
 1498|  5.99k|		if (df->enumerated)
  ------------------
  |  Branch (1498:7): [True: 5.58k, False: 402]
  ------------------
 1499|  5.58k|			continue;
 1500|       |		/* Enumerate the DF's, so p15card->obj_list is populated. */
 1501|    402|		if (p15card->ops.parse_df)
  ------------------
  |  Branch (1501:7): [True: 0, False: 402]
  ------------------
 1502|      0|			r = p15card->ops.parse_df(p15card, df);
 1503|    402|		else
 1504|    402|			r = sc_pkcs15_parse_df(p15card, df);
 1505|    402|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|    402|#define SC_SUCCESS				0
  ------------------
  |  Branch (1505:7): [True: 376, False: 26]
  ------------------
 1506|    376|			continue;
 1507|    402|	}
 1508|       |
 1509|       |	/* And now loop over all objects */
 1510|  72.0k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1510:32): [True: 62.8k, False: 9.23k]
  ------------------
 1511|       |		/* Check object type */
 1512|  62.8k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|  62.8k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1512:7): [True: 53.5k, False: 9.29k]
  ------------------
 1513|  53.5k|			continue;
 1514|  9.29k|		if (type != 0
  ------------------
  |  Branch (1514:7): [True: 9.29k, False: 0]
  ------------------
 1515|  9.29k|		 && obj->type != type
  ------------------
  |  Branch (1515:7): [True: 2.36k, False: 6.93k]
  ------------------
 1516|  2.36k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  2.36k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1516:7): [True: 0, False: 2.36k]
  ------------------
 1517|      0|			continue;
 1518|       |
 1519|       |		/* Potential candidate, apply search function */
 1520|  9.29k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1520:7): [True: 2.36k, False: 6.93k]
  |  Branch (1520:23): [True: 612, False: 1.75k]
  ------------------
 1521|    612|			continue;
 1522|       |		/* Okay, we have a match. */
 1523|  8.68k|		match_count++;
 1524|  8.68k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1524:7): [True: 0, False: 8.68k]
  |  Branch (1524:15): [True: 0, False: 8.68k]
  ------------------
 1525|      0|			continue;
 1526|  8.68k|		ret[match_count-1] = obj;
 1527|  8.68k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1527:7): [True: 1.75k, False: 6.93k]
  ------------------
 1528|  1.75k|			break;
 1529|  8.68k|	}
 1530|       |
 1531|  10.9k|	return (int)match_count;
 1532|  10.9k|}
pkcs15.c:compare_obj_key:
 1677|  2.36k|{
 1678|  2.36k|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1679|       |
 1680|  2.36k|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1680:6): [True: 1.25k, False: 1.11k]
  |  Branch (1680:16): [True: 353, False: 899]
  ------------------
 1681|    353|		return 0;
 1682|  2.01k|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1682:6): [True: 0, False: 2.01k]
  |  Branch (1682:21): [True: 0, False: 0]
  ------------------
 1683|      0|		return 0;
 1684|  2.01k|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1684:6): [True: 1.11k, False: 898]
  |  Branch (1684:24): [True: 259, False: 853]
  ------------------
 1685|    259|		return 0;
 1686|  1.75k|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1686:6): [True: 0, False: 1.75k]
  |  Branch (1686:24): [True: 0, False: 0]
  ------------------
 1687|      0|		return 0;
 1688|  1.75k|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1688:6): [True: 0, False: 1.75k]
  |  Branch (1688:29): [True: 0, False: 0]
  ------------------
 1689|      0|		return 0;
 1690|  1.75k|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1690:6): [True: 0, False: 1.75k]
  |  Branch (1690:18): [True: 0, False: 0]
  ------------------
 1691|      0|		return 0;
 1692|  1.75k|	if (sk->app_label) {
  ------------------
  |  Branch (1692:6): [True: 0, False: 1.75k]
  ------------------
 1693|      0|		if (sk->label && !compare_obj_data_name(obj, sk->app_label, sk->label))
  ------------------
  |  Branch (1693:7): [True: 0, False: 0]
  |  Branch (1693:20): [True: 0, False: 0]
  ------------------
 1694|      0|			return 0;
 1695|  1.75k|	} else {
 1696|  1.75k|		if (sk->label && strncmp(sk->label, obj->label, sizeof(obj->label)) != 0)
  ------------------
  |  Branch (1696:7): [True: 0, False: 1.75k]
  |  Branch (1696:20): [True: 0, False: 0]
  ------------------
 1697|      0|			return 0;
 1698|  1.75k|	}
 1699|       |
 1700|  1.75k|	return 1;
 1701|  1.75k|}
pkcs15.c:compare_obj_id:
 1545|  1.25k|{
 1546|  1.25k|	void *data = obj->data;
 1547|       |
 1548|  1.25k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  1.25k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1548:10): [True: 1.25k, False: 0]
  ------------------
 1549|    361|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|    361|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1549:2): [True: 361, False: 891]
  ------------------
 1550|    361|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_cert_info *) data)->id, id);
 1551|     99|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|     99|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1551:2): [True: 99, False: 1.15k]
  ------------------
 1552|     99|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) data)->id, id);
 1553|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1553:2): [True: 0, False: 1.25k]
  ------------------
 1554|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_pubkey_info *) data)->id, id);
 1555|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1555:2): [True: 0, False: 1.25k]
  ------------------
 1556|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1557|    792|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|    792|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1557:2): [True: 792, False: 460]
  ------------------
 1558|    792|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_auth_info *) data)->auth_id, id);
 1559|      0|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (1559:2): [True: 0, False: 1.25k]
  ------------------
 1560|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1561|  1.25k|	}
 1562|      0|	return 0;
 1563|  1.25k|}
pkcs15.c:compare_obj_usage:
 1577|  1.11k|{
 1578|  1.11k|	void		*data = obj->data;
 1579|  1.11k|	unsigned int	usage;
 1580|       |
 1581|  1.11k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  1.11k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 1582|  1.11k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  1.11k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1582:2): [True: 1.11k, False: 0]
  ------------------
 1583|  1.11k|		usage = ((struct sc_pkcs15_prkey_info *) data)->usage;
 1584|  1.11k|		break;
 1585|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1585:2): [True: 0, False: 1.11k]
  ------------------
 1586|      0|		usage = ((struct sc_pkcs15_pubkey_info *) data)->usage;
 1587|      0|		break;
 1588|      0|	default:
  ------------------
  |  Branch (1588:2): [True: 0, False: 1.11k]
  ------------------
 1589|      0|		return 0;
 1590|  1.11k|	}
 1591|  1.11k|	return (usage & mask & value) != 0;
 1592|  1.11k|}
pkcs15.c:find_by_key:
 1707|  4.52k|{
 1708|  4.52k|	int r;
 1709|       |
 1710|  4.52k|	r = sc_pkcs15_get_objects_cond(p15card, type, compare_obj_key, sk, out, 1);
 1711|  4.52k|	if (r < 0)
  ------------------
  |  Branch (1711:6): [True: 0, False: 4.52k]
  ------------------
 1712|      0|		return r;
 1713|  4.52k|	if (r == 0)
  ------------------
  |  Branch (1713:6): [True: 3.67k, False: 853]
  ------------------
 1714|  3.67k|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  3.67k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1715|    853|	return 0;
 1716|  4.52k|}
pkcs15.c:sc_pkcs15_remove_objects:
 2021|  26.9k|{
 2022|  26.9k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 2023|       |
 2024|  26.9k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (2024:6): [True: 0, False: 26.9k]
  |  Branch (2024:18): [True: 22.6k, False: 4.32k]
  ------------------
 2025|  22.6k|		return;
 2026|  32.7k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (2026:32): [True: 28.4k, False: 4.32k]
  ------------------
 2027|  28.4k|		next = cur->next;
 2028|  28.4k|		sc_pkcs15_free_object(cur);
 2029|  28.4k|	}
 2030|       |
 2031|       |	p15card->obj_list = NULL;
 2032|  4.32k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2102|  26.9k|{
 2103|  26.9k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2104|       |
 2105|  26.9k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2105:6): [True: 0, False: 26.9k]
  |  Branch (2105:18): [True: 22.5k, False: 4.44k]
  ------------------
 2106|  22.5k|		return;
 2107|       |
 2108|  12.8k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2108:31): [True: 8.40k, False: 4.44k]
  ------------------
 2109|  8.40k|		next = cur->next;
 2110|  8.40k|		free(cur);
 2111|  8.40k|	}
 2112|       |
 2113|       |	p15card->df_list = NULL;
 2114|  4.44k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2337|  11.9k|{
 2338|  11.9k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2339|       |
 2340|  11.9k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2340:6): [True: 0, False: 11.9k]
  |  Branch (2340:18): [True: 11.9k, False: 0]
  ------------------
 2341|  11.9k|		return;
 2342|      0|	for (cur = p15card->unusedspace_list; cur; cur = next)   {
  ------------------
  |  Branch (2342:40): [True: 0, False: 0]
  ------------------
 2343|      0|		next = cur->next;
 2344|      0|		free(cur);
 2345|      0|	}
 2346|       |
 2347|       |	p15card->unusedspace_list = NULL;
 2348|      0|}
pkcs15.c:decompress_file:
 2477|    308|{
 2478|    308|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    308|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    308|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    308|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    308|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 308]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2479|    308|#ifdef ENABLE_ZLIB
 2480|    308|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
 2481|    308|	int method = 0;
 2482|       |
 2483|    308|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|    308|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2483:6): [True: 0, False: 308]
  ------------------
 2484|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2485|    308|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|    308|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2485:13): [True: 0, False: 308]
  ------------------
 2486|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2487|    308|	} else {
 2488|    308|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|    308|#define COMPRESSION_AUTO	0
  ------------------
 2489|    308|	}
 2490|       |
 2491|    308|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2492|    308|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
  |  Branch (2492:6): [True: 240, False: 68]
  ------------------
 2493|    240|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   71|    240|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2494|    240|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|    240|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    240|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    240|	int _ret = r; \
  |  |  |  |  155|    240|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    240|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    240|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    240|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    240|	return _ret; \
  |  |  |  |  163|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|    240|	}
 2496|     68|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     68|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     68|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     68|	int _ret = r; \
  |  |  |  |  155|     68|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 68, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     68|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     68|	return _ret; \
  |  |  |  |  163|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2497|       |#else
 2498|       |	sc_log(card->ctx, "Compression not supported, no zlib");
 2499|       |	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2500|       |#endif
 2501|     68|}

sc_get_ctapi_driver:
  557|  15.2k|{
  558|  15.2k|	ctapi_ops.init = ctapi_init;
  559|  15.2k|	ctapi_ops.finish = ctapi_finish;
  560|  15.2k|	ctapi_ops.detect_readers = NULL;
  561|  15.2k|	ctapi_ops.transmit = ctapi_transmit;
  562|  15.2k|	ctapi_ops.detect_card_presence = ctapi_detect_card_presence;
  563|  15.2k|	ctapi_ops.lock = ctapi_lock;
  564|  15.2k|	ctapi_ops.unlock = ctapi_unlock;
  565|  15.2k|	ctapi_ops.release = ctapi_release;
  566|  15.2k|	ctapi_ops.connect = ctapi_connect;
  567|  15.2k|	ctapi_ops.disconnect = ctapi_disconnect;
  568|  15.2k|	ctapi_ops.perform_verify = ctbcs_pin_cmd;
  569|  15.2k|	ctapi_ops.perform_pace = NULL;
  570|  15.2k|	ctapi_ops.use_reader = NULL;
  571|       |
  572|  15.2k|	return &ctapi_drv;
  573|  15.2k|}
reader-ctapi.c:ctapi_init:
  514|  15.2k|{
  515|  15.2k|	int i;
  516|  15.2k|	struct ctapi_global_private_data *gpriv;
  517|  15.2k|	scconf_block **blocks = NULL, *conf_block = NULL;
  518|       |
  519|  15.2k|	gpriv = calloc(1, sizeof(struct ctapi_global_private_data));
  520|  15.2k|	if (gpriv == NULL)
  ------------------
  |  Branch (520:6): [True: 0, False: 15.2k]
  ------------------
  521|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  522|  15.2k|	ctx->reader_drv_data = gpriv;
  523|       |
  524|  15.2k|	conf_block = sc_get_conf_block(ctx, "reader_driver", "ctapi", 1);
  525|  15.2k|	if (conf_block)   {
  ------------------
  |  Branch (525:6): [True: 0, False: 15.2k]
  ------------------
  526|      0|		blocks = scconf_find_blocks(ctx->conf, conf_block, "module", NULL);
  527|      0|		for (i = 0; blocks != NULL && blocks[i] != NULL; i++)
  ------------------
  |  Branch (527:15): [True: 0, False: 0]
  |  Branch (527:33): [True: 0, False: 0]
  ------------------
  528|      0|			ctapi_load_module(ctx, gpriv, blocks[i]);
  529|      0|		free(blocks);
  530|      0|	}
  531|       |
  532|  15.2k|	return 0;
  533|  15.2k|}
reader-ctapi.c:ctapi_finish:
  536|  15.2k|{
  537|  15.2k|	struct ctapi_global_private_data *priv = (struct ctapi_global_private_data *) ctx->reader_drv_data;
  538|       |
  539|  15.2k|	if (priv) {
  ------------------
  |  Branch (539:6): [True: 15.2k, False: 0]
  ------------------
  540|  15.2k|		int i;
  541|       |
  542|  15.2k|		for (i = 0; i < priv->module_count; i++) {
  ------------------
  |  Branch (542:15): [True: 0, False: 15.2k]
  ------------------
  543|      0|			struct ctapi_module *mod = &priv->modules[i];
  544|       |
  545|      0|			free(mod->name);
  546|      0|			sc_dlclose(mod->dlhandle);
  547|      0|		}
  548|  15.2k|		if (priv->module_count)
  ------------------
  |  Branch (548:7): [True: 0, False: 15.2k]
  ------------------
  549|      0|			free(priv->modules);
  550|  15.2k|		free(priv);
  551|  15.2k|	}
  552|       |
  553|  15.2k|	return 0;
  554|  15.2k|}

card-epass2003.c:sc_evp_cipher:
  133|  2.39k|{
  134|  2.39k|	return (EVP_CIPHER *)EVP_get_cipherbyname(algorithm);
  135|  2.39k|}
card-epass2003.c:sc_evp_cipher_free:
  138|  2.39k|{
  139|  2.39k|	return;
  140|  2.39k|}

sc_get_version:
   58|  15.2k|{
   59|  15.2k|    return sc_version;
   60|  15.2k|}
sc_hex_to_bin:
   63|   343k|{
   64|   343k|	const char *sc_hex_to_bin_separators = " :";
   65|   343k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (65:6): [True: 66, False: 343k]
  |  Branch (65:20): [True: 0, False: 343k]
  |  Branch (65:35): [True: 0, False: 343k]
  ------------------
   66|     66|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     66|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   67|     66|	}
   68|       |
   69|   343k|	int byte_needs_nibble = 0;
   70|   343k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   343k|#define SC_SUCCESS				0
  ------------------
   71|   343k|	size_t left = *outlen;
   72|   343k|	u8 byte = 0;
   73|  5.39M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (73:9): [True: 5.04M, False: 342k]
  |  Branch (73:24): [True: 5.04M, False: 16]
  ------------------
   74|  5.04M|		char c = *in++;
   75|  5.04M|		u8 nibble;
   76|  5.04M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (76:12): [True: 5.04M, False: 410]
  |  Branch (76:24): [True: 2.72M, False: 2.32M]
  ------------------
   77|  2.72M|			nibble = c - '0';
   78|  2.32M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (78:12): [True: 457k, False: 1.86M]
  |  Branch (78:24): [True: 457k, False: 16]
  ------------------
   79|   457k|			nibble = c - 'a' + 10;
   80|  1.86M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (80:12): [True: 634k, False: 1.23M]
  |  Branch (80:24): [True: 634k, False: 19]
  ------------------
   81|   634k|			nibble = c - 'A' + 10;
   82|  1.23M|		else {
   83|  1.23M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (83:8): [True: 1.23M, False: 113]
  ------------------
   84|  1.23M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (84:9): [True: 3, False: 1.23M]
  ------------------
   85|      3|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   86|      3|					goto err;
   87|      3|				}
   88|  1.23M|				continue;
   89|  1.23M|			}
   90|    113|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    113|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   91|    113|			goto err;
   92|  1.23M|		}
   93|       |
   94|  3.81M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (94:7): [True: 1.90M, False: 1.91M]
  ------------------
   95|  1.90M|			byte |= nibble;
   96|  1.90M|			*out++ = (u8) byte;
   97|  1.90M|			left--;
   98|  1.90M|			byte_needs_nibble = 0;
   99|  1.91M|		} else {
  100|  1.91M|			byte  = nibble << 4;
  101|  1.91M|			byte_needs_nibble = 1;
  102|  1.91M|		}
  103|  3.81M|	}
  104|       |
  105|   342k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (105:6): [True: 9.65k, False: 333k]
  |  Branch (105:25): [True: 5.51k, False: 4.14k]
  |  Branch (105:51): [True: 5.51k, False: 0]
  ------------------
  106|       |		/* no output written so far, but we have a valid nibble in the upper
  107|       |		 * bits. Allow this special case. */
  108|  5.51k|		*out = (u8) byte>>4;
  109|  5.51k|		left--;
  110|  5.51k|		byte_needs_nibble = 0;
  111|  5.51k|	}
  112|       |
  113|       |	/* for ease of implementation we only accept completely hexed bytes. */
  114|   342k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (114:6): [True: 7, False: 342k]
  ------------------
  115|      7|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      7|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  116|      7|		goto err;
  117|      7|	}
  118|       |
  119|       |	/* skip all trailing separators to see if we missed something */
  120|   343k|	while (*in != '\0') {
  ------------------
  |  Branch (120:9): [True: 210, False: 342k]
  ------------------
  121|    210|		if (NULL == strchr(sc_hex_to_bin_separators, (int) *in))
  ------------------
  |  Branch (121:7): [True: 9, False: 201]
  ------------------
  122|      9|			break;
  123|    201|		in++;
  124|    201|	}
  125|   342k|	if (*in != '\0') {
  ------------------
  |  Branch (125:6): [True: 9, False: 342k]
  ------------------
  126|      9|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      9|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  127|      9|		goto err;
  128|      9|	}
  129|       |
  130|   343k|err:
  131|   343k|	*outlen -= left;
  132|   343k|	return r;
  133|   342k|}
sc_bin_to_hex:
  137|   339k|{
  138|   339k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (138:6): [True: 0, False: 339k]
  |  Branch (138:20): [True: 0, False: 339k]
  ------------------
  139|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  140|      0|	}
  141|       |
  142|   339k|	if (in_sep > 0) {
  ------------------
  |  Branch (142:6): [True: 336k, False: 3.11k]
  ------------------
  143|   336k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (143:7): [True: 0, False: 336k]
  |  Branch (143:29): [True: 0, False: 336k]
  ------------------
  144|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  145|   336k|	} else {
  146|  3.11k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (146:7): [True: 2, False: 3.11k]
  ------------------
  147|      2|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      2|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  148|  3.11k|	}
  149|       |
  150|   339k|	const char hex[] = "0123456789abcdef";
  151|  3.11M|	while (in_len) {
  ------------------
  |  Branch (151:9): [True: 2.77M, False: 339k]
  ------------------
  152|  2.77M|		unsigned char value = *in++;
  153|  2.77M|		*out++ = hex[(value >> 4) & 0xF];
  154|  2.77M|		*out++ = hex[ value       & 0xF];
  155|  2.77M|		in_len--;
  156|  2.77M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (156:7): [True: 2.58M, False: 183k]
  |  Branch (156:17): [True: 2.57M, False: 15.3k]
  ------------------
  157|  2.57M|			*out++ = (char)in_sep;
  158|  2.77M|	}
  159|   339k|	*out = '\0';
  160|       |
  161|   339k|	return SC_SUCCESS;
  ------------------
  |  |   28|   339k|#define SC_SUCCESS				0
  ------------------
  162|   339k|}
ulong2bebytes:
  188|  56.2k|{
  189|  56.2k|	if (buf != NULL) {
  ------------------
  |  Branch (189:6): [True: 56.2k, False: 0]
  ------------------
  190|  56.2k|		buf[3] = (u8) (x & 0xff);
  191|  56.2k|		buf[2] = (u8) ((x >> 8) & 0xff);
  192|  56.2k|		buf[1] = (u8) ((x >> 16) & 0xff);
  193|  56.2k|		buf[0] = (u8) ((x >> 24) & 0xff);
  194|  56.2k|	}
  195|  56.2k|	return buf;
  196|  56.2k|}
bebytes2ulong:
  208|  94.2k|{
  209|  94.2k|	if (buf == NULL)
  ------------------
  |  Branch (209:6): [True: 0, False: 94.2k]
  ------------------
  210|      0|		return 0UL;
  211|  94.2k|	return (unsigned long)buf[0] << 24
  212|  94.2k|		| (unsigned long)buf[1] << 16
  213|  94.2k|		| (unsigned long)buf[2] << 8
  214|  94.2k|		| (unsigned long)buf[3];
  215|  94.2k|}
bebytes2ushort:
  218|   124k|{
  219|   124k|	if (buf == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 124k]
  ------------------
  220|      0|		return 0U;
  221|   124k|	return (unsigned short)buf[0] << 8
  222|   124k|		| (unsigned short)buf[1];
  223|   124k|}
lebytes2ushort:
  226|  4.14k|{
  227|  4.14k|	if (buf == NULL)
  ------------------
  |  Branch (227:6): [True: 0, False: 4.14k]
  ------------------
  228|      0|		return 0U;
  229|  4.14k|	return (unsigned short)buf[1] << 8
  230|  4.14k|		| (unsigned short)buf[0];
  231|  4.14k|}
lebytes2ulong:
  234|  1.09k|{
  235|  1.09k|	if (buf == NULL)
  ------------------
  |  Branch (235:6): [True: 0, False: 1.09k]
  ------------------
  236|      0|		return 0UL;
  237|  1.09k|	return (unsigned long)buf[3] << 24
  238|  1.09k|		| (unsigned long)buf[2] << 16
  239|  1.09k|		| (unsigned long)buf[1] << 8
  240|  1.09k|		| (unsigned long)buf[0];
  241|  1.09k|}
set_string:
  244|  13.5k|{
  245|  13.5k|	if (strp == NULL) {
  ------------------
  |  Branch (245:6): [True: 0, False: 13.5k]
  ------------------
  246|      0|		return;
  247|      0|	}
  248|       |
  249|  13.5k|	free(*strp);
  250|  13.5k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (250:10): [True: 13.5k, False: 0]
  ------------------
  251|  13.5k|}
sc_init_oid:
  254|  54.8k|{
  255|  54.8k|	int ii;
  256|       |
  257|  54.8k|	if (!oid)
  ------------------
  |  Branch (257:6): [True: 0, False: 54.8k]
  ------------------
  258|      0|		return;
  259|   933k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   933k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (259:13): [True: 878k, False: 54.8k]
  ------------------
  260|   878k|		oid->value[ii] = -1;
  261|  54.8k|}
sc_format_oid:
  264|  20.4k|{
  265|  20.4k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  20.4k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  266|  20.4k|	const char *p;
  267|  20.4k|	char       *q;
  268|       |
  269|  20.4k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (269:6): [True: 0, False: 20.4k]
  |  Branch (269:21): [True: 0, False: 20.4k]
  ------------------
  270|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  271|       |
  272|  20.4k|	sc_init_oid(oid);
  273|       |
  274|  20.4k|	p = in;
  275|   179k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   179k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (275:13): [True: 179k, False: 0]
  ------------------
  276|   179k|		oid->value[ii] = (int)strtol(p, &q, 10);
  277|   179k|		if (!*q)
  ------------------
  |  Branch (277:7): [True: 20.4k, False: 159k]
  ------------------
  278|  20.4k|			break;
  279|       |
  280|   159k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (280:9): [True: 159k, False: 0]
  |  Branch (280:24): [True: 159k, False: 0]
  ------------------
  281|      0|			goto out;
  282|       |
  283|   159k|		p = q + 1;
  284|   159k|	}
  285|       |
  286|  20.4k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (286:6): [True: 0, False: 20.4k]
  ------------------
  287|      0|		goto out;
  288|       |
  289|  20.4k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  20.4k|#define SC_SUCCESS				0
  ------------------
  290|  20.4k|out:
  291|  20.4k|	if (ret)
  ------------------
  |  Branch (291:6): [True: 0, False: 20.4k]
  ------------------
  292|      0|		sc_init_oid(oid);
  293|       |
  294|  20.4k|	return ret;
  295|  20.4k|}
sc_compare_oid:
  298|  40.9k|{
  299|  40.9k|	int i;
  300|       |
  301|  40.9k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (301:6): [True: 0, False: 40.9k]
  |  Branch (301:22): [True: 0, False: 40.9k]
  ------------------
  302|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  303|      0|	}
  304|       |
  305|   104k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   104k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (305:14): [True: 104k, False: 0]
  ------------------
  306|   104k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (306:7): [True: 36.8k, False: 67.8k]
  ------------------
  307|  36.8k|			return 0;
  308|  67.8k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (308:7): [True: 4.11k, False: 63.7k]
  ------------------
  309|  4.11k|			break;
  310|  67.8k|	}
  311|       |
  312|  4.11k|	return 1;
  313|  40.9k|}
sc_valid_oid:
  317|  20.8k|{
  318|  20.8k|	int ii;
  319|       |
  320|  20.8k|	if (!oid)
  ------------------
  |  Branch (320:6): [True: 0, False: 20.8k]
  ------------------
  321|      0|		return 0;
  322|  20.8k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (322:6): [True: 34, False: 20.8k]
  |  Branch (322:29): [True: 0, False: 20.8k]
  ------------------
  323|     34|		return 0;
  324|  20.8k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (324:6): [True: 0, False: 20.8k]
  |  Branch (324:27): [True: 0, False: 20.8k]
  ------------------
  325|      0|		return 0;
  326|  20.8k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  20.8k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (326:12): [True: 20.8k, False: 0]
  ------------------
  327|  20.8k|		if (oid->value[ii])
  ------------------
  |  Branch (327:7): [True: 20.8k, False: 0]
  ------------------
  328|  20.8k|			break;
  329|  20.8k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  20.8k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (329:6): [True: 0, False: 20.8k]
  ------------------
  330|      0|		return 0;
  331|  20.8k|	return 1;
  332|  20.8k|}
sc_path_set:
  354|  23.0k|{
  355|  23.0k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  23.0k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (355:6): [True: 0, False: 23.0k]
  |  Branch (355:22): [True: 0, False: 23.0k]
  |  Branch (355:36): [True: 0, False: 23.0k]
  |  Branch (355:51): [True: 0, False: 23.0k]
  ------------------
  356|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  357|       |
  358|  23.0k|	memset(path, 0, sizeof(*path));
  359|  23.0k|	memcpy(path->value, id, id_len);
  360|  23.0k|	path->len   = id_len;
  361|  23.0k|	path->type  = type;
  362|  23.0k|	path->index = idx;
  363|  23.0k|	path->count = count;
  364|       |
  365|  23.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  23.0k|#define SC_SUCCESS				0
  ------------------
  366|  23.0k|}
sc_format_path:
  369|   152k|{
  370|   152k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   152k|#define SC_PATH_TYPE_PATH		2
  ------------------
  371|       |
  372|   152k|	if (path) {
  ------------------
  |  Branch (372:6): [True: 152k, False: 0]
  ------------------
  373|   152k|		memset(path, 0, sizeof(*path));
  374|   152k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (374:7): [True: 82, False: 152k]
  |  Branch (374:22): [True: 0, False: 152k]
  ------------------
  375|     82|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     82|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  376|     82|			str++;
  377|     82|		}
  378|   152k|		path->len = sizeof(path->value);
  379|   152k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (379:7): [True: 152k, False: 0]
  ------------------
  380|   152k|			path->type = type;
  381|   152k|		}
  382|   152k|		path->count = -1;
  383|   152k|	}
  384|   152k|}
sc_append_path_id:
  392|  44.3k|{
  393|  44.3k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  44.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (393:6): [True: 0, False: 44.3k]
  ------------------
  394|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  395|  44.3k|	memcpy(dest->value + dest->len, id, idlen);
  396|  44.3k|	dest->len += idlen;
  397|  44.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  44.3k|#define SC_SUCCESS				0
  ------------------
  398|  44.3k|}
sc_append_file_id:
  401|  44.3k|{
  402|  44.3k|	u8 id[2] = { fid >> 8, fid & 0xff };
  403|       |
  404|  44.3k|	return sc_append_path_id(dest, id, 2);
  405|  44.3k|}
sc_concatenate_path:
  408|  16.7k|{
  409|  16.7k|	sc_path_t tpath;
  410|       |
  411|  16.7k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (411:6): [True: 0, False: 16.7k]
  |  Branch (411:19): [True: 0, False: 16.7k]
  |  Branch (411:33): [True: 0, False: 16.7k]
  ------------------
  412|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  413|       |
  414|  16.7k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  33.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  16.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (414:6): [True: 0, False: 16.7k]
  |  Branch (414:42): [True: 0, False: 16.7k]
  ------------------
  415|       |		/* we do not support concatenation of AIDs at the moment */
  416|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  417|       |
  418|  16.7k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  16.7k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (418:6): [True: 2, False: 16.7k]
  ------------------
  419|      2|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      2|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  420|       |
  421|  16.7k|	memset(&tpath, 0, sizeof(sc_path_t));
  422|  16.7k|	memcpy(tpath.value, p1->value, p1->len);
  423|  16.7k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  424|  16.7k|	tpath.len  = p1->len + p2->len;
  425|  16.7k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  16.7k|#define SC_PATH_TYPE_PATH		2
  ------------------
  426|       |	/* use 'index' and 'count' entry of the second path object */
  427|  16.7k|	tpath.index = p2->index;
  428|  16.7k|	tpath.count = p2->count;
  429|       |	/* the result is currently always as path */
  430|  16.7k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  16.7k|#define SC_PATH_TYPE_PATH		2
  ------------------
  431|       |
  432|  16.7k|	*d = tpath;
  433|       |
  434|  16.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.7k|#define SC_SUCCESS				0
  ------------------
  435|  16.7k|}
sc_print_path:
  438|   217k|{
  439|   217k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  440|       |
  441|   217k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   217k|#define SC_SUCCESS				0
  ------------------
  |  Branch (441:6): [True: 0, False: 217k]
  ------------------
  442|      0|		buffer[0] = '\0';
  443|       |
  444|   217k|	return buffer;
  445|   217k|}
sc_path_print:
  448|   304k|{
  449|   304k|	size_t i;
  450|       |
  451|   304k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (451:6): [True: 0, False: 304k]
  |  Branch (451:21): [True: 0, False: 304k]
  ------------------
  452|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  453|       |
  454|   304k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (454:6): [True: 280, False: 304k]
  ------------------
  455|    280|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    280|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  456|       |
  457|   304k|	buf[0] = '\0';
  458|   304k|	if (path->aid.len)   {
  ------------------
  |  Branch (458:6): [True: 134k, False: 169k]
  ------------------
  459|  1.08M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (459:15): [True: 948k, False: 134k]
  ------------------
  460|   948k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  461|   134k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  462|   134k|	}
  463|       |
  464|  1.14M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (464:14): [True: 842k, False: 304k]
  ------------------
  465|   842k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  466|   304k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   169k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (466:6): [True: 169k, False: 134k]
  |  Branch (466:24): [True: 29.8k, False: 139k]
  ------------------
  467|  29.8k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  468|       |
  469|   304k|	return SC_SUCCESS;
  ------------------
  |  |   28|   304k|#define SC_SUCCESS				0
  ------------------
  470|   304k|}
sc_compare_path:
  473|  17.8k|{
  474|  17.8k|	return path1->len == path2->len
  ------------------
  |  Branch (474:9): [True: 15.5k, False: 2.21k]
  ------------------
  475|  15.5k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (475:6): [True: 112, False: 15.4k]
  ------------------
  476|  17.8k|}
sc_compare_path_prefix:
  479|  13.0k|{
  480|  13.0k|	sc_path_t tpath;
  481|       |
  482|  13.0k|	if (prefix->len > path->len)
  ------------------
  |  Branch (482:6): [True: 66, False: 13.0k]
  ------------------
  483|     66|		return 0;
  484|       |
  485|  13.0k|	tpath     = *path;
  486|  13.0k|	tpath.len = prefix->len;
  487|       |
  488|  13.0k|	return sc_compare_path(&tpath, prefix);
  489|  13.0k|}
sc_get_mf_path:
  492|  16.8k|{
  493|  16.8k|	static const sc_path_t mf_path = {
  494|  16.8k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  495|  16.8k|		0,
  496|  16.8k|		0,
  497|  16.8k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  16.8k|#define SC_PATH_TYPE_PATH		2
  ------------------
  498|  16.8k|		{{0},0}
  499|  16.8k|	};
  500|  16.8k|	return &mf_path;
  501|  16.8k|}
sc_file_add_acl_entry:
  505|   190k|{
  506|   190k|	sc_acl_entry_t *p, *_new;
  507|       |
  508|   190k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   190k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (508:6): [True: 0, False: 190k]
  |  Branch (508:22): [True: 0, False: 190k]
  ------------------
  509|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  510|      0|	}
  511|       |
  512|   190k|	switch (method) {
  513|  44.8k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  44.8k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (513:2): [True: 44.8k, False: 145k]
  ------------------
  514|  44.8k|		sc_file_clear_acl_entries(file, operation);
  515|  44.8k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  516|  44.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  44.8k|#define SC_SUCCESS				0
  ------------------
  517|  6.87k|	case SC_AC_NONE:
  ------------------
  |  |  150|  6.87k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (517:2): [True: 6.87k, False: 183k]
  ------------------
  518|  6.87k|		sc_file_clear_acl_entries(file, operation);
  519|  6.87k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  520|  6.87k|		return SC_SUCCESS;
  ------------------
  |  |   28|  6.87k|#define SC_SUCCESS				0
  ------------------
  521|  3.05k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  3.05k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (521:2): [True: 3.05k, False: 187k]
  ------------------
  522|  3.05k|		sc_file_clear_acl_entries(file, operation);
  523|  3.05k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  524|  3.05k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.05k|#define SC_SUCCESS				0
  ------------------
  525|   135k|	default:
  ------------------
  |  Branch (525:2): [True: 135k, False: 54.7k]
  ------------------
  526|       |		/* NONE and UNKNOWN get zapped when a new AC is added.
  527|       |		 * If the ACL is NEVER, additional entries will be
  528|       |		 * dropped silently. */
  529|   135k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (529:7): [True: 14, False: 135k]
  ------------------
  530|     14|			return SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
  531|   135k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (531:7): [True: 1.25k, False: 134k]
  ------------------
  532|   134k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (532:7): [True: 18, False: 134k]
  ------------------
  533|  1.27k|			file->acl[operation] = NULL;
  534|   190k|	}
  535|       |
  536|       |	/* If the entry is already present (e.g. due to the mapping)
  537|       |	 * of the card's AC with OpenSC's), don't add it again. */
  538|   181k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (538:33): [True: 48.8k, False: 132k]
  ------------------
  539|  48.8k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (539:7): [True: 46.0k, False: 2.81k]
  |  Branch (539:32): [True: 2.92k, False: 43.0k]
  ------------------
  540|  2.92k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.92k|#define SC_SUCCESS				0
  ------------------
  541|  48.8k|	}
  542|       |
  543|   132k|	_new = malloc(sizeof(sc_acl_entry_t));
  544|   132k|	if (_new == NULL)
  ------------------
  |  Branch (544:6): [True: 0, False: 132k]
  ------------------
  545|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  546|   132k|	_new->method = method;
  547|   132k|	_new->key_ref = (unsigned)key_ref;
  548|   132k|	_new->next = NULL;
  549|       |
  550|   132k|	p = file->acl[operation];
  551|   132k|	if (p == NULL) {
  ------------------
  |  Branch (551:6): [True: 123k, False: 8.62k]
  ------------------
  552|   123k|		file->acl[operation] = _new;
  553|   123k|		return SC_SUCCESS;
  ------------------
  |  |   28|   123k|#define SC_SUCCESS				0
  ------------------
  554|   123k|	}
  555|  43.9k|	while (p->next != NULL)
  ------------------
  |  Branch (555:9): [True: 35.3k, False: 8.62k]
  ------------------
  556|  35.3k|		p = p->next;
  557|  8.62k|	p->next = _new;
  558|       |
  559|  8.62k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.62k|#define SC_SUCCESS				0
  ------------------
  560|   132k|}
sc_file_get_acl_entry:
  564|   347k|{
  565|   347k|	sc_acl_entry_t *p;
  566|   347k|	static const sc_acl_entry_t e_never = {
  567|   347k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   347k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   347k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  568|   347k|	};
  569|   347k|	static const sc_acl_entry_t e_none = {
  570|   347k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   347k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   347k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  571|   347k|	};
  572|   347k|	static const sc_acl_entry_t e_unknown = {
  573|   347k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   347k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   347k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  574|   347k|	};
  575|       |
  576|   347k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   347k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (576:6): [True: 0, False: 347k]
  |  Branch (576:22): [True: 0, False: 347k]
  ------------------
  577|      0|		return NULL;
  578|      0|	}
  579|       |
  580|   347k|	p = file->acl[operation];
  581|   347k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (581:6): [True: 1.88k, False: 346k]
  ------------------
  582|  1.88k|		return &e_never;
  583|   346k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (583:6): [True: 753, False: 345k]
  ------------------
  584|    753|		return &e_none;
  585|   345k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (585:6): [True: 958, False: 344k]
  ------------------
  586|    958|		return &e_unknown;
  587|       |
  588|   344k|	return file->acl[operation];
  589|   345k|}
sc_file_clear_acl_entries:
  592|  3.04M|{
  593|  3.04M|	sc_acl_entry_t *e;
  594|       |
  595|  3.04M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  3.04M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (595:6): [True: 0, False: 3.04M]
  |  Branch (595:22): [True: 0, False: 3.04M]
  ------------------
  596|      0|		return;
  597|      0|	}
  598|       |
  599|  3.04M|	e = file->acl[operation];
  600|  3.04M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (600:6): [True: 44.8k, False: 2.99M]
  ------------------
  601|  2.99M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (601:6): [True: 5.61k, False: 2.99M]
  ------------------
  602|  2.99M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (602:6): [True: 3.03k, False: 2.98M]
  ------------------
  603|  53.4k|		file->acl[operation] = NULL;
  604|  53.4k|		return;
  605|  53.4k|	}
  606|       |
  607|  3.12M|	while (e != NULL) {
  ------------------
  |  Branch (607:9): [True: 132k, False: 2.98M]
  ------------------
  608|   132k|		sc_acl_entry_t *tmp = e->next;
  609|   132k|		free(e);
  610|   132k|		e = tmp;
  611|   132k|	}
  612|       |	file->acl[operation] = NULL;
  613|  2.98M|}
sc_file_new:
  616|  96.4k|{
  617|  96.4k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  618|  96.4k|	if (file == NULL)
  ------------------
  |  Branch (618:6): [True: 0, False: 96.4k]
  ------------------
  619|      0|		return NULL;
  620|       |
  621|  96.4k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|  96.4k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  622|  96.4k|	return file;
  623|  96.4k|}
sc_file_free:
  626|   257k|{
  627|   257k|	unsigned int i;
  628|   257k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (628:6): [True: 161k, False: 96.4k]
  |  Branch (628:22): [True: 0, False: 96.4k]
  ------------------
  629|   161k|		return;
  630|  96.4k|	file->magic = 0;
  631|  3.08M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  3.08M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (631:14): [True: 2.98M, False: 96.4k]
  ------------------
  632|  2.98M|		sc_file_clear_acl_entries(file, i);
  633|  96.4k|	if (file->sec_attr)
  ------------------
  |  Branch (633:6): [True: 984, False: 95.4k]
  ------------------
  634|    984|		free(file->sec_attr);
  635|  96.4k|	if (file->prop_attr)
  ------------------
  |  Branch (635:6): [True: 926, False: 95.4k]
  ------------------
  636|    926|		free(file->prop_attr);
  637|  96.4k|	if (file->type_attr)
  ------------------
  |  Branch (637:6): [True: 2.80k, False: 93.6k]
  ------------------
  638|  2.80k|		free(file->type_attr);
  639|  96.4k|	if (file->encoded_content)
  ------------------
  |  Branch (639:6): [True: 0, False: 96.4k]
  ------------------
  640|      0|		free(file->encoded_content);
  641|  96.4k|	free(file);
  642|  96.4k|}
sc_file_dup:
  645|  11.2k|{
  646|  11.2k|	sc_file_t *newf;
  647|  11.2k|	const sc_acl_entry_t *e;
  648|  11.2k|	unsigned int op;
  649|       |
  650|  11.2k|	if (!dest)
  ------------------
  |  Branch (650:6): [True: 0, False: 11.2k]
  ------------------
  651|      0|		return;
  652|  11.2k|	*dest = NULL;
  653|  11.2k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (653:6): [True: 0, False: 11.2k]
  ------------------
  654|      0|		return;
  655|  11.2k|	newf = sc_file_new();
  656|  11.2k|	if (newf == NULL)
  ------------------
  |  Branch (656:6): [True: 0, False: 11.2k]
  ------------------
  657|      0|		return;
  658|  11.2k|	*dest = newf;
  659|       |
  660|  11.2k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  661|  11.2k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  662|  11.2k|	newf->namelen = src->namelen;
  663|  11.2k|	newf->type    = src->type;
  664|  11.2k|	newf->shareable    = src->shareable;
  665|  11.2k|	newf->ef_structure = src->ef_structure;
  666|  11.2k|	newf->size    = src->size;
  667|  11.2k|	newf->id      = src->id;
  668|  11.2k|	newf->status  = src->status;
  669|   358k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   358k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (669:15): [True: 347k, False: 11.2k]
  ------------------
  670|   347k|		newf->acl[op] = NULL;
  671|   347k|		e = sc_file_get_acl_entry(src, op);
  672|   347k|		if (e != NULL) {
  ------------------
  |  Branch (672:7): [True: 10.0k, False: 337k]
  ------------------
  673|  10.0k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (673:8): [True: 0, False: 10.0k]
  ------------------
  674|      0|				goto err;
  675|  10.0k|		}
  676|   347k|	}
  677|  11.2k|	newf->record_length = src->record_length;
  678|  11.2k|	newf->record_count  = src->record_count;
  679|       |
  680|  11.2k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (680:6): [True: 0, False: 11.2k]
  ------------------
  681|      0|		goto err;
  682|  11.2k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (682:6): [True: 0, False: 11.2k]
  ------------------
  683|      0|		goto err;
  684|  11.2k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (684:6): [True: 0, False: 11.2k]
  ------------------
  685|      0|		goto err;
  686|  11.2k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (686:6): [True: 0, False: 11.2k]
  ------------------
  687|      0|		goto err;
  688|  11.2k|	return;
  689|  11.2k|err:
  690|      0|	sc_file_free(newf);
  691|       |	*dest = NULL;
  692|      0|}
sc_file_set_sec_attr:
  696|  12.5k|{
  697|  12.5k|	u8 *tmp;
  698|  12.5k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (698:6): [True: 0, False: 12.5k]
  ------------------
  699|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  700|      0|	}
  701|       |
  702|  12.5k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (702:6): [True: 11.1k, False: 1.35k]
  |  Branch (702:26): [True: 274, False: 1.08k]
  ------------------
  703|  11.4k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (703:7): [True: 69, False: 11.4k]
  ------------------
  704|     69|			free(file->sec_attr);
  705|  11.4k|		file->sec_attr = NULL;
  706|  11.4k|		file->sec_attr_len = 0;
  707|  11.4k|		return 0;
  708|  11.4k|	 }
  709|  1.08k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  710|  1.08k|	if (!tmp) {
  ------------------
  |  Branch (710:6): [True: 0, False: 1.08k]
  ------------------
  711|      0|		if (file->sec_attr)
  ------------------
  |  Branch (711:7): [True: 0, False: 0]
  ------------------
  712|      0|			free(file->sec_attr);
  713|      0|		file->sec_attr     = NULL;
  714|      0|		file->sec_attr_len = 0;
  715|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  716|      0|	}
  717|  1.08k|	file->sec_attr = tmp;
  718|  1.08k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  719|  1.08k|	file->sec_attr_len = sec_attr_len;
  720|       |
  721|  1.08k|	return 0;
  722|  1.08k|}
sc_file_set_prop_attr:
  726|  12.6k|{
  727|  12.6k|	u8 *tmp;
  728|  12.6k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (728:6): [True: 0, False: 12.6k]
  ------------------
  729|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  730|      0|	}
  731|       |
  732|  12.6k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (732:6): [True: 11.1k, False: 1.42k]
  |  Branch (732:27): [True: 358, False: 1.06k]
  ------------------
  733|  11.5k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (733:7): [True: 66, False: 11.4k]
  ------------------
  734|     66|			free(file->prop_attr);
  735|  11.5k|		file->prop_attr = NULL;
  736|  11.5k|		file->prop_attr_len = 0;
  737|  11.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
  738|  11.5k|	 }
  739|  1.06k|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  740|  1.06k|	if (!tmp) {
  ------------------
  |  Branch (740:6): [True: 0, False: 1.06k]
  ------------------
  741|      0|		if (file->prop_attr)
  ------------------
  |  Branch (741:7): [True: 0, False: 0]
  ------------------
  742|      0|			free(file->prop_attr);
  743|      0|		file->prop_attr = NULL;
  744|      0|		file->prop_attr_len = 0;
  745|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  746|      0|	}
  747|  1.06k|	file->prop_attr = tmp;
  748|  1.06k|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  749|  1.06k|	file->prop_attr_len = prop_attr_len;
  750|       |
  751|  1.06k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.06k|#define SC_SUCCESS				0
  ------------------
  752|  1.06k|}
sc_file_set_type_attr:
  756|  13.8k|{
  757|  13.8k|	u8 *tmp;
  758|  13.8k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (758:6): [True: 0, False: 13.8k]
  ------------------
  759|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  760|      0|	}
  761|       |
  762|  13.8k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (762:6): [True: 10.5k, False: 3.32k]
  |  Branch (762:27): [True: 0, False: 3.32k]
  ------------------
  763|  10.5k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (763:7): [True: 0, False: 10.5k]
  ------------------
  764|      0|			free(file->type_attr);
  765|  10.5k|		file->type_attr = NULL;
  766|  10.5k|		file->type_attr_len = 0;
  767|  10.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.5k|#define SC_SUCCESS				0
  ------------------
  768|  10.5k|	 }
  769|  3.32k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  770|  3.32k|	if (!tmp) {
  ------------------
  |  Branch (770:6): [True: 0, False: 3.32k]
  ------------------
  771|      0|		if (file->type_attr)
  ------------------
  |  Branch (771:7): [True: 0, False: 0]
  ------------------
  772|      0|			free(file->type_attr);
  773|      0|		file->type_attr = NULL;
  774|      0|		file->type_attr_len = 0;
  775|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  776|      0|	}
  777|  3.32k|	file->type_attr = tmp;
  778|  3.32k|	memcpy(file->type_attr, type_attr, type_attr_len);
  779|  3.32k|	file->type_attr_len = type_attr_len;
  780|       |
  781|  3.32k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.32k|#define SC_SUCCESS				0
  ------------------
  782|  3.32k|}
sc_file_set_content:
  787|  11.2k|{
  788|  11.2k|	u8 *tmp;
  789|  11.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (789:6): [True: 0, False: 11.2k]
  ------------------
  790|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  791|      0|	}
  792|       |
  793|  11.2k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (793:6): [True: 11.2k, False: 0]
  |  Branch (793:25): [True: 0, False: 0]
  ------------------
  794|  11.2k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (794:7): [True: 0, False: 11.2k]
  ------------------
  795|      0|			free(file->encoded_content);
  796|  11.2k|		file->encoded_content = NULL;
  797|  11.2k|		file->encoded_content_len = 0;
  798|  11.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  11.2k|#define SC_SUCCESS				0
  ------------------
  799|  11.2k|	}
  800|       |
  801|      0|	tmp = (u8 *) realloc(file->encoded_content, content_len);
  802|      0|	if (!tmp) {
  ------------------
  |  Branch (802:6): [True: 0, False: 0]
  ------------------
  803|      0|		if (file->encoded_content)
  ------------------
  |  Branch (803:7): [True: 0, False: 0]
  ------------------
  804|      0|			free(file->encoded_content);
  805|      0|		file->encoded_content = NULL;
  806|      0|		file->encoded_content_len = 0;
  807|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  808|      0|	}
  809|       |
  810|      0|	file->encoded_content = tmp;
  811|      0|	memcpy(file->encoded_content, content, content_len);
  812|      0|	file->encoded_content_len = content_len;
  813|       |
  814|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  815|      0|}
sc_file_valid:
  818|   157k|int sc_file_valid(const sc_file_t *file) {
  819|   157k|	if (file == NULL)
  ------------------
  |  Branch (819:6): [True: 0, False: 157k]
  ------------------
  820|      0|		return 0;
  821|   157k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   56|   157k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  822|   157k|}
_sc_parse_atr:
  825|  15.2k|{
  826|  15.2k|	u8 *p = reader->atr.value;
  827|  15.2k|	int atr_len = (int) reader->atr.len;
  828|  15.2k|	int n_hist, x;
  829|  15.2k|	int tx[4] = {-1, -1, -1, -1};
  830|  15.2k|	int i, FI, DI;
  831|  15.2k|	const int Fi_table[] = {
  832|  15.2k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  833|  15.2k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  834|  15.2k|	const int f_table[] = {
  835|  15.2k|		40, 50, 60, 80, 120, 160, 200, -1,
  836|  15.2k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  837|  15.2k|	const int Di_table[] = {
  838|  15.2k|		-1, 1, 2, 4, 8, 16, 32, -1,
  839|  15.2k|		12, 20, -1, -1, -1, -1, -1, -1 };
  840|       |
  841|  15.2k|	reader->atr_info.hist_bytes_len = 0;
  842|  15.2k|	reader->atr_info.hist_bytes = NULL;
  843|       |
  844|  15.2k|	if (atr_len == 0) {
  ------------------
  |  Branch (844:6): [True: 4.94k, False: 10.3k]
  ------------------
  845|  4.94k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  4.94k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  846|  4.94k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  4.94k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  847|  4.94k|	}
  848|       |
  849|  10.3k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (849:6): [True: 843, False: 9.47k]
  |  Branch (849:22): [True: 811, False: 32]
  ------------------
  850|    811|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   71|    811|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  851|    811|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    811|#define SC_ERROR_INTERNAL			-1400
  ------------------
  852|    811|	}
  853|  9.50k|	n_hist = p[1] & 0x0F;
  854|  9.50k|	x = p[1] >> 4;
  855|  9.50k|	p += 2;
  856|  9.50k|	atr_len -= 2;
  857|  46.7k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (857:14): [True: 37.4k, False: 9.31k]
  |  Branch (857:23): [True: 37.2k, False: 188]
  ------------------
  858|  37.2k|                if (x & (1 << i)) {
  ------------------
  |  Branch (858:21): [True: 25.1k, False: 12.1k]
  ------------------
  859|  25.1k|                        tx[i] = *p;
  860|  25.1k|                        p++;
  861|  25.1k|                        atr_len--;
  862|  25.1k|                } else
  863|  12.1k|                        tx[i] = -1;
  864|  37.2k|        }
  865|  9.50k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (865:6): [True: 8.31k, False: 1.19k]
  ------------------
  866|  8.31k|		reader->atr_info.FI = FI = tx[0] >> 4;
  867|  8.31k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  868|  8.31k|		reader->atr_info.Fi = Fi_table[FI];
  869|  8.31k|		reader->atr_info.f = f_table[FI];
  870|  8.31k|		reader->atr_info.Di = Di_table[DI];
  871|  8.31k|	} else {
  872|  1.19k|		reader->atr_info.Fi = -1;
  873|  1.19k|		reader->atr_info.f = -1;
  874|  1.19k|		reader->atr_info.Di = -1;
  875|  1.19k|	}
  876|  9.50k|	if (tx[2] >= 0)
  ------------------
  |  Branch (876:6): [True: 6.09k, False: 3.41k]
  ------------------
  877|  6.09k|		reader->atr_info.N = tx[3];
  878|  3.41k|	else
  879|  3.41k|		reader->atr_info.N = -1;
  880|  20.2k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (880:9): [True: 10.9k, False: 9.26k]
  |  Branch (880:22): [True: 10.7k, False: 209]
  |  Branch (880:38): [True: 10.7k, False: 30]
  ------------------
  881|  10.7k|		x = tx[3] >> 4;
  882|  53.6k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (882:15): [True: 42.9k, False: 10.7k]
  |  Branch (882:24): [True: 42.9k, False: 24]
  ------------------
  883|  42.9k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (883:22): [True: 16.4k, False: 26.4k]
  ------------------
  884|  16.4k|	                        tx[i] = *p;
  885|  16.4k|	                        p++;
  886|  16.4k|	                        atr_len--;
  887|  16.4k|	                } else
  888|  26.4k|	                        tx[i] = -1;
  889|  42.9k|		}
  890|  10.7k|	}
  891|  9.50k|	if (atr_len <= 0)
  ------------------
  |  Branch (891:6): [True: 219, False: 9.28k]
  ------------------
  892|    219|		return SC_SUCCESS;
  ------------------
  |  |   28|    219|#define SC_SUCCESS				0
  ------------------
  893|  9.28k|	if (n_hist > atr_len)
  ------------------
  |  Branch (893:6): [True: 744, False: 8.54k]
  ------------------
  894|    744|		n_hist = atr_len;
  895|  9.28k|	reader->atr_info.hist_bytes_len = n_hist;
  896|  9.28k|	reader->atr_info.hist_bytes = p;
  897|  9.28k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.28k|#define SC_SUCCESS				0
  ------------------
  898|  9.50k|}
sc_mem_secure_alloc:
  901|    574|{
  902|    574|	void *p;
  903|       |
  904|       |#ifdef _WIN32
  905|       |	p = VirtualAlloc(NULL, len, MEM_COMMIT, PAGE_READWRITE);
  906|       |	if (p != NULL) {
  907|       |		VirtualLock(p, len);
  908|       |	}
  909|       |#else
  910|    574|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  911|    574|	if (p != NULL) {
  ------------------
  |  Branch (911:6): [True: 574, False: 0]
  ------------------
  912|    574|		mlock(p, len);
  913|    574|	}
  914|    574|#endif
  915|       |
  916|    574|	return p;
  917|    574|}
sc_mem_secure_free:
  920|    574|{
  921|       |#ifdef _WIN32
  922|       |	VirtualUnlock(ptr, len);
  923|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  924|       |#else
  925|    574|	munlock(ptr, len);
  926|    574|	munmap(ptr, len);
  927|    574|#endif
  928|    574|}
sc_mem_clear:
  931|  38.6k|{
  932|  38.6k|	if (len > 0)   {
  ------------------
  |  Branch (932:6): [True: 38.6k, False: 0]
  ------------------
  933|       |#ifdef HAVE_MEMSET_S
  934|       |		memset_s(ptr, len, 0, len);
  935|       |#elif _WIN32
  936|       |		SecureZeroMemory(ptr, len);
  937|       |#elif HAVE_EXPLICIT_BZERO
  938|       |		explicit_bzero(ptr, len);
  939|       |#elif ENABLE_OPENSSL
  940|       |		OPENSSL_cleanse(ptr, len);
  941|       |#else
  942|       |		memset(ptr, 0, len);
  943|       |#endif
  944|  38.6k|	}
  945|  38.6k|}
sc_compacttlv_find_tag:
 1059|    448|{
 1060|    448|	if (buf != NULL) {
  ------------------
  |  Branch (1060:6): [True: 448, False: 0]
  ------------------
 1061|    448|		size_t idx;
 1062|    448|		u8 plain_tag = tag & 0xF0;
 1063|    448|		size_t expected_len = tag & 0x0F;
 1064|       |
 1065|  18.6k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1065:17): [True: 18.4k, False: 223]
  ------------------
 1066|  18.4k|			u8 ctag = buf[idx] & 0xF0;
 1067|  18.4k|			size_t ctag_len = buf[idx] & 0x0F;
 1068|  18.4k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1068:8): [True: 1.03k, False: 17.4k]
  |  Branch (1068:29): [True: 1.02k, False: 13]
  ------------------
 1069|  1.02k|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1069:7): [True: 157, False: 864]
  |  Branch (1069:28): [True: 68, False: 796]
  ------------------
 1070|    225|				if (outlen != NULL)
  ------------------
  |  Branch (1070:9): [True: 157, False: 68]
  ------------------
 1071|    157|					*outlen = ctag_len;
 1072|    225|				return buf + (idx + 1);
 1073|    225|			}
 1074|  18.2k|			idx += ctag_len;
 1075|  18.2k|		}
 1076|    448|	}
 1077|    223|	return NULL;
 1078|    448|}
sc_mutex_create:
 1083|  30.5k|{
 1084|  30.5k|	if (ctx == NULL)
  ------------------
  |  Branch (1084:6): [True: 0, False: 30.5k]
  ------------------
 1085|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1086|  30.5k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1086:6): [True: 0, False: 30.5k]
  |  Branch (1086:33): [True: 0, False: 0]
  ------------------
 1087|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1088|  30.5k|	else
 1089|  30.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  30.5k|#define SC_SUCCESS				0
  ------------------
 1090|  30.5k|}
sc_mutex_lock:
 1093|  1.06M|{
 1094|  1.06M|	if (ctx == NULL)
  ------------------
  |  Branch (1094:6): [True: 0, False: 1.06M]
  ------------------
 1095|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1096|  1.06M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1096:6): [True: 0, False: 1.06M]
  |  Branch (1096:33): [True: 0, False: 0]
  ------------------
 1097|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1098|  1.06M|	else
 1099|  1.06M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.06M|#define SC_SUCCESS				0
  ------------------
 1100|  1.06M|}
sc_mutex_unlock:
 1103|  1.06M|{
 1104|  1.06M|	if (ctx == NULL)
  ------------------
  |  Branch (1104:6): [True: 0, False: 1.06M]
  ------------------
 1105|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1106|  1.06M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1106:6): [True: 0, False: 1.06M]
  |  Branch (1106:33): [True: 0, False: 0]
  ------------------
 1107|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1108|  1.06M|	else
 1109|  1.06M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.06M|#define SC_SUCCESS				0
  ------------------
 1110|  1.06M|}

sc_decipher:
   36|    231|{
   37|    231|	int r;
   38|       |
   39|    231|	if (card == NULL) {
  ------------------
  |  Branch (39:6): [True: 0, False: 231]
  ------------------
   40|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   41|      0|	}
   42|    231|	if (crgram == NULL || out == NULL) {
  ------------------
  |  Branch (42:6): [True: 0, False: 231]
  |  Branch (42:24): [True: 0, False: 231]
  ------------------
   43|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|      0|	}
   45|    231|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    231|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    231|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    231|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    231|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 231]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   46|    231|	if (card->ops->decipher == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 231]
  ------------------
   47|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   48|    231|	r = card->ops->decipher(card, crgram, crgram_len, out, outlen);
   49|    231|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    231|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    231|	int _ret = r; \
  |  |  155|    231|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 134, False: 97]
  |  |  ------------------
  |  |  156|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    117|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 117, False: 17]
  |  |  ------------------
  |  |  157|    134|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    134|	} else { \
  |  |  159|     97|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     97|			"returning with: %d\n", _ret); \
  |  |  161|     97|	} \
  |  |  162|    231|	return _ret; \
  |  |  163|    231|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   50|    231|}
sc_compute_signature:
   55|    166|{
   56|    166|	int r;
   57|       |
   58|    166|	if (card == NULL) {
  ------------------
  |  Branch (58:6): [True: 0, False: 166]
  ------------------
   59|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   60|      0|	}
   61|    166|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    166|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    166|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    166|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    166|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 166]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   62|    166|	if (card->ops->compute_signature == NULL)
  ------------------
  |  Branch (62:6): [True: 0, False: 166]
  ------------------
   63|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   64|    166|	r = card->ops->compute_signature(card, data, datalen, out, outlen);
   65|    166|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    166|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    166|	int _ret = r; \
  |  |  155|    166|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 143, False: 23]
  |  |  ------------------
  |  |  156|    143|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    130|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 130, False: 13]
  |  |  ------------------
  |  |  157|    143|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    143|	} else { \
  |  |  159|     23|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     23|			"returning with: %d\n", _ret); \
  |  |  161|     23|	} \
  |  |  162|    166|	return _ret; \
  |  |  163|    166|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   66|    166|}
sc_set_security_env:
  101|    442|{
  102|    442|	int r;
  103|       |
  104|    442|	if (card == NULL) {
  ------------------
  |  Branch (104:6): [True: 0, False: 442]
  ------------------
  105|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  106|      0|	}
  107|    442|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    442|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    442|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    442|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    442|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 442]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  108|    442|	if (card->ops->set_security_env == NULL)
  ------------------
  |  Branch (108:6): [True: 0, False: 442]
  ------------------
  109|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  110|    442|	r = card->ops->set_security_env(card, env, se_num);
  111|    442|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    442|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    442|	int _ret = r; \
  |  |  155|    442|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 442, False: 0]
  |  |  ------------------
  |  |  156|    442|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 45, False: 397]
  |  |  ------------------
  |  |  157|    442|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    442|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    442|	return _ret; \
  |  |  163|    442|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  112|    442|}
sc_verify:
  130|    852|{
  131|    852|	struct sc_pin_cmd_data data;
  132|       |
  133|    852|	memset(&data, 0, sizeof(data));
  134|    852|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    852|#define SC_PIN_CMD_VERIFY	0
  ------------------
  135|    852|	data.pin_type = type;
  136|    852|	data.pin_reference = ref;
  137|    852|	data.pin1.data = pin;
  138|    852|	data.pin1.len = pinlen;
  139|       |
  140|    852|	int r = sc_pin_cmd(card, &data);
  141|    852|	if (tries_left)
  ------------------
  |  Branch (141:6): [True: 852, False: 0]
  ------------------
  142|    852|		*tries_left = data.pin1.tries_left;
  143|       |
  144|    852|	return r;
  145|    852|}
sc_pin_cmd:
  203|  2.15k|{
  204|  2.15k|	int r, debug;
  205|       |
  206|  2.15k|	if (card == NULL) {
  ------------------
  |  Branch (206:6): [True: 0, False: 2.15k]
  ------------------
  207|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  208|      0|	}
  209|  2.15k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.15k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.15k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|       |
  211|  2.15k|	debug = card->ctx->debug;
  212|  2.15k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  418|  4.30k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (212:6): [True: 1.16k, False: 994]
  ------------------
  213|  1.16k|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (213:7): [True: 1.14k, False: 11]
  ------------------
  214|  1.14k|		card->ctx->debug = 0;
  215|  1.14k|	}
  216|       |
  217|  2.15k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (217:6): [True: 2.15k, False: 0]
  ------------------
  218|  2.15k|		r = card->ops->pin_cmd(card, data);
  219|  2.15k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (219:13): [True: 0, False: 0]
  ------------------
  220|       |		/* Card driver doesn't support new style pin_cmd, fall
  221|       |		 * back to old interface */
  222|       |
  223|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  224|      0|		switch (data->cmd) {
  ------------------
  |  Branch (224:11): [True: 0, False: 0]
  ------------------
  225|      0|		case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (225:3): [True: 0, False: 0]
  ------------------
  226|      0|			if (card->ops->verify != NULL)
  ------------------
  |  Branch (226:8): [True: 0, False: 0]
  ------------------
  227|      0|				r = card->ops->verify(card,
  228|      0|					data->pin_type,
  229|      0|					data->pin_reference,
  230|      0|					data->pin1.data,
  231|      0|					(size_t) data->pin1.len,
  232|      0|					&data->pin1.tries_left);
  233|      0|			break;
  234|      0|		case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (234:3): [True: 0, False: 0]
  ------------------
  235|      0|			if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (235:8): [True: 0, False: 0]
  ------------------
  236|      0|				r = card->ops->change_reference_data(card,
  237|      0|					data->pin_type,
  238|      0|					data->pin_reference,
  239|      0|					data->pin1.data,
  240|      0|					(size_t) data->pin1.len,
  241|      0|					data->pin2.data,
  242|      0|					(size_t) data->pin2.len,
  243|      0|					&data->pin1.tries_left);
  244|      0|			break;
  245|      0|		case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (245:3): [True: 0, False: 0]
  ------------------
  246|      0|			if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (246:8): [True: 0, False: 0]
  ------------------
  247|      0|				r = card->ops->reset_retry_counter(card,
  248|      0|					data->pin_type,
  249|      0|					data->pin_reference,
  250|      0|					data->pin1.data,
  251|      0|					(size_t) data->pin1.len,
  252|      0|					data->pin2.data,
  253|      0|					(size_t) data->pin2.len);
  254|      0|			break;
  255|      0|		}
  256|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (256:7): [True: 0, False: 0]
  ------------------
  257|      0|			sc_log(card->ctx,  "unsupported PIN operation (%d)",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|      0|					data->cmd);
  259|      0|	} else {
  260|      0|		sc_log(card->ctx,  "Use of pin pad not supported by card driver");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  261|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  262|      0|	}
  263|  2.15k|	card->ctx->debug = debug;
  264|       |
  265|  2.15k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.15k|	int _ret = r; \
  |  |  155|  2.15k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.15k, False: 0]
  |  |  ------------------
  |  |  156|  2.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    823|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 823, False: 1.33k]
  |  |  ------------------
  |  |  157|  2.15k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.15k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  2.15k|	return _ret; \
  |  |  163|  2.15k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  266|  2.15k|}
sc_build_pin:
  280|    216|{
  281|    216|	size_t i = 0, j, pin_len = pin->len;
  282|       |
  283|    216|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (283:6): [True: 181, False: 35]
  |  Branch (283:25): [True: 0, False: 181]
  ------------------
  284|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  285|       |
  286|    216|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|    216|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (286:6): [True: 22, False: 194]
  ------------------
  287|     48|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (287:10): [True: 48, False: 0]
  |  Branch (287:25): [True: 26, False: 22]
  ------------------
  288|     26|			pin_len--;
  289|     22|		if (pin_len > 12)
  ------------------
  |  Branch (289:7): [True: 1, False: 21]
  ------------------
  290|      1|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  291|     85|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (291:15): [True: 76, False: 9]
  ------------------
  292|     76|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (292:8): [True: 3, False: 73]
  |  Branch (292:30): [True: 9, False: 64]
  ------------------
  293|     12|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     12|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  294|     76|		}
  295|      9|		buf[0] = 0x20 | (u8) pin_len;
  296|      9|		buf++;
  297|      9|		buflen--;
  298|      9|	}
  299|       |
  300|       |	/* PIN given by application, encode if required */
  301|    203|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  425|    203|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (301:6): [True: 194, False: 9]
  ------------------
  302|    194|		if (pin_len > buflen)
  ------------------
  |  Branch (302:7): [True: 0, False: 194]
  ------------------
  303|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  304|    194|		memcpy(buf, pin->data, pin_len);
  305|    194|		i = pin_len;
  306|    194|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  426|     18|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|      9|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (306:13): [True: 0, False: 9]
  |  Branch (306:53): [True: 9, False: 0]
  ------------------
  307|      9|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (307:7): [True: 0, False: 9]
  ------------------
  308|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  309|     53|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (309:19): [True: 44, False: 9]
  ------------------
  310|     44|			if (!isdigit(pin->data[j])) {
  ------------------
  |  Branch (310:8): [True: 0, False: 44]
  ------------------
  311|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  312|      0|			}
  313|     44|			buf[i] <<= 4;
  314|     44|			buf[i] |= pin->data[j] & 0xf;
  315|     44|			if (j & 1)
  ------------------
  |  Branch (315:8): [True: 20, False: 24]
  ------------------
  316|     20|				i++;
  317|     44|		}
  318|      9|		if (j & 1) {
  ------------------
  |  Branch (318:7): [True: 4, False: 5]
  ------------------
  319|      4|			buf[i] <<= 4;
  320|      4|			buf[i] |= pin->pad_char & 0xf;
  321|      4|			i++;
  322|      4|		}
  323|      9|	}
  324|       |
  325|       |	/* Pad to maximum PIN length if requested */
  326|    203|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|    102|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (326:6): [True: 101, False: 102]
  |  Branch (326:13): [True: 0, False: 102]
  ------------------
  327|    101|		size_t pad_length = pin->pad_length;
  328|    101|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  427|    101|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (328:23): [True: 9, False: 92]
  ------------------
  329|       |
  330|    101|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  426|    101|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (330:7): [True: 0, False: 101]
  ------------------
  331|      0|			pad_length >>= 1;
  332|    101|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  427|    101|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (332:7): [True: 9, False: 92]
  ------------------
  333|      9|			pad_length = 8;
  334|       |
  335|    101|		if (pad_length > buflen)
  ------------------
  |  Branch (335:7): [True: 0, False: 101]
  ------------------
  336|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  337|       |
  338|    101|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (338:7): [True: 101, False: 0]
  |  Branch (338:21): [True: 86, False: 15]
  ------------------
  339|     86|			memset(buf + i, pad_char, pad_length - i);
  340|     86|			i = pad_length;
  341|     86|		}
  342|    101|	}
  343|       |
  344|    203|	return (int)i;
  345|    203|}

sc_simpletlv_put_tag:
   42|    253|{
   43|    253|	u8 *p = out;
   44|       |
   45|    253|	if (outlen < 2 || (outlen < 4 && datalen >= 0xff))
  ------------------
  |  Branch (45:6): [True: 0, False: 253]
  |  Branch (45:21): [True: 23, False: 230]
  |  Branch (45:35): [True: 0, False: 23]
  ------------------
   46|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   47|       |
   48|       |	/* tag is just number between 0x01 and 0xFE */
   49|    253|	if (tag == 0x00 || tag == 0xff)
  ------------------
  |  Branch (49:6): [True: 74, False: 179]
  |  Branch (49:21): [True: 37, False: 142]
  ------------------
   50|    111|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    111|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   51|    142|	if (datalen > 0xffff) {
  ------------------
  |  Branch (51:6): [True: 0, False: 142]
  ------------------
   52|       |		/* we can't store more than two bytes in Simple TLV */
   53|      0|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
   54|      0|	}
   55|       |
   56|    142|	*p++ = tag; /* tag is single byte */
   57|    142|	if (datalen < 0xff) {
  ------------------
  |  Branch (57:6): [True: 110, False: 32]
  ------------------
   58|       |		/* short value up to 255 */
   59|    110|		*p++ = (u8)datalen; /* is in the second byte */
   60|    110|	} else {
   61|       |		/* longer values up to 65535 */
   62|     32|		*p++ = (u8)0xff; /* first byte is 0xff */
   63|     32|		*p++ = (u8)datalen & 0xff;
   64|     32|		*p++ = (u8)(datalen >> 8) & 0xff; /* LE */
   65|     32|	}
   66|    142|	if (ptr != NULL)
  ------------------
  |  Branch (66:6): [True: 142, False: 0]
  ------------------
   67|    142|		*ptr = p;
   68|    142|	return SC_SUCCESS;
  ------------------
  |  |   28|    142|#define SC_SUCCESS				0
  ------------------
   69|    142|}
sc_simpletlv_read_tag:
   76|  50.1k|{
   77|  50.1k|	u8 tag;
   78|  50.1k|	size_t left = buflen, len;
   79|  50.1k|	const u8 *p = *buf;
   80|       |
   81|  50.1k|	*buf = NULL;
   82|       |
   83|  50.1k|	if (left < 2) {
  ------------------
  |  Branch (83:6): [True: 714, False: 49.4k]
  ------------------
   84|    714|		return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    714|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   85|    714|	}
   86|  49.4k|	tag = *p;
   87|  49.4k|	p++;
   88|  49.4k|	len = *p;
   89|  49.4k|	p++;
   90|  49.4k|	left -= 2;
   91|       |
   92|  49.4k|	if (len == 0xff) {
  ------------------
  |  Branch (92:6): [True: 1.17k, False: 48.3k]
  ------------------
   93|       |		/* don't crash on bad data */
   94|  1.17k|		if (left < 2) {
  ------------------
  |  Branch (94:7): [True: 349, False: 824]
  ------------------
   95|    349|			return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    349|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   96|    349|		}
   97|       |		/* skip two bytes (the size) */
   98|    824|		len = lebytes2ushort(p);
   99|    824|		p += 2;
  100|    824|		left -= 2;
  101|    824|	}
  102|       |
  103|  49.1k|	*tag_out = tag;
  104|  49.1k|	*taglen = len;
  105|  49.1k|	*buf = p;
  106|       |
  107|  49.1k|	if (len > left)
  ------------------
  |  Branch (107:6): [True: 3.29k, False: 45.8k]
  ------------------
  108|  3.29k|		return SC_ERROR_TLV_END_OF_CONTENTS;
  ------------------
  |  |   99|  3.29k|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  109|       |
  110|  45.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  45.8k|#define SC_SUCCESS				0
  ------------------
  111|  49.1k|}

sc_sm_parse_answer:
   44|  2.15k|{
   45|  2.15k|	struct sc_asn1_entry asn1_sm_response[4];
   46|  2.15k|	unsigned char data[SC_MAX_APDU_BUFFER_SIZE];
   47|  2.15k|	size_t data_len = sizeof(data);
   48|  2.15k|	unsigned char status[2] = {0, 0};
   49|  2.15k|	size_t status_len = sizeof(status);
   50|  2.15k|	unsigned char mac[8];
   51|  2.15k|	size_t mac_len = sizeof(mac);
   52|  2.15k|	int rv;
   53|       |
   54|  2.15k|	if (!resp_data || !resp_len || !out)
  ------------------
  |  Branch (54:6): [True: 0, False: 2.15k]
  |  Branch (54:20): [True: 0, False: 2.15k]
  |  Branch (54:33): [True: 0, False: 2.15k]
  ------------------
   55|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   56|       |
   57|  2.15k|	sc_copy_asn1_entry(c_asn1_sm_response, asn1_sm_response);
   58|       |
   59|  2.15k|	sc_format_asn1_entry(asn1_sm_response + 0, data, &data_len, 0);
   60|  2.15k|	sc_format_asn1_entry(asn1_sm_response + 1, status, &status_len, 0);
   61|  2.15k|	sc_format_asn1_entry(asn1_sm_response + 2, mac, &mac_len, 0);
   62|       |
   63|  2.15k|	rv = sc_asn1_decode(card->ctx, asn1_sm_response, resp_data, resp_len, NULL, NULL);
   64|  2.15k|	if (rv)
  ------------------
  |  Branch (64:6): [True: 1.74k, False: 414]
  ------------------
   65|  1.74k|		return rv;
   66|       |
   67|    414|	if (asn1_sm_response[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    414|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (67:6): [True: 61, False: 353]
  ------------------
   68|     61|		if (data_len > sizeof(out->data))
  ------------------
  |  Branch (68:7): [True: 0, False: 61]
  ------------------
   69|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   70|     61|		memcpy(out->data, data, data_len);
   71|     61|		out->data_len = data_len;
   72|     61|	}
   73|    414|	if (asn1_sm_response[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    414|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (73:6): [True: 414, False: 0]
  ------------------
   74|    414|		if (!status[0])
  ------------------
  |  Branch (74:7): [True: 217, False: 197]
  ------------------
   75|    217|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    217|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
   76|    197|		out->sw1 = status[0];
   77|    197|		out->sw2 = status[1];
   78|    197|	}
   79|    197|	if (asn1_sm_response[2].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    197|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (79:6): [True: 197, False: 0]
  ------------------
   80|    197|		memcpy(out->mac, mac, mac_len);
   81|    197|		out->mac_len = mac_len;
   82|    197|	}
   83|       |
   84|    197|	return SC_SUCCESS;
  ------------------
  |  |   28|    197|#define SC_SUCCESS				0
  ------------------
   85|    414|}
sc_sm_update_apdu_response:
   98|  2.15k|{
   99|  2.15k|	struct sm_card_response sm_resp;
  100|  2.15k|	int r;
  101|       |
  102|  2.15k|	if (!apdu)
  ------------------
  |  Branch (102:6): [True: 0, False: 2.15k]
  ------------------
  103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  104|  2.15k|	else if (!resp_data || !resp_len)
  ------------------
  |  Branch (104:11): [True: 0, False: 2.15k]
  |  Branch (104:25): [True: 0, False: 2.15k]
  ------------------
  105|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  106|       |
  107|  2.15k|	memset(&sm_resp, 0, sizeof(sm_resp));
  108|  2.15k|	r = sc_sm_parse_answer(card, resp_data, resp_len, &sm_resp);
  109|  2.15k|	if (r)
  ------------------
  |  Branch (109:6): [True: 1.95k, False: 197]
  ------------------
  110|  1.95k|		return r;
  111|       |
  112|    197|	if (sm_resp.mac_len)   {
  ------------------
  |  Branch (112:6): [True: 97, False: 100]
  ------------------
  113|     97|		if (sm_resp.mac_len > sizeof(apdu->mac))
  ------------------
  |  Branch (113:7): [True: 0, False: 97]
  ------------------
  114|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  115|     97|		memcpy(apdu->mac, sm_resp.mac, sm_resp.mac_len);
  116|     97|		apdu->mac_len = sm_resp.mac_len;
  117|     97|	}
  118|       |
  119|    197|	apdu->sw1 = sm_resp.sw1;
  120|    197|	apdu->sw2 = sm_resp.sw2;
  121|       |
  122|    197|	return SC_SUCCESS;
  ------------------
  |  |   28|    197|#define SC_SUCCESS				0
  ------------------
  123|    197|}
sc_sm_single_transmit:
  127|  2.18k|{
  128|  2.18k|	struct sc_context *ctx  = card->ctx;
  129|  2.18k|	struct sc_apdu *sm_apdu = NULL;
  130|  2.18k|	int rv;
  131|       |
  132|  2.18k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  133|  2.18k|	sc_log(ctx, "SM_MODE:%X", card->sm_ctx.sm_mode);
  ------------------
  |  |   71|  2.18k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  134|  2.18k|	if (!card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (134:6): [True: 0, False: 2.18k]
  |  Branch (134:39): [True: 0, False: 2.18k]
  ------------------
  135|  2.18k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  136|       |
  137|       |	/* get SM encoded APDU */
  138|  2.18k|	rv = card->sm_ctx.ops.get_sm_apdu(card, apdu, &sm_apdu);
  139|  2.18k|	if (rv == SC_ERROR_SM_NOT_APPLIED)   {
  ------------------
  |  |  125|  2.18k|#define SC_ERROR_SM_NOT_APPLIED			-1610
  ------------------
  |  Branch (139:6): [True: 0, False: 2.18k]
  ------------------
  140|       |		/* SM wrap of this APDU is ignored by card driver.
  141|       |		 * Send plain APDU to the reader driver */
  142|      0|		rv = card->reader->ops->transmit(card->reader, apdu);
  143|      0|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|  2.18k|	} else {
  145|  2.18k|		if (rv < 0)
  ------------------
  |  Branch (145:7): [True: 0, False: 2.18k]
  ------------------
  146|      0|			sc_sm_stop(card);
  147|  2.18k|	}
  148|  2.18k|	LOG_TEST_RET(ctx, rv, "get SM APDU error");
  ------------------
  |  |  174|  2.18k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.18k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.18k|	int _ret = (r); \
  |  |  |  |  168|  2.18k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.18k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  2.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  149|       |
  150|       |	/* check if SM APDU is still valid */
  151|  2.18k|	rv = sc_check_apdu(card, sm_apdu);
  152|  2.18k|	if (rv < 0)   {
  ------------------
  |  Branch (152:6): [True: 0, False: 2.18k]
  ------------------
  153|      0|		card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  154|      0|		sc_sm_stop(card);
  155|      0|		LOG_TEST_RET(ctx, rv, "cannot validate SM encoded APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|      0|	}
  157|       |
  158|       |	/* send APDU flagged as NO_SM */
  159|  2.18k|	sm_apdu->flags |= SC_APDU_FLAGS_NO_SM | SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  314|  2.18k|#define SC_APDU_FLAGS_NO_SM		0x00000008UL
  ------------------
              	sm_apdu->flags |= SC_APDU_FLAGS_NO_SM | SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|  2.18k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  160|  2.18k|	rv = sc_transmit_apdu(card, sm_apdu);
  161|  2.18k|	if (rv < 0) {
  ------------------
  |  Branch (161:6): [True: 14, False: 2.17k]
  ------------------
  162|     14|		card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  163|     14|		sc_sm_stop(card);
  164|     14|		LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|     14|	}
  166|       |
  167|       |	/* decode SM answer and free temporary SM related data */
  168|  2.17k|	rv = card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  169|  2.17k|	if (rv < 0)
  ------------------
  |  Branch (169:6): [True: 606, False: 1.56k]
  ------------------
  170|    606|		sc_sm_stop(card);
  171|       |
  172|  2.17k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.17k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.17k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.17k|	int _ret = r; \
  |  |  |  |  155|  2.17k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.17k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    606|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 606, False: 1.56k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.17k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.17k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.17k|	return _ret; \
  |  |  |  |  163|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  173|  2.17k|}
sc_sm_stop:
  177|    739|{
  178|    739|    int r = SC_SUCCESS;
  ------------------
  |  |   28|    739|#define SC_SUCCESS				0
  ------------------
  179|       |
  180|    739|    if (card) {
  ------------------
  |  Branch (180:9): [True: 739, False: 0]
  ------------------
  181|    739|        if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.47k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (181:13): [True: 620, False: 119]
  ------------------
  182|    620|                && card->sm_ctx.ops.close)
  ------------------
  |  Branch (182:20): [True: 0, False: 620]
  ------------------
  183|      0|            r = card->sm_ctx.ops.close(card);
  184|    739|        card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    739|#define SM_MODE_NONE		0x0
  ------------------
  185|    739|    }
  186|       |
  187|    739|    return r;
  188|    739|}

scconf_parse_token:
  251|   152k|{
  252|   152k|	scconf_item *item;
  253|   152k|	size_t len;
  254|       |
  255|   152k|	if (parser->error) {
  ------------------
  |  Branch (255:6): [True: 0, False: 152k]
  ------------------
  256|       |		/* fatal error */
  257|      0|		return;
  258|      0|	}
  259|   152k|	switch (token_type) {
  ------------------
  |  Branch (259:10): [True: 152k, False: 0]
  ------------------
  260|      0|	case TOKEN_TYPE_NEWLINE:
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  |  Branch (260:2): [True: 0, False: 152k]
  ------------------
  261|      0|		parser->line++;
  262|      0|		if (parser->last_token_type != TOKEN_TYPE_NEWLINE) {
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  |  Branch (262:7): [True: 0, False: 0]
  ------------------
  263|      0|			break;
  264|      0|		}
  265|       |		/* fall through - treat empty lines as comments */
  266|      0|	case TOKEN_TYPE_COMMENT:
  ------------------
  |  |   31|      0|#define TOKEN_TYPE_COMMENT	0
  ------------------
  |  Branch (266:2): [True: 0, False: 152k]
  ------------------
  267|      0|		item = scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_COMMENT);
  ------------------
  |  |   42|      0|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  268|      0|		if (!item) {
  ------------------
  |  Branch (268:7): [True: 0, False: 0]
  ------------------
  269|      0|			return;
  270|      0|		}
  271|      0|		item->value.comment = token ? strdup(token) : NULL;
  ------------------
  |  Branch (271:25): [True: 0, False: 0]
  ------------------
  272|      0|		break;
  273|  76.3k|	case TOKEN_TYPE_STRING:
  ------------------
  |  |   33|  76.3k|#define TOKEN_TYPE_STRING	2
  ------------------
  |  Branch (273:2): [True: 76.3k, False: 76.3k]
  ------------------
  274|  76.3k|		{
  275|  76.3k|			char *stoken = NULL;
  276|       |
  277|  76.3k|			if ((parser->state & (STATE_VALUE | STATE_SET)) ==
  ------------------
  |  |   37|  76.3k|#define STATE_VALUE	0x02
  ------------------
              			if ((parser->state & (STATE_VALUE | STATE_SET)) ==
  ------------------
  |  |   38|  76.3k|#define STATE_SET	0x10
  ------------------
  |  Branch (277:8): [True: 0, False: 76.3k]
  ------------------
  278|  76.3k|			    (STATE_VALUE | STATE_SET)) {
  ------------------
  |  |   37|  76.3k|#define STATE_VALUE	0x02
  ------------------
              			    (STATE_VALUE | STATE_SET)) {
  ------------------
  |  |   38|  76.3k|#define STATE_SET	0x10
  ------------------
  279|      0|				scconf_parse_warning_expect(parser, ";");
  280|      0|				scconf_parse_reset_state(parser);
  281|      0|			}
  282|  76.3k|			if (token && *token == '"') {
  ------------------
  |  Branch (282:8): [True: 76.3k, False: 0]
  |  Branch (282:17): [True: 0, False: 76.3k]
  ------------------
  283|       |				/* quoted string, remove them */
  284|      0|				token++;
  285|      0|				len = strlen(token);
  286|      0|				if (len < 1 || token[len - 1] != '"') {
  ------------------
  |  Branch (286:9): [True: 0, False: 0]
  |  Branch (286:20): [True: 0, False: 0]
  ------------------
  287|      0|					scconf_parse_warning_expect(parser, "\"");
  288|      0|				} else {
  289|       |					/* stoken */
  290|      0|					stoken = strdup(token);
  291|      0|					if (stoken) {
  ------------------
  |  Branch (291:10): [True: 0, False: 0]
  ------------------
  292|      0|						stoken[len - 1] = '\0';
  293|      0|					}
  294|      0|				}
  295|      0|			}
  296|  76.3k|			if (!stoken) {
  ------------------
  |  Branch (296:8): [True: 76.3k, False: 0]
  ------------------
  297|  76.3k|				stoken = token ? strdup(token) : NULL;
  ------------------
  |  Branch (297:14): [True: 76.3k, False: 0]
  ------------------
  298|  76.3k|			}
  299|  76.3k|			if (parser->state == 0) {
  ------------------
  |  Branch (299:8): [True: 30.5k, False: 45.7k]
  ------------------
  300|       |				/* key */
  301|  30.5k|				parser->key = stoken ? strdup(stoken) : NULL;
  ------------------
  |  Branch (301:19): [True: 30.5k, False: 0]
  ------------------
  302|  30.5k|				parser->state = STATE_NAME;
  ------------------
  |  |   36|  30.5k|#define STATE_NAME	0x01
  ------------------
  303|  45.7k|			} else if (parser->state == STATE_NAME) {
  ------------------
  |  |   36|  45.7k|#define STATE_NAME	0x01
  ------------------
  |  Branch (303:15): [True: 15.2k, False: 30.5k]
  ------------------
  304|       |				/* name */
  305|  15.2k|				parser->state |= STATE_SET;
  ------------------
  |  |   38|  15.2k|#define STATE_SET	0x10
  ------------------
  306|  15.2k|				scconf_list_add(&parser->name, stoken);
  307|  30.5k|			} else if (parser->state == STATE_VALUE && parser->current_item->type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   37|  61.0k|#define STATE_VALUE	0x02
  ------------------
              			} else if (parser->state == STATE_VALUE && parser->current_item->type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   44|  30.5k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (307:15): [True: 30.5k, False: 0]
  |  Branch (307:47): [True: 30.5k, False: 0]
  ------------------
  308|       |				/* value */
  309|  30.5k|				parser->state |= STATE_SET;
  ------------------
  |  |   38|  30.5k|#define STATE_SET	0x10
  ------------------
  310|  30.5k|				scconf_list_add(&parser->current_item->value.list,
  311|  30.5k|						      stoken);
  312|  30.5k|			} else {
  313|       |				/* error */
  314|      0|				scconf_parse_error_not_expect(parser, stoken);
  315|      0|			}
  316|  76.3k|			if (stoken) {
  ------------------
  |  Branch (316:8): [True: 76.3k, False: 0]
  ------------------
  317|  76.3k|				free(stoken);
  318|  76.3k|			}
  319|  76.3k|			stoken = NULL;
  320|  76.3k|		}
  321|  76.3k|		break;
  322|  76.3k|	case TOKEN_TYPE_PUNCT:
  ------------------
  |  |   34|  76.3k|#define TOKEN_TYPE_PUNCT	3
  ------------------
  |  Branch (322:2): [True: 76.3k, False: 76.3k]
  ------------------
  323|  76.3k|		switch (*token) {
  324|  15.2k|		case '{':
  ------------------
  |  Branch (324:3): [True: 15.2k, False: 61.0k]
  ------------------
  325|  15.2k|			if ((parser->state & STATE_NAME) == 0) {
  ------------------
  |  |   36|  15.2k|#define STATE_NAME	0x01
  ------------------
  |  Branch (325:8): [True: 0, False: 15.2k]
  ------------------
  326|      0|				scconf_parse_error_not_expect(parser, "{");
  327|      0|				break;
  328|      0|			}
  329|  15.2k|			parser->nested_blocks++;
  330|  15.2k|			scconf_block_add_internal(parser);
  331|  15.2k|			scconf_parse_reset_state(parser);
  332|  15.2k|			break;
  333|  15.2k|		case '}':
  ------------------
  |  Branch (333:3): [True: 15.2k, False: 61.0k]
  ------------------
  334|  15.2k|			parser->nested_blocks--;
  335|  15.2k|			if (parser->state != 0) {
  ------------------
  |  Branch (335:8): [True: 0, False: 15.2k]
  ------------------
  336|      0|				if ((parser->state & STATE_VALUE) == 0 ||
  ------------------
  |  |   37|      0|#define STATE_VALUE	0x02
  ------------------
  |  Branch (336:9): [True: 0, False: 0]
  ------------------
  337|      0|				    (parser->state & STATE_SET) == 0) {
  ------------------
  |  |   38|      0|#define STATE_SET	0x10
  ------------------
  |  Branch (337:9): [True: 0, False: 0]
  ------------------
  338|      0|					scconf_parse_error_not_expect(parser,
  339|      0|								      "}");
  340|      0|					break;
  341|      0|				}
  342|       |				/* foo = bar } */
  343|      0|				scconf_parse_warning_expect(parser, ";");
  344|      0|				scconf_parse_reset_state(parser);
  345|      0|			}
  346|  15.2k|			if (!parser->block->parent) {
  ------------------
  |  Branch (346:8): [True: 0, False: 15.2k]
  ------------------
  347|       |				/* too many '}' */
  348|      0|				scconf_parse_error(parser,
  349|      0|						   "missing matching '{'");
  350|      0|				break;
  351|      0|			}
  352|  15.2k|			scconf_parse_parent(parser);
  353|  15.2k|			break;
  354|  15.2k|		case ',':
  ------------------
  |  Branch (354:3): [True: 15.2k, False: 61.0k]
  ------------------
  355|  15.2k|			if ((parser->state & (STATE_NAME | STATE_VALUE)) == 0) {
  ------------------
  |  |   36|  15.2k|#define STATE_NAME	0x01
  ------------------
              			if ((parser->state & (STATE_NAME | STATE_VALUE)) == 0) {
  ------------------
  |  |   37|  15.2k|#define STATE_VALUE	0x02
  ------------------
  |  Branch (355:8): [True: 0, False: 15.2k]
  ------------------
  356|      0|				scconf_parse_error_not_expect(parser, ",");
  357|      0|			}
  358|  15.2k|			parser->state &= ~STATE_SET;
  ------------------
  |  |   38|  15.2k|#define STATE_SET	0x10
  ------------------
  359|  15.2k|			break;
  360|  15.2k|		case '=':
  ------------------
  |  Branch (360:3): [True: 15.2k, False: 61.0k]
  ------------------
  361|  15.2k|			if ((parser->state & STATE_NAME) == 0) {
  ------------------
  |  |   36|  15.2k|#define STATE_NAME	0x01
  ------------------
  |  Branch (361:8): [True: 0, False: 15.2k]
  ------------------
  362|      0|				scconf_parse_error_not_expect(parser, "=");
  363|      0|				break;
  364|      0|			}
  365|  15.2k|			scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_VALUE);
  ------------------
  |  |   44|  15.2k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  366|  15.2k|			parser->state = STATE_VALUE;
  ------------------
  |  |   37|  15.2k|#define STATE_VALUE	0x02
  ------------------
  367|  15.2k|			break;
  368|  15.2k|		case ';':
  ------------------
  |  Branch (368:3): [True: 15.2k, False: 61.0k]
  ------------------
  369|  15.2k|			scconf_parse_reset_state(parser);
  370|  15.2k|			break;
  371|      0|		default:
  ------------------
  |  Branch (371:3): [True: 0, False: 76.3k]
  ------------------
  372|      0|			snprintf(parser->emesg, sizeof(parser->emesg),
  373|      0|				"Line %d: bad token ignoring\n",
  374|      0|				parser->line);
  375|  76.3k|		}
  376|  76.3k|		break;
  377|   152k|	}
  378|       |
  379|   152k|	parser->last_token_type = token_type;
  380|   152k|}
scconf_parse:
  383|  15.2k|{
  384|  15.2k|	static char buffer[256];
  385|  15.2k|	scconf_parser p;
  386|  15.2k|	int r = 1;
  387|       |
  388|  15.2k|	memset(&p, 0, sizeof(p));
  389|  15.2k|	p.config = config;
  390|  15.2k|	p.block = config->root;
  391|  15.2k|	p.line = 1;
  392|  15.2k|	p.nested_blocks = 0;
  393|       |
  394|  15.2k|	if (!scconf_lex_parse(&p, config->filename)) {
  ------------------
  |  Branch (394:6): [True: 15.2k, False: 0]
  ------------------
  395|  15.2k|		snprintf(buffer, sizeof(buffer),
  396|  15.2k|				"Unable to open \"%s\": %s",
  397|  15.2k|				config->filename, strerror(errno));
  398|  15.2k|		r = -1;
  399|  15.2k|	} else if (p.error) {
  ------------------
  |  Branch (399:13): [True: 0, False: 0]
  ------------------
  400|      0|		strlcpy(buffer, p.emesg, sizeof(buffer));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  401|      0|		r = 0;
  402|      0|	} else {
  403|      0|		r = 1;
  404|      0|	}
  405|       |
  406|  15.2k|	if (r <= 0)
  ------------------
  |  Branch (406:6): [True: 15.2k, False: 0]
  ------------------
  407|  15.2k|		config->errmsg = buffer;
  408|  15.2k|	return r;
  409|  15.2k|}
scconf_parse_string:
  412|  15.2k|{
  413|  15.2k|	static char buffer[256];
  414|  15.2k|	scconf_parser p;
  415|  15.2k|	int r;
  416|       |
  417|  15.2k|	memset(&p, 0, sizeof(p));
  418|  15.2k|	p.config = config;
  419|  15.2k|	p.block = config->root;
  420|  15.2k|	p.line = 1;
  421|  15.2k|	p.nested_blocks = 0;
  422|       |
  423|  15.2k|	if (!scconf_lex_parse_string(&p, string)) {
  ------------------
  |  Branch (423:6): [True: 0, False: 15.2k]
  ------------------
  424|      0|		snprintf(buffer, sizeof(buffer),
  425|      0|				"Failed to parse configuration string");
  426|      0|		r = -1;
  427|  15.2k|	} else if (p.error) {
  ------------------
  |  Branch (427:13): [True: 0, False: 15.2k]
  ------------------
  428|      0|		strlcpy(buffer, p.emesg, sizeof(buffer));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  429|      0|		r = 0;
  430|  15.2k|	} else {
  431|  15.2k|		r = 1;
  432|  15.2k|	}
  433|       |
  434|  15.2k|	scconf_parse_reset_state(&p);
  435|       |
  436|  15.2k|	if (r <= 0)
  ------------------
  |  Branch (436:6): [True: 0, False: 15.2k]
  ------------------
  437|      0|		config->errmsg = buffer;
  438|  15.2k|	return r;
  439|  15.2k|}
parse.c:scconf_item_add_internal:
   95|  30.5k|{
   96|  30.5k|	scconf_item *item;
   97|       |
   98|  30.5k|	if (type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   44|  30.5k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (98:6): [True: 15.2k, False: 15.2k]
  ------------------
   99|       |		/* if item with same key already exists, use it */
  100|  15.2k|		item = scconf_item_find(parser);
  101|  15.2k|		if (item) {
  ------------------
  |  Branch (101:7): [True: 0, False: 15.2k]
  ------------------
  102|      0|			free(parser->key);
  103|      0|			parser->key = NULL;
  104|      0|			parser->current_item = item;
  105|      0|			return item;
  106|      0|		}
  107|  15.2k|	}
  108|  30.5k|	item = calloc(1, sizeof(scconf_item));
  109|  30.5k|	if (!item) {
  ------------------
  |  Branch (109:6): [True: 0, False: 30.5k]
  ------------------
  110|      0|		return NULL;
  111|      0|	}
  112|  30.5k|	item->type = type;
  113|       |
  114|  30.5k|	item->key = parser->key;
  115|  30.5k|	parser->key = NULL;
  116|       |
  117|  30.5k|	if (parser->last_item) {
  ------------------
  |  Branch (117:6): [True: 0, False: 30.5k]
  ------------------
  118|      0|		parser->last_item->next = item;
  119|  30.5k|	} else {
  120|  30.5k|		parser->block->items = item;
  121|  30.5k|	}
  122|  30.5k|	parser->current_item = parser->last_item = item;
  123|  30.5k|	return item;
  124|  30.5k|}
parse.c:scconf_item_find:
   81|  15.2k|{
   82|  15.2k|	scconf_item *item;
   83|       |
   84|  15.2k|	for (item = parser->block->items; item; item = item->next) {
  ------------------
  |  Branch (84:36): [True: 0, False: 15.2k]
  ------------------
   85|      0|		if (item && item->type == SCCONF_ITEM_TYPE_VALUE
  ------------------
  |  |   44|      0|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (85:7): [True: 0, False: 0]
  |  Branch (85:15): [True: 0, False: 0]
  ------------------
   86|      0|			   	&& item->key && parser->key
  ------------------
  |  Branch (86:11): [True: 0, False: 0]
  |  Branch (86:24): [True: 0, False: 0]
  ------------------
   87|      0|			   	&& strcasecmp(item->key, parser->key) == 0) {
  ------------------
  |  Branch (87:11): [True: 0, False: 0]
  ------------------
   88|      0|			return item;
   89|      0|		}
   90|      0|	}
   91|  15.2k|	return item;
   92|  15.2k|}
parse.c:scconf_block_add_internal:
  173|  15.2k|{
  174|  15.2k|	scconf_block *block;
  175|  15.2k|	scconf_item *item;
  176|       |
  177|  15.2k|	item = scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_BLOCK);
  ------------------
  |  |   43|  15.2k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  178|  15.2k|	if (!item) {
  ------------------
  |  Branch (178:6): [True: 0, False: 15.2k]
  ------------------
  179|      0|		return;
  180|      0|	}
  181|       |
  182|  15.2k|	block = calloc(1, sizeof(scconf_block));
  183|  15.2k|	if (!block) {
  ------------------
  |  Branch (183:6): [True: 0, False: 15.2k]
  ------------------
  184|      0|		return;
  185|      0|	}
  186|  15.2k|	block->parent = parser->block;
  187|  15.2k|	item->value.block = block;
  188|       |
  189|  15.2k|	if (!parser->name) {
  ------------------
  |  Branch (189:6): [True: 0, False: 15.2k]
  ------------------
  190|      0|		scconf_list_add(&parser->name, "");
  191|      0|	}
  192|  15.2k|	block->name = parser->name;
  193|  15.2k|	parser->name = NULL;
  194|       |
  195|  15.2k|	parser->block = block;
  196|       |	parser->last_item = NULL;
  197|  15.2k|}
parse.c:scconf_parse_reset_state:
  231|  45.7k|{
  232|  45.7k|	if (parser) {
  ------------------
  |  Branch (232:6): [True: 45.7k, False: 0]
  ------------------
  233|  45.7k|		if (parser->key) {
  ------------------
  |  Branch (233:7): [True: 0, False: 45.7k]
  ------------------
  234|      0|			free(parser->key);
  235|      0|		}
  236|  45.7k|		scconf_list_destroy(parser->name);
  237|       |
  238|  45.7k|		parser->key = NULL;
  239|       |		parser->name = NULL;
  240|  45.7k|		parser->state = 0;
  241|  45.7k|	}
  242|  45.7k|}
parse.c:scconf_parse_parent:
  219|  15.2k|{
  220|  15.2k|	parser->block = parser->block->parent;
  221|       |
  222|  15.2k|	parser->last_item = parser->block->items;
  223|  15.2k|	if (parser->last_item) {
  ------------------
  |  Branch (223:6): [True: 15.2k, False: 0]
  ------------------
  224|  15.2k|		while (parser->last_item->next) {
  ------------------
  |  Branch (224:10): [True: 0, False: 15.2k]
  ------------------
  225|      0|			parser->last_item = parser->last_item->next;
  226|      0|		}
  227|  15.2k|	}
  228|  15.2k|}

scconf_new:
   37|  15.2k|{
   38|  15.2k|	scconf_context *config;
   39|       |
   40|  15.2k|	config = calloc(1, sizeof(scconf_context));
   41|  15.2k|	if (!config) {
  ------------------
  |  Branch (41:6): [True: 0, False: 15.2k]
  ------------------
   42|      0|		return NULL;
   43|      0|	}
   44|  15.2k|	config->filename = filename ? strdup(filename) : NULL;
  ------------------
  |  Branch (44:21): [True: 15.2k, False: 0]
  ------------------
   45|  15.2k|	config->root = calloc(1, sizeof(scconf_block));
   46|  15.2k|	if (!config->root) {
  ------------------
  |  Branch (46:6): [True: 0, False: 15.2k]
  ------------------
   47|      0|		if (config->filename) {
  ------------------
  |  Branch (47:7): [True: 0, False: 0]
  ------------------
   48|      0|			free(config->filename);
   49|      0|		}
   50|      0|		free(config);
   51|      0|		return NULL;
   52|      0|	}
   53|  15.2k|	return config;
   54|  15.2k|}
scconf_free:
   57|  15.2k|{
   58|  15.2k|	if (config) {
  ------------------
  |  Branch (58:6): [True: 15.2k, False: 0]
  ------------------
   59|  15.2k|		scconf_block_destroy(config->root);
   60|  15.2k|		if (config->filename) {
  ------------------
  |  Branch (60:7): [True: 15.2k, False: 0]
  ------------------
   61|  15.2k|			free(config->filename);
   62|  15.2k|		}
   63|  15.2k|		free(config);
   64|  15.2k|	}
   65|  15.2k|}
scconf_find_blocks:
   87|   806k|{
   88|   806k|	scconf_block **blocks = NULL, **tmp;
   89|   806k|	int alloc_size, size;
   90|   806k|	scconf_item *item;
   91|       |
   92|   806k|	if (!block) {
  ------------------
  |  Branch (92:6): [True: 45.7k, False: 760k]
  ------------------
   93|  45.7k|		block = config->root;
   94|  45.7k|	}
   95|   806k|	if (!item_name) {
  ------------------
  |  Branch (95:6): [True: 0, False: 806k]
  ------------------
   96|      0|		return NULL;
   97|      0|	}
   98|   806k|	size = 0;
   99|   806k|	alloc_size = 10;
  100|   806k|	tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
  101|   806k|	if (!tmp) {
  ------------------
  |  Branch (101:6): [True: 0, False: 806k]
  ------------------
  102|      0|		free(blocks);
  103|      0|		return NULL;
  104|      0|	}
  105|   806k|	blocks = tmp;
  106|       |
  107|  1.61M|	for (item = block->items; item; item = item->next) {
  ------------------
  |  Branch (107:28): [True: 806k, False: 806k]
  ------------------
  108|   806k|		if (item->type == SCCONF_ITEM_TYPE_BLOCK &&
  ------------------
  |  |   43|  1.61M|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (108:7): [True: 45.7k, False: 760k]
  ------------------
  109|  45.7k|		    strcasecmp(item_name, item->key) == 0) {
  ------------------
  |  Branch (109:7): [True: 45.7k, False: 0]
  ------------------
  110|  45.7k|			if (!item->value.block)
  ------------------
  |  Branch (110:8): [True: 0, False: 45.7k]
  ------------------
  111|      0|				continue;
  112|  45.7k|			if (key && strcasecmp(key, item->value.block->name->data)) {
  ------------------
  |  Branch (112:8): [True: 45.7k, False: 0]
  |  Branch (112:15): [True: 30.5k, False: 15.2k]
  ------------------
  113|  30.5k|				continue;
  114|  30.5k|			}
  115|  15.2k|			if (size + 1 >= alloc_size) {
  ------------------
  |  Branch (115:8): [True: 0, False: 15.2k]
  ------------------
  116|      0|				alloc_size *= 2;
  117|      0|				tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
  118|      0|				if (!tmp) {
  ------------------
  |  Branch (118:9): [True: 0, False: 0]
  ------------------
  119|      0|					free(blocks);
  120|      0|					return NULL;
  121|      0|				}
  122|      0|				blocks = tmp;
  123|      0|			}
  124|  15.2k|			blocks[size++] = item->value.block;
  125|  15.2k|		}
  126|   806k|	}
  127|   806k|	blocks[size] = NULL;
  128|   806k|	return blocks;
  129|   806k|}
scconf_find_list:
  132|   130k|{
  133|   130k|	scconf_item *item;
  134|       |
  135|   130k|	if (!block)
  ------------------
  |  Branch (135:6): [True: 23.8k, False: 106k]
  ------------------
  136|  23.8k|		return NULL;
  137|       |
  138|   198k|	for (item = block->items; item; item = item->next)
  ------------------
  |  Branch (138:28): [True: 106k, False: 91.5k]
  ------------------
  139|   106k|		if (item->type == SCCONF_ITEM_TYPE_VALUE && strcasecmp(option, item->key) == 0)
  ------------------
  |  |   44|   213k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (139:7): [True: 106k, False: 0]
  |  Branch (139:47): [True: 15.2k, False: 91.5k]
  ------------------
  140|  15.2k|			return item->value.list;
  141|  91.5k|	return NULL;
  142|   106k|}
scconf_get_str:
  145|  30.5k|{
  146|  30.5k|	const scconf_list *list;
  147|       |
  148|  30.5k|	list = scconf_find_list(block, option);
  149|  30.5k|	if (!list)
  ------------------
  |  Branch (149:6): [True: 30.5k, False: 0]
  ------------------
  150|  30.5k|		return def;
  151|       |
  152|       |	/* ignore non 'auto-configured' values */
  153|      0|	if (*list->data == '@' && *(list->data + strlen(list->data) - 1) == '@')
  ------------------
  |  Branch (153:6): [True: 0, False: 0]
  |  Branch (153:28): [True: 0, False: 0]
  ------------------
  154|      0|		return def;
  155|       |
  156|      0|	return list->data;
  157|      0|}
scconf_get_int:
  160|  15.2k|{
  161|  15.2k|	const scconf_list *list;
  162|  15.2k|	long res;
  163|       |
  164|  15.2k|	list = scconf_find_list(block, option);
  165|  15.2k|	if (!list) {
  ------------------
  |  Branch (165:6): [True: 15.2k, False: 0]
  ------------------
  166|  15.2k|		return def;
  167|  15.2k|	}
  168|      0|	res = strtol(list->data, NULL, 0);
  169|      0|	if (res <= INT_MAX) {
  ------------------
  |  Branch (169:6): [True: 0, False: 0]
  ------------------
  170|      0|		return (int)res;
  171|      0|	}
  172|      0|	return def;
  173|      0|}
scconf_get_bool:
  176|  69.6k|{
  177|  69.6k|	const scconf_list *list;
  178|       |
  179|  69.6k|	list = scconf_find_list(block, option);
  180|  69.6k|	if (!list) {
  ------------------
  |  Branch (180:6): [True: 69.6k, False: 0]
  ------------------
  181|  69.6k|		return def;
  182|  69.6k|	}
  183|      0|	return toupper((int) *list->data) == 'T' || toupper((int) *list->data) == 'Y';
  ------------------
  |  Branch (183:9): [True: 0, False: 0]
  |  Branch (183:46): [True: 0, False: 0]
  ------------------
  184|  69.6k|}
scconf_item_destroy:
  257|  30.5k|{
  258|  30.5k|	scconf_item *next;
  259|       |
  260|  61.0k|	while (item) {
  ------------------
  |  Branch (260:9): [True: 30.5k, False: 30.5k]
  ------------------
  261|  30.5k|		next = item->next;
  262|       |
  263|  30.5k|		switch (item->type) {
  ------------------
  |  Branch (263:11): [True: 30.5k, False: 0]
  ------------------
  264|      0|		case SCCONF_ITEM_TYPE_COMMENT:
  ------------------
  |  |   42|      0|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  |  Branch (264:3): [True: 0, False: 30.5k]
  ------------------
  265|      0|			if (item->value.comment) {
  ------------------
  |  Branch (265:8): [True: 0, False: 0]
  ------------------
  266|      0|				free(item->value.comment);
  267|      0|			}
  268|      0|			item->value.comment = NULL;
  269|      0|			break;
  270|  15.2k|		case SCCONF_ITEM_TYPE_BLOCK:
  ------------------
  |  |   43|  15.2k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (270:3): [True: 15.2k, False: 15.2k]
  ------------------
  271|  15.2k|			scconf_block_destroy(item->value.block);
  272|  15.2k|			break;
  273|  15.2k|		case SCCONF_ITEM_TYPE_VALUE:
  ------------------
  |  |   44|  15.2k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (273:3): [True: 15.2k, False: 15.2k]
  ------------------
  274|  15.2k|			scconf_list_destroy(item->value.list);
  275|  15.2k|			break;
  276|  30.5k|		}
  277|       |
  278|  30.5k|		if (item->key) {
  ------------------
  |  Branch (278:7): [True: 30.5k, False: 0]
  ------------------
  279|  30.5k|			free(item->key);
  280|  30.5k|		}
  281|       |		item->key = NULL;
  282|  30.5k|		free(item);
  283|  30.5k|		item = next;
  284|  30.5k|	}
  285|  30.5k|}
scconf_block_destroy:
  310|  30.5k|{
  311|  30.5k|	if (block) {
  ------------------
  |  Branch (311:6): [True: 30.5k, False: 0]
  ------------------
  312|  30.5k|		scconf_list_destroy(block->name);
  313|  30.5k|		scconf_item_destroy(block->items);
  314|  30.5k|		free(block);
  315|  30.5k|	}
  316|  30.5k|}
scconf_list_add:
  319|  45.7k|{
  320|  45.7k|	scconf_list *rec, **tmp;
  321|       |
  322|  45.7k|	rec = calloc(1, sizeof(scconf_list));
  323|  45.7k|	if (!rec) {
  ------------------
  |  Branch (323:6): [True: 0, False: 45.7k]
  ------------------
  324|      0|		return NULL;
  325|      0|	}
  326|  45.7k|	rec->data = value ? strdup(value) : NULL;
  ------------------
  |  Branch (326:14): [True: 45.7k, False: 0]
  ------------------
  327|       |
  328|  45.7k|	if (!*list) {
  ------------------
  |  Branch (328:6): [True: 30.5k, False: 15.2k]
  ------------------
  329|  30.5k|		*list = rec;
  330|  30.5k|	} else {
  331|  30.5k|		for (tmp = list; *tmp; tmp = &(*tmp)->next);
  ------------------
  |  Branch (331:20): [True: 15.2k, False: 15.2k]
  ------------------
  332|  15.2k|		*tmp = rec;
  333|  15.2k|	}
  334|  45.7k|	return rec;
  335|  45.7k|}
scconf_list_destroy:
  350|  91.5k|{
  351|  91.5k|	scconf_list *next;
  352|       |
  353|   137k|	while (list) {
  ------------------
  |  Branch (353:9): [True: 45.7k, False: 91.5k]
  ------------------
  354|  45.7k|		next = list->next;
  355|  45.7k|		if (list->data) {
  ------------------
  |  Branch (355:7): [True: 45.7k, False: 0]
  ------------------
  356|  45.7k|			free(list->data);
  357|  45.7k|		}
  358|  45.7k|		free(list);
  359|  45.7k|		list = next;
  360|  45.7k|	}
  361|  91.5k|}

scconf_lex_parse:
  181|  15.2k|{
  182|  15.2k|	FILE *fp;
  183|  15.2k|	BUFHAN bhan;
  184|  15.2k|	int ret;
  185|       |
  186|  15.2k|	fp = fopen(filename, "r");
  187|  15.2k|	if (!fp) {
  ------------------
  |  Branch (187:6): [True: 15.2k, False: 0]
  ------------------
  188|  15.2k|		parser->error = 1;
  189|  15.2k|		snprintf(parser->emesg, sizeof(parser->emesg),
  190|  15.2k|			 "File %s can't be opened\n", filename);
  191|  15.2k|		return 0;
  192|  15.2k|	}
  193|      0|	buf_init(&bhan, fp, (char *) NULL);
  194|      0|	ret = scconf_lex_engine(parser, &bhan);
  195|      0|	fclose(fp);
  196|      0|	return ret;
  197|  15.2k|}
scconf_lex_parse_string:
  200|  15.2k|{
  201|  15.2k|	BUFHAN bhan;
  202|  15.2k|	int ret;
  203|       |
  204|       |	buf_init(&bhan, (FILE *) NULL, string);
  205|  15.2k|	ret = scconf_lex_engine(parser, &bhan);
  206|  15.2k|	return ret;
  207|  15.2k|}
sclex.c:buf_init:
   44|  15.2k|{
   45|  15.2k|	bp->fp = fp;
   46|  15.2k|	bp->saved_char = 0;
   47|  15.2k|	bp->buf = malloc(256);
   48|  15.2k|	if (bp->buf) {
  ------------------
  |  Branch (48:6): [True: 15.2k, False: 0]
  ------------------
   49|  15.2k|		bp->bufmax = 256;
   50|  15.2k|		bp->buf[0] = '\0';
   51|  15.2k|	} else
   52|      0|		bp->bufmax = 0;
   53|  15.2k|	bp->bufcur = 0;
   54|  15.2k|	bp->saved_string = saved_string;
   55|  15.2k|}
sclex.c:scconf_lex_engine:
  126|  15.2k|{
  127|  15.2k|	int this_char;
  128|       |
  129|   274k|	while (1) {
  ------------------
  |  Branch (129:9): [True: 274k, Folded]
  ------------------
  130|   274k|		switch (this_char = buf_nextch(bp)) {
  131|      0|		case '#':
  ------------------
  |  Branch (131:3): [True: 0, False: 274k]
  ------------------
  132|       |			/* comment till end of line */
  133|      0|			buf_eat_till(bp, '#', "\r\n");
  134|      0|			scconf_parse_token(parser, TOKEN_TYPE_COMMENT, bp->buf);
  ------------------
  |  |   31|      0|#define TOKEN_TYPE_COMMENT	0
  ------------------
  135|      0|			buf_zero(bp);
  136|      0|			continue;
  137|      0|		case '\n':
  ------------------
  |  Branch (137:3): [True: 0, False: 274k]
  ------------------
  138|      0|			scconf_parse_token(parser, TOKEN_TYPE_NEWLINE, NULL);
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  139|      0|			continue;
  140|   106k|		case ' ':
  ------------------
  |  Branch (140:3): [True: 106k, False: 167k]
  ------------------
  141|   106k|		case '\t':
  ------------------
  |  Branch (141:3): [True: 0, False: 274k]
  ------------------
  142|   106k|		case '\r':
  ------------------
  |  Branch (142:3): [True: 0, False: 274k]
  ------------------
  143|       |			/* eat up whitespace */
  144|   106k|			continue;
  145|  15.2k|		case ',':
  ------------------
  |  Branch (145:3): [True: 15.2k, False: 259k]
  ------------------
  146|  30.5k|		case '{':
  ------------------
  |  Branch (146:3): [True: 15.2k, False: 259k]
  ------------------
  147|  30.5k|			if (parser->nested_blocks >= DEPTH_LIMIT) {
  ------------------
  |  |   36|  30.5k|#define DEPTH_LIMIT 16
  ------------------
  |  Branch (147:8): [True: 0, False: 30.5k]
  ------------------
  148|       |				/* reached the limit, this whole block */
  149|      0|				scconf_skip_block(parser);
  150|      0|				continue;
  151|      0|			}
  152|       |			/* fall through */
  153|  45.7k|		case '}':
  ------------------
  |  Branch (153:3): [True: 15.2k, False: 259k]
  ------------------
  154|  61.0k|		case '=':
  ------------------
  |  Branch (154:3): [True: 15.2k, False: 259k]
  ------------------
  155|  76.3k|		case ';':
  ------------------
  |  Branch (155:3): [True: 15.2k, False: 259k]
  ------------------
  156|  76.3k|			buf_addch(bp, (char) this_char);
  157|  76.3k|			scconf_parse_token(parser, TOKEN_TYPE_PUNCT, bp->buf);
  ------------------
  |  |   34|  76.3k|#define TOKEN_TYPE_PUNCT	3
  ------------------
  158|  76.3k|			buf_zero(bp);
  159|  76.3k|			continue;
  160|      0|		case '"':
  ------------------
  |  Branch (160:3): [True: 0, False: 274k]
  ------------------
  161|      0|			buf_eat_till(bp, (char) this_char, "\"\r\n");
  162|      0|			buf_addch(bp, (char) buf_nextch(bp));
  163|      0|			scconf_parse_token(parser, TOKEN_TYPE_STRING, bp->buf);
  ------------------
  |  |   33|      0|#define TOKEN_TYPE_STRING	2
  ------------------
  164|      0|			buf_zero(bp);
  165|      0|			continue;
  166|  15.2k|		case EOF:
  ------------------
  |  Branch (166:3): [True: 15.2k, False: 259k]
  ------------------
  167|  15.2k|			break;
  168|  76.3k|		default:
  ------------------
  |  Branch (168:3): [True: 76.3k, False: 198k]
  ------------------
  169|  76.3k|			buf_eat_till(bp, (char) this_char, ";, \t\r\n");
  170|  76.3k|			scconf_parse_token(parser, TOKEN_TYPE_STRING, bp->buf);
  ------------------
  |  |   33|  76.3k|#define TOKEN_TYPE_STRING	2
  ------------------
  171|  76.3k|			buf_zero(bp);
  172|  76.3k|			continue;
  173|   274k|		}
  174|  15.2k|		break;
  175|   274k|	}
  176|  15.2k|	buf_finished(bp);
  177|  15.2k|	return 1;
  178|  15.2k|}
sclex.c:buf_nextch:
   73|   778k|{
   74|   778k|	int saved;
   75|       |
   76|   778k|	if (bp->saved_char) {
  ------------------
  |  Branch (76:6): [True: 76.3k, False: 701k]
  ------------------
   77|  76.3k|		saved = bp->saved_char;
   78|  76.3k|		bp->saved_char = 0;
   79|  76.3k|		return saved;
   80|  76.3k|	}
   81|   701k|	if (bp->saved_string) {
  ------------------
  |  Branch (81:6): [True: 701k, False: 0]
  ------------------
   82|   701k|		if (*(bp->saved_string) == '\0')
  ------------------
  |  Branch (82:7): [True: 15.2k, False: 686k]
  ------------------
   83|  15.2k|			return EOF;
   84|   686k|		saved = (unsigned char) (*(bp->saved_string++));
   85|   686k|		return saved;
   86|   701k|	} else {
   87|      0|		saved = fgetc(bp->fp);
   88|      0|		return saved;
   89|      0|	}
   90|   701k|}
sclex.c:buf_eat_till:
  101|  76.3k|{
  102|  76.3k|	int i;
  103|       |
  104|  76.3k|	if (start) {
  ------------------
  |  Branch (104:6): [True: 76.3k, False: 0]
  ------------------
  105|  76.3k|		buf_addch(bp, start);
  106|  76.3k|	}
  107|   503k|	while (1) {
  ------------------
  |  Branch (107:9): [True: 503k, Folded]
  ------------------
  108|   503k|		i = buf_nextch(bp);
  109|   503k|		if (i == EOF)
  ------------------
  |  Branch (109:7): [True: 0, False: 503k]
  ------------------
  110|      0|			return;
  111|   503k|		if (strchr(end, i)) {
  ------------------
  |  Branch (111:7): [True: 76.3k, False: 427k]
  ------------------
  112|  76.3k|			bp->saved_char = i;
  113|  76.3k|			return;
  114|  76.3k|		}
  115|   427k|		buf_addch(bp, (char) i);
  116|   427k|	}
  117|  76.3k|}
sclex.c:buf_zero:
  120|   152k|{
  121|   152k|	bp->bufcur = 0;
  122|   152k|	bp->buf[0] = '\0';
  123|   152k|}
sclex.c:buf_addch:
   58|   579k|{
   59|   579k|	if (bp->bufcur + 1 >= bp->bufmax) {
  ------------------
  |  Branch (59:6): [True: 0, False: 579k]
  ------------------
   60|      0|		char *p = (char *) realloc(bp->buf, bp->bufmax + 256);
   61|      0|		if (!p)
  ------------------
  |  Branch (61:7): [True: 0, False: 0]
  ------------------
   62|      0|			return;
   63|      0|		bp->bufmax += 256;
   64|      0|		bp->buf = p;
   65|      0|	}
   66|   579k|	if (bp->buf) {
  ------------------
  |  Branch (66:6): [True: 579k, False: 0]
  ------------------
   67|   579k|		bp->buf[bp->bufcur++] = ch;
   68|   579k|		bp->buf[bp->bufcur] = '\0';
   69|   579k|	}
   70|   579k|}
sclex.c:buf_finished:
   93|  15.2k|{
   94|  15.2k|	if (bp->buf) {
  ------------------
  |  Branch (94:6): [True: 15.2k, False: 0]
  ------------------
   95|  15.2k|		free(bp->buf);
   96|       |		bp->buf = NULL;
   97|  15.2k|	}
   98|  15.2k|}

fuzz_util_connect_card:
   46|  15.2k|{
   47|  15.2k|	opt_output = NULL; /* Do not create new outputfile */
   48|       |	return fuzz_connect_card(ctx, card, NULL, reader_data, reader_data_size);
   49|  15.2k|}
initialize_global:
   52|  15.3k|{
   53|       |	/* Global variables need to be reser between runs,
   54|       |	   fuzz target is called repetitively in one execution */
   55|  15.3k|	verbose = 0, opt_wait = 0, opt_raw = 0;
   56|  15.3k|	opt_reader = NULL;
   57|  15.3k|	opt_pincode = NULL, opt_key_id = NULL;
   58|  15.3k|	opt_input = NULL, opt_output = NULL;
   59|  15.3k|	opt_bind_to_aid = NULL;
   60|  15.3k|	opt_sig_format = NULL;
   61|  15.3k|	opt_crypt_flags = 0;
   62|  15.3k|	ctx = NULL;
   63|  15.3k|	card = NULL;
   64|  15.3k|	p15card = NULL;
   65|       |
   66|  15.3k|	optind = 0;
   67|  15.3k|	opterr = 0;
   68|  15.3k|	optopt = 0;
   69|  15.3k|}
test_operation:
   73|  4.57k|{
   74|  4.57k|	char *argv[] = {"./fuzz_pkcs15_crypt", op, "-p", pin, "-i", filename,
   75|  4.57k|					hash, "-f", format, NULL, NULL, NULL, NULL, NULL, NULL};
   76|  4.57k|	int argc = 9;
   77|       |
   78|  4.57k|	if (aid) {
  ------------------
  |  Branch (78:6): [True: 282, False: 4.28k]
  ------------------
   79|    282|		argv[argc++] = "--aid";
   80|    282|		argv[argc++] = aid;
   81|    282|	}
   82|  4.57k|	if (id) {
  ------------------
  |  Branch (82:6): [True: 26, False: 4.54k]
  ------------------
   83|     26|		argv[argc++] = "-k";
   84|     26|		argv[argc++] = id;
   85|     26|	}
   86|  4.57k|	if (pad)
  ------------------
  |  Branch (86:6): [True: 2.29k, False: 2.27k]
  ------------------
   87|  2.29k|		argv[argc++] = "--pkcs1";
   88|       |
   89|  4.57k|	reader_data = data;
   90|  4.57k|	reader_data_size = size;
   91|  4.57k|	_main(argc, argv);
   92|  4.57k|}
LLVMFuzzerTestOneInput:
   95|  15.3k|{
   96|  15.3k|	uint8_t operation = 0;
   97|  15.3k|	uint8_t hash = 0;
   98|  15.3k|	char *hash_options[] = {"--md5", "--sha-1", "--sha-224", "--sha-256", "--sha-384", "--sha-512"};
   99|  15.3k|	uint8_t pad = 0;
  100|  15.3k|	uint8_t format = 0;
  101|  15.3k|	char *formats[] = {"rs", "sequence", "openssl"};
  102|  15.3k|	uint8_t aid = 0;
  103|  15.3k|	char *opt_aid = NULL;
  104|  15.3k|	uint8_t id = 0;
  105|  15.3k|	char *opt_id = NULL;
  106|  15.3k|	char *pin = NULL;
  107|  15.3k|	char *filename = NULL;
  108|       |
  109|  15.3k|	if (size < 15)
  ------------------
  |  Branch (109:6): [True: 6, False: 15.3k]
  ------------------
  110|      6|		return 0;
  111|       |
  112|  15.3k|#ifdef FUZZING_ENABLED
  113|  15.3k|	fclose(stdout);
  114|  15.3k|#endif
  115|       |
  116|  15.3k|	initialize_global();
  117|       |
  118|  15.3k|	operation = data[0] % 3;
  119|  15.3k|	data++; size--;
  120|       |
  121|  15.3k|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (121:6): [True: 2, False: 15.3k]
  ------------------
  122|      2|		return 0;
  123|       |
  124|  15.3k|	if (operation == 0) { /* test random arguments */
  ------------------
  |  Branch (124:6): [True: 10.7k, False: 4.59k]
  ------------------
  125|  10.7k|		char **argv = NULL;
  126|  10.7k|		int argc = 0;
  127|       |
  128|       |		/* setup pin and input file otherwise fuzz target waits for input from stdin */
  129|  10.7k|		opt_pincode = pin;
  130|  10.7k|		opt_input = "invalid_filename";
  131|       |
  132|  10.7k|		if (get_fuzzed_argv("./fuzz_pkcs15_crypt", data, size, &argv, &argc, &reader_data, &reader_data_size) != 0)
  ------------------
  |  Branch (132:7): [True: 2, False: 10.7k]
  ------------------
  133|      2|			goto err;
  134|  10.7k|		_main(argc, argv);
  135|  10.7k|		free_arguments(argc, argv);
  136|  10.7k|	} else {
  137|       |		/* Set options */
  138|  4.59k|		if (size < 5)
  ------------------
  |  Branch (138:7): [True: 3, False: 4.59k]
  ------------------
  139|      3|			goto err;
  140|  4.59k|		hash = data[0] % 6; data++; size--;
  141|  4.59k|		pad = data[0] % 2; data++; size--;
  142|  4.59k|		format = data[0] % 3; data++; size--;
  143|       |
  144|  4.59k|		aid = data[0] % 2; data++; size--;
  145|  4.59k|		if (aid) {
  ------------------
  |  Branch (145:7): [True: 286, False: 4.30k]
  ------------------
  146|    286|			if (!(opt_aid = extract_word(&data, &size)))
  ------------------
  |  Branch (146:8): [True: 1, False: 285]
  ------------------
  147|      1|				goto err;
  148|    286|		}
  149|  4.58k|		if (size < 3)
  ------------------
  |  Branch (149:7): [True: 1, False: 4.58k]
  ------------------
  150|      1|			goto err;
  151|       |
  152|  4.58k|		id = data[0] % 2; data++; size--;
  153|  4.58k|		if (id) {
  ------------------
  |  Branch (153:7): [True: 37, False: 4.55k]
  ------------------
  154|     37|			if (!(opt_id = extract_word(&data, &size)))
  ------------------
  |  Branch (154:8): [True: 1, False: 36]
  ------------------
  155|      1|				goto err;
  156|     37|		}
  157|       |
  158|  4.58k|		if (create_input_file(&filename, &data, &size) != 0)
  ------------------
  |  Branch (158:7): [True: 17, False: 4.57k]
  ------------------
  159|     17|			goto err;
  160|  4.57k|		test_operation(operation == 1 ? "-c" : "-s", pin, data, size, filename, hash_options[hash], formats[format], opt_aid, opt_id, pad);
  ------------------
  |  Branch (160:18): [True: 3.14k, False: 1.42k]
  ------------------
  161|       |
  162|  4.57k|		remove_file(filename);
  163|  4.57k|	}
  164|       |
  165|  15.3k|err:
  166|  15.3k|	free(pin);
  167|  15.3k|	free(opt_aid);
  168|  15.3k|	free(opt_id);
  169|  15.3k|	return 0;
  170|  15.3k|}

fuzz_get_chunk:
   36|   459k|{
   37|   459k|    struct driver_data *data;
   38|   459k|    uint16_t c_size;
   39|   459k|    const uint8_t *c;
   40|       |
   41|   459k|    if (chunk)
  ------------------
  |  Branch (41:9): [True: 459k, False: 0]
  ------------------
   42|   459k|        *chunk = NULL;
   43|   459k|    if (chunk_size)
  ------------------
  |  Branch (43:9): [True: 459k, False: 0]
  ------------------
   44|   459k|        *chunk_size = 0;
   45|       |
   46|   459k|    if (!chunk || !chunk_size || !reader) {
  ------------------
  |  Branch (46:9): [True: 0, False: 459k]
  |  Branch (46:19): [True: 0, False: 459k]
  |  Branch (46:34): [True: 0, False: 459k]
  ------------------
   47|      0|        if (reader)
  ------------------
  |  Branch (47:13): [True: 0, False: 0]
  ------------------
   48|      0|            sc_debug(reader->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Invalid Arguments");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   49|      0|        return;
   50|      0|    }
   51|   459k|    data = reader->drv_data;
   52|   459k|    if (!data || !data->Data || data->Size < sizeof c_size) {
  ------------------
  |  Branch (52:9): [True: 0, False: 459k]
  |  Branch (52:18): [True: 0, False: 459k]
  |  Branch (52:33): [True: 160k, False: 298k]
  ------------------
   53|   160k|        sc_debug(reader->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Invalid Arguments");
  ------------------
  |  |   70|   160k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   54|   160k|        return;
   55|   160k|    }
   56|       |    /* parse the length of the returned data on two bytes */
   57|   298k|    c_size = *((uint16_t *) data->Data);
   58|       |    /* consume two bytes from the fuzzing data */
   59|   298k|    data->Size -= sizeof c_size;
   60|   298k|    data->Data += sizeof c_size;
   61|       |
   62|   298k|    if (data->Size < c_size) {
  ------------------
  |  Branch (62:9): [True: 12.6k, False: 286k]
  ------------------
   63|  12.6k|        c_size = data->Size;
   64|  12.6k|    }
   65|       |
   66|       |    /* consume the bytes from the fuzzing data */
   67|   298k|    c = data->Data;
   68|   298k|    data->Size -= c_size;
   69|   298k|    data->Data += c_size;
   70|       |
   71|   298k|    sc_debug_hex(reader->ctx, SC_LOG_DEBUG_VERBOSE_TOOL,
  ------------------
  |  |  127|   298k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   72|   298k|        "Returning fuzzing chunk", c, c_size);
   73|       |
   74|   298k|    *chunk = c;
   75|   298k|    *chunk_size = c_size;
   76|   298k|}
sc_get_fuzz_driver:
  150|  15.2k|{
  151|  15.2k|    fuzz_ops.release = fuzz_reader_release;
  152|  15.2k|    fuzz_ops.connect = fuzz_reader_connect;
  153|  15.2k|    fuzz_ops.disconnect = fuzz_reader_disconnect;
  154|  15.2k|    fuzz_ops.transmit = fuzz_reader_transmit;
  155|  15.2k|    fuzz_ops.lock = fuzz_reader_lock;
  156|  15.2k|    fuzz_ops.unlock = fuzz_reader_unlock;
  157|  15.2k|    return &fuzz_drv;
  158|  15.2k|}
fuzz_add_reader:
  161|  15.2k|{
  162|  15.2k|    sc_reader_t	*reader;
  163|  15.2k|    struct driver_data *data;
  164|  15.2k|    char name[64] = {0};
  165|       |
  166|  15.2k|    if (!(reader = calloc(1, sizeof(*reader)))
  ------------------
  |  Branch (166:9): [True: 0, False: 15.2k]
  ------------------
  167|  15.2k|            || !(data = (calloc(1, sizeof(*data))))) {
  ------------------
  |  Branch (167:16): [True: 0, False: 15.2k]
  ------------------
  168|      0|        free(reader);
  169|      0|        return;
  170|      0|    }
  171|       |
  172|  15.2k|    data->Data = Data;
  173|  15.2k|    data->Size = Size;
  174|       |
  175|  15.2k|    reader->driver = &fuzz_drv;
  176|  15.2k|    reader->ops = &fuzz_ops;
  177|  15.2k|    reader->drv_data = data;
  178|  15.2k|    snprintf(name, sizeof name - 1, "%zu random byte%s reader (%p)",
  179|  15.2k|            Size, Size == 1 ? "" : "s", Data);
  ------------------
  |  Branch (179:19): [True: 8, False: 15.2k]
  ------------------
  180|  15.2k|    reader->name = strdup(name);
  181|       |
  182|  15.2k|    reader->ctx = ctx;
  183|  15.2k|    list_append(&ctx->readers, reader);
  184|  15.2k|}
fuzz_connect_card:
  188|  15.2k|{
  189|  15.2k|    struct sc_reader *reader = NULL;
  190|       |
  191|       |    /* Erase possible readers from ctx */
  192|  15.2k|    while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (192:12): [True: 0, False: 15.2k]
  ------------------
  193|      0|        sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
  194|      0|        _sc_delete_reader(ctx, rdr);
  195|      0|    }
  196|  15.2k|    if (ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (196:9): [True: 15.2k, False: 0]
  ------------------
  197|  15.2k|        ctx->reader_driver->ops->finish(ctx);
  198|       |
  199|       |    /* Create virtual reader */
  200|  15.2k|    ctx->reader_driver = sc_get_fuzz_driver();
  201|  15.2k|    fuzz_add_reader(ctx, data, size);
  202|  15.2k|    reader = sc_ctx_get_reader(ctx, 0);
  203|       |
  204|       |    /* Connect card */
  205|  15.2k|    if (sc_connect_card(reader, card))
  ------------------
  |  Branch (205:9): [True: 3.23k, False: 12.0k]
  ------------------
  206|  3.23k|        return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.23k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  207|       |
  208|  12.0k|    if (reader_out)
  ------------------
  |  Branch (208:9): [True: 0, False: 12.0k]
  ------------------
  209|      0|        *reader_out = reader;
  210|       |
  211|  12.0k|    return SC_SUCCESS;
  ------------------
  |  |   28|  12.0k|#define SC_SUCCESS				0
  ------------------
  212|  15.2k|}
fuzzer_reader.c:fuzz_reader_release:
   79|  15.2k|{
   80|  15.2k|    if (reader) {
  ------------------
  |  Branch (80:9): [True: 15.2k, False: 0]
  ------------------
   81|  15.2k|        free(reader->drv_data);
   82|  15.2k|        reader->drv_data = NULL;
   83|  15.2k|    }
   84|       |
   85|  15.2k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
   86|  15.2k|}
fuzzer_reader.c:fuzz_reader_connect:
   89|  15.2k|{
   90|  15.2k|    uint16_t chunk_size;
   91|  15.2k|    const uint8_t *chunk;
   92|       |
   93|  15.2k|    fuzz_get_chunk(reader, &chunk, &chunk_size);
   94|       |
   95|  15.2k|    if (chunk_size > SC_MAX_ATR_SIZE)
  ------------------
  |  |   41|  15.2k|#define SC_MAX_ATR_SIZE			33
  ------------------
  |  Branch (95:9): [True: 35, False: 15.2k]
  ------------------
   96|     35|        chunk_size = SC_MAX_ATR_SIZE;
  ------------------
  |  |   41|     35|#define SC_MAX_ATR_SIZE			33
  ------------------
   97|  15.2k|    else
   98|  15.2k|        reader->atr.len = chunk_size;
   99|       |
  100|  15.2k|    if (chunk_size > 0)
  ------------------
  |  Branch (100:9): [True: 10.3k, False: 4.90k]
  ------------------
  101|  10.3k|        memcpy(reader->atr.value, chunk, chunk_size);
  102|       |
  103|  15.2k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  104|  15.2k|}
fuzzer_reader.c:fuzz_reader_disconnect:
  107|  15.2k|{
  108|  15.2k|    return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  109|  15.2k|}
fuzzer_reader.c:fuzz_reader_transmit:
  112|   444k|{
  113|   444k|    const uint8_t *chunk;
  114|   444k|    uint16_t chunk_size;
  115|       |
  116|   444k|    fuzz_get_chunk(reader, &chunk, &chunk_size);
  117|       |
  118|   444k|    if (chunk_size >= 2) {
  ------------------
  |  Branch (118:9): [True: 207k, False: 237k]
  ------------------
  119|       |        /* set the SW1 and SW2 status bytes (the last two bytes of
  120|       |         * the response */
  121|   207k|        apdu->sw1 = (unsigned int)chunk[chunk_size - 2];
  122|   207k|        apdu->sw2 = (unsigned int)chunk[chunk_size - 1];
  123|   207k|        chunk_size -= 2;
  124|       |        /* set output length and copy the returned data if necessary */
  125|   207k|        if (chunk_size <= apdu->resplen)
  ------------------
  |  Branch (125:13): [True: 170k, False: 36.7k]
  ------------------
  126|   170k|            apdu->resplen = chunk_size;
  127|       |
  128|   207k|        if (apdu->resplen != 0)
  ------------------
  |  Branch (128:13): [True: 140k, False: 67.1k]
  ------------------
  129|   140k|            memcpy(apdu->resp, chunk, apdu->resplen);
  130|   237k|    } else {
  131|   237k|        apdu->sw1 = 0x6D;
  132|   237k|        apdu->sw2 = 0x00;
  133|   237k|        apdu->resplen = 0;
  134|   237k|    }
  135|       |
  136|   444k|    return SC_SUCCESS;
  ------------------
  |  |   28|   444k|#define SC_SUCCESS				0
  ------------------
  137|   444k|}
fuzzer_reader.c:fuzz_reader_lock:
  140|   289k|{
  141|   289k|    return 0;
  142|   289k|}
fuzzer_reader.c:fuzz_reader_unlock:
  145|   289k|{
  146|   289k|    return 0;
  147|   289k|}

get_word:
   26|   123k|{
   27|       |	/* Words are separated by one zero byte,
   28|       |	   return pointer to the next word if there is one */
   29|   123k|	const uint8_t *ptr = data;
   30|   123k|	if (!data || size == 0 || *data == 0)
  ------------------
  |  Branch (30:6): [True: 0, False: 123k]
  |  Branch (30:15): [True: 0, False: 123k]
  |  Branch (30:28): [True: 2, False: 123k]
  ------------------
   31|      2|		return NULL;
   32|       |	
   33|   123k|	ptr = memchr(data, 0, size - 1);
   34|   123k|	return ptr ? ++ptr : NULL;
  ------------------
  |  Branch (34:9): [True: 123k, False: 2]
  ------------------
   35|   123k|}
extract_word:
   38|  64.3k|{
   39|       |	/* Find word and return its copy (needs to be freed) */
   40|  64.3k|	char *result = NULL;
   41|  64.3k|	const uint8_t *ptr = NULL;
   42|       |
   43|  64.3k|	if (*size < 2)
  ------------------
  |  Branch (43:6): [True: 1, False: 64.3k]
  ------------------
   44|      1|		return NULL;
   45|       |
   46|  64.3k|	ptr = get_word(*data, *size);
   47|  64.3k|	if (!ptr)
  ------------------
  |  Branch (47:6): [True: 3, False: 64.3k]
  ------------------
   48|      3|		return NULL;
   49|  64.3k|	result = strdup((const char *)*data);
   50|  64.3k|	*size -=(ptr - *data);
   51|  64.3k|	*data = ptr;
   52|       |
   53|  64.3k|	return result;
   54|  64.3k|}
get_fuzzed_argv:
   58|  10.7k|{
   59|  10.7k|	const uint8_t *ptr = data, *help_ptr = data;
   60|  10.7k|	size_t ptr_size = size;
   61|  10.7k|	char **argv = NULL;
   62|  10.7k|	int argc = 1;
   63|       |
   64|       |	/* Count arguments until double zero bytes occurs*/
   65|  69.4k|	while(*ptr != 0) {
  ------------------
  |  Branch (65:8): [True: 58.6k, False: 10.7k]
  ------------------
   66|  58.6k|		ptr = get_word(help_ptr, ptr_size);
   67|  58.6k|		if (!ptr)
  ------------------
  |  Branch (67:7): [True: 1, False: 58.6k]
  ------------------
   68|      1|			return -1;
   69|  58.6k|		argc++;
   70|  58.6k|		ptr_size -= (ptr - help_ptr);
   71|  58.6k|		help_ptr = ptr;
   72|  58.6k|	}
   73|       |
   74|  10.7k|	if (argc > MAX_ARGC)
  ------------------
  |  |   23|  10.7k|#define MAX_ARGC 10000
  ------------------
  |  Branch (74:6): [True: 1, False: 10.7k]
  ------------------
   75|      1|		return -1;
   76|       |
   77|  10.7k|	argv = malloc((argc + 1) * sizeof(char*));
   78|  10.7k|	if (!argv)
  ------------------
  |  Branch (78:6): [True: 0, False: 10.7k]
  ------------------
   79|      0|		return -1;
   80|       |
   81|       |	/* Copy arguments into argv */
   82|  10.7k|	ptr = data;
   83|  10.7k|	ptr_size = size;
   84|  10.7k|	argv[0] = strdup(app_name);
   85|  59.4k|	for (int i = 1; i < argc; i++) {
  ------------------
  |  Branch (85:18): [True: 48.6k, False: 10.7k]
  ------------------
   86|  48.6k|		argv[i] = extract_word(&ptr, &ptr_size);
   87|  48.6k|	}
   88|  10.7k|	argv[argc] = NULL;
   89|       |
   90|  10.7k|	*argc_out = argc;
   91|  10.7k|	*argv_out = argv;
   92|  10.7k|	*reader_data = ptr + 1; /* there are two zero bytes at the end of argv */
   93|  10.7k|	*reader_data_size = ptr_size - 1;
   94|  10.7k|	return 0;
   95|  10.7k|}
get_buffer:
   98|  4.58k|{
   99|       |	/* Split buf into two parts according to length stored in first two bytes */
  100|  4.58k|	uint16_t len = 0;
  101|       |
  102|  4.58k|	if (!buf || !(*buf) || buf_len < sizeof(uint16_t))
  ------------------
  |  Branch (102:6): [True: 0, False: 4.58k]
  |  Branch (102:14): [True: 0, False: 4.58k]
  |  Branch (102:25): [True: 1, False: 4.58k]
  ------------------
  103|      1|		return 0;
  104|       |
  105|       |	/* Get length of the result buffer*/
  106|  4.58k|	len = *((uint16_t *) *buf) % max_size;
  107|  4.58k|	(*buf) += 2;
  108|  4.58k|	buf_len -= 2;
  109|  4.58k|	if (buf_len <= len) {
  ------------------
  |  Branch (109:6): [True: 9, False: 4.57k]
  ------------------
  110|      9|		*out = *buf;
  111|      9|		*out_len = buf_len;
  112|      9|		return 0;
  113|      9|	}
  114|       |
  115|       |	/* Set out buffer to new reader data*/
  116|  4.57k|	*out = *buf + len;
  117|  4.57k|	*out_len = buf_len - len;
  118|  4.57k|	return len;
  119|  4.58k|}
create_input_file:
  122|  4.58k|{
  123|  4.58k|	const uint8_t *ptr = *data;
  124|  4.58k|	size_t file_size = 0, backup_size = *size;
  125|  4.58k|	int fd = 0;
  126|  4.58k|	size_t r = 0;
  127|  4.58k|	char *filename = NULL;
  128|       |	
  129|       |	/* Split data into file content and rest*/
  130|  4.58k|	file_size = get_buffer(&ptr, *size, data, size, 6000);
  131|  4.58k|	if (file_size == 0)
  ------------------
  |  Branch (131:6): [True: 17, False: 4.57k]
  ------------------
  132|     17|		return 1;
  133|       |
  134|  4.57k|	filename = strdup("/tmp/input.XXXXXX");
  135|  4.57k|	fd = mkstemp(filename);
  136|  4.57k|	if (fd < 0) {
  ------------------
  |  Branch (136:6): [True: 0, False: 4.57k]
  ------------------
  137|      0|		*data = ptr - 2;
  138|      0|		*size = backup_size;
  139|      0|		free(filename);
  140|      0|		return 1;
  141|      0|	}
  142|       |
  143|  4.57k|	r = write(fd, ptr, file_size);
  144|  4.57k|	close(fd);
  145|       |
  146|  4.57k|	if (r != file_size) {
  ------------------
  |  Branch (146:6): [True: 0, False: 4.57k]
  ------------------
  147|      0|		*data = ptr - 2;
  148|      0|		*size = backup_size;
  149|      0|		remove_file(filename);
  150|      0|		return 1;
  151|      0|	}
  152|       |
  153|  4.57k|	*filename_out = filename;
  154|  4.57k|	return 0;
  155|  4.57k|}
remove_file:
  158|  4.57k|{
  159|  4.57k|	if (filename) {
  ------------------
  |  Branch (159:6): [True: 4.57k, False: 0]
  ------------------
  160|  4.57k|		unlink(filename);
  161|  4.57k|		free(filename);
  162|  4.57k|	}
  163|  4.57k|}
free_arguments:
  166|  10.7k|{
  167|  70.2k|	for (int i = 0; i < argc; i++) {
  ------------------
  |  Branch (167:18): [True: 59.4k, False: 10.7k]
  ------------------
  168|  59.4k|		free(argv[i]);
  169|  59.4k|	}
  170|  10.7k|	free(argv);
  171|  10.7k|}

_main:
  385|  15.3k|{
  386|  15.3k|	int err = 0, r, c, long_optind = 0;
  387|  15.3k|	int do_decipher = 0;
  388|  15.3k|	int do_sign = 0;
  389|  15.3k|	int do_print_version = 0;
  390|  15.3k|	int action_count = 0;
  391|  15.3k|	struct sc_pkcs15_object *key;
  392|  15.3k|	sc_context_param_t ctx_param;
  393|       |
  394|  3.83M|	while (1) {
  ------------------
  |  Branch (394:9): [True: 3.83M, Folded]
  ------------------
  395|  3.83M|		c = getopt_long(argc, argv, "sck:r:i:o:f:Rp:vw", options, &long_optind);
  396|  3.83M|		if (c == -1)
  ------------------
  |  Branch (396:7): [True: 15.3k, False: 3.81M]
  ------------------
  397|  15.3k|			break;
  398|  3.81M|		if (c == '?') {
  ------------------
  |  Branch (398:7): [True: 6, False: 3.81M]
  ------------------
  399|      6|			util_print_usage(app_name, options, option_help, NULL);
  ------------------
  |  |   87|      6|	do { \
  |  |   88|      6|		UTIL_ASSERT_OPTION_HELP(options, option_help); \
  |  |  ------------------
  |  |  |  |   83|      6|	static_assert(ARRAY_SIZE(options) == ARRAY_SIZE(option_help), \
  |  |  |  |   84|      6|			"options and option_help have different lengths")
  |  |  ------------------
  |  |   89|      6|		util_print_usage_internal(app_name, options, option_help, args); \
  |  |   90|      6|	} while (0)
  |  |  ------------------
  |  |  |  Branch (90:11): [Folded, False: 6]
  |  |  ------------------
  ------------------
  400|      6|			return 2;
  401|      6|		}
  402|  3.81M|		switch (c) {
  ------------------
  |  Branch (402:11): [True: 3.81M, False: 0]
  ------------------
  403|      0|		case OPT_VERSION:
  ------------------
  |  Branch (403:3): [True: 0, False: 3.81M]
  ------------------
  404|      0|			do_print_version = 1;
  405|      0|			action_count++;
  406|      0|			break;
  407|  4.48k|		case 's':
  ------------------
  |  Branch (407:3): [True: 4.48k, False: 3.81M]
  ------------------
  408|  4.48k|			do_sign++;
  409|  4.48k|			action_count++;
  410|  4.48k|			break;
  411|  11.4k|		case 'c':
  ------------------
  |  Branch (411:3): [True: 11.4k, False: 3.80M]
  ------------------
  412|  11.4k|			do_decipher++;
  413|  11.4k|			action_count++;
  414|  11.4k|			break;
  415|    270|		case 'k':
  ------------------
  |  Branch (415:3): [True: 270, False: 3.81M]
  ------------------
  416|    270|			opt_key_id = optarg;
  417|    270|			action_count++;
  418|    270|			break;
  419|    245|		case 'r':
  ------------------
  |  Branch (419:3): [True: 245, False: 3.81M]
  ------------------
  420|    245|			opt_reader = optarg;
  421|    245|			break;
  422|  4.76k|		case 'i':
  ------------------
  |  Branch (422:3): [True: 4.76k, False: 3.81M]
  ------------------
  423|  4.76k|			opt_input = optarg;
  424|  4.76k|			break;
  425|    435|		case 'o':
  ------------------
  |  Branch (425:3): [True: 435, False: 3.81M]
  ------------------
  426|    435|			opt_output = optarg;
  427|    435|			break;
  428|  4.77k|		case 'f':
  ------------------
  |  Branch (428:3): [True: 4.77k, False: 3.81M]
  ------------------
  429|  4.77k|			opt_sig_format = optarg;
  430|  4.77k|			break;
  431|    207|		case 'R':
  ------------------
  |  Branch (431:3): [True: 207, False: 3.81M]
  ------------------
  432|    207|			opt_raw = 1;
  433|    207|			break;
  434|  1.67k|		case OPT_SHA1:
  ------------------
  |  Branch (434:3): [True: 1.67k, False: 3.81M]
  ------------------
  435|  1.67k|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|  1.67k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  436|  1.67k|			break;
  437|    884|		case OPT_SHA256:
  ------------------
  |  Branch (437:3): [True: 884, False: 3.81M]
  ------------------
  438|    884|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|    884|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  439|    884|			break;
  440|    273|		case OPT_SHA384:
  ------------------
  |  Branch (440:3): [True: 273, False: 3.81M]
  ------------------
  441|    273|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  139|    273|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  442|    273|			break;
  443|    422|		case OPT_SHA512:
  ------------------
  |  Branch (443:3): [True: 422, False: 3.81M]
  ------------------
  444|    422|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  140|    422|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  445|    422|			break;
  446|    431|		case OPT_SHA224:
  ------------------
  |  Branch (446:3): [True: 431, False: 3.81M]
  ------------------
  447|    431|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  141|    431|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  448|    431|			break;
  449|  1.07k|		case OPT_MD5:
  ------------------
  |  Branch (449:3): [True: 1.07k, False: 3.81M]
  ------------------
  450|  1.07k|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  135|  1.07k|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  451|  1.07k|			break;
  452|  2.48k|		case OPT_PKCS1:
  ------------------
  |  Branch (452:3): [True: 2.48k, False: 3.81M]
  ------------------
  453|  2.48k|			opt_crypt_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|  2.48k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  2.48k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  2.48k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  454|  2.48k|			break;
  455|  3.77M|		case 'v':
  ------------------
  |  Branch (455:3): [True: 3.77M, False: 39.6k]
  ------------------
  456|  3.77M|			verbose++;
  457|  3.77M|			break;
  458|  4.77k|		case 'p':
  ------------------
  |  Branch (458:3): [True: 4.77k, False: 3.81M]
  ------------------
  459|  4.77k|			opt_pincode = optarg;
  460|  4.77k|			break;
  461|    623|		case OPT_BIND_TO_AID:
  ------------------
  |  Branch (461:3): [True: 623, False: 3.81M]
  ------------------
  462|    623|			opt_bind_to_aid = optarg;
  463|    623|			break;
  464|    360|		case 'w':
  ------------------
  |  Branch (464:3): [True: 360, False: 3.81M]
  ------------------
  465|    360|			opt_wait = 1;
  466|    360|			break;
  467|  3.81M|		}
  468|  3.81M|	}
  469|  15.3k|	if (action_count == 0) {
  ------------------
  |  Branch (469:6): [True: 86, False: 15.2k]
  ------------------
  470|     86|		util_print_usage(app_name, options, option_help, NULL);
  ------------------
  |  |   87|     86|	do { \
  |  |   88|     86|		UTIL_ASSERT_OPTION_HELP(options, option_help); \
  |  |  ------------------
  |  |  |  |   83|     86|	static_assert(ARRAY_SIZE(options) == ARRAY_SIZE(option_help), \
  |  |  |  |   84|     86|			"options and option_help have different lengths")
  |  |  ------------------
  |  |   89|     86|		util_print_usage_internal(app_name, options, option_help, args); \
  |  |   90|     86|	} while (0)
  |  |  ------------------
  |  |  |  Branch (90:11): [Folded, False: 86]
  |  |  ------------------
  ------------------
  471|     86|		return 2;
  472|     86|	}
  473|       |
  474|  15.2k|	if (do_print_version)   {
  ------------------
  |  Branch (474:6): [True: 0, False: 15.2k]
  ------------------
  475|      0|		printf("%s\n", OPENSC_SCM_REVISION);
  ------------------
  |  |  226|      0|#define OPENSC_SCM_REVISION "OpenSC-<version not available>, rev: 3832948, commit-time: 2026-10-27 13:51:48 +0100"
  ------------------
  476|      0|		action_count--;
  477|      0|	}
  478|       |
  479|  15.2k|	if (!(opt_crypt_flags & SC_ALGORITHM_RSA_HASHES))
  ------------------
  |  |  142|  15.2k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (479:6): [True: 10.6k, False: 4.57k]
  ------------------
  480|  10.6k|		opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|  10.6k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  481|       |
  482|  15.2k|	memset(&ctx_param, 0, sizeof(ctx_param));
  483|  15.2k|	ctx_param.ver      = 0;
  484|  15.2k|	ctx_param.app_name = app_name;
  485|  15.2k|	ctx_param.debug    = verbose;
  486|  15.2k|	if (verbose)
  ------------------
  |  Branch (486:6): [True: 225, False: 15.0k]
  ------------------
  487|    225|		ctx_param.debug_file = stderr;
  ------------------
  |  |   33|    225|#define stderr stdout
  ------------------
  488|       |
  489|  15.2k|	r = sc_context_create(&ctx, &ctx_param);
  490|  15.2k|	if (r) {
  ------------------
  |  Branch (490:6): [True: 0, False: 15.2k]
  ------------------
  491|      0|		fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r));
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  492|      0|		return 1;
  493|      0|	}
  494|       |
  495|  15.2k|	err = util_connect_card_ex(ctx, &card, opt_reader, opt_wait, 0);
  ------------------
  |  |   37|  15.2k|#define util_connect_card_ex(ctx, card, id, do_wait, do_lock) fuzz_util_connect_card(ctx, card)
  ------------------
  496|  15.2k|	if (err)
  ------------------
  |  Branch (496:6): [True: 3.23k, False: 12.0k]
  ------------------
  497|  3.23k|		goto end;
  498|       |
  499|  12.0k|	if (verbose)
  ------------------
  |  Branch (499:6): [True: 171, False: 11.8k]
  ------------------
  500|    171|		fprintf(stderr, "Trying to find a PKCS #15 compatible card...\n");
  ------------------
  |  |   33|    171|#define stderr stdout
  ------------------
  501|  12.0k|	if (opt_bind_to_aid)   {
  ------------------
  |  Branch (501:6): [True: 416, False: 11.6k]
  ------------------
  502|    416|		struct sc_aid aid;
  503|       |
  504|    416|		aid.len = sizeof(aid.value);
  505|    416|		if (sc_hex_to_bin(opt_bind_to_aid, aid.value, &aid.len))   {
  ------------------
  |  Branch (505:7): [True: 105, False: 311]
  ------------------
  506|    105|			fprintf(stderr, "Invalid AID value: '%s'\n", opt_bind_to_aid);
  ------------------
  |  |   33|    105|#define stderr stdout
  ------------------
  507|    105|			err = 1;
  508|    105|			goto end;
  509|    105|		}
  510|       |
  511|    311|		r = sc_pkcs15_bind(card, &aid, &p15card);
  512|    311|	}
  513|  11.6k|	else   {
  514|  11.6k|		struct sc_app_info *app_generic = sc_pkcs15_get_application_by_type(card, "generic");
  515|  11.6k|		struct sc_aid *aid = app_generic ? &app_generic->aid : NULL;
  ------------------
  |  Branch (515:24): [True: 0, False: 11.6k]
  ------------------
  516|  11.6k|		r = sc_pkcs15_bind(card, aid, &p15card);
  517|  11.6k|	}
  518|  11.9k|	if (r) {
  ------------------
  |  Branch (518:6): [True: 7.38k, False: 4.53k]
  ------------------
  519|  7.38k|		fprintf(stderr, "PKCS #15 binding failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|  7.38k|#define stderr stdout
  ------------------
  520|  7.38k|		err = 1;
  521|  7.38k|		goto end;
  522|  7.38k|	}
  523|  4.53k|	if (verbose)
  ------------------
  |  Branch (523:6): [True: 77, False: 4.45k]
  ------------------
  524|     77|		fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label);
  ------------------
  |  |   33|     77|#define stderr stdout
  ------------------
  525|       |
  526|  4.53k|	if (do_decipher) {
  ------------------
  |  Branch (526:6): [True: 2.89k, False: 1.64k]
  ------------------
  527|  2.89k|		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP, &key))
  ------------------
  |  |  306|  2.89k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP, &key))
  ------------------
  |  |  310|  2.89k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (527:7): [True: 2.57k, False: 320]
  ------------------
  528|    320|		 || (err = decipher(key)))
  ------------------
  |  Branch (528:7): [True: 286, False: 34]
  ------------------
  529|  2.85k|			goto end;
  530|     34|		action_count--;
  531|     34|	}
  532|       |
  533|  1.67k|	if (do_sign) {
  ------------------
  |  Branch (533:6): [True: 1.63k, False: 43]
  ------------------
  534|  1.63k|		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_SIGN|
  ------------------
  |  |  307|  1.63k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  |  Branch (534:7): [True: 1.39k, False: 241]
  ------------------
  535|  1.63k|				   SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|  1.63k|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  536|  1.63k|				   SC_PKCS15_PRKEY_USAGE_NONREPUDIATION, &key))
  ------------------
  |  |  314|  1.63k|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  537|    241|		 || (err = sign(key)))
  ------------------
  |  Branch (537:7): [True: 205, False: 36]
  ------------------
  538|  1.59k|			goto end;
  539|     36|		action_count--;
  540|     36|	}
  541|  15.2k|end:
  542|  15.2k|	if (p15card)
  ------------------
  |  Branch (542:6): [True: 4.53k, False: 10.7k]
  ------------------
  543|  4.53k|		sc_pkcs15_unbind(p15card);
  544|  15.2k|	if (card) {
  ------------------
  |  Branch (544:6): [True: 12.0k, False: 3.23k]
  ------------------
  545|  12.0k|		sc_disconnect_card(card);
  546|  12.0k|	}
  547|  15.2k|	if (ctx)
  ------------------
  |  Branch (547:6): [True: 15.2k, False: 0]
  ------------------
  548|  15.2k|		sc_release_context(ctx);
  549|  15.2k|	return err;
  550|  1.67k|}
fuzz_pkcs15_crypt.c:get_key:
  304|  4.52k|{
  305|  4.52k|	sc_pkcs15_object_t *key, *pin = NULL;
  306|  4.52k|	const char	*usage_name;
  307|  4.52k|	sc_pkcs15_id_t	id;
  308|  4.52k|	int		r;
  309|       |
  310|  4.52k|	usage_name = (usage & SC_PKCS15_PRKEY_USAGE_SIGN)? "signature" : "decryption";
  ------------------
  |  |  307|  4.52k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  |  Branch (310:15): [True: 1.63k, False: 2.89k]
  ------------------
  311|       |
  312|  4.52k|	if (opt_key_id != NULL) {
  ------------------
  |  Branch (312:6): [True: 31, False: 4.49k]
  ------------------
  313|     31|		sc_pkcs15_hex_string_to_id(opt_key_id, &id);
  314|     31|		r = sc_pkcs15_find_prkey_by_id_usage(p15card, &id, usage, &key);
  315|     31|		if (r < 0) {
  ------------------
  |  Branch (315:7): [True: 30, False: 1]
  ------------------
  316|     30|			fprintf(stderr, "Unable to find private %s key '%s': %s\n",
  ------------------
  |  |   33|     30|#define stderr stdout
  ------------------
  317|     30|				usage_name, opt_key_id, sc_strerror(r));
  318|     30|			return 2;
  319|     30|		}
  320|  4.49k|	} else {
  321|  4.49k|		r = sc_pkcs15_find_prkey_by_id_usage(p15card, NULL, usage, &key);
  322|  4.49k|		if (r < 0) {
  ------------------
  |  Branch (322:7): [True: 3.64k, False: 852]
  ------------------
  323|  3.64k|			fprintf(stderr, "Unable to find any private %s key: %s\n",
  ------------------
  |  |   33|  3.64k|#define stderr stdout
  ------------------
  324|  3.64k|				usage_name, sc_strerror(r));
  325|  3.64k|			return 2;
  326|  3.64k|		}
  327|  4.49k|	}
  328|       |
  329|    853|	*result = key;
  330|       |
  331|    853|	if (key->auth_id.len) {
  ------------------
  |  Branch (331:6): [True: 729, False: 124]
  ------------------
  332|    729|		static sc_pkcs15_object_t *prev_pin = NULL;
  333|    729|		char	*pincode;
  334|       |
  335|    729|		r = sc_pkcs15_find_pin_by_auth_id(p15card, &key->auth_id, &pin);
  336|    729|		if (r) {
  ------------------
  |  Branch (336:7): [True: 6, False: 723]
  ------------------
  337|      6|			fprintf(stderr, "Unable to find PIN code for private key: %s\n",
  ------------------
  |  |   33|      6|#define stderr stdout
  ------------------
  338|      6|				sc_strerror(r));
  339|      6|			return 1;
  340|      6|		}
  341|       |
  342|       |		/* Pin already verified previously */
  343|    723|		if (pin == prev_pin && key->user_consent == 0)
  ------------------
  |  Branch (343:7): [True: 249, False: 474]
  |  Branch (343:26): [True: 246, False: 3]
  ------------------
  344|    246|			return 0;
  345|       |
  346|    477|		pincode = get_pin(pin);
  347|    477|		if (((pincode == NULL || *pincode == '\0')) &&
  ------------------
  |  Branch (347:9): [True: 1, False: 476]
  |  Branch (347:28): [True: 0, False: 476]
  ------------------
  348|      1|		    !(p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD)) {
  ------------------
  |  |  376|      1|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (348:7): [True: 1, False: 0]
  ------------------
  349|      1|			free(pincode);
  350|      1|			return 5;
  351|      1|		}
  352|       |
  353|       |		/*
  354|       |		 * Do what PKCS#11 would do for keys requiring CKA_ALWAYS_AUTHENTICATE
  355|       |		 * and CKU_CONTEXT_SPECIFIC login to let driver know this verify will be followed by
  356|       |		 * a crypto operation.  Card drivers can test for SC_AC_CONTEXT_SPECIFIC
  357|       |		 * to do any special handling.
  358|       |		 */
  359|    476|		if (key->user_consent && pin) {
  ------------------
  |  Branch (359:7): [True: 19, False: 457]
  |  Branch (359:28): [True: 19, False: 0]
  ------------------
  360|     19|			int auth_meth_saved;
  361|     19|			struct sc_pkcs15_auth_info *pinfo = (struct sc_pkcs15_auth_info *) pin->data;
  362|       |
  363|     19|			auth_meth_saved = pinfo->auth_method;
  364|       |
  365|     19|			pinfo->auth_method = SC_AC_CONTEXT_SPECIFIC;
  ------------------
  |  |  160|     19|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  366|     19|			r = sc_pkcs15_verify_pin(p15card, pin, (const u8 *)pincode, pincode ? strlen(pincode) : 0);
  ------------------
  |  Branch (366:64): [True: 19, False: 0]
  ------------------
  367|     19|			pinfo->auth_method = auth_meth_saved;
  368|     19|		} else
  369|    457|			r = sc_pkcs15_verify_pin(p15card, pin, (const u8 *)pincode, pincode ? strlen(pincode) : 0);
  ------------------
  |  Branch (369:64): [True: 457, False: 0]
  ------------------
  370|       |
  371|    476|		free(pincode);
  372|    476|		if (r) {
  ------------------
  |  Branch (372:7): [True: 285, False: 191]
  ------------------
  373|    285|			fprintf(stderr, "PIN code verification failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    285|#define stderr stdout
  ------------------
  374|    285|			return 5;
  375|    285|		}
  376|    191|		if (verbose)
  ------------------
  |  Branch (376:7): [True: 3, False: 188]
  ------------------
  377|      3|			fprintf(stderr, "PIN code correct.\n");
  ------------------
  |  |   33|      3|#define stderr stdout
  ------------------
  378|    191|		prev_pin = pin;
  379|    191|	}
  380|       |
  381|    315|	return 0;
  382|    853|}
fuzz_pkcs15_crypt.c:get_pin:
  128|    477|{
  129|    477|	char buf[(sizeof obj->label) + 20];
  130|    477|	char *pincode;
  131|    477|	struct sc_pkcs15_auth_info *pinfo;
  132|       |
  133|    477|	if (!obj)
  ------------------
  |  Branch (133:6): [True: 0, False: 477]
  ------------------
  134|      0|		return NULL;
  135|       |
  136|    477|	pinfo = (struct sc_pkcs15_auth_info *) obj->data;
  137|    477|	if (pinfo->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    477|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (137:6): [True: 0, False: 477]
  ------------------
  138|      0|		return NULL;
  139|       |
  140|    477|	if (opt_pincode != NULL) {
  ------------------
  |  Branch (140:6): [True: 477, False: 0]
  ------------------
  141|    477|		if (strcmp(opt_pincode, "-") == 0)
  ------------------
  |  Branch (141:7): [True: 1, False: 476]
  ------------------
  142|      1|			return readpin_stdin();
  143|    476|		else
  144|    476|			return strdup(opt_pincode);
  145|    477|	}
  146|       |
  147|      0|	snprintf(buf, sizeof(buf), "Enter PIN [%.*s]: ",
  148|      0|		(int) sizeof obj->label, obj->label);
  149|      0|	while (1) {
  ------------------
  |  Branch (149:9): [True: 0, Folded]
  ------------------
  150|      0|		pincode = getpass(buf);
  151|      0|		if (strlen(pincode) == 0)
  ------------------
  |  Branch (151:7): [True: 0, False: 0]
  ------------------
  152|      0|			return NULL;
  153|      0|		if (strlen(pincode) < pinfo->attrs.pin.min_length ||
  ------------------
  |  Branch (153:7): [True: 0, False: 0]
  ------------------
  154|      0|				strlen(pincode) > pinfo->attrs.pin.max_length)
  ------------------
  |  Branch (154:5): [True: 0, False: 0]
  ------------------
  155|      0|			continue;
  156|      0|		return strdup(pincode);
  157|      0|	}
  158|      0|}
fuzz_pkcs15_crypt.c:readpin_stdin:
  113|      1|{
  114|      1|	char buf[128];
  115|      1|	char *p;
  116|       |
  117|      1|	p = fgets(buf, sizeof(buf), stdin);
  118|      1|	if (p != NULL) {
  ------------------
  |  Branch (118:6): [True: 0, False: 1]
  ------------------
  119|      0|		p = strchr(buf, '\n');
  120|      0|		if (p != NULL)
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|      0|			*p = '\0';
  122|      0|		return strdup(buf);
  123|      0|	}
  124|      1|	return NULL;
  125|      1|}
fuzz_pkcs15_crypt.c:decipher:
  274|    320|{
  275|    320|	u8 buf[1024], out[1024];
  276|    320|	int r, len, flags;
  277|    320|	size_t c;
  278|       |
  279|    320|	if (opt_input == NULL) {
  ------------------
  |  Branch (279:6): [True: 0, False: 320]
  ------------------
  280|      0|		fprintf(stderr, "No input file specified. Reading from stdin\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  281|      0|	}
  282|    320|	c = read_input(buf, sizeof(buf));
  283|    320|	if (c <= 0)
  ------------------
  |  Branch (283:6): [True: 48, False: 272]
  ------------------
  284|     48|		return 2;
  285|       |
  286|    272|	len = sizeof(out);
  287|    272|	if (!((struct sc_pkcs15_prkey_info *) obj->data)->native) {
  ------------------
  |  Branch (287:6): [True: 0, False: 272]
  ------------------
  288|      0|                fprintf(stderr, "Deprecated non-native key detected! Upgrade your smart cards.\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  289|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  290|      0|	}
  291|       |
  292|    272|	flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  109|    272|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  293|    272|	r = sc_pkcs15_decipher(p15card, obj, flags, buf, c, out, len, NULL);
  294|    272|	if (r < 0) {
  ------------------
  |  Branch (294:6): [True: 238, False: 34]
  ------------------
  295|    238|		fprintf(stderr, "Decrypt failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    238|#define stderr stdout
  ------------------
  296|    238|		return 1;
  297|    238|	}
  298|     34|	r = write_output(out, r);
  299|       |
  300|     34|	return r;
  301|    272|}
fuzz_pkcs15_crypt.c:read_input:
  161|    561|{
  162|    561|	FILE *inf;
  163|    561|	size_t c;
  164|       |
  165|    561|	if (opt_input==NULL) {
  ------------------
  |  Branch (165:6): [True: 0, False: 561]
  ------------------
  166|      0|		inf = stdin;
  167|    561|	} else {
  168|    561|		inf = fopen(opt_input, "rb");
  169|    561|		if (inf == NULL) {
  ------------------
  |  Branch (169:7): [True: 96, False: 465]
  ------------------
  170|     96|			fprintf(stderr, "Unable to open '%s' for reading.\n", opt_input);
  ------------------
  |  |   33|     96|#define stderr stdout
  ------------------
  171|     96|			return 0;
  172|     96|		}
  173|    561|	}
  174|    465|	c = fread(buf, 1, buflen, inf);
  175|    465|	if (inf!=stdin) {
  ------------------
  |  Branch (175:6): [True: 465, False: 0]
  ------------------
  176|    465|		fclose(inf);
  177|    465|	}
  178|    465|	if (c <= 0) {
  ------------------
  |  Branch (178:6): [True: 0, False: 465]
  ------------------
  179|      0|		perror("read");
  180|      0|		return 0;
  181|      0|	}
  182|    465|	return c;
  183|    465|}
fuzz_pkcs15_crypt.c:write_output:
  186|     70|{
  187|     70|	FILE *outf;
  188|     70|	int output_binary = (opt_output == NULL && opt_raw == 0 ? 0 : 1);
  ------------------
  |  Branch (188:23): [True: 70, False: 0]
  |  Branch (188:45): [True: 70, False: 0]
  ------------------
  189|       |
  190|     70|	if (opt_output != NULL) {
  ------------------
  |  Branch (190:6): [True: 0, False: 70]
  ------------------
  191|      0|		outf = fopen(opt_output, "wb");
  192|      0|		if (outf == NULL) {
  ------------------
  |  Branch (192:7): [True: 0, False: 0]
  ------------------
  193|      0|			fprintf(stderr, "Unable to open '%s' for writing.\n", opt_output);
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  194|      0|			return -1;
  195|      0|		}
  196|     70|	} else {
  197|     70|		outf = stdout;
  198|     70|	}
  199|       |
  200|     70|	if (output_binary == 0)
  ------------------
  |  Branch (200:6): [True: 70, False: 0]
  ------------------
  201|     70|		util_print_binary(outf, buf, len);
  202|      0|	else
  203|      0|		fwrite(buf, len, 1, outf);
  204|       |
  205|     70|	if (outf != stdout)
  ------------------
  |  Branch (205:6): [True: 0, False: 70]
  ------------------
  206|      0|		fclose(outf);
  207|     70|	return 0;
  208|     70|}
fuzz_pkcs15_crypt.c:sign:
  211|    241|{
  212|    241|	u8 buf[1024], out[1024];
  213|    241|	struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data;
  214|    241|	int r, flags;
  215|    241|	size_t c, len;
  216|       |
  217|    241|	if (opt_input == NULL) {
  ------------------
  |  Branch (217:6): [True: 0, False: 241]
  ------------------
  218|      0|		fprintf(stderr, "No input file specified. Reading from stdin\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  219|      0|	}
  220|       |
  221|    241|	c = read_input(buf, sizeof(buf));
  222|    241|	if (c <= 0)
  ------------------
  |  Branch (222:6): [True: 48, False: 193]
  ------------------
  223|     48|		return 2;
  224|    193|	len = sizeof(out);
  225|    193|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA
  ------------------
  |  |  419|    386|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (225:6): [True: 146, False: 47]
  ------------------
  226|    146|			&& !(opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|    146|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (226:7): [True: 2, False: 144]
  ------------------
  227|      2|			&& (size_t)c != key->modulus_length/8) {
  ------------------
  |  Branch (227:7): [True: 1, False: 1]
  ------------------
  228|      1|		fprintf(stderr, "Input has to be exactly %lu bytes, when using no padding.\n",
  ------------------
  |  |   33|      1|#define stderr stdout
  ------------------
  229|      1|			(unsigned long) key->modulus_length/8);
  230|      1|		return 2;
  231|      1|	}
  232|    192|	if (!key->native) {
  ------------------
  |  Branch (232:6): [True: 0, False: 192]
  ------------------
  233|      0|		fprintf(stderr, "Deprecated non-native key detected! Upgrade your smart cards.\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  234|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  235|      0|	}
  236|       |
  237|    192|	flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|    192|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  238|    192|	r = sc_pkcs15_compute_signature(p15card, obj, flags, buf, c, out, len, NULL);
  239|    192|	if (r < 0) {
  ------------------
  |  Branch (239:6): [True: 156, False: 36]
  ------------------
  240|    156|		fprintf(stderr, "Compute signature failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    156|#define stderr stdout
  ------------------
  241|    156|		return 1;
  242|    156|	}
  243|     36|	len = r;
  244|       |
  245|     36|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC)   {
  ------------------
  |  |  421|     36|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (245:6): [True: 4, False: 32]
  ------------------
  246|      4|		if (opt_sig_format &&  (!strcmp(opt_sig_format, "openssl") || !strcmp(opt_sig_format, "sequence")))   {
  ------------------
  |  Branch (246:7): [True: 4, False: 0]
  |  Branch (246:27): [True: 2, False: 2]
  |  Branch (246:65): [True: 1, False: 1]
  ------------------
  247|      3|			unsigned char *seq;
  248|      3|			size_t seqlen;
  249|       |
  250|      3|			if (sc_asn1_sig_value_rs_to_sequence(ctx, out, len, &seq, &seqlen))   {
  ------------------
  |  Branch (250:8): [True: 0, False: 3]
  ------------------
  251|      0|				fprintf(stderr, "Failed to convert signature to ASN1 sequence format.\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  252|      0|				return 2;
  253|      0|			}
  254|       |
  255|      3|			if (seqlen > sizeof(out)) {
  ------------------
  |  Branch (255:8): [True: 0, False: 3]
  ------------------
  256|      0|				free(seq);
  257|      0|				fprintf(stderr, "Signature sequence too large\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  258|      0|				return 2;
  259|      0|			}
  260|       |
  261|      3|			memcpy(out, seq, seqlen);
  262|      3|			len = seqlen;
  263|       |
  264|      3|			free(seq);
  265|      3|		}
  266|      4|	}
  267|       |
  268|     36|	r = write_output(out, len);
  269|       |
  270|     36|	return r;
  271|     36|}

util_print_binary:
  206|     70|{
  207|     70|	size_t i;
  208|       |
  209|  15.4k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (209:14): [True: 15.3k, False: 70]
  ------------------
  210|  15.3k|		unsigned char c = buf[i];
  211|  15.3k|		const char *format;
  212|  15.3k|		if (!isprint(c))
  ------------------
  |  Branch (212:7): [True: 13.8k, False: 1.53k]
  ------------------
  213|  13.8k|			format = "\\x%02X";
  214|  1.53k|		else
  215|  1.53k|			format = "%c";
  216|  15.3k|		fprintf(f, format, c);
  217|  15.3k|	}
  218|     70|	(void) fflush(f);
  219|     70|}
util_print_usage_internal:
  264|     92|{
  265|     92|	int i;
  266|     92|	int header_shown = 0;
  267|       |
  268|     92|	if (args)
  ------------------
  |  Branch (268:6): [True: 0, False: 92]
  ------------------
  269|      0|		printf("Usage: %s [OPTIONS] %s\n", app_name, args);
  270|     92|	else
  271|     92|		printf("Usage: %s [OPTIONS]\n", app_name);
  272|       |
  273|  1.93k|	for (i = 0; options[i].name; i++) {
  ------------------
  |  Branch (273:14): [True: 1.84k, False: 92]
  ------------------
  274|  1.84k|		char buf[40];
  275|  1.84k|		const char *arg_str;
  276|       |
  277|       |		/* Skip "hidden" options */
  278|  1.84k|		if (option_help[i] == NULL)
  ------------------
  |  Branch (278:7): [True: 0, False: 1.84k]
  ------------------
  279|      0|			continue;
  280|       |
  281|  1.84k|		if (!header_shown++)
  ------------------
  |  Branch (281:7): [True: 92, False: 1.74k]
  ------------------
  282|     92|			printf("Options:\n");
  283|       |
  284|  1.84k|		switch (options[i].has_arg) {
  285|    644|		case 1:
  ------------------
  |  Branch (285:3): [True: 644, False: 1.19k]
  ------------------
  286|    644|			arg_str = " <arg>";
  287|    644|			break;
  288|      0|		case 2:
  ------------------
  |  Branch (288:3): [True: 0, False: 1.84k]
  ------------------
  289|      0|			arg_str = " [arg]";
  290|      0|			break;
  291|  1.19k|		default:
  ------------------
  |  Branch (291:3): [True: 1.19k, False: 644]
  ------------------
  292|  1.19k|			arg_str = "";
  293|  1.19k|			break;
  294|  1.84k|		}
  295|  1.84k|		if (isascii(options[i].val) &&
  ------------------
  |  Branch (295:7): [True: 1.01k, False: 828]
  ------------------
  296|  1.84k|		    isprint(options[i].val) && !isspace(options[i].val))
  ------------------
  |  Branch (296:7): [True: 1.01k, False: 0]
  |  Branch (296:34): [True: 1.01k, False: 0]
  ------------------
  297|  1.01k|			sprintf(buf, "-%c, --%s%s", options[i].val, options[i].name, arg_str);
  298|    828|		else
  299|    828|			sprintf(buf, "    --%s%s", options[i].name, arg_str);
  300|       |
  301|       |		/* print the line - wrap if necessary */
  302|  1.84k|		if (strlen(buf) > 28) {
  ------------------
  |  Branch (302:7): [True: 0, False: 1.84k]
  ------------------
  303|      0|			printf("  %s\n", buf);
  304|      0|			buf[0] = '\0';
  305|      0|		}
  306|  1.84k|		printf("  %-28s  %s\n", buf, option_help[i]);
  307|  1.84k|	}
  308|     92|}

sc_notify:
  534|      2|void sc_notify(const char *title, const char *text) {}
sc_notify_id:
  536|    402|		struct sc_pkcs15_card *p15card, enum ui_str id) {}

